From 700f287edcc499a632af270693aa412b6f9c3fa8 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Wed, 4 Dec 2019 00:14:14 +0200 Subject: [PATCH] Added fill area option for the bucket tool - this restores the old "paint all pixels of the same color" tool's functionality --- Main.tscn | 98 +++++++++++++++++++++++++++++++++-------------- Scripts/Canvas.gd | 77 +++++++++++++++++++------------------ Scripts/Global.gd | 10 +++++ Scripts/Main.gd | 9 +++++ 4 files changed, 128 insertions(+), 66 deletions(-) diff --git a/Main.tscn b/Main.tscn index fe81815b5..acb5fe7a7 100644 --- a/Main.tscn +++ b/Main.tscn @@ -176,32 +176,32 @@ custom_constants/separation = 32 [node name="MenusAndTools" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools"] editor/display_folded = true -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 125.0 custom_constants/separation = 17 [node name="SelectionTools" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools"] -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 54.0 [node name="VBoxContainer" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/SelectionTools"] -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 18.0 custom_constants/separation = 0 [node name="SelectionTools" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/SelectionTools/VBoxContainer"] -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 14.0 text = "Selection Tools" [node name="HSeparator6" type="HSeparator" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/SelectionTools/VBoxContainer"] margin_top = 14.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 18.0 [node name="SelectionToolsContainer2" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/SelectionTools"] margin_top = 22.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 54.0 [node name="RectSelect" type="TextureButton" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/SelectionTools/SelectionToolsContainer2"] @@ -216,27 +216,27 @@ texture_normal = ExtResource( 2 ) [node name="DrawTools" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools"] margin_top = 71.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 125.0 [node name="VBoxContainer" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/DrawTools"] -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 18.0 custom_constants/separation = 0 [node name="DrawTools" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/DrawTools/VBoxContainer"] -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 14.0 text = "Draw Tools" [node name="HSeparator5" type="HSeparator" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/DrawTools/VBoxContainer"] margin_top = 14.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 18.0 [node name="PaintToolsContainer" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/DrawTools"] margin_top = 22.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 54.0 [node name="Pencil" type="TextureButton" parent="MenuAndUI/UI/ToolPanel/Tools/MenusAndTools/DrawTools/PaintToolsContainer"] @@ -283,19 +283,19 @@ texture_normal = ExtResource( 6 ) [node name="ToolOptions" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools"] margin_top = 157.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 612.0 size_flags_vertical = 3 custom_constants/separation = 0 [node name="ColorPickersCenter" type="CenterContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions"] editor/display_folded = true -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 32.0 [node name="ColorPickersHorizontal" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/ColorPickersCenter"] -margin_left = 36.0 -margin_right = 189.0 +margin_left = 45.0 +margin_right = 198.0 margin_bottom = 32.0 [node name="LeftColorPickerButton" type="ColorPickerButton" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/ColorPickersCenter/ColorPickersHorizontal"] @@ -348,25 +348,25 @@ color = Color( 1, 1, 1, 1 ) [node name="HSeparator" type="HSeparator" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions"] margin_top = 32.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 36.0 [node name="LeftToolOptions" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions"] margin_top = 36.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 243.0 size_flags_horizontal = 3 size_flags_vertical = 3 [node name="LeftLabel" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"] -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 14.0 text = "Left tool options" align = 1 [node name="LeftIndicatorCheckbox" type="CheckBox" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"] margin_top = 18.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 42.0 hint_tooltip = "Show left mouse indicator when drawing" mouse_default_cursor_shape = 2 @@ -376,7 +376,7 @@ text = "Left cursor" [node name="LeftBrushType" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"] editor/display_folded = true margin_top = 46.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 78.0 [node name="LeftBrushTypeButton" type="TextureButton" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftBrushType"] @@ -403,7 +403,7 @@ text = "Brush: Pixel" [node name="LeftBrushSize" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"] editor/display_folded = true margin_top = 82.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 106.0 [node name="BrushSizeLabel" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftBrushSize"] @@ -465,10 +465,29 @@ margin_bottom = 15.0 rect_pivot_offset = Vector2( -90, -47 ) text = "C" +[node name="LeftFillArea" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"] +visible = false +margin_top = 110.0 +margin_right = 244.0 +margin_bottom = 148.0 + +[node name="FillAreaLabel" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftFillArea"] +margin_right = 244.0 +margin_bottom = 14.0 +text = "Fill area:" + +[node name="LeftFillAreaOptions" type="OptionButton" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftFillArea"] +margin_top = 18.0 +margin_right = 244.0 +margin_bottom = 38.0 +text = "Area of the same color" +items = [ "Area of the same color", null, false, 0, null, "All pixels of the same color", null, false, 1, null ] +selected = 0 + [node name="LeftMirroring" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions"] editor/display_folded = true margin_top = 110.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 134.0 [node name="LeftHorizontalMirroring" type="CheckBox" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftMirroring"] @@ -488,25 +507,25 @@ text = "Vert. Mirror" [node name="HSeparator2" type="HSeparator" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions"] margin_top = 243.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 247.0 [node name="RightToolOptions" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions"] margin_top = 247.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 455.0 size_flags_horizontal = 3 size_flags_vertical = 3 [node name="RightLabel" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions"] -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 14.0 text = "Right tool options" align = 1 [node name="RightIndicatorCheckbox" type="CheckBox" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions"] margin_top = 18.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 42.0 hint_tooltip = "Show right mouse indicator when drawing" mouse_default_cursor_shape = 2 @@ -514,7 +533,7 @@ text = "Right cursor" [node name="RightBrushType" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions"] margin_top = 46.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 78.0 [node name="RightBrushTypeButton" type="TextureButton" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightBrushType"] @@ -540,7 +559,7 @@ text = "Brush: Pixel" [node name="RightBrushSize" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions"] margin_top = 82.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 106.0 [node name="BrushSizeLabel" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightBrushSize"] @@ -601,10 +620,29 @@ margin_bottom = 15.0 rect_pivot_offset = Vector2( -90, -47 ) text = "C" +[node name="RightFillArea" type="VBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions"] +visible = false +margin_top = 110.0 +margin_right = 244.0 +margin_bottom = 148.0 + +[node name="FillAreaLabel" type="Label" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightFillArea"] +margin_right = 244.0 +margin_bottom = 14.0 +text = "Fill area:" + +[node name="RightFillAreaOptions" type="OptionButton" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightFillArea"] +margin_top = 18.0 +margin_right = 244.0 +margin_bottom = 38.0 +text = "Area of the same color" +items = [ "Area of the same color", null, false, 0, null, "All pixels of the same color", null, false, 1, null ] +selected = 0 + [node name="RightMirroring" type="HBoxContainer" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions"] editor/display_folded = true margin_top = 110.0 -margin_right = 226.0 +margin_right = 244.0 margin_bottom = 134.0 [node name="RightHorizontalMirroring" type="CheckBox" parent="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightMirroring"] @@ -1387,12 +1425,14 @@ align = 1 [connection signal="pressed" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftBrushType/LeftBrushTypeButton" to="." method="_on_LeftBrushTypeButton_pressed"] [connection signal="value_changed" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftBrushSize/LeftBrushSizeEdit" to="." method="_on_LeftBrushSizeEdit_value_changed"] [connection signal="value_changed" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftColorInterpolation/InterpolateColor/LeftInterpolateFactor" to="." method="_on_LeftInterpolateFactor_value_changed"] +[connection signal="item_selected" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftFillArea/LeftFillAreaOptions" to="." method="_on_LeftFillAreaOptions_item_selected"] [connection signal="toggled" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftMirroring/LeftHorizontalMirroring" to="." method="_on_LeftHorizontalMirroring_toggled"] [connection signal="toggled" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/LeftToolOptions/LeftMirroring/LeftVerticalMirroring" to="." method="_on_LeftVerticalMirroring_toggled"] [connection signal="toggled" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightIndicatorCheckbox" to="." method="_on_RightIndicatorCheckbox_toggled"] [connection signal="pressed" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightBrushType/RightBrushTypeButton" to="." method="_on_RightBrushTypeButton_pressed"] [connection signal="value_changed" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightBrushSize/RightBrushSizeEdit" to="." method="_on_RightBrushSizeEdit_value_changed"] [connection signal="value_changed" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightColorInterpolation/InterpolateColor/RightInterpolateFactor" to="." method="_on_RightInterpolateFactor_value_changed"] +[connection signal="item_selected" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightFillArea/RightFillAreaOptions" to="." method="_on_RightFillAreaOptions_item_selected"] [connection signal="toggled" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightMirroring/RightHorizontalMirroring" to="." method="_on_RightHorizontalMirroring_toggled"] [connection signal="toggled" from="MenuAndUI/UI/ToolPanel/Tools/ToolOptions/RightToolOptions/RightMirroring/RightVerticalMirroring" to="." method="_on_RightVerticalMirroring_toggled"] [connection signal="pressed" from="MenuAndUI/UI/CanvasAndTimeline/HViewportContainer/ViewportAndRulers/HorizontalRuler" to="MenuAndUI/UI/CanvasAndTimeline/HViewportContainer/ViewportAndRulers/HorizontalRuler" method="_on_HorizontalRuler_pressed"] diff --git a/Scripts/Canvas.gd b/Scripts/Canvas.gd index c9fae1947..33799aa63 100644 --- a/Scripts/Canvas.gd +++ b/Scripts/Canvas.gd @@ -83,12 +83,15 @@ func _process(delta) -> void: var mouse_in_canvas := point_in_rectangle(mouse_pos, location, location + size) var current_mouse_button := "None" var current_action := "None" + var fill_area := 0 #For the bucket tool if Input.is_mouse_button_pressed(BUTTON_LEFT): current_mouse_button = "left_mouse" current_action = Global.current_left_tool + fill_area = Global.left_fill_area elif Input.is_mouse_button_pressed(BUTTON_RIGHT): current_mouse_button = "right_mouse" current_action = Global.current_right_tool + fill_area = Global.right_fill_area if Global.current_frame == frame: if !mouse_in_canvas: @@ -136,46 +139,46 @@ func _process(delta) -> void: pencil_and_eraser(mouse_pos, Color(0, 0, 0, 0), current_mouse_button) "Bucket": if mouse_in_canvas && Global.can_draw && Global.has_focus && Global.current_frame == frame: - var current_color : Color - var horizontal_mirror := false - var vertical_mirror := false - var mirror_x := size.x - mouse_pos.x - 1 - var mirror_y := size.y - mouse_pos.y - 1 - if current_mouse_button == "left_mouse": - current_color = Global.left_color_picker.color - horizontal_mirror = Global.left_horizontal_mirror - vertical_mirror = Global.left_vertical_mirror - elif current_mouse_button == "right_mouse": - current_color = Global.right_color_picker.color - horizontal_mirror = Global.right_horizontal_mirror - vertical_mirror = Global.right_vertical_mirror + if fill_area == 0: #Paint the specific area of the same color + var current_color : Color + var horizontal_mirror := false + var vertical_mirror := false + var mirror_x := size.x - mouse_pos.x - 1 + var mirror_y := size.y - mouse_pos.y - 1 + if current_mouse_button == "left_mouse": + current_color = Global.left_color_picker.color + horizontal_mirror = Global.left_horizontal_mirror + vertical_mirror = Global.left_vertical_mirror + elif current_mouse_button == "right_mouse": + current_color = Global.right_color_picker.color + horizontal_mirror = Global.right_horizontal_mirror + vertical_mirror = Global.right_vertical_mirror - flood_fill(mouse_pos, layers[current_layer_index][0].get_pixelv(mouse_pos), current_color) - if horizontal_mirror: - var pos := Vector2(mirror_x, mouse_pos.y) - flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color) - if vertical_mirror: - var pos := Vector2(mouse_pos.x, mirror_y) - flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color) - if horizontal_mirror && vertical_mirror: - var pos := Vector2(mirror_x, mirror_y) - flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color) + flood_fill(mouse_pos, layers[current_layer_index][0].get_pixelv(mouse_pos), current_color) + if horizontal_mirror: + var pos := Vector2(mirror_x, mouse_pos.y) + flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color) + if vertical_mirror: + var pos := Vector2(mouse_pos.x, mirror_y) + flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color) + if horizontal_mirror && vertical_mirror: + var pos := Vector2(mirror_x, mirror_y) + flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color) - "PaintAllPixelsSameColor": - if mouse_in_canvas && Global.can_draw && Global.has_focus && Global.current_frame == frame: - var current_color : Color - if current_mouse_button == "left_mouse": - current_color = Global.left_color_picker.color - elif current_mouse_button == "right_mouse": - current_color = Global.right_color_picker.color + else: #Paint all pixels of the same color + var current_color : Color + if current_mouse_button == "left_mouse": + current_color = Global.left_color_picker.color + elif current_mouse_button == "right_mouse": + current_color = Global.right_color_picker.color - var pixel_color : Color = layers[current_layer_index][0].get_pixelv(mouse_pos) - for xx in size.x: - for yy in size.y: - var c : Color = layers[current_layer_index][0].get_pixel(xx, yy) - if c == pixel_color: - layers[current_layer_index][0].set_pixel(xx, yy, current_color) - sprite_changed_this_frame = true + var pixel_color : Color = layers[current_layer_index][0].get_pixelv(mouse_pos) + for xx in size.x: + for yy in size.y: + var c : Color = layers[current_layer_index][0].get_pixel(xx, yy) + if c == pixel_color: + layers[current_layer_index][0].set_pixel(xx, yy, current_color) + sprite_changed_this_frame = true "LightenDarken": if mouse_in_canvas && Global.can_draw && Global.has_focus && Global.current_frame == frame: var pixel_color : Color = layers[current_layer_index][0].get_pixelv(mouse_pos) diff --git a/Scripts/Global.gd b/Scripts/Global.gd index d4f4fc419..4d19a7b15 100644 --- a/Scripts/Global.gd +++ b/Scripts/Global.gd @@ -72,6 +72,9 @@ var right_color_interpolation_container : Container var left_interpolate_slider : HSlider var right_interpolate_slider : HSlider +var left_fill_area_container : Container +var right_fill_area_container : Container + var left_mirror_container : Container var right_mirror_container : Container @@ -106,6 +109,10 @@ var current_right_brush_type = BRUSH_TYPES.PIXEL var brushes_popup : Popup var file_brush_container : GridContainer var project_brush_container : GridContainer + +var left_fill_area := 0 +var right_fill_area := 0 + # warning-ignore:unused_class_variable var left_horizontal_mirror := false # warning-ignore:unused_class_variable @@ -177,6 +184,9 @@ func _ready() -> void: left_interpolate_slider = find_node_by_name(left_color_interpolation_container, "LeftInterpolateFactor") right_interpolate_slider = find_node_by_name(right_color_interpolation_container, "RightInterpolateFactor") + left_fill_area_container = find_node_by_name(left_tool_options_container, "LeftFillArea") + right_fill_area_container = find_node_by_name(right_tool_options_container, "RightFillArea") + left_mirror_container = find_node_by_name(left_tool_options_container, "LeftMirroring") right_mirror_container = find_node_by_name(right_tool_options_container, "RightMirroring") diff --git a/Scripts/Main.gd b/Scripts/Main.gd index 5eb8dc92e..5f49aa84a 100644 --- a/Scripts/Main.gd +++ b/Scripts/Main.gd @@ -614,6 +614,7 @@ func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_le Global.left_brush_size_container.visible = true Global.left_mirror_container.visible = true elif current_action == "Bucket": + Global.left_fill_area_container.visible = true Global.left_mirror_container.visible = true elif current_action == "LightenDarken": Global.left_brush_size_container.visible = true @@ -637,6 +638,7 @@ func _on_Tool_pressed(tool_pressed : BaseButton, mouse_press := true, key_for_le Global.right_brush_size_container.visible = true Global.right_mirror_container.visible = true elif current_action == "Bucket": + Global.right_fill_area_container.visible = true Global.right_mirror_container.visible = true elif current_action == "LightenDarken": Global.right_brush_size_container.visible = true @@ -922,6 +924,12 @@ func update_left_custom_brush() -> void: func update_right_custom_brush() -> void: Global.update_right_custom_brush() +func _on_LeftFillAreaOptions_item_selected(ID : int) -> void: + Global.left_fill_area = ID + +func _on_RightFillAreaOptions_item_selected(ID : int) -> void: + Global.right_fill_area = ID + func _on_LeftHorizontalMirroring_toggled(button_pressed) -> void: Global.left_horizontal_mirror = button_pressed func _on_LeftVerticalMirroring_toggled(button_pressed) -> void: @@ -939,3 +947,4 @@ func _exit_tree() -> void: config_cache.set_value("window", "position", OS.window_position) config_cache.set_value("window", "size", OS.window_size) config_cache.save("user://cache.ini") +