OpenTTD Source: src/hotkeys.h Source File

OpenTTD Source 13.2.1

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 "core/smallvec_type.hpp"
14 #include "gfx_type.h"
15 #include "window_type.h"
16 #include "string_type.h"
17
22 struct Hotkey {
23 Hotkey(uint16 default_keycode, const char *name, int num);
24 Hotkey(const uint16 *default_keycodes, const char *name, int num);
25
26 void AddKeycode(uint16 keycode);
27
28 const char *name;
29 int num;
30 std::vector<uint16> keycodes;
31 };
32
33 #define HOTKEY_LIST_END Hotkey((uint16)0, nullptr, -1)
34
35 struct IniFile;
36
40 struct HotkeyList {
41 typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
42
43 HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler = nullptr);
44 ~HotkeyList();
45
46 void Load(IniFile *ini);
47 void Save(IniFile *ini) const;
48
49 int CheckMatch(uint16 keycode, bool global_only = false) const;
50
51 GlobalHotkeyHandlerFunc global_hotkey_handler;
52 private:
53 const char *ini_group;
54 Hotkey *items;
55
60 HotkeyList(const HotkeyList &other);
61 };
62
63 bool IsQuitKey(uint16 keycode);
64
65 void LoadHotkeysFromConfig();
66 void SaveHotkeysToConfig();
67
68
69 void HandleGlobalHotkeys(WChar key, uint16 keycode);
70
71 #endif /* HOTKEYS_H */
WChar
char32_t WChar
Type for wide characters, i.e.
Definition: string_type.h:36
HotkeyList
List of hotkeys for a window.
Definition: hotkeys.h:40
smallvec_type.hpp
window_type.h
Hotkey::AddKeycode
void AddKeycode(uint16 keycode)
Add a keycode to this hotkey, from now that keycode will be matched in addition to any previously add...
Definition: hotkeys.cpp:273
HotkeyList::Save
void Save(IniFile *ini) const
Save HotkeyList to IniFile.
Definition: hotkeys.cpp:310
HotkeyList::Load
void Load(IniFile *ini)
Load HotkeyList from IniFile.
Definition: hotkeys.cpp:294
string_type.h
IniFile
Ini file that supports both loading and saving.
Definition: ini_type.h:89
IsQuitKey
bool IsQuitKey(uint16 keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition: main_gui.cpp:526
EventState
EventState
State of handling an event.
Definition: window_type.h:719
LoadHotkeysFromConfig
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Definition: hotkeys.cpp:357
Hotkey::Hotkey
Hotkey(uint16 default_keycode, const char *name, int num)
Create a new Hotkey object with a single default keycode.
Definition: hotkeys.cpp:244
HotkeyList::CheckMatch
int CheckMatch(uint16 keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:325
gfx_type.h
Hotkey
All data for a single hotkey.
Definition: hotkeys.h:22
SaveHotkeysToConfig
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
Definition: hotkeys.cpp:363