mirror of
https://github.com/godotengine/godot.git
synced 2026-01-03 18:11:19 +03:00
Augment the InputEvent class with a CANCELED state
The `InputEvent` class currently supports the `pressed` and `released` states, which given the binary nature, is represented by a `bool` field. This commit introduced the `CANCELED` state, which signals that an ongoing input event has been canceled. To represent all the states, the `InputEventState` enum is added and the `InputEvent` logic is refactored accordingly.
This commit is contained in:
@@ -56,6 +56,9 @@ class InputEvent : public Resource {
|
||||
int device = 0;
|
||||
|
||||
protected:
|
||||
bool canceled = false;
|
||||
bool pressed = false;
|
||||
|
||||
static void _bind_methods();
|
||||
|
||||
public:
|
||||
@@ -71,8 +74,9 @@ public:
|
||||
float get_action_strength(const StringName &p_action, bool p_exact_match = false) const;
|
||||
float get_action_raw_strength(const StringName &p_action, bool p_exact_match = false) const;
|
||||
|
||||
// To be removed someday, since they do not make sense for all events
|
||||
virtual bool is_pressed() const;
|
||||
bool is_canceled() const;
|
||||
bool is_pressed() const;
|
||||
bool is_released() const;
|
||||
virtual bool is_echo() const;
|
||||
|
||||
virtual String as_text() const = 0;
|
||||
@@ -149,8 +153,6 @@ public:
|
||||
class InputEventKey : public InputEventWithModifiers {
|
||||
GDCLASS(InputEventKey, InputEventWithModifiers);
|
||||
|
||||
bool pressed = false; /// otherwise release
|
||||
|
||||
Key keycode = Key::NONE; // Key enum, without modifier masks.
|
||||
Key physical_keycode = Key::NONE;
|
||||
Key key_label = Key::NONE;
|
||||
@@ -163,7 +165,6 @@ protected:
|
||||
|
||||
public:
|
||||
void set_pressed(bool p_pressed);
|
||||
virtual bool is_pressed() const override;
|
||||
|
||||
void set_keycode(Key p_keycode);
|
||||
Key get_keycode() const;
|
||||
@@ -229,7 +230,6 @@ class InputEventMouseButton : public InputEventMouse {
|
||||
|
||||
float factor = 1;
|
||||
MouseButton button_index = MouseButton::NONE;
|
||||
bool pressed = false; //otherwise released
|
||||
bool double_click = false; //last even less than double click time
|
||||
|
||||
protected:
|
||||
@@ -243,7 +243,7 @@ public:
|
||||
MouseButton get_button_index() const;
|
||||
|
||||
void set_pressed(bool p_pressed);
|
||||
virtual bool is_pressed() const override;
|
||||
void set_canceled(bool p_canceled);
|
||||
|
||||
void set_double_click(bool p_double_click);
|
||||
bool is_double_click() const;
|
||||
@@ -312,8 +312,6 @@ public:
|
||||
void set_axis_value(float p_value);
|
||||
float get_axis_value() const;
|
||||
|
||||
virtual bool is_pressed() const override;
|
||||
|
||||
virtual bool action_match(const Ref<InputEvent> &p_event, bool p_exact_match, float p_deadzone, bool *r_pressed, float *r_strength, float *r_raw_strength) const override;
|
||||
virtual bool is_match(const Ref<InputEvent> &p_event, bool p_exact_match = true) const override;
|
||||
|
||||
@@ -328,7 +326,6 @@ class InputEventJoypadButton : public InputEvent {
|
||||
GDCLASS(InputEventJoypadButton, InputEvent);
|
||||
|
||||
JoyButton button_index = (JoyButton)0;
|
||||
bool pressed = false;
|
||||
float pressure = 0; //0 to 1
|
||||
protected:
|
||||
static void _bind_methods();
|
||||
@@ -338,7 +335,6 @@ public:
|
||||
JoyButton get_button_index() const;
|
||||
|
||||
void set_pressed(bool p_pressed);
|
||||
virtual bool is_pressed() const override;
|
||||
|
||||
void set_pressure(float p_pressure);
|
||||
float get_pressure() const;
|
||||
@@ -360,7 +356,6 @@ class InputEventScreenTouch : public InputEventFromWindow {
|
||||
GDCLASS(InputEventScreenTouch, InputEventFromWindow);
|
||||
int index = 0;
|
||||
Vector2 pos;
|
||||
bool pressed = false;
|
||||
bool double_tap = false;
|
||||
|
||||
protected:
|
||||
@@ -374,7 +369,7 @@ public:
|
||||
Vector2 get_position() const;
|
||||
|
||||
void set_pressed(bool p_pressed);
|
||||
virtual bool is_pressed() const override;
|
||||
void set_canceled(bool p_canceled);
|
||||
|
||||
void set_double_tap(bool p_double_tap);
|
||||
bool is_double_tap() const;
|
||||
@@ -434,7 +429,6 @@ class InputEventAction : public InputEvent {
|
||||
GDCLASS(InputEventAction, InputEvent);
|
||||
|
||||
StringName action;
|
||||
bool pressed = false;
|
||||
float strength = 1.0f;
|
||||
|
||||
protected:
|
||||
@@ -445,7 +439,6 @@ public:
|
||||
StringName get_action() const;
|
||||
|
||||
void set_pressed(bool p_pressed);
|
||||
virtual bool is_pressed() const override;
|
||||
|
||||
void set_strength(float p_strength);
|
||||
float get_strength() const;
|
||||
@@ -569,7 +562,6 @@ protected:
|
||||
public:
|
||||
void set_shortcut(Ref<Shortcut> p_shortcut);
|
||||
Ref<Shortcut> get_shortcut();
|
||||
virtual bool is_pressed() const override;
|
||||
|
||||
virtual String as_text() const override;
|
||||
virtual String to_string() override;
|
||||
|
||||
Reference in New Issue
Block a user