OpenTTD Source 20241224-master-gf74b0cf984
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
21struct 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
32struct IniFile;
33
37struct 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);
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;
49private:
50 const std::string ini_group;
51 std::vector<Hotkey> items;
52
57 HotkeyList(const HotkeyList &other);
58};
59
60bool IsQuitKey(uint16_t keycode);
61
64
65
66void 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
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.