summaryrefslogtreecommitdiff
path: root/scene/2d
diff options
context:
space:
mode:
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/canvas_item.cpp4
-rw-r--r--scene/2d/canvas_item.h2
-rw-r--r--scene/2d/collision_object_2d.cpp6
-rw-r--r--scene/2d/collision_object_2d.h2
-rw-r--r--scene/2d/screen_button.cpp70
-rw-r--r--scene/2d/screen_button.h3
6 files changed, 41 insertions, 46 deletions
diff --git a/scene/2d/canvas_item.cpp b/scene/2d/canvas_item.cpp
index f699c8f0e8..b2258ec94b 100644
--- a/scene/2d/canvas_item.cpp
+++ b/scene/2d/canvas_item.cpp
@@ -688,11 +688,11 @@ Vector2 CanvasItem::make_canvas_pos_local(const Vector2 &screen_point) const {
return local_matrix.xform(screen_point);
}
-InputEvent CanvasItem::make_input_local(const InputEvent &p_event) const {
+Ref<InputEvent> CanvasItem::make_input_local(const Ref<InputEvent> &p_event) const {
ERR_FAIL_COND_V(!is_inside_tree(), p_event);
- return p_event.xform_by((get_canvas_transform() * get_global_transform()).affine_inverse());
+ return p_event->xformed_by((get_canvas_transform() * get_global_transform()).affine_inverse());
}
Vector2 CanvasItem::get_global_mouse_position() const {
diff --git a/scene/2d/canvas_item.h b/scene/2d/canvas_item.h
index 72fe5b93da..bea4301326 100644
--- a/scene/2d/canvas_item.h
+++ b/scene/2d/canvas_item.h
@@ -209,7 +209,7 @@ public:
void set_use_parent_material(bool p_use_parent_material);
bool get_use_parent_material() const;
- InputEvent make_input_local(const InputEvent &pevent) const;
+ Ref<InputEvent> make_input_local(const Ref<InputEvent> &pevent) const;
Vector2 make_canvas_pos_local(const Vector2 &screen_point) const;
Vector2 get_global_mouse_position() const;
diff --git a/scene/2d/collision_object_2d.cpp b/scene/2d/collision_object_2d.cpp
index afbdfec45e..caf9cf201a 100644
--- a/scene/2d/collision_object_2d.cpp
+++ b/scene/2d/collision_object_2d.cpp
@@ -180,7 +180,7 @@ bool CollisionObject2D::is_pickable() const {
return pickable;
}
-void CollisionObject2D::_input_event(Node *p_viewport, const InputEvent &p_input_event, int p_shape) {
+void CollisionObject2D::_input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape) {
if (get_script_instance()) {
get_script_instance()->call(SceneStringNames::get_singleton()->_input_event, p_viewport, p_input_event, p_shape);
@@ -231,9 +231,9 @@ void CollisionObject2D::_bind_methods() {
ClassDB::bind_method(D_METHOD("set_pickable", "enabled"), &CollisionObject2D::set_pickable);
ClassDB::bind_method(D_METHOD("is_pickable"), &CollisionObject2D::is_pickable);
- BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx")));
+ BIND_VMETHOD(MethodInfo("_input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::INT, "shape_idx")));
- ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::INPUT_EVENT, "event"), PropertyInfo(Variant::INT, "shape_idx")));
+ ADD_SIGNAL(MethodInfo("input_event", PropertyInfo(Variant::OBJECT, "viewport"), PropertyInfo(Variant::OBJECT, "event", PROPERTY_HINT_RESOURCE_TYPE, "InputEvent"), PropertyInfo(Variant::INT, "shape_idx")));
ADD_SIGNAL(MethodInfo("mouse_entered"));
ADD_SIGNAL(MethodInfo("mouse_exited"));
diff --git a/scene/2d/collision_object_2d.h b/scene/2d/collision_object_2d.h
index e3dc39feae..4d4611afd1 100644
--- a/scene/2d/collision_object_2d.h
+++ b/scene/2d/collision_object_2d.h
@@ -70,7 +70,7 @@ protected:
void _update_pickable();
friend class Viewport;
- void _input_event(Node *p_viewport, const InputEvent &p_input_event, int p_shape);
+ void _input_event(Node *p_viewport, const Ref<InputEvent> &p_input_event, int p_shape);
void _mouse_enter();
void _mouse_exit();
diff --git a/scene/2d/screen_button.cpp b/scene/2d/screen_button.cpp
index 7712108488..f503a66208 100644
--- a/scene/2d/screen_button.cpp
+++ b/scene/2d/screen_button.cpp
@@ -148,11 +148,6 @@ void TouchScreenButton::_notification(int p_what) {
if (!get_tree()->is_editor_hint())
set_process_input(is_visible_in_tree());
- if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
- action_id = InputMap::get_singleton()->get_action_id(action);
- } else {
- action_id = -1;
- }
} break;
case NOTIFICATION_EXIT_TREE: {
if (is_pressed())
@@ -184,11 +179,6 @@ bool TouchScreenButton::is_pressed() const {
void TouchScreenButton::set_action(const String &p_action) {
action = p_action;
- if (action.operator String() != "" && InputMap::get_singleton()->has_action(action)) {
- action_id = InputMap::get_singleton()->get_action_id(action);
- } else {
- action_id = -1;
- }
}
String TouchScreenButton::get_action() const {
@@ -196,26 +186,32 @@ String TouchScreenButton::get_action() const {
return action;
}
-void TouchScreenButton::_input(const InputEvent &p_event) {
+void TouchScreenButton::_input(const Ref<InputEvent> &p_event) {
if (!get_tree())
return;
- if (p_event.device != 0)
+ if (p_event->get_device() != 0)
return;
if (passby_press) {
- if (p_event.type == InputEvent::SCREEN_TOUCH && !p_event.screen_touch.pressed && finger_pressed == p_event.screen_touch.index) {
+ Ref<InputEventScreenTouch> st = p_event;
+ Ref<InputEventScreenTouch> sd = p_event;
+
+ if (st.is_valid() && !st->is_pressed() && finger_pressed == st->get_index()) {
_release();
}
- if ((p_event.type == InputEvent::SCREEN_TOUCH && p_event.screen_touch.pressed) || p_event.type == InputEvent::SCREEN_DRAG) {
+ if ((st.is_valid() && st->is_pressed()) || sd.is_valid()) {
+
+ int index = st.is_valid() ? st->get_index() : sd->get_index();
+ Vector2 coord = st.is_valid() ? st->get_pos() : sd->get_pos();
- if (finger_pressed == -1 || p_event.screen_touch.index == finger_pressed) {
+ if (finger_pressed == -1 || index == finger_pressed) {
- Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
+ coord = (get_global_transform_with_canvas()).affine_inverse().xform(coord);
bool touched = false;
if (bitmask.is_valid()) {
@@ -233,7 +229,7 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
if (touched) {
if (finger_pressed == -1) {
- _press(p_event.screen_touch.index);
+ _press(index);
}
} else {
if (finger_pressed != -1) {
@@ -245,9 +241,11 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
} else {
- if (p_event.type == InputEvent::SCREEN_TOUCH) {
+ Ref<InputEventScreenTouch> st = p_event;
- if (p_event.screen_touch.pressed) {
+ if (st.is_valid()) {
+
+ if (st->is_pressed()) {
if (!is_visible_in_tree())
return;
@@ -256,7 +254,7 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
if (!can_press)
return; //already fingering
- Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(Point2(p_event.screen_touch.x, p_event.screen_touch.y));
+ Point2 coord = (get_global_transform_with_canvas()).affine_inverse().xform(st->get_pos());
Rect2 item_rect = get_item_rect();
bool touched = false;
@@ -284,10 +282,10 @@ void TouchScreenButton::_input(const InputEvent &p_event) {
}
if (touched) {
- _press(p_event.screen_touch.index);
+ _press(st->get_index());
}
} else {
- if (p_event.screen_touch.index == finger_pressed) {
+ if (st->get_index() == finger_pressed) {
_release();
}
}
@@ -299,15 +297,14 @@ void TouchScreenButton::_press(int p_finger_pressed) {
finger_pressed = p_finger_pressed;
- if (action_id != -1) {
+ if (action != StringName()) {
Input::get_singleton()->action_press(action);
- InputEvent ie;
- ie.type = InputEvent::ACTION;
- ie.ID = 0;
- ie.action.action = action_id;
- ie.action.pressed = true;
- get_tree()->input_event(ie);
+ Ref<InputEventAction> iea;
+ iea.instance();
+ iea->set_action(action);
+ iea->set_pressed(true);
+ get_tree()->input_event(iea);
}
emit_signal("pressed");
@@ -318,16 +315,16 @@ void TouchScreenButton::_release(bool p_exiting_tree) {
finger_pressed = -1;
- if (action_id != -1) {
+ if (action != StringName()) {
Input::get_singleton()->action_release(action);
if (!p_exiting_tree) {
- InputEvent ie;
- ie.type = InputEvent::ACTION;
- ie.ID = 0;
- ie.action.action = action_id;
- ie.action.pressed = false;
- get_tree()->input_event(ie);
+
+ Ref<InputEventAction> iea;
+ iea.instance();
+ iea->set_action(action);
+ iea->set_pressed(false);
+ get_tree()->input_event(iea);
}
}
@@ -419,7 +416,6 @@ void TouchScreenButton::_bind_methods() {
TouchScreenButton::TouchScreenButton() {
finger_pressed = -1;
- action_id = -1;
passby_press = false;
visibility = VISIBILITY_ALWAYS;
shape_centered = true;
diff --git a/scene/2d/screen_button.h b/scene/2d/screen_button.h
index 0cfaf681dd..e44f556c31 100644
--- a/scene/2d/screen_button.h
+++ b/scene/2d/screen_button.h
@@ -58,11 +58,10 @@ private:
StringName action;
bool passby_press;
int finger_pressed;
- int action_id;
VisibilityMode visibility;
- void _input(const InputEvent &p_Event);
+ void _input(const Ref<InputEvent> &p_Event);
void _press(int p_finger_pressed);
void _release(bool p_exiting_tree = false);