#ifndef UI_INTERNAL_H #define UI_INTERNAL_H // Shared between the files of src/platform/ui. Coordinates are in the 960x544 logical screen. #include #include #define UI_SCREEN_W 960 #define UI_SCREEN_H 544 // ---------- Colour tokens (design/stitch/_shared/ui.css), 0xAABBGGRR as GL reads RGBA bytes ---------- #define UI_RGBA(r, g, b, a) ((uint32_t)(r) | ((uint32_t)(g) << 8) | ((uint32_t)(b) << 16) | ((uint32_t)(a) << 24)) // Menu themes (OPTIONS > GENERAL > MENU COLOR, ui_theme.c). Colours and shape of every widget; // the active theme is picked on Core 1 at UiDraw_Begin, so a whole list uses one theme. typedef struct { const char *name; uint32_t frameA, barTop, barBot, barLine, onFrame, onSoft, title; uint32_t paper0, paper1, paper2, paperEdge, paperShade, paperStrip, stripInk, stripSoft; uint32_t rowA, rowB, rowLine, ink, inkSoft; uint32_t selTop, selBot, selEdge, selInk, selArrow; uint32_t tabTop, tabBot, tabEdge, tabHi, tabInk, rail, railEdge; uint32_t keyTop, keyBot, keyLight, keyDark, keyInk; uint32_t capTop, capBot, capEdge, capHi; uint32_t darkTop, darkBot, darkEdge, darkHi; uint32_t winTop, winBot, winInk; uint32_t chipTop, chipBot, chipEdge, chipInk; uint32_t dlgEdge, dlgTop, dlgBot, dlgShade; uint32_t btnTop[3], btnBot[3], btnEdge, btnInk; uint32_t accent, gold, dim, shadowCol; // Battle HUD (design/stitch/combate/themes.js): healthbox plates, HP label and bar back, // command buttons (FIGHT, BAG, POKéMON, RUN), highlighted words of the prompt uint32_t plateTop, plateBot, plateEdge, plateShade, plateRing, lvInk, hpInk, gauge; uint32_t cmdTop[4], cmdBot[4], cmdEdge, cmdInk, em; uint8_t radius; // corner size of boxes uint8_t selRadius; // 0: flat selection bar; >0: rounded selection pill uint8_t edge; // outline of paper panels uint8_t shadow, shadowR; // hard drop shadow, down and right bool chamfer; // corners cut diagonally instead of rounded bool gloss; // glass highlight on the upper half of bars, keys and buttons bool bevel; // inner highlight / shade lines bool stripes; // diagonal stripes on the full-screen frame uint8_t faceTitle; // font face of the Press Start 2P role (titles, labels, footer) uint8_t faceBody; // font face of the VT323 role (text, dialogue) uint8_t faceSign; // regular-weight text face of the zone signs (role 32) } UiTheme; enum { UI_THEME_RED, UI_THEME_EMERALD, UI_THEME_CRYSTAL, UI_THEME_TROPICAL, UI_THEME_ROYAL, UI_THEME_COUNT }; extern const UiTheme *gUiTheme; // Core 1 void UiTheme_Refresh(void); // reads the "ui_theme" extra (UiDraw_Begin) #define UI_COL_FRAME0_A (gUiTheme->frameA) // translucent full-screen frame (D3) #define UI_COL_FRAME1 (gUiTheme->capBot) #define UI_COL_FRAME2 (gUiTheme->darkTop) #define UI_COL_LINE_DARK (gUiTheme->barLine) #define UI_COL_ON_FRAME (gUiTheme->onFrame) #define UI_COL_ON_SOFT (gUiTheme->onSoft) #define UI_COL_TITLE (gUiTheme->title) #define UI_COL_GOLD (gUiTheme->gold) #define UI_COL_PAPER0 (gUiTheme->paper0) #define UI_COL_PAPER1 (gUiTheme->paper1) #define UI_COL_PAPER2 (gUiTheme->paper2) #define UI_COL_INK (gUiTheme->ink) #define UI_COL_INK_SOFT (gUiTheme->inkSoft) #define UI_COL_SELECT (gUiTheme->selBot) #define UI_COL_SELECT_INK (gUiTheme->selInk) #define UI_COL_MONEY UI_RGBA(224, 122, 31, 255) #define UI_COL_HP_HIGH UI_RGBA(63, 183, 107, 255) #define UI_COL_HP_MID UI_RGBA(232, 183, 48, 255) #define UI_COL_HP_LOW UI_RGBA(217, 72, 59, 255) #define UI_COL_EXP UI_RGBA(74, 159, 224, 255) #define UI_COL_BAR_BG UI_RGBA(44, 58, 51, 255) #define UI_COL_DIM (gUiTheme->dim) // ---------- Draw list (ui_draw.c) ---------- // Core 1 emits ready-to-draw vertices (two triangles per quad), so Core 0 only binds and draws. typedef struct { float x, y, u, v; uint32_t rgba; } UiGlVertex; #define UI_MAX_QUADS 4096 typedef struct { uint32_t vcount; // vertices (6 per quad) uint32_t seq; float tickMs; // Core 1 time spent building this list UiGlVertex verts[UI_MAX_QUADS * 6]; } UiDrawList; // Core 1 (writer) void UiDraw_Begin(void); // Quad with a vertical two-colour gradient (top, bottom); texels in atlas pixels. void UiDraw_Quad2(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t u0, uint32_t v0, uint32_t u1, uint32_t v1, uint32_t top, uint32_t bottom); void UiDraw_Quad(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t u0, uint32_t v0, uint32_t u1, uint32_t v1, uint32_t rgba); void UiDraw_Rect(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t rgba); void UiDraw_RectV(int32_t x, int32_t y, int32_t w, int32_t h, uint32_t top, uint32_t bottom); void UiDraw_Frame(int32_t x, int32_t y, int32_t w, int32_t h, int32_t t, uint32_t rgba); // outline void UiDraw_Sprite(uint16_t id, int32_t x, int32_t y, int32_t scale); // Any quad by its 4 corners (clockwise), flat colour: lines, triangles (repeat a corner), polygons void UiDraw_Poly4(const float *xs, const float *ys, uint32_t rgba); void UiDraw_Line(float x0, float y0, float x1, float y1, float width, uint32_t rgba); void UiDraw_Tri(float x0, float y0, float x1, float y1, float x2, float y2, uint32_t rgba); void UiDraw_PushClip(int32_t x, int32_t y, int32_t w, int32_t h); void UiDraw_PopClip(void); void UiDraw_Publish(float tickMs); uint32_t UiDraw_Count(void); // quads in the list being built // Core 0 (reader): the most recently published list (never NULL after init). const UiDrawList *UiDraw_Acquire(void); // ---------- Atlas and text (ui_assets.c) ---------- enum { UI_FACE_PS2P = 0, UI_FACE_VT323 = 1 }; // VT323 has one reading size: 28 was not legible on the Vita screen (D2, 2026-11-06) #define UI_BODY_PX 32 #define UI_DIALOG_PX 40 // dialogue text (VT323 40) // Footer guides and clock: Press Start 2P 16 (VT323 32 is too big for the 40 px footer) #define UI_FOOT_PX 16 #include "ui_sprite_ids.h" // fixed GBA sprites of the atlas (generated by tools/ui2/build_atlas.py) #define UI_SPR_BALL UI_SPR_BALL_POKE // One 1024x2048 RGBA5551 texture (2048 since the theme fonts, 2026-11-13): the fixed atlas on top (ui_atlas.bin, at most UI_DYN_Y rows) // and, below, 64x64 cells for sprites decoded at run time from the game's tables (ui_sprites.c). #define UI_TEX_W 1024 #define UI_TEX_H 2048 #define UI_DYN_Y 1024 #define UI_CELL 64 #define UI_CELL_COLS (UI_TEX_W / UI_CELL) #define UI_CELL_COUNT (UI_CELL_COLS * ((UI_TEX_H - UI_DYN_Y) / UI_CELL)) typedef struct { uint16_t x, y; uint8_t w, h; int8_t xoff, yoff; uint8_t adv; } UiGlyph; bool UiAssets_Load(void); bool UiAssets_Ready(void); const uint16_t *UiAssets_Pixels(uint16_t *outW, uint16_t *outH); // RGBA5551, fixed part (outH <= UI_DYN_Y) void UiAssets_TexSize(uint16_t *outW, uint16_t *outH); // whole texture: UI_TEX_W x UI_TEX_H void UiAssets_White(uint16_t *x, uint16_t *y); bool UiAssets_Sprite(uint16_t id, uint16_t *x, uint16_t *y, uint16_t *w, uint16_t *h); // Text in UTF-8 (Latin-1 subset of the atlas). Returns the advance width in pixels. int32_t UiText_Width(uint8_t face, uint8_t px, const char *s); int32_t UiText_Draw(uint8_t face, uint8_t px, int32_t x, int32_t y, const char *s, uint32_t rgba); // y = top of the line int32_t UiText_LineHeight(uint8_t face, uint8_t px); int32_t UiText_CapMid(uint8_t face, uint8_t px); int32_t UiText_InkWidth(uint8_t face, uint8_t px, const char *s); // width of the glyphs' ink int32_t UiText_DrawCentred(uint8_t face, uint8_t px, int32_t boxX, int32_t boxY, int32_t boxW, int32_t boxH, const char *s, uint32_t rgba); // top of line -> middle of the capitals int32_t UiText_DrawMid(uint8_t face, uint8_t px, int32_t x, int32_t boxY, int32_t boxH, const char *s, uint32_t rgba); // centred in the box // ---------- Run-time sprites (ui_sprites.c) ---------- // Core 1: draws a sprite decoded from the game's tables and cached in the texture's cells. The // first time a sprite is asked for, Core 1 decodes it and queues it for Core 0, which writes it // into the texture before drawing the list that uses it. Decodes per tick are capped, so a sprite // can show up a tick late; the calls return false when nothing was drawn this tick. bool UiSpr_MonIcon(uint16_t species, uint8_t frame, int32_t x, int32_t y, int32_t scale); // 32x32 bool UiSpr_MonFront(uint16_t species, bool shiny, int32_t x, int32_t y, int32_t scale); // 64x64 bool UiSpr_ItemIcon(uint16_t itemId, int32_t x, int32_t y, int32_t scale); // 24x24 bool UiSpr_Footprint(uint16_t species, int32_t x, int32_t y, int32_t scale, uint32_t rgba); // 16x16, tinted bool UiSpr_Wallpaper(uint8_t wallpaperId, int32_t x, int32_t y, int32_t scale); // PC box wallpaper, 160x144 bool UiSpr_ZonePlate(uint8_t theme, bool underwater, int32_t x, int32_t y, int32_t w); // zone sign plate, 80 tall bool UiSpr_Decoration(uint16_t decor, int32_t bx, int32_t by, int32_t box); // decoration picture, centred in a box bool UiSpr_MailStationery(uint8_t mailType, int32_t x, int32_t y, int32_t scale); // 240x160 mail paper bool UiSpr_Trainer(uint16_t trainerPic, int32_t x, int32_t y, int32_t scale); // 64x64 bool UiSpr_MonFrontTint(uint16_t species, int32_t x, int32_t y, int32_t scale, uint32_t rgba); bool UiSpr_MonFrontSized(uint16_t species, int32_t x, int32_t y, int32_t w, int32_t h); bool UiSpr_TrainerSized(uint16_t pic, int32_t x, int32_t y, int32_t w, int32_t h); void UiDraw_SpriteTint(uint16_t id, int32_t x, int32_t y, int32_t scale, uint32_t rgba); void UiSpr_BeginTick(void); // Core 1, before building a list void UiSpr_FlushUploads(void); // Core 0, with the UI texture bound, before drawing uint32_t UiSpr_DecodesLastTick(void); // telemetry for the test screen // ---------- Input (ui_core.c) ---------- typedef struct { uint32_t held, pressed, repeat; // VITA_BTN_* bits; repeat = pressed + auto-repeat of the d-pad bool touching, touchDown, tap; // tap = released without dragging int32_t tx, ty; // current touch point (logical pixels) int32_t downX, downY; // where the touch started int32_t dragDy; // vertical movement this tick while dragging bool dragging; } UiInput; static inline bool UiHit(const UiInput *in, int32_t x, int32_t y, int32_t w, int32_t h) { return in->tap && in->tx >= x && in->tx < x + w && in->ty >= y && in->ty < y + h; } // ---------- Widgets (ui_widgets.c), the components of design/stitch/_shared/ui.css ---------- enum { UI_GLYPH_CROSS = 0, UI_GLYPH_CIRCLE = 1, UI_GLYPH_TRIANGLE = 2, UI_GLYPH_SQUARE = 3 }; enum { UI_BTN_GREEN = 0, UI_BTN_AMBER = 1, UI_BTN_RED = 2 }; void UiW_FullFrame(void); // translucent frame + header + footer bars void UiW_FooterBar(void); // footer bar alone (screens over the world, like the START menu) int32_t UiW_Capsule(int32_t x, int32_t y, int32_t w, int32_t h); void UiW_HeaderTitle(const char *title); // Poké Ball + title in a bevelled capsule void UiW_HeaderValue(const char *text, uint32_t colour); // right-aligned capsule (money, name) // Tab rail "L [tabs] R" starting at x; fills tabX/tabW for hit testing; returns its right edge. int32_t UiW_Tabs(int32_t x, const char *const *labels, int32_t count, int32_t current, int32_t *tabX, int32_t *tabW); int32_t UiW_TabsPad(int32_t x, const char *const *labels, int32_t count, int32_t current, int32_t *tabX, int32_t *tabW, int32_t pad); int32_t UiW_TextWrapped(int32_t x, int32_t y, int32_t w, int32_t lineH, const char *text, uint32_t colour, int32_t maxLines); int32_t UiW_TextWrappedF(uint8_t face, uint8_t px, int32_t x, int32_t y, int32_t w, int32_t lineH, const char *text, uint32_t colour, int32_t maxLines); void UiW_FooterGlyph(int32_t *x, uint8_t glyph, const char *label); // PlayStation button guide void UiW_FooterKey(int32_t *x, const char *key, const char *label); // L / R / SELECT / START guide // Right end of every menu footer: the clock (HH:MM). The money goes in the header (UiW_HeaderValue). void UiW_FooterClock(const char *clock); void UiW_Glyph(int32_t x, int32_t y, uint8_t glyph); // 24 px button circle void UiW_Panel(int32_t x, int32_t y, int32_t w, int32_t h); void UiW_DialogBox(int32_t x, int32_t y, int32_t w, int32_t h); // dialogue and choice boxes // Box in the shape of the menu theme with the caller's colours (battle HUD). pill: fully rounded // ends (themes with a rounded selection); ring: an outline of 3 px around it (0: none) void UiW_ThemeBox(int32_t x, int32_t y, int32_t w, int32_t h, int32_t t, uint32_t edge, uint32_t top, uint32_t bottom, uint32_t hi, uint32_t shade, int32_t shadow, bool pill, uint32_t ring); void UiW_Bevel(int32_t x, int32_t y, int32_t w, int32_t h, int32_t t, uint32_t edge, uint32_t top, uint32_t bottom, int32_t b, uint32_t hi, uint32_t shade, int32_t shadow); void UiDraw_Darken(int32_t num, int32_t den); void UiW_Inset(int32_t x, int32_t y, int32_t w, int32_t h); // sunken info box void UiW_PanelDark(int32_t x, int32_t y, int32_t w, int32_t h); void UiW_PanelHead(int32_t x, int32_t y, int32_t w, const char *label, const char *right); void UiW_Window(int32_t x, int32_t y, int32_t w, int32_t h, const char *title); void UiW_Row(int32_t x, int32_t y, int32_t w, int32_t h, bool selected, int32_t index); int32_t UiW_Chip(int32_t x, int32_t y, const char *label, bool amber); void UiW_Bar(int32_t x, int32_t y, int32_t w, int32_t h, int32_t percent, uint32_t top, uint32_t bottom); void UiW_Button(int32_t x, int32_t y, int32_t w, const char *label, uint8_t colour, bool pressed); void UiW_Strip3(int32_t x, int32_t y, int32_t w, const char *const labels[3], const char *const values[3]); void UiW_Arrow(int32_t x, int32_t y, uint32_t colour); // ▶ cursor, 8x12 void UiW_Stepper(int32_t x, int32_t y, int32_t value, int32_t *minusX, int32_t *plusX); // [−] xNN [+], 40 px tall void UiW_ScrollBar(int32_t x, int32_t y, int32_t h, int32_t first, int32_t visible, int32_t total); void UiW_Toast(const char *text); // ---------- Screen kit (ui_kit.c) ---------- void UiKit_Toast(const char *fmt, ...); // short message over the screen (~2 s) void UiKit_DrawToast(void); // ui_core.c, after the screen's build void UiKit_ClearToast(void); // Scrollable list: d-pad, drag, first tap selects / second tap or X activates typedef struct { int32_t sel, first, count, rows, dragPx; } UiList; void UiList_Reset(UiList *l, int32_t count, int32_t visibleRows); // Returns the activated index, -1 if none (-2: X on an empty list) int32_t UiList_Update(UiList *l, const UiInput *in, int32_t x, int32_t y, int32_t w, int32_t rowH, bool wrap); #define UI_MENU_MAX 8 #define UI_MENU_NONE (-1) #define UI_MENU_CANCEL (-2) typedef struct { bool open; int32_t count, x, y, w; char title[24]; char labels[UI_MENU_MAX][24]; int32_t ids[UI_MENU_MAX]; UiList list; } UiMenu; void UiMenu_Open(UiMenu *m, const char *title, int32_t x, int32_t y, int32_t w); void UiMenu_Add(UiMenu *m, const char *label, int32_t id); int32_t UiMenu_Update(UiMenu *m, const UiInput *in); // id, UI_MENU_CANCEL or UI_MENU_NONE void UiMenu_Draw(const UiMenu *m); typedef struct { bool open; int32_t value, max, minusX, plusX, okX, stepY; char title[24]; } UiQty; void UiQty_Open(UiQty *q, const char *title, int32_t max); int32_t UiQty_Update(UiQty *q, const UiInput *in); // quantity, 0 cancel, -1 open void UiQty_Draw(UiQty *q, uint16_t itemId); // Full frame + title capsule + tab rail; returns the rail's right edge int32_t UiKit_Header(const char *title, const char *const *tabs, int32_t n, int32_t cur, int32_t *tabX, int32_t *tabW, int32_t pad); int32_t UiKit_TabHit(const UiInput *in, const int32_t *tabX, const int32_t *tabW, int32_t n); void UiKit_FooterClock(void); int32_t UiKit_GenderShiny(int32_t x, int32_t y, uint8_t gender, bool shiny); // ♂ / ♀ and the shiny star void UiKit_HeaderMoney(void); // ---------- Screens ---------- typedef struct { void (*enter)(void); // pushed (or replaced into the top) // Returns false to go back (pop). Runs on Core 1 between two game frames. bool (*update)(const UiInput *in); void (*build)(void); // emits this tick's draw list void (*resume)(void); // optional: the screen above it was popped } UiScreen; // Navigation (ui_core.c), from update(): the change shows from the next tick void UiNav_Push(const UiScreen *screen); void UiNav_Replace(const UiScreen *screen); void UiNav_Pop(void); void UiNav_Close(void (*afterClose)(void)); // closes the UI, then runs afterClose (may be NULL) in the field void UiCore_OpenScreen(const UiScreen *screen); bool UiSign_Draw(void); // ui_sign.c: zone sign overlay while no screen is open bool UiMirror_Draw(void); // ui_mirror.c: field windows (dialogue, YES / NO) void UiCore_OpenHosted(const UiScreen *screen, void (*afterClose)(void)); // the UI replaces a whole GBA scene (see ui_core.c) bool UiCore_IsHostCallback(void); void UiCore_OpenFromScript(const UiScreen *screen, void (*afterClose)(void)); // game script owns freeze / controls // opens the UI on a screen (from an afterClose) extern const UiScreen gUiHubScreen; extern const UiScreen gUiNamingScreen; extern const UiScreen gUiPcScreen; extern const UiScreen gUiBerryScreen; extern const UiScreen gUiEasyChatScreen; extern const UiScreen gUiBagScreen; extern const UiScreen gUiPartyScreen; extern const UiScreen gUiTargetScreen; extern const UiScreen gUiCardScreen; extern const UiScreen gUiOptionsScreen; extern const UiScreen gUiForgetMoveScreen; extern const UiScreen gUiPlayerPcScreen; extern const UiScreen gUiMailReadScreen; struct Mail; void UiMailRead_Set(const struct Mail *mail); // ui_scr_playerpc.c void UiMail_Draw(const struct Mail *mail, int32_t x, int32_t y, int32_t scale); extern const UiScreen gUiDexScreen; extern const UiScreen gUiDexDetailScreen; extern const UiScreen gUiNuzlockeScreen; extern const UiScreen gUiNavScreen; extern const UiScreen gUiFlyScreen; extern const UiScreen gUiMartScreen; extern const UiScreen gUiChooseScreen; extern bool gUiVoxelFrame; // sdl2.c (Core 0): the frame is the 3D world void UiFly_Set(uint8_t partySlot); void UiMap_DrawArea(const uint8_t *areas, uint32_t frame); // Hoenn map with highlighted areas (ui_scr_nav.c) // Arguments of the screens opened from others (set before UiNav_Push) enum { UI_TARGET_USE, UI_TARGET_GIVE, UI_TARGET_TM, UI_TARGET_BATTLE }; void UiBag_SetGiveTo(int32_t partySlot); // -1: normal bag; else GIVE to that POKéMON void UiTarget_Set(int32_t mode, uint16_t itemId); // ui_core.c: telemetry shared with the test screen float UiCore_LastRenderMs(void); float UiCore_AvgTickMs(void); void UiCore_SetLastRenderMs(float ms); // Core 0 // Stall detector (ui_stall.c): ux0:data/POKEVITA/ui_stall.log void UiStall_Tick(const UiScreen *top, float lastTickMs); // Core 1 void UiStall_Published(uint32_t seq); // Core 1 void UiStall_Closed(void); // Core 1 void UiStall_Render(uint32_t drawnSeq); // Core 0 // Field mirrors helpers shared with the battle HUD (ui_mirror.c) #include void UiMirror_Inject(uint16_t keys); // GBA keys for the next game frame bool UiMirror_Tap(int32_t *x, int32_t *y); // tap this tick (one caller per tick) // Battle HUD (ui_battle_hud.c), Core 1 bool UiContest_Draw(void); // ui_contest.c: contest appeal choice overlay bool UiBattle_Active(void); // the battle HUD replaces the GBA one void UiBattle_Tick(void); // every tick: hide flags for Core 0 / OAM bool UiBattle_Draw(void); // overlay while no screen is open #endif // UI_INTERNAL_H