Use resize cursors when hovering or dragging guides in the 2D editor
This also tweaks the casing in undo/redo action names for consistency. This closes #30550. Co-authored-by: Emmanuel Barroga <emmanuelbarroga@gmail.com>
This commit is contained in:
parent
584ca0f156
commit
0fb80d7b0f
2 changed files with 56 additions and 20 deletions
|
@ -860,20 +860,47 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
Ref<InputEventMouseButton> b = p_event;
|
||||
Ref<InputEventMouseMotion> m = p_event;
|
||||
|
||||
// Start dragging a guide
|
||||
if (drag_type == DRAG_NONE) {
|
||||
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
|
||||
if (show_guides && show_rulers && EditorNode::get_singleton()->get_edited_scene()) {
|
||||
Transform2D xform = viewport_scrollable->get_transform() * transform;
|
||||
// Retrieve the guide lists
|
||||
Array vguides;
|
||||
if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
|
||||
vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
|
||||
if (show_guides && show_rulers && EditorNode::get_singleton()->get_edited_scene()) {
|
||||
Transform2D xform = viewport_scrollable->get_transform() * transform;
|
||||
// Retrieve the guide lists
|
||||
Array vguides;
|
||||
if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_vertical_guides_")) {
|
||||
vguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_vertical_guides_");
|
||||
}
|
||||
Array hguides;
|
||||
if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) {
|
||||
hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_");
|
||||
}
|
||||
|
||||
// Hover over guides
|
||||
float minimum = 1e20;
|
||||
is_hovering_h_guide = false;
|
||||
is_hovering_v_guide = false;
|
||||
|
||||
if (m.is_valid() && m->get_position().x < RULER_WIDTH) {
|
||||
// Check if we are hovering an existing horizontal guide
|
||||
for (int i = 0; i < hguides.size(); i++) {
|
||||
if (ABS(xform.xform(Point2(0, hguides[i])).y - m->get_position().y) < MIN(minimum, 8)) {
|
||||
is_hovering_h_guide = true;
|
||||
is_hovering_v_guide = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
Array hguides;
|
||||
if (EditorNode::get_singleton()->get_edited_scene()->has_meta("_edit_horizontal_guides_")) {
|
||||
hguides = EditorNode::get_singleton()->get_edited_scene()->get_meta("_edit_horizontal_guides_");
|
||||
|
||||
} else if (m.is_valid() && m->get_position().y < RULER_WIDTH) {
|
||||
// Check if we are hovering an existing vertical guide
|
||||
for (int i = 0; i < vguides.size(); i++) {
|
||||
if (ABS(xform.xform(Point2(vguides[i], 0)).x - m->get_position().x) < MIN(minimum, 8)) {
|
||||
is_hovering_v_guide = true;
|
||||
is_hovering_h_guide = false;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
// Start dragging a guide
|
||||
if (b.is_valid() && b->get_button_index() == BUTTON_LEFT && b->is_pressed()) {
|
||||
|
||||
// Press button
|
||||
if (b->get_position().x < RULER_WIDTH && b->get_position().y < RULER_WIDTH) {
|
||||
|
@ -883,7 +910,6 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
return true;
|
||||
} else if (b->get_position().x < RULER_WIDTH) {
|
||||
// Check if we drag an existing horizontal guide
|
||||
float minimum = 1e20;
|
||||
dragged_guide_index = -1;
|
||||
for (int i = 0; i < hguides.size(); i++) {
|
||||
if (ABS(xform.xform(Point2(0, hguides[i])).y - b->get_position().y) < MIN(minimum, 8)) {
|
||||
|
@ -901,7 +927,6 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
return true;
|
||||
} else if (b->get_position().y < RULER_WIDTH) {
|
||||
// Check if we drag an existing vertical guide
|
||||
float minimum = 1e20;
|
||||
dragged_guide_index = -1;
|
||||
for (int i = 0; i < vguides.size(); i++) {
|
||||
if (ABS(xform.xform(Point2(vguides[i], 0)).x - b->get_position().x) < MIN(minimum, 8)) {
|
||||
|
@ -956,14 +981,14 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
// Adds a new vertical guide
|
||||
if (dragged_guide_index >= 0) {
|
||||
vguides[dragged_guide_index] = edited.x;
|
||||
undo_redo->create_action(TTR("Move vertical guide"));
|
||||
undo_redo->create_action(TTR("Move Vertical Guide"));
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
|
||||
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
|
||||
undo_redo->add_undo_method(viewport, "update");
|
||||
undo_redo->commit_action();
|
||||
} else {
|
||||
vguides.push_back(edited.x);
|
||||
undo_redo->create_action(TTR("Create new vertical guide"));
|
||||
undo_redo->create_action(TTR("Create Vertical Guide"));
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
|
||||
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
|
||||
undo_redo->add_undo_method(viewport, "update");
|
||||
|
@ -972,7 +997,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
} else {
|
||||
if (dragged_guide_index >= 0) {
|
||||
vguides.remove(dragged_guide_index);
|
||||
undo_redo->create_action(TTR("Remove vertical guide"));
|
||||
undo_redo->create_action(TTR("Remove Vertical Guide"));
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
|
||||
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
|
||||
undo_redo->add_undo_method(viewport, "update");
|
||||
|
@ -985,14 +1010,14 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
// Adds a new horizontal guide
|
||||
if (dragged_guide_index >= 0) {
|
||||
hguides[dragged_guide_index] = edited.y;
|
||||
undo_redo->create_action(TTR("Move horizontal guide"));
|
||||
undo_redo->create_action(TTR("Move Horizontal Guide"));
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
|
||||
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
|
||||
undo_redo->add_undo_method(viewport, "update");
|
||||
undo_redo->commit_action();
|
||||
} else {
|
||||
hguides.push_back(edited.y);
|
||||
undo_redo->create_action(TTR("Create new horizontal guide"));
|
||||
undo_redo->create_action(TTR("Create Horizontal Guide"));
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
|
||||
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
|
||||
undo_redo->add_undo_method(viewport, "update");
|
||||
|
@ -1001,7 +1026,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
} else {
|
||||
if (dragged_guide_index >= 0) {
|
||||
hguides.remove(dragged_guide_index);
|
||||
undo_redo->create_action(TTR("Remove horizontal guide"));
|
||||
undo_redo->create_action(TTR("Remove Horizontal Guide"));
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
|
||||
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", prev_hguides);
|
||||
undo_redo->add_undo_method(viewport, "update");
|
||||
|
@ -1015,7 +1040,7 @@ bool CanvasItemEditor::_gui_input_rulers_and_guides(const Ref<InputEvent> &p_eve
|
|||
// Adds a new horizontal guide a new vertical guide
|
||||
vguides.push_back(edited.x);
|
||||
hguides.push_back(edited.y);
|
||||
undo_redo->create_action(TTR("Create new horizontal and vertical guides"));
|
||||
undo_redo->create_action(TTR("Create Horizontal and Vertical Guides"));
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", vguides);
|
||||
undo_redo->add_do_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_horizontal_guides_", hguides);
|
||||
undo_redo->add_undo_method(EditorNode::get_singleton()->get_edited_scene(), "set_meta", "_edit_vertical_guides_", prev_vguides);
|
||||
|
@ -2268,14 +2293,17 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
|
|||
break;
|
||||
case DRAG_LEFT:
|
||||
case DRAG_RIGHT:
|
||||
case DRAG_V_GUIDE:
|
||||
c = CURSOR_HSIZE;
|
||||
break;
|
||||
case DRAG_TOP:
|
||||
case DRAG_BOTTOM:
|
||||
case DRAG_H_GUIDE:
|
||||
c = CURSOR_VSIZE;
|
||||
break;
|
||||
case DRAG_TOP_LEFT:
|
||||
case DRAG_BOTTOM_RIGHT:
|
||||
case DRAG_DOUBLE_GUIDE:
|
||||
c = CURSOR_FDIAGSIZE;
|
||||
break;
|
||||
case DRAG_TOP_RIGHT:
|
||||
|
@ -2288,6 +2316,12 @@ void CanvasItemEditor::_gui_input_viewport(const Ref<InputEvent> &p_event) {
|
|||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
if (is_hovering_h_guide)
|
||||
c = CURSOR_VSIZE;
|
||||
else if (is_hovering_v_guide)
|
||||
c = CURSOR_HSIZE;
|
||||
|
||||
viewport->set_default_cursor_shape(c);
|
||||
|
||||
// Grab focus
|
||||
|
|
|
@ -371,6 +371,8 @@ private:
|
|||
List<CanvasItem *> drag_selection;
|
||||
int dragged_guide_index;
|
||||
Point2 dragged_guide_pos;
|
||||
bool is_hovering_h_guide;
|
||||
bool is_hovering_v_guide;
|
||||
|
||||
bool updating_value_dialog;
|
||||
|
||||
|
|
Loading…
Reference in a new issue