diff options
author | kobewi <kobewi4e@gmail.com> | 2023-12-26 22:56:14 +0100 |
---|---|---|
committer | kobewi <kobewi4e@gmail.com> | 2024-01-05 22:34:31 +0100 |
commit | f41b2c2ec4052cc93a581b6fbb4a446b79e5629b (patch) | |
tree | cd8a7bb6e1c958cbc977d447586b1e9799d932a9 | |
parent | 89cc635c0554cb2e518c830969ca4c5eedda0f4e (diff) | |
download | redot-engine-f41b2c2ec4052cc93a581b6fbb4a446b79e5629b.tar.gz |
Improve Path2D editing
-rw-r--r-- | editor/plugins/path_2d_editor_plugin.cpp | 32 | ||||
-rw-r--r-- | editor/plugins/path_2d_editor_plugin.h | 1 |
2 files changed, 18 insertions, 15 deletions
diff --git a/editor/plugins/path_2d_editor_plugin.cpp b/editor/plugins/path_2d_editor_plugin.cpp index 2e65000f9c..6f44dfc755 100644 --- a/editor/plugins/path_2d_editor_plugin.cpp +++ b/editor/plugins/path_2d_editor_plugin.cpp @@ -156,16 +156,14 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // Check for point creation. if (mb->is_pressed() && mb->get_button_index() == MouseButton::LEFT && ((mb->is_command_or_control_pressed() && mode == MODE_EDIT) || mode == MODE_CREATE)) { Ref<Curve2D> curve = node->get_curve(); + curve->add_point(cpoint); EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Add Point to Curve")); undo_redo->add_do_method(curve.ptr(), "add_point", cpoint); - undo_redo->add_undo_method(curve.ptr(), "remove_point", curve->get_point_count()); - undo_redo->add_do_method(canvas_item_editor, "update_viewport"); - undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); - undo_redo->commit_action(); + undo_redo->add_undo_method(curve.ptr(), "remove_point", curve->get_point_count() - 1); - action = ACTION_MOVING_POINT; + action = ACTION_MOVING_NEW_POINT; action_point = curve->get_point_count() - 1; moving_from = curve->get_point_position(action_point); moving_screen_from = gpoint; @@ -193,15 +191,15 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { insertion_point = curve->get_point_count() - 2; } + const Vector2 new_point = xform.affine_inverse().xform(gpoint2); + curve->add_point(new_point, Vector2(0, 0), Vector2(0, 0), insertion_point + 1); + EditorUndoRedoManager *undo_redo = EditorUndoRedoManager::get_singleton(); undo_redo->create_action(TTR("Split Curve")); - undo_redo->add_do_method(curve.ptr(), "add_point", xform.affine_inverse().xform(gpoint2), Vector2(0, 0), Vector2(0, 0), insertion_point + 1); + undo_redo->add_do_method(curve.ptr(), "add_point", new_point, Vector2(0, 0), Vector2(0, 0), insertion_point + 1); undo_redo->add_undo_method(curve.ptr(), "remove_point", insertion_point + 1); - undo_redo->add_do_method(canvas_item_editor, "update_viewport"); - undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); - undo_redo->commit_action(); - action = ACTION_MOVING_POINT; + action = ACTION_MOVING_NEW_POINT; action_point = insertion_point + 1; moving_from = curve->get_point_position(action_point); moving_screen_from = gpoint2; @@ -224,13 +222,16 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // N/A, handled in above condition. break; - case ACTION_MOVING_POINT: { - undo_redo->create_action(TTR("Move Point in Curve")); + case ACTION_MOVING_POINT: + case ACTION_MOVING_NEW_POINT: { + if (action == ACTION_MOVING_POINT) { + undo_redo->create_action(TTR("Move Point in Curve")); + undo_redo->add_undo_method(curve.ptr(), "set_point_position", action_point, moving_from); + } undo_redo->add_do_method(curve.ptr(), "set_point_position", action_point, cpoint); - undo_redo->add_undo_method(curve.ptr(), "set_point_position", action_point, moving_from); undo_redo->add_do_method(canvas_item_editor, "update_viewport"); undo_redo->add_undo_method(canvas_item_editor, "update_viewport"); - undo_redo->commit_action(); + undo_redo->commit_action(false); } break; @@ -336,7 +337,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) { // N/A, handled in above condition. break; - case ACTION_MOVING_POINT: { + case ACTION_MOVING_POINT: + case ACTION_MOVING_NEW_POINT: { curve->set_point_position(action_point, cpoint); } break; diff --git a/editor/plugins/path_2d_editor_plugin.h b/editor/plugins/path_2d_editor_plugin.h index f70c742e42..af9f307cc8 100644 --- a/editor/plugins/path_2d_editor_plugin.h +++ b/editor/plugins/path_2d_editor_plugin.h @@ -80,6 +80,7 @@ class Path2DEditor : public HBoxContainer { enum Action { ACTION_NONE, ACTION_MOVING_POINT, + ACTION_MOVING_NEW_POINT, ACTION_MOVING_IN, ACTION_MOVING_OUT, }; |