diff --git a/ui/board_view.gd b/ui/board_view.gd index 2b1a566..46f90ce 100644 --- a/ui/board_view.gd +++ b/ui/board_view.gd @@ -229,6 +229,16 @@ func fit() -> void: world.position = Vector2(maxf(8.0, (size.x - bounds.size.x * zoom) / 2.0), 8.0) - bounds.position * zoom +## Makes a layer cover the whole world. A Control's canvas item is clipped to +## its rect, and the world reaches past it (cards can sit at negative +## coordinates), so the clip is switched off: nothing a layer draws is lost. +static func cover_world(layer: Control) -> void: + layer.size = Vector2(WORLD_SIZE, WORLD_SIZE) + # Control sets its clip rect on entering the tree and on every resize, so + # switch it off again whenever the layer draws. + layer.draw.connect(func() -> void: RenderingServer.canvas_item_set_custom_rect(layer.get_canvas_item(), false)) + + ## A control's rect in world coordinates. (Control.get_global_rect ignores the ## world's zoom for the size, so it is wrong whenever the board is not at 100%.) func world_rect_of(control: Control) -> Rect2: diff --git a/ui/card_layer.gd b/ui/card_layer.gd index 7b57909..f1965c8 100644 --- a/ui/card_layer.gd +++ b/ui/card_layer.gd @@ -30,8 +30,7 @@ var _flash_left := 0.0 func _init() -> void: mouse_filter = MOUSE_FILTER_IGNORE - # Controls only draw inside their own rect, so cover the whole world. - size = Vector2(BoardView.WORLD_SIZE, BoardView.WORLD_SIZE) + BoardView.cover_world(self) _shadow = Style.box(Color(0, 0, 0, 0.22), 10) _ring = Style.box(Color(0, 0, 0, 0), 14) _ring.draw_center = false diff --git a/ui/group_layer.gd b/ui/group_layer.gd index 379c00b..fd0f64c 100644 --- a/ui/group_layer.gd +++ b/ui/group_layer.gd @@ -11,8 +11,7 @@ var frozen: Dictionary = {} func _init() -> void: mouse_filter = MOUSE_FILTER_IGNORE - # Controls only draw inside their own rect, so cover the whole world. - size = Vector2(BoardView.WORLD_SIZE, BoardView.WORLD_SIZE) + BoardView.cover_world(self) func _process(_delta: float) -> void: diff --git a/ui/pipe_layer.gd b/ui/pipe_layer.gd index 3d43251..79d238a 100644 --- a/ui/pipe_layer.gd +++ b/ui/pipe_layer.gd @@ -44,8 +44,7 @@ var _batch := PipeBatch.new(self) func _init() -> void: mouse_filter = MOUSE_FILTER_IGNORE - # Controls only draw inside their own rect, so cover the whole world. - size = Vector2(BoardView.WORLD_SIZE, BoardView.WORLD_SIZE) + BoardView.cover_world(self) _label_box = Style.box(Style.CARD, 7, [6, 1, 6, 2]) Style.bordered(_label_box, 1, Style.THREAD_DARK) _lit_label_box = Style.box(Style.LIT, 7, [6, 1, 6, 2]) diff --git a/ui/port_layer.gd b/ui/port_layer.gd index fb3c2a2..94dc10b 100644 --- a/ui/port_layer.gd +++ b/ui/port_layer.gd @@ -24,8 +24,7 @@ var _stack: Array = [] func _init() -> void: mouse_filter = MOUSE_FILTER_STOP mouse_default_cursor_shape = CURSOR_CROSS - # Controls only draw inside their own rect, so cover the whole world. - size = Vector2(BoardView.WORLD_SIZE, BoardView.WORLD_SIZE) + BoardView.cover_world(self) ## Redraws only when the board's geometry changed (BoardView.geometry_rev),