OpenTTD Source: src/hotkeys.h Source File

OpenTTD Source 14.0-RC3

hotkeys.h
Go to the documentation of this file.
1 /*
2 * This file is part of OpenTTD.
3 * OpenTTD is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation, version 2.
4 * OpenTTD is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
5 * See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with OpenTTD. If not, see <http://www.gnu.org/licenses/>.
6 */
7
10 #ifndef HOTKEYS_H
11 #define HOTKEYS_H
12
13 #include "gfx_type.h"
14 #include "window_type.h"
15 #include "string_type.h"
16
21 struct Hotkey {
22 Hotkey(uint16_t default_keycode, const std::string &name, int num);
23 Hotkey(const std::vector<uint16_t> &default_keycodes, const std::string &name, int num);
24
25 void AddKeycode(uint16_t keycode);
26
27 const std::string name;
28 int num;
29 std::set<uint16_t> keycodes;
30 };
31
32 struct IniFile;
33
37 struct HotkeyList {
38 typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
39
40 HotkeyList(const std::string &ini_group, const std::vector<Hotkey> &items, GlobalHotkeyHandlerFunc global_hotkey_handler = nullptr);
41 ~HotkeyList();
42
43 void Load(const IniFile &ini);
44 void Save(IniFile &ini) const;
45
46 int CheckMatch(uint16_t keycode, bool global_only = false) const;
47
48 GlobalHotkeyHandlerFunc global_hotkey_handler;
49 private:
50 const std::string ini_group;
51 std::vector<Hotkey> items;
52
57 HotkeyList(const HotkeyList &other);
58 };
59
60 bool IsQuitKey(uint16_t keycode);
61
62 void LoadHotkeysFromConfig();
63 void SaveHotkeysToConfig();
64
65
66 void HandleGlobalHotkeys(char32_t key, uint16_t keycode);
67
68 #endif /* HOTKEYS_H */
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:37
window_type.h
HotkeyList::Load
void Load(const IniFile &ini)
Load HotkeyList from IniFile.
Definition: hotkeys.cpp:277
string_type.h
IsQuitKey
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition: main_gui.cpp:529
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:88
HotkeyList::CheckMatch
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:309
Hotkey::Hotkey
Hotkey(uint16_t default_keycode, const std::string &name, int num)
Create a new Hotkey object with a single default keycode.
Definition: hotkeys.cpp:229
EventState
EventState
State of handling an event.
Definition: window_type.h:738
LoadHotkeysFromConfig
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Definition: hotkeys.cpp:340
HotkeyList::Save
void Save(IniFile &ini) const
Save HotkeyList to IniFile.
Definition: hotkeys.cpp:294
gfx_type.h
Hotkey::AddKeycode
void AddKeycode(uint16_t keycode)
Add a keycode to this hotkey, from now that keycode will be matched in addition to any previously add...
Definition: hotkeys.cpp:256
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:21
SaveHotkeysToConfig
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
Definition: hotkeys.cpp:346