diff --git a/project.godot b/project.godot index 8283cc227..845e709cd 100644 --- a/project.godot +++ b/project.godot @@ -42,7 +42,7 @@ _global_script_classes=[ { "base": "Line2D", "class": "Guide", "language": "GDScript", -"path": "res://src/UI/Rulers/Guides.gd" +"path": "res://src/UI/Rulers/Guide.gd" }, { "base": "Reference", "class": "Layer", @@ -73,6 +73,11 @@ _global_script_classes=[ { "class": "Project", "language": "GDScript", "path": "res://src/Classes/Project.gd" +}, { +"base": "Guide", +"class": "SymmetryGuide", +"language": "GDScript", +"path": "res://src/UI/Rulers/SymmetryGuide.gd" } ] _global_script_class_icons={ "AnimationTag": "", @@ -87,7 +92,8 @@ _global_script_class_icons={ "Palette": "", "PaletteColor": "", "Patterns": "", -"Project": "" +"Project": "", +"SymmetryGuide": "" } [application] diff --git a/src/Classes/Drawers.gd b/src/Classes/Drawers.gd index 58eea9295..967181619 100644 --- a/src/Classes/Drawers.gd +++ b/src/Classes/Drawers.gd @@ -69,8 +69,8 @@ func set_pixel_perfect(value: bool) -> void: func set_pixel(image: Image, position: Vector2, color: Color) -> void: var project : Project = Global.current_project - var mirror_x = project.size.x - project.x_symmetry_point - position.x - var mirror_y = project.size.y - project.y_symmetry_point - position.y + var mirror_x = project.x_symmetry_point - position.x + var mirror_y = project.y_symmetry_point - position.y var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1 var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1 diff --git a/src/Classes/Project.gd b/src/Classes/Project.gd index 51faaadcf..90c853359 100644 --- a/src/Classes/Project.gd +++ b/src/Classes/Project.gd @@ -16,8 +16,10 @@ var guides := [] # Array of Guides var brushes := [] # Array of Images -var x_symmetry_point := -1 -var y_symmetry_point := -1 +var x_symmetry_point := size.x / 2 + 1 +var y_symmetry_point := size.y / 2 + 1 +var x_symmetry_axis : SymmetryGuide +var y_symmetry_axis : SymmetryGuide var x_min := 0 var x_max := 64 var y_min := 0 @@ -41,6 +43,22 @@ func _init(_frames := [], _name := tr("untitled")) -> void: OpenSave.current_save_paths.append("") OpenSave.backup_save_paths.append("") + if !x_symmetry_axis: + x_symmetry_axis = SymmetryGuide.new() + x_symmetry_axis.type = x_symmetry_axis.Types.HORIZONTAL + x_symmetry_axis.project = self + x_symmetry_axis.add_point(Vector2(-19999, y_symmetry_point)) + x_symmetry_axis.add_point(Vector2(19999, y_symmetry_point)) + Global.canvas.add_child(x_symmetry_axis) + + if !y_symmetry_axis: + y_symmetry_axis = SymmetryGuide.new() + y_symmetry_axis.type = y_symmetry_axis.Types.VERTICAL + y_symmetry_axis.project = self + y_symmetry_axis.add_point(Vector2(x_symmetry_point, -19999)) + y_symmetry_axis.add_point(Vector2(x_symmetry_point, 19999)) + Global.canvas.add_child(y_symmetry_axis) + func _set_selected_rect(value : Rect2) -> void: selected_rect = value @@ -167,6 +185,8 @@ func serialize() -> Dictionary: var guide_data := [] for guide in guides: + if guide is SymmetryGuide: + continue var coords = guide.points[0].x if guide.type == Guide.Types.HORIZONTAL: coords = guide.points[0].y @@ -200,6 +220,7 @@ func serialize() -> Dictionary: "layers" : layer_data, "tags" : tag_data, "guides" : guide_data, + "symmetry_points" : [x_symmetry_point, y_symmetry_point], "frames" : frame_data, "brushes" : brush_data, } @@ -250,6 +271,13 @@ func deserialize(dict : Dictionary) -> void: guide.has_focus = false Global.canvas.add_child(guide) guides.append(guide) + if dict.has("symmetry_points"): + x_symmetry_point = dict.symmetry_points[0] + y_symmetry_point = dict.symmetry_points[1] + x_symmetry_axis.points[0].y = floor(y_symmetry_point / 2 + 1) + x_symmetry_axis.points[1].y = floor(y_symmetry_point / 2 + 1) + y_symmetry_axis.points[0].x = floor(x_symmetry_point / 2 + 1) + y_symmetry_axis.points[1].x = floor(x_symmetry_point / 2 + 1) func name_changed(value : String) -> void: diff --git a/src/Tools/Bucket.gd b/src/Tools/Bucket.gd index 556655eff..92a066e0a 100644 --- a/src/Tools/Bucket.gd +++ b/src/Tools/Bucket.gd @@ -129,8 +129,8 @@ func fill_in_color(position : Vector2) -> void: func fill_in_area(position : Vector2) -> void: var project : Project = Global.current_project - var mirror_x = project.size.x - project.x_symmetry_point - position.x - var mirror_y = project.size.y - project.y_symmetry_point - position.y + var mirror_x = project.x_symmetry_point - position.x + var mirror_y = project.y_symmetry_point - position.y var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1 var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1 diff --git a/src/Tools/Draw.gd b/src/Tools/Draw.gd index c4db65b69..dde73ac05 100644 --- a/src/Tools/Draw.gd +++ b/src/Tools/Draw.gd @@ -269,8 +269,8 @@ func draw_tool_brush(position : Vector2) -> void: dst = dst_rect.position var project : Project = Global.current_project - var mirror_x = project.size.x - (project.x_symmetry_point + 1) - dst.x - src_rect.size.x - var mirror_y = project.size.y - (project.y_symmetry_point + 1) - dst.y - src_rect.size.y + var mirror_x = (project.x_symmetry_point + 1) - dst.x - src_rect.size.x + var mirror_y = (project.y_symmetry_point + 1) - dst.y - src_rect.size.y var mirror_x_inside : bool = mirror_x >= project.x_min and mirror_x <= project.x_max - 1 var mirror_y_inside : bool = mirror_y >= project.y_min and mirror_y <= project.y_max - 1 @@ -279,7 +279,7 @@ func draw_tool_brush(position : Vector2) -> void: _draw_brush_image(_mirror_brushes.x, _flip_rect(src_rect, size, true, false), Vector2(mirror_x, dst.y)) if tool_slot.vertical_mirror and mirror_y_inside: _draw_brush_image(_mirror_brushes.xy, _flip_rect(src_rect, size, true, true), Vector2(mirror_x, mirror_y)) - if tool_slot.vertical_mirror and mirror_x_inside: + if tool_slot.vertical_mirror and mirror_y_inside: _draw_brush_image(_mirror_brushes.y, _flip_rect(src_rect, size, false, true), Vector2(dst.x, mirror_y)) diff --git a/src/UI/Rulers/Guides.gd b/src/UI/Rulers/Guide.gd similarity index 85% rename from src/UI/Rulers/Guides.gd rename to src/UI/Rulers/Guide.gd index 39a11ce83..e2f57d49d 100644 --- a/src/UI/Rulers/Guides.gd +++ b/src/UI/Rulers/Guide.gd @@ -5,19 +5,21 @@ enum Types {HORIZONTAL, VERTICAL} var font := preload("res://assets/fonts/Roboto-Regular.tres") var has_focus := true var mouse_pos := Vector2.ZERO -var previous_points := points var type = Types.HORIZONTAL +var project = Global.current_project func _ready() -> void: width = 0.1 default_color = Global.guide_color - Global.current_project.guides.append(self) + project.guides.append(self) func _input(_event : InputEvent): width = Global.camera.zoom.x * 2 mouse_pos = get_local_mouse_position() + if points.size() < 2: + return var point0 := points[0] var point1 := points[1] if type == Types.HORIZONTAL: @@ -27,13 +29,11 @@ func _input(_event : InputEvent): point0.x -= width * 3 point1.x += width * 3 if Global.can_draw and Global.has_focus and point_in_rectangle(mouse_pos, point0, point1) and Input.is_action_just_pressed("left_mouse"): - if !point_in_rectangle(Global.canvas.current_pixel, Global.canvas.location, Global.canvas.location + Global.current_project.size): + if !point_in_rectangle(Global.canvas.current_pixel, Global.canvas.location, Global.canvas.location + project.size): has_focus = true Global.has_focus = false update() if has_focus and visible: - if Input.is_action_just_pressed("left_mouse"): - previous_points = points if Input.is_action_pressed("left_mouse"): if type == Types.HORIZONTAL: points[0].y = round(mouse_pos.y) @@ -62,11 +62,11 @@ func _draw() -> void: func outside_canvas() -> bool: if type == Types.HORIZONTAL: - if points[0].y < 0 || points[0].y > Global.current_project.size.y: + if points[0].y < 0 || points[0].y > project.size.y: queue_free() return true else: - if points[0].x < 0 || points[0].x > Global.current_project.size.x: + if points[0].x < 0 || points[0].x > project.size.x: queue_free() return true return false diff --git a/src/UI/Rulers/SymmetryGuide.gd b/src/UI/Rulers/SymmetryGuide.gd new file mode 100644 index 000000000..7f9301c1a --- /dev/null +++ b/src/UI/Rulers/SymmetryGuide.gd @@ -0,0 +1,25 @@ +class_name SymmetryGuide extends Guide + + +func _ready() -> void: + ._ready() + has_focus = false + + +func _input(_event : InputEvent) -> void: + ._input(_event) + if type == Types.HORIZONTAL: + project.y_symmetry_point = points[0].y * 2 - 1 + elif type == Types.VERTICAL: + project.x_symmetry_point = points[0].x * 2 - 1 + + +func outside_canvas() -> bool: + if type == Types.HORIZONTAL: + points[0].y = clamp(points[0].y, 0, Global.current_project.size.y) + points[1].y = clamp(points[1].y, 0, Global.current_project.size.y) + elif type == Types.VERTICAL: + points[0].x = clamp(points[0].x, 0, Global.current_project.size.x) + points[1].x = clamp(points[1].x, 0, Global.current_project.size.x) + + return false