Skip to content

Commit

Permalink
Merge pull request #57252 from KoBeWi/clickable_F
Browse files Browse the repository at this point in the history
Add Center View button to 2D editor
  • Loading branch information
YuriSizov authored May 31, 2023
2 parents c3e512e + b8a136c commit 506eaf8
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
14 changes: 12 additions & 2 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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")));
Expand Down Expand Up @@ -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;

Expand Down Expand Up @@ -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));
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/canvas_item_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -479,6 +479,7 @@ class CanvasItemEditor : public VBoxContainer {
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);
Expand Down

0 comments on commit 506eaf8

Please sign in to comment.