1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-30 23:19:49 +00:00

Added a preview in OutlineDialog

This commit is contained in:
OverloadedOrama 2020-07-27 04:36:00 +03:00
parent 4870ebc094
commit 94aa94a364
3 changed files with 101 additions and 41 deletions

View file

@ -324,8 +324,8 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
var new_image := Image.new()
new_image.copy_from(image)
new_image.lock()
image.lock()
Global.canvas.handle_undo("Draw")
for pos in pixels:
var current_pixel := image.get_pixelv(pos)
if current_pixel.a == 0:
@ -448,8 +448,9 @@ func generate_outline(image : Image, pixels : Array, outline_color : Color, thic
if new_pixel.a == 0:
new_image.set_pixelv(new_pos, outline_color)
image.unlock()
new_image.unlock()
image.copy_from(new_image)
Global.canvas.handle_redo("Draw")
func adjust_hsv(img: Image, delta_h : float, delta_s : float, delta_v : float, pixels : Array) -> void:

View file

@ -2,30 +2,40 @@ extends ConfirmationDialog
var pixels := []
var current_cel : Image
var preview_image : Image
var preview_texture : ImageTexture
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
var color := Color.red
var thickness := 1
var diagonal := false
var inside_image := false
onready var preview : TextureRect = $VBoxContainer/Preview
onready var outline_color = $VBoxContainer/OptionsContainer/OutlineColor
#onready var thick_value = $VBoxContainer/OptionsContainer/ThickValue
#onready var diagonal_checkbox = $VBoxContainer/OptionsContainer/DiagonalCheckBox
#onready var inside_image_checkbox = $VBoxContainer/OptionsContainer/InsideImageCheckBox
onready var selection_checkbox = $VBoxContainer/OptionsContainer/SelectionCheckBox
func _ready() -> void:
current_cel = Image.new()
preview_image = Image.new()
preview_texture = ImageTexture.new()
outline_color.get_picker().presets_visible = false
color = outline_color.color
func _on_OutlineDialog_about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
func _on_OutlineDialog_confirmed() -> void:
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, pixels, color, thickness, diagonal, inside_image)
Global.canvas.handle_undo("Draw")
DrawingAlgos.generate_outline(current_cel, pixels, color, thickness, diagonal, inside_image)
Global.canvas.handle_redo("Draw")
func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
@ -36,3 +46,32 @@ func _on_SelectionCheckBox_toggled(button_pressed : bool) -> void:
for x in Global.current_project.size.x:
for y in Global.current_project.size.y:
pixels.append(Vector2(x, y))
update_preview()
func _on_ThickValue_value_changed(value : int):
thickness = value
update_preview()
func _on_OutlineColor_color_changed(_color : Color):
color = _color
update_preview()
func _on_DiagonalCheckBox_toggled(button_pressed : bool):
diagonal = button_pressed
update_preview()
func _on_InsideImageCheckBox_toggled(button_pressed : bool):
inside_image = button_pressed
update_preview()
func update_preview() -> void:
preview_image.copy_from(current_cel)
DrawingAlgos.generate_outline(preview_image, pixels, color, thickness, diagonal, inside_image)
preview_texture.create_from_image(preview_image, 0)
preview.texture = preview_texture

View file

@ -6,29 +6,45 @@
margin_right = 200.0
margin_bottom = 70.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="OptionsContainer" type="GridContainer" parent="."]
anchor_left = 0.5
anchor_top = 0.5
anchor_right = 0.5
anchor_bottom = 0.5
margin_left = -121.0
margin_top = -66.0
margin_right = 121.0
margin_bottom = 38.0
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 320.0
margin_bottom = 316.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
margin_right = 312.0
rect_min_size = Vector2( 200, 200 )
expand = true
stretch_mode = 6
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"]
margin_top = 4.0
margin_right = 312.0
margin_bottom = 108.0
custom_constants/vseparation = 4
custom_constants/hseparation = 4
columns = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ThickLabel" type="Label" parent="OptionsContainer"]
[node name="ThickLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 5.0
margin_right = 90.0
margin_right = 160.0
margin_bottom = 19.0
text = "Thickness:"
[node name="ThickValue" type="SpinBox" parent="OptionsContainer"]
margin_left = 94.0
margin_right = 242.0
[node name="ThickValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 164.0
margin_right = 312.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0
@ -36,42 +52,46 @@ max_value = 16384.0
value = 1.0
suffix = "px"
[node name="OutlineColorLabel" type="Label" parent="OptionsContainer"]
[node name="OutlineColorLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 31.0
margin_right = 90.0
margin_right = 160.0
margin_bottom = 45.0
text = "Fill with color:"
[node name="OutlineColor" type="ColorPickerButton" parent="OptionsContainer"]
margin_left = 94.0
[node name="OutlineColor" type="ColorPickerButton" parent="VBoxContainer/OptionsContainer"]
margin_left = 164.0
margin_top = 28.0
margin_right = 242.0
margin_right = 312.0
margin_bottom = 48.0
rect_min_size = Vector2( 64, 20 )
color = Color( 1, 0, 0, 1 )
[node name="DiagonalCheckBox" type="CheckBox" parent="OptionsContainer"]
[node name="DiagonalCheckBox" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_top = 52.0
margin_right = 90.0
margin_right = 160.0
margin_bottom = 76.0
mouse_default_cursor_shape = 2
text = "Diagonal"
[node name="InsideImageCheckBox" type="CheckBox" parent="OptionsContainer"]
margin_left = 94.0
[node name="InsideImageCheckBox" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 164.0
margin_top = 52.0
margin_right = 242.0
margin_right = 312.0
margin_bottom = 76.0
mouse_default_cursor_shape = 2
text = "Place inside image"
[node name="SelectionCheckBox" type="CheckBox" parent="OptionsContainer"]
[node name="SelectionCheckBox" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_top = 80.0
margin_right = 90.0
margin_right = 160.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"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/ThickValue" to="." method="_on_ThickValue_value_changed"]
[connection signal="color_changed" from="VBoxContainer/OptionsContainer/OutlineColor" to="." method="_on_OutlineColor_color_changed"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/DiagonalCheckBox" to="." method="_on_DiagonalCheckBox_toggled"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/InsideImageCheckBox" to="." method="_on_InsideImageCheckBox_toggled"]
[connection signal="toggled" from="VBoxContainer/OptionsContainer/SelectionCheckBox" to="." method="_on_SelectionCheckBox_toggled"]