Changeset View
Changeset View
Standalone View
Standalone View
source/ps/Hotkey.h
/* Copyright (C) 2019 Wildfire Games. | /* Copyright (C) 2020 Wildfire Games. | ||||
* This file is part of 0 A.D. | * This file is part of 0 A.D. | ||||
* | * | ||||
* 0 A.D. is free software: you can redistribute it and/or modify | * 0 A.D. is free software: you can redistribute it and/or modify | ||||
* it under the terms of the GNU General Public License as published by | * it under the terms of the GNU General Public License as published by | ||||
* the Free Software Foundation, either version 2 of the License, or | * the Free Software Foundation, either version 2 of the License, or | ||||
* (at your option) any later version. | * (at your option) any later version. | ||||
* | * | ||||
* 0 A.D. is distributed in the hope that it will be useful, | * 0 A.D. is distributed in the hope that it will be useful, | ||||
Show All 10 Lines | |||||
/** | /** | ||||
* @file | * @file | ||||
* Hotkey system. | * Hotkey system. | ||||
* | * | ||||
* Hotkeys consist of a name (an arbitrary string), and a key mapping. | * Hotkeys consist of a name (an arbitrary string), and a key mapping. | ||||
* The names and mappings are loaded from the config system (any | * The names and mappings are loaded from the config system (any | ||||
* config setting with the name prefix "hotkey."). | * config setting with the name prefix "hotkey."). | ||||
* When a hotkey is pressed or released, SDL_HOTKEYDOWN and SDL_HOTKEYUP | * When a hotkey is pressed one SDL_HOTKEYPRESS is triggered. While the key is | ||||
* events are triggered, with the hotkey name stored in ev.user.data1 | * kept down repeated SDL_HOTKEYDOWN events are triggered at an interval | ||||
wraitii: Perhaps
```
SDL_HOTKEYPRESS is triggered once when the required keys are pushed down. | |||||
* as a const char*. | * determined by the OS. When a hotkey is released an SDL_HOTKEYUP event is | ||||
Not Done Inline ActionsOk (We could also have a HOTKEYDOWN and HOTKEYPRESS event, thoug no benefit right now) elexis: Ok (We could also have a HOTKEYDOWN and HOTKEYPRESS event, thoug no benefit right now) | |||||
Not Done Inline ActionsWell one benefit: we don't need that casting hell below bb: Well one benefit: we don't need that casting hell below | |||||
Not Done Inline ActionsActually found another benefit (and more arguable): main.cpp has some hotkeys too (screenshots, exit etc.) which could use the press event. bb: Actually found another benefit (and more arguable): main.cpp has some hotkeys too (screenshots… | |||||
* triggered. All with the hotkey name stored in ev.user.data1 as a const char*. | |||||
*/ | */ | ||||
#include "CStr.h" | #include "CStr.h" | ||||
#include "lib/input.h" | #include "lib/input.h" | ||||
#include "lib/external_libraries/libsdl.h" // see note below | #include "lib/external_libraries/libsdl.h" // see note below | ||||
// note: we need the real SDL header - it defines SDL_USEREVENT, which is | // note: we need the real SDL header - it defines SDL_USEREVENT, which is | ||||
// required for our HOTKEY event type definition. this is OK since | // required for our HOTKEY event type definition. this is OK since | ||||
// hotkey.h is not included from any headers. | // hotkey.h is not included from any headers. | ||||
const int SDL_HOTKEYDOWN = SDL_USEREVENT; | const uint SDL_HOTKEYPRESS = SDL_USEREVENT; | ||||
const int SDL_HOTKEYUP = SDL_USEREVENT + 1; | const uint SDL_HOTKEYDOWN = SDL_USEREVENT + 1; | ||||
const uint SDL_HOTKEYUP = SDL_USEREVENT + 2; | |||||
Not Done Inline ActionsDo they need to be signed ints ? Stan: Do they need to be signed ints ? | |||||
Done Inline ActionsSDL documentation appears to say: negative bb: SDL documentation appears to say: `negative` | |||||
extern void LoadHotkeys(); | extern void LoadHotkeys(); | ||||
extern void UnloadHotkeys(); | extern void UnloadHotkeys(); | ||||
extern InReaction HotkeyStateChange(const SDL_Event_* ev); | extern InReaction HotkeyStateChange(const SDL_Event_* ev); | ||||
extern InReaction HotkeyInputHandler(const SDL_Event_* ev); | extern InReaction HotkeyInputHandler(const SDL_Event_* ev); | ||||
extern bool HotkeyIsPressed(const CStr& keyname); | extern bool HotkeyIsPressed(const CStr& keyname); | ||||
#endif // INCLUDED_HOTKEY | #endif // INCLUDED_HOTKEY |
Wildfire Games · Phabricator
Perhaps
The working is slightly weird for me as is.