forked from Blendman974/faceclaw
Add a resource-usage monitor to debug app; fix excessive memory-usage from screen preview when not focused
This commit is contained in:
1 parent
b5213170e3
commit
9ade3503a0
6 files changed
+331
-7
No files matched your search
@@ -1,6 +1,7 @@
|
||||
import { getDefaultSmallFont } from "../../graphics/bdffont";
|
||||
import { GrayImage } from "../../graphics/image";
|
||||
import { Layer, type DashboardInputEvent, type LayerContext } from "../../ui/layers";
|
||||
import { drawListScrollbar } from "../../ui/menu";
|
||||
|
||||
const COLOR_VALUE_COUNT = 256;
|
||||
const COLOR_VALUE_STEP = 1;
|
||||
@@ -10,8 +11,11 @@ const LABEL_Y_OFFSET = 0;
|
||||
const SWATCH_Y_OFFSET = 12;
|
||||
const SWATCH_WIDTH = 24;
|
||||
const SWATCH_HEIGHT = 16;
|
||||
const GRID_ROWS = Math.ceil(COLOR_VALUE_COUNT / GRID_COLUMNS);
|
||||
|
||||
export class ScreenTestLayer implements Layer {
|
||||
private scrollRow = 0;
|
||||
|
||||
paint(ctx: LayerContext): GrayImage {
|
||||
// Sized to the hosting stack (the Debug tests app viewport).
|
||||
const { width, height } = ctx.stack.getBaseSize();
|
||||
@@ -19,13 +23,17 @@ export class ScreenTestLayer implements Layer {
|
||||
const font = getDefaultSmallFont();
|
||||
const cellWidth = Math.floor(width / GRID_COLUMNS);
|
||||
const gridX = Math.floor((width - cellWidth * GRID_COLUMNS) / 2);
|
||||
const visibleRows = Math.max(1, Math.ceil(height / CELL_HEIGHT));
|
||||
const maxScrollRow = Math.max(0, GRID_ROWS - visibleRows);
|
||||
this.scrollRow = Math.max(0, Math.min(maxScrollRow, this.scrollRow));
|
||||
|
||||
for (let value = 0; value < COLOR_VALUE_COUNT; value += COLOR_VALUE_STEP) {
|
||||
const slot = value / COLOR_VALUE_STEP;
|
||||
const col = slot % GRID_COLUMNS;
|
||||
const row = Math.floor(slot / GRID_COLUMNS);
|
||||
const cellX = gridX + col * cellWidth;
|
||||
const cellY = row * CELL_HEIGHT;
|
||||
const cellY = (row - this.scrollRow) * CELL_HEIGHT;
|
||||
if (cellY >= height || cellY + CELL_HEIGHT <= 0) continue;
|
||||
const label = String(value);
|
||||
const labelX = cellX + Math.max(0, Math.floor((cellWidth - font.measureText(label)) / 2));
|
||||
const swatchX = cellX + Math.floor((cellWidth - SWATCH_WIDTH) / 2);
|
||||
@@ -34,12 +42,27 @@ export class ScreenTestLayer implements Layer {
|
||||
fillSwatch(image, swatchX, cellY + SWATCH_Y_OFFSET, SWATCH_WIDTH, SWATCH_HEIGHT, value);
|
||||
}
|
||||
|
||||
if (GRID_ROWS > visibleRows) {
|
||||
drawListScrollbar(image, width - 4, 2, height - 4, this.scrollRow, visibleRows, GRID_ROWS);
|
||||
}
|
||||
|
||||
return image;
|
||||
}
|
||||
|
||||
handleInput(event: DashboardInputEvent, ctx: LayerContext): void {
|
||||
if (event.type === "double-click") {
|
||||
ctx.stack.pop();
|
||||
switch (event.type) {
|
||||
case "scroll-up":
|
||||
this.scrollRow = Math.max(0, this.scrollRow - 1);
|
||||
return;
|
||||
case "scroll-down": {
|
||||
const { height } = ctx.stack.getBaseSize();
|
||||
const visibleRows = Math.max(1, Math.ceil(height / CELL_HEIGHT));
|
||||
this.scrollRow = Math.min(Math.max(0, GRID_ROWS - visibleRows), this.scrollRow + 1);
|
||||
return;
|
||||
}
|
||||
case "double-click":
|
||||
ctx.stack.pop();
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -70,4 +93,4 @@ function ditherPattern(x: number, y: number, fillFraction: number): number {
|
||||
];
|
||||
const patternValue = pattern[y % 4][x % 4];
|
||||
return (fillFraction > patternValue) ? 1 : 0;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user