From cd269c9a4e62b55fed710f3e178e8bebff904234 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 31 Jul 2024 14:28:30 +0300 Subject: [PATCH] Slightly optimize line and curve tool drawing --- src/Tools/DesignTools/CurveTool.gd | 11 +++++++++-- src/Tools/DesignTools/LineTool.gd | 6 ++++-- 2 files changed, 13 insertions(+), 4 deletions(-) diff --git a/src/Tools/DesignTools/CurveTool.gd b/src/Tools/DesignTools/CurveTool.gd index dbdd8aa56..ae4a0a9b9 100644 --- a/src/Tools/DesignTools/CurveTool.gd +++ b/src/Tools/DesignTools/CurveTool.gd @@ -166,11 +166,12 @@ func draw_preview() -> void: func _draw_shape() -> void: var points := _bezier() prepare_undo("Draw Shape") + var images := _get_selected_draw_images() for point in points: # Reset drawer every time because pixel perfect sometimes breaks the tool _drawer.reset() # Draw each point offsetted based on the shape's thickness - draw_tool(point) + _draw_pixel(point, images) if _fill: var v := Vector2i() var image_size := Global.current_project.size @@ -179,11 +180,17 @@ func _draw_shape() -> void: for y in image_size.y: v.y = y if Geometry2D.is_point_in_polygon(v, points): - draw_tool(v) + _draw_pixel(v, images) _clear() commit_undo() +func _draw_pixel(point: Vector2i, images: Array[Image]) -> void: + if Global.current_project.can_pixel_get_drawn(point): + for image in images: + _drawer.set_pixel(image, point, tool_slot.color) + + func _clear() -> void: _curve.clear_points() _drawing = false diff --git a/src/Tools/DesignTools/LineTool.gd b/src/Tools/DesignTools/LineTool.gd index 043a45dbf..c48c9235d 100644 --- a/src/Tools/DesignTools/LineTool.gd +++ b/src/Tools/DesignTools/LineTool.gd @@ -174,14 +174,16 @@ func draw_preview() -> void: func _draw_shape() -> void: -# var rect := _get_result_rect(origin, dest) var points := _get_points() prepare_undo("Draw Shape") + var images := _get_selected_draw_images() for point in points: # Reset drawer every time because pixel perfect sometimes breaks the tool _drawer.reset() # Draw each point offsetted based on the shape's thickness - draw_tool(point) + if Global.current_project.can_pixel_get_drawn(point): + for image in images: + _drawer.set_pixel(image, point, tool_slot.color) commit_undo()