diff options
author | Haoyu Qiu <timothyqiu32@gmail.com> | 2022-02-15 16:48:55 +0800 |
---|---|---|
committer | Haoyu Qiu <timothyqiu32@gmail.com> | 2022-02-23 20:45:44 +0800 |
commit | 33ad21d2edcf4d22d6dd6f7d68d6a2a410414520 (patch) | |
tree | 9b4de7cfe0114a5ce53628657609c37e40964f04 /editor/plugins | |
parent | 1f3916e0b6afc84872f7354432ca8606d764fc22 (diff) |
Utilize mouse position when zooming with shortcuts in 2D editor
Diffstat (limited to 'editor/plugins')
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 24 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 1 |
2 files changed, 15 insertions, 10 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 85ac258c9c..e43d1feb08 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -1163,25 +1163,25 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo if (k.is_valid()) { if (k->is_pressed()) { if (ED_GET_SHORTCUT("canvas_item_editor/zoom_3.125_percent")->matches_event(p_event)) { - _update_zoom((1.0 / 32.0) * MAX(1, EDSCALE)); + _shortcut_zoom_set(1.0 / 32.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_6.25_percent")->matches_event(p_event)) { - _update_zoom((1.0 / 16.0) * MAX(1, EDSCALE)); + _shortcut_zoom_set(1.0 / 16.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_12.5_percent")->matches_event(p_event)) { - _update_zoom((1.0 / 8.0) * MAX(1, EDSCALE)); + _shortcut_zoom_set(1.0 / 8.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_25_percent")->matches_event(p_event)) { - _update_zoom((1.0 / 4.0) * MAX(1, EDSCALE)); + _shortcut_zoom_set(1.0 / 4.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_50_percent")->matches_event(p_event)) { - _update_zoom((1.0 / 2.0) * MAX(1, EDSCALE)); + _shortcut_zoom_set(1.0 / 2.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_100_percent")->matches_event(p_event)) { - _update_zoom(1.0 * MAX(1, EDSCALE)); + _shortcut_zoom_set(1.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_200_percent")->matches_event(p_event)) { - _update_zoom(2.0 * MAX(1, EDSCALE)); + _shortcut_zoom_set(2.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_400_percent")->matches_event(p_event)) { - _update_zoom(4.0 * MAX(1, EDSCALE)); + _shortcut_zoom_set(4.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_800_percent")->matches_event(p_event)) { - _update_zoom(8.0 * MAX(1, EDSCALE)); + _shortcut_zoom_set(8.0); } else if (ED_GET_SHORTCUT("canvas_item_editor/zoom_1600_percent")->matches_event(p_event)) { - _update_zoom(16.0 * MAX(1, EDSCALE)); + _shortcut_zoom_set(16.0); } } } @@ -4010,6 +4010,10 @@ void CanvasItemEditor::_update_zoom(real_t p_zoom) { _zoom_on_position(p_zoom, viewport_scrollable->get_size() / 2.0); } +void CanvasItemEditor::_shortcut_zoom_set(real_t p_zoom) { + _zoom_on_position(p_zoom * MAX(1, EDSCALE), viewport->get_local_mouse_position()); +} + void CanvasItemEditor::_button_toggle_smart_snap(bool p_status) { smart_snap_active = p_status; viewport->update(); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 57760475a1..e7c265ee02 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -470,6 +470,7 @@ private: VBoxContainer *controls_vb; EditorZoomWidget *zoom_widget; void _update_zoom(real_t p_zoom); + void _shortcut_zoom_set(real_t p_zoom); void _zoom_on_position(real_t p_zoom, Point2 p_position = Point2()); void _button_toggle_smart_snap(bool p_status); void _button_toggle_grid_snap(bool p_status); |