Fix scale cursor rotation and handle diagonal ones

(cherry picked from commit 6dd19af439)
This commit is contained in:
Gilles Roudière 2020-10-01 12:19:45 +02:00 committed by Rémi Verschelde
parent a726d011d5
commit 14fa64d289
No known key found for this signature in database
GPG Key ID: C3336907360768E1

View File

@ -2487,13 +2487,28 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
// Handles the mouse hovering // Handles the mouse hovering
_gui_input_hover(p_event); _gui_input_hover(p_event);
// Change the cursor // Compute an eventual rotation of the cursor
CursorShape c = CURSOR_ARROW; CursorShape rotation_array[4] = { CURSOR_HSIZE, CURSOR_BDIAGSIZE, CURSOR_VSIZE, CURSOR_FDIAGSIZE };
bool should_switch = false; int rotation_array_index = 0;
if (drag_selection.size() != 0) {
float angle = drag_selection[0]->_edit_get_rotation(); List<CanvasItem *> selection = _get_edited_canvas_items();
should_switch = abs(Math::cos(angle)) < Math_SQRT12; if (selection.size() == 1) {
float angle = Math::fposmod((double)selection[0]->get_global_transform_with_canvas().get_rotation(), Math_PI);
if (angle > Math_PI * 7.0 / 8.0) {
rotation_array_index = 0;
} else if (angle > Math_PI * 5.0 / 8.0) {
rotation_array_index = 1;
} else if (angle > Math_PI * 3.0 / 8.0) {
rotation_array_index = 2;
} else if (angle > Math_PI * 1.0 / 8.0) {
rotation_array_index = 3;
} else {
rotation_array_index = 0;
}
} }
// Choose the correct cursor
CursorShape c = CURSOR_ARROW;
switch (drag_type) { switch (drag_type) {
case DRAG_NONE: case DRAG_NONE:
switch (tool) { switch (tool) {
@ -2515,38 +2530,28 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
break; break;
case DRAG_LEFT: case DRAG_LEFT:
case DRAG_RIGHT: case DRAG_RIGHT:
c = rotation_array[rotation_array_index];
break;
case DRAG_V_GUIDE: case DRAG_V_GUIDE:
if (should_switch) { c = CURSOR_HSIZE;
c = CURSOR_VSIZE;
} else {
c = CURSOR_HSIZE;
}
break; break;
case DRAG_TOP: case DRAG_TOP:
case DRAG_BOTTOM: case DRAG_BOTTOM:
c = rotation_array[(rotation_array_index + 2) % 4];
break;
case DRAG_H_GUIDE: case DRAG_H_GUIDE:
if (should_switch) { c = CURSOR_VSIZE;
c = CURSOR_HSIZE;
} else {
c = CURSOR_VSIZE;
}
break; break;
case DRAG_TOP_LEFT: case DRAG_TOP_LEFT:
case DRAG_BOTTOM_RIGHT: case DRAG_BOTTOM_RIGHT:
c = rotation_array[(rotation_array_index + 3) % 4];
break;
case DRAG_DOUBLE_GUIDE: case DRAG_DOUBLE_GUIDE:
if (should_switch) { c = CURSOR_FDIAGSIZE;
c = CURSOR_BDIAGSIZE;
} else {
c = CURSOR_FDIAGSIZE;
}
break; break;
case DRAG_TOP_RIGHT: case DRAG_TOP_RIGHT:
case DRAG_BOTTOM_LEFT: case DRAG_BOTTOM_LEFT:
if (should_switch) { c = rotation_array[(rotation_array_index + 1) % 4];
c = CURSOR_FDIAGSIZE;
} else {
c = CURSOR_BDIAGSIZE;
}
break; break;
case DRAG_MOVE: case DRAG_MOVE:
c = CURSOR_MOVE; c = CURSOR_MOVE;