summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorVolTer <mew.pur.pur@abv.bg>2023-01-12 15:04:02 +0200
committerVolTer <mew.pur.pur@abv.bg>2023-01-12 19:13:00 +0200
commit1fa5597520e4bf3c0d17b4ca72f5feb88f2664ec (patch)
treee5dd07b89091a1e62a5d123a96a110a87f404a42
parent1d14c054a12dacdc193b589e4afb0ef319ee2aae (diff)
Fix the Frame Selection functionality
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp39
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h1
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 c3a0c55452..c5b15ca760 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;