Pyrogenesis HEAD
Pyrogenesis, a RTS Engine
CHotkeyPicker.h
Go to the documentation of this file.
1/* Copyright (C) 2021 Wildfire Games.
2 * This file is part of 0 A.D.
3 *
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
8 *
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
13 *
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
16 */
17
18#ifndef INCLUDED_CHOTKEYPICKER
19#define INCLUDED_CHOTKEYPICKER
20
21#include "gui/CGUI.h"
24#include "ps/CStr.h"
25
26#include <vector>
27
28/**
29 * When in focus, returns all currently pressed keys.
30 * After a set time without changes, it will trigger a "combination" event.
31 *
32 * Used to create new hotkey combinations in-game. Mostly custom.
33 * This object does not draw anything.
34 */
36{
38
39public:
40 CHotkeyPicker(CGUI& pGUI);
41 virtual ~CHotkeyPicker();
42
43 // Do nothing.
44 virtual void Draw(CCanvas2D& UNUSED(canvas)) {};
45
46 // Checks if the timer has passed and we need to fire a "combination" event.
47 virtual void Tick();
48
49 // React to blur/focus.
50 virtual void HandleMessage(SGUIMessage& Message);
51
52 // Pre-empt events: this is our sole purpose.
53 virtual InReaction PreemptEvent(const SDL_Event_* ev);
54
55 struct Key
56 {
57 // The scancode is used for fast comparisons.
58 SDL_Scancode code;
59 // This is the name ultimately stored in the config file.
61 };
62protected:
63 // Fire an event with m_KeysPressed as argument.
64 void FireEvent(const CStr& event);
65
66 // Time without changes until a "combination" event is sent.
68 // Time of the last registered key change.
70
71 // Keep track of which keys we are pressing, and precompute their name for JS code.
72 std::vector<Key> m_KeysPressed;
73
74 static const CStr EventNameCombination;
75 static const CStr EventNameKeyChange;
76};
77
78#endif // INCLUDED_CHOTKEYPICKER
#define GUI_OBJECT(obj)
Definition: IGUIObject.h:50
Definition: Canvas2D.h:36
The main object that represents a whole GUI page.
Definition: CGUI.h:61
When in focus, returns all currently pressed keys.
Definition: CHotkeyPicker.h:36
virtual void Draw(CCanvas2D &canvas)
Draws the object.
Definition: CHotkeyPicker.h:44
static const CStr EventNameCombination
Definition: CHotkeyPicker.h:74
void FireEvent(const CStr &event)
Definition: CHotkeyPicker.cpp:58
virtual ~CHotkeyPicker()
Definition: CHotkeyPicker.cpp:54
CGUISimpleSetting< float > m_TimeToCombination
Definition: CHotkeyPicker.h:67
virtual void HandleMessage(SGUIMessage &Message)
This function is called with different messages for instance when the mouse enters the object.
Definition: CHotkeyPicker.cpp:83
double m_LastKeyChange
Definition: CHotkeyPicker.h:69
virtual void Tick()
Called on every GUI tick unless the object or one of its parent is hidden/ghost.
Definition: CHotkeyPicker.cpp:69
CHotkeyPicker(CGUI &pGUI)
Definition: CHotkeyPicker.cpp:48
virtual InReaction PreemptEvent(const SDL_Event_ *ev)
Some objects need to be able to pre-emptively process SDL_Event_.
Definition: CHotkeyPicker.cpp:100
std::vector< Key > m_KeysPressed
Definition: CHotkeyPicker.h:72
static const CStr EventNameKeyChange
Definition: CHotkeyPicker.h:75
GUI object such as a button or an input-box.
Definition: IGUIObject.h:60
#define UNUSED(param)
mark a function parameter as unused and avoid the corresponding compiler warning.
Definition: code_annotation.h:40
InReaction
Definition: input.h:35
Definition: CHotkeyPicker.h:56
SDL_Scancode code
Definition: CHotkeyPicker.h:58
CStr scancodeName
Definition: CHotkeyPicker.h:60
Definition: libsdl.h:53
Message send to IGUIObject::HandleMessage() in order to give life to Objects manually with a derived ...
Definition: SGUIMessage.h:68