Added fill area option for the bucket tool - this restores the old "paint all pixels of the same color" tool's functionality

This commit is contained in:
OverloadedOrama 2019-12-04 00:14:14 +02:00
parent 532f6c75ed
commit 700f287edc
4 changed files with 128 additions and 66 deletions

View file

@ -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)

View file

@ -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")

View file

@ -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")