1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-18 17:19:50 +00:00

Added checkbox in OutlineDialog for affection selection

This commit is contained in:
OverloadedOrama 2020-07-27 04:11:46 +03:00
parent 45126ce908
commit 4870ebc094
3 changed files with 149 additions and 117 deletions

View file

@ -318,7 +318,7 @@ func desaturate_image(image : Image) -> void:
Global.canvas.handle_redo("Draw") Global.canvas.handle_redo("Draw")
func generate_outline(image : Image, outline_color : Color, thickness : int, diagonal : bool, inside_image : bool) -> void: func generate_outline(image : Image, pixels : Array, outline_color : Color, thickness : int, diagonal : bool, inside_image : bool) -> void:
if image.is_invisible(): if image.is_invisible():
return return
var new_image := Image.new() var new_image := Image.new()
@ -326,129 +326,127 @@ func generate_outline(image : Image, outline_color : Color, thickness : int, dia
new_image.lock() new_image.lock()
Global.canvas.handle_undo("Draw") Global.canvas.handle_undo("Draw")
for xx in image.get_size().x: for pos in pixels:
for yy in image.get_size().y: var current_pixel := image.get_pixelv(pos)
var pos = Vector2(xx, yy) if current_pixel.a == 0:
var current_pixel := image.get_pixelv(pos) continue
if current_pixel.a == 0:
continue
for i in range(1, thickness + 1): for i in range(1, thickness + 1):
if inside_image: if inside_image:
var outline_pos : Vector2 = pos + Vector2.LEFT # Left var outline_pos : Vector2 = pos + Vector2.LEFT # Left
if outline_pos.x < 0 || image.get_pixelv(outline_pos).a == 0: if outline_pos.x < 0 || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.RIGHT * (i - 1) var new_pos : Vector2 = pos + Vector2.RIGHT * (i - 1)
if new_pos.x < Global.current_project.size.x:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + Vector2.RIGHT # Right
if outline_pos.x >= Global.current_project.size.x || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.LEFT * (i - 1)
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)
outline_pos = pos + Vector2.UP # Up
if outline_pos.y < 0 || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.DOWN * (i - 1)
if new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + Vector2.DOWN # Down
if outline_pos.y >= Global.current_project.size.y || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.UP * (i - 1)
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)
if diagonal:
outline_pos = pos + (Vector2.LEFT + Vector2.UP) # Top left
if (outline_pos.x < 0 && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.DOWN) * (i - 1)
if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.LEFT + Vector2.DOWN) # Bottom left
if (outline_pos.x < 0 && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.UP) * (i - 1)
if new_pos.x < Global.current_project.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)
outline_pos = pos + (Vector2.RIGHT + Vector2.UP) # Top right
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.DOWN) * (i - 1)
if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.RIGHT + Vector2.DOWN) # Bottom right
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.UP) * (i - 1)
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)
else:
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 # Right
if new_pos.x < Global.current_project.size.x: if new_pos.x < Global.current_project.size.x:
var new_pixel = image.get_pixelv(new_pos) var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0: if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color) new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.UP * i # Up outline_pos = pos + Vector2.RIGHT # Right
if new_pos.y >= 0: if outline_pos.x >= Global.current_project.size.x || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.LEFT * (i - 1)
if new_pos.x >= 0:
var new_pixel = image.get_pixelv(new_pos) var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0: if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color) new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + Vector2.DOWN * i # Down outline_pos = pos + Vector2.UP # Up
if outline_pos.y < 0 || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.DOWN * (i - 1)
if new_pos.y < Global.current_project.size.y: if new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + Vector2.DOWN # Down
if outline_pos.y >= Global.current_project.size.y || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + Vector2.UP * (i - 1)
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)
if diagonal:
outline_pos = pos + (Vector2.LEFT + Vector2.UP) # Top left
if (outline_pos.x < 0 && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.DOWN) * (i - 1)
if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.LEFT + Vector2.DOWN) # Bottom left
if (outline_pos.x < 0 && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.RIGHT + Vector2.UP) * (i - 1)
if new_pos.x < Global.current_project.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)
outline_pos = pos + (Vector2.RIGHT + Vector2.UP) # Top right
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y < 0) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.DOWN) * (i - 1)
if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a > 0:
new_image.set_pixelv(new_pos, outline_color)
outline_pos = pos + (Vector2.RIGHT + Vector2.DOWN) # Bottom right
if (outline_pos.x >= Global.current_project.size.x && outline_pos.y >= Global.current_project.size.y) || image.get_pixelv(outline_pos).a == 0:
var new_pos : Vector2 = pos + (Vector2.LEFT + Vector2.UP) * (i - 1)
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)
else:
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 # Right
if new_pos.x < Global.current_project.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 # 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 # Down
if new_pos.y < Global.current_project.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) var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0: if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color) new_image.set_pixelv(new_pos, outline_color)
if diagonal: new_pos = pos + (Vector2.LEFT + Vector2.DOWN) * i # Bottom left
new_pos = pos + (Vector2.LEFT + Vector2.UP) * i # Top left if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y:
if new_pos.x >= 0 && new_pos.y >= 0: var new_pixel = image.get_pixelv(new_pos)
var new_pixel = image.get_pixelv(new_pos) if new_pixel.a == 0:
if new_pixel.a == 0: new_image.set_pixelv(new_pos, outline_color)
new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.LEFT + Vector2.DOWN) * i # Bottom left new_pos = pos + (Vector2.RIGHT + Vector2.UP) * i # Top right
if new_pos.x >= 0 && new_pos.y < Global.current_project.size.y: if new_pos.x < Global.current_project.size.x && new_pos.y >= 0:
var new_pixel = image.get_pixelv(new_pos) var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0: if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color) new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.UP) * i # Top right new_pos = pos + (Vector2.RIGHT + Vector2.DOWN) * i # Bottom right
if new_pos.x < Global.current_project.size.x && new_pos.y >= 0: if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.size.y:
var new_pixel = image.get_pixelv(new_pos) var new_pixel = image.get_pixelv(new_pos)
if new_pixel.a == 0: if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color) new_image.set_pixelv(new_pos, outline_color)
new_pos = pos + (Vector2.RIGHT + Vector2.DOWN) * i # Bottom right
if new_pos.x < Global.current_project.size.x && new_pos.y < Global.current_project.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) image.copy_from(new_image)
Global.canvas.handle_redo("Draw") Global.canvas.handle_redo("Draw")

View file

@ -1,14 +1,38 @@
extends ConfirmationDialog extends ConfirmationDialog
var pixels := []
onready var outline_color = $OptionsContainer/OutlineColor
onready var thick_value = $OptionsContainer/ThickValue
onready var diagonal_checkbox = $OptionsContainer/DiagonalCheckBox
onready var inside_image_checkbox = $OptionsContainer/InsideImageCheckBox
onready var selection_checkbox = $OptionsContainer/SelectionCheckBox
func _ready() -> void: func _ready() -> void:
$OptionsContainer/OutlineColor.get_picker().presets_visible = false outline_color.get_picker().presets_visible = false
func _on_OutlineDialog_about_to_show() -> void:
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
func _on_OutlineDialog_confirmed() -> void: func _on_OutlineDialog_confirmed() -> void:
var outline_color : Color = $OptionsContainer/OutlineColor.color var color : Color = outline_color.color
var thickness : int = $OptionsContainer/ThickValue.value var thickness : int = thick_value.value
var diagonal : bool = $OptionsContainer/DiagonalCheckBox.pressed var diagonal : bool = diagonal_checkbox.pressed
var inside_image : bool = $OptionsContainer/InsideImageCheckBox.pressed var inside_image : bool = inside_image_checkbox.pressed
var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image var image : Image = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
DrawingAlgos.generate_outline(image, outline_color, thickness, diagonal, inside_image) DrawingAlgos.generate_outline(image, pixels, color, thickness, diagonal, inside_image)
func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
pixels.clear()
if button_pressed:
pixels = Global.current_project.selected_pixels.duplicate()
else:
for x in Global.current_project.size.x:
for y in Global.current_project.size.y:
pixels.append(Vector2(x, y))

View file

@ -13,9 +13,9 @@ anchor_top = 0.5
anchor_right = 0.5 anchor_right = 0.5
anchor_bottom = 0.5 anchor_bottom = 0.5
margin_left = -121.0 margin_left = -121.0
margin_top = -52.0 margin_top = -66.0
margin_right = 121.0 margin_right = 121.0
margin_bottom = 24.0 margin_bottom = 38.0
custom_constants/vseparation = 4 custom_constants/vseparation = 4
custom_constants/hseparation = 4 custom_constants/hseparation = 4
columns = 2 columns = 2
@ -64,4 +64,14 @@ margin_right = 242.0
margin_bottom = 76.0 margin_bottom = 76.0
mouse_default_cursor_shape = 2 mouse_default_cursor_shape = 2
text = "Place inside image" text = "Place inside image"
[node name="SelectionCheckBox" type="CheckBox" parent="OptionsContainer"]
margin_top = 80.0
margin_right = 90.0
margin_bottom = 104.0
mouse_default_cursor_shape = 2
pressed = true
text = "Only affect selection"
[connection signal="about_to_show" from="." to="." method="_on_OutlineDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_OutlineDialog_confirmed"] [connection signal="confirmed" from="." to="." method="_on_OutlineDialog_confirmed"]
[connection signal="toggled" from="OptionsContainer/SelectionCheckBox" to="." method="_on_SelectionCheckBox_toggled"]