Skip to content

Commit f273918

Browse files
committedJan 12, 2025
Fix the resize canvas dialog's offset not resetting to zero on dialog popup
Also renamed some of the script's methods to be snake_case
1 parent 3f2245c commit f273918

File tree

2 files changed

+42
-31
lines changed

2 files changed

+42
-31
lines changed
 

‎src/UI/Dialogs/ImageEffects/ResizeCanvas.gd

+29-19
Original file line numberDiff line numberDiff line change
@@ -8,56 +8,66 @@ var image := Image.create(1, 1, false, Image.FORMAT_RGBA8)
88

99
@onready var width_spinbox: SpinBox = $VBoxContainer/OptionsContainer/WidthValue
1010
@onready var height_spinbox: SpinBox = $VBoxContainer/OptionsContainer/HeightValue
11-
@onready var x_spinbox: SpinBox = $VBoxContainer/OptionsContainer/XSpinBox
12-
@onready var y_spinbox: SpinBox = $VBoxContainer/OptionsContainer/YSpinBox
11+
@onready var x_offset_spinbox: SpinBox = $VBoxContainer/OptionsContainer/XOffsetSpinBox
12+
@onready var y_offset_spinbox: SpinBox = $VBoxContainer/OptionsContainer/YOffsetSpinBox
1313
@onready var aspect_ratio_container: AspectRatioContainer = $VBoxContainer/AspectRatioContainer
1414
@onready var preview_rect: TextureRect = $VBoxContainer/AspectRatioContainer/Preview
1515

1616

17-
func _on_ResizeCanvas_about_to_show() -> void:
17+
func _on_about_to_popup() -> void:
1818
Global.canvas.selection.transform_content_confirm()
1919
image.resize(Global.current_project.size.x, Global.current_project.size.y)
2020
image.fill(Color(0.0, 0.0, 0.0, 0.0))
2121
var frame := Global.current_project.frames[Global.current_project.current_frame]
2222
DrawingAlgos.blend_layers(image, frame)
23-
width_spinbox.value = Global.current_project.size.x
24-
height_spinbox.value = Global.current_project.size.y
23+
if width_spinbox.value == Global.current_project.size.x:
24+
_on_width_value_changed(width_spinbox.value)
25+
else:
26+
width_spinbox.value = Global.current_project.size.x
27+
if height_spinbox.value == Global.current_project.size.y:
28+
_on_height_value_changed(height_spinbox.value)
29+
else:
30+
height_spinbox.value = Global.current_project.size.y
2531
update_preview()
2632

2733

28-
func _on_ResizeCanvas_confirmed() -> void:
34+
func _on_confirmed() -> void:
2935
DrawingAlgos.resize_canvas(width, height, offset_x, offset_y)
3036

3137

32-
func _on_WidthValue_value_changed(value: int) -> void:
38+
func _on_width_value_changed(value: int) -> void:
3339
width = value
34-
x_spinbox.min_value = mini(width - Global.current_project.size.x, 0)
35-
x_spinbox.max_value = maxi(width - Global.current_project.size.x, 0)
36-
x_spinbox.value = clampi(x_spinbox.value, x_spinbox.min_value, x_spinbox.max_value)
40+
x_offset_spinbox.min_value = mini(width - Global.current_project.size.x, 0)
41+
x_offset_spinbox.max_value = maxi(width - Global.current_project.size.x, 0)
42+
x_offset_spinbox.value = clampi(
43+
x_offset_spinbox.value, x_offset_spinbox.min_value, x_offset_spinbox.max_value
44+
)
3745
update_preview()
3846

3947

40-
func _on_HeightValue_value_changed(value: int) -> void:
48+
func _on_height_value_changed(value: int) -> void:
4149
height = value
42-
y_spinbox.min_value = mini(height - Global.current_project.size.y, 0)
43-
y_spinbox.max_value = maxi(height - Global.current_project.size.y, 0)
44-
y_spinbox.value = clampi(y_spinbox.value, y_spinbox.min_value, y_spinbox.max_value)
50+
y_offset_spinbox.min_value = mini(height - Global.current_project.size.y, 0)
51+
y_offset_spinbox.max_value = maxi(height - Global.current_project.size.y, 0)
52+
y_offset_spinbox.value = clampi(
53+
y_offset_spinbox.value, y_offset_spinbox.min_value, y_offset_spinbox.max_value
54+
)
4555
update_preview()
4656

4757

48-
func _on_XSpinBox_value_changed(value: int) -> void:
58+
func _on_x_offset_spin_box_value_changed(value: int) -> void:
4959
offset_x = value
5060
update_preview()
5161

5262

53-
func _on_YSpinBox_value_changed(value: int) -> void:
63+
func _on_y_offset_spin_box_value_changed(value: int) -> void:
5464
offset_y = value
5565
update_preview()
5666

5767

58-
func _on_CenterButton_pressed() -> void:
59-
x_spinbox.value = (x_spinbox.min_value + x_spinbox.max_value) / 2
60-
y_spinbox.value = (y_spinbox.min_value + y_spinbox.max_value) / 2
68+
func _on_center_button_pressed() -> void:
69+
x_offset_spinbox.value = (x_offset_spinbox.min_value + x_offset_spinbox.max_value) / 2
70+
y_offset_spinbox.value = (y_offset_spinbox.min_value + y_offset_spinbox.max_value) / 2
6171

6272

6373
func update_preview() -> void:

‎src/UI/Dialogs/ImageEffects/ResizeCanvas.tscn

+13-12
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,14 @@
66
[node name="ResizeCanvas" type="ConfirmationDialog"]
77
canvas_item_default_texture_filter = 0
88
title = "Resize Canvas"
9+
size = Vector2i(216, 486)
910
script = ExtResource("2")
1011

1112
[node name="VBoxContainer" type="VBoxContainer" parent="."]
1213
offset_left = 8.0
1314
offset_top = 8.0
1415
offset_right = 208.0
15-
offset_bottom = 380.0
16+
offset_bottom = 437.0
1617

1718
[node name="ImageSize" type="Label" parent="VBoxContainer"]
1819
layout_mode = 2
@@ -61,24 +62,24 @@ text = "Offset"
6162
layout_mode = 2
6263
size_flags_horizontal = 3
6364

64-
[node name="XLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
65+
[node name="XOffsetLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
6566
layout_mode = 2
6667
size_flags_horizontal = 3
6768
text = "X:"
6869

69-
[node name="XSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
70+
[node name="XOffsetSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
7071
layout_mode = 2
7172
size_flags_horizontal = 3
7273
mouse_default_cursor_shape = 2
7374
max_value = 0.0
7475
suffix = "px"
7576

76-
[node name="YLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
77+
[node name="YOffsetLabel" type="Label" parent="VBoxContainer/OptionsContainer"]
7778
layout_mode = 2
7879
size_flags_horizontal = 3
7980
text = "Y:"
8081

81-
[node name="YSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
82+
[node name="YOffsetSpinBox" type="SpinBox" parent="VBoxContainer/OptionsContainer"]
8283
layout_mode = 2
8384
size_flags_horizontal = 3
8485
mouse_default_cursor_shape = 2
@@ -105,11 +106,11 @@ stretch_mode = 5
105106
show_behind_parent = true
106107
layout_mode = 2
107108

108-
[connection signal="about_to_popup" from="." to="." method="_on_ResizeCanvas_about_to_show"]
109-
[connection signal="confirmed" from="." to="." method="_on_ResizeCanvas_confirmed"]
109+
[connection signal="about_to_popup" from="." to="." method="_on_about_to_popup"]
110+
[connection signal="confirmed" from="." to="." method="_on_confirmed"]
110111
[connection signal="visibility_changed" from="." to="." method="_on_visibility_changed"]
111-
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/WidthValue" to="." method="_on_WidthValue_value_changed"]
112-
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/HeightValue" to="." method="_on_HeightValue_value_changed"]
113-
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/XSpinBox" to="." method="_on_XSpinBox_value_changed"]
114-
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/YSpinBox" to="." method="_on_YSpinBox_value_changed"]
115-
[connection signal="pressed" from="VBoxContainer/OptionsContainer/CenterButton" to="." method="_on_CenterButton_pressed"]
112+
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/WidthValue" to="." method="_on_width_value_changed"]
113+
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/HeightValue" to="." method="_on_height_value_changed"]
114+
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/XOffsetSpinBox" to="." method="_on_x_offset_spin_box_value_changed"]
115+
[connection signal="value_changed" from="VBoxContainer/OptionsContainer/YOffsetSpinBox" to="." method="_on_y_offset_spin_box_value_changed"]
116+
[connection signal="pressed" from="VBoxContainer/OptionsContainer/CenterButton" to="." method="_on_center_button_pressed"]

0 commit comments

Comments
 (0)
Please sign in to comment.