Scrollwheel (w/o ctrl) to zoom, mouse warping when panning

Now uses Ctrl + Scrollwheel for vertical scrolling
Ctrl + Shift Scrollwheel for horizontal scrolling
Also converts some macros to constants

(cherry picked from commit 13ba788b63)
This commit is contained in:
Lightning_A 2021-04-17 12:02:04 -06:00 committed by Rémi Verschelde
parent 77add76a16
commit 086db0bf9f
No known key found for this signature in database
GPG Key ID: C3336907360768E1
1 changed files with 20 additions and 17 deletions

View File

@ -39,8 +39,8 @@
#include "editor/editor_scale.h" #include "editor/editor_scale.h"
#endif #endif
#define MINIMAP_OFFSET 12 constexpr int MINIMAP_OFFSET = 12;
#define MINIMAP_PADDING 5 constexpr int MINIMAP_PADDING = 5;
bool GraphEditFilter::has_point(const Point2 &p_point) const { bool GraphEditFilter::has_point(const Point2 &p_point) const {
return ge->_filter_input(p_point); return ge->_filter_input(p_point);
@ -1083,8 +1083,9 @@ void GraphEdit::set_selected(Node *p_child) {
void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) { void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
Ref<InputEventMouseMotion> mm = p_ev; Ref<InputEventMouseMotion> mm = p_ev;
if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) { if (mm.is_valid() && (mm->get_button_mask() & BUTTON_MASK_MIDDLE || (mm->get_button_mask() & BUTTON_MASK_LEFT && Input::get_singleton()->is_key_pressed(KEY_SPACE)))) {
h_scroll->set_value(h_scroll->get_value() - mm->get_relative().x); Vector2i relative = Input::get_singleton()->warp_mouse_motion(mm, get_global_rect());
v_scroll->set_value(v_scroll->get_value() - mm->get_relative().y); h_scroll->set_value(h_scroll->get_value() - relative.x);
v_scroll->set_value(v_scroll->get_value() - relative.y);
} }
if (mm.is_valid() && dragging) { if (mm.is_valid() && dragging) {
@ -1333,18 +1334,20 @@ void GraphEdit::_gui_input(const Ref<InputEvent> &p_ev) {
minimap->update(); minimap->update();
} }
if (b->get_button_index() == BUTTON_WHEEL_UP && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { int scroll_direction = (b->get_button_index() == BUTTON_WHEEL_DOWN) - (b->get_button_index() == BUTTON_WHEEL_UP);
set_zoom_custom(zoom * zoom_step, b->get_position()); if (scroll_direction != 0) {
} else if (b->get_button_index() == BUTTON_WHEEL_DOWN && Input::get_singleton()->is_key_pressed(KEY_CONTROL)) { if (b->get_control()) {
set_zoom_custom(zoom / zoom_step, b->get_position()); if (b->get_shift()) {
} else if (b->get_button_index() == BUTTON_WHEEL_UP && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { // Horizontal scrolling.
v_scroll->set_value(v_scroll->get_value() - v_scroll->get_page() * b->get_factor() / 8); h_scroll->set_value(h_scroll->get_value() + (h_scroll->get_page() * b->get_factor() / 8) * scroll_direction);
} else if (b->get_button_index() == BUTTON_WHEEL_DOWN && !Input::get_singleton()->is_key_pressed(KEY_SHIFT)) { } else {
v_scroll->set_value(v_scroll->get_value() + v_scroll->get_page() * b->get_factor() / 8); // Vertical scrolling.
} else if (b->get_button_index() == BUTTON_WHEEL_RIGHT || (b->get_button_index() == BUTTON_WHEEL_DOWN && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { v_scroll->set_value(v_scroll->get_value() + (v_scroll->get_page() * b->get_factor() / 8) * scroll_direction);
h_scroll->set_value(h_scroll->get_value() + h_scroll->get_page() * b->get_factor() / 8); }
} else if (b->get_button_index() == BUTTON_WHEEL_LEFT || (b->get_button_index() == BUTTON_WHEEL_UP && Input::get_singleton()->is_key_pressed(KEY_SHIFT))) { } else {
h_scroll->set_value(h_scroll->get_value() - h_scroll->get_page() * b->get_factor() / 8); // Zooming.
set_zoom_custom(scroll_direction < 0 ? zoom * zoom_step : zoom / zoom_step, b->get_position());
}
} }
} }
@ -1762,7 +1765,7 @@ GraphEdit::GraphEdit() {
// Allow dezooming 8 times from the default zoom level. // Allow dezooming 8 times from the default zoom level.
// At low zoom levels, text is unreadable due to its small size and poor filtering, // At low zoom levels, text is unreadable due to its small size and poor filtering,
// but this is still useful for previewing purposes. // but this is still useful for previewing and navigation.
zoom_min = (1 / Math::pow(zoom_step, 8)); zoom_min = (1 / Math::pow(zoom_step, 8));
// Allow zooming 4 times from the default zoom level. // Allow zooming 4 times from the default zoom level.
zoom_max = (1 * Math::pow(zoom_step, 4)); zoom_max = (1 * Math::pow(zoom_step, 4));