mirror of
https://github.com/Relintai/pandemonium_engine.git
synced 2024-12-31 16:17:12 +01:00
Backported create_reference() helper methods for InputEvents from godot 4.
This commit is contained in:
parent
cf7b59b6c8
commit
4cdb163626
@ -407,6 +407,38 @@ void InputEventKey::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "action_match_force_exact"), "set_action_match_force_exact", "is_action_match_force_exact");
|
||||
}
|
||||
|
||||
Ref<InputEventKey> InputEventKey::create_reference(uint32_t p_keycode, bool p_physical) {
|
||||
Ref<InputEventKey> ie;
|
||||
ie.instance();
|
||||
|
||||
if (p_physical) {
|
||||
ie->set_physical_scancode(p_keycode & KEY_CODE_MASK);
|
||||
} else {
|
||||
ie->set_scancode(p_keycode & KEY_CODE_MASK);
|
||||
}
|
||||
|
||||
char32_t ch = char32_t(p_keycode & KEY_CODE_MASK);
|
||||
if (ch < 0xd800 || (ch > 0xdfff && ch <= 0x10ffff)) {
|
||||
ie->set_unicode(ch);
|
||||
}
|
||||
|
||||
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_META)) {
|
||||
ie->set_command(true);
|
||||
}
|
||||
|
||||
return ie;
|
||||
}
|
||||
|
||||
InputEventKey::InputEventKey() {
|
||||
scancode = 0;
|
||||
physical_scancode = 0;
|
||||
@ -864,6 +896,15 @@ void InputEventJoypadMotion::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::REAL, "axis_value"), "set_axis_value", "get_axis_value");
|
||||
}
|
||||
|
||||
Ref<InputEventJoypadMotion> InputEventJoypadMotion::create_reference(int p_axis, float p_value) {
|
||||
Ref<InputEventJoypadMotion> ie;
|
||||
ie.instance();
|
||||
ie->set_axis(p_axis);
|
||||
ie->set_axis_value(p_value);
|
||||
|
||||
return ie;
|
||||
}
|
||||
|
||||
InputEventJoypadMotion::InputEventJoypadMotion() {
|
||||
axis = 0;
|
||||
axis_value = 0;
|
||||
@ -940,6 +981,14 @@ void InputEventJoypadButton::_bind_methods() {
|
||||
ADD_PROPERTY(PropertyInfo(Variant::BOOL, "pressed"), "set_pressed", "is_pressed");
|
||||
}
|
||||
|
||||
Ref<InputEventJoypadButton> InputEventJoypadButton::create_reference(int p_btn_index) {
|
||||
Ref<InputEventJoypadButton> ie;
|
||||
ie.instance();
|
||||
ie->set_button_index(p_btn_index);
|
||||
|
||||
return ie;
|
||||
}
|
||||
|
||||
InputEventJoypadButton::InputEventJoypadButton() {
|
||||
button_index = 0;
|
||||
pressure = 0;
|
||||
|
@ -328,6 +328,8 @@ public:
|
||||
|
||||
virtual String as_text() const;
|
||||
|
||||
static Ref<InputEventKey> create_reference(uint32_t p_keycode_with_modifier_masks, bool p_physical = false);
|
||||
|
||||
InputEventKey();
|
||||
};
|
||||
|
||||
@ -446,6 +448,8 @@ public:
|
||||
virtual bool is_action_type() const { return true; }
|
||||
virtual String as_text() const;
|
||||
|
||||
static Ref<InputEventJoypadMotion> create_reference(int p_axis, float p_value);
|
||||
|
||||
InputEventJoypadMotion();
|
||||
};
|
||||
|
||||
@ -472,6 +476,8 @@ public:
|
||||
virtual bool is_action_type() const { return true; }
|
||||
virtual String as_text() const;
|
||||
|
||||
static Ref<InputEventJoypadButton> create_reference(int p_btn_index);
|
||||
|
||||
InputEventJoypadButton();
|
||||
};
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user