From 63fac11503c205bae99f916177993eb7c5480585 Mon Sep 17 00:00:00 2001 From: Haoyu Qiu Date: Sun, 7 Apr 2024 09:38:59 +0800 Subject: [PATCH] Add option to toggle visibility of position gizmos in 2D editor Co-authored-by: J. N. Witch <127793256+J-N-Witch@users.noreply.github.com> --- editor/plugins/canvas_item_editor_plugin.cpp | 66 +++++++++++++++----- editor/plugins/canvas_item_editor_plugin.h | 9 ++- 2 files changed, 59 insertions(+), 16 deletions(-) diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 348b8e2fc..01b70fe0b 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -3513,7 +3513,7 @@ void CanvasItemEditor::_draw_invisible_nodes_positions(Node *p_node, const Trans _draw_invisible_nodes_positions(p_node->get_child(i), parent_xform, canvas_xform); } - if (canvas_item && !canvas_item->_edit_use_rect() && (!editor_selection->is_selected(canvas_item) || _is_node_locked(canvas_item))) { + if (show_position_gizmos && canvas_item && !canvas_item->_edit_use_rect() && (!editor_selection->is_selected(canvas_item) || _is_node_locked(canvas_item))) { Transform2D xform = transform * canvas_xform * parent_xform; // Draw the node's position @@ -3587,13 +3587,13 @@ void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p float offset = 0; Ref lock = get_theme_icon("LockViewport", "EditorIcons"); - if (p_node->has_meta("_edit_lock_") && show_edit_locks) { + if (show_lock_gizmos && p_node->has_meta("_edit_lock_")) { lock->draw(viewport_canvas_item, (transform * canvas_xform * parent_xform).xform(Point2(0, 0)) + Point2(offset, 0)); offset += lock->get_size().x; } Ref group = get_theme_icon("GroupViewport", "EditorIcons"); - if (canvas_item->has_meta("_edit_group_") && show_edit_locks) { + if (show_group_gizmos && canvas_item->has_meta("_edit_group_")) { group->draw(viewport_canvas_item, (transform * canvas_xform * parent_xform).xform(Point2(0, 0)) + Point2(offset, 0)); //offset += group->get_size().x; } @@ -4463,10 +4463,22 @@ void CanvasItemEditor::_popup_callback(int p_op) { view_menu->get_popup()->set_item_checked(idx, show_viewport); viewport->update(); } break; - case SHOW_EDIT_LOCKS: { - show_edit_locks = !show_edit_locks; - int idx = view_menu->get_popup()->get_item_index(SHOW_EDIT_LOCKS); - view_menu->get_popup()->set_item_checked(idx, show_edit_locks); + case SHOW_POSITION_GIZMOS: { + show_position_gizmos = !show_position_gizmos; + int idx = gizmos_menu->get_item_index(SHOW_POSITION_GIZMOS); + gizmos_menu->set_item_checked(idx, show_position_gizmos); + viewport->update(); + } break; + case SHOW_LOCK_GIZMOS: { + show_lock_gizmos = !show_lock_gizmos; + int idx = gizmos_menu->get_item_index(SHOW_LOCK_GIZMOS); + gizmos_menu->set_item_checked(idx, show_lock_gizmos); + viewport->update(); + } break; + case SHOW_GROUP_GIZMOS: { + show_group_gizmos = !show_group_gizmos; + int idx = gizmos_menu->get_item_index(SHOW_GROUP_GIZMOS); + gizmos_menu->set_item_checked(idx, show_group_gizmos); viewport->update(); } break; case SNAP_USE_NODE_PARENT: { @@ -5052,7 +5064,9 @@ Dictionary CanvasItemEditor::get_state() const { state["show_guides"] = show_guides; state["show_helpers"] = show_helpers; state["show_zoom_control"] = zoom_hb->is_visible(); - state["show_edit_locks"] = show_edit_locks; + state["show_position_gizmos"] = show_position_gizmos; + state["show_lock_gizmos"] = show_lock_gizmos; + state["show_group_gizmos"] = show_group_gizmos; state["snap_rotation"] = snap_rotation; state["snap_scale"] = snap_scale; state["snap_relative"] = snap_relative; @@ -5183,10 +5197,22 @@ void CanvasItemEditor::set_state(const Dictionary &p_state) { view_menu->get_popup()->set_item_checked(idx, show_helpers); } - if (state.has("show_edit_locks")) { - show_edit_locks = state["show_edit_locks"]; - int idx = view_menu->get_popup()->get_item_index(SHOW_EDIT_LOCKS); - view_menu->get_popup()->set_item_checked(idx, show_edit_locks); + if (state.has("show_position_gizmos")) { + show_position_gizmos = state["show_position_gizmos"]; + int idx = gizmos_menu->get_item_index(SHOW_POSITION_GIZMOS); + gizmos_menu->set_item_checked(idx, show_position_gizmos); + } + + if (state.has("show_lock_gizmos")) { + show_lock_gizmos = state["show_lock_gizmos"]; + int idx = gizmos_menu->get_item_index(SHOW_LOCK_GIZMOS); + gizmos_menu->set_item_checked(idx, show_lock_gizmos); + } + + if (state.has("show_group_gizmos")) { + show_group_gizmos = state["show_group_gizmos"]; + int idx = gizmos_menu->get_item_index(SHOW_GROUP_GIZMOS); + gizmos_menu->set_item_checked(idx, show_group_gizmos); } if (state.has("show_zoom_control")) { @@ -5308,7 +5334,9 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { show_helpers = false; show_rulers = true; show_guides = true; - show_edit_locks = true; + show_position_gizmos = true; + show_lock_gizmos = true; + show_group_gizmos = true; zoom = 1.0 / MAX(1, EDSCALE); view_offset = Point2(-150 - RULER_WIDTH, -95 - RULER_WIDTH); previous_update_view_offset = view_offset; // Moves the view a little bit to the left so that (0,0) is visible. The values a relative to a 16/10 screen @@ -5657,7 +5685,17 @@ CanvasItemEditor::CanvasItemEditor(EditorNode *p_editor) { p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_guides", TTR("Show Guides"), KEY_Y), SHOW_GUIDES); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_origin", TTR("Show Origin")), SHOW_ORIGIN); p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_viewport", TTR("Show Viewport")), SHOW_VIEWPORT); - p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_edit_locks", TTR("Show Group And Lock Icons")), SHOW_EDIT_LOCKS); + + p->add_separator(); + gizmos_menu = memnew(PopupMenu); + gizmos_menu->set_name("GizmosMenu"); + gizmos_menu->connect("id_pressed", this, "_popup_callback"); + gizmos_menu->set_hide_on_checkable_item_selection(false); + gizmos_menu->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_position_gizmos", TTR("Position")), SHOW_POSITION_GIZMOS); + gizmos_menu->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_lock_gizmos", TTR("Lock")), SHOW_LOCK_GIZMOS); + gizmos_menu->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_group_gizmos", TTR("Group")), SHOW_GROUP_GIZMOS); + p->add_child(gizmos_menu); + p->add_submenu_item(TTR("Gizmos"), "GizmosMenu"); p->add_separator(); p->add_shortcut(ED_SHORTCUT("canvas_item_editor/center_selection", TTR("Center Selection"), KEY_F), VIEW_CENTER_TO_SELECTION); diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index 2d9f35a8d..808bd7b91 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -156,7 +156,9 @@ private: SHOW_GUIDES, SHOW_ORIGIN, SHOW_VIEWPORT, - SHOW_EDIT_LOCKS, + SHOW_POSITION_GIZMOS, + SHOW_LOCK_GIZMOS, + SHOW_GROUP_GIZMOS, LOCK_SELECTED, UNLOCK_SELECTED, GROUP_SELECTED, @@ -282,7 +284,9 @@ private: bool show_origin; bool show_viewport; bool show_helpers; - bool show_edit_locks; + bool show_position_gizmos; + bool show_lock_gizmos; + bool show_group_gizmos; float zoom; Point2 view_offset; Point2 previous_update_view_offset; @@ -400,6 +404,7 @@ private: MenuButton *skeleton_menu; ToolButton *override_camera_button; MenuButton *view_menu; + PopupMenu *gizmos_menu; HBoxContainer *animation_hb; MenuButton *animation_menu;