From 72a7b277fb622e319e489e0ef3cd6a672f8ead65 Mon Sep 17 00:00:00 2001 From: Emmanouil Papadeas Date: Wed, 19 Apr 2023 03:44:28 +0300 Subject: [PATCH] Use a ValueSliderV2 in the gradient dialog, and reverse the radius logic The larger the radius value, the larger the circle, as it should be --- src/Shaders/Gradients/Linear.gdshader | 2 +- .../Gradients/LinearDithering.gdshader | 2 +- src/UI/Dialogs/ImageEffects/GradientDialog.gd | 14 +- .../Dialogs/ImageEffects/GradientDialog.tscn | 130 +++++------------- 4 files changed, 41 insertions(+), 107 deletions(-) diff --git a/src/Shaders/Gradients/Linear.gdshader b/src/Shaders/Gradients/Linear.gdshader index 41314dea1..6a72c2aeb 100644 --- a/src/Shaders/Gradients/Linear.gdshader +++ b/src/Shaders/Gradients/Linear.gdshader @@ -27,7 +27,7 @@ float modify_uv(vec2 uv) { else { // Radial vec2 uv_offsetted = uv * 2.0 - 1.0; uv_offsetted -= (center * 2.0) - vec2(1.0); - uv_offsetted *= radius; + uv_offsetted /= radius; modified_uv = length(uv_offsetted); } return modified_uv; diff --git a/src/Shaders/Gradients/LinearDithering.gdshader b/src/Shaders/Gradients/LinearDithering.gdshader index af5e37179..02d4ed263 100644 --- a/src/Shaders/Gradients/LinearDithering.gdshader +++ b/src/Shaders/Gradients/LinearDithering.gdshader @@ -32,7 +32,7 @@ float modify_uv(vec2 uv) { else { // Radial vec2 uv_offsetted = uv * 2.0 - 1.0; uv_offsetted -= (center * 2.0) - vec2(1.0); - uv_offsetted *= radius; + uv_offsetted /= radius; modified_uv = length(uv_offsetted); } return modified_uv; diff --git a/src/UI/Dialogs/ImageEffects/GradientDialog.gd b/src/UI/Dialogs/ImageEffects/GradientDialog.gd index 194d7ccd7..bf2deb578 100644 --- a/src/UI/Dialogs/ImageEffects/GradientDialog.gd +++ b/src/UI/Dialogs/ImageEffects/GradientDialog.gd @@ -23,10 +23,8 @@ onready var repeat_option_button: OptionButton = $"%RepeatOptionButton" onready var position: ValueSlider = $"%PositionSlider" onready var size_slider: ValueSlider = $"%SizeSlider" onready var angle: ValueSlider = $"%AngleSlider" -onready var center_x: ValueSlider = $"%XCenterSlider" -onready var center_y: ValueSlider = $"%YCenterSlider" -onready var radius_x: ValueSlider = $"%XRadiusSlider" -onready var radius_y: ValueSlider = $"%YRadiusSlider" +onready var center_slider := $"%CenterSlider" as ValueSliderV2 +onready var radius_slider := $"%RadiusSlider" as ValueSliderV2 class DitherMatrix: @@ -99,8 +97,8 @@ func commit_action(cel: Image, project: Project = Global.current_project) -> voi "position": (position.value / 100.0) - 0.5, "size": size_slider.value / 100.0, "angle": angle.value, - "center": Vector2(center_x.value / 100.0, center_y.value / 100.0), - "radius": Vector2(radius_x.value, radius_y.value), + "center": center_slider.value / 100.0, + "radius": radius_slider.value, "dither_texture": dither_texture, "image_size": project.size, "pixel_size": pixel_size, @@ -135,6 +133,10 @@ func _value_changed(_value: float) -> void: update_preview() +func _value_v2_changed(_value: Vector2) -> void: + update_preview() + + func _on_DitheringOptionButton_item_selected(index: int) -> void: if index > 0: shader = shader_linear_dither diff --git a/src/UI/Dialogs/ImageEffects/GradientDialog.tscn b/src/UI/Dialogs/ImageEffects/GradientDialog.tscn index ee0de4639..a75b52f0b 100644 --- a/src/UI/Dialogs/ImageEffects/GradientDialog.tscn +++ b/src/UI/Dialogs/ImageEffects/GradientDialog.tscn @@ -1,16 +1,17 @@ -[gd_scene load_steps=5 format=2] +[gd_scene load_steps=6 format=2] [ext_resource path="res://src/UI/Dialogs/ImageEffects/GradientDialog.gd" type="Script" id=1] [ext_resource path="res://src/UI/Dialogs/ImageEffects/ImageEffectParent.tscn" type="PackedScene" id=2] [ext_resource path="res://src/UI/Nodes/GradientEdit.tscn" type="PackedScene" id=3] [ext_resource path="res://src/UI/Nodes/ValueSlider.gd" type="Script" id=4] +[ext_resource path="res://src/UI/Nodes/ValueSliderV2.tscn" type="PackedScene" id=5] [node name="GradientDialog" instance=ExtResource( 2 )] window_title = "Gradient" script = ExtResource( 1 ) [node name="VBoxContainer" parent="." index="3"] -margin_bottom = 468.0 +margin_bottom = 444.0 [node name="AspectRatioContainer" parent="VBoxContainer" index="0"] margin_right = 278.0 @@ -85,13 +86,13 @@ text = "None" items = [ "None", null, false, 0, null, "Repeat", null, false, 1, null, "Mirror", null, false, 2, null, "Truncate", null, false, 3, null ] selected = 0 -[node name="PositionLabel" type="Label" parent="VBoxContainer/GradientOptions" index="6" groups=["gradient_dithering", "gradient_linear", "gradient_step"]] +[node name="PositionLabel" type="Label" parent="VBoxContainer/GradientOptions" index="6" groups=["gradient_linear"]] margin_top = 72.0 margin_right = 137.0 margin_bottom = 86.0 text = "Position:" -[node name="PositionSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions" index="7" groups=["gradient_dithering", "gradient_linear"]] +[node name="PositionSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions" index="7" groups=["gradient_linear"]] unique_name_in_owner = true margin_left = 141.0 margin_top = 72.0 @@ -109,14 +110,15 @@ stretch_margin_right = 3 stretch_margin_bottom = 3 script = ExtResource( 4 ) suffix = "%" +snap_step = 10.0 -[node name="SizeLabel" type="Label" parent="VBoxContainer/GradientOptions" index="8" groups=["gradient_dithering", "gradient_linear", "gradient_step"]] +[node name="SizeLabel" type="Label" parent="VBoxContainer/GradientOptions" index="8" groups=["gradient_linear"]] margin_top = 90.0 margin_right = 137.0 margin_bottom = 104.0 text = "Size:" -[node name="SizeSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions" index="9" groups=["gradient_dithering", "gradient_linear"]] +[node name="SizeSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions" index="9" groups=["gradient_linear"]] unique_name_in_owner = true margin_left = 141.0 margin_top = 90.0 @@ -135,14 +137,15 @@ stretch_margin_right = 3 stretch_margin_bottom = 3 script = ExtResource( 4 ) suffix = "%" +snap_step = 10.0 -[node name="AngleLabel" type="Label" parent="VBoxContainer/GradientOptions" index="10" groups=["gradient_dithering", "gradient_linear", "gradient_step"]] +[node name="AngleLabel" type="Label" parent="VBoxContainer/GradientOptions" index="10" groups=["gradient_linear"]] margin_top = 108.0 margin_right = 137.0 margin_bottom = 122.0 text = "Angle:" -[node name="AngleSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions" index="11" groups=["gradient_dithering", "gradient_linear"]] +[node name="AngleSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions" index="11" groups=["gradient_linear"]] unique_name_in_owner = true margin_left = 141.0 margin_top = 108.0 @@ -158,113 +161,44 @@ stretch_margin_right = 3 stretch_margin_bottom = 3 script = ExtResource( 4 ) suffix = "°" +snap_step = 45.0 -[node name="CenterLabel" type="Label" parent="VBoxContainer/GradientOptions" index="12" groups=["gradient_radial", "gradient_radial_dithering", "gradient_radial_step"]] +[node name="CenterLabel" type="Label" parent="VBoxContainer/GradientOptions" index="12" groups=["gradient_radial"]] visible = false margin_top = 60.0 margin_right = 160.0 margin_bottom = 74.0 +size_flags_vertical = 1 text = "Center:" -[node name="CenterContainer" type="HBoxContainer" parent="VBoxContainer/GradientOptions" index="13" groups=["gradient_radial", "gradient_radial_dithering", "gradient_radial_step"]] +[node name="CenterSlider" parent="VBoxContainer/GradientOptions" index="13" groups=["gradient_radial"] instance=ExtResource( 5 )] +unique_name_in_owner = true visible = false -margin_top = 60.0 -margin_right = 154.0 -margin_bottom = 84.0 - -[node name="XCenterSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions/CenterContainer" index="0"] -unique_name_in_owner = true -margin_right = 75.0 -margin_bottom = 24.0 -mouse_default_cursor_shape = 2 -size_flags_horizontal = 3 -theme_type_variation = "ValueSlider" -value = 50.0 +value = Vector2( 50, 50 ) allow_greater = true allow_lesser = true -nine_patch_stretch = true -stretch_margin_left = 3 -stretch_margin_top = 3 -stretch_margin_right = 3 -stretch_margin_bottom = 3 -script = ExtResource( 4 ) -prefix = "X:" -suffix = "%" +snap_step = 10.0 +suffix_x = "%" +suffix_y = "%" -[node name="YCenterSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions/CenterContainer" index="1"] -unique_name_in_owner = true -margin_left = 79.0 -margin_right = 154.0 -margin_bottom = 24.0 -mouse_default_cursor_shape = 2 -size_flags_horizontal = 3 -theme_type_variation = "ValueSlider" -value = 50.0 -allow_greater = true -allow_lesser = true -nine_patch_stretch = true -stretch_margin_left = 3 -stretch_margin_top = 3 -stretch_margin_right = 3 -stretch_margin_bottom = 3 -script = ExtResource( 4 ) -prefix = "Y:" -suffix = "%" - -[node name="RadiusLabel" type="Label" parent="VBoxContainer/GradientOptions" index="14" groups=["gradient_radial", "gradient_radial_dithering", "gradient_radial_step"]] +[node name="RadiusLabel" type="Label" parent="VBoxContainer/GradientOptions" index="14" groups=["gradient_radial"]] visible = false margin_top = 193.0 margin_right = 160.0 margin_bottom = 207.0 +size_flags_vertical = 1 text = "Radius:" -[node name="RadiusContainer" type="HBoxContainer" parent="VBoxContainer/GradientOptions" index="15" groups=["gradient_radial", "gradient_radial_dithering", "gradient_radial_step"]] +[node name="RadiusSlider" parent="VBoxContainer/GradientOptions" index="15" groups=["gradient_radial"] instance=ExtResource( 5 )] +unique_name_in_owner = true visible = false -margin_top = 60.0 -margin_right = 154.0 -margin_bottom = 84.0 -size_flags_vertical = 3 - -[node name="XRadiusSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions/RadiusContainer" index="0"] -unique_name_in_owner = true -margin_right = 75.0 -margin_bottom = 24.0 -mouse_default_cursor_shape = 2 -size_flags_horizontal = 3 -theme_type_variation = "ValueSlider" -min_value = 0.01 -max_value = 10.0 +margin_right = 52.0 +value = Vector2( 1, 1 ) +min_value = Vector2( 0.01, 0.01 ) +max_value = Vector2( 10, 10 ) step = 0.01 -value = 1.0 allow_greater = true -nine_patch_stretch = true -stretch_margin_left = 3 -stretch_margin_top = 3 -stretch_margin_right = 3 -stretch_margin_bottom = 3 -script = ExtResource( 4 ) -prefix = "X:" - -[node name="YRadiusSlider" type="TextureProgress" parent="VBoxContainer/GradientOptions/RadiusContainer" index="1"] -unique_name_in_owner = true -margin_left = 79.0 -margin_right = 154.0 -margin_bottom = 24.0 -mouse_default_cursor_shape = 2 -size_flags_horizontal = 3 -theme_type_variation = "ValueSlider" -min_value = 0.01 -max_value = 10.0 -step = 0.01 -value = 1.0 -allow_greater = true -nine_patch_stretch = true -stretch_margin_left = 3 -stretch_margin_top = 3 -stretch_margin_right = 3 -stretch_margin_bottom = 3 -script = ExtResource( 4 ) -prefix = "Y:" +show_ratio = true [node name="OptionsContainer" parent="VBoxContainer" index="3"] margin_top = 412.0 @@ -298,7 +232,5 @@ margin_right = 278.0 [connection signal="value_changed" from="VBoxContainer/GradientOptions/PositionSlider" to="." method="_value_changed"] [connection signal="value_changed" from="VBoxContainer/GradientOptions/SizeSlider" to="." method="_value_changed"] [connection signal="value_changed" from="VBoxContainer/GradientOptions/AngleSlider" to="." method="_value_changed"] -[connection signal="value_changed" from="VBoxContainer/GradientOptions/CenterContainer/XCenterSlider" to="." method="_value_changed"] -[connection signal="value_changed" from="VBoxContainer/GradientOptions/CenterContainer/YCenterSlider" to="." method="_value_changed"] -[connection signal="value_changed" from="VBoxContainer/GradientOptions/RadiusContainer/XRadiusSlider" to="." method="_value_changed"] -[connection signal="value_changed" from="VBoxContainer/GradientOptions/RadiusContainer/YRadiusSlider" to="." method="_value_changed"] +[connection signal="value_changed" from="VBoxContainer/GradientOptions/CenterSlider" to="." method="_value_v2_changed"] +[connection signal="value_changed" from="VBoxContainer/GradientOptions/RadiusSlider" to="." method="_value_v2_changed"]