Skip to content

Commit

Permalink
Introduce a "Gizmos" submenu for toggling visibility of gizmos in 2D …
Browse files Browse the repository at this point in the history
…editor

instead of standalone checkboxes like "Show Group And Lock Gizmos".

Add option to toggle visibility of Position gizmos.
  • Loading branch information
J-N-Witch committed Mar 16, 2023
1 parent 1e0f7a1 commit 5af18b2
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 20 deletions.
73 changes: 55 additions & 18 deletions editor/plugins/canvas_item_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3575,7 +3575,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 (ci && !ci->_edit_use_rect() && (!editor_selection->is_selected(ci) || _is_node_locked(ci))) {
if (ci && !ci->_edit_use_rect() && (!editor_selection->is_selected(ci) || _is_node_locked(ci)) && show_position_gizmos) {
Transform2D xform = transform * canvas_xform * parent_xform;

// Draw the node's position
Expand Down Expand Up @@ -3711,13 +3711,13 @@ void CanvasItemEditor::_draw_locks_and_groups(Node *p_node, const Transform2D &p
real_t offset = 0;

Ref<Texture2D> lock = get_theme_icon(SNAME("LockViewport"), SNAME("EditorIcons"));
if (p_node->has_meta("_edit_lock_") && show_edit_locks) {
if (p_node->has_meta("_edit_lock_") && show_lock_gizmos) {
lock->draw(viewport_ci, (transform * canvas_xform * parent_xform).xform(Point2(0, 0)) + Point2(offset, 0));
offset += lock->get_size().x;
}

Ref<Texture2D> group = get_theme_icon(SNAME("GroupViewport"), SNAME("EditorIcons"));
if (ci->has_meta("_edit_group_") && show_edit_locks) {
if (ci->has_meta("_edit_group_") && show_group_gizmos) {
group->draw(viewport_ci, (transform * canvas_xform * parent_xform).xform(Point2(0, 0)) + Point2(offset, 0));
//offset += group->get_size().x;
}
Expand Down Expand Up @@ -4251,16 +4251,28 @@ void CanvasItemEditor::_popup_callback(int p_op) {
view_menu->get_popup()->set_item_checked(idx, show_viewport);
viewport->queue_redraw();
} 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->queue_redraw();
} 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->queue_redraw();
} 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->queue_redraw();
} break;
case SHOW_TRANSFORMATION_GIZMOS: {
show_transformation_gizmos = !show_transformation_gizmos;
int idx = view_menu->get_popup()->get_item_index(SHOW_TRANSFORMATION_GIZMOS);
view_menu->get_popup()->set_item_checked(idx, show_transformation_gizmos);
int idx = gizmos_menu->get_item_index(SHOW_TRANSFORMATION_GIZMOS);
gizmos_menu->set_item_checked(idx, show_transformation_gizmos);
viewport->queue_redraw();
} break;
case SNAP_USE_NODE_PARENT: {
Expand Down Expand Up @@ -4715,7 +4727,9 @@ Dictionary CanvasItemEditor::get_state() const {
state["show_guides"] = show_guides;
state["show_helpers"] = show_helpers;
state["show_zoom_control"] = zoom_widget->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["show_transformation_gizmos"] = show_transformation_gizmos;
state["snap_rotation"] = snap_rotation;
state["snap_scale"] = snap_scale;
Expand Down Expand Up @@ -4845,16 +4859,28 @@ 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_transformation_gizmos")) {
show_transformation_gizmos = state["show_transformation_gizmos"];
int idx = view_menu->get_popup()->get_item_index(SHOW_TRANSFORMATION_GIZMOS);
view_menu->get_popup()->set_item_checked(idx, show_transformation_gizmos);
int idx = gizmos_menu->get_item_index(SHOW_TRANSFORMATION_GIZMOS);
gizmos_menu->set_item_checked(idx, show_transformation_gizmos);
}

if (state.has("show_zoom_control")) {
Expand Down Expand Up @@ -5275,8 +5301,9 @@ CanvasItemEditor::CanvasItemEditor() {
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_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_transformation_gizmos", TTR("Show Transformation Gizmos")), SHOW_TRANSFORMATION_GIZMOS);
p->add_separator();

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);
Expand All @@ -5285,6 +5312,16 @@ CanvasItemEditor::CanvasItemEditor() {
p->add_separator();
p->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/preview_canvas_scale", TTR("Preview Canvas Scale")), PREVIEW_CANVAS_SCALE);

gizmos_menu = memnew(PopupMenu);
p->add_child(gizmos_menu);
gizmos_menu->set_name("GizmosMenu");
gizmos_menu->connect("id_pressed", callable_mp(this, &CanvasItemEditor::_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);
gizmos_menu->add_check_shortcut(ED_SHORTCUT("canvas_item_editor/show_transformation_gizmos", TTR("Transformation")), SHOW_TRANSFORMATION_GIZMOS);

main_menu_hbox->add_child(memnew(VSeparator));

// Contextual toolbars.
Expand Down
9 changes: 7 additions & 2 deletions editor/plugins/canvas_item_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,9 @@ class CanvasItemEditor : public VBoxContainer {
SHOW_GUIDES,
SHOW_ORIGIN,
SHOW_VIEWPORT,
SHOW_EDIT_LOCKS,
SHOW_POSITION_GIZMOS,
SHOW_LOCK_GIZMOS,
SHOW_GROUP_GIZMOS,
SHOW_TRANSFORMATION_GIZMOS,
LOCK_SELECTED,
UNLOCK_SELECTED,
Expand Down Expand Up @@ -202,7 +204,9 @@ class CanvasItemEditor : public VBoxContainer {
bool show_origin = true;
bool show_viewport = true;
bool show_helpers = false;
bool show_edit_locks = true;
bool show_position_gizmos = true;
bool show_lock_gizmos = true;
bool show_group_gizmos = true;
bool show_transformation_gizmos = true;

real_t zoom = 1.0;
Expand Down Expand Up @@ -323,6 +327,7 @@ class CanvasItemEditor : public VBoxContainer {
Button *override_camera_button = nullptr;
MenuButton *view_menu = nullptr;
PopupMenu *grid_menu = nullptr;
PopupMenu *gizmos_menu = nullptr;
HBoxContainer *animation_hb = nullptr;
MenuButton *animation_menu = nullptr;

Expand Down

0 comments on commit 5af18b2

Please sign in to comment.