shithub: choc

Download patch

ref: 35f805c234a4fce24ecbe564b67fd0fd7acca699
parent: 2435f5bb4de3a31c38748a0cab70d654c3bd4a8f
author: Jonathan Dowland <jon+github@alcopop.org>
date: Mon Jul 4 17:17:46 EDT 2016

Fix mix-up of up/down buttons; ignore OS invert

Don't bother trying to override the OS on the mouse wheel
axis inversion, to be consistent with SDL1.

Fix mixing up the up/down button numbers.

Rename some variables for clarity.

--- a/src/i_input.c
+++ b/src/i_input.c
@@ -360,40 +360,31 @@
     // SDL2 distinguishes button events from mouse wheel events.
     // We want to treat the mouse wheel as two buttons, as per
     // SDL1
-    event_t event1, event2;
-    int y = wheel->y;
+    event_t up, down;
     int button;
 
-#if !(SDL_MAJOR_VERSION == 2 && SDL_MINOR_VERSION == 0 && SDL_PATCHLEVEL < 4)
-    // Ignore OS axis inversion (so up is always up)
-    if (wheel->direction == SDL_MOUSEWHEEL_FLIPPED)
-    {
-        y *= -1;
-    }
-#endif
-
-    if (y <= 0)
+    if (wheel->y <= 0)
     {   // scroll down
-        button = 3;
+        button = 4;
     }
     else
     {   // scroll up
-        button = 4;
+        button = 3;
     }
 
     // post a button down event
     mouse_button_state |= (1 << button);
-    event1.type = ev_mouse;
-    event1.data1 = mouse_button_state;
-    event1.data2 = event1.data3 = 0;
-    D_PostEvent(&event1);
+    down.type = ev_mouse;
+    down.data1 = mouse_button_state;
+    down.data2 = down.data3 = 0;
+    D_PostEvent(&down);
 
     // post a button up event
     mouse_button_state &= ~(1 << button);
-    event2.type = ev_mouse;
-    event2.data1 = mouse_button_state;
-    event2.data2 = event2.data3 = 0;
-    D_PostEvent(&event2);
+    up.type = ev_mouse;
+    up.data1 = mouse_button_state;
+    up.data2 = up.data3 = 0;
+    D_PostEvent(&up);
 }
 
 void I_HandleMouseEvent(SDL_Event *sdlevent)
--- a/textscreen/txt_sdl.c
+++ b/textscreen/txt_sdl.c
@@ -535,17 +535,7 @@
 
 static int SDLWheelToTXTButton(SDL_MouseWheelEvent *wheel)
 {
-    int y = wheel->y;
-
-#if !(SDL_MAJOR_VERSION == 2 && SDL_MINOR_VERSION == 0 && SDL_PATCHLEVEL < 4)
-    // Ignore OS axis inversion (so up is always up)
-    if (wheel->direction == SDL_MOUSEWHEEL_FLIPPED)
-    {
-        y *= -1;
-    }
-#endif
-
-    if (y <= 0)
+    if (wheel->y <= 0)
     {
         return TXT_MOUSE_SCROLLDOWN;
     }