summaryrefslogtreecommitdiffstats
path: root/core/os/input_event.h
diff options
context:
space:
mode:
authorJuan Linietsky <reduzio@gmail.com>2017-05-20 12:38:03 -0300
committerJuan Linietsky <reduzio@gmail.com>2017-05-20 17:05:38 -0300
commit5b3709d3096df737b8bb2344446be818b0389bfe (patch)
tree649a0989b1494f3c4687d59e503310f4e6bbeb40 /core/os/input_event.h
parent93f9a83062dbe74474a4a7928758c5cf5588238e (diff)
downloadredot-engine-5b3709d3096df737b8bb2344446be818b0389bfe.tar.gz
Removal of InputEvent as built-in Variant type..
this might cause bugs I haven't found yet..
Diffstat (limited to 'core/os/input_event.h')
-rw-r--r--core/os/input_event.h315
1 files changed, 245 insertions, 70 deletions
diff --git a/core/os/input_event.h b/core/os/input_event.h
index 93cceac27c..b94f0ef46a 100644
--- a/core/os/input_event.h
+++ b/core/os/input_event.h
@@ -32,6 +32,7 @@
#include "math_2d.h"
#include "os/copymem.h"
+#include "resource.h"
#include "typedefs.h"
#include "ustring.h"
/**
@@ -137,7 +138,40 @@ enum {
* Input Modifier Status
* for keyboard/mouse events.
*/
-struct InputModifierState {
+
+class InputEvent : public Resource {
+ GDCLASS(InputEvent, Resource)
+
+ uint32_t id;
+ int device;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_id(uint32_t p_id);
+ uint32_t get_id() const;
+
+ void set_device(int p_device);
+ int get_device() const;
+
+ virtual bool is_pressed() const;
+ virtual bool is_action(const StringName &p_action) const;
+ virtual bool is_action_pressed(const StringName &p_action) const;
+ virtual bool is_action_released(const StringName &p_action) const;
+ virtual bool is_echo() const;
+ virtual String as_text() const;
+
+ 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 is_action_type() const;
+
+ InputEvent();
+};
+
+class InputEventWithModifiers : public InputEvent {
+ GDCLASS(InputEventWithModifiers, InputEvent)
bool shift;
bool alt;
@@ -157,126 +191,267 @@ struct InputModifierState {
#endif
- bool operator==(const InputModifierState &rvalue) const {
+protected:
+ static void _bind_methods();
+
+public:
+ void set_shift(bool p_enabled);
+ bool get_shift() const;
+
+ void set_alt(bool p_enabled);
+ bool get_alt() const;
+
+ void set_control(bool p_enabled);
+ bool get_control() const;
+
+ void set_metakey(bool p_enabled);
+ bool get_metakey() const;
+
+ void set_command(bool p_enabled);
+ bool get_command() const;
- return ((shift == rvalue.shift) && (alt == rvalue.alt) && (control == rvalue.control) && (meta == rvalue.meta));
- }
+ InputEventWithModifiers();
};
-struct InputEventKey {
+class InputEventKey : public InputEventWithModifiers {
- InputModifierState mod;
+ GDCLASS(InputEventKey, InputEventWithModifiers)
bool pressed; /// otherwise release
uint32_t scancode; ///< check keyboard.h , KeyCode enum, without modifier masks
uint32_t unicode; ///unicode
+ bool echo; /// true if this is an echo key
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_pressed(bool p_pressed);
+ bool is_pressed();
+
+ void set_scancode(uint32_t p_scancode);
+ uint32_t get_scancode() const;
+
+ void set_unicode(uint32_t p_unicode);
+ uint32_t get_unicode() const;
+
+ void set_echo(bool p_enable);
+ bool is_echo() const;
+
uint32_t get_scancode_with_modifiers() const;
- bool echo; /// true if this is an echo key
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventKey();
};
-struct InputEventMouse {
+class InputEventMouse : public InputEventWithModifiers {
+
+ GDCLASS(InputEventMouse, InputEventWithModifiers)
- InputModifierState mod;
int button_mask;
- float x, y;
- float global_x, global_y;
- int pointer_index;
+
+ Vector2 pos;
+ Vector2 global_pos;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_button_mask(int p_mask);
+ int get_button_mask() const;
+
+ void set_pos(const Vector2 &p_pos);
+ Vector2 get_pos() const;
+
+ void set_global_pos(const Vector2 &p_global_pos);
+ Vector2 get_global_pos() const;
+
+ InputEventMouse();
};
-struct InputEventMouseButton : public InputEventMouse {
+class InputEventMouseButton : public InputEventMouse {
+
+ GDCLASS(InputEventMouseButton, InputEventMouse)
- double factor;
+ float factor;
int button_index;
bool pressed; //otherwise released
bool doubleclick; //last even less than doubleclick time
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_factor(float p_factor);
+ float get_factor();
+
+ void set_button_index(int p_index);
+ int get_button_index() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ void set_doubleclick(bool p_doubleclick);
+ bool is_doubleclick() const;
+
+ 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 is_action_type() const { return true; }
+
+ InputEventMouseButton();
};
-struct InputEventMouseMotion : public InputEventMouse {
+class InputEventMouseMotion : public InputEventMouse {
+
+ GDCLASS(InputEventMouseMotion, InputEventMouse)
+ Vector2 relative;
+ Vector2 speed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_relative(const Vector2 &p_relative);
+ Vector2 get_relative() const;
+
+ void set_speed(const Vector2 &p_speed);
+ Vector2 get_speed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
- float relative_x, relative_y;
- float speed_x, speed_y;
+ InputEventMouseMotion();
};
-struct InputEventJoypadMotion {
+class InputEventJoypadMotion : public InputEvent {
+ GDCLASS(InputEventJoypadMotion, InputEvent)
int axis; ///< Joypad axis
float axis_value; ///< -1 to 1
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_axis(int p_axis);
+ int get_axis() const;
+
+ void set_axis_value(float p_value);
+ float get_axis_value() const;
+
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventJoypadMotion();
};
-struct InputEventJoypadButton {
+class InputEventJoypadButton : public InputEvent {
+ GDCLASS(InputEventJoypadButton, InputEvent)
int button_index;
bool pressed;
float pressure; //0 to 1
-};
+protected:
+ static void _bind_methods();
+
+public:
+ void set_button_index(int p_index);
+ int get_button_index() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ void set_pressure(float p_pressure);
+ float get_pressure() const;
-struct InputEventScreenTouch {
+ virtual bool action_match(const Ref<InputEvent> &p_event) const;
+ virtual bool is_action_type() const { return true; }
+
+ InputEventJoypadButton();
+};
+
+struct InputEventScreenTouch : public InputEvent {
+ GDCLASS(InputEventScreenTouch, InputEvent)
int index;
- float x, y;
+ Vector2 pos;
bool pressed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_index(int p_index);
+ int get_index() const;
+
+ void set_pos(const Vector2 &p_pos);
+ Vector2 get_pos() const;
+
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+
+ InputEventScreenTouch();
};
-struct InputEventScreenDrag {
+class InputEventScreenDrag : public InputEvent {
+
+ GDCLASS(InputEventScreenDrag, InputEvent)
int index;
- float x, y;
- float relative_x, relative_y;
- float speed_x, speed_y;
+ Vector2 pos;
+ Vector2 relative;
+ Vector2 speed;
+
+protected:
+ static void _bind_methods();
+
+public:
+ void set_index(int p_index);
+ int get_index() const;
+
+ void set_pos(const Vector2 &p_pos);
+ Vector2 get_pos() const;
+
+ void set_relative(const Vector2 &p_relative);
+ Vector2 get_relative() const;
+
+ void set_speed(const Vector2 &p_speed);
+ Vector2 get_speed() const;
+
+ virtual Ref<InputEvent> xformed_by(const Transform2D &p_xform, const Vector2 &p_local_ofs = Vector2()) const;
+
+ InputEventScreenDrag();
};
-struct InputEventAction {
+class InputEventAction : public InputEvent {
+
+ GDCLASS(InputEventAction, InputEvent)
- int action;
+ StringName action;
bool pressed;
-};
-struct InputEvent {
-
- enum Type {
- NONE,
- KEY,
- MOUSE_MOTION,
- MOUSE_BUTTON,
- JOYPAD_MOTION,
- JOYPAD_BUTTON,
- SCREEN_TOUCH,
- SCREEN_DRAG,
- ACTION,
- TYPE_MAX
- };
+protected:
+ static void _bind_methods();
- uint32_t ID;
- int type;
- int device;
+public:
+ void set_action(const StringName &p_action);
+ StringName get_action() const;
- union {
- InputEventMouseMotion mouse_motion;
- InputEventMouseButton mouse_button;
- InputEventJoypadMotion joy_motion;
- InputEventJoypadButton joy_button;
- InputEventKey key;
- InputEventScreenTouch screen_touch;
- InputEventScreenDrag screen_drag;
- InputEventAction action;
- };
+ void set_pressed(bool p_pressed);
+ virtual bool is_pressed() const;
- bool is_pressed() const;
- bool is_action(const String &p_action) const;
- bool is_action_pressed(const String &p_action) const;
- bool is_action_released(const String &p_action) const;
- bool is_echo() const;
- void set_as_action(const String &p_action, bool p_pressed);
-
- InputEvent xform_by(const Transform2D &p_xform) const;
- bool operator==(const InputEvent &p_event) const;
- operator String() const;
- InputEvent() {
- zeromem(this, sizeof(InputEvent));
- mouse_button.factor = 1;
- }
+ virtual bool is_action(const StringName &p_action) const;
+
+ virtual bool is_action_type() const { return true; }
+
+ InputEventAction();
};
#endif