mirror of https://github.com/OpenTTD/OpenTTD.git
(svn r20067) -Add: special modifier (GLOBAL) to mark hotkeys as global hotkeys
This commit is contained in:
parent
4f51623d12
commit
4012f85eec
|
@ -32,7 +32,9 @@ enum WindowKeyCodes {
|
||||||
WKC_ALT = 0x2000,
|
WKC_ALT = 0x2000,
|
||||||
WKC_META = 0x1000,
|
WKC_META = 0x1000,
|
||||||
|
|
||||||
WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META,
|
WKC_GLOBAL_HOTKEY = 0x0800, ///< Fake keycode bit to indicate global hotkeys
|
||||||
|
|
||||||
|
WKC_SPECIAL_KEYS = WKC_SHIFT | WKC_CTRL | WKC_ALT | WKC_META | WKC_GLOBAL_HOTKEY,
|
||||||
|
|
||||||
/* Special ones */
|
/* Special ones */
|
||||||
WKC_NONE = 0,
|
WKC_NONE = 0,
|
||||||
|
|
|
@ -30,6 +30,7 @@ static const KeycodeNames _keycode_to_name[] = {
|
||||||
{"CTRL", WKC_CTRL},
|
{"CTRL", WKC_CTRL},
|
||||||
{"ALT", WKC_ALT},
|
{"ALT", WKC_ALT},
|
||||||
{"META", WKC_META},
|
{"META", WKC_META},
|
||||||
|
{"GLOBAL", WKC_GLOBAL_HOTKEY},
|
||||||
{"ESC", WKC_ESC},
|
{"ESC", WKC_ESC},
|
||||||
{"DEL", WKC_DELETE},
|
{"DEL", WKC_DELETE},
|
||||||
{"RETURN", WKC_RETURN},
|
{"RETURN", WKC_RETURN},
|
||||||
|
|
|
@ -52,7 +52,7 @@ struct Hotkey {
|
||||||
} else {
|
} else {
|
||||||
this->callback = new CallbackWrapper(callback);
|
this->callback = new CallbackWrapper(callback);
|
||||||
}
|
}
|
||||||
if (default_keycode != 0) *this->keycodes.Append() = default_keycode;
|
if (default_keycode != 0) this->AddKeycode(default_keycode);
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -74,7 +74,7 @@ struct Hotkey {
|
||||||
|
|
||||||
const uint16 *keycode = default_keycodes;
|
const uint16 *keycode = default_keycodes;
|
||||||
while (*keycode != 0) {
|
while (*keycode != 0) {
|
||||||
this->keycodes.Include(*keycode);
|
this->AddKeycode(*keycode);
|
||||||
keycode++;
|
keycode++;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -107,13 +107,14 @@ struct Hotkey {
|
||||||
* @param list The list with hotkeys to check
|
* @param list The list with hotkeys to check
|
||||||
* @param keycode The keycode that was pressed
|
* @param keycode The keycode that was pressed
|
||||||
* @param w The window-pointer to give to the callback function (if any).
|
* @param w The window-pointer to give to the callback function (if any).
|
||||||
|
* @param global_only Limit the search to hotkeys defined as 'global'.
|
||||||
* @return The number of the matching hotkey or -1.
|
* @return The number of the matching hotkey or -1.
|
||||||
*/
|
*/
|
||||||
template<class T>
|
template<class T>
|
||||||
int CheckHotkeyMatch(Hotkey<T> *list, uint16 keycode, T *w)
|
int CheckHotkeyMatch(Hotkey<T> *list, uint16 keycode, T *w, bool global_only = false)
|
||||||
{
|
{
|
||||||
while (list->num != -1) {
|
while (list->num != -1) {
|
||||||
if (list->keycodes.Contains(keycode)) {
|
if (list->keycodes.Contains(keycode | WKC_GLOBAL_HOTKEY) || (!global_only && list->keycodes.Contains(keycode))) {
|
||||||
if (list->callback != NULL) (w->*(list->callback->callback))(-1);
|
if (list->callback != NULL) (w->*(list->callback->callback))(-1);
|
||||||
return list->num;
|
return list->num;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue