summaryrefslogtreecommitdiff
path: root/core/os
diff options
context:
space:
mode:
authorAaron Franke <arnfranke@yahoo.com>2021-06-20 13:12:33 -0400
committerAaron Franke <arnfranke@yahoo.com>2021-08-10 16:26:55 -0500
commitfa3a32a2d6b054543645b0d4752514c90732b935 (patch)
treef3ba2c2543431c356ba0eca13d5be9a3e42daedd /core/os
parent18bd0fee5a8aa360177cbe14a16d6be69f088d8f (diff)
Use Key enum instead of plain integers
Diffstat (limited to 'core/os')
-rw-r--r--core/os/keyboard.h47
1 files changed, 47 insertions, 0 deletions
diff --git a/core/os/keyboard.h b/core/os/keyboard.h
index 33f9213c4e..52174432d9 100644
--- a/core/os/keyboard.h
+++ b/core/os/keyboard.h
@@ -46,6 +46,7 @@ enum {
};
enum Key {
+ KEY_NONE = 0,
/* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */
KEY_ESCAPE = SPKEY | 0x01,
KEY_TAB = SPKEY | 0x02,
@@ -314,6 +315,52 @@ enum KeyModifierMask {
// bit 31 can't be used because variant uses regular 32 bits int as datatype
};
+// To avoid having unnecessary operators, only define the ones that are needed.
+
+inline Key operator-(uint32_t a, Key b) {
+ return (Key)(a - (uint32_t)b);
+}
+
+inline Key &operator-=(Key &a, int b) {
+ return (Key &)((int &)a -= b);
+}
+
+inline Key operator+(Key a, Key b) {
+ return (Key)((int)a - (int)b);
+}
+
+inline Key &operator|=(Key &a, Key b) {
+ return (Key &)((int &)a |= (int)b);
+}
+
+inline Key &operator|=(Key &a, KeyModifierMask b) {
+ return (Key &)((int &)a |= (int)b);
+}
+
+inline Key operator|(Key a, KeyModifierMask b) {
+ return (Key)((int)a | (int)b);
+}
+
+inline Key operator&(Key a, KeyModifierMask b) {
+ return (Key)((int)a & (int)b);
+}
+
+inline Key operator+(KeyModifierMask a, Key b) {
+ return (Key)((int)a + (int)b);
+}
+
+inline Key operator|(KeyModifierMask a, Key b) {
+ return (Key)((int)a | (int)b);
+}
+
+inline KeyModifierMask operator+(KeyModifierMask a, KeyModifierMask b) {
+ return (KeyModifierMask)((int)a + (int)b);
+}
+
+inline KeyModifierMask operator|(KeyModifierMask a, KeyModifierMask b) {
+ return (KeyModifierMask)((int)a | (int)b);
+}
+
String keycode_get_string(uint32_t p_code);
bool keycode_has_unicode(uint32_t p_keycode);
int find_keycode(const String &p_code);