@@ -4,6 +4,7 @@ extends MarginContainer
4
4
5
5
const EXTEND_MARGIN : float = 800
6
6
const BLOCK_AUTO_PLACE_MARGIN : Vector2 = Vector2 (16 , 8 )
7
+ const DEFAULT_WINDOW_MARGIN : Vector2 = Vector2 (24 , 24 )
7
8
const ZOOM_FACTOR : float = 1.1
8
9
9
10
@onready var _window : Control = % Window
@@ -31,6 +32,7 @@ var _panning := false
31
32
var zoom : float :
32
33
set (value ):
33
34
_window .scale = Vector2 (value , value )
35
+ _zoom_label .text = "%.1f x" % value
34
36
get :
35
37
return _window .scale .x
36
38
@@ -117,6 +119,8 @@ func bsd_selected(bsd: BlockScriptData):
117
119
_selected_node_label .text = _selected_node_label_format .format ({"node" : edited_node .name })
118
120
_add_block_code_button .disabled = false
119
121
122
+ reset_window_position ()
123
+
120
124
121
125
func _load_bsd (bsd : BlockScriptData ):
122
126
for tree in bsd .block_trees .array :
@@ -227,6 +231,10 @@ func _input(event):
227
231
set_mouse_override (event .pressed )
228
232
229
233
if event is InputEventMouseButton :
234
+ if event .button_index == MOUSE_BUTTON_RIGHT and event .is_pressed ():
235
+ reset_window_position ()
236
+ return
237
+
230
238
if event .button_index == MOUSE_BUTTON_LEFT or event .button_index == MOUSE_BUTTON_MIDDLE :
231
239
if event .pressed and is_mouse_over ():
232
240
_panning = true
@@ -246,15 +254,28 @@ func _input(event):
246
254
if event .button_index == MOUSE_BUTTON_WHEEL_DOWN and zoom > 0.2 :
247
255
zoom /= ZOOM_FACTOR
248
256
249
- _zoom_label .text = "%.1f x" % zoom
250
-
251
257
_window .position -= (old_mouse_window_pos - canvas_to_window (relative_mouse_pos )) * zoom
252
258
253
259
if event is InputEventMouseMotion :
254
260
if (Input .is_key_pressed (KEY_SHIFT ) and _panning ) or (Input .is_mouse_button_pressed (MOUSE_BUTTON_MIDDLE ) and _panning ):
255
261
_window .position += event .relative
256
262
257
263
264
+ func reset_window_position ():
265
+ # Generate a bounding box from all of the blocks in the canvas
266
+
267
+ var blocks = get_blocks ()
268
+ var top_left : Vector2 = blocks .pop_front ().position if blocks .size () > 0 else Vector2 (0 , 0 )
269
+
270
+ for block in blocks :
271
+ if block .position .x < top_left .x :
272
+ top_left .x = block .position .x
273
+ if block .position .y < top_left .y :
274
+ top_left .y = block .position .y
275
+
276
+ _window .position = - top_left + DEFAULT_WINDOW_MARGIN
277
+
278
+
258
279
func canvas_to_window (v : Vector2 ) -> Vector2 :
259
280
return _window .get_transform ().affine_inverse () * v
260
281
@@ -274,3 +295,7 @@ func set_mouse_override(override: bool):
274
295
else :
275
296
_mouse_override .mouse_filter = Control .MOUSE_FILTER_IGNORE
276
297
_mouse_override .mouse_default_cursor_shape = Control .CURSOR_ARROW
298
+
299
+
300
+ func _on_window_resized ():
301
+ pass
0 commit comments