From 4870ebc094570e19020a8f745affbef8cec96710 Mon Sep 17 00:00:00 2001 From: OverloadedOrama <35376950+OverloadedOrama@users.noreply.github.com> Date: Mon, 27 Jul 2020 04:11:46 +0300 Subject: [PATCH] Added checkbox in OutlineDialog for affection selection --- src/Autoload/DrawingAlgos.gd | 216 +++++++++++++++--------------- src/UI/Dialogs/OutlineDialog.gd | 36 ++++- src/UI/Dialogs/OutlineDialog.tscn | 14 +- 3 files changed, 149 insertions(+), 117 deletions(-) diff --git a/src/Autoload/DrawingAlgos.gd b/src/Autoload/DrawingAlgos.gd index 172a4e77f..b8b7267a5 100644 --- a/src/Autoload/DrawingAlgos.gd +++ b/src/Autoload/DrawingAlgos.gd @@ -318,7 +318,7 @@ func desaturate_image(image : Image) -> void: 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(): return var new_image := Image.new() @@ -326,129 +326,127 @@ func generate_outline(image : Image, outline_color : Color, thickness : int, dia new_image.lock() Global.canvas.handle_undo("Draw") - for xx in image.get_size().x: - for yy in image.get_size().y: - var pos = Vector2(xx, yy) - var current_pixel := image.get_pixelv(pos) - if current_pixel.a == 0: - continue + for pos in pixels: + var current_pixel := image.get_pixelv(pos) + if current_pixel.a == 0: + continue - for i in range(1, thickness + 1): - if inside_image: - var outline_pos : Vector2 = pos + Vector2.LEFT # Left - if outline_pos.x < 0 || image.get_pixelv(outline_pos).a == 0: - 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 + for i in range(1, thickness + 1): + if inside_image: + var outline_pos : Vector2 = pos + Vector2.LEFT # Left + if outline_pos.x < 0 || image.get_pixelv(outline_pos).a == 0: + 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: + 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: + 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: + if new_pixel.a > 0: 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: + 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) 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.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) - new_pos = pos + (Vector2.LEFT + Vector2.DOWN) * i # Bottom left - 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) + new_pos = pos + (Vector2.RIGHT + Vector2.UP) * i # Top right + 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) - new_pos = pos + (Vector2.RIGHT + Vector2.UP) * i # Top right - 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) - - 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) + 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) Global.canvas.handle_redo("Draw") diff --git a/src/UI/Dialogs/OutlineDialog.gd b/src/UI/Dialogs/OutlineDialog.gd index db81a100d..3e47a92e2 100644 --- a/src/UI/Dialogs/OutlineDialog.gd +++ b/src/UI/Dialogs/OutlineDialog.gd @@ -1,14 +1,38 @@ 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: - $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: - var outline_color : Color = $OptionsContainer/OutlineColor.color - var thickness : int = $OptionsContainer/ThickValue.value - var diagonal : bool = $OptionsContainer/DiagonalCheckBox.pressed - var inside_image : bool = $OptionsContainer/InsideImageCheckBox.pressed + var color : Color = outline_color.color + var thickness : int = thick_value.value + var diagonal : bool = diagonal_checkbox.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 - 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)) diff --git a/src/UI/Dialogs/OutlineDialog.tscn b/src/UI/Dialogs/OutlineDialog.tscn index d66c8abef..ee2e71cc8 100644 --- a/src/UI/Dialogs/OutlineDialog.tscn +++ b/src/UI/Dialogs/OutlineDialog.tscn @@ -13,9 +13,9 @@ anchor_top = 0.5 anchor_right = 0.5 anchor_bottom = 0.5 margin_left = -121.0 -margin_top = -52.0 +margin_top = -66.0 margin_right = 121.0 -margin_bottom = 24.0 +margin_bottom = 38.0 custom_constants/vseparation = 4 custom_constants/hseparation = 4 columns = 2 @@ -64,4 +64,14 @@ margin_right = 242.0 margin_bottom = 76.0 mouse_default_cursor_shape = 2 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="toggled" from="OptionsContainer/SelectionCheckBox" to="." method="_on_SelectionCheckBox_toggled"]