Added affecting options to the HSVDialog

First option is to affect the selected pixels only. The second it to affect the current cel, or the entire frame (all cels of the frame). Options to affect all frames and all projects will be added next. I also made changes to Canvas.handle_undo() and handle_redo() to make this work.

Once all these options are added successfully in HSVDialog, they will also be added in the rest of the Image effect dialogs.
This commit is contained in:
OverloadedOrama 2020-07-24 03:22:12 +03:00
parent 5612064533
commit 1ce89c6577
4 changed files with 120 additions and 41 deletions

View file

@ -1,5 +1,10 @@
extends WindowDialog
enum {CEL, FRAME, ALL_FRAMES, ALL_PROJECTS}
var affect : int = CEL
var pixels := []
var current_cel : Image
var preview_image : Image
var preview_texture : ImageTexture
@ -13,6 +18,7 @@ onready var sat_spinbox = $MarginContainer/VBoxContainer/HBoxContainer/TextBoxes
onready var val_spinbox = $MarginContainer/VBoxContainer/HBoxContainer/TextBoxes/Value
onready var preview = $MarginContainer/VBoxContainer/TextureRect
onready var selection_checkbox : CheckBox = $MarginContainer/VBoxContainer/AffectHBoxContainer/SelectionCheckBox
func _ready() -> void:
@ -25,6 +31,7 @@ func _ready() -> void:
func _on_HSVDialog_about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
preview_image.copy_from(current_cel)
_on_SelectionCheckBox_toggled(selection_checkbox.pressed)
update_preview()
@ -34,10 +41,15 @@ func _on_Cancel_pressed() -> void:
func _on_Apply_pressed() -> void:
Global.canvas.handle_undo("Draw")
DrawingAlgos.adjust_hsv(current_cel, hue_slider.value, sat_slider.value, val_slider.value)
Global.canvas.update_texture(Global.current_project.current_layer)
Global.canvas.handle_redo("Draw")
if affect == CEL:
Global.canvas.handle_undo("Draw")
DrawingAlgos.adjust_hsv(current_cel, hue_slider.value, sat_slider.value, val_slider.value, pixels)
Global.canvas.handle_redo("Draw")
elif affect == FRAME:
Global.canvas.handle_undo("Draw", Global.current_project, -1)
for cel in Global.current_project.frames[Global.current_project.current_frame].cels:
DrawingAlgos.adjust_hsv(cel.image, hue_slider.value, sat_slider.value, val_slider.value, pixels)
Global.canvas.handle_redo("Draw", Global.current_project, -1)
reset()
visible = false
@ -55,7 +67,7 @@ func reset() -> void:
func update_preview() -> void:
preview_image.copy_from(current_cel)
DrawingAlgos.adjust_hsv(preview_image, hue_slider.value, sat_slider.value, val_slider.value)
DrawingAlgos.adjust_hsv(preview_image, hue_slider.value, sat_slider.value, val_slider.value, pixels)
preview_texture.create_from_image(preview_image, 0)
preview.texture = preview_texture
@ -94,3 +106,19 @@ func _on_Value_value_changed(value : float) -> void:
val_spinbox.value = value
val_slider.value = value
update_preview()
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))
update_preview()
func _on_AffectOptionButton_item_selected(index : int) -> void:
affect = index

View file

@ -33,15 +33,15 @@ __meta__ = {
[node name="TextureRect" type="TextureRect" parent="MarginContainer/VBoxContainer"]
margin_right = 453.0
margin_bottom = 197.0
margin_bottom = 169.0
size_flags_vertical = 3
expand = true
stretch_mode = 6
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 201.0
margin_top = 173.0
margin_right = 453.0
margin_bottom = 285.0
margin_bottom = 257.0
custom_constants/separation = 10
__meta__ = {
"_edit_use_anchors_": false
@ -132,6 +132,27 @@ margin_bottom = 84.0
mouse_default_cursor_shape = 1
min_value = -100.0
[node name="AffectHBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 261.0
margin_right = 453.0
margin_bottom = 285.0
[node name="SelectionCheckBox" type="CheckBox" parent="MarginContainer/VBoxContainer/AffectHBoxContainer"]
margin_right = 160.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
pressed = true
text = "Only affect selection"
[node name="AffectOptionButton" type="OptionButton" parent="MarginContainer/VBoxContainer/AffectHBoxContainer"]
margin_left = 164.0
margin_right = 263.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
text = "Current cel"
items = [ "Current cel", null, false, 0, null, "Current frame", null, false, 1, null, "All frames", null, true, 2, null, "All projects", null, true, 3, null ]
selected = 0
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 289.0
margin_right = 453.0
@ -162,5 +183,7 @@ text = "Cancel"
[connection signal="value_changed" from="MarginContainer/VBoxContainer/HBoxContainer/TextBoxes/Hue" to="." method="_on_Hue_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/HBoxContainer/TextBoxes/Saturation" to="." method="_on_Saturation_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/HBoxContainer/TextBoxes/Value" to="." method="_on_Value_value_changed"]
[connection signal="toggled" from="MarginContainer/VBoxContainer/AffectHBoxContainer/SelectionCheckBox" to="." method="_on_SelectionCheckBox_toggled"]
[connection signal="item_selected" from="MarginContainer/VBoxContainer/AffectHBoxContainer/AffectOptionButton" to="." method="_on_AffectOptionButton_item_selected"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/Apply" to="." method="_on_Apply_pressed"]
[connection signal="pressed" from="MarginContainer/VBoxContainer/HBoxContainer2/Cancel" to="." method="_on_Cancel_pressed"]