OpenTTD
hotkeys.h
Go to the documentation of this file.
1 /* $Id: hotkeys.h 25669 2013-08-05 20:36:28Z michi_cc $ */
2 
3 /*
4  * This file is part of OpenTTD.
5  * 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.
6  * 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.
7  * 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/>.
8  */
9 
12 #ifndef HOTKEYS_H
13 #define HOTKEYS_H
14 
15 #include "core/smallvec_type.hpp"
16 #include "gfx_type.h"
17 #include "window_type.h"
18 #include "string_type.h"
19 
24 struct Hotkey {
25  Hotkey(uint16 default_keycode, const char *name, int num);
26  Hotkey(const uint16 *default_keycodes, const char *name, int num);
27 
28  void AddKeycode(uint16 keycode);
29 
30  const char *name;
31  int num;
32  SmallVector<uint16, 1> keycodes;
33 };
34 
35 #define HOTKEY_LIST_END Hotkey((uint16)0, NULL, -1)
36 
37 struct IniFile;
38 
42 struct HotkeyList {
43  typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
44 
45  HotkeyList(const char *ini_group, Hotkey *items, GlobalHotkeyHandlerFunc global_hotkey_handler = NULL);
46  ~HotkeyList();
47 
48  void Load(IniFile *ini);
49  void Save(IniFile *ini) const;
50 
51  int CheckMatch(uint16 keycode, bool global_only = false) const;
52 
53  GlobalHotkeyHandlerFunc global_hotkey_handler;
54 private:
55  const char *ini_group;
56  Hotkey *items;
57 
62  HotkeyList(const HotkeyList &other);
63 };
64 
65 bool IsQuitKey(uint16 keycode);
66 
68 void SaveHotkeysToConfig();
69 
70 
71 void HandleGlobalHotkeys(WChar key, uint16 keycode);
72 
73 #endif /* HOTKEYS_H */
EventState
State of handling an event.
Definition: window_type.h:701
All data for a single hotkey.
Definition: hotkeys.h:24
Hotkey(uint16 default_keycode, const char *name, int num)
Create a new Hotkey object with a single default keycode.
Definition: hotkeys.cpp:219
Simple vector class that allows allocating an item without the need to copy this->data needlessly...
Types related to windows.
List of hotkeys for a window.
Definition: hotkeys.h:42
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:248
Ini file that supports both loading and saving.
Definition: ini_type.h:88
bool IsQuitKey(uint16 keycode)
Does the given keycode match one of the keycodes bound to &#39;quit game&#39;?
Definition: main_gui.cpp:537
Types for strings.
void LoadHotkeysFromConfig()
Load the hotkeys from the config file.
Definition: hotkeys.cpp:330
void SaveHotkeysToConfig()
Save the hotkeys to the config file.
Definition: hotkeys.cpp:336
uint32 WChar
Type for wide characters, i.e.
Definition: string_type.h:35
Types related to the graphics and/or input devices.