From 8ba2b62921f9480177df9c11175eabde31707e94 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 31 Jul 2024 22:23:50 +0300 Subject: [PATCH] Mirror the previews of the shape tools Now they are consistent with the selection tools --- src/Tools/BaseShapeDrawer.gd | 21 +++++++++++++---- src/Tools/DesignTools/CurveTool.gd | 23 +++++++++++++++---- src/Tools/DesignTools/LineTool.gd | 13 +++++++++++ src/Tools/SelectionTools/EllipseSelect.gd | 28 ++++++++--------------- 4 files changed, 57 insertions(+), 28 deletions(-) diff --git a/src/Tools/BaseShapeDrawer.gd b/src/Tools/BaseShapeDrawer.gd index e61f8e79c..44992ad26 100644 --- a/src/Tools/BaseShapeDrawer.gd +++ b/src/Tools/BaseShapeDrawer.gd @@ -163,10 +163,23 @@ func draw_preview() -> void: var thickness_vector := ( rect.position - Vector2i((Vector2(0.5, 0.5) * (_thickness - 1)).ceil()) ) - for point in points: - var draw_pos := point + thickness_vector - if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_pos): - image.set_pixelv(draw_pos, Color.WHITE) + for i in points.size(): + points[i] += thickness_vector + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]): + image.set_pixelv(points[i], Color.WHITE) + # Handle mirroring + if Tools.horizontal_mirror: + for point in mirror_array(points, true, false): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) + if Tools.vertical_mirror: + for point in mirror_array(points, true, true): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) + if Tools.vertical_mirror: + for point in mirror_array(points, false, true): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) canvas.texture = texture else: diff --git a/src/Tools/DesignTools/CurveTool.gd b/src/Tools/DesignTools/CurveTool.gd index 306496bf5..e00958689 100644 --- a/src/Tools/DesignTools/CurveTool.gd +++ b/src/Tools/DesignTools/CurveTool.gd @@ -129,12 +129,25 @@ func draw_preview() -> void: var image := Image.create( Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_LA8 ) - for point in points: - var draw_point := point + for i in points.size(): if Global.mirror_view: # This fixes previewing in mirror mode - draw_point.x = image.get_width() - point.x - 1 - if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point): - image.set_pixelv(draw_point, Color.WHITE) + points[i].x = image.get_width() - points[i].x - 1 + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]): + image.set_pixelv(points[i], Color.WHITE) + + # Handle mirroring + if Tools.horizontal_mirror: + for point in mirror_array(points, true, false): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) + if Tools.vertical_mirror: + for point in mirror_array(points, true, true): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) + if Tools.vertical_mirror: + for point in mirror_array(points, false, true): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) previews.texture = texture diff --git a/src/Tools/DesignTools/LineTool.gd b/src/Tools/DesignTools/LineTool.gd index 7b1d84f00..c591a0fe0 100644 --- a/src/Tools/DesignTools/LineTool.gd +++ b/src/Tools/DesignTools/LineTool.gd @@ -156,6 +156,19 @@ func draw_preview() -> void: for point in points: if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): image.set_pixelv(point, Color.WHITE) + # Handle mirroring + if Tools.horizontal_mirror: + for point in mirror_array(points, true, false): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) + if Tools.vertical_mirror: + for point in mirror_array(points, true, true): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) + if Tools.vertical_mirror: + for point in mirror_array(points, false, true): + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) canvas.texture = texture else: diff --git a/src/Tools/SelectionTools/EllipseSelect.gd b/src/Tools/SelectionTools/EllipseSelect.gd index afe764e2e..66906d5e4 100644 --- a/src/Tools/SelectionTools/EllipseSelect.gd +++ b/src/Tools/SelectionTools/EllipseSelect.gd @@ -58,33 +58,23 @@ func draw_preview() -> void: ) for i in points.size(): points[i] += temp_rect.position - var draw_point := points[i] if Global.mirror_view: # This fixes previewing in mirror mode - draw_point.x = image.get_width() - draw_point.x - 1 - if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point): - image.set_pixelv(draw_point, Color.WHITE) + points[i].x = image.get_width() - points[i].x - 1 + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(points[i]): + image.set_pixelv(points[i], Color.WHITE) # Handle mirroring if Tools.horizontal_mirror: for point in mirror_array(points, true, false): - var draw_point := point - if Global.mirror_view: # This fixes previewing in mirror mode - draw_point.x = image.get_width() - draw_point.x - 1 - if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point): - image.set_pixelv(draw_point, Color.WHITE) + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) if Tools.vertical_mirror: for point in mirror_array(points, true, true): - var draw_point := point - if Global.mirror_view: # This fixes previewing in mirror mode - draw_point.x = image.get_width() - draw_point.x - 1 - if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point): - image.set_pixelv(draw_point, Color.WHITE) + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) if Tools.vertical_mirror: for point in mirror_array(points, false, true): - var draw_point := point - if Global.mirror_view: # This fixes previewing in mirror mode - draw_point.x = image.get_width() - draw_point.x - 1 - if Rect2i(Vector2i.ZERO, image.get_size()).has_point(draw_point): - image.set_pixelv(draw_point, Color.WHITE) + if Rect2i(Vector2i.ZERO, image.get_size()).has_point(point): + image.set_pixelv(point, Color.WHITE) var texture := ImageTexture.create_from_image(image) canvas.texture = texture else: