Added a new brush type - Filled Circle

Filled Circle brush is just like the Circle brush, but filled. Issue is, when drawing while moving the mouse, some pixels remain unfilled.

Also added some more file brushes.
This commit is contained in:
OverloadedOrama 2019-12-27 22:02:47 +02:00
parent abc622d08e
commit d6a199c53f
31 changed files with 93 additions and 35 deletions

View file

Before

Width:  |  Height:  |  Size: 108 B

After

Width:  |  Height:  |  Size: 108 B

Before After
Before After

View file

@ -0,0 +1,13 @@
[remap]
importer="image"
type="Image"
path="res://.import/circle_filled_9x9.png-e8b23839b7a2268668453f011aef5a21.image"
[deps]
source_file="res://Assets/Graphics/circle_filled_9x9.png"
dest_files=[ "res://.import/circle_filled_9x9.png-e8b23839b7a2268668453f011aef5a21.image" ]
[params]

BIN
Brushes/Godot.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 3.4 KiB

BIN
Brushes/Grass/%Grass1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 666 B

BIN
Brushes/Grass/%Grass2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 665 B

BIN
Brushes/Grass/%Grass3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 675 B

BIN
Brushes/Grass/%Grass4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 663 B

BIN
Brushes/Grass/%Grass5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 642 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 197 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 198 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 110 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 119 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 158 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 126 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 141 B

View file

Before

Width:  |  Height:  |  Size: 199 B

After

Width:  |  Height:  |  Size: 199 B

Before After
Before After

BIN
Brushes/Snow.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 141 B

BIN
Brushes/Star/%star1.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
Brushes/Star/%star2.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
Brushes/Star/%star3.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
Brushes/Star/%star4.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
Brushes/Star/%star5.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

BIN
Brushes/Star/%star6.png Normal file

Binary file not shown.

After

Width:  |  Height:  |  Size: 1.3 KiB

View file

Before

Width:  |  Height:  |  Size: 140 B

After

Width:  |  Height:  |  Size: 140 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 72 B

After

Width:  |  Height:  |  Size: 72 B

Before After
Before After

View file

Before

Width:  |  Height:  |  Size: 79 B

After

Width:  |  Height:  |  Size: 79 B

Before After
Before After

File diff suppressed because one or more lines are too long

View file

@ -1,7 +1,7 @@
extends BaseButton
export var brush_type = Global.BRUSH_TYPES.PIXEL
export var custom_brush_index := -2
export var custom_brush_index := -3
# warning-ignore:unused_class_variable
var random_brushes := []
@ -17,12 +17,15 @@ func _on_BrushButton_pressed() -> void:
Global.left_brush_type_label.text = tr("Custom brush")
else:
Global.left_brush_type_label.text = tr("Brush:") + " %s" % hint_tooltip
elif custom_brush_index == -2: # Pixel brush
elif custom_brush_index == -3: # Pixel brush
Global.left_color_interpolation_container.visible = false
Global.left_brush_type_label.text = tr("Brush: Pixel")
elif custom_brush_index == -1: # Circle brush
elif custom_brush_index == -2: # Circle brush
Global.left_color_interpolation_container.visible = false
Global.left_brush_type_label.text = tr("Brush: Circle")
elif custom_brush_index == -1: # Filled Circle brush
Global.left_color_interpolation_container.visible = false
Global.left_brush_type_label.text = tr("Brush: Filled Circle")
Global.update_left_custom_brush()
@ -36,24 +39,27 @@ func _on_BrushButton_pressed() -> void:
Global.right_brush_type_label.text = tr("Custom brush")
else:
Global.right_brush_type_label.text = tr("Brush:") + " %s" % hint_tooltip
elif custom_brush_index == -2: # Pixel brush
elif custom_brush_index == -3: # Pixel brush
Global.right_color_interpolation_container.visible = false
Global.right_brush_type_label.text = tr("Brush: Pixel")
elif custom_brush_index == -1: # Circle brush
elif custom_brush_index == -2: # Circle brush
Global.right_color_interpolation_container.visible = false
Global.right_brush_type_label.text = tr("Brush: Circle")
elif custom_brush_index == -1: # Filled Circle brush
Global.right_color_interpolation_container.visible = false
Global.right_brush_type_label.text = tr("Brush: Filled Circle")
Global.update_right_custom_brush()
func _on_DeleteButton_pressed() -> void:
if brush_type == Global.BRUSH_TYPES.CUSTOM:
if Global.custom_left_brush_index == custom_brush_index:
Global.custom_left_brush_index = -2
Global.custom_left_brush_index = -3
Global.current_left_brush_type = Global.BRUSH_TYPES.PIXEL
Global.left_brush_type_label.text = "Brush: Pixel"
Global.update_left_custom_brush()
if Global.custom_right_brush_index == custom_brush_index:
Global.custom_right_brush_index = -2
Global.custom_right_brush_index = -3
Global.current_right_brush_type = Global.BRUSH_TYPES.PIXEL
Global.right_brush_type_label.text = "Brush: Pixel"
Global.update_right_custom_brush()

View file

@ -466,7 +466,7 @@ func _draw() -> void:
var start_pos_x = mouse_pos.x - (Global.left_brush_size >> 1)
var start_pos_y = mouse_pos.y - (Global.left_brush_size >> 1)
draw_rect(Rect2(start_pos_x, start_pos_y, Global.left_brush_size, Global.left_brush_size), Color.blue, false)
elif Global.current_left_brush_type == Global.BRUSH_TYPES.CIRCLE:
elif Global.current_left_brush_type == Global.BRUSH_TYPES.CIRCLE || Global.current_left_brush_type == Global.BRUSH_TYPES.FILLED_CIRCLE:
if Global.current_left_tool == "Pencil" || Global.current_left_tool == "Eraser":
draw_set_transform(mouse_pos, rotation, scale)
for rect in Global.left_circle_points:
@ -484,7 +484,7 @@ func _draw() -> void:
var start_pos_x = mouse_pos.x - (Global.right_brush_size >> 1)
var start_pos_y = mouse_pos.y - (Global.right_brush_size >> 1)
draw_rect(Rect2(start_pos_x, start_pos_y, Global.right_brush_size, Global.right_brush_size), Color.red, false)
elif Global.current_right_brush_type == Global.BRUSH_TYPES.CIRCLE:
elif Global.current_right_brush_type == Global.BRUSH_TYPES.CIRCLE || Global.current_right_brush_type == Global.BRUSH_TYPES.FILLED_CIRCLE:
if Global.current_right_tool == "Pencil" || Global.current_right_tool == "Eraser":
draw_set_transform(mouse_pos, rotation, scale)
for rect in Global.right_circle_points:
@ -553,7 +553,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, cur
if brush_type != Global.BRUSH_TYPES.RANDOM_FILE:
custom_brush_image = Global.custom_left_brush_image
else: # Handle random brush
var brush_button = Global.file_brush_container.get_child(brush_index + 2)
var brush_button = Global.file_brush_container.get_child(brush_index + 3)
var random_index = randi() % brush_button.random_brushes.size()
custom_brush_image = Image.new()
custom_brush_image.copy_from(brush_button.random_brushes[random_index])
@ -573,7 +573,7 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, cur
if brush_type != Global.BRUSH_TYPES.RANDOM_FILE:
custom_brush_image = Global.custom_right_brush_image
else: # Handle random brush
var brush_button = Global.file_brush_container.get_child(brush_index + 2)
var brush_button = Global.file_brush_container.get_child(brush_index + 3)
var random_index = randi() % brush_button.random_brushes.size()
custom_brush_image = Image.new()
custom_brush_image.copy_from(brush_button.random_brushes[random_index])
@ -664,18 +664,18 @@ func draw_pixel(pos : Vector2, color : Color, current_mouse_button : String, cur
layers[current_layer_index][0].set_pixel(mirror_x, mirror_y, color)
sprite_changed_this_frame = true
elif brush_type == Global.BRUSH_TYPES.CIRCLE:
plot_circle(layers[current_layer_index][0], pos.x, pos.y, brush_size, color)
elif brush_type == Global.BRUSH_TYPES.CIRCLE || brush_type == Global.BRUSH_TYPES.FILLED_CIRCLE:
plot_circle(layers[current_layer_index][0], pos.x, pos.y, brush_size, color, brush_type == Global.BRUSH_TYPES.FILLED_CIRCLE)
# Handle mirroring
var mirror_x := east_limit + west_limit - pos.x
var mirror_y := south_limit + north_limit - pos.y
if horizontal_mirror:
plot_circle(layers[current_layer_index][0], mirror_x, pos.y, brush_size, color)
plot_circle(layers[current_layer_index][0], mirror_x, pos.y, brush_size, color, brush_type == Global.BRUSH_TYPES.FILLED_CIRCLE)
if vertical_mirror:
plot_circle(layers[current_layer_index][0], pos.x, mirror_y, brush_size, color)
plot_circle(layers[current_layer_index][0], pos.x, mirror_y, brush_size, color, brush_type == Global.BRUSH_TYPES.FILLED_CIRCLE)
if horizontal_mirror && vertical_mirror:
plot_circle(layers[current_layer_index][0], mirror_x, mirror_y, brush_size, color)
plot_circle(layers[current_layer_index][0], mirror_x, mirror_y, brush_size, color, brush_type == Global.BRUSH_TYPES.FILLED_CIRCLE)
sprite_changed_this_frame = true
@ -822,7 +822,7 @@ func flood_fill(pos : Vector2, target_color : Color, replace_color : Color) -> v
sprite_changed_this_frame = true
# Algorithm based on http://members.chello.at/easyfilter/bresenham.html
func plot_circle(sprite : Image, xm : int, ym : int, r : int, color : Color) -> void:
func plot_circle(sprite : Image, xm : int, ym : int, r : int, color : Color, fill := false) -> void:
var west_limit := location.x
var east_limit := location.x + size.x
var north_limit := location.y
@ -833,6 +833,7 @@ func plot_circle(sprite : Image, xm : int, ym : int, r : int, color : Color) ->
north_limit = max(north_limit, Global.selection_rectangle.polygon[0].y)
south_limit = min(south_limit, Global.selection_rectangle.polygon[2].y)
var target_color : Color = sprite.get_pixel(xm, ym) # Used for filling
var x := -r
var y := 0
var err := 2 - r * 2 # II. Quadrant
@ -857,6 +858,9 @@ func plot_circle(sprite : Image, xm : int, ym : int, r : int, color : Color) ->
x += 1
err += x * 2 + 1
if fill:
flood_fill(Vector2(xm, ym), target_color, color)
# Checks if a point is inside a rectangle
func point_in_rectangle(p : Vector2, coord1 : Vector2, coord2 : Vector2) -> bool:
return p.x > coord1.x && p.y > coord1.y && p.x < coord2.x && p.y < coord2.y

View file

@ -85,7 +85,7 @@ var onion_skinning_future_rate := 0
var onion_skinning_blue_red := false
# Brushes
enum BRUSH_TYPES {PIXEL, CIRCLE, FILE, RANDOM_FILE, CUSTOM}
enum BRUSH_TYPES {PIXEL, CIRCLE, FILLED_CIRCLE, FILE, RANDOM_FILE, CUSTOM}
# warning-ignore:unused_class_variable
var left_brush_size := 1
# warning-ignore:unused_class_variable
@ -494,12 +494,15 @@ func update_left_custom_brush() -> void:
if current_left_brush_type == BRUSH_TYPES.PIXEL:
var pixel := Image.new()
pixel = preload("res://Assets/Graphics/pixel_image.png")
pixel = blend_image_with_color(pixel, left_color_picker.color, 1)
left_brush_type_button.get_child(0).texture.create_from_image(pixel, 0)
elif current_left_brush_type == BRUSH_TYPES.CIRCLE:
var pixel := Image.new()
pixel = preload("res://Assets/Graphics/circle_9x9.png")
pixel = blend_image_with_color(pixel, left_color_picker.color, 1)
left_brush_type_button.get_child(0).texture.create_from_image(pixel, 0)
left_circle_points = plot_circle(left_brush_size)
elif current_left_brush_type == BRUSH_TYPES.FILLED_CIRCLE:
var pixel := Image.new()
pixel = preload("res://Assets/Graphics/circle_filled_9x9.png")
left_brush_type_button.get_child(0).texture.create_from_image(pixel, 0)
left_circle_points = plot_circle(left_brush_size)
else:
@ -516,12 +519,15 @@ func update_right_custom_brush() -> void:
if current_right_brush_type == BRUSH_TYPES.PIXEL:
var pixel := Image.new()
pixel = preload("res://Assets/Graphics/pixel_image.png")
pixel = blend_image_with_color(pixel, right_color_picker.color, 1)
right_brush_type_button.get_child(0).texture.create_from_image(pixel, 0)
elif current_right_brush_type == BRUSH_TYPES.CIRCLE:
var pixel := Image.new()
pixel = preload("res://Assets/Graphics/circle_9x9.png")
pixel = blend_image_with_color(pixel, right_color_picker.color, 1)
right_brush_type_button.get_child(0).texture.create_from_image(pixel, 0)
right_circle_points = plot_circle(right_brush_size)
elif current_right_brush_type == BRUSH_TYPES.FILLED_CIRCLE:
var pixel := Image.new()
pixel = preload("res://Assets/Graphics/circle_filled_9x9.png")
right_brush_type_button.get_child(0).texture.create_from_image(pixel, 0)
right_circle_points = plot_circle(right_brush_size)
else: