Moved image effect scene and script files into a new folder

This commit is contained in:
OverloadedOrama 2020-07-29 20:34:27 +03:00
parent 30cd607c65
commit d4fe1f7b12
16 changed files with 23 additions and 19 deletions

View file

@ -0,0 +1,57 @@
extends ConfirmationDialog
var current_cel : Image
var preview_image : Image
var preview_texture : ImageTexture
onready var preview : TextureRect = $VBoxContainer/Preview
onready var color1 : ColorPickerButton = $VBoxContainer/ColorsContainer/ColorPickerButton
onready var color2 : ColorPickerButton = $VBoxContainer/ColorsContainer/ColorPickerButton2
onready var steps : SpinBox = $VBoxContainer/StepsContainer/StepSpinBox
onready var direction : OptionButton = $VBoxContainer/DirectionContainer/DirectionOptionButton
func _ready() -> void:
preview_image = Image.new()
preview_texture = ImageTexture.new()
color1.get_picker().presets_visible = false
color2.get_picker().presets_visible = false
func _on_GradientDialog_about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
update_preview()
func update_preview() -> void:
preview_image.copy_from(current_cel)
DrawingAlgos.generate_gradient(preview_image, [color1.color, color2.color], steps.value, direction.selected)
preview_texture.create_from_image(preview_image, 0)
preview.texture = preview_texture
func _on_ColorPickerButton_color_changed(_color : Color) -> void:
update_preview()
func _on_ColorPickerButton2_color_changed(_color : Color) -> void:
update_preview()
func _on_StepSpinBox_value_changed(_value : int) -> void:
update_preview()
func _on_OptionButton_item_selected(_index : int) -> void:
update_preview()
func _on_GradientDialog_confirmed() -> void:
Global.canvas.handle_undo("Draw")
DrawingAlgos.generate_gradient(current_cel, [color1.color, color2.color], steps.value, direction.selected)
Global.canvas.handle_redo("Draw")
func _on_GradientDialog_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -0,0 +1,108 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/GradientDialog.gd" type="Script" id=1]
[node name="GradientDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 196.0
resizable = true
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = -36.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
margin_right = 188.0
margin_bottom = 100.0
rect_min_size = Vector2( 0, 100 )
expand = true
stretch_mode = 6
[node name="ColorsContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 104.0
margin_right = 188.0
margin_bottom = 124.0
[node name="Label" type="Label" parent="VBoxContainer/ColorsContainer"]
margin_top = 3.0
margin_right = 44.0
margin_bottom = 17.0
text = "Colors:"
[node name="ColorPickerButton" type="ColorPickerButton" parent="VBoxContainer/ColorsContainer"]
margin_left = 48.0
margin_right = 68.0
margin_bottom = 20.0
rect_min_size = Vector2( 20, 0 )
mouse_default_cursor_shape = 2
[node name="ColorPickerButton2" type="ColorPickerButton" parent="VBoxContainer/ColorsContainer"]
margin_left = 72.0
margin_right = 92.0
margin_bottom = 20.0
rect_min_size = Vector2( 20, 0 )
mouse_default_cursor_shape = 2
color = Color( 1, 1, 1, 1 )
[node name="StepsContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 128.0
margin_right = 188.0
margin_bottom = 152.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="VBoxContainer/StepsContainer"]
margin_top = 5.0
margin_right = 39.0
margin_bottom = 19.0
text = "Steps:"
[node name="StepSpinBox" type="SpinBox" parent="VBoxContainer/StepsContainer"]
margin_left = 43.0
margin_right = 117.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 2.0
value = 2.0
[node name="DirectionContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 156.0
margin_right = 188.0
margin_bottom = 176.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="VBoxContainer/DirectionContainer"]
margin_top = 3.0
margin_right = 63.0
margin_bottom = 17.0
text = "Direction:"
[node name="DirectionOptionButton" type="OptionButton" parent="VBoxContainer/DirectionContainer"]
margin_left = 67.0
margin_right = 188.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
text = "Top to Bottom"
items = [ "Top to Bottom", null, false, 0, null, "Bottom to Top", null, false, 1, null, "Left to Right", null, false, 2, null, "Right to Left", null, false, 3, null ]
selected = 0
[connection signal="about_to_show" from="." to="." method="_on_GradientDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_GradientDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_GradientDialog_popup_hide"]
[connection signal="color_changed" from="VBoxContainer/ColorsContainer/ColorPickerButton" to="." method="_on_ColorPickerButton_color_changed"]
[connection signal="color_changed" from="VBoxContainer/ColorsContainer/ColorPickerButton2" to="." method="_on_ColorPickerButton2_color_changed"]
[connection signal="value_changed" from="VBoxContainer/StepsContainer/StepSpinBox" to="." method="_on_StepSpinBox_value_changed"]
[connection signal="item_selected" from="VBoxContainer/DirectionContainer/DirectionOptionButton" to="." method="_on_OptionButton_item_selected"]

View file

@ -0,0 +1,151 @@
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
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
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
onready var preview = $MarginContainer/VBoxContainer/TextureRect
onready var selection_checkbox : CheckBox = $MarginContainer/VBoxContainer/AffectHBoxContainer/SelectionCheckBox
func _ready() -> void:
current_cel = Image.new()
preview_image = Image.new()
preview_texture = ImageTexture.new()
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()
func _on_Cancel_pressed() -> void:
visible = false
reset()
func _on_Apply_pressed() -> void:
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)
elif affect == ALL_FRAMES:
Global.canvas.handle_undo("Draw", Global.current_project, -1, -1)
for frame in Global.current_project.frames:
for cel in 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, -1)
elif affect == ALL_PROJECTS:
for project in Global.projects:
var _pixels := []
if selection_checkbox.pressed:
_pixels = project.selected_pixels.duplicate()
else:
for x in project.size.x:
for y in project.size.y:
_pixels.append(Vector2(x, y))
Global.canvas.handle_undo("Draw", project, -1, -1)
for frame in project.frames:
for cel in frame.cels:
DrawingAlgos.adjust_hsv(cel.image, hue_slider.value, sat_slider.value, val_slider.value, _pixels)
Global.canvas.handle_redo("Draw", project, -1, -1)
reset()
visible = false
func reset() -> void:
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
reconnect_signals()
func update_preview() -> void:
preview_image.copy_from(current_cel)
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
func disconnect_signals() -> void:
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() -> void:
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 : float) -> void:
hue_spinbox.value = value
hue_slider.value = value
update_preview()
func _on_Saturation_value_changed(value : float) -> void:
sat_spinbox.value = value
sat_slider.value = value
update_preview()
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
func _on_HSVDialog_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -0,0 +1,190 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/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 = 318.0
window_title = "Adjust HSV"
resizable = true
script = ExtResource( 1 )
[node name="MarginContainer" type="MarginContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
custom_constants/margin_right = 5
custom_constants/margin_top = 5
custom_constants/margin_left = 5
custom_constants/margin_bottom = 5
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="MarginContainer"]
margin_left = 5.0
margin_top = 5.0
margin_right = 458.0
margin_bottom = 314.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="MarginContainer/VBoxContainer"]
margin_right = 453.0
margin_bottom = 169.0
size_flags_vertical = 3
expand = true
stretch_mode = 6
[node name="HBoxContainer" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 173.0
margin_right = 453.0
margin_bottom = 257.0
custom_constants/separation = 10
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Names" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer"]
margin_right = 82.0
margin_bottom = 84.0
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.9
custom_constants/separation = 8
[node name="Hue" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer/Names"]
margin_right = 82.0
margin_bottom = 14.0
text = "Hue"
align = 2
[node name="Saturation" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer/Names"]
margin_top = 22.0
margin_right = 82.0
margin_bottom = 36.0
text = "Saturation"
align = 2
[node name="Value" type="Label" parent="MarginContainer/VBoxContainer/HBoxContainer/Names"]
margin_top = 44.0
margin_right = 82.0
margin_bottom = 58.0
text = "Value"
align = 2
[node name="Sliders" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer"]
margin_left = 92.0
margin_right = 368.0
margin_bottom = 84.0
size_flags_horizontal = 3
size_flags_stretch_ratio = 3.0
custom_constants/separation = 7
[node name="Hue" type="HSlider" parent="MarginContainer/VBoxContainer/HBoxContainer/Sliders"]
margin_right = 276.0
margin_bottom = 16.0
mouse_default_cursor_shape = 2
min_value = -180.0
max_value = 180.0
[node name="Saturation" type="HSlider" parent="MarginContainer/VBoxContainer/HBoxContainer/Sliders"]
margin_top = 23.0
margin_right = 276.0
margin_bottom = 39.0
mouse_default_cursor_shape = 2
min_value = -100.0
[node name="Value" type="HSlider" parent="MarginContainer/VBoxContainer/HBoxContainer/Sliders"]
margin_top = 46.0
margin_right = 276.0
margin_bottom = 62.0
mouse_default_cursor_shape = 2
min_value = -100.0
[node name="TextBoxes" type="VBoxContainer" parent="MarginContainer/VBoxContainer/HBoxContainer"]
margin_left = 378.0
margin_right = 452.0
margin_bottom = 84.0
size_flags_horizontal = 3
size_flags_stretch_ratio = 0.0
custom_constants/separation = 6
[node name="Hue" type="SpinBox" parent="MarginContainer/VBoxContainer/HBoxContainer/TextBoxes"]
margin_right = 74.0
margin_bottom = 24.0
mouse_default_cursor_shape = 1
min_value = -180.0
max_value = 180.0
[node name="Saturation" type="SpinBox" parent="MarginContainer/VBoxContainer/HBoxContainer/TextBoxes"]
margin_top = 30.0
margin_right = 74.0
margin_bottom = 54.0
mouse_default_cursor_shape = 1
min_value = -100.0
[node name="Value" type="SpinBox" parent="MarginContainer/VBoxContainer/HBoxContainer/TextBoxes"]
margin_top = 60.0
margin_right = 74.0
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, false, 2, null, "All projects", null, false, 3, null ]
selected = 0
[node name="HBoxContainer2" type="HBoxContainer" parent="MarginContainer/VBoxContainer"]
margin_top = 289.0
margin_right = 453.0
margin_bottom = 309.0
custom_constants/separation = 16
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Apply" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
margin_right = 218.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
text = "Apply"
[node name="Cancel" type="Button" parent="MarginContainer/VBoxContainer/HBoxContainer2"]
margin_left = 234.0
margin_right = 453.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
text = "Cancel"
[connection signal="about_to_show" from="." to="." method="_on_HSVDialog_about_to_show"]
[connection signal="popup_hide" from="." to="." method="_on_HSVDialog_popup_hide"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/HBoxContainer/Sliders/Hue" to="." method="_on_Hue_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/HBoxContainer/Sliders/Saturation" to="." method="_on_Saturation_value_changed"]
[connection signal="value_changed" from="MarginContainer/VBoxContainer/HBoxContainer/Sliders/Value" to="." method="_on_Value_value_changed"]
[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"]

View file

@ -0,0 +1,39 @@
[gd_scene load_steps=8 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn" type="PackedScene" id=8]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/RotateImage.tscn" type="PackedScene" id=9]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ShaderEffect.tscn" type="PackedScene" id=10]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/HSVDialog.tscn" type="PackedScene" id=11]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/GradientDialog.tscn" type="PackedScene" id=12]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/OutlineDialog.tscn" type="PackedScene" id=13]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ScaleImage.tscn" type="PackedScene" id=14]
[node name="ImageEffects" type="Control"]
mouse_filter = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ScaleImage" parent="." instance=ExtResource( 14 )]
margin_bottom = 127.0
[node name="ResizeCanvas" parent="." instance=ExtResource( 8 )]
margin_right = 216.0
margin_bottom = 392.0
[node name="RotateImage" parent="." instance=ExtResource( 9 )]
[node name="OutlineDialog" parent="." instance=ExtResource( 13 )]
margin_right = 217.0
margin_bottom = 106.0
[node name="HSVDialog" parent="." instance=ExtResource( 11 )]
[node name="GradientDialog" parent="." instance=ExtResource( 12 )]
margin_bottom = 214.0
[node name="ShaderEffect" parent="." instance=ExtResource( 10 )]

View file

@ -0,0 +1,114 @@
extends ConfirmationDialog
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
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 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:
if affect == CEL:
Global.canvas.handle_undo("Draw")
DrawingAlgos.generate_outline(current_cel, pixels, color, thickness, diagonal, inside_image)
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.generate_outline(cel.image, pixels, color, thickness, diagonal, inside_image)
Global.canvas.handle_redo("Draw", Global.current_project, -1)
elif affect == ALL_FRAMES:
Global.canvas.handle_undo("Draw", Global.current_project, -1, -1)
for frame in Global.current_project.frames:
for cel in frame.cels:
DrawingAlgos.generate_outline(cel.image, pixels, color, thickness, diagonal, inside_image)
Global.canvas.handle_redo("Draw", Global.current_project, -1, -1)
elif affect == ALL_PROJECTS:
for project in Global.projects:
var _pixels := []
if selection_checkbox.pressed:
_pixels = project.selected_pixels.duplicate()
else:
for x in project.size.x:
for y in project.size.y:
_pixels.append(Vector2(x, y))
Global.canvas.handle_undo("Draw", project, -1, -1)
for frame in project.frames:
for cel in frame.cels:
DrawingAlgos.generate_outline(cel.image, _pixels, color, thickness, diagonal, inside_image)
Global.canvas.handle_redo("Draw", project, -1, -1)
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_ThickValue_value_changed(value : int) -> void:
thickness = value
update_preview()
func _on_OutlineColor_color_changed(_color : Color) -> void:
color = _color
update_preview()
func _on_DiagonalCheckBox_toggled(button_pressed : bool) -> void:
diagonal = button_pressed
update_preview()
func _on_InsideImageCheckBox_toggled(button_pressed : bool) -> void:
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
func _on_AffectOptionButton_item_selected(index : int) -> void:
affect = index
func _on_OutlineDialog_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -0,0 +1,108 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/OutlineDialog.gd" type="Script" id=1]
[node name="OutlineDialog" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 70.0
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[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
margin_bottom = 200.0
rect_min_size = Vector2( 200, 200 )
expand = true
stretch_mode = 6
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"]
margin_top = 204.0
margin_right = 312.0
margin_bottom = 308.0
custom_constants/vseparation = 4
custom_constants/hseparation = 4
columns = 2
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ThickLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 5.0
margin_right = 160.0
margin_bottom = 19.0
text = "Thickness:"
[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
max_value = 16384.0
value = 1.0
suffix = "px"
[node name="OutlineColorLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 31.0
margin_right = 160.0
margin_bottom = 45.0
text = "Fill with color:"
[node name="OutlineColor" type="ColorPickerButton" parent="VBoxContainer/OptionsContainer"]
margin_left = 164.0
margin_top = 28.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="VBoxContainer/OptionsContainer"]
margin_top = 52.0
margin_right = 160.0
margin_bottom = 76.0
mouse_default_cursor_shape = 2
text = "Diagonal"
[node name="InsideImageCheckBox" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 164.0
margin_top = 52.0
margin_right = 312.0
margin_bottom = 76.0
mouse_default_cursor_shape = 2
text = "Place inside image"
[node name="SelectionCheckBox" type="CheckBox" parent="VBoxContainer/OptionsContainer"]
margin_top = 80.0
margin_right = 160.0
margin_bottom = 104.0
mouse_default_cursor_shape = 2
pressed = true
text = "Only affect selection"
[node name="AffectOptionButton" type="OptionButton" parent="VBoxContainer/OptionsContainer"]
margin_right = 29.0
margin_bottom = 20.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, false, 2, null, "All projects", null, false, 3, null ]
selected = 0
[connection signal="about_to_show" from="." to="." method="_on_OutlineDialog_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_OutlineDialog_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_OutlineDialog_popup_hide"]
[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"]
[connection signal="item_selected" from="VBoxContainer/OptionsContainer/AffectOptionButton" to="." method="_on_AffectOptionButton_item_selected"]

View file

@ -0,0 +1,107 @@
extends ConfirmationDialog
var width := 64
var height := 64
var offset_x := 0
var offset_y := 0
var image : Image
var first_time := true
onready var width_spinbox : SpinBox = $VBoxContainer/OptionsContainer/WidthValue
onready var height_spinbox : SpinBox = $VBoxContainer/OptionsContainer/HeightValue
onready var x_spinbox : SpinBox = $VBoxContainer/OptionsContainer/XSpinBox
onready var y_spinbox : SpinBox = $VBoxContainer/OptionsContainer/YSpinBox
onready var preview_rect : TextureRect = $VBoxContainer/Preview
func _on_ResizeCanvas_about_to_show() -> void:
if first_time:
width_spinbox.value = Global.current_project.size.x
height_spinbox.value = Global.current_project.size.y
image = Image.new()
image.create(Global.current_project.size.x, Global.current_project.size.y, false, Image.FORMAT_RGBA8)
image.lock()
var layer_i := 0
for cel in Global.current_project.frames[Global.current_project.current_frame].cels:
if Global.current_project.layers[layer_i].visible:
var cel_image := Image.new()
cel_image.copy_from(cel.image)
cel_image.lock()
if cel.opacity < 1: # If we have cel transparency
for xx in cel_image.get_size().x:
for yy in cel_image.get_size().y:
var pixel_color := cel_image.get_pixel(xx, yy)
var alpha : float = pixel_color.a * cel.opacity
cel_image.set_pixel(xx, yy, Color(pixel_color.r, pixel_color.g, pixel_color.b, alpha))
image.blend_rect(cel_image, Rect2(Global.canvas.location, Global.current_project.size), Vector2.ZERO)
layer_i += 1
image.unlock()
preview_rect.get_node("TransparentChecker").rect_size = preview_rect.rect_size
update_preview()
func _on_ResizeCanvas_confirmed() -> void:
DrawingAlgos.resize_canvas(width, height, offset_x, offset_y)
first_time = false
func _on_WidthValue_value_changed(value : int) -> void:
width = value
x_spinbox.min_value = min(width - Global.current_project.size.x, 0)
x_spinbox.max_value = max(width - Global.current_project.size.x, 0)
x_spinbox.value = clamp(x_spinbox.value, x_spinbox.min_value, x_spinbox.max_value)
update_preview()
func _on_HeightValue_value_changed(value : int) -> void:
height = value
y_spinbox.min_value = min(height - Global.current_project.size.y, 0)
y_spinbox.max_value = max(height - Global.current_project.size.y, 0)
y_spinbox.value = clamp(y_spinbox.value, y_spinbox.min_value, y_spinbox.max_value)
update_preview()
func _on_XSpinBox_value_changed(value : int) -> void:
offset_x = value
update_preview()
func _on_YSpinBox_value_changed(value : int) -> void:
offset_y = value
update_preview()
func _on_CenterButton_pressed() -> void:
x_spinbox.value = (x_spinbox.min_value + x_spinbox.max_value) / 2
y_spinbox.value = (y_spinbox.min_value + y_spinbox.max_value) / 2
func update_preview() -> void:
var preview_image := Image.new()
preview_image.create(width, height, false, Image.FORMAT_RGBA8)
preview_image.blend_rect(image, Rect2(Vector2.ZERO, Global.current_project.size), Vector2(offset_x, offset_y))
var preview_texture := ImageTexture.new()
preview_texture.create_from_image(preview_image, 0)
preview_rect.texture = preview_texture
update_transparent_background_size(preview_image)
func update_transparent_background_size(preview_image : Image) -> void:
var image_size_y = preview_rect.rect_size.y
var image_size_x = preview_rect.rect_size.x
if preview_image.get_size().x > preview_image.get_size().y:
var scale_ratio = preview_image.get_size().x / image_size_x
image_size_y = preview_image.get_size().y / scale_ratio
else:
var scale_ratio = preview_image.get_size().y / image_size_y
image_size_x = preview_image.get_size().x / scale_ratio
preview_rect.get_node("TransparentChecker").rect_size.x = image_size_x
preview_rect.get_node("TransparentChecker").rect_size.y = image_size_y
func _on_ResizeCanvas_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -0,0 +1,134 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/UI/TransparentChecker.tscn" type="PackedScene" id=1]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ResizeCanvas.gd" type="Script" id=2]
[node name="ResizeCanvas" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 114.0
resizable = true
script = ExtResource( 2 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 208.0
margin_bottom = 380.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="ImageSize" type="Label" parent="VBoxContainer"]
margin_right = 200.0
margin_bottom = 14.0
text = "Canvas Size"
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"]
margin_top = 18.0
margin_right = 200.0
margin_bottom = 168.0
custom_constants/vseparation = 4
custom_constants/hseparation = 2
columns = 2
[node name="WidthLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 5.0
margin_right = 54.0
margin_bottom = 19.0
text = "Width:"
[node name="WidthValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 56.0
margin_right = 130.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0
max_value = 16384.0
value = 64.0
suffix = "px"
[node name="Height" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 33.0
margin_right = 54.0
margin_bottom = 47.0
text = "Height:"
[node name="HeightValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 56.0
margin_top = 28.0
margin_right = 130.0
margin_bottom = 52.0
mouse_default_cursor_shape = 2
min_value = 1.0
max_value = 16384.0
value = 64.0
suffix = "px"
[node name="OffsetLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 56.0
margin_right = 54.0
margin_bottom = 70.0
text = "Offset"
[node name="EmptySpacer" type="Control" parent="VBoxContainer/OptionsContainer"]
margin_left = 56.0
margin_top = 56.0
margin_right = 130.0
margin_bottom = 70.0
[node name="XLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 79.0
margin_right = 54.0
margin_bottom = 93.0
text = "X:"
[node name="XSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 56.0
margin_top = 74.0
margin_right = 130.0
margin_bottom = 98.0
mouse_default_cursor_shape = 2
max_value = 0.0
suffix = "px"
[node name="YLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 107.0
margin_right = 54.0
margin_bottom = 121.0
text = "Y:"
[node name="YSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 56.0
margin_top = 102.0
margin_right = 130.0
margin_bottom = 126.0
mouse_default_cursor_shape = 2
max_value = 0.0
suffix = "px"
[node name="CenterButton" type="Button" parent="VBoxContainer/OptionsContainer"]
margin_top = 130.0
margin_right = 54.0
margin_bottom = 150.0
text = "Center"
[node name="Preview" type="TextureRect" parent="VBoxContainer"]
margin_top = 172.0
margin_right = 200.0
margin_bottom = 372.0
rect_min_size = Vector2( 200, 200 )
size_flags_horizontal = 0
size_flags_vertical = 0
expand = true
stretch_mode = 5
[node name="TransparentChecker" parent="VBoxContainer/Preview" instance=ExtResource( 1 )]
show_behind_parent = true
[connection signal="about_to_show" from="." to="." method="_on_ResizeCanvas_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_ResizeCanvas_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_ResizeCanvas_popup_hide"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/WidthValue" to="." method="_on_WidthValue_value_changed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/HeightValue" to="." method="_on_HeightValue_value_changed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/XSpinBox" to="." method="_on_XSpinBox_value_changed"]
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/YSpinBox" to="." method="_on_YSpinBox_value_changed"]
[connection signal="pressed" from="VBoxContainer/OptionsContainer/CenterButton" to="." method="_on_CenterButton_pressed"]

View file

@ -0,0 +1,64 @@
extends ConfirmationDialog
var texture : ImageTexture
var aux_img : Image
var layer : Image
func _ready() -> void:
texture = ImageTexture.new()
aux_img = Image.new()
$VBoxContainer/HBoxContainer2/OptionButton.add_item("Rotxel")
$VBoxContainer/HBoxContainer2/OptionButton.add_item("Upscale, Rotate and Downscale")
$VBoxContainer/HBoxContainer2/OptionButton.add_item("Nearest neighbour")
func set_sprite(sprite : Image) -> void:
aux_img.copy_from(sprite)
layer = sprite
texture.create_from_image(aux_img, 0)
$VBoxContainer/TextureRect.texture = texture
func _on_HSlider_value_changed(_value) -> void:
rotate()
$VBoxContainer/HBoxContainer/SpinBox.value = $VBoxContainer/HBoxContainer/HSlider.value
func _on_SpinBox_value_changed(_value):
$VBoxContainer/HBoxContainer/HSlider.value = $VBoxContainer/HBoxContainer/SpinBox.value
func _on_RotateImage_confirmed() -> void:
Global.canvas.handle_undo("Draw")
match $VBoxContainer/HBoxContainer2/OptionButton.text:
"Rotxel":
DrawingAlgos.rotxel(layer,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
"Nearest neighbour":
DrawingAlgos.nn_rotate(layer,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
"Upscale, Rotate and Downscale":
DrawingAlgos.fake_rotsprite(layer,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
Global.canvas.handle_redo("Draw")
$VBoxContainer/HBoxContainer/HSlider.value = 0
func rotate() -> void:
var sprite : Image = Image.new()
sprite.copy_from(aux_img)
match $VBoxContainer/HBoxContainer2/OptionButton.text:
"Rotxel":
DrawingAlgos.rotxel(sprite,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
"Nearest neighbour":
DrawingAlgos.nn_rotate(sprite,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
"Upscale, Rotate and Downscale":
DrawingAlgos.fake_rotsprite(sprite,$VBoxContainer/HBoxContainer/HSlider.value*PI/180)
texture.create_from_image(sprite, 0)
func _on_OptionButton_item_selected(_id) -> void:
rotate()
func _on_RotateImage_about_to_show() -> void:
$VBoxContainer/HBoxContainer/HSlider.value = 0
func _on_RotateImage_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -0,0 +1,86 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/RotateImage.gd" type="Script" id=1]
[node name="RotateImage" type="ConfirmationDialog"]
margin_right = 245.0
margin_bottom = 241.0
resizable = true
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = -36.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="TextureRect" type="TextureRect" parent="VBoxContainer"]
margin_right = 229.0
margin_bottom = 145.0
size_flags_vertical = 3
expand = true
stretch_mode = 6
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 149.0
margin_right = 229.0
margin_bottom = 169.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer2"]
margin_top = 3.0
margin_right = 34.0
margin_bottom = 17.0
text = "Type:"
[node name="OptionButton" type="OptionButton" parent="VBoxContainer/HBoxContainer2"]
margin_left = 38.0
margin_right = 229.0
margin_bottom = 20.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
size_flags_vertical = 3
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer"]
margin_top = 173.0
margin_right = 229.0
margin_bottom = 197.0
[node name="Label" type="Label" parent="VBoxContainer/HBoxContainer"]
margin_top = 5.0
margin_right = 44.0
margin_bottom = 19.0
text = "Angle:"
[node name="HSlider" type="HSlider" parent="VBoxContainer/HBoxContainer"]
margin_left = 48.0
margin_right = 151.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
size_flags_horizontal = 3
size_flags_vertical = 3
max_value = 359.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="SpinBox" type="SpinBox" parent="VBoxContainer/HBoxContainer"]
margin_left = 155.0
margin_right = 229.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
max_value = 359.0
suffix = "°"
[connection signal="about_to_show" from="." to="." method="_on_RotateImage_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_RotateImage_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_RotateImage_popup_hide"]
[connection signal="item_selected" from="VBoxContainer/HBoxContainer2/OptionButton" to="." method="_on_OptionButton_item_selected"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/HSlider" to="." method="_on_HSlider_value_changed"]
[connection signal="value_changed" from="VBoxContainer/HBoxContainer/SpinBox" to="." method="_on_SpinBox_value_changed"]

View file

@ -0,0 +1,12 @@
extends ConfirmationDialog
func _on_ScaleImage_confirmed() -> void:
var width : int = $VBoxContainer/OptionsContainer/WidthValue.value
var height : int = $VBoxContainer/OptionsContainer/HeightValue.value
var interpolation : int = $VBoxContainer/OptionsContainer/InterpolationType.selected
DrawingAlgos.scale_image(width, height, interpolation)
func _on_ScaleImage_popup_hide() -> void:
Global.dialog_open(false)

View file

@ -0,0 +1,77 @@
[gd_scene load_steps=2 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ScaleImage.gd" type="Script" id=1]
[node name="ScaleImage" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 114.0
script = ExtResource( 1 )
[node name="VBoxContainer" type="VBoxContainer" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 192.0
margin_bottom = 102.0
[node name="ImageSize" type="Label" parent="VBoxContainer"]
margin_right = 184.0
margin_bottom = 14.0
text = "Image Size"
[node name="OptionsContainer" type="GridContainer" parent="VBoxContainer"]
margin_top = 18.0
margin_right = 184.0
margin_bottom = 94.0
custom_constants/vseparation = 4
custom_constants/hseparation = 2
columns = 2
[node name="WidthLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 5.0
margin_right = 87.0
margin_bottom = 19.0
text = "Width:"
[node name="WidthValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 89.0
margin_right = 168.0
margin_bottom = 24.0
mouse_default_cursor_shape = 2
min_value = 1.0
max_value = 16384.0
value = 64.0
suffix = "px"
[node name="Height" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 33.0
margin_right = 87.0
margin_bottom = 47.0
text = "Height:"
[node name="HeightValue" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
margin_left = 89.0
margin_top = 28.0
margin_right = 168.0
margin_bottom = 52.0
mouse_default_cursor_shape = 2
min_value = 1.0
max_value = 16384.0
value = 64.0
suffix = "px"
[node name="InterpolationLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
margin_top = 59.0
margin_right = 87.0
margin_bottom = 73.0
text = "Interpolation:"
[node name="InterpolationType" type="OptionButton" parent="VBoxContainer/OptionsContainer"]
margin_left = 89.0
margin_top = 56.0
margin_right = 168.0
margin_bottom = 76.0
text = "Nearest"
items = [ "Nearest", null, false, 0, null, "Bilinear", null, false, 1, null, "Cubic", null, false, 2, null, "Trilinear", null, false, 3, null, "Lanczos", null, false, 4, null ]
selected = 0
[connection signal="confirmed" from="." to="." method="_on_ScaleImage_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_ScaleImage_popup_hide"]

View file

@ -0,0 +1,117 @@
extends ConfirmationDialog
var current_cel : Image
onready var viewport : Viewport = $VBoxContainer/ViewportContainer/Viewport
onready var preview : TextureRect = viewport.get_node("Preview")
onready var shader_loaded_label : Label = $VBoxContainer/ShaderLoadedLabel
onready var shader_params : BoxContainer = $VBoxContainer/ShaderParams
func _on_ShaderEffect_about_to_show() -> void:
current_cel = Global.current_project.frames[Global.current_project.current_frame].cels[Global.current_project.current_layer].image
current_cel.unlock()
viewport.size = Global.current_project.size
# var viewport_texture = viewport.get_texture().get_data()
# viewport_texture.convert(Image.FORMAT_RGBA8)
var preview_image := Image.new()
preview_image.copy_from(current_cel)
var preview_texture = ImageTexture.new()
preview_texture.create_from_image(preview_image, 0)
preview.texture = preview_texture
func _on_ShaderEffect_confirmed() -> void:
var viewport_texture := Image.new()
viewport_texture.copy_from(viewport.get_texture().get_data())
var viewport_texture_size = viewport_texture.get_size()
if viewport_texture_size == Vector2.ZERO:
return
viewport_texture.flip_y()
viewport_texture.convert(Image.FORMAT_RGBA8)
print(viewport_texture.get_size())
Global.canvas.handle_undo("Draw")
current_cel.copy_from(viewport_texture)
Global.canvas.handle_redo("Draw")
func _on_ShaderEffect_popup_hide() -> void:
current_cel.lock()
Global.dialog_open(false)
yield(get_tree().create_timer(0.2), "timeout")
preview.texture = null
viewport.size = Vector2.ONE
rect_size = Vector2.ONE
func _on_ChooseShader_pressed() -> void:
if OS.get_name() == "HTML5":
Html5FileExchange.load_shader()
else:
$FileDialog.popup_centered(Vector2(300, 340))
func _on_FileDialog_file_selected(path : String) -> void:
var shader = load(path)
if !shader is Shader:
return
change_shader(shader, path.get_file().get_basename())
func change_shader(shader : Shader, name : String) -> void:
preview.material.shader = shader
shader_loaded_label.text = tr("Shader loaded:") + " " + name
for child in shader_params.get_children():
child.queue_free()
var code = shader.code.split("\n")
var uniforms := []
for line in code:
if line.begins_with("uniform"):
uniforms.append(line)
for uniform in uniforms:
# Example uniform:
# uniform float parameter_name : hint_range(0, 255) = 100.0;
var uniform_split = uniform.split("=")
var u_value := ""
if uniform_split.size() > 1:
u_value = uniform_split[1].replace(";", "").strip_edges()
var u_left_side = uniform_split[0].split(":")
var _u_hint := ""
if u_left_side.size() > 1:
_u_hint = u_left_side[1].strip_edges()
var u_init = u_left_side[0].split(" ")
var u_type = u_init[1]
var u_name = u_init[2]
if u_type == "float":
var label := Label.new()
label.text = u_name
var spinbox := SpinBox.new()
spinbox.min_value = 0.01
spinbox.max_value = 255
spinbox.step = 0.01
if u_value != "":
spinbox.value = float(u_value)
spinbox.connect("value_changed", self, "set_shader_param", [u_name])
var hbox := HBoxContainer.new()
hbox.add_child(label)
hbox.add_child(spinbox)
shader_params.add_child(hbox)
# print("---")
# print(uniform_split)
# print(u_type)
# print(u_name)
# print(u_hint)
# print(u_value)
# print("--")
func set_shader_param(value, param : String) -> void:
preview.material.set_shader_param(param, value)

View file

@ -0,0 +1,90 @@
[gd_scene load_steps=3 format=2]
[ext_resource path="res://src/UI/Dialogs/ImageEffects/ShaderEffect.gd" type="Script" id=1]
[sub_resource type="ShaderMaterial" id=1]
[node name="ShaderEffect" type="ConfirmationDialog"]
margin_right = 200.0
margin_bottom = 228.0
rect_min_size = Vector2( 400, 300 )
resizable = true
script = ExtResource( 1 )
__meta__ = {
"_edit_use_anchors_": false
}
[node name="VBoxContainer" type="VBoxContainer" parent="."]
anchor_right = 1.0
anchor_bottom = 1.0
margin_left = 8.0
margin_top = 8.0
margin_right = -8.0
margin_bottom = -36.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Label" type="Label" parent="VBoxContainer"]
margin_right = 384.0
margin_bottom = 31.0
text = "This is an experimental feature and may not be included in the stable version"
autowrap = true
[node name="ViewportContainer" type="ViewportContainer" parent="VBoxContainer"]
margin_top = 35.0
margin_right = 384.0
margin_bottom = 36.0
__meta__ = {
"_edit_use_anchors_": false
}
[node name="Viewport" type="Viewport" parent="VBoxContainer/ViewportContainer"]
size = Vector2( 1, 1 )
transparent_bg = true
handle_input_locally = false
disable_3d = true
usage = 0
render_target_update_mode = 0
gui_disable_input = true
[node name="Preview" type="TextureRect" parent="VBoxContainer/ViewportContainer/Viewport"]
material = SubResource( 1 )
anchor_right = 1.0
anchor_bottom = 1.0
[node name="ChooseShader" type="Button" parent="VBoxContainer"]
margin_top = 40.0
margin_right = 384.0
margin_bottom = 60.0
mouse_default_cursor_shape = 2
text = "Choose Shader"
[node name="ShaderLoadedLabel" type="Label" parent="VBoxContainer"]
margin_top = 64.0
margin_right = 384.0
margin_bottom = 78.0
text = "No shader loaded!"
autowrap = true
[node name="ShaderParams" type="VBoxContainer" parent="VBoxContainer"]
margin_right = 40.0
margin_bottom = 40.0
[node name="FileDialog" type="FileDialog" parent="."]
margin_left = 8.0
margin_top = 8.0
margin_right = 392.0
margin_bottom = 264.0
window_title = "Open a File"
resizable = true
mode = 0
access = 2
filters = PoolStringArray( "*shader" )
current_dir = "/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama"
current_path = "/Users/Overloaded/Dropbox/Orama Founding Members/εταιρικα αρχεια/Godot Projects/Pixelorama/"
[connection signal="about_to_show" from="." to="." method="_on_ShaderEffect_about_to_show"]
[connection signal="confirmed" from="." to="." method="_on_ShaderEffect_confirmed"]
[connection signal="popup_hide" from="." to="." method="_on_ShaderEffect_popup_hide"]
[connection signal="pressed" from="VBoxContainer/ChooseShader" to="." method="_on_ChooseShader_pressed"]
[connection signal="file_selected" from="FileDialog" to="." method="_on_FileDialog_file_selected"]