From 318b381938d7edf9228a84da4b66e205d787e469 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas <35376950+OverloadedOrama@users.noreply.github.com> Date: Tue, 21 May 2024 02:28:40 +0300 Subject: [PATCH] Add a fill shape checkbox in the curve tool options Now the curve tool can also be used as a polygon tool --- src/Tools/DesignTools/CurveTool.gd | 18 +++++++++++++++++- src/Tools/DesignTools/CurveTool.tscn | 13 ++++++++++--- 2 files changed, 27 insertions(+), 4 deletions(-) diff --git a/src/Tools/DesignTools/CurveTool.gd b/src/Tools/DesignTools/CurveTool.gd index 5fed0692d..84876411e 100644 --- a/src/Tools/DesignTools/CurveTool.gd +++ b/src/Tools/DesignTools/CurveTool.gd @@ -2,6 +2,7 @@ extends "res://src/Tools/BaseDraw.gd" var _curve := Curve2D.new() ## The [Curve2D] responsible for the shape of the curve being drawn. var _drawing := false ## Set to true when a curve is being drawn. +var _fill := false ## When true, the inside area of the curve gets filled. var _editing_bezier := false ## Needed to determine when to show the control points preview line. var _thickness := 1 ## The thickness of the curve. @@ -16,13 +17,19 @@ func update_brush() -> void: pass -func _on_Thickness_value_changed(value: int) -> void: +func _on_thickness_value_changed(value: int) -> void: _thickness = value update_indicator() update_config() save_config() +func _on_fill_checkbox_toggled(toggled_on: bool) -> void: + _fill = toggled_on + update_config() + save_config() + + func update_indicator() -> void: var bitmap := BitMap.new() bitmap.create(Vector2i.ONE * _thickness) @@ -142,6 +149,15 @@ func _draw_shape() -> void: _drawer.reset() # Draw each point offsetted based on the shape's thickness draw_tool(point) + if _fill: + var v := Vector2i() + var image_size := Global.current_project.size + for x in image_size.x: + v.x = x + for y in image_size.y: + v.y = y + if Geometry2D.is_point_in_polygon(v, points): + draw_tool(v) _curve.clear_points() _drawing = false commit_undo() diff --git a/src/Tools/DesignTools/CurveTool.tscn b/src/Tools/DesignTools/CurveTool.tscn index 34874b3e6..354b58a1b 100644 --- a/src/Tools/DesignTools/CurveTool.tscn +++ b/src/Tools/DesignTools/CurveTool.tscn @@ -20,6 +20,12 @@ suffix = "px" global_increment_action = "brush_size_increment" global_decrement_action = "brush_size_decrement" +[node name="FillCheckbox" type="CheckBox" parent="." index="3"] +layout_mode = 2 +tooltip_text = "Fills the drawn shape with color, instead of drawing a hollow shape" +mouse_default_cursor_shape = 2 +text = "Fill Shape" + [node name="Rotate90" parent="RotationOptions/Rotate" index="0"] button_group = SubResource("ButtonGroup_ko8wf") @@ -29,11 +35,12 @@ button_group = SubResource("ButtonGroup_ko8wf") [node name="Rotate270" parent="RotationOptions/Rotate" index="2"] button_group = SubResource("ButtonGroup_ko8wf") -[node name="Brush" parent="." index="4"] +[node name="Brush" parent="." index="5"] visible = false -[node name="DoubleClickTimer" type="Timer" parent="." index="6"] +[node name="DoubleClickTimer" type="Timer" parent="." index="7"] wait_time = 0.2 one_shot = true -[connection signal="value_changed" from="ThicknessSlider" to="." method="_on_Thickness_value_changed"] +[connection signal="value_changed" from="ThicknessSlider" to="." method="_on_thickness_value_changed"] +[connection signal="toggled" from="FillCheckbox" to="." method="_on_fill_checkbox_toggled"]