mirror of
https://github.com/Orama-Interactive/Pixelorama.git
synced 2025-01-18 17:19:50 +00:00
Added HSV Adjust Dialog
This commit is contained in:
parent
bdd3cdf45e
commit
2b8796aacc
|
@ -43,6 +43,7 @@
|
|||
[ext_resource path="res://Assets/Graphics/Dark Themes/Tools/Vertical_Mirror_On.png" type="Texture" id=41]
|
||||
[ext_resource path="res://Assets/Graphics/Dark Themes/Tools/Vertical_Mirror_Off.png" type="Texture" id=42]
|
||||
[ext_resource path="res://Assets/Graphics/Dark Themes/Tools/Zoom.png" type="Texture" id=43]
|
||||
[ext_resource path="res://Prefabs/Dialogs/HSVDialog.tscn" type="PackedScene" id=44]
|
||||
|
||||
[sub_resource type="InputEventKey" id=1]
|
||||
scancode = 88
|
||||
|
@ -1363,8 +1364,11 @@ dialog_text = "This is an error message!"
|
|||
|
||||
[node name="PaletteImportFileDialog" parent="." instance=ExtResource( 37 )]
|
||||
filters = PoolStringArray( "*.json ; JavaScript Object Notation", "*.gpl ; Gimp Palette Library", "*.png; Portable Network Graphics" )
|
||||
current_dir = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
|
||||
current_path = "C:/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
|
||||
current_dir = "D:/libDev/git/Pixelorama-git"
|
||||
current_path = "D:/libDev/git/Pixelorama-git/"
|
||||
|
||||
[node name="HSVDialog" parent="." instance=ExtResource( 44 )]
|
||||
visible = false
|
||||
|
||||
[node name="LeftCursor" type="Sprite" parent="."]
|
||||
visible = false
|
||||
|
@ -1441,6 +1445,7 @@ visible = false
|
|||
[connection signal="confirmed" from="NewPaletteDialog" to="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_new_palette_confirmed"]
|
||||
[connection signal="popup_hide" from="NewPaletteDialog" to="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="_on_NewPaletteDialog_popup_hide"]
|
||||
[connection signal="file_selected" from="PaletteImportFileDialog" to="MenuAndUI/UI/RightPanel/PreviewAndPalettes/ToolAndPaletteVSplit/PaletteVBoxContainer/ScrollPalette/CenterPalette/PaletteContainer" method="on_palette_import_file_selected"]
|
||||
[connection signal="popup_hide" from="HSVDialog" to="." method="_can_draw_true"]
|
||||
|
||||
[editable path="BrushesPopup/TabContainer/File/FileBrushContainer/CircleBrushButton"]
|
||||
|
||||
|
|
137
Prefabs/Dialogs/HSVDialog.tscn
Normal file
137
Prefabs/Dialogs/HSVDialog.tscn
Normal file
|
@ -0,0 +1,137 @@
|
|||
[gd_scene load_steps=2 format=2]
|
||||
|
||||
[ext_resource path="res://Scripts/Dialogs/HSVDialog.gd" type="Script" id=1]
|
||||
|
||||
[node name="HSVDialog" type="WindowDialog"]
|
||||
margin_left = 1.0
|
||||
margin_top = -1.0
|
||||
margin_right = 464.0
|
||||
margin_bottom = 151.0
|
||||
window_title = "Adjust HSV"
|
||||
script = ExtResource( 1 )
|
||||
|
||||
[node name="HBoxContainer" type="HBoxContainer" parent="."]
|
||||
anchor_right = 1.0
|
||||
anchor_bottom = 1.0
|
||||
margin_top = 17.0
|
||||
margin_right = -8.0
|
||||
margin_bottom = -44.0
|
||||
custom_constants/separation = 10
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Names" type="VBoxContainer" parent="HBoxContainer"]
|
||||
margin_right = 83.0
|
||||
margin_bottom = 91.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 0.9
|
||||
custom_constants/separation = 8
|
||||
|
||||
[node name="Hue" type="Label" parent="HBoxContainer/Names"]
|
||||
margin_right = 83.0
|
||||
margin_bottom = 14.0
|
||||
text = "Hue"
|
||||
align = 2
|
||||
|
||||
[node name="Saturation" type="Label" parent="HBoxContainer/Names"]
|
||||
margin_top = 22.0
|
||||
margin_right = 83.0
|
||||
margin_bottom = 36.0
|
||||
text = "Saturation"
|
||||
align = 2
|
||||
|
||||
[node name="Value" type="Label" parent="HBoxContainer/Names"]
|
||||
margin_top = 44.0
|
||||
margin_right = 83.0
|
||||
margin_bottom = 58.0
|
||||
text = "Value"
|
||||
align = 2
|
||||
|
||||
[node name="Sliders" type="VBoxContainer" parent="HBoxContainer"]
|
||||
margin_left = 93.0
|
||||
margin_right = 370.0
|
||||
margin_bottom = 91.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 3.0
|
||||
custom_constants/separation = 7
|
||||
|
||||
[node name="Hue" type="HSlider" parent="HBoxContainer/Sliders"]
|
||||
margin_right = 277.0
|
||||
margin_bottom = 16.0
|
||||
max_value = 359.0
|
||||
value = 180.0
|
||||
|
||||
[node name="Saturation" type="HSlider" parent="HBoxContainer/Sliders"]
|
||||
margin_top = 23.0
|
||||
margin_right = 277.0
|
||||
margin_bottom = 39.0
|
||||
max_value = 99.0
|
||||
value = 50.0
|
||||
|
||||
[node name="Value" type="HSlider" parent="HBoxContainer/Sliders"]
|
||||
margin_top = 46.0
|
||||
margin_right = 277.0
|
||||
margin_bottom = 62.0
|
||||
max_value = 99.0
|
||||
value = 50.0
|
||||
|
||||
[node name="TextBoxes" type="VBoxContainer" parent="HBoxContainer"]
|
||||
margin_left = 380.0
|
||||
margin_right = 454.0
|
||||
margin_bottom = 91.0
|
||||
size_flags_horizontal = 3
|
||||
size_flags_stretch_ratio = 0.0
|
||||
custom_constants/separation = 6
|
||||
|
||||
[node name="Hue" type="SpinBox" parent="HBoxContainer/TextBoxes"]
|
||||
margin_right = 74.0
|
||||
margin_bottom = 24.0
|
||||
max_value = 359.0
|
||||
value = 180.0
|
||||
|
||||
[node name="Saturation" type="SpinBox" parent="HBoxContainer/TextBoxes"]
|
||||
margin_top = 30.0
|
||||
margin_right = 74.0
|
||||
margin_bottom = 54.0
|
||||
max_value = 359.0
|
||||
value = 50.0
|
||||
|
||||
[node name="Value" type="SpinBox" parent="HBoxContainer/TextBoxes"]
|
||||
margin_top = 60.0
|
||||
margin_right = 74.0
|
||||
margin_bottom = 84.0
|
||||
max_value = 359.0
|
||||
value = 50.0
|
||||
|
||||
[node name="HBoxContainer2" type="HBoxContainer" parent="."]
|
||||
margin_left = 117.0
|
||||
margin_top = 97.9999
|
||||
margin_right = 359.0
|
||||
margin_bottom = 138.0
|
||||
custom_constants/separation = 16
|
||||
__meta__ = {
|
||||
"_edit_use_anchors_": false
|
||||
}
|
||||
|
||||
[node name="Apply" type="Button" parent="HBoxContainer2"]
|
||||
margin_right = 113.0
|
||||
margin_bottom = 40.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Apply"
|
||||
|
||||
[node name="Cancel" type="Button" parent="HBoxContainer2"]
|
||||
margin_left = 129.0
|
||||
margin_right = 242.0
|
||||
margin_bottom = 40.0
|
||||
size_flags_horizontal = 3
|
||||
text = "Cancel"
|
||||
[connection signal="about_to_show" from="." to="." method="_on_HSVDialog_about_to_show"]
|
||||
[connection signal="value_changed" from="HBoxContainer/Sliders/Hue" to="." method="_on_Hue_value_changed"]
|
||||
[connection signal="value_changed" from="HBoxContainer/Sliders/Saturation" to="." method="_on_Saturation_value_changed"]
|
||||
[connection signal="value_changed" from="HBoxContainer/Sliders/Value" to="." method="_on_Value_value_changed"]
|
||||
[connection signal="value_changed" from="HBoxContainer/TextBoxes/Hue" to="." method="_on_Hue_value_changed"]
|
||||
[connection signal="value_changed" from="HBoxContainer/TextBoxes/Saturation" to="." method="_on_Saturation_value_changed"]
|
||||
[connection signal="value_changed" from="HBoxContainer/TextBoxes/Value" to="." method="_on_Value_value_changed"]
|
||||
[connection signal="pressed" from="HBoxContainer2/Apply" to="." method="_on_Apply_pressed"]
|
||||
[connection signal="pressed" from="HBoxContainer2/Cancel" to="." method="_on_Cancel_pressed"]
|
|
@ -1010,3 +1010,81 @@ func blend_rect(bg : Image, brush : Image, src_rect : Rect2, dst : Vector2) -> v
|
|||
if out_color.a != 0:
|
||||
bg.set_pixel(dst_x, dst_y, out_color)
|
||||
brush.unlock()
|
||||
|
||||
func adjust_hsv(id,delta)->void:
|
||||
var selection_only:bool = !Global.selected_pixels.empty()
|
||||
var layer:Image = layers[Global.current_layer][0]
|
||||
layer.lock()
|
||||
match id:
|
||||
#Hue
|
||||
0:
|
||||
for i in range(layer.get_width()):
|
||||
for j in range(layer.get_height()):
|
||||
if(selection_only and Global.selected_pixels.has(Vector2(i,j))):
|
||||
var c: Color = layer.get_pixel(i,j)
|
||||
var hue = range_lerp(c.h,0,1,0,360)
|
||||
hue = hue + delta
|
||||
|
||||
while(hue >= 360):
|
||||
hue -= 360
|
||||
while(hue < 0):
|
||||
hue += 360
|
||||
c.h = range_lerp(hue,0,360,0,1)
|
||||
layer.set_pixel(i,j,c)
|
||||
elif(!selection_only):
|
||||
var c: Color = layer.get_pixel(i,j)
|
||||
var hue = range_lerp(c.h,0,1,0,360)
|
||||
hue = hue + delta
|
||||
|
||||
while(hue >= 360):
|
||||
hue -= 360
|
||||
while(hue < 0):
|
||||
hue += 360
|
||||
c.h = range_lerp(hue,0,360,0,1)
|
||||
layer.set_pixel(i,j,c)
|
||||
|
||||
#Saturation
|
||||
1:
|
||||
for i in range(layer.get_width()):
|
||||
for j in range(layer.get_height()):
|
||||
if(selection_only and Global.selected_pixels.has(Vector2(i,j))):
|
||||
var c: Color = layer.get_pixel(i,j)
|
||||
var sat = range_lerp(c.s,0,1,0,100)
|
||||
sat = sat + delta
|
||||
|
||||
sat = clamp(sat,0,100)
|
||||
c.s = range_lerp(sat,0,100,0,1)
|
||||
layer.set_pixel(i,j,c)
|
||||
elif(!selection_only):
|
||||
var c: Color = layer.get_pixel(i,j)
|
||||
var sat = range_lerp(c.s,0,1,0,100)
|
||||
sat = sat + delta
|
||||
|
||||
sat = clamp(sat,0,100)
|
||||
c.s = range_lerp(sat,0,100,0,1)
|
||||
layer.set_pixel(i,j,c)
|
||||
|
||||
#value
|
||||
2:
|
||||
for i in range(layer.get_width()):
|
||||
for j in range(layer.get_height()):
|
||||
if(selection_only and Global.selected_pixels.has(Vector2(i,j))):
|
||||
var c: Color = layer.get_pixel(i,j)
|
||||
var val = range_lerp(c.v,0,1,0,100)
|
||||
val = val + delta
|
||||
|
||||
val = clamp(val,0,100)
|
||||
c.v = range_lerp(val,0,100,0,1)
|
||||
layer.set_pixel(i,j,c)
|
||||
elif(!selection_only):
|
||||
var c: Color = layer.get_pixel(i,j)
|
||||
var val = range_lerp(c.v,0,1,0,100)
|
||||
val = val + delta
|
||||
|
||||
val = clamp(val,0,100)
|
||||
c.v = range_lerp(val,0,100,0,1)
|
||||
layer.set_pixel(i,j,c)
|
||||
|
||||
layer.unlock()
|
||||
update_texture(Global.current_layer)
|
||||
pass
|
||||
|
|
91
Scripts/Dialogs/HSVDialog.gd
Normal file
91
Scripts/Dialogs/HSVDialog.gd
Normal file
|
@ -0,0 +1,91 @@
|
|||
extends WindowDialog
|
||||
|
||||
onready var hue_slider = $ HBoxContainer/Sliders/Hue
|
||||
onready var sat_slider = $ HBoxContainer/Sliders/Saturation
|
||||
onready var val_slider = $ HBoxContainer/Sliders/Value
|
||||
|
||||
onready var hue_spinbox = $ HBoxContainer/TextBoxes/Hue
|
||||
onready var sat_spinbox = $ HBoxContainer/TextBoxes/Saturation
|
||||
onready var val_spinbox = $ HBoxContainer/TextBoxes/Value
|
||||
|
||||
onready var hue_text = $ HBoxContainer/TextBoxes/Hue.get_line_edit()
|
||||
onready var sat_text = $ HBoxContainer/TextBoxes/Saturation.get_line_edit()
|
||||
onready var val_text = $ HBoxContainer/TextBoxes/Value.get_line_edit()
|
||||
|
||||
var oldHue = 180
|
||||
var oldSat = 50
|
||||
var oldVal = 50
|
||||
|
||||
func _ready():
|
||||
get_close_button().connect("pressed",self,"_on_Cancel_pressed")
|
||||
|
||||
func _on_Cancel_pressed():
|
||||
Global.undo_redo.undo()
|
||||
visible = false
|
||||
reset()
|
||||
|
||||
func _on_Apply_pressed():
|
||||
Global.canvas.handle_redo("Draw")
|
||||
reset()
|
||||
visible = false
|
||||
|
||||
|
||||
func reset():
|
||||
disconnect_signals()
|
||||
hue_slider.value = 180
|
||||
sat_slider.value = 50
|
||||
val_slider.value = 50
|
||||
hue_text.text = str(180)
|
||||
sat_text.text = str(50)
|
||||
val_text.text = str(50)
|
||||
reconnect_signals()
|
||||
|
||||
func disconnect_signals():
|
||||
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")
|
||||
|
||||
func reconnect_signals():
|
||||
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_HSVDialog_about_to_show():
|
||||
Global.canvas.handle_undo("Draw")
|
||||
|
||||
func _on_Hue_value_changed(value):
|
||||
hue_text.text = str(value)
|
||||
hue_slider.value = int(value)
|
||||
var delta = value - oldHue
|
||||
oldHue = value
|
||||
Global.canvas.adjust_hsv(0,delta)
|
||||
|
||||
func _on_Saturation_value_changed(value):
|
||||
sat_text.text = str(value)
|
||||
sat_slider.value = int(value)
|
||||
var delta = value - oldSat
|
||||
oldSat = value
|
||||
Global.canvas.adjust_hsv(1,delta)
|
||||
|
||||
|
||||
func _on_Value_value_changed(value):
|
||||
val_text.text = str(value)
|
||||
val_slider.value = int(value)
|
||||
var delta = value - oldVal
|
||||
oldVal = value
|
||||
Global.canvas.adjust_hsv(2,delta)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
|
@ -70,7 +70,8 @@ func _ready() -> void:
|
|||
"Rotate Image" : 0,
|
||||
"Invert colors" : 0,
|
||||
"Desaturation" : 0,
|
||||
"Outline" : 0
|
||||
"Outline" : 0,
|
||||
"Adjust Hue/Sat/Val":0
|
||||
}
|
||||
var help_menu_items := {
|
||||
"View Splash Screen" : 0,
|
||||
|
@ -385,6 +386,9 @@ func image_menu_id_pressed(id : int) -> void:
|
|||
7: # Outline
|
||||
$OutlineDialog.popup_centered()
|
||||
Global.can_draw = false
|
||||
8: # HSV
|
||||
$HSVDialog.popup_centered()
|
||||
Global.can_draw = false
|
||||
|
||||
func help_menu_id_pressed(id : int) -> void:
|
||||
match id:
|
||||
|
|
Loading…
Reference in a new issue