Skip to content
This repository has been archived by the owner on Jun 6, 2020. It is now read-only.

Accomodate new pan event changes #56

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 3 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
55 changes: 27 additions & 28 deletions src/sdl2.re
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,12 @@ module Keycode = {
let left = 1073741904;
};

module Axis = {
type t =
| Vertical
| Horizontal;
};

module WheelType = {
type t =
| Last
Expand Down Expand Up @@ -391,17 +397,20 @@ module Event = {
isFlipped: bool,
};

type mousePan = {
module PanElements = {
type t =
| Interrupt
| Fling
| Pan(float);
}

type panEvent = {
windowID: int,
deltaX: int,
deltaY: int,
containsX: bool,
containsY: bool,
isFling: bool,
isInterrupt: bool,
source: WheelType.t,
timestamp: int,
};
source: WheelType.t,
axis: Axis.t,
action: PanElements.t,
}

type mouseButtonEvent = {
windowID: int,
Expand Down Expand Up @@ -471,7 +480,7 @@ module Event = {
| WindowClosed(windowEvent)
| WindowTakeFocus(windowEvent)
| WindowHitTest(windowEvent)
| MousePan(mousePan)
| Pan(panEvent)
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is mousePan still used ?

// An event that hasn't been implemented yet
| Unknown;

Expand All @@ -488,26 +497,16 @@ module Event = {
deltaY,
isFlipped ? 1 : 0,
)
| MousePan({
| Pan({
windowID,
deltaX,
deltaY,
containsX,
containsY,
isFling,
isInterrupt,
timestamp,
action,
_,
}) =>
Printf.sprintf(
"Pan event: %d %d %d %d %d %d %d",
windowID,
deltaX,
deltaY,
if (containsX) {1} else {0},
if (containsY) {1} else {0},
if (isFling) {1} else {0},
if (isInterrupt) {1} else {0},
)
}) => switch (action) {
| Interrupt => Printf.sprintf("Interrupt event at timestamp %d", timestamp)
| Fling => Printf.sprintf("Fling event at timestamp %d", timestamp)
| Pan(delta) => Printf.sprintf("Pan event at timestamp %d with delta %f", timestamp, delta);
}
| MouseButtonUp({windowID, button, _}) =>
Printf.sprintf(
"MouseButtonUp windowId: %d button: %s",
Expand Down
42 changes: 32 additions & 10 deletions src/sdl2_wrapper.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -717,17 +717,39 @@ CAMLprim value Val_SDL_Event(SDL_Event *event) {
case SDL_PANEVENT:
v = caml_alloc(1, 24);

vInner = caml_alloc(9, 0);
vInner = caml_alloc(40, 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

5 is enough ? panEvent has 5 field: so 5 values.

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦 yep, forgot it isn't malloc lol

Copy link
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed

Store_field(vInner, 0, Val_int(event->window.windowID));
Store_field(vInner, 1, Val_int(event->pan.x));
Store_field(vInner, 2, Val_int(event->pan.y));
Store_field(vInner, 3, Val_bool(event->pan.contains_x));
Store_field(vInner, 4, Val_bool(event->pan.contains_y));
Store_field(vInner, 5, Val_bool(event->pan.fling));
Store_field(vInner, 6, Val_bool(event->pan.interrupt));
// verify this is the correct way of representing a ref to some WheelType.t
Store_field(vInner, 7, Val_int(event->pan.source_type));
Store_field(vInner, 8, Val_int(event->pan.timestamp));
Store_field(vInner, 1, Val_int(event->pan.timestamp));

Store_field(vInner, 2, Val_int(event->pan.source));
int axis;
switch (event->pan.axis) {
case SDL_PAN_AXIS_VERTICAL: axis = 0; break;
case SDL_PAN_AXIS_HORIZONTAL: axis = 1; break;
}

Store_field(vInner, 3, Val_int(axis));

switch (event->pan.pantype) {
case SDL_PANEVENTTYPE_INTERRUPT:
//
Store_field(vInner, 4, Val_int(0));
break;
case SDL_PANEVENTTYPE_FLING:
//
Store_field(vInner, 4, Val_int(1));
break;
case SDL_PANEVENTTYPE_PAN:
CAMLlocal2(panElement, floatElement);
panElement = caml_alloc(1, 0);

floatElement = caml_copy_double(event->pan.contents.pan.delta);

Store_field(panElement, 0, floatElement);

Store_field(vInner, 4, panElement);
break;
}

Store_field(v, 0, vInner);
break;
Expand Down