forked from Blendman974/faceclaw
Apps submit mutli-plane images with glyphs, rather than mere images
This commit is contained in:
1 parent
df85fb4072
commit
fdf683761e
22 files changed
+348
-101
No files matched your search
+33
-15
@@ -1,5 +1,5 @@
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../graphics/image";
|
||||
import { BdfFont } from "../graphics/bdffont";
|
||||
import { type Plane } from "../graphics/plane";
|
||||
import { spanCurrent } from "../native/frame-timings";
|
||||
import { type ConfigSettingString } from "./dashboard-settings";
|
||||
|
||||
@@ -58,6 +58,18 @@ export const noopLayerActions: LayerActions = {
|
||||
playBuzzerSequence: () => {},
|
||||
};
|
||||
|
||||
/**
|
||||
* Hands a layer its paint canvas: a fresh transparent (0-filled) image the
|
||||
* size of the stack. Calling it also declares that the layers below should
|
||||
* stay visible beneath this layer — each layer becomes its own plane, so a
|
||||
* layer that never calls paintBelow fully replaces what is under it (its
|
||||
* plane is submitted alone), while one that does gets composited above the
|
||||
* planes below. Repeat calls return the same canvas.
|
||||
*
|
||||
* Note the plane model's occlusion rule: raster painted onto the canvas
|
||||
* covers lower planes entirely (including their text), but glyphs drawn into
|
||||
* the *same* image always render above that image's own raster.
|
||||
*/
|
||||
export type PaintBelow = () => GrayImage;
|
||||
|
||||
function notifyRemoved(layer: Layer | undefined): void {
|
||||
@@ -153,7 +165,12 @@ export class LayerStack {
|
||||
Object.assign(this.ctx.actions, actions);
|
||||
}
|
||||
|
||||
paint(): GrayImage {
|
||||
/**
|
||||
* Paint the stack as planes, bottom to top: the top layer's plane last,
|
||||
* preceded by the planes of the layers it asked to remain visible (see
|
||||
* PaintBelow). All planes share the stack's base size at offset (0, 0).
|
||||
*/
|
||||
paint(): Plane[] {
|
||||
return this.paintLayer(this.layers.length - 1);
|
||||
}
|
||||
|
||||
@@ -161,23 +178,24 @@ export class LayerStack {
|
||||
await this.layers[this.layers.length - 1]!.handleInput(event, this.ctx);
|
||||
}
|
||||
|
||||
private paintLayer(index: number): GrayImage {
|
||||
private paintLayer(index: number): Plane[] {
|
||||
const layer = this.layers[index]!;
|
||||
let cachedBelow: GrayImage | null = null;
|
||||
return spanCurrent(`paint[${index}]:${layer.constructor.name}`, () =>
|
||||
let canvas: GrayImage | null = null;
|
||||
let belowRequested = false;
|
||||
const image = spanCurrent(`paint[${index}]:${layer.constructor.name}`, () =>
|
||||
layer.paint(this.ctx, () => {
|
||||
if (cachedBelow) {
|
||||
return cachedBelow;
|
||||
belowRequested = true;
|
||||
if (!canvas) {
|
||||
canvas = new GrayImage(this.baseWidth, this.baseHeight, 0);
|
||||
}
|
||||
if (index <= 0) {
|
||||
cachedBelow = new GrayImage(this.baseWidth, this.baseHeight, 0);
|
||||
} else if (layer.paintOverBase) {
|
||||
cachedBelow = this.paintLayer(0);
|
||||
} else {
|
||||
cachedBelow = this.paintLayer(index - 1);
|
||||
}
|
||||
return cachedBelow;
|
||||
return canvas;
|
||||
}),
|
||||
);
|
||||
const ownPlane: Plane = { image, x: 0, y: 0 };
|
||||
if (index <= 0 || !belowRequested) {
|
||||
return [ownPlane];
|
||||
}
|
||||
const below = layer.paintOverBase ? this.paintLayer(0) : this.paintLayer(index - 1);
|
||||
return [...below, ownPlane];
|
||||
}
|
||||
}
|
||||
@@ -1,4 +1,5 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { type Plane } from "../../graphics/plane";
|
||||
import * as frameTimings from "../../native/frame-timings";
|
||||
import { beginRenderPass, endRenderPass } from "../../util/render-freshness";
|
||||
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
|
||||
@@ -37,7 +38,7 @@ export type InProcessWindowOptions = {
|
||||
/** Shared actions; requestRender is rebound to this window's render. */
|
||||
actions: LayerActions;
|
||||
baseLayer: Layer;
|
||||
submitFrame: (image: GrayImage, paintMs: number, frameId: number) => Promise<void>;
|
||||
submitFrame: (planes: Plane[], paintMs: number, frameId: number) => Promise<void>;
|
||||
setSurfaceVisible: (visible: boolean) => void;
|
||||
removeSurface?: () => void;
|
||||
onClosed?: () => void;
|
||||
@@ -52,7 +53,7 @@ export type InProcessWindow = {
|
||||
/** The controller-provided plumbing common to every in-process app window. */
|
||||
export type InProcessAppOptions = {
|
||||
actions: LayerActions;
|
||||
submitFrame: (image: GrayImage, paintMs: number, frameId: number) => Promise<void>;
|
||||
submitFrame: (planes: Plane[], paintMs: number, frameId: number) => Promise<void>;
|
||||
setSurfaceVisible: (visible: boolean) => void;
|
||||
removeSurface: () => void;
|
||||
onClosed: () => void;
|
||||
@@ -89,9 +90,9 @@ export function createInProcessWindow(options: InProcessWindowOptions): InProces
|
||||
nextRenderWantsFreshData = false;
|
||||
beginRenderPass(!wantFreshData);
|
||||
const paintStartedAtMs = Date.now();
|
||||
const image = stack.paint();
|
||||
const planes = stack.paint();
|
||||
const paintUsedStaleData = endRenderPass();
|
||||
await options.submitFrame(image, Date.now() - paintStartedAtMs, frameId);
|
||||
await options.submitFrame(planes, Date.now() - paintStartedAtMs, frameId);
|
||||
if (paintUsedStaleData) {
|
||||
nextRenderWantsFreshData = true;
|
||||
requestRender();
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { flattenPlanes } from "../../graphics/plane";
|
||||
import { DashboardInputEvent, Layer, LayerActions, LayerContext, LayerStack, PaintBelow } from "../layers";
|
||||
import { appViewportRect, appViewportSize, SHELL_OPAQUE_BLACK } from "./geometry";
|
||||
|
||||
@@ -43,7 +44,9 @@ export class ShellModalLayer implements Layer {
|
||||
|
||||
paint(ctx: LayerContext, paintBelow: PaintBelow): GrayImage {
|
||||
const image = paintBelow();
|
||||
const inner = this.stack.paint();
|
||||
// Flattening bakes the inner stack's planes (glyphs included) so the blit
|
||||
// below transplants the finished modal content into this layer's plane.
|
||||
const inner = flattenPlanes(this.stack.paint(), MODAL_INTERIOR);
|
||||
const rect = modalRect();
|
||||
image.fillRoundedRect(rect.x, rect.y, rect.width, rect.height, SHELL_OPAQUE_BLACK, 8);
|
||||
image.drawRoundedRect(rect.x, rect.y, rect.width, rect.height, 110, 8);
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { G2_LENS_HEIGHT, G2_LENS_WIDTH, GrayImage } from "../../graphics/image";
|
||||
import { singlePlane, type Plane } from "../../graphics/plane";
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { EvenAIStatus, EventSourceType, OsEventTypeList } from "../../g2/events";
|
||||
import type { RawInputEvent } from "../../native/faceclaw-communicator";
|
||||
@@ -470,9 +471,9 @@ class Shell {
|
||||
}
|
||||
|
||||
/** Paint the shell surface: transparent chrome, or all-transparent when asleep. */
|
||||
paintSurface(): GrayImage {
|
||||
paintSurface(): Plane[] {
|
||||
if (!this.screenOn) {
|
||||
return new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0);
|
||||
return singlePlane(new GrayImage(G2_LENS_WIDTH, G2_LENS_HEIGHT, 0));
|
||||
}
|
||||
return this.stack.paint();
|
||||
}
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
import { GrayImage } from "../graphics/image";
|
||||
import { singlePlane, type Plane } from "../graphics/plane";
|
||||
import {
|
||||
noopLayerActions,
|
||||
LayerStack,
|
||||
@@ -61,8 +62,8 @@ export class WindowMenu {
|
||||
}
|
||||
|
||||
/** Paint the window content with the menu over it (content alone if closed). */
|
||||
paint(): GrayImage {
|
||||
return this.stack ? this.stack.paint() : this.options.paintBase();
|
||||
paint(): Plane[] {
|
||||
return this.stack ? this.stack.paint() : singlePlane(this.options.paintBase());
|
||||
}
|
||||
|
||||
/** Route an input event to the menu; the menu closes by popping itself. */
|
||||
|
||||
Reference in new issue
Block a user