diff options
Diffstat (limited to 'core')
-rw-r--r-- | core/os/input_event.cpp | 39 | ||||
-rw-r--r-- | core/os/input_event.h | 4 | ||||
-rw-r--r-- | core/reference.h | 2 | ||||
-rw-r--r-- | core/ustring.cpp | 2 |
4 files changed, 45 insertions, 2 deletions
diff --git a/core/os/input_event.cpp b/core/os/input_event.cpp index dbdf9628e3..e60f588be3 100644 --- a/core/os/input_event.cpp +++ b/core/os/input_event.cpp @@ -89,6 +89,11 @@ bool InputEvent::action_match(const Ref<InputEvent> &p_event) const { return false; } +bool InputEvent::shortcut_match(const Ref<InputEvent> &p_event) const { + + return false; +} + bool InputEvent::is_action_type() const { return false; @@ -130,6 +135,7 @@ void InputEvent::_bind_methods() { ClassDB::bind_method(D_METHOD("as_text"), &InputEvent::as_text); ClassDB::bind_method(D_METHOD("action_match", "event:InputEvent"), &InputEvent::action_match); + ClassDB::bind_method(D_METHOD("shortcut_match", "event:InputEvent"), &InputEvent::shortcut_match); ClassDB::bind_method(D_METHOD("is_action_type"), &InputEvent::is_action_type); @@ -276,6 +282,27 @@ uint32_t InputEventKey::get_scancode_with_modifiers() const { return sc; } +String InputEventKey::as_text() const { + + String kc = keycode_get_string(scancode); + if (kc == String()) + return kc; + + if (get_metakey()) { + kc = "Meta+" + kc; + } + if (get_alt()) { + kc = "Alt+" + kc; + } + if (get_shift()) { + kc = "Shift+" + kc; + } + if (get_control()) { + kc = "Ctrl+" + kc; + } + return kc; +} + bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const { Ref<InputEventKey> key = p_event; @@ -288,6 +315,18 @@ bool InputEventKey::action_match(const Ref<InputEvent> &p_event) const { return get_scancode() == key->get_scancode() && (!key->is_pressed() || (code & event_code) == code); } +bool InputEventKey::shortcut_match(const Ref<InputEvent> &p_event) const { + + Ref<InputEventKey> key = p_event; + if (key.is_null()) + return false; + + uint32_t code = get_scancode_with_modifiers(); + uint32_t event_code = key->get_scancode_with_modifiers(); + + return code == event_code; +} + void InputEventKey::_bind_methods() { ClassDB::bind_method(D_METHOD("set_pressed", "pressed"), &InputEventKey::set_pressed); diff --git a/core/os/input_event.h b/core/os/input_event.h index 6a694df345..b120d4b840 100644 --- a/core/os/input_event.h +++ b/core/os/input_event.h @@ -165,6 +165,7 @@ public: virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const; virtual bool action_match(const Ref<InputEvent> &p_event) const; + virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const; InputEvent(); @@ -243,9 +244,12 @@ public: uint32_t get_scancode_with_modifiers() const; virtual bool action_match(const Ref<InputEvent> &p_event) const; + virtual bool shortcut_match(const Ref<InputEvent> &p_event) const; virtual bool is_action_type() const { return true; } + virtual String as_text() const; + InputEventKey(); }; diff --git a/core/reference.h b/core/reference.h index afc097817a..4e2d6c36c0 100644 --- a/core/reference.h +++ b/core/reference.h @@ -344,7 +344,7 @@ struct PtrToArg<const Ref<T> &> { _FORCE_INLINE_ static Ref<T> convert(const void *p_ptr) { - return Ref<T>(reinterpret_cast<const T *>(p_ptr)); + return Ref<T>((T *)p_ptr); } }; diff --git a/core/ustring.cpp b/core/ustring.cpp index 6a93d7789e..7ccf7fd209 100644 --- a/core/ustring.cpp +++ b/core/ustring.cpp @@ -65,7 +65,7 @@ bool CharString::operator<(const CharString &p_right) const { } const char *this_str = get_data(); - const char *that_str = get_data(); + const char *that_str = p_right.get_data(); while (true) { if (*that_str == 0 && *this_str == 0) |