Skip to content

Commit c98cc9c

Browse files
authored
Spritesheet preview improvements (#4)
* UI changes and Diagonal Movement * Removed print() statements * a little improvement * a typo
1 parent 36fcb95 commit c98cc9c

3 files changed

Lines changed: 93 additions & 43 deletions

File tree

Code/SpritesheetPreview/src/Extensions/SpritesheetPreview/Main.gd

Lines changed: 48 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ enum Orientation { ROWS = 0, COLUMNS = 1 }
44

55
var global :Node #Needed for reference to "global" node of Pixelorama (Used most of the time)
66
onready var previews = $VBoxContainer/Preview/PreviewPanel/ScrollContainer/Previews
7-
onready var spritesheet_lines_count_label = $VBoxContainer/Preview/Orientation/LinesCountLabel
8-
onready var spritesheet_lines_count = $VBoxContainer/Preview/Orientation/LinesCount
9-
onready var spritesheet_orientation = $VBoxContainer/Preview/Orientation/Orientation
7+
onready var spritesheet_lines_count_label = $VBoxContainer/Preview/Orientation/HBoxContainer2/LinesCountLabel
8+
onready var spritesheet_lines_count = $VBoxContainer/Preview/Orientation/HBoxContainer2/LinesCount
9+
onready var spritesheet_orientation = $VBoxContainer/Preview/Orientation/HBoxContainer/Orientation
1010

1111
var processed_images = [] # Image[]
1212
var number_of_frames := 1
@@ -181,22 +181,22 @@ var moving = false
181181
var scaling = false
182182
var can_scale = false
183183
var mode = 0
184-
enum Mode { NONE, LEFT, RIGHT, UP, DOWN }
184+
enum Mode { NONE, LEFT, RIGHT, UP, DOWN, T_LEFT, T_RIGHT, B_LEFT, B_RIGHT }
185185
var scale_limit = 5
186186
var offset = Vector2.ZERO
187187

188188

189189
func _on_Main_mouse_entered() -> void:
190190
if global:
191191
global.can_draw = false
192-
can_scale = true
192+
can_scale = true
193193

194194

195195
func _on_Main_mouse_exited() -> void:
196196
if global:
197197
global.can_draw = true
198-
if !scaling:
199-
can_scale = false
198+
if !scaling:
199+
can_scale = false
200200

201201

202202
func _on_Title_gui_input(event: InputEvent) -> void:
@@ -218,17 +218,29 @@ func _input(event: InputEvent) -> void:
218218
if !event.pressed:
219219
$RefreshTimer.start()
220220

221-
if event is InputEventMouse:
221+
if event is InputEventMouse: # Set cursor and mode accordingly
222222
var mouse_pos = get_local_mouse_position()
223223
if event is InputEventMouseMotion and !scaling:
224-
if (mouse_pos.x >= rect_size.x - scale_limit and mouse_pos.x <= rect_size.x + scale_limit
225-
and (mouse_pos.y > 0 and mouse_pos.y < rect_size.y)): #Right
226-
mouse_default_cursor_shape = Control.CURSOR_HSIZE
227-
mode = Mode.RIGHT
224+
if mouse_pos.distance_to(Vector2.ZERO) <= scale_limit: #Top left
225+
mouse_default_cursor_shape = Control.CURSOR_FDIAGSIZE
226+
mode = Mode.T_LEFT
227+
elif mouse_pos.distance_to(Vector2(rect_size.x, 0)) <= scale_limit: #Top right
228+
mouse_default_cursor_shape = Control.CURSOR_BDIAGSIZE
229+
mode = Mode.T_RIGHT
230+
elif mouse_pos.distance_to(Vector2(0,rect_size.y)) <= scale_limit: #Bottom left
231+
mouse_default_cursor_shape = Control.CURSOR_BDIAGSIZE
232+
mode = Mode.B_LEFT
233+
elif mouse_pos.distance_to(rect_size) <= scale_limit: #Bottom right
234+
mouse_default_cursor_shape = Control.CURSOR_FDIAGSIZE
235+
mode = Mode.B_RIGHT
228236
elif ((mouse_pos.x < scale_limit and mouse_pos.x > -scale_limit)
229237
and (mouse_pos.y > 0 and mouse_pos.y < rect_size.y)): #Left
230238
mouse_default_cursor_shape = Control.CURSOR_HSIZE
231239
mode = Mode.LEFT
240+
elif (mouse_pos.x >= rect_size.x - scale_limit and mouse_pos.x <= rect_size.x + scale_limit
241+
and (mouse_pos.y > 0 and mouse_pos.y < rect_size.y)): #Right
242+
mouse_default_cursor_shape = Control.CURSOR_HSIZE
243+
mode = Mode.RIGHT
232244
elif ((mouse_pos.y < scale_limit and mouse_pos.y > -scale_limit)
233245
and (mouse_pos.x > 0 and mouse_pos.x < rect_size.x)): #Up
234246
mouse_default_cursor_shape = Control.CURSOR_VSIZE
@@ -242,9 +254,10 @@ func _input(event: InputEvent) -> void:
242254
mouse_default_cursor_shape = Control.CURSOR_ARROW
243255
mode = Mode.NONE
244256

245-
elif event is InputEventMouseMotion and scaling:
257+
elif event is InputEventMouseMotion and scaling: # Here's where the scaling is done
246258
if can_scale:
247259
match mode:
260+
# SIDES
248261
Mode.RIGHT:
249262
rect_size.x += get_global_mouse_position().x - rect_global_position.x - (rect_size.x)
250263
Mode.LEFT:
@@ -258,6 +271,28 @@ func _input(event: InputEvent) -> void:
258271
rect_size.y += rect_global_position.y - get_global_mouse_position().y
259272
rect_position.y -= (rect_global_position.y) - get_global_mouse_position().y
260273

274+
#CORNERS
275+
Mode.T_LEFT:
276+
if rect_size.y + (rect_global_position.y - get_global_mouse_position().y) > rect_min_size.y:
277+
rect_size.y += rect_global_position.y - get_global_mouse_position().y
278+
rect_position.y -= (rect_global_position.y) - get_global_mouse_position().y
279+
if rect_size.x + (rect_global_position.x - get_global_mouse_position().x) > rect_min_size.x:
280+
rect_size.x += rect_global_position.x - get_global_mouse_position().x
281+
rect_position.x -= (rect_global_position.x) - get_global_mouse_position().x
282+
Mode.T_RIGHT:
283+
if rect_size.y + (rect_global_position.y - get_global_mouse_position().y) > rect_min_size.y:
284+
rect_size.y += rect_global_position.y - get_global_mouse_position().y
285+
rect_position.y -= (rect_global_position.y) - get_global_mouse_position().y
286+
rect_size.x += get_global_mouse_position().x - rect_global_position.x - (rect_size.x)
287+
Mode.B_LEFT:
288+
rect_size.y += get_global_mouse_position().y - rect_global_position.y - (rect_size.y)
289+
if rect_size.x + (rect_global_position.x - get_global_mouse_position().x) > rect_min_size.x:
290+
rect_size.x += rect_global_position.x - get_global_mouse_position().x
291+
rect_position.x -= (rect_global_position.x) - get_global_mouse_position().x
292+
Mode.B_RIGHT:
293+
rect_size.y += get_global_mouse_position().y - rect_global_position.y - (rect_size.y)
294+
rect_size.x += get_global_mouse_position().x - rect_global_position.x - (rect_size.x)
295+
261296
if event is InputEventMouseButton:
262297
if event.pressed:
263298
scaling = true

Code/SpritesheetPreview/src/Extensions/SpritesheetPreview/Main.tscn

Lines changed: 45 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -49,9 +49,9 @@ shader_param/follow_movement = false
4949
shader_param/follow_scale = false
5050

5151
[node name="Main" type="Panel"]
52-
margin_right = 297.0
53-
margin_bottom = 256.0
54-
rect_min_size = Vector2( 337, 296 )
52+
margin_right = 213.0
53+
margin_bottom = 222.0
54+
rect_min_size = Vector2( 170, 170 )
5555
script = ExtResource( 1 )
5656

5757
[node name="VBoxContainer" type="VBoxContainer" parent="."]
@@ -63,7 +63,7 @@ margin_right = -10.0
6363
margin_bottom = -10.0
6464

6565
[node name="Title" type="Label" parent="VBoxContainer"]
66-
margin_right = 317.0
66+
margin_right = 193.0
6767
margin_bottom = 14.0
6868
mouse_filter = 0
6969
mouse_default_cursor_shape = 6
@@ -73,14 +73,14 @@ valign = 1
7373

7474
[node name="Preview" type="VBoxContainer" parent="VBoxContainer"]
7575
margin_top = 18.0
76-
margin_right = 317.0
77-
margin_bottom = 276.0
76+
margin_right = 193.0
77+
margin_bottom = 202.0
7878
size_flags_horizontal = 3
7979
size_flags_vertical = 3
8080

8181
[node name="PreviewPanel" type="Panel" parent="VBoxContainer/Preview"]
82-
margin_right = 317.0
83-
margin_bottom = 230.0
82+
margin_right = 193.0
83+
margin_bottom = 132.0
8484
size_flags_horizontal = 3
8585
size_flags_vertical = 3
8686

@@ -95,42 +95,57 @@ anchor_right = 1.0
9595
anchor_bottom = 1.0
9696

9797
[node name="Previews" type="GridContainer" parent="VBoxContainer/Preview/PreviewPanel/ScrollContainer"]
98-
margin_right = 317.0
99-
margin_bottom = 230.0
98+
margin_right = 193.0
99+
margin_bottom = 132.0
100100
size_flags_horizontal = 3
101101
size_flags_vertical = 3
102102

103-
[node name="Orientation" type="HBoxContainer" parent="VBoxContainer/Preview"]
104-
margin_top = 234.0
105-
margin_right = 317.0
106-
margin_bottom = 258.0
103+
[node name="Orientation" type="VBoxContainer" parent="VBoxContainer/Preview"]
104+
margin_top = 136.0
105+
margin_right = 193.0
106+
margin_bottom = 184.0
107107
alignment = 1
108108

109-
[node name="OrientationLabel" type="Label" parent="VBoxContainer/Preview/Orientation"]
110-
margin_top = 5.0
111-
margin_right = 77.0
112-
margin_bottom = 19.0
109+
[node name="HBoxContainer" type="HBoxContainer" parent="VBoxContainer/Preview/Orientation"]
110+
margin_right = 193.0
111+
margin_bottom = 20.0
112+
113+
[node name="OrientationLabel" type="Label" parent="VBoxContainer/Preview/Orientation/HBoxContainer"]
114+
margin_top = 3.0
115+
margin_right = 94.0
116+
margin_bottom = 17.0
117+
size_flags_horizontal = 3
113118
text = "Orientation:"
119+
align = 2
120+
valign = 1
114121

115-
[node name="Orientation" type="OptionButton" parent="VBoxContainer/Preview/Orientation"]
116-
margin_left = 81.0
117-
margin_right = 165.0
118-
margin_bottom = 24.0
122+
[node name="Orientation" type="OptionButton" parent="VBoxContainer/Preview/Orientation/HBoxContainer"]
123+
margin_left = 98.0
124+
margin_right = 193.0
125+
margin_bottom = 20.0
119126
size_flags_horizontal = 3
120127
text = "Rows"
121128
items = [ "Rows", null, false, 0, null, "Columns", null, false, 1, null ]
122129
selected = 0
123130

124-
[node name="LinesCountLabel" type="Label" parent="VBoxContainer/Preview/Orientation"]
125-
margin_left = 169.0
131+
[node name="HBoxContainer2" type="HBoxContainer" parent="VBoxContainer/Preview/Orientation"]
132+
margin_top = 24.0
133+
margin_right = 193.0
134+
margin_bottom = 48.0
135+
alignment = 1
136+
137+
[node name="LinesCountLabel" type="Label" parent="VBoxContainer/Preview/Orientation/HBoxContainer2"]
126138
margin_top = 5.0
127-
margin_right = 229.0
139+
margin_right = 94.0
128140
margin_bottom = 19.0
141+
size_flags_horizontal = 3
129142
text = "Columns:"
143+
align = 2
144+
valign = 1
130145

131-
[node name="LinesCount" type="SpinBox" parent="VBoxContainer/Preview/Orientation"]
132-
margin_left = 233.0
133-
margin_right = 317.0
146+
[node name="LinesCount" type="SpinBox" parent="VBoxContainer/Preview/Orientation/HBoxContainer2"]
147+
margin_left = 98.0
148+
margin_right = 193.0
134149
margin_bottom = 24.0
135150
size_flags_horizontal = 3
136151
min_value = 1.0
@@ -144,6 +159,6 @@ one_shot = true
144159
[connection signal="mouse_entered" from="." to="." method="_on_Main_mouse_entered"]
145160
[connection signal="mouse_exited" from="." to="." method="_on_Main_mouse_exited"]
146161
[connection signal="gui_input" from="VBoxContainer/Title" to="." method="_on_Title_gui_input"]
147-
[connection signal="item_selected" from="VBoxContainer/Preview/Orientation/Orientation" to="." method="_on_Orientation_item_selected"]
148-
[connection signal="value_changed" from="VBoxContainer/Preview/Orientation/LinesCount" to="." method="_on_LinesCount_value_changed"]
162+
[connection signal="item_selected" from="VBoxContainer/Preview/Orientation/HBoxContainer/Orientation" to="." method="_on_Orientation_item_selected"]
163+
[connection signal="value_changed" from="VBoxContainer/Preview/Orientation/HBoxContainer2/LinesCount" to="." method="_on_LinesCount_value_changed"]
149164
[connection signal="timeout" from="RefreshTimer" to="." method="_on_RefreshTimer_timeout"]

Extensions/SpritesheetPreview.pck

1.89 KB
Binary file not shown.

0 commit comments

Comments
 (0)