]> git.xonotic.org Git - xonotic/darkplaces.git/commitdiff
sdl2: fix mouse wheel
authordivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Jan 2014 18:53:30 +0000 (18:53 +0000)
committerdivverent <divverent@d7cf8633-e32d-0410-b094-e92efae38249>
Fri, 10 Jan 2014 18:53:30 +0000 (18:53 +0000)
git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12049 d7cf8633-e32d-0410-b094-e92efae38249

common.h
vid_sdl.c

index aa0491a2b1eb3e6873c64895229bbbe8373bde05..6e45808efd5f8fdfbd9dc98294727f7ac0ce62f9 100644 (file)
--- a/common.h
+++ b/common.h
@@ -383,5 +383,7 @@ char **XPM_DecodeString(const char *in);
 
 size_t base64_encode(unsigned char *buf, size_t buflen, size_t outbuflen);
 
+#define ARRAY_SIZE(a) (sizeof(a) / sizeof((a)[0]))
+
 #endif
 
index 11fec7351456f3ab8f4f011a9cec8ce83772d909..b090c2bc17ad6e7ad3698aa1965e4a03152906a5 100644 (file)
--- a/vid_sdl.c
+++ b/vid_sdl.c
@@ -1066,13 +1066,19 @@ static void sdl_newmap(void)
 }
 #endif
 
-static keynum_t buttonremap[18] =
+static keynum_t buttonremap[] =
 {
        K_MOUSE1,
        K_MOUSE3,
        K_MOUSE2,
+#if SDL_MAJOR_VERSION == 1
+       // TODO Find out how SDL maps these buttons. It looks like we should
+       // still include these for sdl2? At least the button indexes don't
+       // differ between SDL1 and SDL2 for me, thus this array should stay the
+       // same (in X11 button order).
        K_MWHEELUP,
        K_MWHEELDOWN,
+#endif
        K_MOUSE4,
        K_MOUSE5,
        K_MOUSE6,
@@ -1121,7 +1127,7 @@ void Sys_SendKeyEvents( void )
                        case SDL_MOUSEBUTTONDOWN:
                        case SDL_MOUSEBUTTONUP:
                                if (!vid_touchscreen.integer)
-                               if (event.button.button <= 18)
+                               if (event.button.button > 0 && event.button.button <= ARRAY_SIZE(buttonremap))
                                        Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
                                break;
                        case SDL_JOYBUTTONDOWN:
@@ -1237,9 +1243,23 @@ void Sys_SendKeyEvents( void )
                                        Con_DPrintf("SDL_Event: SDL_MOUSEBUTTONUP\n");
 #endif
                                if (!vid_touchscreen.integer)
-                               if (event.button.button <= 18)
+                               if (event.button.button > 0 && event.button.button <= ARRAY_SIZE(buttonremap))
                                        Key_Event( buttonremap[event.button.button - 1], 0, event.button.state == SDL_PRESSED );
                                break;
+                       case SDL_MOUSEWHEEL:
+                               // TODO support wheel x direction.
+                               i = event.wheel.y;
+                               while (i > 0) {
+                                       --i;
+                                       Key_Event( K_MWHEELUP, 0, true );
+                                       Key_Event( K_MWHEELUP, 0, false );
+                               }
+                               while (i < 0) {
+                                       ++i;
+                                       Key_Event( K_MWHEELDOWN, 0, true );
+                                       Key_Event( K_MWHEELDOWN, 0, false );
+                               }
+                               break;
                        case SDL_JOYBUTTONDOWN:
                        case SDL_JOYBUTTONUP:
                        case SDL_JOYAXISMOTION: