diff --git a/src/sdl2.re b/src/sdl2.re index b77d376..ed21d7c 100644 --- a/src/sdl2.re +++ b/src/sdl2.re @@ -313,6 +313,12 @@ module Keycode = { let left = 1073741904; }; +module Axis = { + type t = + | Vertical + | Horizontal; +}; + module WheelType = { type t = | Last @@ -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, @@ -471,7 +480,7 @@ module Event = { | WindowClosed(windowEvent) | WindowTakeFocus(windowEvent) | WindowHitTest(windowEvent) - | MousePan(mousePan) + | Pan(panEvent) // An event that hasn't been implemented yet | Unknown; @@ -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", diff --git a/src/sdl2_wrapper.cpp b/src/sdl2_wrapper.cpp index a60f650..7f49c91 100644 --- a/src/sdl2_wrapper.cpp +++ b/src/sdl2_wrapper.cpp @@ -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(5, 0); 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;