diff --git a/src/gfx_type.h b/src/gfx_type.h index 339d39d57c..73d8ce3f4b 100644 --- a/src/gfx_type.h +++ b/src/gfx_type.h @@ -113,7 +113,9 @@ enum WindowKeyCodes { WKC_ASTERISK = 161, ///< * Asterisk WKC_DOLLAR = 162, ///< $ Dollar sign - CM_WKC_MOUSE_MIDDLE = 255, ///< CityMania special code for middle mouse button + CM_WKC_MOUSE_MIDDLE = 0x703, ///< CityMania: special code for middle mouse button + CM_WKC_MOUSE_OTHER_START = 0x704, ///< CityMania: start of the numbered buttons (whatever number driver reports), starts as MOUSE_4 hotkey + CM_WKC_MOUSE_OTHER_END = 0x71f, ///< CityMania: 30 buttons should be enough for any mouse, right? ;) }; /** A single sprite of a list of animated cursors */ diff --git a/src/hotkeys.cpp b/src/hotkeys.cpp index 9d79fb5739..298551d559 100644 --- a/src/hotkeys.cpp +++ b/src/hotkeys.cpp @@ -85,7 +85,35 @@ static const KeycodeNames _keycode_to_name[] = { {"R_PAREN", WKC_R_PAREN}, {"EXCLAIM", WKC_EXCLAIM}, {"ASTERISK", WKC_ASTERISK}, + {"MOUSE_MIDDLE", CM_WKC_MOUSE_MIDDLE}, + {"MOUSE_4", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 0)}, + {"MOUSE_5", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 1)}, + {"MOUSE_6", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 2)}, + {"MOUSE_7", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 3)}, + {"MOUSE_8", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 4)}, + {"MOUSE_9", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 5)}, + {"MOUSE_10", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 6)}, + {"MOUSE_11", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 7)}, + {"MOUSE_12", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 8)}, + {"MOUSE_13", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 9)}, + {"MOUSE_14", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 10)}, + {"MOUSE_15", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 11)}, + {"MOUSE_16", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 12)}, + {"MOUSE_17", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 13)}, + {"MOUSE_18", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 14)}, + {"MOUSE_19", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 15)}, + {"MOUSE_20", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 16)}, + {"MOUSE_21", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 17)}, + {"MOUSE_22", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 18)}, + {"MOUSE_23", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 19)}, + {"MOUSE_24", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 20)}, + {"MOUSE_25", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 21)}, + {"MOUSE_26", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 22)}, + {"MOUSE_27", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 23)}, + {"MOUSE_28", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 24)}, + {"MOUSE_29", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 25)}, + {"MOUSE_30", (WindowKeyCodes)(CM_WKC_MOUSE_OTHER_START + 26)}, }; /** diff --git a/src/video/cocoa/event.mm b/src/video/cocoa/event.mm index 193de584c1..5c4f76c9bf 100644 --- a/src/video/cocoa/event.mm +++ b/src/video/cocoa/event.mm @@ -370,7 +370,8 @@ static void QZ_MouseMovedEvent(int x, int y) } -static void QZ_MouseButtonEvent(int button, BOOL down) +static void +QZ_MouseButtonEvent(int button, BOOL down) { switch (button) { case 0: @@ -392,6 +393,18 @@ static void QZ_MouseButtonEvent(int button, BOOL down) } HandleMouseEvents(); break; + + case 2: + HandleKeypress(CM_WKC_MOUSE_MIDDLE, 0); + break; + + default: { + int button = CM_WKC_MOUSE_OTHER_START + ev.button.button - 3; + if (!down && button >= CM_WKC_MOUSE_OTHER_START && button < CM_WKC_MOUSE_OTHER_END) { + HandleKeypress(button, 0); + } + break + } } } @@ -501,11 +514,11 @@ static bool QZ_PollEvent() QZ_MouseButtonEvent(1, NO); break; -#if 0 +// #if 0 CityMania uses this! /* This is not needed since openttd currently only use two buttons */ case NSOtherMouseDown: - pt = QZ_GetMouseLocation(event); - if (!QZ_MouseIsInsideView(&pt)) { + pt = _cocoa_subdriver->GetMouseLocation(event); + if (!_cocoa_subdriver->MouseIsInsideView(&pt)) { [ NSApp sendEvent:event ]; break; } @@ -515,8 +528,8 @@ static bool QZ_PollEvent() break; case NSOtherMouseUp: - pt = QZ_GetMouseLocation(event); - if (!QZ_MouseIsInsideView(&pt)) { + pt = _cocoa_subdriver->GetMouseLocation(event); + if (!_cocoa_subdriver->MouseIsInsideView(&pt)) { [ NSApp sendEvent:event ]; break; } @@ -524,7 +537,7 @@ static bool QZ_PollEvent() QZ_MouseMovedEvent((int)pt.x, (int)pt.y); QZ_MouseButtonEvent([ event buttonNumber ], NO); break; -#endif +// #endif case NSKeyDown: { /* Quit, hide and minimize */ diff --git a/src/video/sdl2_v.cpp b/src/video/sdl2_v.cpp index 64fb51807c..c95e10d16a 100644 --- a/src/video/sdl2_v.cpp +++ b/src/video/sdl2_v.cpp @@ -524,7 +524,7 @@ int VideoDriver_SDL::PollEvent() break; case SDL_MOUSEBUTTONDOWN: - if (_rightclick_emulate && SDL_GetModState() & KMOD_CTRL) { + if (_rightclick_emulate && (SDL_GetModState() & KMOD_CTRL) && ev.button.button == SDL_BUTTON_LEFT) { ev.button.button = SDL_BUTTON_RIGHT; } @@ -547,7 +547,14 @@ int VideoDriver_SDL::PollEvent() if (ev.button.button == SDL_BUTTON_MIDDLE) { HandleKeypress(CM_WKC_MOUSE_MIDDLE, 0); break; + } else if (ev.button.button > SDL_BUTTON_RIGHT) { + int button = CM_WKC_MOUSE_OTHER_START + ev.button.button - 4; + if (button >= CM_WKC_MOUSE_OTHER_START && button < CM_WKC_MOUSE_OTHER_END) { + HandleKeypress(button, 0); + } + break; } + if (_rightclick_emulate) { _right_button_down = false; _left_button_down = false; diff --git a/src/video/sdl_v.cpp b/src/video/sdl_v.cpp index 50ff5ff101..330c477662 100644 --- a/src/video/sdl_v.cpp +++ b/src/video/sdl_v.cpp @@ -27,7 +27,7 @@ #include #include -#include "../../citymania/cm_hotkeys.hpp" +#include "../citymania/cm_hotkeys.hpp" #include "../safeguards.h" @@ -527,7 +527,7 @@ int VideoDriver_SDL::PollEvent() break; case SDL_MOUSEBUTTONDOWN: - if (_rightclick_emulate && SDL_GetModState() & KMOD_CTRL) { + if (_rightclick_emulate && (SDL_GetModState() & KMOD_CTRL) && ev.button.button == SDL_BUTTON_LEFT) { ev.button.button = SDL_BUTTON_RIGHT; } @@ -550,6 +550,17 @@ int VideoDriver_SDL::PollEvent() break; case SDL_MOUSEBUTTONUP: + if (ev.button.button == SDL_BUTTON_MIDDLE) { + HandleKeypress(CM_WKC_MOUSE_MIDDLE, 0); + break; + } else if (ev.button.button > SDL_BUTTON_WHEELDOWN) { + int button = CM_WKC_MOUSE_OTHER_START + ev.button.button - 4; + if (button >= CM_WKC_MOUSE_OTHER_START && button < CM_WKC_MOUSE_OTHER_END) { + HandleKeypress(button, 0); + } + break; + } + if (_rightclick_emulate) { _right_button_down = false; _left_button_down = false; diff --git a/src/video/win32_v.cpp b/src/video/win32_v.cpp index 037dfc6ebc..4d175b4923 100644 --- a/src/video/win32_v.cpp +++ b/src/video/win32_v.cpp @@ -715,6 +715,22 @@ static LRESULT CALLBACK WndProcGdi(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lP HandleMouseEvents(); return 0; + /* CityMania code start */ + case WM_MBUTTONUP: + ReleaseCapture(); + HandleKeypress(CM_WKC_MOUSE_MIDDLE); + return 0; + + case WM_XBUTTONUP: { + ReleaseCapture(); + int button = CM_WKC_MOUSE_OTHER_START + ev.button.button - 1; + if (button >= CM_WKC_MOUSE_OTHER_START && button < CM_WKC_MOUSE_OTHER_END) { + HandleKeypress(button, 0); + } + return 0; + } + /* CityMania code end */ + case WM_MOUSELEAVE: UndrawMouseCursor(); _cursor.in_window = false;