summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjsjtxietian <jsjtxietian@outlook.com>2024-03-04 15:00:01 +0800
committerjsjtxietian <jsjtxietian@outlook.com>2024-03-06 10:24:18 +0800
commitb04720661921bd17930213832826cf585135fa14 (patch)
tree2cc229e956f075d15d91e515abe0228a766b2eb8
parentdf78c0636d79c9545a283e0e2a926d623998cc27 (diff)
downloadredot-engine-b04720661921bd17930213832826cf585135fa14.tar.gz
Update lock and group button state when selection changed
-rw-r--r--editor/plugins/canvas_item_editor_plugin.cpp62
-rw-r--r--editor/plugins/canvas_item_editor_plugin.h1
2 files changed, 34 insertions, 29 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp
index 7446857582..f8ce5484b9 100644
--- a/editor/plugins/canvas_item_editor_plugin.cpp
+++ b/editor/plugins/canvas_item_editor_plugin.cpp
@@ -2640,6 +2640,38 @@ void CanvasItemEditor::_update_cursor() {
set_default_cursor_shape(c);
}
+void CanvasItemEditor::_update_lock_and_group_button() {
+ bool all_locked = true;
+ bool all_group = true;
+ List<Node *> selection = editor_selection->get_selected_node_list();
+ if (selection.is_empty()) {
+ all_locked = false;
+ all_group = false;
+ } else {
+ for (Node *E : selection) {
+ CanvasItem *item = Object::cast_to<CanvasItem>(E);
+ if (item) {
+ if (all_locked && !item->has_meta("_edit_lock_")) {
+ all_locked = false;
+ }
+ if (all_group && !item->has_meta("_edit_group_")) {
+ all_group = false;
+ }
+ }
+ if (!all_locked && !all_group) {
+ break;
+ }
+ }
+ }
+
+ lock_button->set_visible(!all_locked);
+ lock_button->set_disabled(selection.is_empty());
+ unlock_button->set_visible(all_locked);
+ group_button->set_visible(!all_group);
+ group_button->set_disabled(selection.is_empty());
+ ungroup_button->set_visible(all_group);
+}
+
Control::CursorShape CanvasItemEditor::get_cursor_shape(const Point2 &p_pos) const {
// Compute an eventual rotation of the cursor
const CursorShape rotation_array[4] = { CURSOR_HSIZE, CURSOR_BDIAGSIZE, CURSOR_VSIZE, CURSOR_FDIAGSIZE };
@@ -3795,35 +3827,6 @@ void CanvasItemEditor::_draw_viewport() {
transform.columns[2] = -view_offset * zoom;
EditorNode::get_singleton()->get_scene_root()->set_global_canvas_transform(transform);
- // hide/show buttons depending on the selection
- bool all_locked = true;
- bool all_group = true;
- List<Node *> selection = editor_selection->get_selected_node_list();
- if (selection.is_empty()) {
- all_locked = false;
- all_group = false;
- } else {
- for (Node *E : selection) {
- if (Object::cast_to<CanvasItem>(E) && !Object::cast_to<CanvasItem>(E)->has_meta("_edit_lock_")) {
- all_locked = false;
- break;
- }
- }
- for (Node *E : selection) {
- if (Object::cast_to<CanvasItem>(E) && !Object::cast_to<CanvasItem>(E)->has_meta("_edit_group_")) {
- all_group = false;
- break;
- }
- }
- }
-
- lock_button->set_visible(!all_locked);
- lock_button->set_disabled(selection.is_empty());
- unlock_button->set_visible(all_locked);
- group_button->set_visible(!all_group);
- group_button->set_disabled(selection.is_empty());
- ungroup_button->set_visible(all_group);
-
_draw_grid();
_draw_ruler_tool();
_draw_axis();
@@ -4027,6 +4030,7 @@ void CanvasItemEditor::_notification(int p_what) {
}
void CanvasItemEditor::_selection_changed() {
+ _update_lock_and_group_button();
if (!selected_from_canvas) {
_reset_drag();
}
diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h
index 4e160dde47..723dbc7f59 100644
--- a/editor/plugins/canvas_item_editor_plugin.h
+++ b/editor/plugins/canvas_item_editor_plugin.h
@@ -477,6 +477,7 @@ private:
void _gui_input_viewport(const Ref<InputEvent> &p_event);
void _update_cursor();
+ void _update_lock_and_group_button();
void _selection_changed();
void _focus_selection(int p_op);