Compare commits

...

10 commits

Author SHA1 Message Date
tachyonwolf
d7d7fb66ea Thread pick radius 12 screen px
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 09:07:11 -06:00
tachyonwolf
2c6ed11ed3 Selected lit threads glow too
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 09:06:55 -06:00
tachyonwolf
f90427d748 A selected thread glows in the selection colour, like a selected card
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 09:04:18 -06:00
tachyonwolf
3d51c8c8ba Threads pick within 8 screen px of the line at any zoom
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 09:03:28 -06:00
tachyonwolf
2241937eb2 Build: clicking a card's empty body selects the card
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 09:03:20 -06:00
tachyonwolf
258b62a44a Output dots: grab area grows to half the gap to the nearest dot (max 24 screen px)
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 09:00:04 -06:00
tachyonwolf
54eb5d1af2 Dragged threads snap to an input dot within 24 screen px and highlight it
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 08:57:42 -06:00
tachyonwolf
f87aa00795 Selecting a thread no longer highlights its source card
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 08:56:30 -06:00
tachyonwolf
0a72c2b12c Layers keep drawing outside their rect: ports and lit threads vanished for cards at negative or far coordinates
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 08:53:15 -06:00
tachyonwolf
5c69acbba0 Fix dots and drops when zoomed: read control rects in world space; 10px drop reach on input dots
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-11-21 08:48:35 -06:00
13 changed files with 156 additions and 40 deletions

View file

@ -13,6 +13,7 @@ func _init() -> void:
await _test_show_less()
await _test_add_scrolls_and_focuses()
await _test_wheel_zooms()
await _test_zoomed_in_anchors()
finish()
@ -165,3 +166,21 @@ func _button(n: Node, prefix: String) -> Button:
if found:
return found
return null
## Zoomed in, a result's dot still sits on its row and shows (the row rect was
## once read at 100% scale, hiding dots low in a scrolling list).
func _test_zoomed_in_anchors() -> void:
var card := main.card_for("road")
card.set_user_size(380.0, 120.0)
main.board.set_zoom(1.5)
await _frames()
var last: String = main.data.get_table("road").entries[-1].id
var row := card.rows[last] as Control
var a := card.anchor_for(last)
var expected := card.position.y + (card.get_global_transform().affine_inverse() * row.get_global_position()).y + row.size.y / 2.0
var in_list := main.board.world_rect_of(card.list_scroll).intersects(main.board.world_rect_of(row))
_check(absf(a["pos"].y - expected) < 1.0 or not in_list, "zoomed in, a result's dot sits on its row: %.1f vs %.1f" % [a["pos"].y, expected])
var scroll_rect := main.board.world_rect_of(card.list_scroll)
_check(is_equal_approx(scroll_rect.size.y, 120.0), "world_rect_of gives the list's size in world units: %.1f" % scroll_rect.size.y)
main.board.set_zoom(1.0)

View file

@ -14,6 +14,8 @@ const FAR_ZOOM := 0.22
## roll on a click; their names show as tooltips (CardShield).
const COMPACT_ZOOM := 0.45
const WORLD_SIZE := 40000.0
## How far (screen pixels) from a thread's line a click or hover still picks it.
const PIPE_HIT_RADIUS := 12.0
var main: Main
var world: Control
@ -203,6 +205,11 @@ func world_mouse() -> Vector2:
return world.get_local_mouse_position()
## The pipe under the mouse, within PIPE_HIT_RADIUS screen pixels of its line.
func pipe_under_mouse() -> String:
return pipes.pipe_at(world_mouse(), PIPE_HIT_RADIUS / zoom)
func screen_to_world(p: Vector2) -> Vector2:
return (p - world.position) / zoom
@ -229,6 +236,22 @@ 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:
return (world.get_global_transform().affine_inverse() * control.get_global_transform()) * Rect2(Vector2.ZERO, control.size)
## The part of the world the board shows right now.
func view_rect() -> Rect2:
return Rect2(screen_to_world(Vector2.ZERO), size / zoom)
@ -300,7 +323,7 @@ func _gui_input(ev: InputEvent) -> void:
if f is LineEdit or f is TextEdit:
f.release_focus()
if build_left:
var key := pipes.pipe_at(world_mouse(), 11.0) if main.mode == Main.Mode.BUILD else ""
var key := pipe_under_mouse() if main.mode == Main.Mode.BUILD else ""
if key != "":
# The pipe opens in the inspector (Main.open_pipe_options).
main.open_pipe_options(key, mb.global_position)
@ -343,7 +366,7 @@ func _gui_input(ev: InputEvent) -> void:
MOUSE_BUTTON_RIGHT:
if mb.pressed:
# A thread under the mouse, else the empty spread.
var key := pipes.pipe_at(world_mouse(), 11.0)
var key := pipe_under_mouse()
var list := Actions.thread(main, key) if key != "" else Actions.background(main, world_mouse())
if not list.is_empty():
Actions.popup_at(main, list, mb.global_position)
@ -369,7 +392,7 @@ func _gui_input(ev: InputEvent) -> void:
elif _panning:
world.position += mm.relative
elif main.mode == Main.Mode.BUILD:
pipes.hover_key = pipes.pipe_at(world_mouse(), 11.0)
pipes.hover_key = pipe_under_mouse()
mouse_default_cursor_shape = CURSOR_POINTING_HAND if pipes.hover_key != "" else CURSOR_ARROW
return
var pan := ev as InputEventPanGesture

View file

@ -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

View file

@ -276,9 +276,7 @@ func inlet_point() -> Vector2:
func anchor_for(tid: String, eid: String) -> Vector2:
var row: Control = lit_rows.get(Roller.entry_key(tid, eid))
if row != null and row.is_inside_tree():
var to_world := main.board.world.get_global_transform().affine_inverse()
var r := row.get_global_rect()
return Vector2(position.x + size.x, (to_world * (r.position + Vector2(0, r.size.y / 2.0))).y)
return Vector2(position.x + size.x, main.board.world_rect_of(row).get_center().y)
return Vector2(position.x + size.x, position.y + INLET_Y)

View file

@ -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:

View file

@ -107,8 +107,10 @@ func clear() -> void:
func _mark_cards() -> void:
if main == null:
return
var tid := str(selection.get("tid", ""))
var eid := str(selection.get("eid", "")) if str(selection.get("kind", "")) == "result" else ""
var kind := str(selection.get("kind", ""))
# A selected thread is the selection itself; its source card is not.
var tid := str(selection.get("tid", "")) if kind != "pipe" else ""
var eid := str(selection.get("eid", "")) if kind == "result" else ""
for c in main.cards.values():
var card := c as TableCard
if card and card.has_method("set_selected_entry"):

View file

@ -198,6 +198,8 @@ func start_link(tid: String, eid: String) -> void:
editing.start_link(tid, eid)
func update_link() -> void:
editing.update_link()
func link_snap_point() -> Variant:
return editing.link_snap_point()
func finish_link() -> void:
editing.finish_link()
func is_selected(tid: String) -> bool:

View file

@ -29,6 +29,8 @@ const ADD_KINDS := [
]
const MENU_FROM_TEMPLATE := 100
const MENU_GROUP := 101
## How close (screen pixels) a dragged thread must be to a card's input dot to drop on it.
const LINK_DROP_RADIUS := 24.0
const MENU_SAVE_SELECTION := 102
@ -256,6 +258,16 @@ func update_link() -> void:
_drop_card.set_drop_target(true)
## The input dot a dragged thread would land on if dropped now, or null when
## the mouse is not within LINK_DROP_RADIUS of one (the preview snaps to it).
func link_snap_point() -> Variant:
var card := _card_under_mouse()
if card == null or card.table.kind == RollTable.KIND_VARIABLE:
return null
var mouse := m.board.world.get_local_mouse_position()
return card.inlet_point() if card.inlet_point().distance_to(mouse) <= LINK_DROP_RADIUS / m.board.zoom else null
func finish_link() -> void:
var over := _card_under_mouse()
if is_instance_valid(_drop_card):
@ -286,11 +298,12 @@ func finish_link() -> void:
func _card_under_mouse() -> TableCard:
if _card_under_mouse_override:
return _card_under_mouse_override
var gp := m.get_global_mouse_position()
var mouse := m.board.world.get_local_mouse_position()
var reach := LINK_DROP_RADIUS / m.board.zoom
var kids := m.board.cards.get_children()
for i in range(kids.size() - 1, -1, -1):
var card := kids[i] as TableCard
if card and card.visible and card.get_global_rect().has_point(gp):
if card and card.visible and (m.board.world_rect_of(card).has_point(mouse) or (card.table.kind != RollTable.KIND_VARIABLE and card.inlet_point().distance_to(mouse) <= reach)):
return card
return null

View file

@ -61,15 +61,23 @@ static func coarse(rid: RID, pts: PackedVector2Array, color: Color, width: float
RenderingServer.canvas_item_add_polyline(rid, points, PackedColorArray([color]), width, false)
## The glow selected cards have (TableCardSkin), around a selected thread.
static func select_glow(rid: RID, pts: PackedVector2Array) -> void:
line(rid, pts, Color(Style.SELECTED, 0.3), 26.0)
line(rid, pts, Style.SELECTED, 15.0)
## An unlit thread (as PipeLayer._draw_pipe draws it), in its own canvas item.
## `own` is the thread's own colour ("" = the theme's THREAD).
func add_pipe(pts: PackedVector2Array, hovered: bool, own: String = "") -> void:
func add_pipe(pts: PackedVector2Array, hovered: bool, own: String = "", selected: bool = false) -> void:
var rid := item()
var color := Color.from_string(own, Style.THREAD) if own != "" else Style.THREAD
var dark := color.darkened(0.6) if own != "" else Style.THREAD_DARK
if far:
coarse(rid, pts, color, 10.0)
return
if selected:
select_glow(rid, pts)
if ThreadStrip.active:
ThreadStrip.active.add_to(rid, pts, color.lightened(0.35) if hovered else color, dark)
ThreadStrip.active.add_pins(item(), pts)

View file

@ -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])
@ -143,7 +142,10 @@ func _draw() -> void:
if not is_ref and not rerouted and e.is_conditional(to):
diamonds.append([pts, lit, e.is_otherwise(to)])
if lit:
(lit_refs if is_ref else lit_list).append(pts)
if is_ref:
lit_refs.append(pts)
else:
lit_list.append([pts, key])
if not is_ref and not rerouted:
var lt := RulesView.pipe_label(e, to, main.data, plain)
if lt != "":
@ -159,7 +161,7 @@ func _draw() -> void:
elif rerouted:
_batch.add_bundle(pts)
else:
_batch.add_pipe(pts, build and (key == hover_key or key == select_key), str(e.pipe_color.get(to, "")))
_batch.add_pipe(pts, build and (key == hover_key or key == select_key), str(e.pipe_color.get(to, "")), build and key == select_key)
if not is_ref and not rerouted:
var tag := RulesView.pipe_label(e, to, main.data, plain)
if tag != "":
@ -167,8 +169,8 @@ func _draw() -> void:
# Lit pipes go on top so the path of the last roll reads clearly.
for pts in lit_refs:
_draw_ref(pts, true)
for pts in lit_list:
_draw_pipe(pts, true, false)
for lit_pipe: Array in lit_list:
_draw_pipe(lit_pipe[0], true, false, build and lit_pipe[1] == select_key)
for d in diamonds:
_draw_diamond(d[0], d[1], d[2])
var placed: Array[Rect2] = []
@ -249,7 +251,13 @@ func _draw_diamond(pts: PackedVector2Array, lit: bool, otherwise: bool) -> void:
draw_colored_polygon(inner, fill)
func _draw_pipe(pts: PackedVector2Array, lit: bool, hovered: bool) -> void:
func _draw_pipe(pts: PackedVector2Array, lit: bool, hovered: bool, selected: bool = false) -> void:
if selected: # the glow selected cards have (TableCardSkin)
if ThreadStrip.active and not _batch.far:
PipeBatch.select_glow(_batch.item(), pts)
else:
draw_polyline(pts, Color(Style.SELECTED, 0.3), 26.0, true)
draw_polyline(pts, Style.SELECTED, 15.0, true)
if ThreadStrip.active and not _batch.far:
_strip_pipe(pts, lit, hovered)
return

View file

@ -5,10 +5,15 @@ extends Control
## mode, dragging from an outlet lays a new pipe.
## Only the ports themselves take mouse input; everything else passes through.
const GRAB_RADIUS := 10.0
## Screen pixels: the most a dot's grab area grows to, and the gap kept
## between the grab areas of two close dots.
const GRAB_RADIUS_MAX := MainEditing.LINK_DROP_RADIUS
const GRAB_GAP := 2.0
var main: Main
var _grab: Array = [] # [{pos, tid, eid}] outlets that can start a pipe
var _grab: Array = [] # [{pos, tid, eid, reach}] outlets that can start a pipe (reach: grab radius, world units)
## Where the dot under the mouse sits (null for none).
var _hot_pos: Variant = null
var _linking := false
var _ghost_from := Vector2.ZERO
var _ghost_to := Vector2.ZERO
@ -17,6 +22,7 @@ var _drawn_rev := -1
var _drawn_hover := -1
var _drawn_mode := -1
var _drawn_far := false
var _drawn_zoom := 0.0
## [stack index, rect] of each visible card, for hiding ports under other cards.
var _stack: Array = []
@ -24,8 +30,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),
@ -35,8 +40,9 @@ func _process(_delta: float) -> void:
return
var hover := _hovered_grab()
var far := main.board.cards.far
if _linking or main.board.geometry_rev != _drawn_rev or hover != _drawn_hover or main.mode != _drawn_mode or far != _drawn_far:
if _linking or main.board.geometry_rev != _drawn_rev or hover != _drawn_hover or main.mode != _drawn_mode or far != _drawn_far or main.board.zoom != _drawn_zoom:
_drawn_far = far
_drawn_zoom = main.board.zoom
_drawn_rev = main.board.geometry_rev
_drawn_hover = hover
_drawn_mode = main.mode
@ -49,7 +55,7 @@ func _hovered_grab() -> int:
return -1
var mouse := get_local_mouse_position()
for i in _grab.size():
if mouse.distance_to(_grab[i]["pos"]) <= GRAB_RADIUS:
if mouse.distance_to(_grab[i]["pos"]) <= _grab[i]["reach"]:
return i
return -1
@ -60,12 +66,15 @@ func _has_point(p: Vector2) -> bool:
if main == null or main.mode != Main.Mode.BUILD:
return false
for g in _grab:
if p.distance_to(g["pos"]) <= GRAB_RADIUS:
if p.distance_to(g["pos"]) <= g["reach"]:
return true
return false
func _draw() -> void:
# The dot under the mouse (found with last frame's grab areas).
var hover_index := _hovered_grab()
_hot_pos = _grab[hover_index]["pos"] if hover_index >= 0 else null
_grab.clear()
# Zoomed far out (BoardView.FAR_ZOOM) the ports would be specks.
if main.board.cards.far and not _linking:
@ -80,7 +89,10 @@ func _draw() -> void:
var below := card.get_index()
# Variable cards are never rolled, so nothing pipes into them.
if t.kind != RollTable.KIND_VARIABLE and not _covered(card.inlet_point(), below):
_port(card.inlet_point(), Style.THREAD, Style.THREAD_DARK, 1.0)
if _linking and _ghost_to == card.inlet_point():
_port(card.inlet_point(), Style.ACCENT, Style.ACCENT_DARK, 1.4) # the drop will land here
else:
_port(card.inlet_point(), Style.THREAD, Style.THREAD_DARK, 1.0)
for e in t.entries:
if not card.rows.has(e.id):
continue
@ -99,7 +111,7 @@ func _draw() -> void:
if on and main.is_entry_lit(t.id, e.id):
fill = Style.ACCENT
ring = Style.ACCENT_DARK
if build and pos.distance_to(mouse) <= GRAB_RADIUS and not _linking:
if build and _hot_pos == pos and not _linking:
fill = Style.ACCENT
s = 1.2
_port(pos, fill, ring, s)
@ -124,10 +136,33 @@ func _draw() -> void:
_port(Vector2(p), Style.ACCENT, Style.ACCENT_DARK, 1.0)
else:
_port(Vector2(p), Style.THREAD, Style.THREAD_DARK, 1.0)
_size_grab_areas()
if _linking:
_draw_ghost(PipeLayer.curve(_ghost_from, _ghost_to, _ghost_down))
## Each dot's grab radius: up to GRAB_RADIUS_MAX on screen, less where another
## dot is near, so neighbouring areas stay GRAB_GAP screen pixels apart.
func _size_grab_areas() -> void:
var zoom := main.board.zoom
var cell := 2.0 * GRAB_RADIUS_MAX / zoom # only dots this close can matter
var buckets := {}
for g: Dictionary in _grab:
var key := Vector2i((g["pos"] as Vector2) / cell)
if not buckets.has(key):
buckets[key] = []
(buckets[key] as Array).append(g)
for g: Dictionary in _grab:
var key := Vector2i((g["pos"] as Vector2) / cell)
var nearest := cell
for dx in range(-1, 2):
for dy in range(-1, 2):
for other: Dictionary in buckets.get(key + Vector2i(dx, dy), []):
if not is_same(other, g):
nearest = minf(nearest, (g["pos"] as Vector2).distance_to(other["pos"]))
g["reach"] = clampf(nearest / 2.0 - GRAB_GAP / 2.0 / zoom, 4.0 / zoom, GRAB_RADIUS_MAX / zoom)
## The port on a card's bottom edge for card threads (CardThreads): in Build
## always (drag from it to add one), in Play only when the card has some.
func _outlet_port(t: RollTable, card: TableCard, build: bool, mouse: Vector2, below: int) -> void:
@ -142,7 +177,7 @@ func _outlet_port(t: RollTable, card: TableCard, build: bool, mouse: Vector2, be
if main.lit_pipes.has(Roller.pipe_key(t.id, RollTable.OUTLET_ID, to)):
fill = Style.ACCENT
ring = Style.ACCENT_DARK
if build and pos.distance_to(mouse) <= GRAB_RADIUS and not _linking:
if build and _hot_pos == pos and not _linking:
fill = Style.ACCENT
s = 1.2
_port(pos, fill, ring, s)
@ -190,7 +225,7 @@ func _gui_input(ev: InputEvent) -> void:
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
if mb.pressed:
for g in _grab:
if mb.position.distance_to(g["pos"]) <= GRAB_RADIUS:
if mb.position.distance_to(g["pos"]) <= g["reach"]:
_linking = true
_ghost_from = g["pos"]
_ghost_down = g["eid"] == RollTable.OUTLET_ID
@ -205,6 +240,7 @@ func _gui_input(ev: InputEvent) -> void:
return
var mm := ev as InputEventMouseMotion
if mm and _linking:
_ghost_to = mm.position
main.update_link()
var snap: Variant = main.link_snap_point()
_ghost_to = snap if snap != null else mm.position
accept_event()

View file

@ -27,14 +27,13 @@ func anchor_for(eid: String) -> Dictionary:
var row: Control = card.rows.get(eid, card.more_row)
if row == null or not row.is_inside_tree():
return {}
var to_world := card.main.board.world.get_global_transform().affine_inverse()
var r := row.get_global_rect()
var y := (to_world * (r.position + Vector2(0, r.size.y / 2.0))).y
var board := card.main.board
var y := board.world_rect_of(row).get_center().y
var shown := true
if card.list_scroll != null and card.rows.has(eid):
var sr := card.list_scroll.get_global_rect()
var top := (to_world * sr.position).y + 14.0
var bottom := (to_world * sr.end).y - 14.0
var scroll_rect := board.world_rect_of(card.list_scroll)
var top := scroll_rect.position.y + 14.0
var bottom := scroll_rect.end.y - 14.0
shown = y >= top - 4.0 and y <= bottom + 4.0
y = clampf(y, top, bottom)
return {"pos": Vector2(card.position.x + card.size.x, y), "visible": shown}

View file

@ -15,6 +15,10 @@ func gui_input(ev: InputEvent) -> void:
# ends, so scrolling past the last result doesn't start zooming.
var mb := ev as InputEventMouseButton
if mb and mb.button_index == MOUSE_BUTTON_LEFT:
# In Build, a click on the card's own body (no control took it) selects the card.
# (A click on a result row already selected that result; leave it.)
if mb.pressed and card.main.mode == Main.Mode.BUILD and not _is_inspected():
card.main.select_card(card.table.id)
card.accept_event()
elif mb and _wheel_in_list(mb):
card.accept_event()
@ -22,6 +26,12 @@ func gui_input(ev: InputEvent) -> void:
card.accept_event()
## True when the inspector already shows this card or one of its results.
func _is_inspected() -> bool:
var selection := card.main.inspector_selection()
return str(selection.get("tid", "")) == card.table.id and str(selection.get("kind", "")) != "pipe"
func _wheel_in_list(mb: InputEventMouseButton) -> bool:
if mb.button_index != MOUSE_BUTTON_WHEEL_UP and mb.button_index != MOUSE_BUTTON_WHEEL_DOWN:
return false