Skip to content

Commit

Permalink
Fix Path2D splitting
Browse files Browse the repository at this point in the history
  • Loading branch information
KoBeWi committed Aug 28, 2024
1 parent e439154 commit 7e7a4f2
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 7 deletions.
24 changes: 17 additions & 7 deletions editor/plugins/path_2d_editor_plugin.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -197,12 +197,7 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
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", new_point, Vector2(0, 0), Vector2(0, 0), insertion_point + 1);
undo_redo->add_undo_method(curve.ptr(), "remove_point", insertion_point + 1);

action = ACTION_MOVING_NEW_POINT;
action = ACTION_MOVING_NEW_POINT_FROM_SPLIT;
action_point = insertion_point + 1;
moving_from = curve->get_point_position(action_point);
moving_screen_from = gpoint2;
Expand Down Expand Up @@ -245,6 +240,16 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
undo_redo->commit_action(false);
} break;

case ACTION_MOVING_NEW_POINT_FROM_SPLIT: {
undo_redo->create_action(TTR("Split Curve"));
undo_redo->add_do_method(curve.ptr(), "add_point", Vector2(), Vector2(), Vector2(), action_point);
undo_redo->add_do_method(curve.ptr(), "set_point_position", action_point, cpoint);
undo_redo->add_undo_method(curve.ptr(), "remove_point", action_point);
undo_redo->add_do_method(canvas_item_editor, "update_viewport");
undo_redo->add_undo_method(canvas_item_editor, "update_viewport");
undo_redo->commit_action(false);
} break;

case ACTION_MOVING_IN: {
if (original_mouse_pos != gpoint) {
undo_redo->create_action(TTR("Move In-Control in Curve"));
Expand Down Expand Up @@ -350,7 +355,8 @@ bool Path2DEditor::forward_gui_input(const Ref<InputEvent> &p_event) {
break;

case ACTION_MOVING_POINT:
case ACTION_MOVING_NEW_POINT: {
case ACTION_MOVING_NEW_POINT:
case ACTION_MOVING_NEW_POINT_FROM_SPLIT: {
curve->set_point_position(action_point, cpoint);
} break;

Expand Down Expand Up @@ -573,6 +579,10 @@ void Path2DEditor::_cancel_current_action() {
curve->remove_point(curve->get_point_count() - 1);
} break;

case ACTION_MOVING_NEW_POINT_FROM_SPLIT: {
curve->remove_point(action_point);
} break;

case ACTION_MOVING_IN: {
curve->set_point_in(action_point, moving_from);
curve->set_point_out(action_point, mirror_handle_length ? -moving_from : (-moving_from.normalized() * orig_out_length));
Expand Down
1 change: 1 addition & 0 deletions editor/plugins/path_2d_editor_plugin.h
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ class Path2DEditor : public HBoxContainer {
ACTION_NONE,
ACTION_MOVING_POINT,
ACTION_MOVING_NEW_POINT,
ACTION_MOVING_NEW_POINT_FROM_SPLIT,
ACTION_MOVING_IN,
ACTION_MOVING_OUT,
};
Expand Down

0 comments on commit 7e7a4f2

Please sign in to comment.