mirror of
https://github.com/juanjiant-bit/JIANT.git
synced 2026-12-06 21:04:32 +01:00
- SKIN in MENU > DISPLAY after COLOR (COLORS by default; ui_skin, engine 15 byte 20 of the settings: older settings and unknown values load as COLORS; the editor's MENU id 21; DISPLAY now seven rows, the menu's TAB rows 17 apart, its MENU tiles 72 / 64 tall, ROWS 5-7). ux.skin follows it (style_apply); BOTTOM and HUD make SURF the background. - Palettes (tools/gen_ui_palettes.py): four knob colours each (KNOBS: the mock-up's for JIANT PAPER GREEN AMBER ICE, the rest in its spirit; GREY grey, MONO white; 4.5:1 on BG and SURF, 4:1 on RAISE checked), gfx.c T_K(c); JIANT's SURF the mock-up's near-black (10, 9, 14) and its RAISE 4 % (the 0.6 cards, #131218); its boxes rounded like the others (the black-SURF square case gone). JIANT's heat ramp the 0.6's (indigo violet red orange amber cream white). - Values and the header's BPM in a rounded sans again, as 0.6 (the mock-up's "Sans 0.6"): face M is Inter Tight SemiBold 15 px (assets/fonts, already credited), was Chakra Petch; labels, tabs, breadcrumb keep the 5 x 7 face. - The header (every skin, the mock-up's): the selected track's number in an ACCENT box, a THEME triangle playing, the BPM in M; HUD: no rule. The breadcrumb: the lens DIM, the level THEME, the set TEXT, the count TEXT. - COLORS: rounded tabs (THEME / RAISE), rounded RAISE cards with a 7 x 7 mark before the label where the label has one (CUT RES ATK REL WAVE DETUNE MIX NOISE STEP NOTE TYPE ACCENT SIZE DEPTH and kin), the label TEXT, the value and a 3 px rounded gauge in the knob's colour, the knob turned framed in it; the panel rounded. - BOTTOM: the tabs three words (the level's THEME with a pill), the panel the screen's width with no box (42..189; HOME's beings 240 x 148), the knobs a slim row over the breadcrumb (191..223: mark and label MID, the value in its colour, a hairline gauge); LINE draws its rules over and under the panel. - HUD: as BOTTOM; on HOME (ECO) the beings' water is the whole screen: every strip (header, tabs, the middle, the four cards 60 px each, the breadcrumb) is drawn each frame on the beings under it (ui_lzhome.c eco_draw / eco_backdrop: a being off the strip skipped; the numbers only in the middle), its words with a 1 px BG outline (gfx.c cv_halo), the level's word underlined; the knob row fades to 22 % 3 s after the last knob turn (ui.knob_ms) and is whole again at a turn. LOAD LITE / ECO pace the whole HUD frame as the panel's. - MENU > LARGE: COLORS' layout (the tall cards on top) in every skin, with the skin's tabs and colours. - Panels after the mock-up: EDIT > SOUND (the being larger, the scope a tile, the page's four parameters as chips in their knobs' colours, "2/2 CUT RES DRIVE" under them); FX > BUSES's tiles (lz_tile: COLORS rounded cards, the module framed THEME; BOTTOM / HUD bare, the module underlined); SEQ's bar cells and roll (BOTTOM / HUD: bare cells over a line, the beats only; the cursor framed TEXT); PUNCH's empty steps ticks; the dialogs (NOTICE, DICE) in the skin's tabs, cards and buttons; header messages in plain 5 x 7 words (the keycap gone). - CV_MAX 240 x 150 (HUD's middle). The new statics in the pool section, so the audio's data and code are where they were (target budgets identical to 0.8.8's). - Tests: ui_test SKIN (default, menu steps, saved / older / unknown, geometry, HUD's beings over the screen, the fade, every lens page in each skin); the menu, header, roll, editor and theme tests updated for SKIN, the box and Inter Tight; ui_render: every screen in BOTTOM and HUD (FLAT, LINE, LARGE, every palette) linted, their PNGs (JIANT PAPER GREY MONO), the draw cost per skin. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01KMHk6yH4XbP1xxHYKCo9Mh
167 lines
9.3 KiB
C
167 lines
9.3 KiB
C
/* SPDX-License-Identifier: GPL-3.0-only */
|
|
/* The palettes and the real canvas/text renderer (src/gfx.c): GREY stays gray in every token and blend, MONO is
|
|
* black and white in every token (one grey: DIM LINE RAISE LANE) and neutral in every blend,
|
|
* every palette's text contrast, the alpha blend, the ramp cache, the fonts' metrics and the ellipsis.
|
|
* Optional: a palette sheet (PPM). */
|
|
#include <stdint.h>
|
|
#include <stdio.h>
|
|
#include <assert.h>
|
|
#include <math.h>
|
|
#include <string.h>
|
|
#define __attribute__(x)
|
|
static void lcd_sync(void) {}
|
|
static void lcd_power(uint32_t s) { (void)s; } /* (MENU > SCREEN OFF: lcd.c) */
|
|
static void lcd_wake_now(void) {}
|
|
static void lcd_blit(uint32_t x, uint32_t y, uint32_t w, uint32_t h, const uint16_t *p)
|
|
{ (void)x; (void)y; (void)w; (void)h; (void)p; }
|
|
#include "../firmware/src/gfx.c"
|
|
|
|
#define SHEET_W 960u
|
|
#define SHEET_H (((NPALETTES + 3u) / 4u) * 124u)
|
|
static uint16_t sheet[SHEET_W * SHEET_H];
|
|
static unsigned channel(uint16_t c, unsigned n)
|
|
{ return n == 0 ? c >> 11 : n == 1 ? (c >> 5) & 63 : c & 31; }
|
|
static int gray(uint16_t c) { return channel(c, 0) == channel(c, 2) && channel(c, 1) == channel(c, 0) * 2u; }
|
|
/* MONO's blends: R = B, G within 2 of 2 R (blended per channel, the 5-6-5 rounding) */
|
|
static int neutral(uint16_t c)
|
|
{ return channel(c, 0) == channel(c, 2) && (int)channel(c, 1) - 2 * (int)channel(c, 0) >= -2 && (int)channel(c, 1) - 2 * (int)channel(c, 0) <= 2; }
|
|
static double luminance(uint16_t color)
|
|
{
|
|
const double weight[] = {0.2126, 0.7152, 0.0722};
|
|
double result = 0;
|
|
for (unsigned c = 0; c < 3; c++) {
|
|
double v = channel(color, c) / (c == 1 ? 63.0 : 31.0);
|
|
result += weight[c] * (v <= 0.04045 ? v / 12.92 : pow((v + 0.055) / 1.055, 2.4));
|
|
}
|
|
return result;
|
|
}
|
|
static double contrast(uint16_t fg, uint16_t bg)
|
|
{
|
|
double a = luminance(fg), b = luminance(bg);
|
|
return a > b ? (a + 0.05) / (b + 0.05) : (b + 0.05) / (a + 0.05);
|
|
}
|
|
|
|
int main(int argc, char **argv)
|
|
{
|
|
static const aag_t pg[1] = {{0, 48, 0, 0, 3, 1}}; /* one glyph 'A': 3 px, alpha 0, 8, 15 */
|
|
static const uint8_t pd[] = {0x08, 0xf0};
|
|
const aafont_t probe = {1, 1, 'A', 'A', 0, 0, pg, pd, 0, 0, 0};
|
|
double worst = 100;
|
|
assert(NPALETTES == 11u && !strcmp(UI_PALETTES[0].name, "GREY") && !strcmp(UI_PALETTES[7].name, "HI-CON") &&
|
|
!strcmp(UI_PALETTES[8].name, "NIGHT") && !strcmp(UI_PALETTES[9].name, "MONO") && UI_BW_INDEX == 9u &&
|
|
!strcmp(UI_PALETTES[10].name, "JIANT") && UI_JIANT_INDEX == 10u); /* (JIANT 0.1: appended) */
|
|
/* (#50, 1.0.2: appended, the ids stay; GREY is the MONO of 1.0.1, id 0) */
|
|
for (unsigned st = ST_FLAT; st <= ST_LINE; st++) { /* MONO: every token black or white, in FLAT and LINE */
|
|
uint16_t *tok = &ux.bg;
|
|
ux.style = (uint8_t)st;
|
|
palette_set(UI_BW_INDEX);
|
|
assert(&ux.grid - tok == 15);
|
|
for (unsigned i = 0; i < 16; i++) {
|
|
/* the one grey: DIM (inactive), LINE (tracks), RAISE (wells under white text), LANE (the piano roll) */
|
|
int grey_ok = tok[i] == UI_BW_GREY && (&tok[i] == &ux.dim || &tok[i] == &ux.line || &tok[i] == &ux.raise ||
|
|
&tok[i] == &ux.lane);
|
|
if (!(tok[i] == 0x0000u || tok[i] == 0xFFFFu || grey_ok))
|
|
printf("MONO (%s): token %u = %04x is not black or white\n", st ? "LINE" : "FLAT", i, tok[i]);
|
|
assert(tok[i] == 0x0000u || tok[i] == 0xFFFFu || grey_ok);
|
|
}
|
|
assert(T_BG == 0u && T_SURF == 0u && T_TEXT == 0xFFFFu && T_SEL == 0xFFFFu && T_INK == 0u && T_REC == 0xFFFFu);
|
|
}
|
|
ux.style = ST_FLAT;
|
|
for (unsigned p = 0; p < NPALETTES; p++) {
|
|
uint16_t *tok = &ux.bg;
|
|
palette_set(p);
|
|
if (p == UI_GREY_INDEX)
|
|
for (unsigned i = 0; i < 14; i++) assert(gray(tok[i])); /* every token, derived ones too (RAISE, KEY the last) */
|
|
/* text and the things read on the screen; the generator checks the same (tools/gen_ui_palettes.py) */
|
|
struct { uint16_t fg, bg; double min; } c[] = {
|
|
{T_TEXT, T_BG, 12.0}, {T_TEXT, T_SURF, 9.0}, {T_MID, T_BG, 5.0}, {T_MID, T_SURF, 4.0},
|
|
{T_THEME, T_BG, 4.5}, {T_THEME, T_SURF, 4.5}, {T_ACCENT, T_BG, 4.5}, {T_ACCENT, T_SURF, 4.5},
|
|
{T_INK, T_SEL, 4.5}, {T_INK, T_THEME, 4.5}, {T_DIM, T_BG, 2.2}, {T_LINE, T_BG, 1.25}, {T_REC, T_BG, 3.0},
|
|
{T_INK, T_KEY, 4.5}, {T_KEY, T_BG, 3.0}, {T_KEY, T_SURF, 2.5}, {T_INK, T_DIM, 1.8}, {T_INK, T_ACCENT, 4.5},
|
|
{T_TEXT, T_RAISE, 7.0}};
|
|
double min = 100;
|
|
for (unsigned i = 0; i < sizeof c / sizeof c[0]; i++) {
|
|
double r = contrast(c[i].fg, c[i].bg);
|
|
if (r < c[i].min) printf("%s: pairing %u contrast %.2f < %.2f\n", UI_PALETTES[p].name, i, r, c[i].min);
|
|
assert(r >= c[i].min);
|
|
if (r / c[i].min < min) min = r / c[i].min;
|
|
}
|
|
if (min < worst) worst = min;
|
|
printf("%-7s text %.1f:1, labels %.1f:1, values %.1f:1, selection %.1f:1\n", UI_PALETTES[p].name,
|
|
contrast(T_TEXT, T_BG), contrast(T_MID, T_BG), contrast(T_THEME, T_BG), contrast(T_INK, T_SEL));
|
|
assert((p == 6u) == ux.light); /* PAPER is the light one */
|
|
assert(T_REC == (p == UI_GREY_INDEX || p == UI_BW_INDEX ? T_ACCENT : ux.light ? UI_REC_LIGHT : UI_REC_DARK));
|
|
/* the blend: transparent, solid and an edge between the two, on two backgrounds */
|
|
for (unsigned b = 0; b < 2; b++) {
|
|
uint16_t under = b ? T_SEL : T_BG, ink = b ? T_INK : T_THEME;
|
|
cv_begin(3, 1, under);
|
|
cv_text_on(0, 0, &probe, "A", ink, under);
|
|
assert(swap16(cv_px[0]) == under && swap16(cv_px[2]) == ink);
|
|
for (unsigned k = 0; k < 3; k++) {
|
|
unsigned a = channel(under, k), z = channel(ink, k), m = channel(swap16(cv_px[1]), k);
|
|
assert(m >= (a < z ? a : z) && m <= (a > z ? a : z)); /* no halo */
|
|
}
|
|
if (p == UI_GREY_INDEX) assert(gray(swap16(cv_px[1])));
|
|
if (p == UI_BW_INDEX) assert(neutral(swap16(cv_px[1])));
|
|
}
|
|
assert(text_w(&AF_S, UI_PALETTES[p].name) <= 60); /* the COLOR row's value */
|
|
cv_begin(240, 124, T_BG);
|
|
cv_text(4, 2, &AF_M, UI_PALETTES[p].name, T_TEXT);
|
|
for (unsigned k = 0; k < 5; k++) cv_rect(150 + k * 16, 4, 12, 12, tok[k]);
|
|
cv_text(4, 26, &AF_S, "LABEL", T_MID);
|
|
cv_text(70, 22, &AF_M, "VALUE 127", T_THEME);
|
|
cv_text(170, 22, &AF_M, "HOT", T_ACCENT);
|
|
cv_text(4, 46, &AF_S, "INACTIVE", T_DIM);
|
|
cv_rect(80, 44, 150, 17, T_SEL);
|
|
cv_text_on(86, 45, &AF_S, "SELECTED ROW", T_INK, T_SEL);
|
|
cv_rect(4, 66, 232, 1, T_LINE);
|
|
cv_rect(4, 72, 120, 3, T_LINE);
|
|
cv_rect(4, 72, 70, 3, T_SEL);
|
|
cv_rect(74, 70, 1, 7, T_THEME);
|
|
cv_text(136, 66, &AF_S, "REC", T_REC);
|
|
cv_text(4, 82, &AF_L, "124", T_THEME);
|
|
cv_text(80, 92, &AF_S, "Mixed case text", T_TEXT);
|
|
cv_key_hint(80, 108, KC_OCTUP, "LOAD", 1, T_BG); /* keycaps: available, unavailable */
|
|
cv_key_hint(150, 108, KC_OCTDN, "BACK", 0, T_BG);
|
|
for (unsigned y = 0; y < 124; y++)
|
|
for (unsigned x = 0; x < 240; x++) {
|
|
uint16_t v = swap16(cv_px[y * 240 + x]);
|
|
if (p == UI_GREY_INDEX) assert(gray(v)); /* every blended pixel of GREY */
|
|
if (p == UI_BW_INDEX) assert(neutral(v)); /* and of MONO */
|
|
sheet[(p / 4 * 124 + y) * 960 + p % 4 * 240 + x] = v;
|
|
}
|
|
}
|
|
/* the ramp cache follows the palette (a stale ramp would blend toward the old background) */
|
|
palette_set(1);
|
|
cv_begin(3, 1, T_BG); cv_text(0, 0, &probe, "A", T_THEME);
|
|
uint16_t green = swap16(cv_px[1]);
|
|
palette_set(6);
|
|
cv_begin(3, 1, T_BG); cv_text(0, 0, &probe, "A", T_THEME);
|
|
assert(swap16(cv_px[1]) != green);
|
|
/* fonts: Chakra Petch (JIANT 0.5) S 12 px; (0.8.9) M Inter Tight SemiBold 15 px (the values, as the 0.6), L Michroma
|
|
* 18 px; tabular digits; the ellipsis; L has capitals only */
|
|
assert(AF_S.h == 16 && AF_S.asc == 12 && AF_M.h == 19 && AF_M.asc == 15 && AF_L.h == 26 && AF_L.asc == 21);
|
|
assert(text_w(&AF_M, "0000") == text_w(&AF_M, "1111") && text_w(&AF_S, "1.25") == text_w(&AF_S, "8.75"));
|
|
assert(glyph(&AF_S, (uint8_t)ELLIPSIS) != glyph(&AF_S, '?') && glyph(&AF_M, (uint8_t)ELLIPSIS) != glyph(&AF_M, '?'));
|
|
assert(text_w(&AF_L, "abc") == text_w(&AF_L, "ABC"));
|
|
{
|
|
char b[32];
|
|
assert(!text_fit(b, sizeof b, "KICK", &AF_S, 60) && !strcmp(b, "KICK"));
|
|
assert(text_fit(b, sizeof b, "A VERY LONG PRESET NAME", &AF_S, 60) && text_w(&AF_S, b) <= 60);
|
|
assert(b[strlen(b) - 1] == ELLIPSIS && b[strlen(b) - 2] != ' ');
|
|
assert(text_fit(b, sizeof b, "WWWWWWWW", &AF_M, 1) && b[0] == ELLIPSIS && !b[1]);
|
|
}
|
|
if (argc > 1) {
|
|
FILE *f = fopen(argv[1], "wb"); assert(f);
|
|
fprintf(f, "P6\n%u %u\n255\n", (unsigned)SHEET_W, (unsigned)SHEET_H);
|
|
for (unsigned i = 0; i < SHEET_W * SHEET_H; i++) {
|
|
fputc(channel(sheet[i], 0) * 255 / 31, f);
|
|
fputc(channel(sheet[i], 1) * 255 / 63, f);
|
|
fputc(channel(sheet[i], 2) * 255 / 31, f);
|
|
}
|
|
fclose(f);
|
|
}
|
|
printf("Palettes: GREY gray, MONO black and white, contrast (worst margin x%.2f), blending, ramp cache, font metrics and ellipsis passed.\n", worst);
|
|
return 0;
|
|
}
|