diff --git a/src/Autoload/Tools.gd b/src/Autoload/Tools.gd index 1188a9586..a9eb19bae 100644 --- a/src/Autoload/Tools.gd +++ b/src/Autoload/Tools.gd @@ -437,6 +437,25 @@ func get_assigned_color(button: int) -> Color: return _slots[button].color +func get_mirrored_positions( + pos: Vector2i, project := Global.current_project, offset := 0 +) -> Array[Vector2i]: + var positions: Array[Vector2i] = [] + if horizontal_mirror: + var mirror_x := pos + mirror_x.x = project.x_symmetry_point - pos.x + offset + positions.append(mirror_x) + if vertical_mirror: + var mirror_xy := mirror_x + mirror_xy.y = project.y_symmetry_point - pos.y + offset + positions.append(mirror_xy) + if vertical_mirror: + var mirror_y := pos + mirror_y.y = project.y_symmetry_point - pos.y + offset + positions.append(mirror_y) + return positions + + func set_button_size(button_size: int) -> void: var size := Vector2(24, 24) if button_size == Global.ButtonSize.SMALL else Vector2(32, 32) for t in _tool_buttons.get_children(): diff --git a/src/Classes/Drawers.gd b/src/Classes/Drawers.gd index dcf72a85e..1698778c7 100644 --- a/src/Classes/Drawers.gd +++ b/src/Classes/Drawers.gd @@ -7,8 +7,6 @@ var pixel_perfect := false: drawers = pixel_perfect_drawers.duplicate() else: drawers = [simple_drawer, simple_drawer, simple_drawer, simple_drawer] -var horizontal_mirror := false -var vertical_mirror := false var color_op := ColorOp.new() var simple_drawer := SimpleDrawer.new() @@ -72,14 +70,9 @@ func set_pixel(image: Image, position: Vector2i, color: Color, ignore_mirroring drawers[0].set_pixel(image, position, color, color_op) if ignore_mirroring: return - - # Handle Mirroring - var mirror_x := project.x_symmetry_point - position.x - var mirror_y := project.y_symmetry_point - position.y - - if horizontal_mirror and project.can_pixel_get_drawn(Vector2i(mirror_x, position.y)): - drawers[1].set_pixel(image, Vector2i(mirror_x, position.y), color, color_op) - if vertical_mirror and project.can_pixel_get_drawn(Vector2i(position.x, mirror_y)): - drawers[2].set_pixel(image, Vector2i(mirror_x, mirror_y), color, color_op) - if vertical_mirror and project.can_pixel_get_drawn(Vector2i(position.x, mirror_y)): - drawers[3].set_pixel(image, Vector2i(position.x, mirror_y), color, color_op) + # Handle mirroring + var i := 1 + for mirror_pos in Tools.get_mirrored_positions(position, project): + if project.can_pixel_get_drawn(mirror_pos): + drawers[i].set_pixel(image, mirror_pos, color, color_op) + i += 1 diff --git a/src/Tools/BaseDraw.gd b/src/Tools/BaseDraw.gd index 26a0cf147..6f862f2cc 100644 --- a/src/Tools/BaseDraw.gd +++ b/src/Tools/BaseDraw.gd @@ -262,8 +262,6 @@ func _prepare_tool() -> void: lerpf(Tools.brush_size_min, Tools.brush_size_max, Tools.mouse_velocity) ) _drawer.pixel_perfect = Tools.pixel_perfect if _brush_size == 1 else false - _drawer.horizontal_mirror = Tools.horizontal_mirror - _drawer.vertical_mirror = Tools.vertical_mirror _drawer.color_op.strength = strength _indicator = _create_brush_indicator() _polylines = _create_polylines(_indicator) diff --git a/src/Tools/DesignTools/Bucket.gd b/src/Tools/DesignTools/Bucket.gd index 3b7c38c59..bcdae748d 100644 --- a/src/Tools/DesignTools/Bucket.gd +++ b/src/Tools/DesignTools/Bucket.gd @@ -231,19 +231,10 @@ func fill_in_color(pos: Vector2i) -> void: func fill_in_area(pos: Vector2i) -> void: var project := Global.current_project _flood_fill(pos) - - # Handle Mirroring - var mirror_x := project.x_symmetry_point - pos.x - var mirror_y := project.y_symmetry_point - pos.y - var mirror_x_inside := project.can_pixel_get_drawn(Vector2i(mirror_x, pos.y)) - var mirror_y_inside := project.can_pixel_get_drawn(Vector2i(pos.x, mirror_y)) - - if Tools.horizontal_mirror and mirror_x_inside: - _flood_fill(Vector2i(mirror_x, pos.y)) - if Tools.vertical_mirror and mirror_y_inside: - _flood_fill(Vector2i(mirror_x, mirror_y)) - if Tools.vertical_mirror and mirror_y_inside: - _flood_fill(Vector2i(pos.x, mirror_y)) + # Handle mirroring + for mirror_pos in Tools.get_mirrored_positions(pos, project): + if project.can_pixel_get_drawn(mirror_pos): + _flood_fill(mirror_pos) func fill_in_selection() -> void: diff --git a/src/Tools/SelectionTools/EllipseSelect.gd b/src/Tools/SelectionTools/EllipseSelect.gd index dce89511d..0df67e9b0 100644 --- a/src/Tools/SelectionTools/EllipseSelect.gd +++ b/src/Tools/SelectionTools/EllipseSelect.gd @@ -75,35 +75,20 @@ func apply_selection(_position: Vector2i) -> void: Global.canvas.selection.clear_selection() if _rect.size == Vector2i.ZERO and Global.current_project.has_selection: Global.canvas.selection.commit_undo("Select", undo_data) + if _rect.size == Vector2i.ZERO: + return + set_ellipse(project.selection_map, _rect.position) + # Handle mirroring + var mirror_positions := Tools.get_mirrored_positions(_rect.position, project, 1) + var mirror_ends := Tools.get_mirrored_positions(_rect.end, project, 1) + for i in mirror_positions.size(): + var mirror_rect := Rect2i() + mirror_rect.position = mirror_positions[i] + mirror_rect.end = mirror_ends[i] + set_ellipse(project.selection_map, mirror_rect.abs().position) - if _rect.size != Vector2i.ZERO: - set_ellipse(project.selection_map, _rect.position) - - # Handle mirroring - if Tools.horizontal_mirror: - var mirror_x_rect := _rect - mirror_x_rect.position.x = ( - Global.current_project.x_symmetry_point - _rect.position.x + 1 - ) - mirror_x_rect.end.x = Global.current_project.x_symmetry_point - _rect.end.x + 1 - set_ellipse(project.selection_map, mirror_x_rect.abs().position) - if Tools.vertical_mirror: - var mirror_xy_rect := mirror_x_rect - mirror_xy_rect.position.y = ( - Global.current_project.y_symmetry_point - _rect.position.y + 1 - ) - mirror_xy_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1 - set_ellipse(project.selection_map, mirror_xy_rect.abs().position) - if Tools.vertical_mirror: - var mirror_y_rect := _rect - mirror_y_rect.position.y = ( - Global.current_project.y_symmetry_point - _rect.position.y + 1 - ) - mirror_y_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1 - set_ellipse(project.selection_map, mirror_y_rect.abs().position) - - Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() - Global.canvas.selection.commit_undo("Select", undo_data) + Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() + Global.canvas.selection.commit_undo("Select", undo_data) func set_ellipse(selection_map: SelectionMap, pos: Vector2i) -> void: diff --git a/src/Tools/SelectionTools/MagicWand.gd b/src/Tools/SelectionTools/MagicWand.gd index f49979d8f..5b6cf8074 100644 --- a/src/Tools/SelectionTools/MagicWand.gd +++ b/src/Tools/SelectionTools/MagicWand.gd @@ -33,20 +33,10 @@ func apply_selection(pos: Vector2i) -> void: var cel_image := Image.new() cel_image.copy_from(_get_draw_image()) _flood_fill(pos, cel_image, project.selection_map) - # Handle mirroring - if Tools.horizontal_mirror: - var mirror_x := pos - mirror_x.x = Global.current_project.x_symmetry_point - pos.x - _flood_fill(mirror_x, cel_image, project.selection_map) - if Tools.vertical_mirror: - var mirror_xy := mirror_x - mirror_xy.y = Global.current_project.y_symmetry_point - pos.y - _flood_fill(mirror_xy, cel_image, project.selection_map) - if Tools.vertical_mirror: - var mirror_y := pos - mirror_y.y = Global.current_project.y_symmetry_point - pos.y - _flood_fill(mirror_y, cel_image, project.selection_map) + for mirror_pos in Tools.get_mirrored_positions(pos): + _flood_fill(mirror_pos, cel_image, project.selection_map) + Global.canvas.selection.big_bounding_rectangle = project.selection_map.get_used_rect() Global.canvas.selection.commit_undo("Select", undo_data) diff --git a/src/Tools/SelectionTools/RectSelect.gd b/src/Tools/SelectionTools/RectSelect.gd index 96c718ffc..1e3cb7cf1 100644 --- a/src/Tools/SelectionTools/RectSelect.gd +++ b/src/Tools/SelectionTools/RectSelect.gd @@ -50,33 +50,24 @@ func draw_end(pos: Vector2i) -> void: func draw_preview() -> void: if _move: return + var project := Global.current_project var canvas: Node2D = Global.canvas.previews var pos := canvas.position var canvas_scale := canvas.scale if Global.mirror_view: - pos.x = pos.x + Global.current_project.size.x + pos.x = pos.x + project.size.x canvas_scale.x = -1 canvas.draw_set_transform(pos, canvas.rotation, canvas_scale) canvas.draw_rect(_rect, Color.BLACK, false) - # Handle mirroring - if Tools.horizontal_mirror: - var mirror_x_rect := _rect - mirror_x_rect.position.x = Global.current_project.x_symmetry_point - _rect.position.x + 1 - mirror_x_rect.end.x = Global.current_project.x_symmetry_point - _rect.end.x + 1 - canvas.draw_rect(mirror_x_rect, Color.BLACK, false) - if Tools.vertical_mirror: - var mirror_xy_rect := mirror_x_rect - mirror_xy_rect.position.y = ( - Global.current_project.y_symmetry_point - _rect.position.y + 1 - ) - mirror_xy_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1 - canvas.draw_rect(mirror_xy_rect, Color.BLACK, false) - if Tools.vertical_mirror: - var mirror_y_rect := _rect - mirror_y_rect.position.y = Global.current_project.y_symmetry_point - _rect.position.y + 1 - mirror_y_rect.end.y = Global.current_project.y_symmetry_point - _rect.end.y + 1 - canvas.draw_rect(mirror_y_rect, Color.BLACK, false) + var mirror_positions := Tools.get_mirrored_positions(_rect.position, project, 1) + var mirror_ends := Tools.get_mirrored_positions(_rect.end, project, 1) + for i in mirror_positions.size(): + var mirror_rect := Rect2i() + mirror_rect.position = mirror_positions[i] + mirror_rect.end = mirror_ends[i] + canvas.draw_rect(mirror_rect, Color.BLACK, false) + canvas.draw_set_transform(canvas.position, canvas.rotation, canvas.scale) @@ -95,23 +86,14 @@ func apply_selection(pos: Vector2i) -> void: elif _intersect: operation = 2 Global.canvas.selection.select_rect(_rect, operation) - # Handle mirroring - if Tools.horizontal_mirror: - var mirror_x_rect := _rect - mirror_x_rect.position.x = project.x_symmetry_point - _rect.position.x + 1 - mirror_x_rect.end.x = project.x_symmetry_point - _rect.end.x + 1 - Global.canvas.selection.select_rect(mirror_x_rect.abs(), operation) - if Tools.vertical_mirror: - var mirror_xy_rect := mirror_x_rect - mirror_xy_rect.position.y = project.y_symmetry_point - _rect.position.y + 1 - mirror_xy_rect.end.y = project.y_symmetry_point - _rect.end.y + 1 - Global.canvas.selection.select_rect(mirror_xy_rect.abs(), operation) - if Tools.vertical_mirror: - var mirror_y_rect := _rect - mirror_y_rect.position.y = project.y_symmetry_point - _rect.position.y + 1 - mirror_y_rect.end.y = project.y_symmetry_point - _rect.end.y + 1 - Global.canvas.selection.select_rect(mirror_y_rect.abs(), operation) + var mirror_positions := Tools.get_mirrored_positions(_rect.position, project, 1) + var mirror_ends := Tools.get_mirrored_positions(_rect.end, project, 1) + for i in mirror_positions.size(): + var mirror_rect := Rect2i() + mirror_rect.position = mirror_positions[i] + mirror_rect.end = mirror_ends[i] + Global.canvas.selection.select_rect(mirror_rect.abs(), operation) Global.canvas.selection.commit_undo("Select", undo_data)