]> git.lizzy.rs Git - dragonfireclient.git/blob - src/client/keycode.h
Decouple entity minimap markers from nametags replacing with show_on_minimap property...
[dragonfireclient.git] / src / client / keycode.h
1 /*
2 Minetest
3 Copyright (C) 2010-2013 celeron55, Perttu Ahola <celeron55@gmail.com>
4
5 This program is free software; you can redistribute it and/or modify
6 it under the terms of the GNU Lesser General Public License as published by
7 the Free Software Foundation; either version 2.1 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU Lesser General Public License for more details.
14
15 You should have received a copy of the GNU Lesser General Public License along
16 with this program; if not, write to the Free Software Foundation, Inc.,
17 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
18 */
19
20 #pragma once
21
22 #include "irrlichttypes.h"
23 #include "Keycodes.h"
24 #include <IEventReceiver.h>
25 #include <string>
26
27 class KeyPress;
28 namespace std
29 {
30         template <> struct hash<KeyPress>;
31 }
32
33 /* A key press, consisting of either an Irrlicht keycode
34    or an actual char */
35
36 class KeyPress
37 {
38 public:
39         friend struct std::hash<KeyPress>;
40
41         KeyPress() = default;
42
43         KeyPress(const char *name);
44
45         KeyPress(const irr::SEvent::SKeyInput &in, bool prefer_character = false);
46
47         bool operator==(const KeyPress &o) const
48         {
49                 return (Char > 0 && Char == o.Char) || (valid_kcode(Key) && Key == o.Key);
50         }
51
52         const char *sym() const;
53         const char *name() const;
54
55 protected:
56         static bool valid_kcode(irr::EKEY_CODE k)
57         {
58                 return k > 0 && k < irr::KEY_KEY_CODES_COUNT;
59         }
60
61         irr::EKEY_CODE Key = irr::KEY_KEY_CODES_COUNT;
62         wchar_t Char = L'\0';
63         std::string m_name = "";
64 };
65
66 namespace std
67 {
68         template <> struct hash<KeyPress>
69         {
70                 size_t operator()(const KeyPress &key) const
71                 {
72                         return key.Key;
73                 }
74         };
75 }
76
77 extern const KeyPress EscapeKey;
78 extern const KeyPress CancelKey;
79
80 // Key configuration getter
81 KeyPress getKeySetting(const char *settingname);
82
83 // Clear fast lookup cache
84 void clearKeyCache();
85
86 irr::EKEY_CODE keyname_to_keycode(const char *name);