[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

patch for ocamlsdl bug: mouse button event mismatch



Hi,

In current ocamlsdl, if the user does a mouse left clic, ocamlsdl sends a 
right clic event. (right clic will send middle clic, etc...)

This is because ocamlsdl's stub doesn't uses the macros SDL_BUTTON_LEFT, but 
uses an integer value instead (probably a value from an older SDL version).

This patch can be applied for the current CVS or for the version 0.9.0.

Kind regards
diff -Naur OCamlSDL.orig/src/sdlevent_stub.c OCamlSDL.work/src/sdlevent_stub.c
--- OCamlSDL.orig/src/sdlevent_stub.c	2012-06-18 19:56:45.000000000 +0200
+++ OCamlSDL.work/src/sdlevent_stub.c	2012-06-18 22:11:37.000000000 +0200
@@ -112,14 +112,21 @@
 
 static value value_of_mouse_button(Uint8 b)
 {
-  value r;
-  if (SDL_BUTTON_LEFT <= b && b <= SDL_BUTTON_WHEELDOWN)
-    r = Val_int(b);
-  else {
-    r = caml_alloc_small(1, 0);
-    Field(r, 0) = Val_int(b);
+  switch (b) {
+    case SDL_BUTTON_LEFT:      return Val_int(0);
+    case SDL_BUTTON_MIDDLE:    return Val_int(1);
+    case SDL_BUTTON_RIGHT:     return Val_int(2);
+    case SDL_BUTTON_WHEELUP:   return Val_int(3);
+    case SDL_BUTTON_WHEELDOWN: return Val_int(4);
+    case SDL_BUTTON_X1:
+    case SDL_BUTTON_X2:
+    default:
+    { value r = caml_alloc_small(1, 0);
+      Field(r, 0) = Val_int(b);
+      return r;
+    }
   }
-  return r;
+  raise_event_exn("unrecognised mouse button");
 }
 
 static value value_of_SDLEvent(SDL_Event evt)

Reply to: