From d0ecf3b03d2afe46831d081fd0ba8a8dca95e65f Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 21 Nov 2024 16:33:19 +0200 Subject: [PATCH] Center diagonal symmetry guides when initializing a new project The guides appear centered, but the symmetry itself is not working properly yet --- src/Autoload/Tools.gd | 11 +++++++---- src/Classes/Project.gd | 8 ++++++-- src/UI/Canvas/Rulers/Guide.gd | 5 +++-- 3 files changed, 16 insertions(+), 8 deletions(-) diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index f6d9f86fb..f1cd0bb08 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -548,7 +548,7 @@ func get_mirrored_positions( if diagonal_xy_mirror: var mirror_diagonal := calculate_mirror_xy(pos, project) positions.append(mirror_diagonal) - if not horizontal_mirror and not vertical_mirror: + if not horizontal_mirror and not vertical_mirror and diagonal_x_minus_y_mirror: positions.append(calculate_mirror_x_minus_y(mirror_diagonal, project)) if diagonal_x_minus_y_mirror: positions.append(calculate_mirror_x_minus_y(pos, project)) @@ -564,11 +564,14 @@ func calculate_mirror_vertical(pos: Vector2i, project: Project, offset := 0) -> func calculate_mirror_xy(pos: Vector2i, project: Project) -> Vector2i: - return Vector2i(Vector2(pos).reflect(XY_LINE).round()) + project.size - Vector2i.ONE + return Vector2i(Vector2(pos).reflect(XY_LINE).round()) + Vector2i(project.xy_symmetry_point) -func calculate_mirror_x_minus_y(pos: Vector2i, _project: Project) -> Vector2i: - return Vector2i(Vector2(pos).reflect(X_MINUS_Y_LINE).round()) +func calculate_mirror_x_minus_y(pos: Vector2i, project: Project) -> Vector2i: + return ( + Vector2i(Vector2(pos).reflect(X_MINUS_Y_LINE).round()) + + Vector2i(project.x_minus_y_symmetry_point) + ) func set_button_size(button_size: int) -> void: diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 809639322..19f41db8d 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -69,6 +69,8 @@ var user_data := "" ## User defined data, set in the project properties. var x_symmetry_point: float var y_symmetry_point: float +var xy_symmetry_point: Vector2 +var x_minus_y_symmetry_point: Vector2 var x_symmetry_axis := SymmetryGuide.new() var y_symmetry_axis := SymmetryGuide.new() var diagonal_xy_symmetry_axis := SymmetryGuide.new() @@ -113,6 +115,8 @@ func _init(_frames: Array[Frame] = [], _name := tr("untitled"), _size := Vector2 x_symmetry_point = size.x - 1 y_symmetry_point = size.y - 1 + xy_symmetry_point = Vector2i(size.y, size.x) - Vector2i.ONE + x_minus_y_symmetry_point = Vector2(maxi(size.x - size.y, 0), maxi(size.y - size.x, 0)) x_symmetry_axis.type = Guide.Types.HORIZONTAL x_symmetry_axis.project = self x_symmetry_axis.add_point(Vector2(-19999, y_symmetry_point / 2 + 0.5)) @@ -128,13 +132,13 @@ func _init(_frames: Array[Frame] = [], _name := tr("untitled"), _size := Vector2 diagonal_xy_symmetry_axis.type = Guide.Types.XY diagonal_xy_symmetry_axis.project = self diagonal_xy_symmetry_axis.add_point(Vector2(19999, -19999)) - diagonal_xy_symmetry_axis.add_point(Vector2i(-19999, 19999) + size) + diagonal_xy_symmetry_axis.add_point(Vector2(-19999, 19999) + xy_symmetry_point + Vector2.ONE) Global.canvas.add_child(diagonal_xy_symmetry_axis) diagonal_x_minus_y_symmetry_axis.type = Guide.Types.X_MINUS_Y diagonal_x_minus_y_symmetry_axis.project = self diagonal_x_minus_y_symmetry_axis.add_point(Vector2(-19999, -19999)) - diagonal_x_minus_y_symmetry_axis.add_point(Vector2(19999, 19999)) + diagonal_x_minus_y_symmetry_axis.add_point(Vector2(19999, 19999) + x_minus_y_symmetry_point) Global.canvas.add_child(diagonal_x_minus_y_symmetry_axis) if OS.get_name() == "Web": diff --git a/src/UI/Canvas/Rulers/Guide.gd b/src/UI/Canvas/Rulers/Guide.gd index e874af01b..3a4fa7230 100644 --- a/src/UI/Canvas/Rulers/Guide.gd +++ b/src/UI/Canvas/Rulers/Guide.gd @@ -31,12 +31,13 @@ func _input(_event: InputEvent) -> void: if type == Types.HORIZONTAL: point0.y -= width * INPUT_WIDTH point1.y += width * INPUT_WIDTH - else: + elif type == Types.VERTICAL: point0.x -= width * INPUT_WIDTH point1.x += width * INPUT_WIDTH var rect := Rect2() rect.position = point0 rect.end = point1 + rect = rect.abs() if ( Input.is_action_just_pressed(&"left_mouse") and Global.can_draw @@ -55,7 +56,7 @@ func _input(_event: InputEvent) -> void: var yy := snappedf(mouse_pos.y, 0.5) points[0].y = yy points[1].y = yy - else: + elif type == Types.VERTICAL: var xx := snappedf(mouse_pos.x, 0.5) points[0].x = xx points[1].x = xx