1
0
Fork 0
mirror of https://github.com/Orama-Interactive/Pixelorama.git synced 2025-01-19 17:49:47 +00:00
Pixelorama/Scripts/Dialogs/HSVDialog.gd

97 lines
3.1 KiB
GDScript3
Raw Normal View History

2020-04-13 14:10:17 +00:00
extends WindowDialog
onready var hue_slider = $MarginContainer/VBoxContainer/HBoxContainer/Sliders/Hue
onready var sat_slider = $MarginContainer/VBoxContainer/HBoxContainer/Sliders/Saturation
onready var val_slider = $MarginContainer/VBoxContainer/HBoxContainer/Sliders/Value
2020-04-13 14:10:17 +00:00
onready var hue_spinbox = $MarginContainer/VBoxContainer/HBoxContainer/TextBoxes/Hue
onready var sat_spinbox = $MarginContainer/VBoxContainer/HBoxContainer/TextBoxes/Saturation
onready var val_spinbox = $MarginContainer/VBoxContainer/HBoxContainer/TextBoxes/Value
2020-04-13 14:10:17 +00:00
onready var preview = $MarginContainer/VBoxContainer/TextureRect
2020-04-13 14:10:17 +00:00
var current_layer:Image
var preview_image:Image
var preview_texture:ImageTexture
2020-04-13 14:10:17 +00:00
func _ready():
current_layer = Image.new()
preview_image = Image.new()
preview_texture = ImageTexture.new()
preview_texture.flags = 0
func _on_HSVDialog_about_to_show():
current_layer = Global.canvas.layers[Global.current_layer][0]
preview_image.copy_from(current_layer)
update_preview()
2020-04-13 14:10:17 +00:00
func _on_Cancel_pressed():
visible = false
reset()
func _on_Apply_pressed():
Global.canvas.handle_undo("Draw")
Global.canvas.adjust_hsv(current_layer,0,hue_slider.value)
Global.canvas.adjust_hsv(current_layer,1,sat_slider.value)
Global.canvas.adjust_hsv(current_layer,2,val_slider.value)
Global.canvas.update_texture(Global.current_layer)
2020-04-13 14:10:17 +00:00
Global.canvas.handle_redo("Draw")
reset()
visible = false
2020-04-15 09:49:29 +00:00
func reset() -> void:
2020-04-13 14:10:17 +00:00
disconnect_signals()
hue_slider.value = 0
sat_slider.value = 0
val_slider.value = 0
hue_spinbox.value = 0
sat_spinbox.value = 0
val_spinbox.value = 0
2020-04-13 14:10:17 +00:00
reconnect_signals()
2020-04-15 09:49:29 +00:00
func update_preview() -> void:
preview_image.copy_from(current_layer)
Global.canvas.adjust_hsv(preview_image,0,hue_slider.value)
Global.canvas.adjust_hsv(preview_image,1,sat_slider.value)
Global.canvas.adjust_hsv(preview_image,2,val_slider.value)
preview_texture.create_from_image(preview_image, 0)
preview.texture = preview_texture
2020-04-15 09:49:29 +00:00
func disconnect_signals() -> void:
2020-04-13 14:10:17 +00:00
hue_slider.disconnect("value_changed",self,"_on_Hue_value_changed")
sat_slider.disconnect("value_changed",self,"_on_Saturation_value_changed")
val_slider.disconnect("value_changed",self,"_on_Value_value_changed")
hue_spinbox.disconnect("value_changed",self,"_on_Hue_value_changed")
sat_spinbox.disconnect("value_changed",self,"_on_Saturation_value_changed")
val_spinbox.disconnect("value_changed",self,"_on_Value_value_changed")
2020-04-15 09:49:29 +00:00
func reconnect_signals() -> void:
2020-04-13 14:10:17 +00:00
hue_slider.connect("value_changed",self,"_on_Hue_value_changed")
sat_slider.connect("value_changed",self,"_on_Saturation_value_changed")
val_slider.connect("value_changed",self,"_on_Value_value_changed")
hue_spinbox.connect("value_changed",self,"_on_Hue_value_changed")
sat_spinbox.connect("value_changed",self,"_on_Saturation_value_changed")
val_spinbox.connect("value_changed",self,"_on_Value_value_changed")
func _on_Hue_value_changed(value):
hue_spinbox.value = value
hue_slider.value = value
update_preview()
2020-04-13 14:10:17 +00:00
func _on_Saturation_value_changed(value):
sat_spinbox.value = value
sat_slider.value = value
update_preview()
2020-04-13 14:10:17 +00:00
func _on_Value_value_changed(value):
val_spinbox.value = value
val_slider.value = value
update_preview()
2020-04-13 14:10:17 +00:00