OpenTTD Source  20241120-master-g6d3adc6169
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 
63 void SaveHotkeysToConfig();
64 
65 
66 void HandleGlobalHotkeys(char32_t key, uint16_t keycode);
67 
68 #endif /* HOTKEYS_H */
Types related to the graphics and/or input devices.
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Definition: hotkeys.cpp:340
bool IsQuitKey(uint16_t keycode)
Does the given keycode match one of the keycodes bound to 'quit game'?
Definition: main_gui.cpp:534
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
Definition: hotkeys.cpp:346
Types for strings.
List of hotkeys for a window.
Definition: hotkeys.h:37
void Save(IniFile &ini) const
Save HotkeyList to IniFile.
Definition: hotkeys.cpp:294
HotkeyList(const HotkeyList &other)
Dummy private copy constructor to prevent compilers from copying the structure, which fails due to _h...
int CheckMatch(uint16_t keycode, bool global_only=false) const
Check if a keycode is bound to something.
Definition: hotkeys.cpp:309
void Load(const IniFile &ini)
Load HotkeyList from IniFile.
Definition: hotkeys.cpp:277
All data for a single hotkey.
Definition: hotkeys.h:21
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
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
Ini file that supports both loading and saving.
Definition: ini_type.h:88
Types related to windows.
EventState
State of handling an event.
Definition: window_type.h:743