diff options
author | RĂ©mi Verschelde <remi@verschelde.fr> | 2022-01-14 16:13:53 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-01-14 16:13:53 +0100 |
commit | 6689a9360c2dae0ca940e4e470c4d0a0e0a9bef4 (patch) | |
tree | de3203e2780dc1dffa1f8a2d724ef6b8674757a0 /scene | |
parent | 387f2744f70618c9e5efd0bc2d0cedcb7c2b25b9 (diff) | |
parent | fbb5580b3d1c298ed3a9565acc2da801ac1ac18a (diff) |
Merge pull request #56756 from KoBeWi/great_unification_theory
Diffstat (limited to 'scene')
-rw-r--r-- | scene/gui/view_panner.cpp | 12 | ||||
-rw-r--r-- | scene/gui/view_panner.h | 17 |
2 files changed, 20 insertions, 9 deletions
diff --git a/scene/gui/view_panner.cpp b/scene/gui/view_panner.cpp index 375b3732a4..ba5e8d4a17 100644 --- a/scene/gui/view_panner.cpp +++ b/scene/gui/view_panner.cpp @@ -36,11 +36,18 @@ bool ViewPanner::gui_input(const Ref<InputEvent> &p_event, Rect2 p_canvas_rect) { Ref<InputEventMouseButton> mb = p_event; if (mb.is_valid()) { + // Alt modifier is unused, so ignore such events. + if (mb->is_alt_pressed()) { + return false; + } + Vector2i scroll_vec = Vector2((mb->get_button_index() == MouseButton::WHEEL_RIGHT) - (mb->get_button_index() == MouseButton::WHEEL_LEFT), (mb->get_button_index() == MouseButton::WHEEL_DOWN) - (mb->get_button_index() == MouseButton::WHEEL_UP)); if (scroll_vec != Vector2()) { if (control_scheme == SCROLL_PANS) { if (mb->is_ctrl_pressed()) { + scroll_vec.y *= mb->get_factor(); callback_helper(zoom_callback, scroll_vec, mb->get_position()); + return true; } else { Vector2 panning; if (mb->is_shift_pressed()) { @@ -51,7 +58,6 @@ bool ViewPanner::gui_input(const Ref<InputEvent> &p_event, Rect2 p_canvas_rect) panning.x += mb->get_factor() * scroll_vec.x; } callback_helper(scroll_callback, panning); - return true; } } else { @@ -65,16 +71,16 @@ bool ViewPanner::gui_input(const Ref<InputEvent> &p_event, Rect2 p_canvas_rect) panning.x += mb->get_factor() * scroll_vec.x; } callback_helper(scroll_callback, panning); - return true; } else if (!mb->is_shift_pressed()) { + scroll_vec.y *= mb->get_factor(); callback_helper(zoom_callback, scroll_vec, mb->get_position()); return true; } } } - if (mb->get_button_index() == MouseButton::MIDDLE || (mb->get_button_index() == MouseButton::RIGHT && !disable_rmb) || (mb->get_button_index() == MouseButton::LEFT && (Input::get_singleton()->is_key_pressed(Key::SPACE) || !mb->is_pressed()))) { + if (mb->get_button_index() == MouseButton::MIDDLE || (mb->get_button_index() == MouseButton::RIGHT && !disable_rmb) || (mb->get_button_index() == MouseButton::LEFT && (Input::get_singleton()->is_key_pressed(Key::SPACE) || (is_dragging && !mb->is_pressed())))) { if (mb->is_pressed()) { is_dragging = true; } else { diff --git a/scene/gui/view_panner.h b/scene/gui/view_panner.h index e083d83de4..0a92cb3dfd 100644 --- a/scene/gui/view_panner.h +++ b/scene/gui/view_panner.h @@ -38,6 +38,13 @@ class InputEvent; class ViewPanner : public RefCounted { GDCLASS(ViewPanner, RefCounted); +public: + enum ControlScheme { + SCROLL_ZOOMS, + SCROLL_PANS, + }; + +private: bool is_dragging = false; bool disable_rmb = false; @@ -46,17 +53,15 @@ class ViewPanner : public RefCounted { Callable zoom_callback; void callback_helper(Callable p_callback, Vector2 p_arg1, Vector2 p_arg2 = Vector2()); - -public: - enum ControlScheme { - SCROLL_ZOOMS, - SCROLL_PANS, - }; ControlScheme control_scheme = SCROLL_ZOOMS; +public: void set_callbacks(Callable p_scroll_callback, Callable p_pan_callback, Callable p_zoom_callback); void set_control_scheme(ControlScheme p_scheme); void set_disable_rmb(bool p_disable); + + bool is_panning() const { return is_dragging; } + bool gui_input(const Ref<InputEvent> &p_ev, Rect2 p_canvas_rect = Rect2()); }; |