Add drag zoom feature with CTRL+MiddleMouseButton

This change introduces a DragType enum to scene/gui/view_panner.cpp of
dragging, which includes:

- DRAG_TYPE_NONE: Not dragging
- DRAG_TYPE_PAN: Panning (dragging using MMB)
- DRAG_TYPE_ZOOM: Zooming (dragging using CTRL+MMB)

The goal of this change is the third option, which was already available
in 3D viewport but not in 2D. This feature should work in other editors
as well such as Animation Track Editor and Visual Shader Editor and so
on.
This commit is contained in:
hamid
2025-04-25 18:12:02 +03:30
parent 80a3d205f1
commit 82e23da12e
7 changed files with 67 additions and 15 deletions

View File

@ -51,15 +51,32 @@ public:
PAN_AXIS_VERTICAL,
};
enum DragType {
DRAG_TYPE_NONE,
DRAG_TYPE_PAN,
DRAG_TYPE_ZOOM,
};
enum ZoomStyle {
ZOOM_VERTICAL,
ZOOM_HORIZONTAL,
};
private:
int scroll_speed = 32;
float scroll_zoom_factor = 1.1;
PanAxis pan_axis = PAN_AXIS_BOTH;
bool is_dragging = false;
bool pan_key_pressed = false;
bool force_drag = false;
DragType drag_type = DragType::DRAG_TYPE_NONE;
ZoomStyle zoom_style = ZoomStyle::ZOOM_VERTICAL;
Vector2 drag_zoom_position;
float drag_zoom_sensitivity_factor = -0.01f;
bool enable_rmb = false;
bool simple_panning_enabled = false;
@ -80,6 +97,7 @@ public:
void set_scroll_speed(int p_scroll_speed);
void set_scroll_zoom_factor(float p_scroll_zoom_factor);
void set_pan_axis(PanAxis p_pan_axis);
void set_zoom_style(ZoomStyle p_zoom_style);
void setup(ControlScheme p_scheme, Ref<Shortcut> p_shortcut, bool p_simple_panning);
void setup_warped_panning(Viewport *p_viewport, bool p_allowed);