forked from Blendman974/faceclaw
Merge main into ios-port and update the iOS CFW transport
This commit is contained in:
commit
e8e144f3f2
156 files changed
+10528
-1679
No files matched your search
+62
-23
@@ -1,20 +1,36 @@
|
||||
import { GrayImage, imageFromAsciiArt } from "./image";
|
||||
|
||||
const EMPTY_BATTERY_ICON = imageFromAsciiArt(
|
||||
[
|
||||
" ################## ",
|
||||
" #................# ",
|
||||
" #................###",
|
||||
" #................###",
|
||||
" #................###",
|
||||
" #................###",
|
||||
" #................###",
|
||||
" #................###",
|
||||
" #................# ",
|
||||
" ################## ",
|
||||
],
|
||||
120,
|
||||
);
|
||||
/**
|
||||
* Top-bar battery gauge: a 10px-tall outlined body with a nub on the right,
|
||||
* filled left-to-right in proportion to the charge. The fill is drawn as
|
||||
* BATTERY_BAR_COUNT bars of BATTERY_BAR_WIDTH px separated by dimmed
|
||||
* BATTERY_BAR_GAP-px columns; the body outline is sized from those
|
||||
* constants so they can be tuned freely. The fill level is continuous (not
|
||||
* quantized to whole bars): the rightmost lit bar is cut to a partial width.
|
||||
*/
|
||||
export const BATTERY_BAR_COUNT = 4;
|
||||
export const BATTERY_BAR_WIDTH = 3;
|
||||
export const BATTERY_BAR_GAP = 1;
|
||||
|
||||
const OUTLINE_VALUE = 120;
|
||||
const BAR_VALUE = 190;
|
||||
/** The separator columns inside the lit portion of the fill. */
|
||||
const BAR_GAP_VALUE = 70;
|
||||
|
||||
const ICON_HEIGHT = 10;
|
||||
/** Outline stroke plus one clear pixel between it and the fill, per side. */
|
||||
const BODY_INSET = 2;
|
||||
const NUB_WIDTH = 2;
|
||||
const NUB_TOP = 2;
|
||||
const NUB_HEIGHT = 6;
|
||||
|
||||
const FILL_X = BODY_INSET;
|
||||
const FILL_Y = BODY_INSET;
|
||||
const FILL_WIDTH = BATTERY_BAR_COUNT * BATTERY_BAR_WIDTH + (BATTERY_BAR_COUNT - 1) * BATTERY_BAR_GAP;
|
||||
const FILL_HEIGHT = ICON_HEIGHT - 2 * BODY_INSET;
|
||||
const BODY_WIDTH = FILL_WIDTH + 2 * BODY_INSET;
|
||||
|
||||
export const BATTERY_ICON_WIDTH = BODY_WIDTH + NUB_WIDTH;
|
||||
|
||||
const BATTERY_BOLT_ICON = imageFromAsciiArt(
|
||||
[
|
||||
@@ -29,25 +45,48 @@ const BATTERY_BOLT_ICON = imageFromAsciiArt(
|
||||
255,
|
||||
);
|
||||
|
||||
export const BATTERY_ICON_WIDTH = EMPTY_BATTERY_ICON.width;
|
||||
/** The empty outline, built once from the geometry constants. */
|
||||
const EMPTY_BATTERY_ICON = buildEmptyBattery();
|
||||
|
||||
const BATTERY_FILL_X = 3;
|
||||
const BATTERY_FILL_Y = 2;
|
||||
const BATTERY_FILL_WIDTH = 14;
|
||||
const BATTERY_FILL_HEIGHT = 6;
|
||||
function buildEmptyBattery(): GrayImage {
|
||||
const icon = new GrayImage(BATTERY_ICON_WIDTH, ICON_HEIGHT, 0);
|
||||
icon.fillRect(0, 0, BODY_WIDTH, 1, OUTLINE_VALUE);
|
||||
icon.fillRect(0, ICON_HEIGHT - 1, BODY_WIDTH, 1, OUTLINE_VALUE);
|
||||
icon.fillRect(0, 0, 1, ICON_HEIGHT, OUTLINE_VALUE);
|
||||
icon.fillRect(BODY_WIDTH - 1, 0, 1, ICON_HEIGHT, OUTLINE_VALUE);
|
||||
icon.fillRect(BODY_WIDTH, NUB_TOP, NUB_WIDTH, NUB_HEIGHT, OUTLINE_VALUE);
|
||||
return icon;
|
||||
}
|
||||
|
||||
export function drawBattery(percentCharge: number, isCharging: boolean): GrayImage {
|
||||
const icon = new GrayImage(EMPTY_BATTERY_ICON.width, EMPTY_BATTERY_ICON.height, 0);
|
||||
icon.bitBlt(EMPTY_BATTERY_ICON, 0, 0);
|
||||
const clamped = Math.max(0, Math.min(100, percentCharge));
|
||||
const fillWidth = Math.round((BATTERY_FILL_WIDTH * clamped) / 100);
|
||||
icon.fillRect(BATTERY_FILL_X, BATTERY_FILL_Y, fillWidth, BATTERY_FILL_HEIGHT, 190);
|
||||
const litWidth = Math.round((FILL_WIDTH * clamped) / 100);
|
||||
drawSegmentedFill(icon, litWidth);
|
||||
if (isCharging) {
|
||||
overlayImage(icon, BATTERY_BOLT_ICON, 7, 1, clamped > 50 ? 0 : 255);
|
||||
const boltX = FILL_X + (((FILL_WIDTH - BATTERY_BOLT_ICON.width) / 2) | 0);
|
||||
overlayImage(icon, BATTERY_BOLT_ICON, boltX, 1, clamped > 50 ? 0 : 255);
|
||||
}
|
||||
return icon;
|
||||
}
|
||||
|
||||
/**
|
||||
* Light the leftmost `litWidth` columns of the fill area as bars with dim
|
||||
* separator columns. Columns past the lit width stay clear, so a partial
|
||||
* charge ends mid-bar rather than snapping to a bar boundary. A separator is
|
||||
* only drawn between two lit bars: when the lit width ends exactly on one it
|
||||
* is left clear rather than dangling past the last bar.
|
||||
*/
|
||||
function drawSegmentedFill(icon: GrayImage, litWidth: number): void {
|
||||
const pitch = BATTERY_BAR_WIDTH + BATTERY_BAR_GAP;
|
||||
for (let column = 0; column < litWidth; column++) {
|
||||
const isBar = column % pitch < BATTERY_BAR_WIDTH;
|
||||
if (!isBar && column + BATTERY_BAR_GAP >= litWidth) continue;
|
||||
icon.fillRect(FILL_X + column, FILL_Y, 1, FILL_HEIGHT, isBar ? BAR_VALUE : BAR_GAP_VALUE);
|
||||
}
|
||||
}
|
||||
|
||||
function overlayImage(target: GrayImage, source: GrayImage, dx: number, dy: number, value: number): void {
|
||||
for (let y = 0; y < source.height; y++) {
|
||||
for (let x = 0; x < source.width; x++) {
|
||||
|
||||
@@ -16,6 +16,10 @@ const ICON_STROKE_WIDTH = 2;
|
||||
// Lucide icons (MIT/ISC licensed). Kept verbatim so they can be diffed
|
||||
// against upstream if an icon needs updating.
|
||||
export const ICON_SVGS = {
|
||||
"message-circle":
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M21 11.5a8.4 8.4 0 0 1-.9 3.8 8.5 8.5 0 0 1-7.6 4.7 8.4 8.4 0 0 1-3.8-.9L3 21l1.9-5.7a8.4 8.4 0 0 1-.9-3.8 8.5 8.5 0 0 1 4.7-7.6 8.4 8.4 0 0 1 3.8-.9h.5a8.5 8.5 0 0 1 8 8z"/></svg>',
|
||||
eye:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M2.062 12.348a1 1 0 0 1 0-.696 10.75 10.75 0 0 1 19.876 0 1 1 0 0 1 0 .696 10.75 10.75 0 0 1-19.876 0"/><circle cx="12" cy="12" r="3"/></svg>',
|
||||
"layout-grid":
|
||||
'<svg viewBox="0 0 24 24" fill="none"><rect width="7" height="7" x="3" y="3" rx="1"/><rect width="7" height="7" x="14" y="3" rx="1"/><rect width="7" height="7" x="14" y="14" rx="1"/><rect width="7" height="7" x="3" y="14" rx="1"/></svg>',
|
||||
timer:
|
||||
@@ -30,6 +34,8 @@ export const ICON_SVGS = {
|
||||
// Not a Lucide icon: a ball above two angled flippers, for Pinball.
|
||||
pinball:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><circle cx="12" cy="6" r="3"/><path d="M4 14l7 5"/><path d="M20 14l-7 5"/><circle cx="4" cy="14" r="1"/><circle cx="20" cy="14" r="1"/></svg>',
|
||||
bird:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M16 7h.01"/><path d="M3.4 18H12a8 8 0 0 0 8-8V7a4 4 0 0 0-7.28-2.3L2 20"/><path d="m20 7 2 .5-2 .5"/><path d="M10 18v3"/><path d="M14 17.75V21"/><path d="M7 18a6 6 0 0 0 3.84-10.61"/></svg>',
|
||||
spade:
|
||||
'<svg viewBox="0 0 24 24" fill="none"><path d="M12 18v4"/><path d="M2 14.499a5.5 5.5 0 0 0 9.591 3.675.6.6 0 0 1 .818.001A5.5 5.5 0 0 0 22 14.5c0-2.29-1.5-4-3-5.5l-5.492-5.312a2 2 0 0 0-3-.02L5 8.999c-1.5 1.5-3 3.2-3 5.5"/></svg>',
|
||||
terminal:
|
||||
|
||||
Reference in new issue
Block a user