From b8ce079829aeec6b8fa1860a6605f26b1b42167c Mon Sep 17 00:00:00 2001 From: iota97 Date: Thu, 5 Mar 2020 15:57:45 +0100 Subject: [PATCH] Fix wheel up/down and additional mouse button --- SDL/SDLMain.cpp | 56 +++++++++++++++++++++++++++++++++++++++++++------ 1 file changed, 50 insertions(+), 6 deletions(-) diff --git a/SDL/SDLMain.cpp b/SDL/SDLMain.cpp index 649fa45c27..f640e66a83 100644 --- a/SDL/SDLMain.cpp +++ b/SDL/SDLMain.cpp @@ -682,10 +682,22 @@ int main(int argc, char *argv[]) { float mouseDeltaX = 0; float mouseDeltaY = 0; + int mouseWheelMovedDir = 0; bool mouseCaptured = false; bool windowHidden = false; while (true) { double startTime = time_now_d(); + + // SDL2 doesn't consider the mousewheel a button anymore + // so let's send the KEY_UP if it was moved last cycle + if (mouseWheelMovedDir != 0) { + KeyInput key; + key.deviceId = DEVICE_ID_MOUSE; + key.keyCode = mouseWheelMovedDir > 0 ? NKCODE_EXT_MOUSEWHEEL_UP : NKCODE_EXT_MOUSEWHEEL_DOWN; + key.flags = KEY_UP; + NativeKey(key); + mouseWheelMovedDir = 0; + } SDL_Event event, touchEvent; while (SDL_PollEvent(&event)) { float mx = event.motion.x * g_dpi_scale_x; @@ -868,6 +880,24 @@ int main(int argc, char *argv[]) { NativeKey(key); } break; + case SDL_BUTTON_MIDDLE: + { + KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_3, KEY_DOWN); + NativeKey(key); + } + break; + case SDL_BUTTON_X1: + { + KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_4, KEY_DOWN); + NativeKey(key); + } + break; + case SDL_BUTTON_X2: + { + KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_5, KEY_DOWN); + NativeKey(key); + } + break; } break; case SDL_MOUSEWHEEL: @@ -876,17 +906,13 @@ int main(int argc, char *argv[]) { key.deviceId = DEVICE_ID_MOUSE; if (event.wheel.y > 0) { key.keyCode = NKCODE_EXT_MOUSEWHEEL_UP; + mouseWheelMovedDir = 1; } else { key.keyCode = NKCODE_EXT_MOUSEWHEEL_DOWN; + mouseWheelMovedDir = -1; } key.flags = KEY_DOWN; NativeKey(key); - - // SDL2 doesn't consider the mousewheel a button anymore - // so let's send the KEY_UP right away. - // Maybe KEY_UP alone will suffice? - key.flags = KEY_UP; - NativeKey(key); } break; case SDL_MOUSEMOTION: @@ -922,6 +948,24 @@ int main(int argc, char *argv[]) { NativeKey(key); } break; + case SDL_BUTTON_MIDDLE: + { + KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_3, KEY_UP); + NativeKey(key); + } + break; + case SDL_BUTTON_X1: + { + KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_4, KEY_UP); + NativeKey(key); + } + break; + case SDL_BUTTON_X2: + { + KeyInput key(DEVICE_ID_MOUSE, NKCODE_EXT_MOUSEBUTTON_5, KEY_UP); + NativeKey(key); + } + break; } break;