Draw scene symbols as white panel icons that make room for each other
The scene view drew its symbols from its own SVGs, each in a type colour and some on a plate. They looked heavier than the panel icons and were hard to read on busy ground. Symbols of different objects also sat on top of each other whenever their positions met. - Every symbol is now the panel icon of its kind, one file for both places. The scene-only SVGs in src/viewport/icons are gone. - Symbols are white in a thin dark outline with no plate behind them. haloSvg widens each shape of the file by its own stroke and draws that silhouette dark under the icon, so no second file is needed. - A butt stroke end would leave its end without outline. The halo caps such strokes square, and the rigidbody arrow shaft is now a filled rect so its top edge is outlined exactly. - Symbols are 18 world units across, stay upright and are clickable. A click selects the object, a drag moves it. - symbolLayout places every symbol on its object's position. Symbols that overlap stand on a ring round the middle of their positions, evenly spaced one icon apart. A ring that reaches into another symbol takes it in until nothing overlaps. Ownership plays no part. - Names sit beside their symbol, on the outside of a ring. Selection frames and parent links follow the symbol. - A collider icon no longer shows trigger or invalid state. The outline colour of the shape still does. - A lone collider sits on its sprite's middle again. A press there on an unselected sprite drags the collider, so e2e 02 and 16 now grab the sprite beside its middle. Hook __gm.container.objectRect helps 16 find that spot. Tests: - check.sh: 2245 tests, CHECK EXIT 0 (+8 for layout and halo) - e2e 1-16,31,39-43: 670 PASS, 2 FAIL. Both were sampling too strictly for the thinner, smaller icons. 5c looked for the exact outline colour, which the thin outline only reaches blended at this zoom. 31n started the ring scan one pixel past the smaller ring. Both are fixed, and e2e 5,31 then passed with 48 checks. - 5c checks white with an outline and none of the old colours, 41b checks the ring positions and that a click on a symbol selects its object, 31n checks the now white particle ring. - Counter-checks: without the halo only 5c fails, also with the looser outline match. Without the layout the ring and click checks in 41b fail. Originals restored by cmp. - The e2e check total stays 1351. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
e3d47ca9c1
commit
cb32b4bc23
22 files changed
+414
-176
No files matched your search
+4
-1
@@ -39,7 +39,10 @@ export const Theme = {
|
||||
danger: 0xe0553f,
|
||||
viewport: 0x121316,
|
||||
gizmo: 0x4c8dff,
|
||||
/** Behavior symbols and owner links. */
|
||||
/** Every symbol in the scene view: white, held off any ground by a dark outline. */
|
||||
symbol: 0xffffff,
|
||||
symbolOutline: 0x0b0c0f,
|
||||
/** Owner links of behaviors. */
|
||||
behavior: 0xb066ff,
|
||||
/** Collider outlines: solid (blocking) and trigger (events only). */
|
||||
collider: 0x4fd18b,
|
||||
|
||||
+1
-1
@@ -71,4 +71,4 @@ export {
|
||||
toHex,
|
||||
} from './color';
|
||||
export { pressCount } from './clicks';
|
||||
export { drawSvg, tintSvg } from './svg';
|
||||
export { drawSvg, haloSvg, tintSvg } from './svg';
|
||||
@@ -9,6 +9,32 @@ export function tintSvg(svg: string, color: number): string {
|
||||
return svg.replaceAll('currentColor', `#${color.toString(16).padStart(6, '0')}`);
|
||||
}
|
||||
|
||||
const SHAPE = /<(rect|circle|ellipse|path|polygon|polyline|line)\b([^>]*?)\s*\/>/g;
|
||||
|
||||
/**
|
||||
* The same file as a silhouette `width` units wider on every side: each shape keeps its fill and
|
||||
* gets a stroke of its own stroke plus twice `width`, all in `currentColor`. Drawn in a dark colour
|
||||
* under the file itself it is an outline that keeps a light icon readable on any ground.
|
||||
* A stroke that ends flat (`butt`, the default) would leave its ends without an outline, so the
|
||||
* halo caps it square – a little long by half the own stroke. An icon that wants an exact outline
|
||||
* at an open end draws that part as a filled shape.
|
||||
*/
|
||||
export function haloSvg(svg: string, width: number): string {
|
||||
return svg.replace(SHAPE, (_, tag: string, attrs: string) => {
|
||||
const fill = /\sfill="([^"]*)"/.exec(attrs)?.[1] ?? 'none';
|
||||
const stroke = /\sstroke="([^"]*)"/.exec(attrs)?.[1] ?? 'none';
|
||||
const own = stroke === 'none' ? 0 : Number(/\sstroke-width="([^"]*)"/.exec(attrs)?.[1] ?? 1);
|
||||
const cap = /\sstroke-linecap="([^"]*)"/.exec(attrs)?.[1] ?? 'butt';
|
||||
const geometry = attrs.replace(
|
||||
/\s(fill|stroke|stroke-width|stroke-linecap|fill-opacity|stroke-opacity)="[^"]*"/g,
|
||||
'',
|
||||
);
|
||||
const paint = fill === 'none' ? 'none' : 'currentColor';
|
||||
const ends = cap === 'butt' ? 'square' : cap;
|
||||
return `<${tag}${geometry} fill="${paint}" stroke="currentColor" stroke-width="${own + 2 * width}" stroke-linecap="${ends}" />`;
|
||||
});
|
||||
}
|
||||
|
||||
/** Parsed once per file and colour: a scene symbol is redrawn with every frame. */
|
||||
const parsed = new Map<string, Map<number, SVGElement>>();
|
||||
|
||||
|
||||
Reference in new issue
Block a user