From 0d96dbcb2a6bad6d863971eb044e7749dc777f91 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. --- .../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 2f94176e2ad..bd0c1afd191 100644 --- a/editor/plugins/animation_state_machine_editor.cpp +++ b/editor/plugins/animation_state_machine_editor.cpp @@ -346,29 +346,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; } } } @@ -378,16 +370,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; @@ -397,6 +379,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()) { @@ -1287,6 +1286,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); @@ -1295,6 +1295,7 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { state_machine_draw->connect("gui_input", callable_mp(this, &AnimationNodeStateMachineEditor::_state_machine_gui_input)); state_machine_draw->connect("draw", callable_mp(this, &AnimationNodeStateMachineEditor::_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); @@ -1347,8 +1348,6 @@ AnimationNodeStateMachineEditor::AnimationNodeStateMachineEditor() { open_file->connect("file_selected", callable_mp(this, &AnimationNodeStateMachineEditor::_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 208bd27f8e0..03991d00f96 100644 --- a/editor/plugins/animation_state_machine_editor.h +++ b/editor/plugins/animation_state_machine_editor.h @@ -138,7 +138,6 @@ class AnimationNodeStateMachineEditor : public AnimationTreeNodeEditorPlugin { StringName selected_transition_from; StringName selected_transition_to; - bool over_text; StringName over_node; int over_node_what; @@ -185,6 +184,7 @@ public: static AnimationNodeStateMachineEditor *get_singleton() { return singleton; } virtual bool can_edit(const Ref &p_node) override; virtual void edit(const Ref &p_node) override; + virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override; AnimationNodeStateMachineEditor(); };