You've already forked godot
mirror of
https://github.com/godotengine/godot.git
synced 2025-11-06 12:20:30 +00:00
Merge pull request #59081 from Sauermann/fix-cursorshape-canvasitemeditor
Use get_cursor_shape for identifying the cursor shape in CanvasItemEditor
This commit is contained in:
@@ -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);
|
||||
@@ -1226,7 +1226,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) {
|
||||
@@ -2570,8 +2569,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())) {
|
||||
@@ -2580,6 +2581,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;
|
||||
@@ -2601,26 +2627,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];
|
||||
@@ -2662,16 +2670,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) {
|
||||
|
||||
Reference in New Issue
Block a user