diff --git a/app/assets/css/main.css b/app/assets/css/main.css index 99125fd..f670aee 100644 --- a/app/assets/css/main.css +++ b/app/assets/css/main.css @@ -6314,3 +6314,40 @@ button.tile:hover { .scope-chan .scope-bits { width: 52px; } + +/* Screens: size by the corner */ +.node .frame { + image-rendering: pixelated; + pointer-events: none; +} + +.node .resize-grip { + fill: var(--accent); + stroke: var(--bg); + stroke-width: 1.5; + cursor: nwse-resize; +} + +.node .size-badge { + fill: var(--accent); + font-size: 10px; + font-weight: 600; + pointer-events: none; +} + +.size-row { + display: flex; + align-items: center; + gap: 6px; +} + +.size-row .field-input { + width: 70px; +} + +.size-presets { + display: flex; + flex-wrap: wrap; + gap: 4px; + margin-top: 6px; +} diff --git a/app/components/editor/Canvas.vue b/app/components/editor/Canvas.vue index 0d500d7..690b0fc 100644 --- a/app/components/editor/Canvas.vue +++ b/app/components/editor/Canvas.vue @@ -11,6 +11,7 @@ import type { CanvasOps, MenuEntry } from '~/composables/useMenu' import { cableInUse, LANE, plugLayout, ribbon, RIBBON_MAX } from '~/lib/logic/cables' import { latchLayout, latchSeam } from '~/lib/logic/latch' import { keyCode } from '~/lib/logic/devices' +import { displayLayout, displaySize } from '~/lib/logic/displays' import { moveParts, moveStart, type MoveStart } from '~/lib/logic/move' import { wirePath, type HopSpan } from '~/lib/draw' import { downloadSheet, printSheet, sheetSvg } from '~/lib/sheet' @@ -639,6 +640,14 @@ function onDrop(e: DragEvent) { // ── Pointer interaction ───────────────────────────────────────────── type Drag = + | { + /** A screen's corner: its size in characters or pixels follows. */ + kind: 'resize' + node: CircuitNode + start: Pt + size: [number, number] + cell: [number, number] + } | { kind: 'pan' sx: number @@ -758,6 +767,13 @@ function onPointerDown(e: PointerEvent) { } const target = e.target as Element + const resizeEl = target.closest('[data-resize]') + const resizing = resizeEl ? nodeMap.value.get(resizeEl.closest('[data-node]')?.getAttribute('data-node') ?? '') : undefined + if (resizing) { + const l = displayLayout(resizing) + drag.value = { kind: 'resize', node: resizing, start: w, size: displaySize(resizing), cell: [l.cw, l.ch] } + return + } const actionEl = target.closest('[data-action]') if (actionEl) return actionButtons.value.find(b => b.key === actionEl.getAttribute('data-action'))?.run(e) const widenEl = target.closest('[data-inputs]') @@ -902,6 +918,9 @@ function onPointerMove(e: PointerEvent) { const d = drag.value if (!d) return trackHover(e.target as Element) switch (d.kind) { + case 'resize': + ed.setDims(d.node.id, d.size[0] + Math.round((w[0] - d.start[0]) / d.cell[0]), d.size[1] + Math.round((w[1] - d.start[1]) / d.cell[1]), false) + break case 'pan': ed.views[def.value.id] = { ...view.value, x: d.vx + e.clientX - d.sx, y: d.vy + e.clientY - d.sy } break @@ -1152,6 +1171,9 @@ function onPointerUp(e: PointerEvent) { drag.value = null if (!d) return switch (d.kind) { + case 'resize': + ed.commit() + break case 'pan': if (d.menu && Math.abs(e.clientX - d.sx) + Math.abs(e.clientY - d.sy) < 5) openMenuAt(d.menu.target, d.menu.at, e.clientX, e.clientY) break diff --git a/app/components/editor/NodeSettings.vue b/app/components/editor/NodeSettings.vue index 610af55..4cc3c2a 100644 --- a/app/components/editor/NodeSettings.vue +++ b/app/components/editor/NodeSettings.vue @@ -6,6 +6,7 @@ import { cableOf } from '~/lib/logic/cables' import { INVERTIBLE } from '~/lib/logic/compile' import { cableBits, cableOffsets, chipPins, MAX_BITS, panelOffsets, portName, rowLabel } from '~/lib/logic/geometry' import { SINK_KINDS, SOURCE_KINDS, uid } from '~/lib/logic/ops' +import { DISPLAY_SIZES, displaySize, isDisplay, ratioText, type DisplayKind } from '~/lib/logic/displays' import { KIND_NAMES } from '~/lib/logic/progress' import { baseOf, gateFamily, inputCount, MAX_GATE_INPUTS } from '~/lib/logic/wide' import { LAMP_COLORS, WIRE_COLORS, type CircuitNode, type NodeKind, type PanelControl, type PanelRow } from '~/lib/logic/types' @@ -345,6 +346,9 @@ function setRowHz(row: PanelRow, e: Event) { ed.commit() } +/** Monitor sizes a click away. */ +const SIZE_PRESETS: [number, number][] = [[16, 16], [32, 32], [64, 32], [64, 64], [128, 64], [128, 128]] + /** Logic analyzer channels. */ function addChannel(bits: number) { const used = new Set((n.value.scope?.cols ?? []).map(c => c.name)) @@ -712,6 +716,19 @@ function setChannelBits(i: number, v: string) { +
+ Size in {{ DISPLAY_SIZES[n.kind as DisplayKind].unit }} +
+ + × + + +
+
+ +
+
+
Channels: wire to their pins on the left
diff --git a/app/components/editor/NodeView.vue b/app/components/editor/NodeView.vue index 0b044a9..4726b8d 100644 --- a/app/components/editor/NodeView.vue +++ b/app/components/editor/NodeView.vue @@ -5,7 +5,8 @@ import { baseOf, gateFamily, inputCount, MAX_GATE_INPUTS } from '~/lib/logic/wid import { faceTransform, GRID as G, noteLines, noteScale, PANEL_CONTROL_W, portLines, rgbHex, shapeTransform, type Shape } from '~/lib/logic/geometry' import { benchLayout } from '~/lib/logic/benchLayout' import { SCOPE_CELL, SCOPE_SAMPLES, scopeLayout } from '~/lib/logic/scopeLayout' -import { keyLabel, TERMINAL_COLS, TERMINAL_LINES } from '~/lib/logic/devices' +import { keyLabel } from '~/lib/logic/devices' +import { displayLayout, displaySize, isDisplay, MONO_PIXEL, ratioText, RGB_PIXEL, TERM_CHAR } from '~/lib/logic/displays' import type { CircuitNode } from '~/lib/logic/types' const props = defineProps<{ @@ -257,16 +258,44 @@ const bench = computed(() => { return { state: r?.fail || (r?.error && !r.pass) ? 'fail' : r?.pass ? 'pass' : 'idle', line, cols, rows, right } }) -// Terminal and keyboard: what the store keeps for this part. -const TERM_CHAR = 6.6 +// Terminal and monitors: what the store keeps for this part, and its size. +const display = computed(() => isDisplay(props.node.kind)) +const dl = computed(() => (display.value ? displayLayout(props.node) : { w: 0, h: 0, sx: 0, sy: 0, sw: 0, sh: 0, cw: 0, ch: 0 })) +const TERM_PX = TERM_CHAR * G +const sizeText = computed(() => { + if (!display.value) return '' + const [w, h] = displaySize(props.node) + return props.node.kind === 'terminal' ? `${w} × ${h} characters` : `${w} × ${h} · ${ratioText(w, h)}` +}) const termLines = computed(() => { if (props.node.kind !== 'terminal' || props.ghost) return [] void ed.devVersion.value - return (ed.screens.value.get(props.node.id) ?? ['']).slice(-TERMINAL_LINES) + return (ed.screens.value.get(props.node.id) ?? ['']).slice(-displaySize(props.node)[1]) }) const termCursor = computed(() => { const lines = termLines.value.length ? termLines.value : [''] - return { x: Math.min(TERMINAL_COLS - 1, lines[lines.length - 1]!.length), y: lines.length - 1 } + return { x: Math.min(displaySize(props.node)[0] - 1, lines[lines.length - 1]!.length), y: lines.length - 1 } +}) +/** A monitor's pixels as an image, made again when they change. */ +const frameUrl = computed(() => { + const n = props.node + if ((n.kind !== 'monitor' && n.kind !== 'rgbmonitor') || props.ghost || typeof document === 'undefined') return '' + void ed.devVersion.value + const f = ed.frames.value.get(n.id) + if (!f) return '' + const c = document.createElement('canvas') + c.width = f.w + c.height = f.h + const ctx = c.getContext('2d') + if (!ctx) return '' + const img = ctx.createImageData(f.w, f.h) + const palette = (n.kind === 'rgbmonitor' ? RGB_PIXEL : ['#000000', MONO_PIXEL]).map(h => [parseInt(h.slice(1, 3), 16), parseInt(h.slice(3, 5), 16), parseInt(h.slice(5, 7), 16)]) + for (let i = 0; i < f.px.length; i++) { + const [r, g, bl] = palette[f.px[i]!] ?? palette[0]! + img.data.set([r!, g!, bl!, f.px[i] ? 255 : 0], i * 4) + } + ctx.putImageData(img, 0, 0) + return c.toDataURL() }) const kbTyping = computed(() => ed.typingInto.value === props.node.id) const kbWaiting = computed(() => { @@ -550,14 +579,21 @@ const title = computed(() => { {{ p.label }} - -