Added diagonal outlines, changed paint all pixels of the same color to respect selection

This commit is contained in:
OverloadedOrama 2019-12-25 02:53:45 +02:00
parent a06dbdb9fc
commit d3ff1e984b
3 changed files with 64 additions and 19 deletions

View file

@ -1721,23 +1721,23 @@ anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -92.0
margin_top = -27.0
margin_right = 92.0
margin_bottom = -4.0
margin_left = -120.5
margin_top = -46.0
margin_right = 120.5
margin_bottom = 15.0
custom_constants/vseparation = 4
custom_constants/hseparation = 4
columns = 2
[node name="ThickLabel" type="Label" parent="OutlineDialog/OptionsContainer"]
margin_top = 1.0
margin_right = 75.0
margin_right = 115.0
margin_bottom = 16.0
text = "Thickness:"
[node name="ThickValue" type="SpinBox" parent="OutlineDialog/OptionsContainer"]
margin_left = 79.0
margin_right = 143.0
margin_left = 119.0
margin_right = 183.0
margin_bottom = 17.0
min_value = 1.0
max_value = 16384.0
@ -1746,18 +1746,24 @@ suffix = "px"
[node name="OutlineColorLabel" type="Label" parent="OutlineDialog/OptionsContainer"]
margin_top = 23.0
margin_right = 75.0
margin_right = 115.0
margin_bottom = 38.0
text = "Fill with color:"
[node name="OutlineColor" type="ColorPickerButton" parent="OutlineDialog/OptionsContainer"]
margin_left = 79.0
margin_left = 119.0
margin_top = 21.0
margin_right = 143.0
margin_right = 183.0
margin_bottom = 41.0
rect_min_size = Vector2( 64, 20 )
color = Color( 1, 0, 0, 1 )
[node name="DiagonalCheckBox" type="CheckBox" parent="OutlineDialog/OptionsContainer"]
margin_top = 45.0
margin_right = 115.0
margin_bottom = 61.0
text = "Diagonal outlines"
[node name="AboutDialog" type="AcceptDialog" parent="."]
editor/display_folded = true
margin_right = 284.0

View file

@ -163,7 +163,7 @@ func _process(delta : float) -> void:
pencil_and_eraser(mouse_pos, Color(0, 0, 0, 0), current_mouse_button)
"Bucket":
if can_handle && Global.current_frame == frame:
if fill_area == 0: #Paint the specific area of the same color
if fill_area == 0: # Paint the specific area of the same color
var current_color : Color
var horizontal_mirror := false
var vertical_mirror := false
@ -189,7 +189,17 @@ func _process(delta : float) -> void:
var pos := Vector2(mirror_x, mirror_y)
flood_fill(pos, layers[current_layer_index][0].get_pixelv(pos), current_color)
else: #Paint all pixels of the same color
else: # Paint all pixels of the same color
var west_limit := location.x
var east_limit := location.x + size.x
var north_limit := location.y
var south_limit := location.y + size.y
if Global.selected_pixels.size() != 0:
west_limit = max(west_limit, Global.selection_rectangle.polygon[0].x)
east_limit = min(east_limit, Global.selection_rectangle.polygon[2].x)
north_limit = max(north_limit, Global.selection_rectangle.polygon[0].y)
south_limit = min(south_limit, Global.selection_rectangle.polygon[2].y)
var current_color : Color
if current_mouse_button == "left_mouse":
current_color = Global.left_color_picker.color
@ -197,8 +207,8 @@ func _process(delta : float) -> void:
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:
for xx in range(west_limit, east_limit):
for yy in range(north_limit, south_limit):
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)

View file

@ -124,6 +124,8 @@ func _ready() -> void:
i = 0
for item in image_menu_items.keys():
image_menu.add_item(item, i, image_menu_items[item])
if i == 3:
image_menu.add_separator()
i += 1
i = 0
for item in help_menu_items.keys():
@ -361,7 +363,7 @@ func image_menu_id_pressed(id : int) -> void:
var px_color = image.get_pixel(xx, yy)
if px_color.a == 0:
continue
var gray = image.get_pixel(xx, yy).gray()
var gray = image.get_pixel(xx, yy).v
px_color = Color(gray, gray, gray, px_color.a)
image.set_pixel(xx, yy, px_color)
Global.canvas.handle_redo("Draw")
@ -706,6 +708,8 @@ func _on_ScaleImage_confirmed() -> void:
func _on_OutlineDialog_confirmed() -> void:
var outline_color : Color = $OutlineDialog/OptionsContainer/OutlineColor.color
var thickness : int = $OutlineDialog/OptionsContainer/ThickValue.value
var diagonal : bool = $OutlineDialog/OptionsContainer/DiagonalCheckBox.pressed
var image : Image = Global.canvas.layers[Global.canvas.current_layer_index][0]
if image.is_invisible():
return
@ -722,30 +726,55 @@ func _on_OutlineDialog_confirmed() -> void:
continue
for i in range(1, thickness + 1):
var new_pos : Vector2 = pos + Vector2.LEFT * i
var new_pos : Vector2 = pos + Vector2.LEFT * i # Left
if new_pos.x >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.RIGHT * i
new_pos = pos + Vector2.RIGHT * i # Right
if new_pos.x < Global.canvas.size.x:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.UP * i
new_pos = pos + Vector2.UP * i # Up
if new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.DOWN * i
new_pos = pos + Vector2.DOWN * i # Down
if new_pos.y < Global.canvas.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
if diagonal:
new_pos = pos + (Vector2.LEFT + Vector2.UP) * i # Top left
if new_pos.x >= 0 && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.LEFT + Vector2.DOWN) * i # Bottom left
if new_pos.x >= 0 && new_pos.y < Global.canvas.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.UP) * i # Top right
if new_pos.x < Global.canvas.size.x && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.DOWN) * i # Bottom right
if new_pos.x < Global.canvas.size.x && new_pos.y < Global.canvas.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
image.copy_from(new_image)
Global.canvas.handle_redo("Draw")