summaryrefslogtreecommitdiff
path: root/core/input/input_event.cpp
diff options
context:
space:
mode:
authorEric M <itsjusteza@gmail.com>2020-12-07 21:31:25 +1000
committerEric M <itsjusteza@gmail.com>2021-02-18 16:22:39 +0100
commitca1abc7352ed3d8e9ca82eb4838777270f7c27a9 (patch)
tree0a9628283cedf799715dd4da4fa1141b6a798ef8 /core/input/input_event.cpp
parent5c2fe970b87f8e95306bad0f713567a150b1e442 (diff)
Added convenience create_reference methods for Key and JoyButton inputs
Diffstat (limited to 'core/input/input_event.cpp')
-rw-r--r--core/input/input_event.cpp33
1 files changed, 33 insertions, 0 deletions
diff --git a/core/input/input_event.cpp b/core/input/input_event.cpp
index b1c8f1ad66..c6910d2b1f 100644
--- a/core/input/input_event.cpp
+++ b/core/input/input_event.cpp
@@ -384,6 +384,31 @@ String InputEventKey::to_string() {
return vformat("InputEventKey: keycode=%s mods=%s physical=%s pressed=%s echo=%s", kc, mods, physical, p, e);
}
+Ref<InputEventKey> InputEventKey::create_reference(uint32_t p_keycode) {
+ Ref<InputEventKey> ie;
+ ie.instance();
+ ie->set_keycode(p_keycode & KEY_CODE_MASK);
+ ie->set_unicode(p_keycode & KEY_CODE_MASK);
+
+ if (p_keycode & KEY_MASK_SHIFT) {
+ ie->set_shift(true);
+ }
+ if (p_keycode & KEY_MASK_ALT) {
+ ie->set_alt(true);
+ }
+ if (p_keycode & KEY_MASK_CTRL) {
+ ie->set_control(true);
+ }
+ if (p_keycode & KEY_MASK_CMD) {
+ ie->set_command(true);
+ }
+ if (p_keycode & KEY_MASK_META) {
+ ie->set_metakey(true);
+ }
+
+ return ie;
+}
+
bool InputEventKey::action_match(const Ref<InputEvent> &p_event, bool *p_pressed, float *p_strength, float *p_raw_strength, float p_deadzone) const {
Ref<InputEventKey> key = p_event;
if (key.is_null()) {
@@ -1011,6 +1036,14 @@ String InputEventJoypadButton::to_string() {
return "InputEventJoypadButton : button_index=" + itos(button_index) + ", pressed=" + (pressed ? "true" : "false") + ", pressure=" + String(Variant(pressure));
}
+Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(int p_btn_index) {
+ Ref<InputEventJoypadButton> ie;
+ ie.instance();
+ ie->set_button_index(p_btn_index);
+
+ return ie;
+}
+
void InputEventJoypadButton::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_button_index", "button_index"), &InputEventJoypadButton::set_button_index);
ClassDB::bind_method(D_METHOD("get_button_index"), &InputEventJoypadButton::get_button_index);