diff options
author | Markus Sauermann <6299227+Sauermann@users.noreply.github.com> | 2022-04-06 08:42:47 +0200 |
---|---|---|
committer | Markus Sauermann <6299227+Sauermann@users.noreply.github.com> | 2022-11-03 19:34:43 +0100 |
commit | 69fca9286fb53870a403c2c1e9e3f4c3ae801233 (patch) | |
tree | 1125ea8969340d48003e64ed24aea8f30ebbcb91 | |
parent | c0de8d32d51d579e6dc1a5aac3fbcd6c7104eb61 (diff) |
Use get_cursor_shape for identifying the cursor shape in CanvasItemEditor
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.
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.cpp | 67 | ||||
-rw-r--r-- | editor/plugins/canvas_item_editor_plugin.h | 6 |
2 files changed, 37 insertions, 36 deletions
diff --git a/editor/plugins/canvas_item_editor_plugin.cpp b/editor/plugins/canvas_item_editor_plugin.cpp index 1d6f41d4c4..c5e4997df9 100644 --- a/editor/plugins/canvas_item_editor_plugin.cpp +++ b/editor/plugins/canvas_item_editor_plugin.cpp @@ -246,7 +246,7 @@ public: } }; -bool CanvasItemEditor::_is_node_locked(const Node *p_node) { +bool CanvasItemEditor::_is_node_locked(const Node *p_node) const { return p_node->get_meta("_edit_lock_", false); } @@ -770,7 +770,7 @@ bool CanvasItemEditor::_select_click_on_item(CanvasItem *item, Point2 p_click_po return still_selected; } -List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool retrieve_locked, bool remove_canvas_item_if_parent_in_selection) { +List<CanvasItem *> CanvasItemEditor::_get_edited_canvas_items(bool retrieve_locked, bool remove_canvas_item_if_parent_in_selection) const { List<CanvasItem *> selection; for (const KeyValue<Node *, Object *> &E : editor_selection->get_selection()) { CanvasItem *ci = Object::cast_to<CanvasItem>(E.key); @@ -1228,7 +1228,6 @@ bool CanvasItemEditor::_gui_input_zoom_or_pan(const Ref<InputEvent> &p_event, bo bool panner_active = panner->gui_input(p_event, warped_panning ? viewport->get_global_rect() : Rect2()); if (panner->is_panning() != pan_pressed) { pan_pressed = panner->is_panning(); - _update_cursor(); } if (panner_active) { @@ -2584,8 +2583,10 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { // Handles the mouse hovering _gui_input_hover(p_event); - // Change the cursor - _update_cursor(); + if (mb.is_valid()) { + // Update the default cursor. + _update_cursor(); + } // Grab focus if (!viewport->has_focus() && (!get_viewport()->gui_get_focus_owner() || !get_viewport()->gui_get_focus_owner()->is_text_field())) { @@ -2594,6 +2595,31 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) { } void CanvasItemEditor::_update_cursor() { + // Choose the correct default cursor. + CursorShape c = CURSOR_ARROW; + switch (tool) { + case TOOL_MOVE: + c = CURSOR_MOVE; + break; + case TOOL_EDIT_PIVOT: + c = CURSOR_CROSS; + break; + case TOOL_PAN: + c = CURSOR_DRAG; + break; + case TOOL_RULER: + c = CURSOR_CROSS; + break; + default: + break; + } + if (pan_pressed) { + c = CURSOR_DRAG; + } + set_default_cursor_shape(c); +} + +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 }; int rotation_array_index = 0; @@ -2615,26 +2641,8 @@ void CanvasItemEditor::_update_cursor() { } // Choose the correct cursor - CursorShape c = CURSOR_ARROW; + CursorShape c = get_default_cursor_shape(); switch (drag_type) { - case DRAG_NONE: - switch (tool) { - case TOOL_MOVE: - c = CURSOR_MOVE; - break; - case TOOL_EDIT_PIVOT: - c = CURSOR_CROSS; - break; - case TOOL_PAN: - c = CURSOR_DRAG; - break; - case TOOL_RULER: - c = CURSOR_CROSS; - break; - default: - break; - } - break; case DRAG_LEFT: case DRAG_RIGHT: c = rotation_array[rotation_array_index]; @@ -2676,16 +2684,7 @@ void CanvasItemEditor::_update_cursor() { if (pan_pressed) { c = CURSOR_DRAG; } - - if (c != viewport->get_default_cursor_shape()) { - viewport->set_default_cursor_shape(c); - - // Force refresh cursor if it's over the viewport. - if (viewport->get_global_rect().has_point(get_global_mouse_position())) { - DisplayServer::CursorShape ds_cursor_shape = (DisplayServer::CursorShape)viewport->get_default_cursor_shape(); - DisplayServer::get_singleton()->cursor_set_shape(ds_cursor_shape); - } - } + return c; } void CanvasItemEditor::_draw_text_at_position(Point2 p_position, String p_string, Side p_side) { diff --git a/editor/plugins/canvas_item_editor_plugin.h b/editor/plugins/canvas_item_editor_plugin.h index ba193a67b8..e2438e5506 100644 --- a/editor/plugins/canvas_item_editor_plugin.h +++ b/editor/plugins/canvas_item_editor_plugin.h @@ -366,7 +366,7 @@ private: void _pan_callback(Vector2 p_scroll_vec); void _zoom_callback(Vector2 p_scroll_vec, Vector2 p_origin, bool p_alt); - bool _is_node_locked(const Node *p_node); + bool _is_node_locked(const Node *p_node) const; bool _is_node_movable(const Node *p_node, bool p_popup_warning = false); void _find_canvas_items_at_pos(const Point2 &p_pos, Node *p_node, Vector<_SelectResult> &r_items, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D()); void _get_canvas_items_at_pos(const Point2 &p_pos, Vector<_SelectResult> &r_items, bool p_allow_locked = false); @@ -400,7 +400,7 @@ private: void _prepare_grid_menu(); void _on_grid_menu_id_pressed(int p_id); - List<CanvasItem *> _get_edited_canvas_items(bool retrieve_locked = false, bool remove_canvas_item_if_parent_in_selection = true); + List<CanvasItem *> _get_edited_canvas_items(bool retrieve_locked = false, bool remove_canvas_item_if_parent_in_selection = true) const; Rect2 _get_encompassing_rect_from_list(List<CanvasItem *> p_list); void _expand_encompassing_rect_using_children(Rect2 &r_rect, const Node *p_node, bool &r_first, const Transform2D &p_parent_xform = Transform2D(), const Transform2D &p_canvas_xform = Transform2D(), bool include_locked_nodes = true); Rect2 _get_encompassing_rect(const Node *p_node); @@ -549,6 +549,8 @@ public: void focus_selection(); + virtual CursorShape get_cursor_shape(const Point2 &p_pos) const override; + EditorSelection *editor_selection = nullptr; CanvasItemEditor(); |