From: divverent Date: Fri, 10 Jan 2014 18:53:30 +0000 (+0000) Subject: sdl2: fix mouse wheel X-Git-Tag: xonotic-v0.8.0~86 X-Git-Url: https://git.xonotic.org/?p=xonotic%2Fdarkplaces.git;a=commitdiff_plain;h=ab6c6f89732ae364c4201a57be8e2d6f4fd55824 sdl2: fix mouse wheel git-svn-id: svn://svn.icculus.org/twilight/trunk/darkplaces@12049 d7cf8633-e32d-0410-b094-e92efae38249 ::stable-branch::merge=2420097dc121c3bf40bd0fb63c2c1be182720e62 --- diff --git a/common.h b/common.h index aa0491a2..6e45808e 100644 --- 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 diff --git a/vid_sdl.c b/vid_sdl.c index 11fec735..b090c2bc 100644 --- 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: