From 93447eb1ae699362c14fc03913134ecff40e721a Mon Sep 17 00:00:00 2001 From: Markus Sauermann <6299227+Sauermann@users.noreply.github.com> Date: Fri, 11 Mar 2022 18:56:31 +0100 Subject: [PATCH] Use get_cursor_shape for identifying the cursor shape in AnimationNodeStateMachineEditor get_cursor_shape() is used in cases where a Control displays different cursors in different areas. There is no need to set the default cursor shape on every mouse move event. Fix minor issue with selection order. (cherry picked from commit 0d96dbcb2a6bad6d863971eb044e7749dc777f91) --- .../animation_state_machine_editor.cpp | 45 +++++++++---------- .../plugins/animation_state_machine_editor.h | 2 +- 2 files changed, 23 insertions(+), 24 deletions(-) diff --git a/editor/plugins/animation_state_machine_editor.cpp b/editor/plugins/animation_state_machine_editor.cpp index a85b0f8422c..27b720781da 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -343,29 +343,21 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Refupdate(); } - //put ibeam (text cursor) over names to make it clearer that they are editable if (mm.is_valid()) { state_machine_draw->grab_focus(); - bool over_text_now = false; String new_over_node = StringName(); int new_over_node_what = -1; if (tool_select->is_pressed()) { - for (int i = node_rects.size() - 1; i >= 0; i--) { //inverse to draw order - - if (node_rects[i].name.has_point(mm->get_position())) { - over_text_now = true; - break; - } - + for (int i = node_rects.size() - 1; i >= 0; i--) { // Inverse to draw order. if (node_rects[i].node.has_point(mm->get_position())) { new_over_node = node_rects[i].node_name; if (node_rects[i].play.has_point(mm->get_position())) { new_over_node_what = 0; - } - if (node_rects[i].edit.has_point(mm->get_position())) { + } else if (node_rects[i].edit.has_point(mm->get_position())) { new_over_node_what = 1; } + break; } } } @@ -375,16 +367,6 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Refupdate(); } - - if (over_text != over_text_now) { - if (over_text_now) { - state_machine_draw->set_default_cursor_shape(CURSOR_IBEAM); - } else { - state_machine_draw->set_default_cursor_shape(CURSOR_ARROW); - } - - over_text = over_text_now; - } } Ref pan_gesture = p_event; @@ -394,6 +376,23 @@ void AnimationNodeStateMachineEditor::_state_machine_gui_input(const Refget_transform() * state_machine_draw->get_transform(); + Point2 pos = xform.xform_inv(p_pos); + Control::CursorShape cursor_shape = get_default_cursor_shape(); + + for (int i = node_rects.size() - 1; i >= 0; i--) { // Inverse to draw order. + if (node_rects[i].node.has_point(pos)) { + if (node_rects[i].name.has_point(pos)) { + cursor_shape = Control::CURSOR_IBEAM; + } + break; + } + } + return cursor_shape; +} + void AnimationNodeStateMachineEditor::_file_opened(const String &p_file) { file_loaded = ResourceLoader::load(p_file); if (file_loaded.is_valid()) { @@ -1295,6 +1294,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { panel = memnew(PanelContainer); panel->set_clip_contents(true); + panel->set_mouse_filter(Control::MOUSE_FILTER_PASS); add_child(panel); panel->set_v_size_flags(SIZE_EXPAND_FILL); @@ -1303,6 +1303,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { state_machine_draw->connect("gui_input", this, "_state_machine_gui_input"); state_machine_draw->connect("draw", this, "_state_machine_draw"); state_machine_draw->set_focus_mode(FOCUS_ALL); + state_machine_draw->set_mouse_filter(Control::MOUSE_FILTER_PASS); state_machine_play_pos = memnew(Control); state_machine_draw->add_child(state_machine_play_pos); @@ -1354,8 +1355,6 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { open_file->connect("file_selected", this, "_file_opened"); undo_redo = EditorNode::get_undo_redo(); - over_text = false; - over_node_what = -1; dragging_selected_attempt = false; connecting = false; diff --git a/editor/plugins/animation_state_machine_editor.h b/editor/plugins/animation_state_machine_editor.h index f0c3f4bf8ba..4d295c5900e 100644 --- a/editor/plugins/animation_state_machine_editor.h +++ b/editor/plugins/animation_state_machine_editor.h @@ -136,7 +136,6 @@ class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin { StringName selected_transition_from; StringName selected_transition_to; - bool over_text; StringName over_node; int over_node_what; @@ -183,6 +182,7 @@ public: static AnimationNodeStateMachineEditor *get_singleton() { return singleton; } virtual bool can_edit(const Ref &p_node); virtual void edit(const Ref &p_node); + virtual CursorShape get_cursor_shape(const Point2 &p_pos) const; AnimationNodeStateMachineEditor(); };