From 81c0b49c59be5377fd0b2c4e21f9a2c3095897fb Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Tue, 4 Jul 2023 00:20:55 +0300 Subject: [PATCH] Add animatable properties to the Gradient effect --- src/UI/Dialogs/ImageEffects/GradientDialog.gd | 33 ++++++++++++++----- .../Dialogs/ImageEffects/GradientDialog.tscn | 11 ++----- 2 files changed, 27 insertions(+), 17 deletions(-) diff --git a/src/UI/Dialogs/ImageEffects/GradientDialog.gd b/src/UI/Dialogs/ImageEffects/GradientDialog.gd index 25ba89654..410084b8d 100644 --- a/src/UI/Dialogs/ImageEffects/GradientDialog.gd +++ b/src/UI/Dialogs/ImageEffects/GradientDialog.gd @@ -1,6 +1,7 @@ extends ImageEffect enum { LINEAR, RADIAL, LINEAR_DITHERING, RADIAL_DITHERING } +enum Animate { POSITION, SIZE, ANGLE, CENTER_X, CENTER_Y, RADIUS_X, RADIUS_Y } var shader_linear: Shader = preload("res://src/Shaders/Gradients/Linear.gdshader") var shader_linear_dither: Shader = preload("res://src/Shaders/Gradients/LinearDithering.gdshader") @@ -17,12 +18,11 @@ var selected_dither_matrix: DitherMatrix = dither_matrices[0] onready var options_cont: Container = $VBoxContainer/GradientOptions onready var gradient_edit: GradientEditNode = $VBoxContainer/GradientEdit onready var shape_option_button: OptionButton = $"%ShapeOptionButton" -onready var dithering_label: Label = $"%DitheringLabel" onready var dithering_option_button: OptionButton = $"%DitheringOptionButton" onready var repeat_option_button: OptionButton = $"%RepeatOptionButton" -onready var position: ValueSlider = $"%PositionSlider" +onready var position_slider: ValueSlider = $"%PositionSlider" onready var size_slider: ValueSlider = $"%SizeSlider" -onready var angle: ValueSlider = $"%AngleSlider" +onready var angle_slider: ValueSlider = $"%AngleSlider" onready var center_slider := $"%CenterSlider" as ValueSliderV2 onready var radius_slider := $"%RadiusSlider" as ValueSliderV2 @@ -44,6 +44,15 @@ func _ready() -> void: for matrix in dither_matrices: dithering_option_button.add_item(matrix.name) + # Set as in the Animate enum + animate_panel.add_float_property("Position", position_slider) + animate_panel.add_float_property("Size", size_slider) + animate_panel.add_float_property("Angle", angle_slider) + animate_panel.add_float_property("Center X", center_slider.get_sliders()[0]) + animate_panel.add_float_property("Center Y", center_slider.get_sliders()[1]) + animate_panel.add_float_property("Radius X", radius_slider.get_sliders()[0]) + animate_panel.add_float_property("Radius Y", radius_slider.get_sliders()[1]) + func commit_action(cel: Image, project: Project = Global.current_project) -> void: var selection: Image @@ -83,16 +92,24 @@ func commit_action(cel: Image, project: Project = Global.current_project) -> voi else: gradient_tex = ImageTexture.new() gradient_tex.create_from_image(gradient_image, 0) + var center := Vector2( + animate_panel.get_animated_value(commit_idx, Animate.CENTER_X), + animate_panel.get_animated_value(commit_idx, Animate.CENTER_Y) + ) + var radius := Vector2( + animate_panel.get_animated_value(commit_idx, Animate.RADIUS_X), + animate_panel.get_animated_value(commit_idx, Animate.RADIUS_Y) + ) var params := { "gradient_texture": gradient_tex, "offset_texture": offsets_tex, "selection": selection_tex, "repeat": repeat_option_button.selected, - "position": (position.value / 100.0) - 0.5, - "size": size_slider.value / 100.0, - "angle": angle.value, - "center": center_slider.value / 100.0, - "radius": radius_slider.value, + "position": (animate_panel.get_animated_value(commit_idx, Animate.POSITION) / 100.0) - 0.5, + "size": animate_panel.get_animated_value(commit_idx, Animate.SIZE) / 100.0, + "angle": animate_panel.get_animated_value(commit_idx, Animate.ANGLE), + "center": center / 100.0, + "radius": radius, "dither_texture": dither_texture, "image_size": project.size, "pixel_size": pixel_size, diff --git a/src/UI/Dialogs/ImageEffects/GradientDialog.tscn b/src/UI/Dialogs/ImageEffects/GradientDialog.tscn index db7fd2030..08378537c 100644 --- a/src/UI/Dialogs/ImageEffects/GradientDialog.tscn +++ b/src/UI/Dialogs/ImageEffects/GradientDialog.tscn @@ -11,10 +11,7 @@ window_title = "Gradient" script = ExtResource( 1 ) [node name="VBoxContainer" parent="." index="3"] -margin_bottom = 468.0 - -[node name="ShowAnimate" parent="VBoxContainer" index="0"] -visible = false +margin_bottom = 444.0 [node name="AspectRatioContainer" parent="VBoxContainer" index="1"] margin_bottom = 224.0 @@ -56,7 +53,6 @@ items = [ "Linear", null, false, 0, null, "Radial", null, false, 1, null ] selected = 0 [node name="DitheringLabel" type="Label" parent="VBoxContainer/GradientOptions" index="2" groups=["gradient_common"]] -unique_name_in_owner = true margin_top = 27.0 margin_right = 178.0 margin_bottom = 41.0 @@ -208,11 +204,8 @@ show_ratio = true margin_top = 436.0 margin_bottom = 460.0 -[node name="AffectOptionButton" parent="VBoxContainer/OptionsContainer" index="1"] -items = [ "Selected cels", null, false, 0, null, "Current frame", null, false, 1, null, "All frames", null, false, 2, null, "All projects", null, false, 3, null ] - [node name="AnimateDialog" parent="." index="4"] -margin_bottom = 468.0 +margin_bottom = 444.0 [connection signal="updated" from="VBoxContainer/GradientEdit" to="." method="_on_GradientEdit_updated"] [connection signal="item_selected" from="VBoxContainer/GradientOptions/ShapeOptionButton" to="." method="_on_ShapeOptionButton_item_selected"]