diff options
author | Juan Linietsky <reduzio@gmail.com> | 2017-05-20 12:38:03 -0300 |
---|---|---|
committer | Juan Linietsky <reduzio@gmail.com> | 2017-05-20 17:05:38 -0300 |
commit | 5b3709d3096df737b8bb2344446be818b0389bfe (patch) | |
tree | 649a0989b1494f3c4687d59e503310f4e6bbeb40 /scene/2d/screen_button.cpp | |
parent | 93f9a83062dbe74474a4a7928758c5cf5588238e (diff) | |
download | redot-engine-5b3709d3096df737b8bb2344446be818b0389bfe.tar.gz |
Removal of InputEvent as built-in Variant type..
this might cause bugs I haven't found yet..
Diffstat (limited to 'scene/2d/screen_button.cpp')
-rw-r--r-- | scene/2d/screen_button.cpp | 70 |
1 files changed, 33 insertions, 37 deletions
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; |