1
0
mirror of https://github.com/godotengine/godot.git synced 2025-11-07 12:30:27 +00:00

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.
This commit is contained in:
Markus Sauermann
2022-04-06 08:42:47 +02:00
parent c0de8d32d5
commit 69fca9286f
2 changed files with 37 additions and 36 deletions

View File

@@ -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) {