From aa1731b7014088b6e3714123d381aeafda382af9 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Thu, 21 Nov 2024 04:00:40 +0200 Subject: [PATCH] Initial work on diagonal symmetry guides Still no buttons yet, and they cannot be moved yet. --- src/Autoload/Global.gd | 8 ++++++-- src/Classes/Project.gd | 19 +++++++++++++++++-- src/UI/Canvas/Rulers/Guide.gd | 12 ++++++++++-- src/UI/TopMenuContainer/TopMenuContainer.gd | 6 +++++- 4 files changed, 38 insertions(+), 7 deletions(-) diff --git a/src/Autoload/Global.gd b/src/Autoload/Global.gd index 30e8450e1..a32016986 100644 --- a/src/Autoload/Global.gd +++ b/src/Autoload/Global.gd @@ -179,10 +179,14 @@ var can_draw := true var move_guides_on_canvas := true var play_only_tags := true ## If [code]true[/code], animation plays only on frames of the same tag. -## (Intended to be used as getter only) Tells if the x-symmetry guide ( -- ) is visible. +## If true, the x symmetry guide ( -- ) is visible. var show_x_symmetry_axis := false -## (Intended to be used as getter only) Tells if the y-symmetry guide ( | ) is visible. +## If true, the y symmetry guide ( | ) is visible. var show_y_symmetry_axis := false +## If true, the x=y symmetry guide ( / ) is visible. +var show_x_y_symmetry_axis := false +## If true, the x==y symmetry guide ( \ ) is visible. +var show_x_minus_y_symmetry_axis := false # Preferences ## Found in Preferences. If [code]true[/code], the last saved project will open on startup. diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index eec345466..809639322 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -71,6 +71,8 @@ var x_symmetry_point: float var y_symmetry_point: float var x_symmetry_axis := SymmetryGuide.new() var y_symmetry_axis := SymmetryGuide.new() +var diagonal_xy_symmetry_axis := SymmetryGuide.new() +var diagonal_x_minus_y_symmetry_axis := SymmetryGuide.new() var selection_map := SelectionMap.new() ## This is useful for when the selection is outside of the canvas boundaries, @@ -111,17 +113,30 @@ func _init(_frames: Array[Frame] = [], _name := tr("untitled"), _size := Vector2 x_symmetry_point = size.x - 1 y_symmetry_point = size.y - 1 - x_symmetry_axis.type = x_symmetry_axis.Types.HORIZONTAL + 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)) x_symmetry_axis.add_point(Vector2(19999, y_symmetry_point / 2 + 0.5)) Global.canvas.add_child(x_symmetry_axis) - y_symmetry_axis.type = y_symmetry_axis.Types.VERTICAL + + y_symmetry_axis.type = Guide.Types.VERTICAL y_symmetry_axis.project = self y_symmetry_axis.add_point(Vector2(x_symmetry_point / 2 + 0.5, -19999)) y_symmetry_axis.add_point(Vector2(x_symmetry_point / 2 + 0.5, 19999)) Global.canvas.add_child(y_symmetry_axis) + 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) + 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)) + Global.canvas.add_child(diagonal_x_minus_y_symmetry_axis) + if OS.get_name() == "Web": export_directory_path = "user://" else: diff --git a/src/UI/Canvas/Rulers/Guide.gd b/src/UI/Canvas/Rulers/Guide.gd index 2cdeeae55..a159b0659 100644 --- a/src/UI/Canvas/Rulers/Guide.gd +++ b/src/UI/Canvas/Rulers/Guide.gd @@ -1,7 +1,7 @@ class_name Guide extends Line2D -enum Types { HORIZONTAL, VERTICAL } +enum Types { HORIZONTAL, VERTICAL, XY, X_MINUS_Y } const INPUT_WIDTH := 4 @@ -221,14 +221,22 @@ func set_color(color: Color) -> void: default_color = color +func get_direction() -> Vector2: + return points[0].direction_to(points[1]) + + func _project_switched() -> void: if self in Global.current_project.guides: visible = Global.show_guides if self is SymmetryGuide: if type == Types.HORIZONTAL: visible = Global.show_x_symmetry_axis and Global.show_guides - else: + elif type == Types.VERTICAL: visible = Global.show_y_symmetry_axis and Global.show_guides + elif type == Types.XY: + visible = Global.show_x_y_symmetry_axis and Global.show_guides + elif type == Types.X_MINUS_Y: + visible = Global.show_x_minus_y_symmetry_axis and Global.show_guides else: visible = false diff --git a/src/UI/TopMenuContainer/TopMenuContainer.gd b/src/UI/TopMenuContainer/TopMenuContainer.gd index 41ce71277..3858450e7 100644 --- a/src/UI/TopMenuContainer/TopMenuContainer.gd +++ b/src/UI/TopMenuContainer/TopMenuContainer.gd @@ -835,8 +835,12 @@ func _toggle_show_guides() -> void: if guide is SymmetryGuide: if guide.type == Guide.Types.HORIZONTAL: guide.visible = Global.show_x_symmetry_axis and Global.show_guides - else: + elif guide.type == Guide.Types.VERTICAL: guide.visible = Global.show_y_symmetry_axis and Global.show_guides + elif guide.type == Guide.Types.XY: + guide.visible = Global.show_x_y_symmetry_axis and Global.show_guides + elif guide.type == Guide.Types.X_MINUS_Y: + guide.visible = Global.show_x_minus_y_symmetry_axis and Global.show_guides func _toggle_show_mouse_guides() -> void: