From b8a136c3850b3863362cc6aa33530247335c3951 Mon Sep 17 00:00:00 2001 From: kobewi Date: Wed, 26 Jan 2022 15:27:30 +0100 Subject: [PATCH] Add Center View button to 2D editor --- editor/plugins/canvas_item_editor_plugin.cpp | 14 ++++++++++++-- editor/plugins/canvas_item_editor_plugin.h | 1 + 2 files changed, 13 insertions(+), 2 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index dcf3dc5b1b9..ff6d0f81cfe 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3818,7 +3818,9 @@ void CanvasItemEditor::set_current_tool(Tool p_tool) { } void CanvasItemEditor::_update_editor_settings() { + button_center_view->set_icon(get_theme_icon(SNAME("CenterView"), SNAME("EditorIcons"))); select_button->set_icon(get_theme_icon(SNAME("ToolSelect"), SNAME("EditorIcons"))); + select_sb->set_texture(get_theme_icon(SNAME("EditorRect2D"), SNAME("EditorIcons"))); list_select_button->set_icon(get_theme_icon(SNAME("ListSelect"), SNAME("EditorIcons"))); move_button->set_icon(get_theme_icon(SNAME("ToolMove"), SNAME("EditorIcons"))); scale_button->set_icon(get_theme_icon(SNAME("ToolScale"), SNAME("EditorIcons"))); @@ -3951,7 +3953,6 @@ void CanvasItemEditor::_notification(int p_what) { } break; case EditorSettings::NOTIFICATION_EDITOR_SETTINGS_CHANGED: { - select_sb->set_texture(get_theme_icon(SNAME("EditorRect2D"), SNAME("EditorIcons"))); _update_editor_settings(); } break; @@ -5052,8 +5053,17 @@ CanvasItemEditor::CanvasItemEditor() { ED_SHORTCUT_ARRAY("canvas_item_editor/zoom_1600_percent", TTR("Zoom to 1600%"), { int32_t(Key::KEY_5), int32_t(Key::KP_5) }); + HBoxContainer *controls_hb = memnew(HBoxContainer); + controls_vb->add_child(controls_hb); + + button_center_view = memnew(Button); + controls_hb->add_child(button_center_view); + button_center_view->set_flat(true); + button_center_view->set_tooltip_text(TTR("Center View")); + button_center_view->connect("pressed", callable_mp(this, &CanvasItemEditor::_popup_callback).bind(VIEW_CENTER_TO_SELECTION)); + zoom_widget = memnew(EditorZoomWidget); - controls_vb->add_child(zoom_widget); + controls_hb->add_child(zoom_widget); zoom_widget->set_anchors_and_offsets_preset(Control::PRESET_TOP_LEFT, Control::PRESET_MODE_MINSIZE, 2 * EDSCALE); zoom_widget->set_shortcut_context(this); zoom_widget->connect("zoom_changed", callable_mp(this, &CanvasItemEditor::_update_zoom)); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 6d8c6842b24..4e2a629c7ee 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -479,6 +479,7 @@ private: const Node *p_current); VBoxContainer *controls_vb = nullptr; + Button *button_center_view = nullptr; EditorZoomWidget *zoom_widget = nullptr; void _update_zoom(real_t p_zoom); void _shortcut_zoom_set(real_t p_zoom);