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/>.
10 /** @file hotkeys.h %Hotkey related functions. */
17 #include "core/smallvec_type.hpp"
19 #include "window_type.h"
23 * All data for a single hotkey. The name (for saving/loading a configfile),
24 * a list of keycodes and a number to help identifying this hotkey.
27 const char *const name
; ///< Name of the hotkey in the config file.
28 const int num
; ///< Hotkey identifier in its group.
29 /* We cannot make the default hotkeys an array because not all the
30 * compilers we support allow to statically construct an array. */
31 uint16 default0
; ///< First default keycode for the hotkey.
32 uint16 default1
; ///< First default keycode for the hotkey.
33 uint16 default2
; ///< First default keycode for the hotkey.
34 uint16 default3
; ///< First default keycode for the hotkey.
36 CONSTEXPR
Hotkey (const char *name
, const int num
, uint16 k0
= 0,
37 uint16 k1
= 0, uint16 k2
= 0, uint16 k3
= 0)
38 : name(name
), num(num
),
39 default0(k0
), default1(k1
), default2(k2
), default3(k3
)
48 * List of hotkeys for a window.
52 typedef EventState (*GlobalHotkeyHandlerFunc
)(int hotkey
);
58 CONSTEXPR
Mapping (uint16 keycode
, int value
)
59 : keycode (keycode
), value (value
)
64 std::vector
<Mapping
> mappings
;
65 const char *const ini_group
;
66 const Hotkey
*const descs
;
72 GlobalHotkeyHandlerFunc global_hotkey_handler
;
75 HotkeyList (const char *ini_group
, const Hotkey (&items
) [N
], GlobalHotkeyHandlerFunc global_hotkey_handler
= NULL
)
76 : mappings(), ini_group(ini_group
), descs(items
), ndescs(N
),
77 global_hotkey_handler(global_hotkey_handler
)
84 void Load(IniFile
*ini
);
85 void Save(IniFile
*ini
) const;
87 int CheckMatch(uint16 keycode
, bool global_only
= false) const;
91 * Dummy private copy constructor to prevent compilers from
92 * copying the structure, which fails due to _hotkey_lists.
94 HotkeyList(const HotkeyList
&other
);
96 /** Helper function to push a mapping. */
97 void push_mapping (uint16 keycode
, int value
)
99 this->mappings
.push_back (Mapping (keycode
, value
));
103 bool IsQuitKey(uint16 keycode
);
105 void LoadHotkeysFromConfig();
106 void SaveHotkeysToConfig();
109 void HandleGlobalHotkeys(WChar key
, uint16 keycode
);
111 #endif /* HOTKEYS_H */