Changeset View
Changeset View
Standalone View
Standalone View
source/ps/Hotkey.h
Show All 27 Lines | |||||
* When a hotkey is pressed one SDL_HOTKEYPRESS is triggered. While the key is | * When a hotkey is pressed one SDL_HOTKEYPRESS is triggered. While the key is | ||||
* kept down repeated SDL_HOTKEYDOWN events are triggered at an interval | * kept down repeated SDL_HOTKEYDOWN events are triggered at an interval | ||||
* determined by the OS. When a hotkey is released an SDL_HOTKEYUP event is | * determined by the OS. When a hotkey is released an SDL_HOTKEYUP event is | ||||
* triggered. All with the hotkey name stored in ev.user.data1 as a const char*. | * 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 | |||||
// note: we need the real SDL header - it defines SDL_USEREVENT, which is | // Static_asserted to equal the real SDL_Keycode in Hotkey.cpp | ||||
// required for our HOTKEY event type definition. this is OK since | // We do this to avoid including SDL in this header. | ||||
// hotkey.h is not included from any headers. | using SDL_Keycode_ = int; | ||||
const uint SDL_HOTKEYPRESS = SDL_USEREVENT; | // 0x8000 is SDL_USEREVENT, this is static_asserted in Hotkey.cpp | ||||
const uint SDL_HOTKEYDOWN = SDL_USEREVENT + 1; | // We do this to avoid including SDL in this header. | ||||
const uint SDL_HOTKEYUP = SDL_USEREVENT + 2; | const uint SDL_USEREVENT_ = 0x8000; | ||||
const uint SDL_HOTKEYPRESS = SDL_USEREVENT_; | |||||
const uint SDL_HOTKEYDOWN = SDL_USEREVENT_ + 1; | |||||
const uint SDL_HOTKEYUP = SDL_USEREVENT_ + 2; | |||||
struct SKey | |||||
{ | |||||
SDL_Keycode_ code; // keycode or MOUSE_ or UNIFIED_ value | |||||
bool negated; // whether the key must be pressed (false) or unpressed (true) | |||||
}; | |||||
// Hotkey data associated with an externally-specified 'primary' keycode | |||||
struct SHotkeyMapping | |||||
{ | |||||
CStr name; // name of the hotkey | |||||
bool negated; // whether the primary key must be pressed (false) or unpressed (true) | |||||
std::vector<SKey> requires; // list of non-primary keys that must also be active | |||||
}; | |||||
typedef std::vector<SHotkeyMapping> KeyMapping; | |||||
// A mapping of keycodes onto the hotkeys that are associated with that key. | |||||
// (A hotkey triggered by a combination of multiple keys will be in this map | |||||
// multiple times.) | |||||
extern std::map<SDL_Keycode_, KeyMapping> g_HotkeyMap; | |||||
// The current pressed status of hotkeys | |||||
extern std::map<std::string, bool> g_HotkeyStatus; | |||||
Stan: Unordered ? | |||||
extern void LoadHotkeys(); | extern void LoadHotkeys(); | ||||
extern void UnloadHotkeys(); | extern void UnloadHotkeys(); | ||||
Done Inline ActionsCStr ? Unordered? Stan: CStr ? Unordered? | |||||
Done Inline Actionsno hash function for Str but unordered is OK. wraitii: no hash function for Str but unordered is OK. | |||||
Done Inline ActionsJust for posterity. Could also have been vector of pair no? Stan: Just for posterity. Could also have been vector of pair no? | |||||
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
Unordered ?