diff options
author | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-12 20:08:31 +0100 |
---|---|---|
committer | Rémi Verschelde <rverschelde@gmail.com> | 2023-01-12 20:08:31 +0100 |
commit | 318af8f36c328cfc778df15d04e5b4596ac00b7f (patch) | |
tree | f4e02af97139f319f4ea4276b0ad4f7dd2873cb4 | |
parent | 800216924cdf82706eb56f0c427cd8a2b03f32c1 (diff) | |
parent | 1fa5597520e4bf3c0d17b4ca72f5feb88f2664ec (diff) |
Merge pull request #71272 from MewPurPur/fix-frame-selection
Fix the Frame Selection (Shift + F) functionality in the 2D editor
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 39 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 1 |
2 files changed, 20 insertions, 20 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 7f9a23463c..bd7b7ff1cb 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -4370,8 +4370,7 @@ void CanvasItemEditor::_popup_callback(int p_op) { show_rulers = !show_rulers; int idx = view_menu->get_popup()->get_item_index(SHOW_RULERS); view_menu->get_popup()->set_item_checked(idx, show_rulers); - _update_scrollbars(); - viewport->queue_redraw(); + update_viewport(); } break; case SHOW_GUIDES: { show_guides = !show_guides; @@ -4683,25 +4682,18 @@ void CanvasItemEditor::_focus_selection(int p_op) { } else { rect = rect.merge(canvas_item_rect); } - }; - - if (p_op == VIEW_CENTER_TO_SELECTION) { - center = rect.get_center(); - Vector2 offset = viewport->get_size() / 2 - EditorNode::get_singleton()->get_scene_root()->get_global_canvas_transform().xform(center); - view_offset -= (offset / zoom).round(); - update_viewport(); - - } else { // VIEW_FRAME_TO_SELECTION + } - if (rect.size.x > CMP_EPSILON && rect.size.y > CMP_EPSILON) { - real_t scale_x = viewport->get_size().x / rect.size.x; - real_t scale_y = viewport->get_size().y / rect.size.y; - zoom = scale_x < scale_y ? scale_x : scale_y; - zoom *= 0.90; - viewport->queue_redraw(); - zoom_widget->set_zoom(zoom); - call_deferred(SNAME("_popup_callback"), VIEW_CENTER_TO_SELECTION); - } + if (p_op == VIEW_FRAME_TO_SELECTION && rect.size.x > CMP_EPSILON && rect.size.y > CMP_EPSILON) { + real_t scale_x = viewport->get_size().x / rect.size.x; + real_t scale_y = viewport->get_size().y / rect.size.y; + zoom = scale_x < scale_y ? scale_x : scale_y; + zoom *= 0.90; + zoom_widget->set_zoom(zoom); + viewport->queue_redraw(); // Redraw to update the global canvas transform after zoom changes. + call_deferred(SNAME("center_at"), rect.get_center()); // Defer because the updated transform is needed. + } else { + center_at(rect.get_center()); } } @@ -4715,6 +4707,7 @@ void CanvasItemEditor::_bind_methods() { ClassDB::bind_method(D_METHOD("set_state"), &CanvasItemEditor::set_state); ClassDB::bind_method(D_METHOD("update_viewport"), &CanvasItemEditor::update_viewport); + ClassDB::bind_method(D_METHOD("center_at", "position"), &CanvasItemEditor::center_at); ClassDB::bind_method("_set_owner_for_node_and_children", &CanvasItemEditor::_set_owner_for_node_and_children); @@ -4961,6 +4954,12 @@ void CanvasItemEditor::focus_selection() { _focus_selection(VIEW_CENTER_TO_SELECTION); } +void CanvasItemEditor::center_at(const Point2 &p_pos) { + Vector2 offset = viewport->get_size() / 2 - EditorNode::get_singleton()->get_scene_root()->get_global_canvas_transform().xform(p_pos); + view_offset -= (offset / zoom).round(); + update_viewport(); +} + CanvasItemEditor::CanvasItemEditor() { zoom = 1.0 / MAX(1, EDSCALE); view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 8f02f02c32..f4fcc8a3d2 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -550,6 +550,7 @@ public: void edit(CanvasItem *p_canvas_item); void focus_selection(); + void center_at(const Point2 &p_pos); EditorSelection *editor_selection = nullptr; |