feat(signage): slides keep their shape on any screen, custom shapes (21:9, 16:10…), Calibrate the picture edge by edge with presets
A slide is drawn at its playlist's shape, as large as fits the screen's picture, the bands in its own background (or stretched, the screen's choice). Playlists and library slides may have a shape of their own (aspect, Alembic 0045). Signage -> Screens -> Calibrate the picture: the TV outlines its area with arrows and its size, each edge moves pixel by pixel or a preset centres a shape; the TV follows live (signage.calibrate) and reports its window (POST /screen/viewport). Plan 6R.13, F-110. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,113 @@
|
||||
// Calibrating a screen's picture (6R.13, owner 2026-11-22). While this is open the TV outlines its
|
||||
// picture area with four arrows pointing out and shows its size; each edge moves in or out here
|
||||
// pixel by pixel (or in steps of 10 / 50 px), or a preset sets the largest box of a common shape in
|
||||
// the middle of the TV's window (it reports its size). Every change reaches the TV at once; closing
|
||||
// ends the calibration (the TV also stops by itself after 15 min).
|
||||
import { useCallback, useEffect, useRef, useState } from 'react'
|
||||
import toast from 'react-hot-toast'
|
||||
import { errorMessage } from '@xenia/api'
|
||||
import { useTranslation } from '@xenia/i18n'
|
||||
import { Button, Dialog, Field, NumberInput, Segmented } from '@xenia/ui'
|
||||
import { pictureArea, presetInsets, shapeName } from '@xenia/signage'
|
||||
import * as api from './signageApi'
|
||||
import { ShapeMark } from './ShapeField'
|
||||
|
||||
const EDGES = ['top', 'right', 'bottom', 'left']
|
||||
const PRESETS = ['full', '16:9', '16:10', '21:9', '32:9', '4:3', '9:16']
|
||||
const SAVE_MS = 200
|
||||
|
||||
export default function CalibrateDialog({ screen, onClose, onSaved }) {
|
||||
const { t } = useTranslation('manager')
|
||||
const [area, setArea] = useState(screen.area || { left: 0, top: 0, right: 0, bottom: 0 })
|
||||
const [viewport, setViewport] = useState(screen.viewport || null)
|
||||
const [step, setStep] = useState(1)
|
||||
const timer = useRef(null)
|
||||
const latest = useRef(area)
|
||||
|
||||
// on while open; off when closed
|
||||
useEffect(() => {
|
||||
api.calibrateScreen(screen.id, true).catch(err => toast.error(errorMessage(err, t)))
|
||||
return () => { api.calibrateScreen(screen.id, false).catch(() => {}) }
|
||||
}, [screen.id]) // eslint-disable-line react-hooks/exhaustive-deps
|
||||
// the TV's window size (it reports it when it starts and when it changes)
|
||||
useEffect(() => {
|
||||
const id = setInterval(() => {
|
||||
api.listScreens().then(list => setViewport(list.find(s => s.id === screen.id)?.viewport || null)).catch(() => {})
|
||||
}, 2000)
|
||||
return () => clearInterval(id)
|
||||
}, [screen.id])
|
||||
|
||||
const send = useCallback(() => {
|
||||
const a = latest.current
|
||||
api.updateScreen(screen.id, { area_left: a.left, area_top: a.top, area_right: a.right, area_bottom: a.bottom })
|
||||
.then(onSaved).catch(err => toast.error(errorMessage(err, t)))
|
||||
}, [screen.id, onSaved, t])
|
||||
const change = next => {
|
||||
latest.current = next
|
||||
setArea(next)
|
||||
clearTimeout(timer.current)
|
||||
timer.current = setTimeout(send, SAVE_MS)
|
||||
}
|
||||
useEffect(() => () => clearTimeout(timer.current), [])
|
||||
const win = viewport ? { w: viewport.width, h: viewport.height } : null
|
||||
const pic = win ? pictureArea(win, area) : null
|
||||
const setEdge = (edge, v) => change({ ...area, [edge]: Math.max(0, Math.min(4000, v ?? 0)) })
|
||||
|
||||
// the diagram: the TV's window and the picture inside it, to scale
|
||||
const W = 320
|
||||
const H = win ? Math.round(W * win.h / win.w) : 180
|
||||
const k = win ? W / win.w : 0
|
||||
const edge = e => (
|
||||
<Field label={t(`signage.calibrate.edges.${e}`)} className="w-36">
|
||||
<NumberInput size="sm" value={area[e]} min={0} max={4000} step={step} suffix="px" onChange={v => setEdge(e, v)} data-testid={`signage-calibrate-${e}`} />
|
||||
</Field>
|
||||
)
|
||||
return (
|
||||
<Dialog open size="lg" onClose={onClose} title={t('signage.calibrate.title', { name: screen.name })} description={t('signage.calibrate.intro')}
|
||||
footer={<>
|
||||
<Button variant="secondary" onClick={() => change({ left: 0, top: 0, right: 0, bottom: 0 })} data-testid="signage-calibrate-reset">{t('signage.calibrate.reset')}</Button>
|
||||
<Button onClick={onClose} data-testid="signage-calibrate-done">{t('signage.calibrate.done')}</Button>
|
||||
</>}>
|
||||
<div className="grid gap-5" data-testid="signage-calibrate-dialog">
|
||||
<p className="text-label text-ink-2" data-testid="signage-calibrate-window">
|
||||
{win ? t('signage.calibrate.window', { w: win.w, h: win.h, shape: shapeName(win.w, win.h) }) : t('signage.calibrate.waiting')}
|
||||
</p>
|
||||
<div className="grid gap-2">
|
||||
<span className="text-label font-medium text-ink">{t('signage.calibrate.presets')}</span>
|
||||
<div className="flex flex-wrap gap-1.5">
|
||||
{PRESETS.map(p => (
|
||||
<Button key={p} size="sm" variant="secondary" disabled={!win} onClick={() => change(presetInsets(win, p))} data-preset={p}
|
||||
icon={p === 'full' ? undefined : <ShapeMark shape={p} size={16} />}>
|
||||
{p === 'full' ? t('signage.calibrate.full') : p}
|
||||
</Button>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
<div className="flex flex-wrap items-center gap-3">
|
||||
<span className="text-label font-medium text-ink">{t('signage.calibrate.step')}</span>
|
||||
<Segmented value={step} onChange={setStep} options={[1, 10, 50].map(n => ({ value: n, label: `${n} px` }))} data-testid="signage-calibrate-step" />
|
||||
</div>
|
||||
<div className="grid justify-items-center gap-2">
|
||||
{edge('top')}
|
||||
<div className="flex items-center gap-3 flex-wrap justify-center">
|
||||
{edge('left')}
|
||||
<div className="relative rounded-control border border-line-strong bg-surface-2" style={{ width: W, height: H }} aria-hidden="true">
|
||||
{pic && (
|
||||
<div className="absolute border-2 border-accent bg-accent-soft grid place-items-center text-caption text-accent-ink tabular-nums"
|
||||
style={{ left: pic.left * k, top: pic.top * k, width: pic.width * k, height: pic.height * k }}>
|
||||
{Math.round(pic.width)} × {Math.round(pic.height)}
|
||||
</div>
|
||||
)}
|
||||
</div>
|
||||
{edge('right')}
|
||||
</div>
|
||||
{edge('bottom')}
|
||||
</div>
|
||||
<p className="text-label text-ink-2 text-center" data-testid="signage-calibrate-picture">
|
||||
{pic ? t('signage.calibrate.picture', { w: Math.round(pic.width), h: Math.round(pic.height), shape: shapeName(pic.width, pic.height) }) : ''}
|
||||
</p>
|
||||
{EDGES.some(e => area[e] > 0) && <p className="text-caption text-ink-3">{t('signage.calibrate.outside')}</p>}
|
||||
</div>
|
||||
</Dialog>
|
||||
)
|
||||
}
|
||||
Reference in New Issue
Block a user