diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/core_bind.cpp | 8 | ||||
-rw-r--r-- | core/core_bind.h | 6 | ||||
-rw-r--r-- | core/core_constants.cpp | 651 | ||||
-rw-r--r-- | core/input/input.cpp | 180 | ||||
-rw-r--r-- | core/input/input.h | 22 | ||||
-rw-r--r-- | core/input/input_enums.h | 184 | ||||
-rw-r--r-- | core/input/input_event.cpp | 156 | ||||
-rw-r--r-- | core/input/input_event.h | 24 | ||||
-rw-r--r-- | core/input/input_map.cpp | 172 | ||||
-rw-r--r-- | core/io/http_client.cpp | 3 | ||||
-rw-r--r-- | core/io/resource_importer.h | 4 | ||||
-rw-r--r-- | core/math/color.cpp | 96 | ||||
-rw-r--r-- | core/math/color.h | 4 | ||||
-rw-r--r-- | core/math/math_funcs.h | 13 | ||||
-rw-r--r-- | core/math/vector2.cpp | 2 | ||||
-rw-r--r-- | core/object/object.cpp | 7 | ||||
-rw-r--r-- | core/os/keyboard.cpp | 709 | ||||
-rw-r--r-- | core/os/keyboard.h | 539 | ||||
-rw-r--r-- | core/os/midi_driver.cpp | 18 | ||||
-rw-r--r-- | core/string/ustring.cpp | 22 | ||||
-rw-r--r-- | core/variant/binder_common.h | 2 | ||||
-rw-r--r-- | core/variant/variant.h | 17 | ||||
-rw-r--r-- | core/variant/variant_call.cpp | 9 | ||||
-rw-r--r-- | core/variant/variant_utility.cpp | 5 |
24 files changed, 1478 insertions, 1375 deletions
diff --git a/core/core_bind.cpp b/core/core_bind.cpp index b1858c6b32..d42d39a159 100644 --- a/core/core_bind.cpp +++ b/core/core_bind.cpp @@ -502,15 +502,15 @@ String OS::get_system_dir(SystemDir p_dir, bool p_shared_storage) const { return ::OS::get_singleton()->get_system_dir(::OS::SystemDir(p_dir), p_shared_storage); } -String OS::get_keycode_string(uint32_t p_code) const { +String OS::get_keycode_string(Key p_code) const { return ::keycode_get_string(p_code); } -bool OS::is_keycode_unicode(uint32_t p_unicode) const { - return ::keycode_has_unicode(p_unicode); +bool OS::is_keycode_unicode(char32_t p_unicode) const { + return ::keycode_has_unicode((Key)p_unicode); } -int OS::find_keycode_from_string(const String &p_code) const { +Key OS::find_keycode_from_string(const String &p_code) const { return find_keycode(p_code); } diff --git a/core/core_bind.h b/core/core_bind.h index 72865f583c..641e3a33ae 100644 --- a/core/core_bind.h +++ b/core/core_bind.h @@ -195,9 +195,9 @@ public: String get_unique_id() const; - String get_keycode_string(uint32_t p_code) const; - bool is_keycode_unicode(uint32_t p_unicode) const; - int find_keycode_from_string(const String &p_code) const; + String get_keycode_string(Key p_code) const; + bool is_keycode_unicode(char32_t p_unicode) const; + Key find_keycode_from_string(const String &p_code) const; void set_use_file_access_save_and_swap(bool p_enable); diff --git a/core/core_constants.cpp b/core/core_constants.cpp index c04d6ea56e..dd1754f010 100644 --- a/core/core_constants.cpp +++ b/core/core_constants.cpp @@ -71,6 +71,16 @@ static Vector<_CoreConstant> _global_constants; #define BIND_CORE_ENUM_CONSTANT(m_constant) \ _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_constant, #m_constant), #m_constant, m_constant)); +// This just binds enum classes as if they were regular enum constants. +#define BIND_CORE_ENUM_CLASS_CONSTANT(m_enum, m_prefix, m_member) \ + _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_enum::m_member, #m_prefix "_" #m_member), #m_prefix "_" #m_member, (int)m_enum::m_member)); + +#define BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(m_enum, m_name, m_member) \ + _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_enum::m_member, #m_name), #m_name, (int)m_enum::m_member)); + +#define BIND_CORE_ENUM_CLASS_CONSTANT_NO_VAL(m_enum, m_prefix, m_member) \ + _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_enum::m_member, #m_prefix "_" #m_member), #m_prefix "_" #m_member, (int)m_enum::m_member, true)); + #define BIND_CORE_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \ _global_constants.push_back(_CoreConstant(__constant_get_enum_name(m_constant, #m_constant), m_custom_name, m_constant)); @@ -91,6 +101,16 @@ static Vector<_CoreConstant> _global_constants; #define BIND_CORE_ENUM_CONSTANT(m_constant) \ _global_constants.push_back(_CoreConstant(#m_constant, m_constant)); +// This just binds enum classes as if they were regular enum constants. +#define BIND_CORE_ENUM_CLASS_CONSTANT(m_enum, m_prefix, m_member) \ + _global_constants.push_back(_CoreConstant(#m_prefix "_" #m_member, (int)m_enum::m_member)); + +#define BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(m_enum, m_name, m_member) \ + _global_constants.push_back(_CoreConstant(#m_name, (int)m_enum::m_member)); + +#define BIND_CORE_ENUM_CLASS_CONSTANT_NO_VAL(m_enum, m_prefix, m_member) \ + _global_constants.push_back(_CoreConstant(#m_prefix "_" #m_member, (int)m_enum::m_member)); + #define BIND_CORE_ENUM_CONSTANT_CUSTOM(m_custom_name, m_constant) \ _global_constants.push_back(_CoreConstant(m_custom_name, m_constant)); @@ -144,326 +164,317 @@ void register_global_constants() { BIND_CORE_ENUM_CONSTANT(INLINE_ALIGN_CENTER); BIND_CORE_ENUM_CONSTANT(INLINE_ALIGN_BOTTOM); - // huge list of keys - BIND_CORE_CONSTANT(SPKEY); - - BIND_CORE_ENUM_CONSTANT(KEY_ESCAPE); - BIND_CORE_ENUM_CONSTANT(KEY_TAB); - BIND_CORE_ENUM_CONSTANT(KEY_BACKTAB); - BIND_CORE_ENUM_CONSTANT(KEY_BACKSPACE); - BIND_CORE_ENUM_CONSTANT(KEY_ENTER); - BIND_CORE_ENUM_CONSTANT(KEY_KP_ENTER); - BIND_CORE_ENUM_CONSTANT(KEY_INSERT); - BIND_CORE_ENUM_CONSTANT(KEY_DELETE); - BIND_CORE_ENUM_CONSTANT(KEY_PAUSE); - BIND_CORE_ENUM_CONSTANT(KEY_PRINT); - BIND_CORE_ENUM_CONSTANT(KEY_SYSREQ); - BIND_CORE_ENUM_CONSTANT(KEY_CLEAR); - BIND_CORE_ENUM_CONSTANT(KEY_HOME); - BIND_CORE_ENUM_CONSTANT(KEY_END); - BIND_CORE_ENUM_CONSTANT(KEY_LEFT); - BIND_CORE_ENUM_CONSTANT(KEY_UP); - BIND_CORE_ENUM_CONSTANT(KEY_RIGHT); - BIND_CORE_ENUM_CONSTANT(KEY_DOWN); - BIND_CORE_ENUM_CONSTANT(KEY_PAGEUP); - BIND_CORE_ENUM_CONSTANT(KEY_PAGEDOWN); - BIND_CORE_ENUM_CONSTANT(KEY_SHIFT); - BIND_CORE_ENUM_CONSTANT(KEY_CTRL); - BIND_CORE_ENUM_CONSTANT(KEY_META); - BIND_CORE_ENUM_CONSTANT(KEY_ALT); - BIND_CORE_ENUM_CONSTANT(KEY_CAPSLOCK); - BIND_CORE_ENUM_CONSTANT(KEY_NUMLOCK); - BIND_CORE_ENUM_CONSTANT(KEY_SCROLLLOCK); - BIND_CORE_ENUM_CONSTANT(KEY_F1); - BIND_CORE_ENUM_CONSTANT(KEY_F2); - BIND_CORE_ENUM_CONSTANT(KEY_F3); - BIND_CORE_ENUM_CONSTANT(KEY_F4); - BIND_CORE_ENUM_CONSTANT(KEY_F5); - BIND_CORE_ENUM_CONSTANT(KEY_F6); - BIND_CORE_ENUM_CONSTANT(KEY_F7); - BIND_CORE_ENUM_CONSTANT(KEY_F8); - BIND_CORE_ENUM_CONSTANT(KEY_F9); - BIND_CORE_ENUM_CONSTANT(KEY_F10); - BIND_CORE_ENUM_CONSTANT(KEY_F11); - BIND_CORE_ENUM_CONSTANT(KEY_F12); - BIND_CORE_ENUM_CONSTANT(KEY_F13); - BIND_CORE_ENUM_CONSTANT(KEY_F14); - BIND_CORE_ENUM_CONSTANT(KEY_F15); - BIND_CORE_ENUM_CONSTANT(KEY_F16); - BIND_CORE_ENUM_CONSTANT(KEY_KP_MULTIPLY); - BIND_CORE_ENUM_CONSTANT(KEY_KP_DIVIDE); - BIND_CORE_ENUM_CONSTANT(KEY_KP_SUBTRACT); - BIND_CORE_ENUM_CONSTANT(KEY_KP_PERIOD); - BIND_CORE_ENUM_CONSTANT(KEY_KP_ADD); - BIND_CORE_ENUM_CONSTANT(KEY_KP_0); - BIND_CORE_ENUM_CONSTANT(KEY_KP_1); - BIND_CORE_ENUM_CONSTANT(KEY_KP_2); - BIND_CORE_ENUM_CONSTANT(KEY_KP_3); - BIND_CORE_ENUM_CONSTANT(KEY_KP_4); - BIND_CORE_ENUM_CONSTANT(KEY_KP_5); - BIND_CORE_ENUM_CONSTANT(KEY_KP_6); - BIND_CORE_ENUM_CONSTANT(KEY_KP_7); - BIND_CORE_ENUM_CONSTANT(KEY_KP_8); - BIND_CORE_ENUM_CONSTANT(KEY_KP_9); - BIND_CORE_ENUM_CONSTANT(KEY_SUPER_L); - BIND_CORE_ENUM_CONSTANT(KEY_SUPER_R); - BIND_CORE_ENUM_CONSTANT(KEY_MENU); - BIND_CORE_ENUM_CONSTANT(KEY_HYPER_L); - BIND_CORE_ENUM_CONSTANT(KEY_HYPER_R); - BIND_CORE_ENUM_CONSTANT(KEY_HELP); - BIND_CORE_ENUM_CONSTANT(KEY_DIRECTION_L); - BIND_CORE_ENUM_CONSTANT(KEY_DIRECTION_R); - BIND_CORE_ENUM_CONSTANT(KEY_BACK); - BIND_CORE_ENUM_CONSTANT(KEY_FORWARD); - BIND_CORE_ENUM_CONSTANT(KEY_STOP); - BIND_CORE_ENUM_CONSTANT(KEY_REFRESH); - BIND_CORE_ENUM_CONSTANT(KEY_VOLUMEDOWN); - BIND_CORE_ENUM_CONSTANT(KEY_VOLUMEMUTE); - BIND_CORE_ENUM_CONSTANT(KEY_VOLUMEUP); - BIND_CORE_ENUM_CONSTANT(KEY_BASSBOOST); - BIND_CORE_ENUM_CONSTANT(KEY_BASSUP); - BIND_CORE_ENUM_CONSTANT(KEY_BASSDOWN); - BIND_CORE_ENUM_CONSTANT(KEY_TREBLEUP); - BIND_CORE_ENUM_CONSTANT(KEY_TREBLEDOWN); - BIND_CORE_ENUM_CONSTANT(KEY_MEDIAPLAY); - BIND_CORE_ENUM_CONSTANT(KEY_MEDIASTOP); - BIND_CORE_ENUM_CONSTANT(KEY_MEDIAPREVIOUS); - BIND_CORE_ENUM_CONSTANT(KEY_MEDIANEXT); - BIND_CORE_ENUM_CONSTANT(KEY_MEDIARECORD); - BIND_CORE_ENUM_CONSTANT(KEY_HOMEPAGE); - BIND_CORE_ENUM_CONSTANT(KEY_FAVORITES); - BIND_CORE_ENUM_CONSTANT(KEY_SEARCH); - BIND_CORE_ENUM_CONSTANT(KEY_STANDBY); - BIND_CORE_ENUM_CONSTANT(KEY_OPENURL); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHMAIL); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHMEDIA); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH0); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH1); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH2); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH3); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH4); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH5); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH6); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH7); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH8); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCH9); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHA); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHB); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHC); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHD); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHE); - BIND_CORE_ENUM_CONSTANT(KEY_LAUNCHF); - - BIND_CORE_ENUM_CONSTANT(KEY_UNKNOWN); - BIND_CORE_ENUM_CONSTANT(KEY_SPACE); - BIND_CORE_ENUM_CONSTANT(KEY_EXCLAM); - BIND_CORE_ENUM_CONSTANT(KEY_QUOTEDBL); - BIND_CORE_ENUM_CONSTANT(KEY_NUMBERSIGN); - BIND_CORE_ENUM_CONSTANT(KEY_DOLLAR); - BIND_CORE_ENUM_CONSTANT(KEY_PERCENT); - BIND_CORE_ENUM_CONSTANT(KEY_AMPERSAND); - BIND_CORE_ENUM_CONSTANT(KEY_APOSTROPHE); - BIND_CORE_ENUM_CONSTANT(KEY_PARENLEFT); - BIND_CORE_ENUM_CONSTANT(KEY_PARENRIGHT); - BIND_CORE_ENUM_CONSTANT(KEY_ASTERISK); - BIND_CORE_ENUM_CONSTANT(KEY_PLUS); - BIND_CORE_ENUM_CONSTANT(KEY_COMMA); - BIND_CORE_ENUM_CONSTANT(KEY_MINUS); - BIND_CORE_ENUM_CONSTANT(KEY_PERIOD); - BIND_CORE_ENUM_CONSTANT(KEY_SLASH); - BIND_CORE_ENUM_CONSTANT(KEY_0); - BIND_CORE_ENUM_CONSTANT(KEY_1); - BIND_CORE_ENUM_CONSTANT(KEY_2); - BIND_CORE_ENUM_CONSTANT(KEY_3); - BIND_CORE_ENUM_CONSTANT(KEY_4); - BIND_CORE_ENUM_CONSTANT(KEY_5); - BIND_CORE_ENUM_CONSTANT(KEY_6); - BIND_CORE_ENUM_CONSTANT(KEY_7); - BIND_CORE_ENUM_CONSTANT(KEY_8); - BIND_CORE_ENUM_CONSTANT(KEY_9); - BIND_CORE_ENUM_CONSTANT(KEY_COLON); - BIND_CORE_ENUM_CONSTANT(KEY_SEMICOLON); - BIND_CORE_ENUM_CONSTANT(KEY_LESS); - BIND_CORE_ENUM_CONSTANT(KEY_EQUAL); - BIND_CORE_ENUM_CONSTANT(KEY_GREATER); - BIND_CORE_ENUM_CONSTANT(KEY_QUESTION); - BIND_CORE_ENUM_CONSTANT(KEY_AT); - BIND_CORE_ENUM_CONSTANT(KEY_A); - BIND_CORE_ENUM_CONSTANT(KEY_B); - BIND_CORE_ENUM_CONSTANT(KEY_C); - BIND_CORE_ENUM_CONSTANT(KEY_D); - BIND_CORE_ENUM_CONSTANT(KEY_E); - BIND_CORE_ENUM_CONSTANT(KEY_F); - BIND_CORE_ENUM_CONSTANT(KEY_G); - BIND_CORE_ENUM_CONSTANT(KEY_H); - BIND_CORE_ENUM_CONSTANT(KEY_I); - BIND_CORE_ENUM_CONSTANT(KEY_J); - BIND_CORE_ENUM_CONSTANT(KEY_K); - BIND_CORE_ENUM_CONSTANT(KEY_L); - BIND_CORE_ENUM_CONSTANT(KEY_M); - BIND_CORE_ENUM_CONSTANT(KEY_N); - BIND_CORE_ENUM_CONSTANT(KEY_O); - BIND_CORE_ENUM_CONSTANT(KEY_P); - BIND_CORE_ENUM_CONSTANT(KEY_Q); - BIND_CORE_ENUM_CONSTANT(KEY_R); - BIND_CORE_ENUM_CONSTANT(KEY_S); - BIND_CORE_ENUM_CONSTANT(KEY_T); - BIND_CORE_ENUM_CONSTANT(KEY_U); - BIND_CORE_ENUM_CONSTANT(KEY_V); - BIND_CORE_ENUM_CONSTANT(KEY_W); - BIND_CORE_ENUM_CONSTANT(KEY_X); - BIND_CORE_ENUM_CONSTANT(KEY_Y); - BIND_CORE_ENUM_CONSTANT(KEY_Z); - BIND_CORE_ENUM_CONSTANT(KEY_BRACKETLEFT); - BIND_CORE_ENUM_CONSTANT(KEY_BACKSLASH); - BIND_CORE_ENUM_CONSTANT(KEY_BRACKETRIGHT); - BIND_CORE_ENUM_CONSTANT(KEY_ASCIICIRCUM); - BIND_CORE_ENUM_CONSTANT(KEY_UNDERSCORE); - BIND_CORE_ENUM_CONSTANT(KEY_QUOTELEFT); - BIND_CORE_ENUM_CONSTANT(KEY_BRACELEFT); - BIND_CORE_ENUM_CONSTANT(KEY_BAR); - BIND_CORE_ENUM_CONSTANT(KEY_BRACERIGHT); - BIND_CORE_ENUM_CONSTANT(KEY_ASCIITILDE); - BIND_CORE_ENUM_CONSTANT(KEY_NOBREAKSPACE); - BIND_CORE_ENUM_CONSTANT(KEY_EXCLAMDOWN); - BIND_CORE_ENUM_CONSTANT(KEY_CENT); - BIND_CORE_ENUM_CONSTANT(KEY_STERLING); - BIND_CORE_ENUM_CONSTANT(KEY_CURRENCY); - BIND_CORE_ENUM_CONSTANT(KEY_YEN); - BIND_CORE_ENUM_CONSTANT(KEY_BROKENBAR); - BIND_CORE_ENUM_CONSTANT(KEY_SECTION); - BIND_CORE_ENUM_CONSTANT(KEY_DIAERESIS); - BIND_CORE_ENUM_CONSTANT(KEY_COPYRIGHT); - BIND_CORE_ENUM_CONSTANT(KEY_ORDFEMININE); - BIND_CORE_ENUM_CONSTANT(KEY_GUILLEMOTLEFT); - BIND_CORE_ENUM_CONSTANT(KEY_NOTSIGN); - BIND_CORE_ENUM_CONSTANT(KEY_HYPHEN); - BIND_CORE_ENUM_CONSTANT(KEY_REGISTERED); - BIND_CORE_ENUM_CONSTANT(KEY_MACRON); - BIND_CORE_ENUM_CONSTANT(KEY_DEGREE); - BIND_CORE_ENUM_CONSTANT(KEY_PLUSMINUS); - BIND_CORE_ENUM_CONSTANT(KEY_TWOSUPERIOR); - BIND_CORE_ENUM_CONSTANT(KEY_THREESUPERIOR); - BIND_CORE_ENUM_CONSTANT(KEY_ACUTE); - BIND_CORE_ENUM_CONSTANT(KEY_MU); - BIND_CORE_ENUM_CONSTANT(KEY_PARAGRAPH); - BIND_CORE_ENUM_CONSTANT(KEY_PERIODCENTERED); - BIND_CORE_ENUM_CONSTANT(KEY_CEDILLA); - BIND_CORE_ENUM_CONSTANT(KEY_ONESUPERIOR); - BIND_CORE_ENUM_CONSTANT(KEY_MASCULINE); - BIND_CORE_ENUM_CONSTANT(KEY_GUILLEMOTRIGHT); - BIND_CORE_ENUM_CONSTANT(KEY_ONEQUARTER); - BIND_CORE_ENUM_CONSTANT(KEY_ONEHALF); - BIND_CORE_ENUM_CONSTANT(KEY_THREEQUARTERS); - BIND_CORE_ENUM_CONSTANT(KEY_QUESTIONDOWN); - BIND_CORE_ENUM_CONSTANT(KEY_AGRAVE); - BIND_CORE_ENUM_CONSTANT(KEY_AACUTE); - BIND_CORE_ENUM_CONSTANT(KEY_ACIRCUMFLEX); - BIND_CORE_ENUM_CONSTANT(KEY_ATILDE); - BIND_CORE_ENUM_CONSTANT(KEY_ADIAERESIS); - BIND_CORE_ENUM_CONSTANT(KEY_ARING); - BIND_CORE_ENUM_CONSTANT(KEY_AE); - BIND_CORE_ENUM_CONSTANT(KEY_CCEDILLA); - BIND_CORE_ENUM_CONSTANT(KEY_EGRAVE); - BIND_CORE_ENUM_CONSTANT(KEY_EACUTE); - BIND_CORE_ENUM_CONSTANT(KEY_ECIRCUMFLEX); - BIND_CORE_ENUM_CONSTANT(KEY_EDIAERESIS); - BIND_CORE_ENUM_CONSTANT(KEY_IGRAVE); - BIND_CORE_ENUM_CONSTANT(KEY_IACUTE); - BIND_CORE_ENUM_CONSTANT(KEY_ICIRCUMFLEX); - BIND_CORE_ENUM_CONSTANT(KEY_IDIAERESIS); - BIND_CORE_ENUM_CONSTANT(KEY_ETH); - BIND_CORE_ENUM_CONSTANT(KEY_NTILDE); - BIND_CORE_ENUM_CONSTANT(KEY_OGRAVE); - BIND_CORE_ENUM_CONSTANT(KEY_OACUTE); - BIND_CORE_ENUM_CONSTANT(KEY_OCIRCUMFLEX); - BIND_CORE_ENUM_CONSTANT(KEY_OTILDE); - BIND_CORE_ENUM_CONSTANT(KEY_ODIAERESIS); - BIND_CORE_ENUM_CONSTANT(KEY_MULTIPLY); - BIND_CORE_ENUM_CONSTANT(KEY_OOBLIQUE); - BIND_CORE_ENUM_CONSTANT(KEY_UGRAVE); - BIND_CORE_ENUM_CONSTANT(KEY_UACUTE); - BIND_CORE_ENUM_CONSTANT(KEY_UCIRCUMFLEX); - BIND_CORE_ENUM_CONSTANT(KEY_UDIAERESIS); - BIND_CORE_ENUM_CONSTANT(KEY_YACUTE); - BIND_CORE_ENUM_CONSTANT(KEY_THORN); - BIND_CORE_ENUM_CONSTANT(KEY_SSHARP); - - BIND_CORE_ENUM_CONSTANT(KEY_DIVISION); - BIND_CORE_ENUM_CONSTANT(KEY_YDIAERESIS); - - BIND_CORE_ENUM_CONSTANT(KEY_CODE_MASK); - BIND_CORE_ENUM_CONSTANT(KEY_MODIFIER_MASK); - - BIND_CORE_ENUM_CONSTANT(KEY_MASK_SHIFT); - BIND_CORE_ENUM_CONSTANT(KEY_MASK_ALT); - BIND_CORE_ENUM_CONSTANT(KEY_MASK_META); - BIND_CORE_ENUM_CONSTANT(KEY_MASK_CTRL); - BIND_CORE_ENUM_CONSTANT_NO_VAL(KEY_MASK_CMD); - BIND_CORE_ENUM_CONSTANT(KEY_MASK_KPAD); - BIND_CORE_ENUM_CONSTANT(KEY_MASK_GROUP_SWITCH); - - // mouse - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_LEFT); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_RIGHT); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MIDDLE); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_XBUTTON1); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_XBUTTON2); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_UP); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_DOWN); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_LEFT); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_WHEEL_RIGHT); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_LEFT); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_RIGHT); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_MIDDLE); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_XBUTTON1); - BIND_CORE_ENUM_CONSTANT(MOUSE_BUTTON_MASK_XBUTTON2); - - // Joypad buttons - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_INVALID); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_A); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_B); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_X); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_Y); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_BACK); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_GUIDE); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_START); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_LEFT_STICK); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_RIGHT_STICK); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_LEFT_SHOULDER); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_RIGHT_SHOULDER); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_UP); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_DOWN); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_LEFT); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_DPAD_RIGHT); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_MISC1); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_PADDLE1); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_PADDLE2); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_PADDLE3); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_PADDLE4); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_TOUCHPAD); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_SDL_MAX); - BIND_CORE_ENUM_CONSTANT(JOY_BUTTON_MAX); - - // Joypad axes - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_INVALID); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_X); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_LEFT_Y); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_X); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_RIGHT_Y); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_LEFT); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_TRIGGER_RIGHT); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_SDL_MAX); - BIND_CORE_ENUM_CONSTANT(JOY_AXIS_MAX); - - // midi - BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_OFF); - BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_NOTE_ON); - BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_AFTERTOUCH); - BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_CONTROL_CHANGE); - BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_PROGRAM_CHANGE); - BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_CHANNEL_PRESSURE); - BIND_CORE_ENUM_CONSTANT(MIDI_MESSAGE_PITCH_BEND); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SPECIAL); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ESCAPE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TAB); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BACKTAB); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BACKSPACE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ENTER); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_ENTER); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, INSERT); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_DELETE, KEY_DELETE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PAUSE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PRINT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SYSREQ); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CLEAR); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HOME); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, END); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, RIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PAGEUP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PAGEDOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SHIFT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CTRL); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, META); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ALT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CAPSLOCK); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NUMLOCK); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SCROLLLOCK); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F1); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F2); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F3); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F4); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F5); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F6); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F7); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F8); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F9); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F10); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F11); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F12); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F13); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F14); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F15); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F16); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_MULTIPLY); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_DIVIDE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_SUBTRACT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_PERIOD); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_ADD); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_0); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_1); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_2); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_3); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_4); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_5); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_6); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_7); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_8); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, KP_9); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_L); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SUPER_R); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MENU); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_L); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPER_R); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HELP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_L); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIRECTION_R); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BACK); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, FORWARD); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STOP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, REFRESH); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEDOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEMUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, VOLUMEUP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSBOOST); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSUP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BASSDOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEUP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TREBLEDOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPLAY); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIASTOP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIAPREVIOUS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIANEXT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MEDIARECORD); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HOMEPAGE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, FAVORITES); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SEARCH); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STANDBY); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OPENURL); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHMAIL); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHMEDIA); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH0); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH1); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH2); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH3); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH4); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH5); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH6); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH7); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH8); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCH9); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHA); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHB); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHC); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHD); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LAUNCHF); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UNKNOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SPACE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EXCLAM); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, QUOTEDBL); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NUMBERSIGN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DOLLAR); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PERCENT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AMPERSAND); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, APOSTROPHE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PARENLEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PARENRIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ASTERISK); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PLUS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, COMMA); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MINUS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PERIOD); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SLASH); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_0, KEY_0); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_1, KEY_1); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_2, KEY_2); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_3, KEY_3); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_4, KEY_4); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_5, KEY_5); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_6, KEY_6); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_7, KEY_7); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_8, KEY_8); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_9, KEY_9); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, COLON); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SEMICOLON); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, LESS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EQUAL); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GREATER); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, QUESTION); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, A); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, B); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, C); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, D); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, E); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, F); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, G); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, H); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, I); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, J); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, K); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, L); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, M); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, N); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, O); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, P); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, Q); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, R); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, S); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, T); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, U); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, V); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, W); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, X); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, Y); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, Z); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BRACKETLEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BACKSLASH); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BRACKETRIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ASCIICIRCUM); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UNDERSCORE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, QUOTELEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BRACELEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BAR); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BRACERIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ASCIITILDE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOBREAKSPACE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EXCLAMDOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CENT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, STERLING); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CURRENCY); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YEN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, BROKENBAR); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SECTION); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIAERESIS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, COPYRIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ORDFEMININE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTLEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NOTSIGN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, HYPHEN); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(Key, KEY_REGISTERED, KEY_REGISTERED); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MACRON); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DEGREE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PLUSMINUS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, TWOSUPERIOR); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREESUPERIOR); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MU); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PARAGRAPH); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, PERIODCENTERED); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CEDILLA); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONESUPERIOR); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MASCULINE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, GUILLEMOTRIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEQUARTER); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ONEHALF); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THREEQUARTERS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, QUESTIONDOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AGRAVE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AACUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ACIRCUMFLEX); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ATILDE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ADIAERESIS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ARING); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, AE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, CCEDILLA); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EGRAVE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EACUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ECIRCUMFLEX); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, EDIAERESIS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IGRAVE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IACUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ICIRCUMFLEX); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, IDIAERESIS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ETH); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, NTILDE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OGRAVE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OACUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OCIRCUMFLEX); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OTILDE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, ODIAERESIS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, MULTIPLY); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, OOBLIQUE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UGRAVE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UACUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UCIRCUMFLEX); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, UDIAERESIS); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YACUTE); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, THORN); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, SSHARP); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, DIVISION); + BIND_CORE_ENUM_CLASS_CONSTANT(Key, KEY, YDIAERESIS); + + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(KeyModifierMask, KEY_CODE_MASK, CODE_MASK); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(KeyModifierMask, KEY_MODIFIER_MASK, MODIFIER_MASK); + BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, SHIFT); + BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, ALT); + BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, META); + BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, CTRL); + BIND_CORE_ENUM_CLASS_CONSTANT_NO_VAL(KeyModifierMask, KEY_MASK, CMD); + BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, KPAD); + BIND_CORE_ENUM_CLASS_CONSTANT(KeyModifierMask, KEY_MASK, GROUP_SWITCH); + + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, LEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, RIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, MIDDLE); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, WHEEL_UP); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, WHEEL_DOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, WHEEL_LEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, WHEEL_RIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(MouseButton, MOUSE_BUTTON_XBUTTON1, MB_XBUTTON1); + BIND_CORE_ENUM_CLASS_CONSTANT_CUSTOM(MouseButton, MOUSE_BUTTON_XBUTTON2, MB_XBUTTON2); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, MASK_LEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, MASK_RIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, MASK_MIDDLE); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, MASK_XBUTTON1); + BIND_CORE_ENUM_CLASS_CONSTANT(MouseButton, MOUSE_BUTTON, MASK_XBUTTON2); + + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, INVALID); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, A); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, B); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, X); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, Y); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, BACK); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, GUIDE); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, START); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, LEFT_STICK); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, RIGHT_STICK); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, LEFT_SHOULDER); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, RIGHT_SHOULDER); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, DPAD_UP); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, DPAD_DOWN); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, DPAD_LEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, DPAD_RIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, MISC1); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, PADDLE1); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, PADDLE2); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, PADDLE3); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, PADDLE4); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, TOUCHPAD); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, SDL_MAX); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyButton, JOY_BUTTON, MAX); + + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, INVALID); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, LEFT_X); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, LEFT_Y); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, RIGHT_X); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, RIGHT_Y); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, TRIGGER_LEFT); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, TRIGGER_RIGHT); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, SDL_MAX); + BIND_CORE_ENUM_CLASS_CONSTANT(JoyAxis, JOY_AXIS, MAX); + + BIND_CORE_ENUM_CLASS_CONSTANT(MIDIMessage, MIDI_MESSAGE, NOTE_OFF); + BIND_CORE_ENUM_CLASS_CONSTANT(MIDIMessage, MIDI_MESSAGE, NOTE_ON); + BIND_CORE_ENUM_CLASS_CONSTANT(MIDIMessage, MIDI_MESSAGE, AFTERTOUCH); + BIND_CORE_ENUM_CLASS_CONSTANT(MIDIMessage, MIDI_MESSAGE, CONTROL_CHANGE); + BIND_CORE_ENUM_CLASS_CONSTANT(MIDIMessage, MIDI_MESSAGE, PROGRAM_CHANGE); + BIND_CORE_ENUM_CLASS_CONSTANT(MIDIMessage, MIDI_MESSAGE, CHANNEL_PRESSURE); + BIND_CORE_ENUM_CLASS_CONSTANT(MIDIMessage, MIDI_MESSAGE, PITCH_BEND); // error list diff --git a/core/input/input.cpp b/core/input/input.cpp index 35ca8aefe6..4b5a84f401 100644 --- a/core/input/input.cpp +++ b/core/input/input.cpp @@ -35,7 +35,7 @@ #include "core/input/input_map.h" #include "core/os/os.h" -static const char *_joy_buttons[JOY_BUTTON_SDL_MAX] = { +static const char *_joy_buttons[(size_t)JoyButton::SDL_MAX] = { "a", "b", "x", @@ -59,7 +59,7 @@ static const char *_joy_buttons[JOY_BUTTON_SDL_MAX] = { "touchpad", }; -static const char *_joy_axes[JOY_AXIS_SDL_MAX] = { +static const char *_joy_axes[(size_t)JoyAxis::SDL_MAX] = { "leftx", "lefty", "rightx", @@ -225,11 +225,15 @@ bool Input::is_key_pressed(Key p_keycode) const { bool Input::is_mouse_button_pressed(MouseButton p_button) const { _THREAD_SAFE_METHOD_ - return (mouse_button_mask & (1 << (p_button - 1))) != 0; + return (mouse_button_mask & mouse_button_to_mask(p_button)) != MouseButton::NONE; } -static int _combine_device(int p_value, int p_device) { - return p_value | (p_device << 20); +static JoyAxis _combine_device(JoyAxis p_value, int p_device) { + return JoyAxis((int)p_value | (p_device << 20)); +} + +static JoyButton _combine_device(JoyButton p_value, int p_device) { + return JoyButton((int)p_value | (p_device << 20)); } bool Input::is_joy_button_pressed(int p_device, JoyButton p_button) const { @@ -338,7 +342,7 @@ Vector2 Input::get_vector(const StringName &p_negative_x, const StringName &p_po float Input::get_joy_axis(int p_device, JoyAxis p_axis) const { _THREAD_SAFE_METHOD_ - int c = _combine_device(p_axis, p_device); + JoyAxis c = _combine_device(p_axis, p_device); if (_joy_axis.has(c)) { return _joy_axis[c]; } else { @@ -412,11 +416,11 @@ void Input::joy_connection_changed(int p_idx, bool p_connected, String p_name, S js.mapping = mapping; } else { js.connected = false; - for (int i = 0; i < JOY_BUTTON_MAX; i++) { - int c = _combine_device(i, p_idx); + for (int i = 0; i < (int)JoyButton::MAX; i++) { + JoyButton c = _combine_device((JoyButton)i, p_idx); joy_buttons_pressed.erase(c); } - for (int i = 0; i < JOY_AXIS_MAX; i++) { + for (int i = 0; i < (int)JoyAxis::MAX; i++) { set_joy_axis(p_idx, (JoyAxis)i, 0.0f); } } @@ -454,7 +458,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em // require additional handling by this class. Ref<InputEventKey> k = p_event; - if (k.is_valid() && !k->is_echo() && k->get_keycode() != 0) { + if (k.is_valid() && !k->is_echo() && k->get_keycode() != Key::NONE) { if (k->is_pressed()) { keys_pressed.insert(k->get_keycode()); } else { @@ -466,9 +470,9 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em if (mb.is_valid()) { if (mb->is_pressed()) { - mouse_button_mask |= (MouseButton)(1 << (mb->get_button_index() - 1)); + mouse_button_mask |= mouse_button_to_mask(mb->get_button_index()); } else { - mouse_button_mask &= (MouseButton) ~(1 << (mb->get_button_index() - 1)); + mouse_button_mask &= ~mouse_button_to_mask(mb->get_button_index()); } Point2 pos = mb->get_global_position(); @@ -476,7 +480,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em set_mouse_position(pos); } - if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == 1) { + if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mb->get_button_index() == MouseButton::LEFT) { Ref<InputEventScreenTouch> touch_event; touch_event.instantiate(); touch_event->set_pressed(mb->is_pressed()); @@ -493,7 +497,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em set_mouse_position(pos); } - if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && mm->get_button_mask() & 1) { + if (event_dispatch_function && emulate_touch_from_mouse && !p_is_emulated && (mm->get_button_mask() & MouseButton::LEFT) != MouseButton::NONE) { Ref<InputEventScreenDrag> drag_event; drag_event.instantiate(); @@ -539,11 +543,11 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em button_event->set_position(st->get_position()); button_event->set_global_position(st->get_position()); button_event->set_pressed(st->is_pressed()); - button_event->set_button_index(MOUSE_BUTTON_LEFT); + button_event->set_button_index(MouseButton::LEFT); if (st->is_pressed()) { - button_event->set_button_mask(MouseButton(mouse_button_mask | MOUSE_BUTTON_MASK_LEFT)); + button_event->set_button_mask(MouseButton(mouse_button_mask | MouseButton::MASK_LEFT)); } else { - button_event->set_button_mask(MouseButton(mouse_button_mask & ~MOUSE_BUTTON_MASK_LEFT)); + button_event->set_button_mask(MouseButton(mouse_button_mask & ~MouseButton::MASK_LEFT)); } _parse_input_event_impl(button_event, true); @@ -576,7 +580,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em Ref<InputEventJoypadButton> jb = p_event; if (jb.is_valid()) { - int c = _combine_device(jb->get_button_index(), jb->get_device()); + JoyButton c = _combine_device(jb->get_button_index(), jb->get_device()); if (jb->is_pressed()) { joy_buttons_pressed.insert(c); @@ -624,7 +628,7 @@ void Input::_parse_input_event_impl(const Ref<InputEvent> &p_event, bool p_is_em void Input::set_joy_axis(int p_device, JoyAxis p_axis, float p_value) { _THREAD_SAFE_METHOD_ - int c = _combine_device(p_axis, p_device); + JoyAxis c = _combine_device(p_axis, p_device); _joy_axis[c] = p_value; } @@ -692,7 +696,7 @@ Point2 Input::get_last_mouse_speed() const { return mouse_speed_track.speed; } -int Input::get_mouse_button_mask() const { +MouseButton Input::get_mouse_button_mask() const { return mouse_button_mask; // do not trust OS implementation, should remove it - OS::get_singleton()->get_mouse_button_state(); } @@ -771,8 +775,8 @@ void Input::ensure_touch_mouse_raised() { button_event->set_position(mouse_pos); button_event->set_global_position(mouse_pos); button_event->set_pressed(false); - button_event->set_button_index(MOUSE_BUTTON_LEFT); - button_event->set_button_mask(MouseButton(mouse_button_mask & ~MOUSE_BUTTON_MASK_LEFT)); + button_event->set_button_index(MouseButton::LEFT); + button_event->set_button_mask(MouseButton(mouse_button_mask & ~MouseButton::MASK_LEFT)); _parse_input_event_impl(button_event, true); } @@ -876,10 +880,10 @@ void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) { _THREAD_SAFE_METHOD_; Joypad &joy = joy_names[p_device]; //printf("got button %i, mapping is %i\n", p_button, joy.mapping); - if (joy.last_buttons[p_button] == p_pressed) { + if (joy.last_buttons[(size_t)p_button] == p_pressed) { return; } - joy.last_buttons[p_button] = p_pressed; + joy.last_buttons[(size_t)p_button] = p_pressed; if (joy.mapping == -1) { _button_event(p_device, p_button, p_pressed); return; @@ -901,16 +905,16 @@ void Input::joy_button(int p_device, JoyButton p_button, bool p_pressed) { void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value) { _THREAD_SAFE_METHOD_; - ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); + ERR_FAIL_INDEX((int)p_axis, (int)JoyAxis::MAX); Joypad &joy = joy_names[p_device]; - if (joy.last_axis[p_axis] == p_value.value) { + if (joy.last_axis[(size_t)p_axis] == p_value.value) { return; } //when changing direction quickly, insert fake event to release pending inputmap actions - float last = joy.last_axis[p_axis]; + float last = joy.last_axis[(size_t)p_axis]; if (p_value.min == 0 && (last < 0.25 || last > 0.75) && (last - 0.5) * (p_value.value - 0.5) < 0) { JoyAxisValue jx; jx.min = p_value.min; @@ -923,7 +927,7 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value) joy_axis(p_device, p_axis, jx); } - joy.last_axis[p_axis] = p_value.value; + joy.last_axis[(size_t)p_axis] = p_value.value; float val = p_value.min == 0 ? -1.0f + 2.0f * p_value.value : p_value.value; if (joy.mapping == -1) { @@ -935,32 +939,32 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value) if (map.type == TYPE_BUTTON) { bool pressed = map.value > 0.5; - if (pressed == joy_buttons_pressed.has(_combine_device(map.index, p_device))) { + if (pressed == joy_buttons_pressed.has(_combine_device((JoyButton)map.index, p_device))) { // Button already pressed or released; so ignore. return; } _button_event(p_device, (JoyButton)map.index, pressed); // Ensure opposite D-Pad button is also released. - switch (map.index) { - case JOY_BUTTON_DPAD_UP: - if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_DOWN, p_device))) { - _button_event(p_device, JOY_BUTTON_DPAD_DOWN, false); + switch ((JoyButton)map.index) { + case JoyButton::DPAD_UP: + if (joy_buttons_pressed.has(_combine_device(JoyButton::DPAD_DOWN, p_device))) { + _button_event(p_device, JoyButton::DPAD_DOWN, false); } break; - case JOY_BUTTON_DPAD_DOWN: - if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_UP, p_device))) { - _button_event(p_device, JOY_BUTTON_DPAD_UP, false); + case JoyButton::DPAD_DOWN: + if (joy_buttons_pressed.has(_combine_device(JoyButton::DPAD_UP, p_device))) { + _button_event(p_device, JoyButton::DPAD_UP, false); } break; - case JOY_BUTTON_DPAD_LEFT: - if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_RIGHT, p_device))) { - _button_event(p_device, JOY_BUTTON_DPAD_RIGHT, false); + case JoyButton::DPAD_LEFT: + if (joy_buttons_pressed.has(_combine_device(JoyButton::DPAD_RIGHT, p_device))) { + _button_event(p_device, JoyButton::DPAD_RIGHT, false); } break; - case JOY_BUTTON_DPAD_RIGHT: - if (joy_buttons_pressed.has(_combine_device(JOY_BUTTON_DPAD_LEFT, p_device))) { - _button_event(p_device, JOY_BUTTON_DPAD_LEFT, false); + case JoyButton::DPAD_RIGHT: + if (joy_buttons_pressed.has(_combine_device(JoyButton::DPAD_LEFT, p_device))) { + _button_event(p_device, JoyButton::DPAD_LEFT, false); } break; default: @@ -977,27 +981,27 @@ void Input::joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value) //printf("invalid mapping\n"); } -void Input::joy_hat(int p_device, int p_val) { +void Input::joy_hat(int p_device, HatMask p_val) { _THREAD_SAFE_METHOD_; const Joypad &joy = joy_names[p_device]; - JoyEvent map[HAT_MAX]; + JoyEvent map[(size_t)HatDir::MAX]; - map[HatDir::HAT_UP].type = TYPE_BUTTON; - map[HatDir::HAT_UP].index = JOY_BUTTON_DPAD_UP; - map[HatDir::HAT_UP].value = 0; + map[(size_t)HatDir::UP].type = TYPE_BUTTON; + map[(size_t)HatDir::UP].index = (int)JoyButton::DPAD_UP; + map[(size_t)HatDir::UP].value = 0; - map[HatDir::HAT_RIGHT].type = TYPE_BUTTON; - map[HatDir::HAT_RIGHT].index = JOY_BUTTON_DPAD_RIGHT; - map[HatDir::HAT_RIGHT].value = 0; + map[(size_t)HatDir::RIGHT].type = TYPE_BUTTON; + map[(size_t)HatDir::RIGHT].index = (int)JoyButton::DPAD_RIGHT; + map[(size_t)HatDir::RIGHT].value = 0; - map[HatDir::HAT_DOWN].type = TYPE_BUTTON; - map[HatDir::HAT_DOWN].index = JOY_BUTTON_DPAD_DOWN; - map[HatDir::HAT_DOWN].value = 0; + map[(size_t)HatDir::DOWN].type = TYPE_BUTTON; + map[(size_t)HatDir::DOWN].index = (int)JoyButton::DPAD_DOWN; + map[(size_t)HatDir::DOWN].value = 0; - map[HatDir::HAT_LEFT].type = TYPE_BUTTON; - map[HatDir::HAT_LEFT].index = JOY_BUTTON_DPAD_LEFT; - map[HatDir::HAT_LEFT].value = 0; + map[(size_t)HatDir::LEFT].type = TYPE_BUTTON; + map[(size_t)HatDir::LEFT].index = (int)JoyButton::DPAD_LEFT; + map[(size_t)HatDir::LEFT].value = 0; if (joy.mapping != -1) { _get_mapped_hat_events(map_db[joy.mapping], (HatDir)0, map); @@ -1005,18 +1009,18 @@ void Input::joy_hat(int p_device, int p_val) { int cur_val = joy_names[p_device].hat_current; - for (int hat_direction = 0, hat_mask = 1; hat_direction < HAT_MAX; hat_direction++, hat_mask <<= 1) { - if ((p_val & hat_mask) != (cur_val & hat_mask)) { + for (int hat_direction = 0, hat_mask = 1; hat_direction < (int)HatDir::MAX; hat_direction++, hat_mask <<= 1) { + if (((int)p_val & hat_mask) != (cur_val & hat_mask)) { if (map[hat_direction].type == TYPE_BUTTON) { - _button_event(p_device, (JoyButton)map[hat_direction].index, p_val & hat_mask); + _button_event(p_device, (JoyButton)map[hat_direction].index, (int)p_val & hat_mask); } if (map[hat_direction].type == TYPE_AXIS) { - _axis_event(p_device, (JoyAxis)map[hat_direction].index, (p_val & hat_mask) ? map[hat_direction].value : 0.0); + _axis_event(p_device, (JoyAxis)map[hat_direction].index, ((int)p_val & hat_mask) ? map[hat_direction].value : 0.0); } } } - joy_names[p_device].hat_current = p_val; + joy_names[p_device].hat_current = (int)p_val; } void Input::_button_event(int p_device, JoyButton p_index, bool p_pressed) { @@ -1049,10 +1053,10 @@ Input::JoyEvent Input::_get_mapped_button_event(const JoyDeviceMapping &mapping, event.type = binding.outputType; switch (binding.outputType) { case TYPE_BUTTON: - event.index = binding.output.button; + event.index = (int)binding.output.button; return event; case TYPE_AXIS: - event.index = binding.output.axis.axis; + event.index = (int)binding.output.axis.axis; switch (binding.output.axis.range) { case POSITIVE_HALF_AXIS: event.value = 1; @@ -1104,7 +1108,7 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, J } switch (binding.outputType) { case TYPE_BUTTON: - event.index = binding.output.button; + event.index = (int)binding.output.button; switch (binding.input.axis.range) { case POSITIVE_HALF_AXIS: event.value = shifted_positive_value; @@ -1121,7 +1125,7 @@ Input::JoyEvent Input::_get_mapped_axis_event(const JoyDeviceMapping &mapping, J } return event; case TYPE_AXIS: - event.index = binding.output.axis.axis; + event.index = (int)binding.output.axis.axis; event.value = value; if (binding.output.axis.range != binding.input.axis.range) { switch (binding.output.axis.range) { @@ -1150,43 +1154,43 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat for (int i = 0; i < mapping.bindings.size(); i++) { const JoyBinding binding = mapping.bindings[i]; if (binding.inputType == TYPE_HAT && binding.input.hat.hat == p_hat) { - int hat_direction; + HatDir hat_direction; switch (binding.input.hat.hat_mask) { - case HatMask::HAT_MASK_UP: - hat_direction = HatDir::HAT_UP; + case HatMask::UP: + hat_direction = HatDir::UP; break; - case HatMask::HAT_MASK_RIGHT: - hat_direction = HatDir::HAT_RIGHT; + case HatMask::RIGHT: + hat_direction = HatDir::RIGHT; break; - case HatMask::HAT_MASK_DOWN: - hat_direction = HatDir::HAT_DOWN; + case HatMask::DOWN: + hat_direction = HatDir::DOWN; break; - case HatMask::HAT_MASK_LEFT: - hat_direction = HatDir::HAT_LEFT; + case HatMask::LEFT: + hat_direction = HatDir::LEFT; break; default: ERR_PRINT_ONCE("Joypad button mapping error."); continue; } - r_events[hat_direction].type = binding.outputType; + r_events[(size_t)hat_direction].type = binding.outputType; switch (binding.outputType) { case TYPE_BUTTON: - r_events[hat_direction].index = binding.output.button; + r_events[(size_t)hat_direction].index = (int)binding.output.button; break; case TYPE_AXIS: - r_events[hat_direction].index = binding.output.axis.axis; + r_events[(size_t)hat_direction].index = (int)binding.output.axis.axis; switch (binding.output.axis.range) { case POSITIVE_HALF_AXIS: - r_events[hat_direction].value = 1; + r_events[(size_t)hat_direction].value = 1; break; case NEGATIVE_HALF_AXIS: - r_events[hat_direction].value = -1; + r_events[(size_t)hat_direction].value = -1; break; case FULL_AXIS: // It doesn't make sense for a hat direction to map to a full axis, // but keeping as a default for a trigger with a positive half-axis. - r_events[hat_direction].value = 1; + r_events[(size_t)hat_direction].value = 1; break; } break; @@ -1198,21 +1202,21 @@ void Input::_get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat } JoyButton Input::_get_output_button(String output) { - for (int i = 0; i < JOY_BUTTON_SDL_MAX; i++) { + for (int i = 0; i < (int)JoyButton::SDL_MAX; i++) { if (output == _joy_buttons[i]) { return JoyButton(i); } } - return JoyButton::JOY_BUTTON_INVALID; + return JoyButton::INVALID; } JoyAxis Input::_get_output_axis(String output) { - for (int i = 0; i < JOY_AXIS_SDL_MAX; i++) { + for (int i = 0; i < (int)JoyAxis::SDL_MAX; i++) { if (output == _joy_axes[i]) { return JoyAxis(i); } } - return JoyAxis::JOY_AXIS_INVALID; + return JoyAxis::INVALID; } void Input::parse_mapping(String p_mapping) { @@ -1273,16 +1277,16 @@ void Input::parse_mapping(String p_mapping) { JoyButton output_button = _get_output_button(output); JoyAxis output_axis = _get_output_axis(output); - ERR_CONTINUE_MSG(output_button == JOY_BUTTON_INVALID && output_axis == JOY_AXIS_INVALID, + ERR_CONTINUE_MSG(output_button == JoyButton::INVALID && output_axis == JoyAxis::INVALID, vformat("Unrecognised output string \"%s\" in mapping:\n%s", output, p_mapping)); - ERR_CONTINUE_MSG(output_button != JOY_BUTTON_INVALID && output_axis != JOY_AXIS_INVALID, + ERR_CONTINUE_MSG(output_button != JoyButton::INVALID && output_axis != JoyAxis::INVALID, vformat("Output string \"%s\" matched both button and axis in mapping:\n%s", output, p_mapping)); JoyBinding binding; - if (output_button != JOY_BUTTON_INVALID) { + if (output_button != JoyButton::INVALID) { binding.outputType = TYPE_BUTTON; binding.output.button = output_button; - } else if (output_axis != JOY_AXIS_INVALID) { + } else if (output_axis != JoyAxis::INVALID) { binding.outputType = TYPE_AXIS; binding.output.axis.axis = output_axis; binding.output.axis.range = output_range; diff --git a/core/input/input.h b/core/input/input.h index f63138a875..dd57ebb563 100644 --- a/core/input/input.h +++ b/core/input/input.h @@ -85,11 +85,11 @@ public: typedef void (*EventDispatchFunc)(const Ref<InputEvent> &p_event); private: - int mouse_button_mask = 0; + MouseButton mouse_button_mask = MouseButton::NONE; - Set<int> keys_pressed; - Set<int> joy_buttons_pressed; - Map<int, float> _joy_axis; + Set<Key> keys_pressed; + Set<JoyButton> joy_buttons_pressed; + Map<JoyAxis, float> _joy_axis; //Map<StringName,int> custom_action_press; Vector3 gravity; Vector3 accelerometer; @@ -133,9 +133,9 @@ private: StringName name; StringName uid; bool connected = false; - bool last_buttons[JOY_BUTTON_MAX] = { false }; - float last_axis[JOY_AXIS_MAX] = { 0.0f }; - int last_hat = HatMask::HAT_MASK_CENTER; + bool last_buttons[(size_t)JoyButton::MAX] = { false }; + float last_axis[(size_t)JoyAxis::MAX] = { 0.0f }; + HatMask last_hat = HatMask::CENTER; int mapping = -1; int hat_current = 0; }; @@ -162,7 +162,7 @@ private: struct JoyEvent { int type; - int index; + int index; // Can be either JoyAxis or JoyButton. float value; }; @@ -206,7 +206,7 @@ private: JoyEvent _get_mapped_button_event(const JoyDeviceMapping &mapping, JoyButton p_button); JoyEvent _get_mapped_axis_event(const JoyDeviceMapping &mapping, JoyAxis p_axis, float p_value); - void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[HAT_MAX]); + void _get_mapped_hat_events(const JoyDeviceMapping &mapping, HatDir p_hat, JoyEvent r_events[(size_t)HatDir::MAX]); JoyButton _get_output_button(String output); JoyAxis _get_output_axis(String output); void _button_event(int p_device, JoyButton p_index, bool p_pressed); @@ -273,7 +273,7 @@ public: Point2 get_mouse_position() const; Point2 get_last_mouse_speed() const; - int get_mouse_button_mask() const; + MouseButton get_mouse_button_mask() const; void warp_mouse_position(const Vector2 &p_to); Point2i warp_mouse_motion(const Ref<InputEventMouseMotion> &p_motion, const Rect2 &p_rect); @@ -312,7 +312,7 @@ public: void parse_mapping(String p_mapping); void joy_button(int p_device, JoyButton p_button, bool p_pressed); void joy_axis(int p_device, JoyAxis p_axis, const JoyAxisValue &p_value); - void joy_hat(int p_device, int p_val); + void joy_hat(int p_device, HatMask p_val); void add_joy_mapping(String p_mapping, bool p_update_existing = false); void remove_joy_mapping(String p_guid); diff --git a/core/input/input_enums.h b/core/input/input_enums.h index 4479a85bfe..8601007ac9 100644 --- a/core/input/input_enums.h +++ b/core/input/input_enums.h @@ -31,90 +31,106 @@ #ifndef INPUT_ENUMS_H #define INPUT_ENUMS_H -enum HatDir { - HAT_UP = 0, - HAT_RIGHT = 1, - HAT_DOWN = 2, - HAT_LEFT = 3, - HAT_MAX = 4, +enum class HatDir { + UP = 0, + RIGHT = 1, + DOWN = 2, + LEFT = 3, + MAX = 4, }; -enum HatMask { - HAT_MASK_CENTER = 0, - HAT_MASK_UP = 1, - HAT_MASK_RIGHT = 2, - HAT_MASK_DOWN = 4, - HAT_MASK_LEFT = 8, +enum class HatMask { + CENTER = 0, + UP = 1, + RIGHT = 2, + DOWN = 4, + LEFT = 8, }; -enum JoyAxis { - JOY_AXIS_INVALID = -1, - JOY_AXIS_LEFT_X = 0, - JOY_AXIS_LEFT_Y = 1, - JOY_AXIS_RIGHT_X = 2, - JOY_AXIS_RIGHT_Y = 3, - JOY_AXIS_TRIGGER_LEFT = 4, - JOY_AXIS_TRIGGER_RIGHT = 5, - JOY_AXIS_SDL_MAX = 6, - JOY_AXIS_MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes. +enum class JoyAxis { + INVALID = -1, + LEFT_X = 0, + LEFT_Y = 1, + RIGHT_X = 2, + RIGHT_Y = 3, + TRIGGER_LEFT = 4, + TRIGGER_RIGHT = 5, + SDL_MAX = 6, + MAX = 10, // OpenVR supports up to 5 Joysticks making a total of 10 axes. }; -enum JoyButton { - JOY_BUTTON_INVALID = -1, - JOY_BUTTON_A = 0, - JOY_BUTTON_B = 1, - JOY_BUTTON_X = 2, - JOY_BUTTON_Y = 3, - JOY_BUTTON_BACK = 4, - JOY_BUTTON_GUIDE = 5, - JOY_BUTTON_START = 6, - JOY_BUTTON_LEFT_STICK = 7, - JOY_BUTTON_RIGHT_STICK = 8, - JOY_BUTTON_LEFT_SHOULDER = 9, - JOY_BUTTON_RIGHT_SHOULDER = 10, - JOY_BUTTON_DPAD_UP = 11, - JOY_BUTTON_DPAD_DOWN = 12, - JOY_BUTTON_DPAD_LEFT = 13, - JOY_BUTTON_DPAD_RIGHT = 14, - JOY_BUTTON_MISC1 = 15, - JOY_BUTTON_PADDLE1 = 16, - JOY_BUTTON_PADDLE2 = 17, - JOY_BUTTON_PADDLE3 = 18, - JOY_BUTTON_PADDLE4 = 19, - JOY_BUTTON_TOUCHPAD = 20, - JOY_BUTTON_SDL_MAX = 21, - JOY_BUTTON_MAX = 36, // Android supports up to 36 buttons. +enum class JoyButton { + INVALID = -1, + A = 0, + B = 1, + X = 2, + Y = 3, + BACK = 4, + GUIDE = 5, + START = 6, + LEFT_STICK = 7, + RIGHT_STICK = 8, + LEFT_SHOULDER = 9, + RIGHT_SHOULDER = 10, + DPAD_UP = 11, + DPAD_DOWN = 12, + DPAD_LEFT = 13, + DPAD_RIGHT = 14, + MISC1 = 15, + PADDLE1 = 16, + PADDLE2 = 17, + PADDLE3 = 18, + PADDLE4 = 19, + TOUCHPAD = 20, + SDL_MAX = 21, + MAX = 36, // Android supports up to 36 buttons. }; -enum MIDIMessage { - MIDI_MESSAGE_NONE = 0, - MIDI_MESSAGE_NOTE_OFF = 0x8, - MIDI_MESSAGE_NOTE_ON = 0x9, - MIDI_MESSAGE_AFTERTOUCH = 0xA, - MIDI_MESSAGE_CONTROL_CHANGE = 0xB, - MIDI_MESSAGE_PROGRAM_CHANGE = 0xC, - MIDI_MESSAGE_CHANNEL_PRESSURE = 0xD, - MIDI_MESSAGE_PITCH_BEND = 0xE, +enum class MIDIMessage { + NONE = 0, + NOTE_OFF = 0x8, + NOTE_ON = 0x9, + AFTERTOUCH = 0xA, + CONTROL_CHANGE = 0xB, + PROGRAM_CHANGE = 0xC, + CHANNEL_PRESSURE = 0xD, + PITCH_BEND = 0xE, }; -enum MouseButton { - MOUSE_BUTTON_NONE = 0, - MOUSE_BUTTON_LEFT = 1, - MOUSE_BUTTON_RIGHT = 2, - MOUSE_BUTTON_MIDDLE = 3, - MOUSE_BUTTON_WHEEL_UP = 4, - MOUSE_BUTTON_WHEEL_DOWN = 5, - MOUSE_BUTTON_WHEEL_LEFT = 6, - MOUSE_BUTTON_WHEEL_RIGHT = 7, - MOUSE_BUTTON_XBUTTON1 = 8, - MOUSE_BUTTON_XBUTTON2 = 9, - MOUSE_BUTTON_MASK_LEFT = (1 << (MOUSE_BUTTON_LEFT - 1)), - MOUSE_BUTTON_MASK_RIGHT = (1 << (MOUSE_BUTTON_RIGHT - 1)), - MOUSE_BUTTON_MASK_MIDDLE = (1 << (MOUSE_BUTTON_MIDDLE - 1)), - MOUSE_BUTTON_MASK_XBUTTON1 = (1 << (MOUSE_BUTTON_XBUTTON1 - 1)), - MOUSE_BUTTON_MASK_XBUTTON2 = (1 << (MOUSE_BUTTON_XBUTTON2 - 1)), +enum class MouseButton { + NONE = 0, + LEFT = 1, + RIGHT = 2, + MIDDLE = 3, + WHEEL_UP = 4, + WHEEL_DOWN = 5, + WHEEL_LEFT = 6, + WHEEL_RIGHT = 7, + MB_XBUTTON1 = 8, // "XBUTTON1" is a reserved word on Windows. + MB_XBUTTON2 = 9, // "XBUTTON2" is a reserved word on Windows. + MASK_LEFT = (1 << (LEFT - 1)), + MASK_RIGHT = (1 << (RIGHT - 1)), + MASK_MIDDLE = (1 << (MIDDLE - 1)), + MASK_XBUTTON1 = (1 << (MB_XBUTTON1 - 1)), + MASK_XBUTTON2 = (1 << (MB_XBUTTON2 - 1)), }; +inline MouseButton mouse_button_to_mask(MouseButton button) { + return MouseButton(1 << ((int)button - 1)); +} + +inline MouseButton operator&(MouseButton a, MouseButton b) { + return (MouseButton)((int)a & (int)b); +} + +inline MouseButton operator|(MouseButton a, MouseButton b) { + return (MouseButton)((int)a | (int)b); +} + +inline MouseButton operator^(MouseButton a, MouseButton b) { + return (MouseButton)((int)a ^ (int)b); +} + inline MouseButton &operator|=(MouseButton &a, MouseButton b) { return (MouseButton &)((int &)a |= (int)b); } @@ -123,4 +139,28 @@ inline MouseButton &operator&=(MouseButton &a, MouseButton b) { return (MouseButton &)((int &)a &= (int)b); } +inline MouseButton operator~(MouseButton a) { + return (MouseButton)(~(int)a); +} + +inline HatMask operator|(HatMask a, HatMask b) { + return (HatMask)((int)a | (int)b); +} + +inline HatMask operator&(HatMask a, HatMask b) { + return (HatMask)((int)a & (int)b); +} + +inline HatMask &operator&=(HatMask &a, HatMask b) { + return (HatMask &)((int &)a &= (int)b); +} + +inline HatMask &operator|=(HatMask &a, HatMask b) { + return (HatMask &)((int &)a |= (int)b); +} + +inline HatMask operator~(HatMask a) { + return (HatMask)(~(int)a); +} + #endif // INPUT_ENUMS_H diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp index af3190bb17..ccde8838e1 100644 --- a/core/input/input_event.cpp +++ b/core/input/input_event.cpp @@ -203,19 +203,19 @@ void InputEventWithModifiers::set_modifiers_from_event(const InputEventWithModif set_meta_pressed(event->is_meta_pressed()); } -uint32_t InputEventWithModifiers::get_modifiers_mask() const { - uint32_t mask = 0; +Key InputEventWithModifiers::get_modifiers_mask() const { + Key mask = Key::NONE; if (is_ctrl_pressed()) { - mask |= KEY_MASK_CTRL; + mask |= KeyModifierMask::CTRL; } if (is_shift_pressed()) { - mask |= KEY_MASK_SHIFT; + mask |= KeyModifierMask::SHIFT; } if (is_alt_pressed()) { - mask |= KEY_MASK_ALT; + mask |= KeyModifierMask::ALT; } if (is_meta_pressed()) { - mask |= KEY_MASK_META; + mask |= KeyModifierMask::META; } return mask; } @@ -224,16 +224,16 @@ String InputEventWithModifiers::as_text() const { Vector<String> mod_names; if (is_ctrl_pressed()) { - mod_names.push_back(find_keycode_name(KEY_CTRL)); + mod_names.push_back(find_keycode_name(Key::CTRL)); } if (is_shift_pressed()) { - mod_names.push_back(find_keycode_name(KEY_SHIFT)); + mod_names.push_back(find_keycode_name(Key::SHIFT)); } if (is_alt_pressed()) { - mod_names.push_back(find_keycode_name(KEY_ALT)); + mod_names.push_back(find_keycode_name(Key::ALT)); } if (is_meta_pressed()) { - mod_names.push_back(find_keycode_name(KEY_META)); + mod_names.push_back(find_keycode_name(Key::META)); } if (!mod_names.is_empty()) { @@ -325,12 +325,12 @@ Key InputEventKey::get_physical_keycode() const { return physical_keycode; } -void InputEventKey::set_unicode(uint32_t p_unicode) { +void InputEventKey::set_unicode(char32_t p_unicode) { unicode = p_unicode; emit_changed(); } -uint32_t InputEventKey::get_unicode() const { +char32_t InputEventKey::get_unicode() const { return unicode; } @@ -343,18 +343,18 @@ bool InputEventKey::is_echo() const { return echo; } -uint32_t InputEventKey::get_keycode_with_modifiers() const { +Key InputEventKey::get_keycode_with_modifiers() const { return keycode | get_modifiers_mask(); } -uint32_t InputEventKey::get_physical_keycode_with_modifiers() const { +Key InputEventKey::get_physical_keycode_with_modifiers() const { return physical_keycode | get_modifiers_mask(); } String InputEventKey::as_text() const { String kc; - if (keycode == 0) { + if (keycode == Key::NONE) { kc = keycode_get_string(physical_keycode) + " (" + RTR("Physical") + ")"; } else { kc = keycode_get_string(keycode); @@ -374,11 +374,11 @@ String InputEventKey::to_string() { String kc = ""; String physical = "false"; - if (keycode == 0) { - kc = itos(physical_keycode) + " (" + keycode_get_string(physical_keycode) + ")"; + if (keycode == Key::NONE) { + kc = itos((int64_t)physical_keycode) + " (" + keycode_get_string(physical_keycode) + ")"; physical = "true"; } else { - kc = itos(keycode) + " (" + keycode_get_string(keycode) + ")"; + kc = itos((int64_t)keycode) + " (" + keycode_get_string(keycode) + ")"; } String mods = InputEventWithModifiers::as_text(); @@ -390,22 +390,22 @@ String InputEventKey::to_string() { Ref<InputEventKey> InputEventKey::create_reference(Key p_keycode) { Ref<InputEventKey> ie; ie.instantiate(); - ie->set_keycode(p_keycode & KEY_CODE_MASK); - ie->set_unicode(p_keycode & KEY_CODE_MASK); + ie->set_keycode(p_keycode & KeyModifierMask::CODE_MASK); + ie->set_unicode(char32_t(p_keycode & KeyModifierMask::CODE_MASK)); - if (p_keycode & KEY_MASK_SHIFT) { + if ((p_keycode & KeyModifierMask::SHIFT) != Key::NONE) { ie->set_shift_pressed(true); } - if (p_keycode & KEY_MASK_ALT) { + if ((p_keycode & KeyModifierMask::ALT) != Key::NONE) { ie->set_alt_pressed(true); } - if (p_keycode & KEY_MASK_CTRL) { + if ((p_keycode & KeyModifierMask::CTRL) != Key::NONE) { ie->set_ctrl_pressed(true); } - if (p_keycode & KEY_MASK_CMD) { + if ((p_keycode & KeyModifierMask::CMD) != Key::NONE) { ie->set_command_pressed(true); } - if (p_keycode & KEY_MASK_META) { + if ((p_keycode & KeyModifierMask::META) != Key::NONE) { ie->set_meta_pressed(true); } @@ -419,14 +419,14 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed } bool match = false; - if (get_keycode() == 0) { - uint32_t code = get_physical_keycode_with_modifiers(); - uint32_t event_code = key->get_physical_keycode_with_modifiers(); + if (get_keycode() == Key::NONE) { + Key code = get_physical_keycode_with_modifiers(); + Key event_code = key->get_physical_keycode_with_modifiers(); match = get_physical_keycode() == key->get_physical_keycode() && (!key->is_pressed() || (code & event_code) == code); } else { - uint32_t code = get_keycode_with_modifiers(); - uint32_t event_code = key->get_keycode_with_modifiers(); + Key code = get_keycode_with_modifiers(); + Key event_code = key->get_keycode_with_modifiers(); match = get_keycode() == key->get_keycode() && (!key->is_pressed() || (code & event_code) == code); } @@ -452,7 +452,7 @@ bool InputEventKey::is_match(const Ref<InputEvent> &p_event, bool p_exact_match) return false; } - if (keycode == 0) { + if (keycode == Key::NONE) { return physical_keycode == key->physical_keycode && (!p_exact_match || get_modifiers_mask() == key->get_modifiers_mask()); } else { @@ -487,12 +487,12 @@ void InputEventKey::_bind_methods() { /////////////////////////////////// -void InputEventMouse::set_button_mask(int p_mask) { +void InputEventMouse::set_button_mask(MouseButton p_mask) { button_mask = p_mask; emit_changed(); } -int InputEventMouse::get_button_mask() const { +MouseButton InputEventMouse::get_button_mask() const { return button_mask; } @@ -637,21 +637,21 @@ String InputEventMouseButton::as_text() const { String full_string = mods_text == "" ? "" : mods_text + "+"; // Button - int idx = get_button_index(); + MouseButton idx = get_button_index(); switch (idx) { - case MOUSE_BUTTON_LEFT: - case MOUSE_BUTTON_RIGHT: - case MOUSE_BUTTON_MIDDLE: - case MOUSE_BUTTON_WHEEL_UP: - case MOUSE_BUTTON_WHEEL_DOWN: - case MOUSE_BUTTON_WHEEL_LEFT: - case MOUSE_BUTTON_WHEEL_RIGHT: - case MOUSE_BUTTON_XBUTTON1: - case MOUSE_BUTTON_XBUTTON2: - full_string += RTR(_mouse_button_descriptions[idx - 1]); // button index starts from 1, array index starts from 0, so subtract 1 + case MouseButton::LEFT: + case MouseButton::RIGHT: + case MouseButton::MIDDLE: + case MouseButton::WHEEL_UP: + case MouseButton::WHEEL_DOWN: + case MouseButton::WHEEL_LEFT: + case MouseButton::WHEEL_RIGHT: + case MouseButton::MB_XBUTTON1: + case MouseButton::MB_XBUTTON2: + full_string += RTR(_mouse_button_descriptions[(size_t)idx - 1]); // button index starts from 1, array index starts from 0, so subtract 1 break; default: - full_string += RTR("Button") + " #" + itos(idx); + full_string += RTR("Button") + " #" + itos((int64_t)idx); break; } @@ -667,20 +667,20 @@ String InputEventMouseButton::to_string() { String p = is_pressed() ? "true" : "false"; String d = double_click ? "true" : "false"; - int idx = get_button_index(); - String button_string = itos(idx); + MouseButton idx = get_button_index(); + String button_string = itos((int64_t)idx); switch (idx) { - case MOUSE_BUTTON_LEFT: - case MOUSE_BUTTON_RIGHT: - case MOUSE_BUTTON_MIDDLE: - case MOUSE_BUTTON_WHEEL_UP: - case MOUSE_BUTTON_WHEEL_DOWN: - case MOUSE_BUTTON_WHEEL_LEFT: - case MOUSE_BUTTON_WHEEL_RIGHT: - case MOUSE_BUTTON_XBUTTON1: - case MOUSE_BUTTON_XBUTTON2: - button_string += " (" + RTR(_mouse_button_descriptions[idx - 1]) + ")"; // button index starts from 1, array index starts from 0, so subtract 1 + case MouseButton::LEFT: + case MouseButton::RIGHT: + case MouseButton::MIDDLE: + case MouseButton::WHEEL_UP: + case MouseButton::WHEEL_DOWN: + case MouseButton::WHEEL_LEFT: + case MouseButton::WHEEL_RIGHT: + case MouseButton::MB_XBUTTON1: + case MouseButton::MB_XBUTTON2: + button_string += " (" + RTR(_mouse_button_descriptions[(size_t)idx - 1]) + ")"; // button index starts from 1, array index starts from 0, so subtract 1 break; default: break; @@ -778,23 +778,23 @@ String InputEventMouseMotion::as_text() const { } String InputEventMouseMotion::to_string() { - int button_mask = get_button_mask(); - String button_mask_string = itos(button_mask); - switch (get_button_mask()) { - case MOUSE_BUTTON_MASK_LEFT: - button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_LEFT - 1]) + ")"; + MouseButton button_mask = get_button_mask(); + String button_mask_string = itos((int64_t)button_mask); + switch (button_mask) { + case MouseButton::MASK_LEFT: + button_mask_string += " (" + RTR(_mouse_button_descriptions[(size_t)MouseButton::LEFT - 1]) + ")"; break; - case MOUSE_BUTTON_MASK_MIDDLE: - button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_MIDDLE - 1]) + ")"; + case MouseButton::MASK_MIDDLE: + button_mask_string += " (" + RTR(_mouse_button_descriptions[(size_t)MouseButton::MIDDLE - 1]) + ")"; break; - case MOUSE_BUTTON_MASK_RIGHT: - button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_RIGHT - 1]) + ")"; + case MouseButton::MASK_RIGHT: + button_mask_string += " (" + RTR(_mouse_button_descriptions[(size_t)MouseButton::RIGHT - 1]) + ")"; break; - case MOUSE_BUTTON_MASK_XBUTTON1: - button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_XBUTTON1 - 1]) + ")"; + case MouseButton::MASK_XBUTTON1: + button_mask_string += " (" + RTR(_mouse_button_descriptions[(size_t)MouseButton::MB_XBUTTON1 - 1]) + ")"; break; - case MOUSE_BUTTON_MASK_XBUTTON2: - button_mask_string += " (" + RTR(_mouse_button_descriptions[MOUSE_BUTTON_XBUTTON2 - 1]) + ")"; + case MouseButton::MASK_XBUTTON2: + button_mask_string += " (" + RTR(_mouse_button_descriptions[(size_t)MouseButton::MB_XBUTTON2 - 1]) + ")"; break; default: break; @@ -869,7 +869,7 @@ void InputEventMouseMotion::_bind_methods() { /////////////////////////////////// void InputEventJoypadMotion::set_axis(JoyAxis p_axis) { - ERR_FAIL_INDEX(p_axis, JOY_AXIS_MAX); + ERR_FAIL_COND(p_axis < JoyAxis::LEFT_X || p_axis > JoyAxis::MAX); axis = p_axis; emit_changed(); @@ -938,7 +938,7 @@ bool InputEventJoypadMotion::is_match(const Ref<InputEvent> &p_event, bool p_exa (!p_exact_match || ((axis_value < 0) == (jm->axis_value < 0))); } -static const char *_joy_axis_descriptions[JOY_AXIS_MAX] = { +static const char *_joy_axis_descriptions[(size_t)JoyAxis::MAX] = { TTRC("Left Stick X-Axis, Joystick 0 X-Axis"), TTRC("Left Stick Y-Axis, Joystick 0 Y-Axis"), TTRC("Right Stick X-Axis, Joystick 1 X-Axis"), @@ -952,7 +952,7 @@ static const char *_joy_axis_descriptions[JOY_AXIS_MAX] = { }; String InputEventJoypadMotion::as_text() const { - String desc = axis < JOY_AXIS_MAX ? RTR(_joy_axis_descriptions[axis]) : TTR("Unknown Joypad Axis"); + String desc = axis < JoyAxis::MAX ? RTR(_joy_axis_descriptions[(size_t)axis]) : TTR("Unknown Joypad Axis"); return vformat(TTR("Joypad Motion on Axis %d (%s) with Value %.2f"), axis, desc, axis_value); } @@ -1032,7 +1032,7 @@ bool InputEventJoypadButton::is_match(const Ref<InputEvent> &p_event, bool p_exa return button_index == button->button_index; } -static const char *_joy_button_descriptions[JOY_BUTTON_SDL_MAX] = { +static const char *_joy_button_descriptions[(size_t)JoyButton::SDL_MAX] = { TTRC("Bottom Action, Sony Cross, Xbox A, Nintendo B"), TTRC("Right Action, Sony Circle, Xbox B, Nintendo A"), TTRC("Left Action, Sony Square, Xbox X, Nintendo Y"), @@ -1057,10 +1057,10 @@ static const char *_joy_button_descriptions[JOY_BUTTON_SDL_MAX] = { }; String InputEventJoypadButton::as_text() const { - String text = "Joypad Button " + itos(button_index); + String text = "Joypad Button " + itos((int64_t)button_index); - if (button_index >= 0 && button_index < JOY_BUTTON_SDL_MAX) { - text += vformat(" (%s)", _joy_button_descriptions[button_index]); + if (button_index > JoyButton::INVALID && button_index < JoyButton::SDL_MAX) { + text += vformat(" (%s)", _joy_button_descriptions[(size_t)button_index]); } if (pressure != 0) { @@ -1506,7 +1506,7 @@ int InputEventMIDI::get_controller_value() const { } String InputEventMIDI::as_text() const { - return vformat(RTR("MIDI Input on Channel=%s Message=%s"), itos(channel), itos(message)); + return vformat(RTR("MIDI Input on Channel=%s Message=%s"), itos(channel), itos((int64_t)message)); } String InputEventMIDI::to_string() { diff --git a/core/input/input_event.h b/core/input/input_event.h index 3fc8078a09..70046e4491 100644 --- a/core/input/input_event.h +++ b/core/input/input_event.h @@ -151,7 +151,7 @@ public: void set_modifiers_from_event(const InputEventWithModifiers *event); - uint32_t get_modifiers_mask() const; + Key get_modifiers_mask() const; virtual String as_text() const override; virtual String to_string() override; @@ -164,8 +164,8 @@ class InputEventKey : public InputEventWithModifiers { bool pressed = false; /// otherwise release - Key keycode = KEY_NONE; // Key enum, without modifier masks. - Key physical_keycode = KEY_NONE; + Key keycode = Key::NONE; // Key enum, without modifier masks. + Key physical_keycode = Key::NONE; uint32_t unicode = 0; ///unicode bool echo = false; /// true if this is an echo key @@ -183,14 +183,14 @@ public: void set_physical_keycode(Key p_keycode); Key get_physical_keycode() const; - void set_unicode(uint32_t p_unicode); - uint32_t get_unicode() const; + void set_unicode(char32_t p_unicode); + char32_t get_unicode() const; void set_echo(bool p_enable); virtual bool is_echo() const override; - uint32_t get_keycode_with_modifiers() const; - uint32_t get_physical_keycode_with_modifiers() const; + Key get_keycode_with_modifiers() const; + Key get_physical_keycode_with_modifiers() const; virtual bool action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const override; virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override; @@ -208,7 +208,7 @@ public: class InputEventMouse : public InputEventWithModifiers { GDCLASS(InputEventMouse, InputEventWithModifiers); - int button_mask = 0; + MouseButton button_mask = MouseButton::NONE; Vector2 pos; Vector2 global_pos; @@ -217,8 +217,8 @@ protected: static void _bind_methods(); public: - void set_button_mask(int p_mask); - int get_button_mask() const; + void set_button_mask(MouseButton p_mask); + MouseButton get_button_mask() const; void set_position(const Vector2 &p_pos); Vector2 get_position() const; @@ -233,7 +233,7 @@ class InputEventMouseButton : public InputEventMouse { GDCLASS(InputEventMouseButton, InputEventMouse); float factor = 1; - MouseButton button_index = MOUSE_BUTTON_NONE; + MouseButton button_index = MouseButton::NONE; bool pressed = false; //otherwise released bool double_click = false; //last even less than double click time @@ -501,7 +501,7 @@ class InputEventMIDI : public InputEvent { GDCLASS(InputEventMIDI, InputEvent); int channel = 0; - MIDIMessage message = MIDI_MESSAGE_NONE; + MIDIMessage message = MIDIMessage::NONE; int pitch = 0; int velocity = 0; int instrument = 0; diff --git a/core/input/input_map.cpp b/core/input/input_map.cpp index 1ec4299093..84e1313756 100644 --- a/core/input/input_map.cpp +++ b/core/input/input_map.cpp @@ -381,320 +381,320 @@ const OrderedHashMap<String, List<Ref<InputEvent>>> &InputMap::get_builtins() { } List<Ref<InputEvent>> inputs; - inputs.push_back(InputEventKey::create_reference(KEY_ENTER)); - inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER)); - inputs.push_back(InputEventKey::create_reference(KEY_SPACE)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::SPACE)); default_builtin_cache.insert("ui_accept", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_Y)); - inputs.push_back(InputEventKey::create_reference(KEY_SPACE)); + inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::Y)); + inputs.push_back(InputEventKey::create_reference(Key::SPACE)); default_builtin_cache.insert("ui_select", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_ESCAPE)); + inputs.push_back(InputEventKey::create_reference(Key::ESCAPE)); default_builtin_cache.insert("ui_cancel", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_TAB)); + inputs.push_back(InputEventKey::create_reference(Key::TAB)); default_builtin_cache.insert("ui_focus_next", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_TAB | KEY_MASK_SHIFT)); + inputs.push_back(InputEventKey::create_reference(Key::TAB | KeyModifierMask::SHIFT)); default_builtin_cache.insert("ui_focus_prev", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_LEFT)); - inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_LEFT)); + inputs.push_back(InputEventKey::create_reference(Key::LEFT)); + inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_LEFT)); default_builtin_cache.insert("ui_left", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_RIGHT)); - inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_RIGHT)); + inputs.push_back(InputEventKey::create_reference(Key::RIGHT)); + inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_RIGHT)); default_builtin_cache.insert("ui_right", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_UP)); - inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_UP)); + inputs.push_back(InputEventKey::create_reference(Key::UP)); + inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_UP)); default_builtin_cache.insert("ui_up", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DOWN)); - inputs.push_back(InputEventJoypadButton::create_reference(JOY_BUTTON_DPAD_DOWN)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN)); + inputs.push_back(InputEventJoypadButton::create_reference(JoyButton::DPAD_DOWN)); default_builtin_cache.insert("ui_down", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_PAGEUP)); + inputs.push_back(InputEventKey::create_reference(Key::PAGEUP)); default_builtin_cache.insert("ui_page_up", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_PAGEDOWN)); + inputs.push_back(InputEventKey::create_reference(Key::PAGEDOWN)); default_builtin_cache.insert("ui_page_down", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_HOME)); + inputs.push_back(InputEventKey::create_reference(Key::HOME)); default_builtin_cache.insert("ui_home", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_END)); + inputs.push_back(InputEventKey::create_reference(Key::END)); default_builtin_cache.insert("ui_end", inputs); // ///// UI basic Shortcuts ///// inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_X | KEY_MASK_CMD)); - inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_SHIFT)); + inputs.push_back(InputEventKey::create_reference(Key::X | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::SHIFT)); default_builtin_cache.insert("ui_cut", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_C | KEY_MASK_CMD)); - inputs.push_back(InputEventKey::create_reference(KEY_INSERT | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::C | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::INSERT | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_copy", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_V | KEY_MASK_CMD)); - inputs.push_back(InputEventKey::create_reference(KEY_INSERT | KEY_MASK_SHIFT)); + inputs.push_back(InputEventKey::create_reference(Key::V | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::INSERT | KeyModifierMask::SHIFT)); default_builtin_cache.insert("ui_paste", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_Z | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_undo", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_Z | KEY_MASK_CMD | KEY_MASK_SHIFT)); - inputs.push_back(InputEventKey::create_reference(KEY_Y | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::Z | KeyModifierMask::CMD | KeyModifierMask::SHIFT)); + inputs.push_back(InputEventKey::create_reference(Key::Y | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_redo", inputs); // ///// UI Text Input Shortcuts ///// inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_SPACE | KEY_MASK_CTRL)); + inputs.push_back(InputEventKey::create_reference(Key::SPACE | KeyModifierMask::CTRL)); default_builtin_cache.insert("ui_text_completion_query", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_ENTER)); - inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER)); default_builtin_cache.insert("ui_text_completion_accept", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_TAB)); + inputs.push_back(InputEventKey::create_reference(Key::TAB)); default_builtin_cache.insert("ui_text_completion_replace", inputs); // Newlines inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_ENTER)); - inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER)); default_builtin_cache.insert("ui_text_newline", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_ENTER | KEY_MASK_CMD)); - inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_newline_blank", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_ENTER | KEY_MASK_SHIFT | KEY_MASK_CMD)); - inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER | KEY_MASK_SHIFT | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER | KeyModifierMask::SHIFT | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_newline_above", inputs); // Indentation inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_TAB)); + inputs.push_back(InputEventKey::create_reference(Key::TAB)); default_builtin_cache.insert("ui_text_indent", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_TAB | KEY_MASK_SHIFT)); + inputs.push_back(InputEventKey::create_reference(Key::TAB | KeyModifierMask::SHIFT)); default_builtin_cache.insert("ui_text_dedent", inputs); // Text Backspace and Delete inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE)); - inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE | KEY_MASK_SHIFT)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::SHIFT)); default_builtin_cache.insert("ui_text_backspace", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_backspace_word", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE | KEY_MASK_ALT)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_backspace_word.macos", inputs); inputs = List<Ref<InputEvent>>(); default_builtin_cache.insert("ui_text_backspace_all_to_left", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_backspace_all_to_left.macos", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DELETE)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE)); default_builtin_cache.insert("ui_text_delete", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_delete_word", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_ALT)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_delete_word.macos", inputs); inputs = List<Ref<InputEvent>>(); default_builtin_cache.insert("ui_text_delete_all_to_right", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DELETE | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_delete_all_to_right.macos", inputs); // Text Caret Movement Left/Right inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_LEFT)); + inputs.push_back(InputEventKey::create_reference(Key::LEFT)); default_builtin_cache.insert("ui_text_caret_left", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_LEFT | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_word_left", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_LEFT | KEY_MASK_ALT)); + inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_caret_word_left.macos", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_RIGHT)); + inputs.push_back(InputEventKey::create_reference(Key::RIGHT)); default_builtin_cache.insert("ui_text_caret_right", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_RIGHT | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_word_right", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_RIGHT | KEY_MASK_ALT)); + inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_caret_word_right.macos", inputs); // Text Caret Movement Up/Down inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_UP)); + inputs.push_back(InputEventKey::create_reference(Key::UP)); default_builtin_cache.insert("ui_text_caret_up", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DOWN)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN)); default_builtin_cache.insert("ui_text_caret_down", inputs); // Text Caret Movement Line Start/End inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_HOME)); + inputs.push_back(InputEventKey::create_reference(Key::HOME)); default_builtin_cache.insert("ui_text_caret_line_start", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_A | KEY_MASK_CTRL)); - inputs.push_back(InputEventKey::create_reference(KEY_LEFT | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::A | KeyModifierMask::CTRL)); + inputs.push_back(InputEventKey::create_reference(Key::LEFT | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_line_start.macos", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_END)); + inputs.push_back(InputEventKey::create_reference(Key::END)); default_builtin_cache.insert("ui_text_caret_line_end", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_E | KEY_MASK_CTRL)); - inputs.push_back(InputEventKey::create_reference(KEY_RIGHT | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::E | KeyModifierMask::CTRL)); + inputs.push_back(InputEventKey::create_reference(Key::RIGHT | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_line_end.macos", inputs); // Text Caret Movement Page Up/Down inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_PAGEUP)); + inputs.push_back(InputEventKey::create_reference(Key::PAGEUP)); default_builtin_cache.insert("ui_text_caret_page_up", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_PAGEDOWN)); + inputs.push_back(InputEventKey::create_reference(Key::PAGEDOWN)); default_builtin_cache.insert("ui_text_caret_page_down", inputs); // Text Caret Movement Document Start/End inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_HOME | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::HOME | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_document_start", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_UP | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_document_start.macos", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_END | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::END | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_document_end", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DOWN | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_caret_document_end.macos", inputs); // Text Scrolling inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_UP | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_scroll_up", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_UP | KEY_MASK_CMD | KEY_MASK_ALT)); + inputs.push_back(InputEventKey::create_reference(Key::UP | KeyModifierMask::CMD | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_scroll_up.macos", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DOWN | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_scroll_down", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DOWN | KEY_MASK_CMD | KEY_MASK_ALT)); + inputs.push_back(InputEventKey::create_reference(Key::DOWN | KeyModifierMask::CMD | KeyModifierMask::ALT)); default_builtin_cache.insert("ui_text_scroll_down.macos", inputs); // Text Misc inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_A | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::A | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_select_all", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_D | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_text_select_word_under_caret", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_INSERT)); + inputs.push_back(InputEventKey::create_reference(Key::INSERT)); default_builtin_cache.insert("ui_text_toggle_insert_mode", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_MENU)); + inputs.push_back(InputEventKey::create_reference(Key::MENU)); default_builtin_cache.insert("ui_menu", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_ENTER)); - inputs.push_back(InputEventKey::create_reference(KEY_KP_ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::ENTER)); + inputs.push_back(InputEventKey::create_reference(Key::KP_ENTER)); default_builtin_cache.insert("ui_text_submit", inputs); // ///// UI Graph Shortcuts ///// inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_D | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::D | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_graph_duplicate", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_DELETE)); + inputs.push_back(InputEventKey::create_reference(Key::KEY_DELETE)); default_builtin_cache.insert("ui_graph_delete", inputs); // ///// UI File Dialog Shortcuts ///// inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_BACKSPACE)); + inputs.push_back(InputEventKey::create_reference(Key::BACKSPACE)); default_builtin_cache.insert("ui_filedialog_up_one_level", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_F5)); + inputs.push_back(InputEventKey::create_reference(Key::F5)); default_builtin_cache.insert("ui_filedialog_refresh", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_H)); + inputs.push_back(InputEventKey::create_reference(Key::H)); default_builtin_cache.insert("ui_filedialog_show_hidden", inputs); inputs = List<Ref<InputEvent>>(); - inputs.push_back(InputEventKey::create_reference(KEY_QUOTELEFT | KEY_MASK_CMD)); + inputs.push_back(InputEventKey::create_reference(Key::QUOTELEFT | KeyModifierMask::CMD)); default_builtin_cache.insert("ui_swap_input_direction", inputs); return default_builtin_cache; diff --git a/core/io/http_client.cpp b/core/io/http_client.cpp index 5c1352c1b6..800ac779e5 100644 --- a/core/io/http_client.cpp +++ b/core/io/http_client.cpp @@ -85,8 +85,7 @@ String HTTPClient::query_string_from_dict(const Dictionary &p_dict) { } } } - query.erase(0, 1); - return query; + return query.substr(1); } Dictionary HTTPClient::_get_response_headers_as_dictionary() { diff --git a/core/io/resource_importer.h b/core/io/resource_importer.h index a1cacbd306..cd583e2533 100644 --- a/core/io/resource_importer.h +++ b/core/io/resource_importer.h @@ -134,8 +134,8 @@ public: virtual int get_preset_count() const { return 0; } virtual String get_preset_name(int p_idx) const { return String(); } - virtual void get_import_options(List<ImportOption> *r_options, int p_preset = 0) const = 0; - virtual bool get_option_visibility(const String &p_option, const Map<StringName, Variant> &p_options) const = 0; + virtual void get_import_options(const String &p_path, List<ImportOption> *r_options, int p_preset = 0) const = 0; + virtual bool get_option_visibility(const String &p_path, const String &p_option, const Map<StringName, Variant> &p_options) const = 0; virtual String get_option_group_file() const { return String(); } virtual Error import(const String &p_source_file, const String &p_save_path, const Map<StringName, Variant> &p_options, List<String> *r_platform_variants, List<String> *r_gen_files = nullptr, Variant *r_metadata = nullptr) = 0; diff --git a/core/math/color.cpp b/core/math/color.cpp index dc86cacf8f..8310c342ed 100644 --- a/core/math/color.cpp +++ b/core/math/color.cpp @@ -107,6 +107,39 @@ uint64_t Color::to_rgba64() const { return c; } +String _to_hex(float p_val) { + int v = Math::round(p_val * 255); + v = CLAMP(v, 0, 255); + String ret; + + for (int i = 0; i < 2; i++) { + char32_t c[2] = { 0, 0 }; + int lv = v & 0xF; + if (lv < 10) { + c[0] = '0' + lv; + } else { + c[0] = 'a' + lv - 10; + } + + v >>= 4; + String cs = (const char32_t *)c; + ret = cs + ret; + } + + return ret; +} + +String Color::to_html(bool p_alpha) const { + String txt; + txt += _to_hex(r); + txt += _to_hex(g); + txt += _to_hex(b); + if (p_alpha) { + txt += _to_hex(a); + } + return txt; +} + float Color::get_h() const { float min = MIN(r, g); min = MIN(min, b); @@ -249,20 +282,6 @@ Color Color::hex64(uint64_t p_hex) { return Color(r, g, b, a); } -Color Color::from_rgbe9995(uint32_t p_rgbe) { - float r = p_rgbe & 0x1ff; - float g = (p_rgbe >> 9) & 0x1ff; - float b = (p_rgbe >> 18) & 0x1ff; - float e = (p_rgbe >> 27); - float m = Math::pow(2, e - 15.0 - 9.0); - - float rd = r * m; - float gd = g * m; - float bd = b * m; - - return Color(rd, gd, bd, 1.0f); -} - static int _parse_col4(const String &p_str, int p_ofs) { char character = p_str[p_ofs]; @@ -428,43 +447,24 @@ Color Color::from_string(const String &p_string, const Color &p_default) { } } -String _to_hex(float p_val) { - int v = Math::round(p_val * 255); - v = CLAMP(v, 0, 255); - String ret; - - for (int i = 0; i < 2; i++) { - char32_t c[2] = { 0, 0 }; - int lv = v & 0xF; - if (lv < 10) { - c[0] = '0' + lv; - } else { - c[0] = 'a' + lv - 10; - } - - v >>= 4; - String cs = (const char32_t *)c; - ret = cs + ret; - } - - return ret; +Color Color::from_hsv(float p_h, float p_s, float p_v, float p_alpha) { + Color c; + c.set_hsv(p_h, p_s, p_v, p_alpha); + return c; } -String Color::to_html(bool p_alpha) const { - String txt; - txt += _to_hex(r); - txt += _to_hex(g); - txt += _to_hex(b); - if (p_alpha) { - txt += _to_hex(a); - } - return txt; -} +Color Color::from_rgbe9995(uint32_t p_rgbe) { + float r = p_rgbe & 0x1ff; + float g = (p_rgbe >> 9) & 0x1ff; + float b = (p_rgbe >> 18) & 0x1ff; + float e = (p_rgbe >> 27); + float m = Math::pow(2, e - 15.0 - 9.0); -Color Color::from_hsv(float p_h, float p_s, float p_v, float p_a) const { - Color c; - c.set_hsv(p_h, p_s, p_v, p_a); - return c; + float rd = r * m; + float gd = g * m; + float bd = b * m; + + return Color(rd, gd, bd, 1.0f); } Color::operator String() const { diff --git a/core/math/color.h b/core/math/color.h index a95dbf4f60..ffd0fd8f6e 100644 --- a/core/math/color.h +++ b/core/math/color.h @@ -51,6 +51,7 @@ struct Color { uint64_t to_rgba64() const; uint64_t to_argb64() const; uint64_t to_abgr64() const; + String to_html(bool p_alpha = true) const; float get_h() const; float get_s() const; float get_v() const; @@ -189,8 +190,7 @@ struct Color { static String get_named_color_name(int p_idx); static Color get_named_color(int p_idx); static Color from_string(const String &p_string, const Color &p_default); - String to_html(bool p_alpha = true) const; - Color from_hsv(float p_h, float p_s, float p_v, float p_a) const; + static Color from_hsv(float p_h, float p_s, float p_v, float p_alpha = 1.0); static Color from_rgbe9995(uint32_t p_rgbe); _FORCE_INLINE_ bool operator<(const Color &p_color) const; //used in set keys diff --git a/core/math/math_funcs.h b/core/math/math_funcs.h index baff10af98..b3eabd3e7a 100644 --- a/core/math/math_funcs.h +++ b/core/math/math_funcs.h @@ -291,6 +291,19 @@ public: return is_zero_approx(range) ? min : value - (range * Math::floor((value - min) / range)); } + static _ALWAYS_INLINE_ float fract(float value) { + return value - floor(value); + } + static _ALWAYS_INLINE_ double fract(double value) { + return value - floor(value); + } + static _ALWAYS_INLINE_ float pingpong(float value, float length) { + return (length != 0.0f) ? abs(fract((value - length) / (length * 2.0f)) * length * 2.0f - length) : 0.0f; + } + static _ALWAYS_INLINE_ double pingpong(double value, double length) { + return (length != 0.0) ? abs(fract((value - length) / (length * 2.0)) * length * 2.0 - length) : 0.0; + } + // double only, as these functions are mainly used by the editor and not performance-critical, static double ease(double p_x, double p_c); static int step_decimals(double p_step); diff --git a/core/math/vector2.cpp b/core/math/vector2.cpp index 6259bdead0..1d3f93848e 100644 --- a/core/math/vector2.cpp +++ b/core/math/vector2.cpp @@ -79,7 +79,7 @@ real_t Vector2::angle_to(const Vector2 &p_vector2) const { } real_t Vector2::angle_to_point(const Vector2 &p_vector2) const { - return (*this - p_vector2).angle(); + return (p_vector2 - *this).angle(); } real_t Vector2::dot(const Vector2 &p_other) const { diff --git a/core/object/object.cpp b/core/object/object.cpp index 498f116997..8e96695f0d 100644 --- a/core/object/object.cpp +++ b/core/object/object.cpp @@ -628,7 +628,10 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons script_instance->get_property_list(p_list); } - _get_property_listv(p_list, p_reversed); + if (_extension) { + p_list->push_back(PropertyInfo(Variant::NIL, _extension->class_name, PROPERTY_HINT_NONE, String(), PROPERTY_USAGE_CATEGORY)); + ClassDB::get_property_list(_extension->class_name, p_list, true, this); + } if (_extension && _extension->get_property_list) { uint32_t pcount; @@ -641,6 +644,8 @@ void Object::get_property_list(List<PropertyInfo> *p_list, bool p_reversed) cons } } + _get_property_listv(p_list, p_reversed); + if (!is_class("Script")) { // can still be set, but this is for user-friendliness p_list->push_back(PropertyInfo(Variant::OBJECT, "script", PROPERTY_HINT_RESOURCE_TYPE, "Script", PROPERTY_USAGE_DEFAULT)); } diff --git a/core/os/keyboard.cpp b/core/os/keyboard.cpp index 4c5f0b5220..fdc43da7a5 100644 --- a/core/os/keyboard.cpp +++ b/core/os/keyboard.cpp @@ -33,400 +33,399 @@ #include "core/os/os.h" struct _KeyCodeText { - int code; + Key code; const char *text; }; static const _KeyCodeText _keycodes[] = { /* clang-format off */ - {KEY_ESCAPE ,"Escape"}, - {KEY_TAB ,"Tab"}, - {KEY_BACKTAB ,"BackTab"}, - {KEY_BACKSPACE ,"BackSpace"}, - {KEY_ENTER ,"Enter"}, - {KEY_KP_ENTER ,"Kp Enter"}, - {KEY_INSERT ,"Insert"}, - {KEY_DELETE ,"Delete"}, - {KEY_PAUSE ,"Pause"}, - {KEY_PRINT ,"Print"}, - {KEY_SYSREQ ,"SysReq"}, - {KEY_CLEAR ,"Clear"}, - {KEY_HOME ,"Home"}, - {KEY_END ,"End"}, - {KEY_LEFT ,"Left"}, - {KEY_UP ,"Up"}, - {KEY_RIGHT ,"Right"}, - {KEY_DOWN ,"Down"}, - {KEY_PAGEUP ,"PageUp"}, - {KEY_PAGEDOWN ,"PageDown"}, - {KEY_SHIFT ,"Shift"}, - {KEY_CTRL ,"Ctrl"}, + {Key::ESCAPE ,"Escape"}, + {Key::TAB ,"Tab"}, + {Key::BACKTAB ,"BackTab"}, + {Key::BACKSPACE ,"BackSpace"}, + {Key::ENTER ,"Enter"}, + {Key::KP_ENTER ,"Kp Enter"}, + {Key::INSERT ,"Insert"}, + {Key::KEY_DELETE ,"Delete"}, + {Key::PAUSE ,"Pause"}, + {Key::PRINT ,"Print"}, + {Key::SYSREQ ,"SysReq"}, + {Key::CLEAR ,"Clear"}, + {Key::HOME ,"Home"}, + {Key::END ,"End"}, + {Key::LEFT ,"Left"}, + {Key::UP ,"Up"}, + {Key::RIGHT ,"Right"}, + {Key::DOWN ,"Down"}, + {Key::PAGEUP ,"PageUp"}, + {Key::PAGEDOWN ,"PageDown"}, + {Key::SHIFT ,"Shift"}, + {Key::CTRL ,"Ctrl"}, #ifdef OSX_ENABLED - {KEY_META ,"Command"}, + {Key::META ,"Command"}, #else - {KEY_META ,"Meta"}, + {Key::META ,"Meta"}, #endif - {KEY_ALT ,"Alt"}, - {KEY_CAPSLOCK ,"CapsLock"}, - {KEY_NUMLOCK ,"NumLock"}, - {KEY_SCROLLLOCK ,"ScrollLock"}, - {KEY_F1 ,"F1"}, - {KEY_F2 ,"F2"}, - {KEY_F3 ,"F3"}, - {KEY_F4 ,"F4"}, - {KEY_F5 ,"F5"}, - {KEY_F6 ,"F6"}, - {KEY_F7 ,"F7"}, - {KEY_F8 ,"F8"}, - {KEY_F9 ,"F9"}, - {KEY_F10 ,"F10"}, - {KEY_F11 ,"F11"}, - {KEY_F12 ,"F12"}, - {KEY_F13 ,"F13"}, - {KEY_F14 ,"F14"}, - {KEY_F15 ,"F15"}, - {KEY_F16 ,"F16"}, - {KEY_KP_MULTIPLY ,"Kp Multiply"}, - {KEY_KP_DIVIDE ,"Kp Divide"}, - {KEY_KP_SUBTRACT ,"Kp Subtract"}, - {KEY_KP_PERIOD ,"Kp Period"}, - {KEY_KP_ADD ,"Kp Add"}, - {KEY_KP_0 ,"Kp 0"}, - {KEY_KP_1 ,"Kp 1"}, - {KEY_KP_2 ,"Kp 2"}, - {KEY_KP_3 ,"Kp 3"}, - {KEY_KP_4 ,"Kp 4"}, - {KEY_KP_5 ,"Kp 5"}, - {KEY_KP_6 ,"Kp 6"}, - {KEY_KP_7 ,"Kp 7"}, - {KEY_KP_8 ,"Kp 8"}, - {KEY_KP_9 ,"Kp 9"}, - {KEY_SUPER_L ,"Super L"}, - {KEY_SUPER_R ,"Super R"}, - {KEY_MENU ,"Menu"}, - {KEY_HYPER_L ,"Hyper L"}, - {KEY_HYPER_R ,"Hyper R"}, - {KEY_HELP ,"Help"}, - {KEY_DIRECTION_L ,"Direction L"}, - {KEY_DIRECTION_R ,"Direction R"}, - {KEY_BACK ,"Back"}, - {KEY_FORWARD ,"Forward"}, - {KEY_STOP ,"Stop"}, - {KEY_REFRESH ,"Refresh"}, - {KEY_VOLUMEDOWN ,"VolumeDown"}, - {KEY_VOLUMEMUTE ,"VolumeMute"}, - {KEY_VOLUMEUP ,"VolumeUp"}, - {KEY_BASSBOOST ,"BassBoost"}, - {KEY_BASSUP ,"BassUp"}, - {KEY_BASSDOWN ,"BassDown"}, - {KEY_TREBLEUP ,"TrebleUp"}, - {KEY_TREBLEDOWN ,"TrebleDown"}, - {KEY_MEDIAPLAY ,"MediaPlay"}, - {KEY_MEDIASTOP ,"MediaStop"}, - {KEY_MEDIAPREVIOUS ,"MediaPrevious"}, - {KEY_MEDIANEXT ,"MediaNext"}, - {KEY_MEDIARECORD ,"MediaRecord"}, - {KEY_HOMEPAGE ,"HomePage"}, - {KEY_FAVORITES ,"Favorites"}, - {KEY_SEARCH ,"Search"}, - {KEY_STANDBY ,"StandBy"}, - {KEY_LAUNCHMAIL ,"LaunchMail"}, - {KEY_LAUNCHMEDIA ,"LaunchMedia"}, - {KEY_LAUNCH0 ,"Launch0"}, - {KEY_LAUNCH1 ,"Launch1"}, - {KEY_LAUNCH2 ,"Launch2"}, - {KEY_LAUNCH3 ,"Launch3"}, - {KEY_LAUNCH4 ,"Launch4"}, - {KEY_LAUNCH5 ,"Launch5"}, - {KEY_LAUNCH6 ,"Launch6"}, - {KEY_LAUNCH7 ,"Launch7"}, - {KEY_LAUNCH8 ,"Launch8"}, - {KEY_LAUNCH9 ,"Launch9"}, - {KEY_LAUNCHA ,"LaunchA"}, - {KEY_LAUNCHB ,"LaunchB"}, - {KEY_LAUNCHC ,"LaunchC"}, - {KEY_LAUNCHD ,"LaunchD"}, - {KEY_LAUNCHE ,"LaunchE"}, - {KEY_LAUNCHF ,"LaunchF"}, - - {KEY_UNKNOWN ,"Unknown"}, - - {KEY_SPACE ,"Space"}, - {KEY_EXCLAM ,"Exclam"}, - {KEY_QUOTEDBL ,"QuoteDbl"}, - {KEY_NUMBERSIGN ,"NumberSign"}, - {KEY_DOLLAR ,"Dollar"}, - {KEY_PERCENT ,"Percent"}, - {KEY_AMPERSAND ,"Ampersand"}, - {KEY_APOSTROPHE ,"Apostrophe"}, - {KEY_PARENLEFT ,"ParenLeft"}, - {KEY_PARENRIGHT ,"ParenRight"}, - {KEY_ASTERISK ,"Asterisk"}, - {KEY_PLUS ,"Plus"}, - {KEY_COMMA ,"Comma"}, - {KEY_MINUS ,"Minus"}, - {KEY_PERIOD ,"Period"}, - {KEY_SLASH ,"Slash"}, - {KEY_0 ,"0"}, - {KEY_1 ,"1"}, - {KEY_2 ,"2"}, - {KEY_3 ,"3"}, - {KEY_4 ,"4"}, - {KEY_5 ,"5"}, - {KEY_6 ,"6"}, - {KEY_7 ,"7"}, - {KEY_8 ,"8"}, - {KEY_9 ,"9"}, - {KEY_COLON ,"Colon"}, - {KEY_SEMICOLON ,"Semicolon"}, - {KEY_LESS ,"Less"}, - {KEY_EQUAL ,"Equal"}, - {KEY_GREATER ,"Greater"}, - {KEY_QUESTION ,"Question"}, - {KEY_AT ,"At"}, - {KEY_A ,"A"}, - {KEY_B ,"B"}, - {KEY_C ,"C"}, - {KEY_D ,"D"}, - {KEY_E ,"E"}, - {KEY_F ,"F"}, - {KEY_G ,"G"}, - {KEY_H ,"H"}, - {KEY_I ,"I"}, - {KEY_J ,"J"}, - {KEY_K ,"K"}, - {KEY_L ,"L"}, - {KEY_M ,"M"}, - {KEY_N ,"N"}, - {KEY_O ,"O"}, - {KEY_P ,"P"}, - {KEY_Q ,"Q"}, - {KEY_R ,"R"}, - {KEY_S ,"S"}, - {KEY_T ,"T"}, - {KEY_U ,"U"}, - {KEY_V ,"V"}, - {KEY_W ,"W"}, - {KEY_X ,"X"}, - {KEY_Y ,"Y"}, - {KEY_Z ,"Z"}, - {KEY_BRACKETLEFT ,"BracketLeft"}, - {KEY_BACKSLASH ,"BackSlash"}, - {KEY_BRACKETRIGHT ,"BracketRight"}, - {KEY_ASCIICIRCUM ,"AsciiCircum"}, - {KEY_UNDERSCORE ,"UnderScore"}, - {KEY_QUOTELEFT ,"QuoteLeft"}, - {KEY_BRACELEFT ,"BraceLeft"}, - {KEY_BAR ,"Bar"}, - {KEY_BRACERIGHT ,"BraceRight"}, - {KEY_ASCIITILDE ,"AsciiTilde"}, - {KEY_NOBREAKSPACE ,"NoBreakSpace"}, - {KEY_EXCLAMDOWN ,"ExclamDown"}, - {KEY_CENT ,"Cent"}, - {KEY_STERLING ,"Sterling"}, - {KEY_CURRENCY ,"Currency"}, - {KEY_YEN ,"Yen"}, - {KEY_BROKENBAR ,"BrokenBar"}, - {KEY_SECTION ,"Section"}, - {KEY_DIAERESIS ,"Diaeresis"}, - {KEY_COPYRIGHT ,"Copyright"}, - {KEY_ORDFEMININE ,"Ordfeminine"}, - {KEY_GUILLEMOTLEFT ,"GuillemotLeft"}, - {KEY_NOTSIGN ,"NotSign"}, - {KEY_HYPHEN ,"Hyphen"}, - {KEY_REGISTERED ,"Registered"}, - {KEY_MACRON ,"Macron"}, - {KEY_DEGREE ,"Degree"}, - {KEY_PLUSMINUS ,"PlusMinus"}, - {KEY_TWOSUPERIOR ,"TwoSuperior"}, - {KEY_THREESUPERIOR ,"ThreeSuperior"}, - {KEY_ACUTE ,"Acute"}, - {KEY_MU ,"Mu"}, - {KEY_PARAGRAPH ,"Paragraph"}, - {KEY_PERIODCENTERED ,"PeriodCentered"}, - {KEY_CEDILLA ,"Cedilla"}, - {KEY_ONESUPERIOR ,"OneSuperior"}, - {KEY_MASCULINE ,"Masculine"}, - {KEY_GUILLEMOTRIGHT ,"GuillemotRight"}, - {KEY_ONEQUARTER ,"OneQuarter"}, - {KEY_ONEHALF ,"OneHalf"}, - {KEY_THREEQUARTERS ,"ThreeQuarters"}, - {KEY_QUESTIONDOWN ,"QuestionDown"}, - {KEY_AGRAVE ,"Agrave"}, - {KEY_AACUTE ,"Aacute"}, - {KEY_ACIRCUMFLEX ,"AcircumFlex"}, - {KEY_ATILDE ,"Atilde"}, - {KEY_ADIAERESIS ,"Adiaeresis"}, - {KEY_ARING ,"Aring"}, - {KEY_AE ,"Ae"}, - {KEY_CCEDILLA ,"Ccedilla"}, - {KEY_EGRAVE ,"Egrave"}, - {KEY_EACUTE ,"Eacute"}, - {KEY_ECIRCUMFLEX ,"Ecircumflex"}, - {KEY_EDIAERESIS ,"Ediaeresis"}, - {KEY_IGRAVE ,"Igrave"}, - {KEY_IACUTE ,"Iacute"}, - {KEY_ICIRCUMFLEX ,"Icircumflex"}, - {KEY_IDIAERESIS ,"Idiaeresis"}, - {KEY_ETH ,"Eth"}, - {KEY_NTILDE ,"Ntilde"}, - {KEY_OGRAVE ,"Ograve"}, - {KEY_OACUTE ,"Oacute"}, - {KEY_OCIRCUMFLEX ,"Ocircumflex"}, - {KEY_OTILDE ,"Otilde"}, - {KEY_ODIAERESIS ,"Odiaeresis"}, - {KEY_MULTIPLY ,"Multiply"}, - {KEY_OOBLIQUE ,"Ooblique"}, - {KEY_UGRAVE ,"Ugrave"}, - {KEY_UACUTE ,"Uacute"}, - {KEY_UCIRCUMFLEX ,"Ucircumflex"}, - {KEY_UDIAERESIS ,"Udiaeresis"}, - {KEY_YACUTE ,"Yacute"}, - {KEY_THORN ,"Thorn"}, - {KEY_SSHARP ,"Ssharp"}, - - {KEY_DIVISION ,"Division"}, - {KEY_YDIAERESIS ,"Ydiaeresis"}, - {0 ,nullptr} + {Key::ALT ,"Alt"}, + {Key::CAPSLOCK ,"CapsLock"}, + {Key::NUMLOCK ,"NumLock"}, + {Key::SCROLLLOCK ,"ScrollLock"}, + {Key::F1 ,"F1"}, + {Key::F2 ,"F2"}, + {Key::F3 ,"F3"}, + {Key::F4 ,"F4"}, + {Key::F5 ,"F5"}, + {Key::F6 ,"F6"}, + {Key::F7 ,"F7"}, + {Key::F8 ,"F8"}, + {Key::F9 ,"F9"}, + {Key::F10 ,"F10"}, + {Key::F11 ,"F11"}, + {Key::F12 ,"F12"}, + {Key::F13 ,"F13"}, + {Key::F14 ,"F14"}, + {Key::F15 ,"F15"}, + {Key::F16 ,"F16"}, + {Key::KP_MULTIPLY ,"Kp Multiply"}, + {Key::KP_DIVIDE ,"Kp Divide"}, + {Key::KP_SUBTRACT ,"Kp Subtract"}, + {Key::KP_PERIOD ,"Kp Period"}, + {Key::KP_ADD ,"Kp Add"}, + {Key::KP_0 ,"Kp 0"}, + {Key::KP_1 ,"Kp 1"}, + {Key::KP_2 ,"Kp 2"}, + {Key::KP_3 ,"Kp 3"}, + {Key::KP_4 ,"Kp 4"}, + {Key::KP_5 ,"Kp 5"}, + {Key::KP_6 ,"Kp 6"}, + {Key::KP_7 ,"Kp 7"}, + {Key::KP_8 ,"Kp 8"}, + {Key::KP_9 ,"Kp 9"}, + {Key::SUPER_L ,"Super L"}, + {Key::SUPER_R ,"Super R"}, + {Key::MENU ,"Menu"}, + {Key::HYPER_L ,"Hyper L"}, + {Key::HYPER_R ,"Hyper R"}, + {Key::HELP ,"Help"}, + {Key::DIRECTION_L ,"Direction L"}, + {Key::DIRECTION_R ,"Direction R"}, + {Key::BACK ,"Back"}, + {Key::FORWARD ,"Forward"}, + {Key::STOP ,"Stop"}, + {Key::REFRESH ,"Refresh"}, + {Key::VOLUMEDOWN ,"VolumeDown"}, + {Key::VOLUMEMUTE ,"VolumeMute"}, + {Key::VOLUMEUP ,"VolumeUp"}, + {Key::BASSBOOST ,"BassBoost"}, + {Key::BASSUP ,"BassUp"}, + {Key::BASSDOWN ,"BassDown"}, + {Key::TREBLEUP ,"TrebleUp"}, + {Key::TREBLEDOWN ,"TrebleDown"}, + {Key::MEDIAPLAY ,"MediaPlay"}, + {Key::MEDIASTOP ,"MediaStop"}, + {Key::MEDIAPREVIOUS ,"MediaPrevious"}, + {Key::MEDIANEXT ,"MediaNext"}, + {Key::MEDIARECORD ,"MediaRecord"}, + {Key::HOMEPAGE ,"HomePage"}, + {Key::FAVORITES ,"Favorites"}, + {Key::SEARCH ,"Search"}, + {Key::STANDBY ,"StandBy"}, + {Key::LAUNCHMAIL ,"LaunchMail"}, + {Key::LAUNCHMEDIA ,"LaunchMedia"}, + {Key::LAUNCH0 ,"Launch0"}, + {Key::LAUNCH1 ,"Launch1"}, + {Key::LAUNCH2 ,"Launch2"}, + {Key::LAUNCH3 ,"Launch3"}, + {Key::LAUNCH4 ,"Launch4"}, + {Key::LAUNCH5 ,"Launch5"}, + {Key::LAUNCH6 ,"Launch6"}, + {Key::LAUNCH7 ,"Launch7"}, + {Key::LAUNCH8 ,"Launch8"}, + {Key::LAUNCH9 ,"Launch9"}, + {Key::LAUNCHA ,"LaunchA"}, + {Key::LAUNCHB ,"LaunchB"}, + {Key::LAUNCHC ,"LaunchC"}, + {Key::LAUNCHD ,"LaunchD"}, + {Key::LAUNCHE ,"LaunchE"}, + {Key::LAUNCHF ,"LaunchF"}, + {Key::UNKNOWN ,"Unknown"}, + {Key::SPACE ,"Space"}, + {Key::EXCLAM ,"Exclam"}, + {Key::QUOTEDBL ,"QuoteDbl"}, + {Key::NUMBERSIGN ,"NumberSign"}, + {Key::DOLLAR ,"Dollar"}, + {Key::PERCENT ,"Percent"}, + {Key::AMPERSAND ,"Ampersand"}, + {Key::APOSTROPHE ,"Apostrophe"}, + {Key::PARENLEFT ,"ParenLeft"}, + {Key::PARENRIGHT ,"ParenRight"}, + {Key::ASTERISK ,"Asterisk"}, + {Key::PLUS ,"Plus"}, + {Key::COMMA ,"Comma"}, + {Key::MINUS ,"Minus"}, + {Key::PERIOD ,"Period"}, + {Key::SLASH ,"Slash"}, + {Key::KEY_0 ,"0"}, + {Key::KEY_1 ,"1"}, + {Key::KEY_2 ,"2"}, + {Key::KEY_3 ,"3"}, + {Key::KEY_4 ,"4"}, + {Key::KEY_5 ,"5"}, + {Key::KEY_6 ,"6"}, + {Key::KEY_7 ,"7"}, + {Key::KEY_8 ,"8"}, + {Key::KEY_9 ,"9"}, + {Key::COLON ,"Colon"}, + {Key::SEMICOLON ,"Semicolon"}, + {Key::LESS ,"Less"}, + {Key::EQUAL ,"Equal"}, + {Key::GREATER ,"Greater"}, + {Key::QUESTION ,"Question"}, + {Key::AT ,"At"}, + {Key::A ,"A"}, + {Key::B ,"B"}, + {Key::C ,"C"}, + {Key::D ,"D"}, + {Key::E ,"E"}, + {Key::F ,"F"}, + {Key::G ,"G"}, + {Key::H ,"H"}, + {Key::I ,"I"}, + {Key::J ,"J"}, + {Key::K ,"K"}, + {Key::L ,"L"}, + {Key::M ,"M"}, + {Key::N ,"N"}, + {Key::O ,"O"}, + {Key::P ,"P"}, + {Key::Q ,"Q"}, + {Key::R ,"R"}, + {Key::S ,"S"}, + {Key::T ,"T"}, + {Key::U ,"U"}, + {Key::V ,"V"}, + {Key::W ,"W"}, + {Key::X ,"X"}, + {Key::Y ,"Y"}, + {Key::Z ,"Z"}, + {Key::BRACKETLEFT ,"BracketLeft"}, + {Key::BACKSLASH ,"BackSlash"}, + {Key::BRACKETRIGHT ,"BracketRight"}, + {Key::ASCIICIRCUM ,"AsciiCircum"}, + {Key::UNDERSCORE ,"UnderScore"}, + {Key::QUOTELEFT ,"QuoteLeft"}, + {Key::BRACELEFT ,"BraceLeft"}, + {Key::BAR ,"Bar"}, + {Key::BRACERIGHT ,"BraceRight"}, + {Key::ASCIITILDE ,"AsciiTilde"}, + {Key::NOBREAKSPACE ,"NoBreakSpace"}, + {Key::EXCLAMDOWN ,"ExclamDown"}, + {Key::CENT ,"Cent"}, + {Key::STERLING ,"Sterling"}, + {Key::CURRENCY ,"Currency"}, + {Key::YEN ,"Yen"}, + {Key::BROKENBAR ,"BrokenBar"}, + {Key::SECTION ,"Section"}, + {Key::DIAERESIS ,"Diaeresis"}, + {Key::COPYRIGHT ,"Copyright"}, + {Key::ORDFEMININE ,"Ordfeminine"}, + {Key::GUILLEMOTLEFT ,"GuillemotLeft"}, + {Key::NOTSIGN ,"NotSign"}, + {Key::HYPHEN ,"Hyphen"}, + {Key::KEY_REGISTERED ,"Registered"}, + {Key::MACRON ,"Macron"}, + {Key::DEGREE ,"Degree"}, + {Key::PLUSMINUS ,"PlusMinus"}, + {Key::TWOSUPERIOR ,"TwoSuperior"}, + {Key::THREESUPERIOR ,"ThreeSuperior"}, + {Key::ACUTE ,"Acute"}, + {Key::MU ,"Mu"}, + {Key::PARAGRAPH ,"Paragraph"}, + {Key::PERIODCENTERED ,"PeriodCentered"}, + {Key::CEDILLA ,"Cedilla"}, + {Key::ONESUPERIOR ,"OneSuperior"}, + {Key::MASCULINE ,"Masculine"}, + {Key::GUILLEMOTRIGHT ,"GuillemotRight"}, + {Key::ONEQUARTER ,"OneQuarter"}, + {Key::ONEHALF ,"OneHalf"}, + {Key::THREEQUARTERS ,"ThreeQuarters"}, + {Key::QUESTIONDOWN ,"QuestionDown"}, + {Key::AGRAVE ,"Agrave"}, + {Key::AACUTE ,"Aacute"}, + {Key::ACIRCUMFLEX ,"AcircumFlex"}, + {Key::ATILDE ,"Atilde"}, + {Key::ADIAERESIS ,"Adiaeresis"}, + {Key::ARING ,"Aring"}, + {Key::AE ,"Ae"}, + {Key::CCEDILLA ,"Ccedilla"}, + {Key::EGRAVE ,"Egrave"}, + {Key::EACUTE ,"Eacute"}, + {Key::ECIRCUMFLEX ,"Ecircumflex"}, + {Key::EDIAERESIS ,"Ediaeresis"}, + {Key::IGRAVE ,"Igrave"}, + {Key::IACUTE ,"Iacute"}, + {Key::ICIRCUMFLEX ,"Icircumflex"}, + {Key::IDIAERESIS ,"Idiaeresis"}, + {Key::ETH ,"Eth"}, + {Key::NTILDE ,"Ntilde"}, + {Key::OGRAVE ,"Ograve"}, + {Key::OACUTE ,"Oacute"}, + {Key::OCIRCUMFLEX ,"Ocircumflex"}, + {Key::OTILDE ,"Otilde"}, + {Key::ODIAERESIS ,"Odiaeresis"}, + {Key::MULTIPLY ,"Multiply"}, + {Key::OOBLIQUE ,"Ooblique"}, + {Key::UGRAVE ,"Ugrave"}, + {Key::UACUTE ,"Uacute"}, + {Key::UCIRCUMFLEX ,"Ucircumflex"}, + {Key::UDIAERESIS ,"Udiaeresis"}, + {Key::YACUTE ,"Yacute"}, + {Key::THORN ,"Thorn"}, + {Key::SSHARP ,"Ssharp"}, + {Key::DIVISION ,"Division"}, + {Key::YDIAERESIS ,"Ydiaeresis"}, + {Key::NONE ,nullptr} /* clang-format on */ }; -bool keycode_has_unicode(uint32_t p_keycode) { +bool keycode_has_unicode(Key p_keycode) { switch (p_keycode) { - case KEY_ESCAPE: - case KEY_TAB: - case KEY_BACKTAB: - case KEY_BACKSPACE: - case KEY_ENTER: - case KEY_KP_ENTER: - case KEY_INSERT: - case KEY_DELETE: - case KEY_PAUSE: - case KEY_PRINT: - case KEY_SYSREQ: - case KEY_CLEAR: - case KEY_HOME: - case KEY_END: - case KEY_LEFT: - case KEY_UP: - case KEY_RIGHT: - case KEY_DOWN: - case KEY_PAGEUP: - case KEY_PAGEDOWN: - case KEY_SHIFT: - case KEY_CTRL: - case KEY_META: - case KEY_ALT: - case KEY_CAPSLOCK: - case KEY_NUMLOCK: - case KEY_SCROLLLOCK: - case KEY_F1: - case KEY_F2: - case KEY_F3: - case KEY_F4: - case KEY_F5: - case KEY_F6: - case KEY_F7: - case KEY_F8: - case KEY_F9: - case KEY_F10: - case KEY_F11: - case KEY_F12: - case KEY_F13: - case KEY_F14: - case KEY_F15: - case KEY_F16: - case KEY_SUPER_L: - case KEY_SUPER_R: - case KEY_MENU: - case KEY_HYPER_L: - case KEY_HYPER_R: - case KEY_HELP: - case KEY_DIRECTION_L: - case KEY_DIRECTION_R: - case KEY_BACK: - case KEY_FORWARD: - case KEY_STOP: - case KEY_REFRESH: - case KEY_VOLUMEDOWN: - case KEY_VOLUMEMUTE: - case KEY_VOLUMEUP: - case KEY_BASSBOOST: - case KEY_BASSUP: - case KEY_BASSDOWN: - case KEY_TREBLEUP: - case KEY_TREBLEDOWN: - case KEY_MEDIAPLAY: - case KEY_MEDIASTOP: - case KEY_MEDIAPREVIOUS: - case KEY_MEDIANEXT: - case KEY_MEDIARECORD: - case KEY_HOMEPAGE: - case KEY_FAVORITES: - case KEY_SEARCH: - case KEY_STANDBY: - case KEY_OPENURL: - case KEY_LAUNCHMAIL: - case KEY_LAUNCHMEDIA: - case KEY_LAUNCH0: - case KEY_LAUNCH1: - case KEY_LAUNCH2: - case KEY_LAUNCH3: - case KEY_LAUNCH4: - case KEY_LAUNCH5: - case KEY_LAUNCH6: - case KEY_LAUNCH7: - case KEY_LAUNCH8: - case KEY_LAUNCH9: - case KEY_LAUNCHA: - case KEY_LAUNCHB: - case KEY_LAUNCHC: - case KEY_LAUNCHD: - case KEY_LAUNCHE: - case KEY_LAUNCHF: + case Key::ESCAPE: + case Key::TAB: + case Key::BACKTAB: + case Key::BACKSPACE: + case Key::ENTER: + case Key::KP_ENTER: + case Key::INSERT: + case Key::KEY_DELETE: + case Key::PAUSE: + case Key::PRINT: + case Key::SYSREQ: + case Key::CLEAR: + case Key::HOME: + case Key::END: + case Key::LEFT: + case Key::UP: + case Key::RIGHT: + case Key::DOWN: + case Key::PAGEUP: + case Key::PAGEDOWN: + case Key::SHIFT: + case Key::CTRL: + case Key::META: + case Key::ALT: + case Key::CAPSLOCK: + case Key::NUMLOCK: + case Key::SCROLLLOCK: + case Key::F1: + case Key::F2: + case Key::F3: + case Key::F4: + case Key::F5: + case Key::F6: + case Key::F7: + case Key::F8: + case Key::F9: + case Key::F10: + case Key::F11: + case Key::F12: + case Key::F13: + case Key::F14: + case Key::F15: + case Key::F16: + case Key::SUPER_L: + case Key::SUPER_R: + case Key::MENU: + case Key::HYPER_L: + case Key::HYPER_R: + case Key::HELP: + case Key::DIRECTION_L: + case Key::DIRECTION_R: + case Key::BACK: + case Key::FORWARD: + case Key::STOP: + case Key::REFRESH: + case Key::VOLUMEDOWN: + case Key::VOLUMEMUTE: + case Key::VOLUMEUP: + case Key::BASSBOOST: + case Key::BASSUP: + case Key::BASSDOWN: + case Key::TREBLEUP: + case Key::TREBLEDOWN: + case Key::MEDIAPLAY: + case Key::MEDIASTOP: + case Key::MEDIAPREVIOUS: + case Key::MEDIANEXT: + case Key::MEDIARECORD: + case Key::HOMEPAGE: + case Key::FAVORITES: + case Key::SEARCH: + case Key::STANDBY: + case Key::OPENURL: + case Key::LAUNCHMAIL: + case Key::LAUNCHMEDIA: + case Key::LAUNCH0: + case Key::LAUNCH1: + case Key::LAUNCH2: + case Key::LAUNCH3: + case Key::LAUNCH4: + case Key::LAUNCH5: + case Key::LAUNCH6: + case Key::LAUNCH7: + case Key::LAUNCH8: + case Key::LAUNCH9: + case Key::LAUNCHA: + case Key::LAUNCHB: + case Key::LAUNCHC: + case Key::LAUNCHD: + case Key::LAUNCHE: + case Key::LAUNCHF: return false; + default: { + } } return true; } -String keycode_get_string(uint32_t p_code) { +String keycode_get_string(Key p_code) { String codestr; - if (p_code & KEY_MASK_SHIFT) { - codestr += find_keycode_name(KEY_SHIFT); + if ((p_code & KeyModifierMask::SHIFT) != Key::NONE) { + codestr += find_keycode_name(Key::SHIFT); codestr += "+"; } - if (p_code & KEY_MASK_ALT) { - codestr += find_keycode_name(KEY_ALT); + if ((p_code & KeyModifierMask::ALT) != Key::NONE) { + codestr += find_keycode_name(Key::ALT); codestr += "+"; } - if (p_code & KEY_MASK_CTRL) { - codestr += find_keycode_name(KEY_CTRL); + if ((p_code & KeyModifierMask::CTRL) != Key::NONE) { + codestr += find_keycode_name(Key::CTRL); codestr += "+"; } - if (p_code & KEY_MASK_META) { - codestr += find_keycode_name(KEY_META); + if ((p_code & KeyModifierMask::META) != Key::NONE) { + codestr += find_keycode_name(Key::META); codestr += "+"; } - p_code &= KEY_CODE_MASK; + p_code &= KeyModifierMask::CODE_MASK; const _KeyCodeText *kct = &_keycodes[0]; while (kct->text) { - if (kct->code == (int)p_code) { + if (kct->code == p_code) { codestr += kct->text; return codestr; } kct++; } - codestr += String::chr(p_code); + codestr += String::chr((char32_t)p_code); return codestr; } -int find_keycode(const String &p_code) { +Key find_keycode(const String &p_code) { const _KeyCodeText *kct = &_keycodes[0]; while (kct->text) { @@ -436,10 +435,10 @@ int find_keycode(const String &p_code) { kct++; } - return 0; + return Key::NONE; } -const char *find_keycode_name(int p_keycode) { +const char *find_keycode_name(Key p_keycode) { const _KeyCodeText *kct = &_keycodes[0]; while (kct->text) { @@ -464,7 +463,7 @@ int keycode_get_count() { } int keycode_get_value_by_index(int p_index) { - return _keycodes[p_index].code; + return (int)_keycodes[p_index].code; } const char *keycode_get_name_by_index(int p_index) { diff --git a/core/os/keyboard.h b/core/os/keyboard.h index 52174432d9..c780099553 100644 --- a/core/os/keyboard.h +++ b/core/os/keyboard.h @@ -33,148 +33,142 @@ #include "core/string/ustring.h" -/* - Special Key: - - The strategy here is similar to the one used by toolkits, - which consists in leaving the 24 bits unicode range for printable - characters, and use the upper 8 bits for special keys and - modifiers. This way everything (char/keycode) can fit nicely in one 32 bits unsigned integer. -*/ -enum { - SPKEY = (1 << 24) -}; - -enum Key { - KEY_NONE = 0, +enum class Key { + NONE = 0, + // Special key: The strategy here is similar to the one used by toolkits, + // which consists in leaving the 24 bits unicode range for printable + // characters, and use the upper 8 bits for special keys and modifiers. + // This way everything (char/keycode) can fit nicely in one 32-bit + // integer (the enum's underlying type is `int` by default). + SPECIAL = (1 << 24), /* CURSOR/FUNCTION/BROWSER/MULTIMEDIA/MISC KEYS */ - KEY_ESCAPE = SPKEY | 0x01, - KEY_TAB = SPKEY | 0x02, - KEY_BACKTAB = SPKEY | 0x03, - KEY_BACKSPACE = SPKEY | 0x04, - KEY_ENTER = SPKEY | 0x05, - KEY_KP_ENTER = SPKEY | 0x06, - KEY_INSERT = SPKEY | 0x07, - KEY_DELETE = SPKEY | 0x08, - KEY_PAUSE = SPKEY | 0x09, - KEY_PRINT = SPKEY | 0x0A, - KEY_SYSREQ = SPKEY | 0x0B, - KEY_CLEAR = SPKEY | 0x0C, - KEY_HOME = SPKEY | 0x0D, - KEY_END = SPKEY | 0x0E, - KEY_LEFT = SPKEY | 0x0F, - KEY_UP = SPKEY | 0x10, - KEY_RIGHT = SPKEY | 0x11, - KEY_DOWN = SPKEY | 0x12, - KEY_PAGEUP = SPKEY | 0x13, - KEY_PAGEDOWN = SPKEY | 0x14, - KEY_SHIFT = SPKEY | 0x15, - KEY_CTRL = SPKEY | 0x16, - KEY_META = SPKEY | 0x17, - KEY_ALT = SPKEY | 0x18, - KEY_CAPSLOCK = SPKEY | 0x19, - KEY_NUMLOCK = SPKEY | 0x1A, - KEY_SCROLLLOCK = SPKEY | 0x1B, - KEY_F1 = SPKEY | 0x1C, - KEY_F2 = SPKEY | 0x1D, - KEY_F3 = SPKEY | 0x1E, - KEY_F4 = SPKEY | 0x1F, - KEY_F5 = SPKEY | 0x20, - KEY_F6 = SPKEY | 0x21, - KEY_F7 = SPKEY | 0x22, - KEY_F8 = SPKEY | 0x23, - KEY_F9 = SPKEY | 0x24, - KEY_F10 = SPKEY | 0x25, - KEY_F11 = SPKEY | 0x26, - KEY_F12 = SPKEY | 0x27, - KEY_F13 = SPKEY | 0x28, - KEY_F14 = SPKEY | 0x29, - KEY_F15 = SPKEY | 0x2A, - KEY_F16 = SPKEY | 0x2B, - KEY_KP_MULTIPLY = SPKEY | 0x81, - KEY_KP_DIVIDE = SPKEY | 0x82, - KEY_KP_SUBTRACT = SPKEY | 0x83, - KEY_KP_PERIOD = SPKEY | 0x84, - KEY_KP_ADD = SPKEY | 0x85, - KEY_KP_0 = SPKEY | 0x86, - KEY_KP_1 = SPKEY | 0x87, - KEY_KP_2 = SPKEY | 0x88, - KEY_KP_3 = SPKEY | 0x89, - KEY_KP_4 = SPKEY | 0x8A, - KEY_KP_5 = SPKEY | 0x8B, - KEY_KP_6 = SPKEY | 0x8C, - KEY_KP_7 = SPKEY | 0x8D, - KEY_KP_8 = SPKEY | 0x8E, - KEY_KP_9 = SPKEY | 0x8F, - KEY_SUPER_L = SPKEY | 0x2C, - KEY_SUPER_R = SPKEY | 0x2D, - KEY_MENU = SPKEY | 0x2E, - KEY_HYPER_L = SPKEY | 0x2F, - KEY_HYPER_R = SPKEY | 0x30, - KEY_HELP = SPKEY | 0x31, - KEY_DIRECTION_L = SPKEY | 0x32, - KEY_DIRECTION_R = SPKEY | 0x33, - KEY_BACK = SPKEY | 0x40, - KEY_FORWARD = SPKEY | 0x41, - KEY_STOP = SPKEY | 0x42, - KEY_REFRESH = SPKEY | 0x43, - KEY_VOLUMEDOWN = SPKEY | 0x44, - KEY_VOLUMEMUTE = SPKEY | 0x45, - KEY_VOLUMEUP = SPKEY | 0x46, - KEY_BASSBOOST = SPKEY | 0x47, - KEY_BASSUP = SPKEY | 0x48, - KEY_BASSDOWN = SPKEY | 0x49, - KEY_TREBLEUP = SPKEY | 0x4A, - KEY_TREBLEDOWN = SPKEY | 0x4B, - KEY_MEDIAPLAY = SPKEY | 0x4C, - KEY_MEDIASTOP = SPKEY | 0x4D, - KEY_MEDIAPREVIOUS = SPKEY | 0x4E, - KEY_MEDIANEXT = SPKEY | 0x4F, - KEY_MEDIARECORD = SPKEY | 0x50, - KEY_HOMEPAGE = SPKEY | 0x51, - KEY_FAVORITES = SPKEY | 0x52, - KEY_SEARCH = SPKEY | 0x53, - KEY_STANDBY = SPKEY | 0x54, - KEY_OPENURL = SPKEY | 0x55, - KEY_LAUNCHMAIL = SPKEY | 0x56, - KEY_LAUNCHMEDIA = SPKEY | 0x57, - KEY_LAUNCH0 = SPKEY | 0x58, - KEY_LAUNCH1 = SPKEY | 0x59, - KEY_LAUNCH2 = SPKEY | 0x5A, - KEY_LAUNCH3 = SPKEY | 0x5B, - KEY_LAUNCH4 = SPKEY | 0x5C, - KEY_LAUNCH5 = SPKEY | 0x5D, - KEY_LAUNCH6 = SPKEY | 0x5E, - KEY_LAUNCH7 = SPKEY | 0x5F, - KEY_LAUNCH8 = SPKEY | 0x60, - KEY_LAUNCH9 = SPKEY | 0x61, - KEY_LAUNCHA = SPKEY | 0x62, - KEY_LAUNCHB = SPKEY | 0x63, - KEY_LAUNCHC = SPKEY | 0x64, - KEY_LAUNCHD = SPKEY | 0x65, - KEY_LAUNCHE = SPKEY | 0x66, - KEY_LAUNCHF = SPKEY | 0x67, + ESCAPE = SPECIAL | 0x01, + TAB = SPECIAL | 0x02, + BACKTAB = SPECIAL | 0x03, + BACKSPACE = SPECIAL | 0x04, + ENTER = SPECIAL | 0x05, + KP_ENTER = SPECIAL | 0x06, + INSERT = SPECIAL | 0x07, + KEY_DELETE = SPECIAL | 0x08, // "DELETE" is a reserved word on Windows. + PAUSE = SPECIAL | 0x09, + PRINT = SPECIAL | 0x0A, + SYSREQ = SPECIAL | 0x0B, + CLEAR = SPECIAL | 0x0C, + HOME = SPECIAL | 0x0D, + END = SPECIAL | 0x0E, + LEFT = SPECIAL | 0x0F, + UP = SPECIAL | 0x10, + RIGHT = SPECIAL | 0x11, + DOWN = SPECIAL | 0x12, + PAGEUP = SPECIAL | 0x13, + PAGEDOWN = SPECIAL | 0x14, + SHIFT = SPECIAL | 0x15, + CTRL = SPECIAL | 0x16, + META = SPECIAL | 0x17, + ALT = SPECIAL | 0x18, + CAPSLOCK = SPECIAL | 0x19, + NUMLOCK = SPECIAL | 0x1A, + SCROLLLOCK = SPECIAL | 0x1B, + F1 = SPECIAL | 0x1C, + F2 = SPECIAL | 0x1D, + F3 = SPECIAL | 0x1E, + F4 = SPECIAL | 0x1F, + F5 = SPECIAL | 0x20, + F6 = SPECIAL | 0x21, + F7 = SPECIAL | 0x22, + F8 = SPECIAL | 0x23, + F9 = SPECIAL | 0x24, + F10 = SPECIAL | 0x25, + F11 = SPECIAL | 0x26, + F12 = SPECIAL | 0x27, + F13 = SPECIAL | 0x28, + F14 = SPECIAL | 0x29, + F15 = SPECIAL | 0x2A, + F16 = SPECIAL | 0x2B, + KP_MULTIPLY = SPECIAL | 0x81, + KP_DIVIDE = SPECIAL | 0x82, + KP_SUBTRACT = SPECIAL | 0x83, + KP_PERIOD = SPECIAL | 0x84, + KP_ADD = SPECIAL | 0x85, + KP_0 = SPECIAL | 0x86, + KP_1 = SPECIAL | 0x87, + KP_2 = SPECIAL | 0x88, + KP_3 = SPECIAL | 0x89, + KP_4 = SPECIAL | 0x8A, + KP_5 = SPECIAL | 0x8B, + KP_6 = SPECIAL | 0x8C, + KP_7 = SPECIAL | 0x8D, + KP_8 = SPECIAL | 0x8E, + KP_9 = SPECIAL | 0x8F, + SUPER_L = SPECIAL | 0x2C, + SUPER_R = SPECIAL | 0x2D, + MENU = SPECIAL | 0x2E, + HYPER_L = SPECIAL | 0x2F, + HYPER_R = SPECIAL | 0x30, + HELP = SPECIAL | 0x31, + DIRECTION_L = SPECIAL | 0x32, + DIRECTION_R = SPECIAL | 0x33, + BACK = SPECIAL | 0x40, + FORWARD = SPECIAL | 0x41, + STOP = SPECIAL | 0x42, + REFRESH = SPECIAL | 0x43, + VOLUMEDOWN = SPECIAL | 0x44, + VOLUMEMUTE = SPECIAL | 0x45, + VOLUMEUP = SPECIAL | 0x46, + BASSBOOST = SPECIAL | 0x47, + BASSUP = SPECIAL | 0x48, + BASSDOWN = SPECIAL | 0x49, + TREBLEUP = SPECIAL | 0x4A, + TREBLEDOWN = SPECIAL | 0x4B, + MEDIAPLAY = SPECIAL | 0x4C, + MEDIASTOP = SPECIAL | 0x4D, + MEDIAPREVIOUS = SPECIAL | 0x4E, + MEDIANEXT = SPECIAL | 0x4F, + MEDIARECORD = SPECIAL | 0x50, + HOMEPAGE = SPECIAL | 0x51, + FAVORITES = SPECIAL | 0x52, + SEARCH = SPECIAL | 0x53, + STANDBY = SPECIAL | 0x54, + OPENURL = SPECIAL | 0x55, + LAUNCHMAIL = SPECIAL | 0x56, + LAUNCHMEDIA = SPECIAL | 0x57, + LAUNCH0 = SPECIAL | 0x58, + LAUNCH1 = SPECIAL | 0x59, + LAUNCH2 = SPECIAL | 0x5A, + LAUNCH3 = SPECIAL | 0x5B, + LAUNCH4 = SPECIAL | 0x5C, + LAUNCH5 = SPECIAL | 0x5D, + LAUNCH6 = SPECIAL | 0x5E, + LAUNCH7 = SPECIAL | 0x5F, + LAUNCH8 = SPECIAL | 0x60, + LAUNCH9 = SPECIAL | 0x61, + LAUNCHA = SPECIAL | 0x62, + LAUNCHB = SPECIAL | 0x63, + LAUNCHC = SPECIAL | 0x64, + LAUNCHD = SPECIAL | 0x65, + LAUNCHE = SPECIAL | 0x66, + LAUNCHF = SPECIAL | 0x67, - KEY_UNKNOWN = SPKEY | 0xFFFFFF, + UNKNOWN = SPECIAL | 0xFFFFFF, /* PRINTABLE LATIN 1 CODES */ - KEY_SPACE = 0x0020, - KEY_EXCLAM = 0x0021, - KEY_QUOTEDBL = 0x0022, - KEY_NUMBERSIGN = 0x0023, - KEY_DOLLAR = 0x0024, - KEY_PERCENT = 0x0025, - KEY_AMPERSAND = 0x0026, - KEY_APOSTROPHE = 0x0027, - KEY_PARENLEFT = 0x0028, - KEY_PARENRIGHT = 0x0029, - KEY_ASTERISK = 0x002A, - KEY_PLUS = 0x002B, - KEY_COMMA = 0x002C, - KEY_MINUS = 0x002D, - KEY_PERIOD = 0x002E, - KEY_SLASH = 0x002F, + SPACE = 0x0020, + EXCLAM = 0x0021, + QUOTEDBL = 0x0022, + NUMBERSIGN = 0x0023, + DOLLAR = 0x0024, + PERCENT = 0x0025, + AMPERSAND = 0x0026, + APOSTROPHE = 0x0027, + PARENLEFT = 0x0028, + PARENRIGHT = 0x0029, + ASTERISK = 0x002A, + PLUS = 0x002B, + COMMA = 0x002C, + MINUS = 0x002D, + PERIOD = 0x002E, + SLASH = 0x002F, KEY_0 = 0x0030, KEY_1 = 0x0031, KEY_2 = 0x0032, @@ -185,134 +179,133 @@ enum Key { KEY_7 = 0x0037, KEY_8 = 0x0038, KEY_9 = 0x0039, - KEY_COLON = 0x003A, - KEY_SEMICOLON = 0x003B, - KEY_LESS = 0x003C, - KEY_EQUAL = 0x003D, - KEY_GREATER = 0x003E, - KEY_QUESTION = 0x003F, - KEY_AT = 0x0040, - KEY_A = 0x0041, - KEY_B = 0x0042, - KEY_C = 0x0043, - KEY_D = 0x0044, - KEY_E = 0x0045, - KEY_F = 0x0046, - KEY_G = 0x0047, - KEY_H = 0x0048, - KEY_I = 0x0049, - KEY_J = 0x004A, - KEY_K = 0x004B, - KEY_L = 0x004C, - KEY_M = 0x004D, - KEY_N = 0x004E, - KEY_O = 0x004F, - KEY_P = 0x0050, - KEY_Q = 0x0051, - KEY_R = 0x0052, - KEY_S = 0x0053, - KEY_T = 0x0054, - KEY_U = 0x0055, - KEY_V = 0x0056, - KEY_W = 0x0057, - KEY_X = 0x0058, - KEY_Y = 0x0059, - KEY_Z = 0x005A, - KEY_BRACKETLEFT = 0x005B, - KEY_BACKSLASH = 0x005C, - KEY_BRACKETRIGHT = 0x005D, - KEY_ASCIICIRCUM = 0x005E, - KEY_UNDERSCORE = 0x005F, - KEY_QUOTELEFT = 0x0060, - KEY_BRACELEFT = 0x007B, - KEY_BAR = 0x007C, - KEY_BRACERIGHT = 0x007D, - KEY_ASCIITILDE = 0x007E, - KEY_NOBREAKSPACE = 0x00A0, - KEY_EXCLAMDOWN = 0x00A1, - KEY_CENT = 0x00A2, - KEY_STERLING = 0x00A3, - KEY_CURRENCY = 0x00A4, - KEY_YEN = 0x00A5, - KEY_BROKENBAR = 0x00A6, - KEY_SECTION = 0x00A7, - KEY_DIAERESIS = 0x00A8, - KEY_COPYRIGHT = 0x00A9, - KEY_ORDFEMININE = 0x00AA, - KEY_GUILLEMOTLEFT = 0x00AB, - KEY_NOTSIGN = 0x00AC, - KEY_HYPHEN = 0x00AD, - KEY_REGISTERED = 0x00AE, - KEY_MACRON = 0x00AF, - KEY_DEGREE = 0x00B0, - KEY_PLUSMINUS = 0x00B1, - KEY_TWOSUPERIOR = 0x00B2, - KEY_THREESUPERIOR = 0x00B3, - KEY_ACUTE = 0x00B4, - KEY_MU = 0x00B5, - KEY_PARAGRAPH = 0x00B6, - KEY_PERIODCENTERED = 0x00B7, - KEY_CEDILLA = 0x00B8, - KEY_ONESUPERIOR = 0x00B9, - KEY_MASCULINE = 0x00BA, - KEY_GUILLEMOTRIGHT = 0x00BB, - KEY_ONEQUARTER = 0x00BC, - KEY_ONEHALF = 0x00BD, - KEY_THREEQUARTERS = 0x00BE, - KEY_QUESTIONDOWN = 0x00BF, - KEY_AGRAVE = 0x00C0, - KEY_AACUTE = 0x00C1, - KEY_ACIRCUMFLEX = 0x00C2, - KEY_ATILDE = 0x00C3, - KEY_ADIAERESIS = 0x00C4, - KEY_ARING = 0x00C5, - KEY_AE = 0x00C6, - KEY_CCEDILLA = 0x00C7, - KEY_EGRAVE = 0x00C8, - KEY_EACUTE = 0x00C9, - KEY_ECIRCUMFLEX = 0x00CA, - KEY_EDIAERESIS = 0x00CB, - KEY_IGRAVE = 0x00CC, - KEY_IACUTE = 0x00CD, - KEY_ICIRCUMFLEX = 0x00CE, - KEY_IDIAERESIS = 0x00CF, - KEY_ETH = 0x00D0, - KEY_NTILDE = 0x00D1, - KEY_OGRAVE = 0x00D2, - KEY_OACUTE = 0x00D3, - KEY_OCIRCUMFLEX = 0x00D4, - KEY_OTILDE = 0x00D5, - KEY_ODIAERESIS = 0x00D6, - KEY_MULTIPLY = 0x00D7, - KEY_OOBLIQUE = 0x00D8, - KEY_UGRAVE = 0x00D9, - KEY_UACUTE = 0x00DA, - KEY_UCIRCUMFLEX = 0x00DB, - KEY_UDIAERESIS = 0x00DC, - KEY_YACUTE = 0x00DD, - KEY_THORN = 0x00DE, - KEY_SSHARP = 0x00DF, + COLON = 0x003A, + SEMICOLON = 0x003B, + LESS = 0x003C, + EQUAL = 0x003D, + GREATER = 0x003E, + QUESTION = 0x003F, + AT = 0x0040, + A = 0x0041, + B = 0x0042, + C = 0x0043, + D = 0x0044, + E = 0x0045, + F = 0x0046, + G = 0x0047, + H = 0x0048, + I = 0x0049, + J = 0x004A, + K = 0x004B, + L = 0x004C, + M = 0x004D, + N = 0x004E, + O = 0x004F, + P = 0x0050, + Q = 0x0051, + R = 0x0052, + S = 0x0053, + T = 0x0054, + U = 0x0055, + V = 0x0056, + W = 0x0057, + X = 0x0058, + Y = 0x0059, + Z = 0x005A, + BRACKETLEFT = 0x005B, + BACKSLASH = 0x005C, + BRACKETRIGHT = 0x005D, + ASCIICIRCUM = 0x005E, + UNDERSCORE = 0x005F, + QUOTELEFT = 0x0060, + BRACELEFT = 0x007B, + BAR = 0x007C, + BRACERIGHT = 0x007D, + ASCIITILDE = 0x007E, + NOBREAKSPACE = 0x00A0, + EXCLAMDOWN = 0x00A1, + CENT = 0x00A2, + STERLING = 0x00A3, + CURRENCY = 0x00A4, + YEN = 0x00A5, + BROKENBAR = 0x00A6, + SECTION = 0x00A7, + DIAERESIS = 0x00A8, + COPYRIGHT = 0x00A9, + ORDFEMININE = 0x00AA, + GUILLEMOTLEFT = 0x00AB, + NOTSIGN = 0x00AC, + HYPHEN = 0x00AD, + KEY_REGISTERED = 0x00AE, // "REGISTERED" is a reserved word on Windows. + MACRON = 0x00AF, + DEGREE = 0x00B0, + PLUSMINUS = 0x00B1, + TWOSUPERIOR = 0x00B2, + THREESUPERIOR = 0x00B3, + ACUTE = 0x00B4, + MU = 0x00B5, + PARAGRAPH = 0x00B6, + PERIODCENTERED = 0x00B7, + CEDILLA = 0x00B8, + ONESUPERIOR = 0x00B9, + MASCULINE = 0x00BA, + GUILLEMOTRIGHT = 0x00BB, + ONEQUARTER = 0x00BC, + ONEHALF = 0x00BD, + THREEQUARTERS = 0x00BE, + QUESTIONDOWN = 0x00BF, + AGRAVE = 0x00C0, + AACUTE = 0x00C1, + ACIRCUMFLEX = 0x00C2, + ATILDE = 0x00C3, + ADIAERESIS = 0x00C4, + ARING = 0x00C5, + AE = 0x00C6, + CCEDILLA = 0x00C7, + EGRAVE = 0x00C8, + EACUTE = 0x00C9, + ECIRCUMFLEX = 0x00CA, + EDIAERESIS = 0x00CB, + IGRAVE = 0x00CC, + IACUTE = 0x00CD, + ICIRCUMFLEX = 0x00CE, + IDIAERESIS = 0x00CF, + ETH = 0x00D0, + NTILDE = 0x00D1, + OGRAVE = 0x00D2, + OACUTE = 0x00D3, + OCIRCUMFLEX = 0x00D4, + OTILDE = 0x00D5, + ODIAERESIS = 0x00D6, + MULTIPLY = 0x00D7, + OOBLIQUE = 0x00D8, + UGRAVE = 0x00D9, + UACUTE = 0x00DA, + UCIRCUMFLEX = 0x00DB, + UDIAERESIS = 0x00DC, + YACUTE = 0x00DD, + THORN = 0x00DE, + SSHARP = 0x00DF, - KEY_DIVISION = 0x00F7, - KEY_YDIAERESIS = 0x00FF, + DIVISION = 0x00F7, + YDIAERESIS = 0x00FF, + END_LATIN1 = 0x0100, }; -enum KeyModifierMask { - KEY_CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers. - KEY_MODIFIER_MASK = (0xFF << 24), ///< Apply this mask to isolate modifiers. - KEY_MASK_SHIFT = (1 << 25), - KEY_MASK_ALT = (1 << 26), - KEY_MASK_META = (1 << 27), - KEY_MASK_CTRL = (1 << 28), +enum class KeyModifierMask { + CODE_MASK = ((1 << 25) - 1), ///< Apply this mask to any keycode to remove modifiers. + MODIFIER_MASK = (0xFF << 24), ///< Apply this mask to isolate modifiers. + SHIFT = (1 << 25), + ALT = (1 << 26), + META = (1 << 27), + CTRL = (1 << 28), #ifdef APPLE_STYLE_KEYS - KEY_MASK_CMD = KEY_MASK_META, + CMD = META, #else - KEY_MASK_CMD = KEY_MASK_CTRL, + CMD = CTRL, #endif - - KEY_MASK_KPAD = (1 << 29), - KEY_MASK_GROUP_SWITCH = (1 << 30) - // bit 31 can't be used because variant uses regular 32 bits int as datatype + KPAD = (1 << 29), + GROUP_SWITCH = (1 << 30) }; // To avoid having unnecessary operators, only define the ones that are needed. @@ -325,10 +318,26 @@ inline Key &operator-=(Key &a, int b) { return (Key &)((int &)a -= b); } +inline Key operator+(Key a, int 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, 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, Key b) { + return (Key)((int)a | (int)b); +} + inline Key &operator|=(Key &a, Key b) { return (Key &)((int &)a |= (int)b); } @@ -337,6 +346,10 @@ 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); } @@ -361,10 +374,10 @@ 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); -const char *find_keycode_name(int p_keycode); +String keycode_get_string(Key p_code); +bool keycode_has_unicode(Key p_keycode); +Key find_keycode(const String &p_code); +const char *find_keycode_name(Key p_keycode); int keycode_get_count(); int keycode_get_value_by_index(int p_index); const char *keycode_get_name_by_index(int p_index); diff --git a/core/os/midi_driver.cpp b/core/os/midi_driver.cpp index ee87346dfc..ee33eef83f 100644 --- a/core/os/midi_driver.cpp +++ b/core/os/midi_driver.cpp @@ -68,46 +68,46 @@ void MIDIDriver::receive_input_packet(uint64_t timestamp, uint8_t *data, uint32_ } switch (event->get_message()) { - case MIDI_MESSAGE_AFTERTOUCH: + case MIDIMessage::AFTERTOUCH: if (length >= 2 + param_position) { event->set_pitch(data[param_position]); event->set_pressure(data[param_position + 1]); } break; - case MIDI_MESSAGE_CONTROL_CHANGE: + case MIDIMessage::CONTROL_CHANGE: if (length >= 2 + param_position) { event->set_controller_number(data[param_position]); event->set_controller_value(data[param_position + 1]); } break; - case MIDI_MESSAGE_NOTE_ON: - case MIDI_MESSAGE_NOTE_OFF: + case MIDIMessage::NOTE_ON: + case MIDIMessage::NOTE_OFF: if (length >= 2 + param_position) { event->set_pitch(data[param_position]); event->set_velocity(data[param_position + 1]); - if (event->get_message() == MIDI_MESSAGE_NOTE_ON && event->get_velocity() == 0) { + if (event->get_message() == MIDIMessage::NOTE_ON && event->get_velocity() == 0) { // https://www.midi.org/forum/228-writing-midi-software-send-note-off,-or-zero-velocity-note-on - event->set_message(MIDI_MESSAGE_NOTE_OFF); + event->set_message(MIDIMessage::NOTE_OFF); } } break; - case MIDI_MESSAGE_PITCH_BEND: + case MIDIMessage::PITCH_BEND: if (length >= 2 + param_position) { event->set_pitch((data[param_position + 1] << 7) | data[param_position]); } break; - case MIDI_MESSAGE_PROGRAM_CHANGE: + case MIDIMessage::PROGRAM_CHANGE: if (length >= 1 + param_position) { event->set_instrument(data[param_position]); } break; - case MIDI_MESSAGE_CHANNEL_PRESSURE: + case MIDIMessage::CHANNEL_PRESSURE: if (length >= 1 + param_position) { event->set_pressure(data[param_position]); } diff --git a/core/string/ustring.cpp b/core/string/ustring.cpp index 8d6da31cf3..70236231a2 100644 --- a/core/string/ustring.cpp +++ b/core/string/ustring.cpp @@ -38,6 +38,7 @@ #include "core/string/translation.h" #include "core/string/ucaps.h" #include "core/variant/variant.h" +#include "core/version_generated.gen.h" #include <stdio.h> #include <stdlib.h> @@ -952,10 +953,6 @@ const char32_t *String::get_data() const { return size() ? &operator[](0) : &zero; } -void String::erase(int p_pos, int p_chars) { - *this = left(MAX(p_pos, 0)) + substr(p_pos + p_chars, length() - ((p_pos + p_chars))); -} - String String::capitalize() const { String aux = this->camelcase_to_underscore(true).replace("_", " ").strip_edges(); String cap; @@ -4420,7 +4417,7 @@ String String::property_name_encode() const { // as well as '"', '=' or ' ' (32) const char32_t *cstr = get_data(); for (int i = 0; cstr[i]; i++) { - if (cstr[i] == '=' || cstr[i] == '"' || cstr[i] < 33 || cstr[i] > 126) { + if (cstr[i] == '=' || cstr[i] == '"' || cstr[i] == ';' || cstr[i] == '[' || cstr[i] == ']' || cstr[i] < 33 || cstr[i] > 126) { return "\"" + c_escape_multiline() + "\""; } } @@ -4872,15 +4869,20 @@ String TTRN(const String &p_text, const String &p_text_plural, int p_n, const St return p_text_plural; } +/* DTR and DTRN are used for the documentation, handling descriptions extracted + * from the XML. + * They also replace `$DOCS_URL` with the actual URL to the documentation's branch, + * to allow dehardcoding it in the XML and doing proper substitutions everywhere. + */ String DTR(const String &p_text, const String &p_context) { // Comes straight from the XML, so remove indentation and any trailing whitespace. const String text = p_text.dedent().strip_edges(); if (TranslationServer::get_singleton()) { - return TranslationServer::get_singleton()->doc_translate(text, p_context); + return String(TranslationServer::get_singleton()->doc_translate(text, p_context)).replace("$DOCS_URL", VERSION_DOCS_URL); } - return text; + return text.replace("$DOCS_URL", VERSION_DOCS_URL); } String DTRN(const String &p_text, const String &p_text_plural, int p_n, const String &p_context) { @@ -4888,14 +4890,14 @@ String DTRN(const String &p_text, const String &p_text_plural, int p_n, const St const String text_plural = p_text_plural.dedent().strip_edges(); if (TranslationServer::get_singleton()) { - return TranslationServer::get_singleton()->doc_translate_plural(text, text_plural, p_n, p_context); + return String(TranslationServer::get_singleton()->doc_translate_plural(text, text_plural, p_n, p_context)).replace("$DOCS_URL", VERSION_DOCS_URL); } // Return message based on English plural rule if translation is not possible. if (p_n == 1) { - return text; + return text.replace("$DOCS_URL", VERSION_DOCS_URL); } - return text_plural; + return text_plural.replace("$DOCS_URL", VERSION_DOCS_URL); } #endif diff --git a/core/variant/binder_common.h b/core/variant/binder_common.h index f06d767cf5..98be62391f 100644 --- a/core/variant/binder_common.h +++ b/core/variant/binder_common.h @@ -80,7 +80,7 @@ struct VariantCaster<const T &> { } \ typedef int64_t EncodeT; \ _FORCE_INLINE_ static void encode(m_enum p_val, const void *p_ptr) { \ - *(int64_t *)p_ptr = p_val; \ + *(int64_t *)p_ptr = (int64_t)p_val; \ } \ }; diff --git a/core/variant/variant.h b/core/variant/variant.h index 8ce5e7dcd2..230ed33c0c 100644 --- a/core/variant/variant.h +++ b/core/variant/variant.h @@ -31,6 +31,7 @@ #ifndef VARIANT_H #define VARIANT_H +#include "core/input/input_enums.h" #include "core/io/ip_address.h" #include "core/math/aabb.h" #include "core/math/basis.h" @@ -43,6 +44,7 @@ #include "core/math/vector3.h" #include "core/math/vector3i.h" #include "core/object/object_id.h" +#include "core/os/keyboard.h" #include "core/string/node_path.h" #include "core/string/ustring.h" #include "core/templates/rid.h" @@ -430,6 +432,21 @@ public: Variant(const IPAddress &p_address); +#define VARIANT_ENUM_CLASS_CONSTRUCTOR(m_enum) \ + Variant(const m_enum &p_value) { \ + type = INT; \ + _data._int = (int64_t)p_value; \ + } + + // Only enum classes that need to be bound need this to be defined. + VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyAxis) + VARIANT_ENUM_CLASS_CONSTRUCTOR(JoyButton) + VARIANT_ENUM_CLASS_CONSTRUCTOR(Key) + VARIANT_ENUM_CLASS_CONSTRUCTOR(MIDIMessage) + VARIANT_ENUM_CLASS_CONSTRUCTOR(MouseButton) + +#undef VARIANT_ENUM_CLASS_CONSTRUCTOR + // If this changes the table in variant_op must be updated enum Operator { //comparison diff --git a/core/variant/variant_call.cpp b/core/variant/variant_call.cpp index c3fe443456..65ea969146 100644 --- a/core/variant/variant_call.cpp +++ b/core/variant/variant_call.cpp @@ -1412,8 +1412,6 @@ static void _register_variant_builtin_methods() { bind_method(String, plus_file, sarray("file"), varray()); bind_method(String, unicode_at, sarray("at"), varray()); bind_method(String, dedent, sarray(), varray()); - // FIXME: String needs to be immutable when binding - //bind_method(String, erase, sarray("position", "chars"), varray()); bind_method(String, hash, sarray(), varray()); bind_method(String, md5_text, sarray(), varray()); bind_method(String, sha1_text, sarray(), varray()); @@ -1422,8 +1420,6 @@ static void _register_variant_builtin_methods() { bind_method(String, sha1_buffer, sarray(), varray()); bind_method(String, sha256_buffer, sarray(), varray()); bind_method(String, is_empty, sarray(), varray()); - // FIXME: Static function, not sure how to bind - //bind_method(String, humanize_size, sarray("size"), varray()); bind_method(String, is_absolute_path, sarray(), varray()); bind_method(String, is_relative_path, sarray(), varray()); @@ -1635,17 +1631,15 @@ static void _register_variant_builtin_methods() { bind_method(Color, to_argb64, sarray(), varray()); bind_method(Color, to_abgr64, sarray(), varray()); bind_method(Color, to_rgba64, sarray(), varray()); + bind_method(Color, to_html, sarray("with_alpha"), varray(true)); bind_method(Color, clamp, sarray("min", "max"), varray(Color(0, 0, 0, 0), Color(1, 1, 1, 1))); bind_method(Color, inverted, sarray(), varray()); bind_method(Color, lerp, sarray("to", "weight"), varray()); bind_method(Color, lightened, sarray("amount"), varray()); bind_method(Color, darkened, sarray("amount"), varray()); - bind_method(Color, to_html, sarray("with_alpha"), varray(true)); bind_method(Color, blend, sarray("over"), varray()); - // FIXME: Color is immutable, need to probably find a way to do this via constructor - //ADDFUNC4R(COLOR, COLOR, Color, from_hsv, FLOAT, "h", FLOAT, "s", FLOAT, "v", FLOAT, "a", varray(1.0)); bind_method(Color, is_equal_approx, sarray("to"), varray()); bind_static_method(Color, hex, sarray("hex"), varray()); @@ -1657,6 +1651,7 @@ static void _register_variant_builtin_methods() { bind_static_method(Color, get_named_color_name, sarray("idx"), varray()); bind_static_method(Color, get_named_color, sarray("idx"), varray()); bind_static_method(Color, from_string, sarray("str", "default"), varray()); + bind_static_method(Color, from_hsv, sarray("h", "s", "v", "alpha"), varray(1.0)); bind_static_method(Color, from_rgbe9995, sarray("rgbe"), varray()); /* RID */ diff --git a/core/variant/variant_utility.cpp b/core/variant/variant_utility.cpp index 666b582e39..e89bdd4faa 100644 --- a/core/variant/variant_utility.cpp +++ b/core/variant/variant_utility.cpp @@ -275,6 +275,10 @@ struct VariantUtilityFunctions { return Math::wrapf(value, min, max); } + static inline double pingpong(double value, double length) { + return Math::pingpong(value, length); + } + static inline Variant max(const Variant **p_args, int p_argcount, Callable::CallError &r_error) { if (p_argcount < 2) { r_error.error = Callable::CallError::CALL_ERROR_TOO_FEW_ARGUMENTS; @@ -1226,6 +1230,7 @@ void Variant::_register_variant_utility_functions() { FUNCBINDR(clampf, sarray("value", "min", "max"), Variant::UTILITY_FUNC_TYPE_MATH); FUNCBINDR(nearest_po2, sarray("value"), Variant::UTILITY_FUNC_TYPE_MATH); + FUNCBINDR(pingpong, sarray("value", "length"), Variant::UTILITY_FUNC_TYPE_MATH); // Random |