Boot manager: Niveus window, keys and wells, Instrument Sans, pointer, other systems, working power entries
The F8 menu is redrawn in the Niveus language: a window with three lights, bevelled keys with a lit edge, wells for panels, anti-aliased corners and a soft shadow, set in Instrument Sans rasterised into include/gfx/nvfont.h (tools/python/mknvfont.py, make nvfont). Scale doubles on screens 1400 px tall or more. Lists taller than the screen scroll. The keyboard still drives everything, and a mouse, touchpad or tablet does too: both UEFI pointer protocols are polled, hover moves the highlight, a click activates. The cursor stays hidden until the pointer has really done something, since the firmware installs a pointer protocol with or without a mouse. The 'keep this resolution?' countdown is one ten-second budget however many times the pointer moves. Loaders found at well-known paths on any volume (Windows, Ubuntu, Debian, Fedora, Arch, openSUSE, systemd-boot, rEFInd, other BOOTX64.EFI) are listed and chain-loaded with LoadImage/StartImage. 'Reboot to firmware' used to halt; it now sets OsIndications and restarts, and Restart and Shut Down call ResetSystem. Checked under QEMU+OVMF: menu, resolution list (incl. 2560x1600 at double scale), system information, shut down, firmware setup, chain-loading a copy of the loader from a second disk, and a full boot of the ISO to the login prompt. Pointer hover and click were checked only with synthetic events: in this setup a USB mouse or tablet delivered no event to the loader (one USB I/O handle appeared but no pointer protocol came from it), and why was not established. Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01EVRhxi9zpdW2uDUN4FVcao
This commit is contained in:
parent
020aa6113c
commit
dee3affa3b
11 changed files with 9304 additions and 208 deletions
695
boot/common/ui.c
695
boot/common/ui.c
|
|
@ -13,6 +13,7 @@
|
|||
#include "../../include/gfx/theme.h"
|
||||
#include "../../include/gfx/font.h"
|
||||
#include "../../include/gfx/logo.h"
|
||||
#include "../../include/gfx/nvfont.h"
|
||||
|
||||
/* "Draw the glyph, leave the background alone." Not a colour anyone can mean:
|
||||
* the palette is 24-bit, so the high byte is free for a sentinel. */
|
||||
|
|
@ -21,6 +22,25 @@
|
|||
static struct ui_fb FB;
|
||||
static int ACTIVE;
|
||||
|
||||
/* What the mark is blended against: the splash ground, or a window body. */
|
||||
static ui_u32 LOGO_BG = SCH_BG;
|
||||
|
||||
/* The boot manager's scale and faces. 2 on a screen big enough that a 15 px
|
||||
* face would be a speck; the faces are rasterised at both sizes, not doubled. */
|
||||
static int SC = 1;
|
||||
static const struct nvfont *F_BODY, *F_SMALL, *F_TITLE;
|
||||
static int CUR_ON; /* the pointer is drawn right now */
|
||||
|
||||
static void
|
||||
ui_set_scale(void)
|
||||
{
|
||||
SC = (FB.height >= 1400 || FB.width >= 2400) ? 2 : 1;
|
||||
F_BODY = SC == 2 ? &nvfont_body2 : &nvfont_body1;
|
||||
F_SMALL = SC == 2 ? &nvfont_small2 : &nvfont_small1;
|
||||
F_TITLE = SC == 2 ? &nvfont_title2 : &nvfont_title1;
|
||||
CUR_ON = 0; /* a new framebuffer holds no pointer */
|
||||
}
|
||||
|
||||
/* Progress state. Kept here rather than passed around because the caller ticks
|
||||
* it from inside a read loop that has no business carrying UI state. */
|
||||
static ui_u32 PROG_TOTAL, PROG_DONE;
|
||||
|
|
@ -101,6 +121,7 @@ ui_init(const struct ui_fb *fb)
|
|||
if (!FB.stride)
|
||||
FB.stride = FB.width * 4;
|
||||
ACTIVE = 1;
|
||||
ui_set_scale();
|
||||
}
|
||||
|
||||
int ui_active(void) { return ACTIVE; }
|
||||
|
|
@ -236,7 +257,7 @@ ui_logo(int y, int w)
|
|||
|
||||
/* Coverage blends the shaded metal against the ground, so the mark
|
||||
* has soft edges and a lit face at the same time. */
|
||||
put(x0 + dx, y + dy, mix(SCH_BG, shade, (int)cov, 15));
|
||||
put(x0 + dx, y + dy, mix(LOGO_BG, shade, (int)cov, 15));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
@ -280,85 +301,521 @@ ui_splash(const char *subtitle)
|
|||
ui_text_centered(PROG_Y + PROG_H + SUB_GAP, subtitle, SCH_DIM);
|
||||
}
|
||||
|
||||
/* --- panels ---------------------------------------------------------------
|
||||
/* --- Niveus -----------------------------------------------------------------
|
||||
*
|
||||
* A panel is a plate: a slightly lighter ground than the screen, one lighter
|
||||
* row along the top and a darker border, which is the whole of the bevel. Two
|
||||
* rows of shading do more for the impression of a raised surface than any
|
||||
* amount of gradient inside it, and cost nothing to draw.
|
||||
* The boot manager is drawn in the same language as the rest of the system
|
||||
* (docs/Website/niveus): windows are solid and carry three lights, controls are
|
||||
* bevelled keys with light falling across them, fields are wells cut into the
|
||||
* surface, and the ground under all of it is warm graphite rather than blue.
|
||||
*
|
||||
* Every shape here is a rounded rectangle with a vertical gradient, which is
|
||||
* all that skeuomorphism needs at this size. Corners are anti-aliased by
|
||||
* supersampling the corner pixels only, and the AA blends against a colour the
|
||||
* caller *names*, never against what is in the framebuffer: reading the
|
||||
* framebuffer back is uncached on real hardware and ruinously slow.
|
||||
*
|
||||
* The typeface is Instrument Sans, rasterised at build time (nvfont.h).
|
||||
*/
|
||||
static void
|
||||
panel(int x, int y, int w, int h)
|
||||
|
||||
#define NV_BG_TOP 0x1B1B1Eu /* the ground, light at the top */
|
||||
#define NV_BG_BOT 0x0B0B0Du
|
||||
#define NV_WIN_BODY 0x232326u
|
||||
#define NV_WIN_EDGE 0x050507u
|
||||
#define NV_TITLE_TOP 0x45444Au
|
||||
#define NV_TITLE_BOT 0x2C2B30u
|
||||
#define NV_HILITE 0x5E5D64u /* the lit upper edge of a raised thing */
|
||||
#define NV_KEY_TOP 0x3F3E44u
|
||||
#define NV_KEY_BOT 0x2D2C32u
|
||||
#define NV_KEY_EDGE 0x111113u
|
||||
#define NV_KEY_SHADOW 0x141416u
|
||||
#define NV_WELL_TOP 0x101012u
|
||||
#define NV_WELL_BOT 0x171719u
|
||||
#define NV_WELL_EDGE 0x0A0A0Bu
|
||||
#define NV_WELL_LIP 0x3A393Eu /* light catching the lower lip of a well */
|
||||
#define NV_TXT 0xECEAE5u
|
||||
#define NV_TXT2 0xA9A7A1u
|
||||
#define NV_TXT3 0x74726Du
|
||||
#define NV_LIGHT_CLOSE 0xFF5F57u
|
||||
#define NV_LIGHT_MIN 0xFEBC2Eu
|
||||
#define NV_LIGHT_ZOOM 0x28C840u
|
||||
|
||||
#define S(n) ((n) * SC)
|
||||
#define WHITE 0xFFFFFFu
|
||||
#define BLACK 0x000000u
|
||||
|
||||
static ui_u32
|
||||
bg_at(int y)
|
||||
{
|
||||
ui_fill_rect(x, y, w, h, PANEL_BG);
|
||||
ui_fill_rect(x, y, w, 1, PANEL_TOP); /* lit top edge */
|
||||
ui_fill_rect(x, y + h - 1, w, 1, METAL_EDGE); /* shadowed bottom */
|
||||
ui_fill_rect(x, y, 1, h, METAL_EDGE);
|
||||
ui_fill_rect(x + w - 1, y, 1, h, METAL_EDGE);
|
||||
return mix(NV_BG_TOP, NV_BG_BOT, y, (int)FB.height > 1 ? (int)FB.height - 1 : 1);
|
||||
}
|
||||
|
||||
/* A heading in metal: the same shading the mark uses, applied per row of the
|
||||
* glyph cell, so a title looks struck out of the same material. */
|
||||
static void
|
||||
metal_text_centered(int y, const char *s)
|
||||
nv_backdrop(void)
|
||||
{
|
||||
int len = slen(s);
|
||||
int x = ((int)FB.width - len * GLYPH_W) / 2;
|
||||
for (int y = 0; y < (int)FB.height; y++)
|
||||
ui_fill_rect(0, y, (int)FB.width, 1, bg_at(y));
|
||||
}
|
||||
|
||||
for (int row = 0; row < GLYPH_H; row++) {
|
||||
ui_u32 shade = metal(row, GLYPH_H);
|
||||
for (int i = 0; i < len; i++) {
|
||||
ui_u8 bits = font_data[(ui_u8)s[i]][row];
|
||||
for (int col = 0; col < GLYPH_W; col++)
|
||||
if (bits & (0x80 >> col))
|
||||
put(x + i * GLYPH_W + col, y + row, shade);
|
||||
static int
|
||||
nv_glyph_index(unsigned c)
|
||||
{
|
||||
if (c < NVFONT_FIRST || c > NVFONT_LAST)
|
||||
c = '?';
|
||||
return (int)(c - NVFONT_FIRST);
|
||||
}
|
||||
|
||||
static int
|
||||
nv_width(const struct nvfont *f, const char *s)
|
||||
{
|
||||
int w = 0;
|
||||
for (; *s && *s != '\n'; s++)
|
||||
w += f->g[nv_glyph_index((ui_u8)*s)].adv;
|
||||
return (w + 32) >> 6;
|
||||
}
|
||||
|
||||
static int
|
||||
nv_height(const struct nvfont *f)
|
||||
{
|
||||
return f->ascent + f->descent;
|
||||
}
|
||||
|
||||
/* Draw `s` (up to a newline) with its origin on baseline `base`. The colour
|
||||
* under it is a vertical gradient from bgtop at row y0 to bgbot at y0+h. */
|
||||
static void
|
||||
nv_text(const struct nvfont *f, int x, int base, const char *s, ui_u32 fg,
|
||||
ui_u32 bgtop, ui_u32 bgbot, int y0, int h)
|
||||
{
|
||||
int pen = 0; /* 1/64 px: the face's own spacing */
|
||||
for (; *s && *s != '\n'; s++) {
|
||||
const struct nvglyph *g = &f->g[nv_glyph_index((ui_u8)*s)];
|
||||
const ui_u8 *bits = f->bits + g->off;
|
||||
int gx = x + ((pen + 32) >> 6);
|
||||
for (int r = 0; r < g->h; r++) {
|
||||
int py = base + g->oy + r;
|
||||
ui_u32 bg = mix(bgtop, bgbot, py - y0, h > 1 ? h - 1 : 1);
|
||||
for (int c = 0; c < g->w; c++) {
|
||||
ui_u8 a = bits[r * g->w + c];
|
||||
if (a)
|
||||
put(gx + g->ox + c, py, mix(bg, fg, a, 255));
|
||||
}
|
||||
}
|
||||
pen += g->adv;
|
||||
}
|
||||
}
|
||||
|
||||
/* How much of the pixel at (dx,dy) from a corner's centre lies inside a circle
|
||||
* of radius r, in sixteenths. */
|
||||
static int
|
||||
corner_cov(int dx, int dy, int r)
|
||||
{
|
||||
int n = 0, R = r * 8;
|
||||
for (int j = 0; j < 4; j++)
|
||||
for (int i = 0; i < 4; i++) {
|
||||
int sx = dx * 8 + 2 * i + 1, sy = dy * 8 + 2 * j + 1;
|
||||
if (sx * sx + sy * sy <= R * R)
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
static void
|
||||
rrect(int x, int y, int w, int h, int r, ui_u32 top, ui_u32 bot,
|
||||
ui_u32 bgtop, ui_u32 bgbot, int bgy, int bgh)
|
||||
{
|
||||
if (w <= 0 || h <= 0)
|
||||
return;
|
||||
if (r * 2 > h) r = h / 2;
|
||||
if (r * 2 > w) r = w / 2;
|
||||
|
||||
for (int rr = 0; rr < h; rr++) {
|
||||
int yy = y + rr;
|
||||
ui_u32 col = mix(top, bot, rr, h > 1 ? h - 1 : 1);
|
||||
int cy, corner = 1;
|
||||
if (rr < r) cy = y + r;
|
||||
else if (rr >= h - r) cy = y + h - r;
|
||||
else corner = 0;
|
||||
|
||||
if (!corner) {
|
||||
ui_fill_rect(x, yy, w, 1, col);
|
||||
continue;
|
||||
}
|
||||
ui_u32 bg = mix(bgtop, bgbot, yy - bgy, bgh > 1 ? bgh - 1 : 1);
|
||||
ui_fill_rect(x + r, yy, w - 2 * r, 1, col);
|
||||
for (int k = 0; k < r; k++) {
|
||||
int dy = yy - cy;
|
||||
int cl = corner_cov(k - r, dy, r);
|
||||
int cr = corner_cov(k, dy, r);
|
||||
if (cl) put(x + k, yy, mix(bg, col, cl, 16));
|
||||
if (cr) put(x + w - r + k, yy, mix(bg, col, cr, 16));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/* Panel metrics.
|
||||
*
|
||||
* TITLE_H is the whole title band -- the padding above the heading, the
|
||||
* heading itself, and the air beneath it before the rule. It was 34 while the
|
||||
* heading alone needs 18 + 16 = 34, so the rule at TITLE_H - 6 was drawn
|
||||
* *through* the lettering and the first row started on the heading's baseline.
|
||||
* Derived from its parts now, so it cannot drift from them again.
|
||||
*/
|
||||
#define ROW_H 24
|
||||
#define PANEL_PAD 18
|
||||
#define TITLE_GAP 14 /* heading to the rule */
|
||||
#define TITLE_H (PANEL_PAD + GLYPH_H + TITLE_GAP) /* = 48 */
|
||||
#define ROW_LIFT ((ROW_H - GLYPH_H) / 2) /* highlight overhang */
|
||||
/* A raised object: an edge, a gradient face, and a bright line just inside the
|
||||
* top where the light lands. */
|
||||
static void
|
||||
bevel(int x, int y, int w, int h, int r, ui_u32 top, ui_u32 bot, ui_u32 edge,
|
||||
ui_u32 hi, ui_u32 bgtop, ui_u32 bgbot, int bgy, int bgh)
|
||||
{
|
||||
rrect(x, y, w, h, r, edge, edge, bgtop, bgbot, bgy, bgh);
|
||||
rrect(x + SC, y + SC, w - 2 * SC, h - 2 * SC, r > SC ? r - SC : r,
|
||||
top, bot, edge, edge, 0, 1);
|
||||
if (hi)
|
||||
ui_fill_rect(x + r, y + SC, w - 2 * r, SC, hi);
|
||||
}
|
||||
|
||||
/* A recess: the same thing with the light reversed. Darker at the top where the
|
||||
* rim shades it, with a pale lip along the bottom edge. */
|
||||
static void
|
||||
well(int x, int y, int w, int h, ui_u32 bgcol)
|
||||
{
|
||||
int r = S(8);
|
||||
bevel(x, y, w, h, r, NV_WELL_TOP, NV_WELL_BOT, NV_WELL_EDGE, 0, bgcol, bgcol, 0, 1);
|
||||
ui_fill_rect(x + r, y + h - SC, w - 2 * r, SC, NV_WELL_LIP);
|
||||
}
|
||||
|
||||
/* The soft shadow beneath a window, as stacked translucent layers laid down
|
||||
* from the outermost in, each one blended against the backdrop's own gradient. */
|
||||
static void
|
||||
shadow(int x, int y, int w, int h, int r)
|
||||
{
|
||||
int spread = S(16), dy = S(8);
|
||||
for (int i = spread; i > 0; i -= SC) {
|
||||
int t = spread - i;
|
||||
int a = 60 * t * t / (spread * spread); /* percent black */
|
||||
int ty = y - i + dy, th = h + 2 * i;
|
||||
ui_u32 top = mix(bg_at(ty), BLACK, a, 100);
|
||||
ui_u32 bot = mix(bg_at(ty + th), BLACK, a, 100);
|
||||
rrect(x - i, ty, w + 2 * i, th, r + i, top, bot,
|
||||
bg_at(ty), bg_at(ty + th), ty, th);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
panel_frame(const char *title, int rows, const char *hint,
|
||||
int *out_x, int *out_y, int *out_w)
|
||||
light(int x, int y, int d, ui_u32 colour, int tb_y, int tb_h)
|
||||
{
|
||||
int w = (int)FB.width / 2;
|
||||
if (w < 360) w = 360;
|
||||
if (w > (int)FB.width - 60) w = (int)FB.width - 60;
|
||||
ui_u32 top = mix(colour, WHITE, 28, 100);
|
||||
ui_u32 bot = mix(colour, BLACK, 22, 100);
|
||||
ui_u32 rim = mix(colour, BLACK, 62, 100);
|
||||
rrect(x - SC, y - SC, d + 2 * SC, d + 2 * SC, d / 2 + SC, rim, rim,
|
||||
NV_TITLE_TOP, NV_TITLE_BOT, tb_y, tb_h);
|
||||
rrect(x, y, d, d, d / 2, top, bot, rim, rim, 0, 1);
|
||||
}
|
||||
|
||||
int h = TITLE_H + rows * ROW_H + PANEL_PAD * 2;
|
||||
int x = ((int)FB.width - w) / 2;
|
||||
int y = ((int)FB.height - h) / 2;
|
||||
/* --- the pointer ----------------------------------------------------------- */
|
||||
|
||||
ui_clear();
|
||||
#define CUR_W 12
|
||||
#define CUR_H 19
|
||||
static const char *const CUR_SHAPE[CUR_H] = {
|
||||
"X ",
|
||||
"XX ",
|
||||
"X.X ",
|
||||
"X..X ",
|
||||
"X...X ",
|
||||
"X....X ",
|
||||
"X.....X ",
|
||||
"X......X ",
|
||||
"X.......X ",
|
||||
"X........X ",
|
||||
"X.........X ",
|
||||
"X......XXXXX",
|
||||
"X...X..X ",
|
||||
"X..X X..X ",
|
||||
"X.X X..X ",
|
||||
"XX X..X ",
|
||||
"X X..X ",
|
||||
" X..X ",
|
||||
" XXX ",
|
||||
};
|
||||
static ui_u32 CUR_SAVE[CUR_W * 2 * CUR_H * 2];
|
||||
static int CUR_X, CUR_Y, CUR_WANT;
|
||||
|
||||
/* The mark, small, above the plate: it is the same screen, not a new one. */
|
||||
int mw = ui_mark_width() * 2 / 3;
|
||||
int mh = (LOGO_H * mw) / LOGO_W;
|
||||
if (y - mh - 24 > 0)
|
||||
ui_logo(y - mh - 24, mw);
|
||||
static void
|
||||
cursor_hide(void)
|
||||
{
|
||||
if (!CUR_ON || !ACTIVE)
|
||||
return;
|
||||
int w = CUR_W * SC, h = CUR_H * SC;
|
||||
for (int r = 0; r < h; r++)
|
||||
for (int c = 0; c < w; c++) {
|
||||
int px = CUR_X + c, py = CUR_Y + r;
|
||||
if (px >= 0 && py >= 0 && (ui_u32)px < FB.width && (ui_u32)py < FB.height)
|
||||
*(ui_u32 *)(FB.base + (ui_u64)py * FB.stride + (ui_u64)px * 4) =
|
||||
CUR_SAVE[r * w + c];
|
||||
}
|
||||
CUR_ON = 0;
|
||||
}
|
||||
|
||||
panel(x, y, w, h);
|
||||
metal_text_centered(y + PANEL_PAD, title);
|
||||
ui_fill_rect(x + PANEL_PAD, y + PANEL_PAD + GLYPH_H + TITLE_GAP / 2,
|
||||
w - PANEL_PAD * 2, 1, METAL_EDGE);
|
||||
static void
|
||||
cursor_show(void)
|
||||
{
|
||||
if (!CUR_WANT || CUR_ON || !ACTIVE)
|
||||
return;
|
||||
int w = CUR_W * SC, h = CUR_H * SC;
|
||||
for (int r = 0; r < h; r++)
|
||||
for (int c = 0; c < w; c++) {
|
||||
int px = CUR_X + c, py = CUR_Y + r;
|
||||
if (px < 0 || py < 0 || (ui_u32)px >= FB.width || (ui_u32)py >= FB.height)
|
||||
continue;
|
||||
ui_u32 *p = (ui_u32 *)(FB.base + (ui_u64)py * FB.stride + (ui_u64)px * 4);
|
||||
CUR_SAVE[r * w + c] = *p;
|
||||
char ch = CUR_SHAPE[r / SC][c / SC];
|
||||
if (ch == 'X') *p = BLACK;
|
||||
else if (ch == '.') *p = WHITE;
|
||||
}
|
||||
CUR_ON = 1;
|
||||
}
|
||||
|
||||
if (hint)
|
||||
ui_text_centered(y + h + 16, hint, SCH_DIM);
|
||||
void
|
||||
ui_cursor(int x, int y, int show)
|
||||
{
|
||||
cursor_hide();
|
||||
CUR_X = x; CUR_Y = y; CUR_WANT = show;
|
||||
cursor_show();
|
||||
}
|
||||
|
||||
*out_x = x; *out_y = y + TITLE_H; *out_w = w;
|
||||
/* --- window chrome --------------------------------------------------------- */
|
||||
|
||||
#define TB_H S(34)
|
||||
#define BODY_PAD S(18)
|
||||
#define HINT_H S(36)
|
||||
|
||||
static void
|
||||
window(int x, int y, int w, int h, const char *title)
|
||||
{
|
||||
int r = S(12), tb = TB_H;
|
||||
|
||||
shadow(x, y, w, h, r);
|
||||
rrect(x, y, w, h, r, NV_WIN_EDGE, NV_WIN_EDGE, bg_at(y), bg_at(y + h), y, h);
|
||||
rrect(x + SC, y + SC, w - 2 * SC, h - 2 * SC, r - SC, NV_WIN_BODY, NV_WIN_BODY,
|
||||
NV_WIN_EDGE, NV_WIN_EDGE, 0, 1);
|
||||
|
||||
/* The titlebar is rounded on top only: draw it tall enough that its bottom
|
||||
* corners fall below the line, then lay the body colour over the excess. */
|
||||
rrect(x + SC, y + SC, w - 2 * SC, tb + r, r - SC, NV_TITLE_TOP, NV_TITLE_BOT,
|
||||
NV_WIN_EDGE, NV_WIN_EDGE, 0, 1);
|
||||
ui_fill_rect(x + SC, y + SC + tb, w - 2 * SC, r, NV_WIN_BODY);
|
||||
ui_fill_rect(x + SC, y + SC + tb - SC, w - 2 * SC, SC, NV_WIN_EDGE);
|
||||
ui_fill_rect(x + r, y + SC, w - 2 * r, SC, NV_HILITE);
|
||||
|
||||
int d = S(12), ly = y + SC + (tb - d) / 2, lx = x + S(18);
|
||||
light(lx, ly, d, NV_LIGHT_CLOSE, y + SC, tb);
|
||||
light(lx + S(20), ly, d, NV_LIGHT_MIN, y + SC, tb);
|
||||
light(lx + S(40), ly, d, NV_LIGHT_ZOOM, y + SC, tb);
|
||||
|
||||
int tw = nv_width(F_BODY, title);
|
||||
int base = y + SC + (tb - nv_height(F_BODY)) / 2 + F_BODY->ascent;
|
||||
nv_text(F_BODY, x + (w - tw) / 2, base, title, NV_TXT2,
|
||||
NV_TITLE_TOP, NV_TITLE_BOT, y + SC, tb);
|
||||
}
|
||||
|
||||
static void
|
||||
footer(int x, int y, int w, int h, const char *hint)
|
||||
{
|
||||
if (!hint)
|
||||
return;
|
||||
int fy = y + h - HINT_H;
|
||||
ui_fill_rect(x + S(14), fy, w - S(28), SC, 0x1A1A1Cu);
|
||||
ui_fill_rect(x + S(14), fy + SC, w - S(28), SC, 0x2E2E32u);
|
||||
int tw = nv_width(F_SMALL, hint);
|
||||
int base = fy + (HINT_H - nv_height(F_SMALL)) / 2 + F_SMALL->ascent + SC;
|
||||
nv_text(F_SMALL, x + (w - tw) / 2, base, hint, NV_TXT3,
|
||||
NV_WIN_BODY, NV_WIN_BODY, fy, HINT_H);
|
||||
}
|
||||
|
||||
/* --- keys ------------------------------------------------------------------ */
|
||||
|
||||
#define MAXKEYS 40
|
||||
|
||||
static struct { int x, y, w, h; } KEY[MAXKEYS];
|
||||
|
||||
static struct {
|
||||
const char *title, *hint;
|
||||
const char *const *items;
|
||||
int n, sel, scroll, vis, kind; /* kind: 0 a list of keys, 1 a panel */
|
||||
int has_detail, kh, gap, logo;
|
||||
int wx, wy, ww, wh;
|
||||
int lx, ly, lw; /* the list's box */
|
||||
int ypos[MAXKEYS];
|
||||
} M;
|
||||
|
||||
static int
|
||||
has_nl(const char *s)
|
||||
{
|
||||
for (; *s; s++)
|
||||
if (*s == '\n')
|
||||
return 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static const char *
|
||||
label_of(const char *s)
|
||||
{
|
||||
return s[0] == 1 ? s + 1 : s;
|
||||
}
|
||||
|
||||
static const char *
|
||||
detail_of(const char *s)
|
||||
{
|
||||
for (; *s; s++)
|
||||
if (*s == '\n')
|
||||
return s + 1;
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void
|
||||
paint_key(int i, int sel)
|
||||
{
|
||||
if (i < M.scroll || i >= M.scroll + M.vis || i >= MAXKEYS)
|
||||
return;
|
||||
|
||||
int x = KEY[i].x, y = KEY[i].y, w = KEY[i].w, h = KEY[i].h, r = S(8);
|
||||
const char *item = M.items[i];
|
||||
const char *label = label_of(item), *detail = detail_of(item);
|
||||
|
||||
/* Wipe the ring/shadow a previous state left, then draw this one. */
|
||||
ui_fill_rect(x - S(3), y - S(3), w + S(6), h + S(7), NV_WIN_BODY);
|
||||
|
||||
ui_u32 top, bot, edge, hi, fg, fg2;
|
||||
if (sel) {
|
||||
ui_u32 ring = mix(NV_WIN_BODY, SCH_ACCENT, 70, 100);
|
||||
rrect(x - S(2), y - S(2), w + S(4), h + S(4), r + S(2), ring, ring,
|
||||
NV_WIN_BODY, NV_WIN_BODY, 0, 1);
|
||||
top = mix(SCH_ACCENT, WHITE, 20, 100);
|
||||
bot = mix(SCH_ACCENT, BLACK, 24, 100);
|
||||
edge = mix(SCH_ACCENT, BLACK, 62, 100);
|
||||
hi = mix(top, WHITE, 45, 100);
|
||||
fg = WHITE; fg2 = 0xE2DBFFu;
|
||||
} else {
|
||||
rrect(x, y + SC, w, h, r, NV_KEY_SHADOW, NV_KEY_SHADOW,
|
||||
NV_WIN_BODY, NV_WIN_BODY, 0, 1);
|
||||
top = NV_KEY_TOP; bot = NV_KEY_BOT; edge = NV_KEY_EDGE; hi = NV_HILITE;
|
||||
fg = NV_TXT; fg2 = NV_TXT3;
|
||||
}
|
||||
bevel(x, y, w, h, r, top, bot, edge, hi, NV_WIN_BODY, NV_WIN_BODY, 0, 1);
|
||||
|
||||
int ty0 = y + SC, th = h - 2 * SC, tx = x + S(18);
|
||||
if (detail) {
|
||||
int lh = nv_height(F_BODY), dh = nv_height(F_SMALL);
|
||||
int total = lh + S(2) + dh;
|
||||
int t = y + (h - total) / 2;
|
||||
nv_text(F_BODY, tx, t + F_BODY->ascent, label, fg, top, bot, ty0, th);
|
||||
nv_text(F_SMALL, tx, t + lh + S(2) + F_SMALL->ascent, detail,
|
||||
sel ? fg2 : NV_TXT2, top, bot, ty0, th);
|
||||
} else {
|
||||
int base = y + (h - nv_height(F_BODY)) / 2 + F_BODY->ascent;
|
||||
nv_text(F_BODY, tx, base, label, fg, top, bot, ty0, th);
|
||||
}
|
||||
|
||||
if (M.kind == 0 && M.n <= 9 && M.vis == M.n) {
|
||||
char num[2] = { (char)('1' + i), 0 };
|
||||
int nw = nv_width(F_SMALL, num);
|
||||
int base = y + (h - nv_height(F_SMALL)) / 2 + F_SMALL->ascent;
|
||||
nv_text(F_SMALL, x + w - S(18) - nw, base, num, sel ? fg2 : NV_TXT3,
|
||||
top, bot, ty0, th);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
menu_layout(void)
|
||||
{
|
||||
int n = M.n > MAXKEYS ? MAXKEYS : M.n;
|
||||
M.n = n;
|
||||
M.has_detail = 0;
|
||||
for (int i = 0; i < n; i++)
|
||||
if (has_nl(M.items[i]))
|
||||
M.has_detail = 1;
|
||||
M.gap = S(8);
|
||||
M.kh = M.has_detail ? S(50) : S(34);
|
||||
M.ww = S(520);
|
||||
if (M.ww > (int)FB.width - S(24))
|
||||
M.ww = (int)FB.width - S(24);
|
||||
|
||||
int maxh = (int)FB.height - S(24);
|
||||
int chrome = TB_H + BODY_PAD * 2 + HINT_H + 2 * SC;
|
||||
int logoh = S(56) + S(16);
|
||||
int full;
|
||||
|
||||
for (int pass = 0; pass < 2; pass++) {
|
||||
int y = 0;
|
||||
for (int i = 0; i < n; i++) {
|
||||
if (pass == 0 && i && M.items[i][0] == 1)
|
||||
y += S(14);
|
||||
M.ypos[i] = y;
|
||||
y += M.kh + M.gap;
|
||||
}
|
||||
full = n ? y - M.gap : 0;
|
||||
if (pass == 0 && chrome + full <= maxh)
|
||||
break;
|
||||
if (pass == 0 && chrome + logoh + full <= maxh)
|
||||
break;
|
||||
}
|
||||
|
||||
M.logo = 1;
|
||||
M.vis = n;
|
||||
int list_h = full;
|
||||
if (chrome + logoh + full > maxh)
|
||||
M.logo = 0;
|
||||
if (chrome + full > maxh) {
|
||||
int avail = maxh - chrome;
|
||||
M.vis = (avail + M.gap) / (M.kh + M.gap);
|
||||
if (M.vis < 1) M.vis = 1;
|
||||
if (M.vis > n) M.vis = n;
|
||||
list_h = M.vis * M.kh + (M.vis - 1) * M.gap;
|
||||
}
|
||||
M.wh = chrome + (M.logo ? logoh : 0) + list_h;
|
||||
M.wx = ((int)FB.width - M.ww) / 2;
|
||||
M.wy = ((int)FB.height - M.wh) / 2;
|
||||
if (M.wy < 0) M.wy = 0;
|
||||
M.lx = M.wx + S(20);
|
||||
M.lw = M.ww - S(40) - (M.vis < n ? S(14) : 0);
|
||||
M.ly = M.wy + SC + TB_H + BODY_PAD + (M.logo ? logoh : 0);
|
||||
|
||||
if (M.sel < M.scroll) M.scroll = M.sel;
|
||||
if (M.sel >= M.scroll + M.vis) M.scroll = M.sel - M.vis + 1;
|
||||
if (M.scroll < 0) M.scroll = 0;
|
||||
if (M.scroll > n - M.vis) M.scroll = n - M.vis;
|
||||
if (M.scroll < 0) M.scroll = 0;
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
KEY[i].x = M.lx;
|
||||
KEY[i].w = M.lw;
|
||||
KEY[i].h = M.kh;
|
||||
KEY[i].y = M.ly + M.ypos[i] - M.ypos[M.scroll];
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
menu_paint(void)
|
||||
{
|
||||
cursor_hide();
|
||||
nv_backdrop();
|
||||
window(M.wx, M.wy, M.ww, M.wh, M.title);
|
||||
|
||||
if (M.logo) {
|
||||
ui_u32 saved = LOGO_BG;
|
||||
LOGO_BG = NV_WIN_BODY;
|
||||
ui_logo(M.wy + SC + TB_H + BODY_PAD, S(56));
|
||||
LOGO_BG = saved;
|
||||
}
|
||||
|
||||
for (int i = M.scroll; i < M.scroll + M.vis && i < M.n; i++)
|
||||
paint_key(i, i == M.sel);
|
||||
|
||||
if (M.vis < M.n) {
|
||||
int tx = M.lx + M.lw + S(8), tw = S(4);
|
||||
int th = M.vis * M.kh + (M.vis - 1) * M.gap;
|
||||
rrect(tx, M.ly, tw, th, tw / 2, NV_WELL_TOP, NV_WELL_BOT,
|
||||
NV_WIN_BODY, NV_WIN_BODY, 0, 1);
|
||||
int thumb = th * M.vis / M.n;
|
||||
if (thumb < S(16)) thumb = S(16);
|
||||
int ty = M.ly + (th - thumb) * M.scroll / (M.n - M.vis);
|
||||
rrect(tx, ty, tw, thumb, tw / 2, NV_KEY_TOP, NV_KEY_BOT,
|
||||
NV_WIN_BODY, NV_WIN_BODY, 0, 1);
|
||||
}
|
||||
|
||||
footer(M.wx, M.wy, M.ww, M.wh, M.hint);
|
||||
cursor_show();
|
||||
}
|
||||
|
||||
void
|
||||
|
|
@ -367,47 +824,111 @@ ui_menu(const char *title, const char *const *items, int n, int selected,
|
|||
{
|
||||
if (!ACTIVE)
|
||||
return;
|
||||
M.title = title; M.items = items; M.n = n; M.sel = selected; M.hint = hint;
|
||||
M.scroll = 0; M.kind = 0;
|
||||
menu_layout();
|
||||
menu_paint();
|
||||
}
|
||||
|
||||
int x, y, w;
|
||||
panel_frame(title, n, hint, &x, &y, &w);
|
||||
void
|
||||
ui_menu_select(int selected)
|
||||
{
|
||||
if (!ACTIVE || M.kind != 0 || selected < 0 || selected >= M.n || selected == M.sel)
|
||||
return;
|
||||
int old = M.sel;
|
||||
M.sel = selected;
|
||||
if (selected < M.scroll || selected >= M.scroll + M.vis) {
|
||||
menu_layout();
|
||||
menu_paint();
|
||||
return;
|
||||
}
|
||||
cursor_hide();
|
||||
paint_key(old, 0);
|
||||
paint_key(selected, 1);
|
||||
cursor_show();
|
||||
}
|
||||
|
||||
int
|
||||
ui_menu_hit(int x, int y)
|
||||
{
|
||||
if (!ACTIVE)
|
||||
return -1;
|
||||
for (int i = M.scroll; i < M.scroll + M.vis && i < M.n; i++)
|
||||
if (x >= KEY[i].x && x < KEY[i].x + KEY[i].w &&
|
||||
y >= KEY[i].y && y < KEY[i].y + KEY[i].h)
|
||||
return i;
|
||||
return -1;
|
||||
}
|
||||
|
||||
/* A panel: label/value rows in a well, and one button underneath. With no
|
||||
* values, the labels are a message and are centred. */
|
||||
static void
|
||||
box(const char *title, const char *const *labels, const char *const *values,
|
||||
int n, const char *button, const char *hint)
|
||||
{
|
||||
if (!ACTIVE)
|
||||
return;
|
||||
int rowh = S(28), wpad = S(12);
|
||||
int well_h = n * rowh + 2 * wpad;
|
||||
int btn_h = S(34), btn_w = S(180);
|
||||
|
||||
M.title = title; M.hint = hint; M.kind = 1;
|
||||
M.items = &button; M.n = 1; M.sel = 0; M.scroll = 0; M.vis = 1;
|
||||
M.ww = S(520);
|
||||
if (M.ww > (int)FB.width - S(24))
|
||||
M.ww = (int)FB.width - S(24);
|
||||
M.wh = TB_H + 2 * SC + BODY_PAD + well_h + S(18) + btn_h + BODY_PAD + HINT_H;
|
||||
M.wx = ((int)FB.width - M.ww) / 2;
|
||||
M.wy = ((int)FB.height - M.wh) / 2;
|
||||
if (M.wy < 0) M.wy = 0;
|
||||
|
||||
cursor_hide();
|
||||
nv_backdrop();
|
||||
window(M.wx, M.wy, M.ww, M.wh, title);
|
||||
|
||||
int wx = M.wx + S(20), ww = M.ww - S(40);
|
||||
int wy = M.wy + SC + TB_H + BODY_PAD;
|
||||
well(wx, wy, ww, well_h, NV_WIN_BODY);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int ry = y + i * ROW_H;
|
||||
|
||||
if (i == selected) {
|
||||
/* The selected row is the only lit thing on the plate. Filling it
|
||||
* with the accent and putting the label in the ground colour reads
|
||||
* at a glance; an outline does not, at this size. */
|
||||
/* Centred on the glyph box: (ROW_H - GLYPH_H) / 2 above it, the
|
||||
* same below. Off-by-a-few here is what makes a highlight look
|
||||
* like it is sitting on the text rather than around it. */
|
||||
ui_fill_rect(x + PANEL_PAD / 2, ry - ROW_LIFT, w - PANEL_PAD, ROW_H,
|
||||
SCH_ACCENT);
|
||||
ui_text(x + PANEL_PAD, ry, items[i], PANEL_BG, SCH_BG_NONE);
|
||||
int ry = wy + wpad + i * rowh;
|
||||
int base = ry + (rowh - nv_height(F_BODY)) / 2 + F_BODY->ascent;
|
||||
if (i)
|
||||
ui_fill_rect(wx + S(14), ry, ww - S(28), SC, 0x1E1E21u);
|
||||
if (values) {
|
||||
nv_text(F_BODY, wx + S(16), base, labels[i], NV_TXT2,
|
||||
NV_WELL_TOP, NV_WELL_BOT, wy, well_h);
|
||||
int vw = nv_width(F_BODY, values[i]);
|
||||
nv_text(F_BODY, wx + ww - S(16) - vw, base, values[i], NV_TXT,
|
||||
NV_WELL_TOP, NV_WELL_BOT, wy, well_h);
|
||||
} else {
|
||||
ui_text(x + PANEL_PAD, ry, items[i], SCH_FG, SCH_BG_NONE);
|
||||
int lw = nv_width(F_BODY, labels[i]);
|
||||
nv_text(F_BODY, wx + (ww - lw) / 2, base, labels[i], NV_TXT,
|
||||
NV_WELL_TOP, NV_WELL_BOT, wy, well_h);
|
||||
}
|
||||
}
|
||||
|
||||
KEY[0].w = btn_w; KEY[0].h = btn_h;
|
||||
KEY[0].x = M.wx + (M.ww - btn_w) / 2;
|
||||
KEY[0].y = wy + well_h + S(18);
|
||||
M.has_detail = 0;
|
||||
paint_key(0, 1);
|
||||
footer(M.wx, M.wy, M.ww, M.wh, hint);
|
||||
cursor_show();
|
||||
}
|
||||
|
||||
void
|
||||
ui_panel(const char *title, const char *const *labels,
|
||||
const char *const *values, int n, const char *hint)
|
||||
{
|
||||
if (!ACTIVE)
|
||||
return;
|
||||
box(title, labels, values, n, "Back", hint);
|
||||
}
|
||||
|
||||
int x, y, w;
|
||||
panel_frame(title, n, hint, &x, &y, &w);
|
||||
|
||||
for (int i = 0; i < n; i++) {
|
||||
int ry = y + i * ROW_H;
|
||||
ui_text(x + PANEL_PAD, ry, labels[i], SCH_DIM, SCH_BG_NONE);
|
||||
|
||||
/* Values right-aligned, so the column reads down rather than ragged. */
|
||||
int vw = slen(values[i]) * GLYPH_W;
|
||||
ui_text(x + w - PANEL_PAD - vw, ry, values[i], SCH_FG, SCH_BG_NONE);
|
||||
}
|
||||
void
|
||||
ui_notice(const char *title, const char *const *lines, int n,
|
||||
const char *button, const char *hint)
|
||||
{
|
||||
box(title, lines, 0, n, button, hint);
|
||||
}
|
||||
|
||||
void
|
||||
|
|
|
|||
|
|
@ -77,6 +77,21 @@ void ui_splash(const char *subtitle);
|
|||
void ui_menu(const char *title, const char *const *items, int n, int selected,
|
||||
const char *hint);
|
||||
|
||||
/* Repaint only the keys that changed when the highlight moves (a full paint
|
||||
* redraws the screen). Returns without effect on a panel. */
|
||||
void ui_menu_select(int selected);
|
||||
|
||||
/* Which key is under a point, or -1. A panel has one key, index 0. */
|
||||
int ui_menu_hit(int x, int y);
|
||||
|
||||
/* The pointer: drawn on top of everything, with what is under it saved and put
|
||||
* back. Menus hide it while they repaint and show it again afterwards. */
|
||||
void ui_cursor(int x, int y, int show);
|
||||
|
||||
/* A message in the same window as the panels, with one button. */
|
||||
void ui_notice(const char *title, const char *const *lines, int n,
|
||||
const char *button, const char *hint);
|
||||
|
||||
/* A panel of label/value rows -- the system information screen. */
|
||||
void ui_panel(const char *title, const char *const *labels,
|
||||
const char *const *values, int n, const char *hint);
|
||||
|
|
|
|||
Loading…
Reference in a new issue