Add hotkeys for other mouse buttons and video drivers

This commit is contained in:
dP
2021-01-27 18:58:51 +03:00
parent 688410e6ce
commit 0cde13b1ca
6 changed files with 88 additions and 11 deletions

View File

@@ -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 */

View File

@@ -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)},
};
/**

View File

@@ -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 */

View File

@@ -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;

View File

@@ -27,7 +27,7 @@
#include <condition_variable>
#include <algorithm>
#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;

View File

@@ -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;