2010-07-03 13:27:32 +00:00
|
|
|
/*
|
|
|
|
* This file is part of OpenTTD.
|
|
|
|
* 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.
|
|
|
|
* 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.
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
2012-01-01 17:22:32 +00:00
|
|
|
/** @file hotkeys.h %Hotkey related functions. */
|
2010-07-03 13:27:32 +00:00
|
|
|
|
|
|
|
#ifndef HOTKEYS_H
|
|
|
|
#define HOTKEYS_H
|
|
|
|
|
2010-07-03 21:43:44 +00:00
|
|
|
#include "gfx_type.h"
|
2013-06-15 15:31:22 +00:00
|
|
|
#include "window_type.h"
|
2013-08-05 20:36:28 +00:00
|
|
|
#include "string_type.h"
|
2010-07-03 13:27:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* All data for a single hotkey. The name (for saving/loading a configfile),
|
|
|
|
* a list of keycodes and a number to help identifying this hotkey.
|
|
|
|
*/
|
|
|
|
struct Hotkey {
|
2023-05-08 17:01:06 +00:00
|
|
|
Hotkey(uint16_t default_keycode, const std::string &name, int num);
|
|
|
|
Hotkey(const std::vector<uint16_t> &default_keycodes, const std::string &name, int num);
|
2010-07-03 13:27:32 +00:00
|
|
|
|
2023-05-08 17:01:06 +00:00
|
|
|
void AddKeycode(uint16_t keycode);
|
2010-07-03 13:27:32 +00:00
|
|
|
|
2023-06-05 17:12:30 +00:00
|
|
|
const std::string name;
|
2010-07-03 13:27:32 +00:00
|
|
|
int num;
|
2023-05-08 17:01:06 +00:00
|
|
|
std::set<uint16_t> keycodes;
|
2010-07-03 13:27:32 +00:00
|
|
|
};
|
|
|
|
|
2013-06-15 15:28:09 +00:00
|
|
|
struct IniFile;
|
|
|
|
|
|
|
|
/**
|
|
|
|
* List of hotkeys for a window.
|
|
|
|
*/
|
|
|
|
struct HotkeyList {
|
2013-06-15 15:31:22 +00:00
|
|
|
typedef EventState (*GlobalHotkeyHandlerFunc)(int hotkey);
|
|
|
|
|
2023-06-05 17:12:30 +00:00
|
|
|
HotkeyList(const std::string &ini_group, const std::vector<Hotkey> &items, GlobalHotkeyHandlerFunc global_hotkey_handler = nullptr);
|
2013-06-15 15:28:09 +00:00
|
|
|
~HotkeyList();
|
|
|
|
|
2023-10-10 23:38:57 +00:00
|
|
|
void Load(const IniFile &ini);
|
2023-10-10 18:25:56 +00:00
|
|
|
void Save(IniFile &ini) const;
|
2013-06-15 15:28:09 +00:00
|
|
|
|
2023-05-08 17:01:06 +00:00
|
|
|
int CheckMatch(uint16_t keycode, bool global_only = false) const;
|
2013-06-15 15:28:09 +00:00
|
|
|
|
2013-06-15 15:31:22 +00:00
|
|
|
GlobalHotkeyHandlerFunc global_hotkey_handler;
|
2013-06-15 15:28:09 +00:00
|
|
|
private:
|
2023-06-05 17:12:30 +00:00
|
|
|
const std::string ini_group;
|
|
|
|
std::vector<Hotkey> items;
|
2013-06-15 15:28:09 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Dummy private copy constructor to prevent compilers from
|
|
|
|
* copying the structure, which fails due to _hotkey_lists.
|
|
|
|
*/
|
|
|
|
HotkeyList(const HotkeyList &other);
|
|
|
|
};
|
2010-07-03 13:27:32 +00:00
|
|
|
|
2023-05-08 17:01:06 +00:00
|
|
|
bool IsQuitKey(uint16_t keycode);
|
2010-07-04 11:28:16 +00:00
|
|
|
|
2010-07-03 13:28:15 +00:00
|
|
|
void LoadHotkeysFromConfig();
|
|
|
|
void SaveHotkeysToConfig();
|
|
|
|
|
2010-07-03 21:43:44 +00:00
|
|
|
|
2023-05-08 17:01:06 +00:00
|
|
|
void HandleGlobalHotkeys(char32_t key, uint16_t keycode);
|
2010-07-03 21:43:44 +00:00
|
|
|
|
2010-07-03 13:27:32 +00:00
|
|
|
#endif /* HOTKEYS_H */
|