mGUI: De-constify fonts
Vicki Pfau vi@endrift.com
Sat, 27 Mar 2021 21:46:20 -0700
7 files changed,
74 insertions(+),
83 deletions(-)
M
include/mgba-util/gui.h
→
include/mgba-util/gui.h
@@ -60,7 +60,7 @@
struct GUIParams { unsigned width; unsigned height; - const struct GUIFont* font; + struct GUIFont* font; const char* basePath; void (*drawStart)(void);
M
include/mgba-util/gui/font.h
→
include/mgba-util/gui/font.h
@@ -81,13 +81,12 @@ unsigned GUIFontGlyphWidth(const struct GUIFont*, uint32_t glyph);
unsigned GUIFontSpanWidth(const struct GUIFont*, const char* text); void GUIFontIconMetrics(const struct GUIFont*, enum GUIIcon icon, unsigned* w, unsigned* h); -// TODO: de-const these ATTRIBUTE_FORMAT(printf, 6, 7) -void GUIFontPrintf(const struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text, ...); -void GUIFontPrint(const struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text); -void GUIFontDrawGlyph(const struct GUIFont*, int x, int y, uint32_t color, uint32_t glyph); -void GUIFontDrawIcon(const struct GUIFont*, int x, int y, enum GUIAlignment, enum GUIOrientation, uint32_t color, enum GUIIcon); -void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon); +void GUIFontPrintf(struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text, ...); +void GUIFontPrint(struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text); +void GUIFontDrawGlyph(struct GUIFont*, int x, int y, uint32_t color, uint32_t glyph); +void GUIFontDrawIcon(struct GUIFont*, int x, int y, enum GUIAlignment, enum GUIOrientation, uint32_t color, enum GUIIcon); +void GUIFontDrawIconSize(struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon); #ifdef __SWITCH__ void GUIFontDrawSubmit(struct GUIFont* font);
M
src/platform/3ds/gui-font.c
→
src/platform/3ds/gui-font.c
@@ -89,7 +89,7 @@ }
} } -void GUIFontDrawGlyph(const struct GUIFont* font, int glyph_x, int glyph_y, uint32_t color, uint32_t glyph) { +void GUIFontDrawGlyph(struct GUIFont* font, int glyph_x, int glyph_y, uint32_t color, uint32_t glyph) { int index = fontGlyphIndexFromCodePoint(font->font, glyph); fontGlyphPos_s data; fontCalcGlyphPos(&data, font->font, index, 0, 1.0, 1.0);@@ -109,7 +109,7 @@ tex->width * width * font->size, tex->height * height * -font->size,
u, v, tex->width * width, tex->height * height, 0); } -void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIcon(struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { ctrActivateTexture(&font->icons); if (icon >= GUI_ICON_MAX) {@@ -159,7 +159,7 @@ break;
} } -void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIconSize(struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { ctrActivateTexture(&font->icons); if (icon >= GUI_ICON_MAX) {
M
src/platform/psp2/gui-font.c
→
src/platform/psp2/gui-font.c
@@ -65,13 +65,13 @@ }
} } -void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { +void GUIFontDrawGlyph(struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { char base[5] = { 0 }; toUtf8(glyph, base); vita2d_pgf_draw_text(font->pgf, x, y, color, FONT_SIZE, base); } -void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIcon(struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { if (icon >= GUI_ICON_MAX) { return; }@@ -117,7 +117,7 @@ break;
} } -void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIconSize(struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { if (icon >= GUI_ICON_MAX) { return; }
M
src/platform/switch/gui-font.c
→
src/platform/switch/gui-font.c
@@ -302,39 +302,38 @@ }
} } -void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { +void GUIFontDrawGlyph(struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { if (glyph > 0x7F) { glyph = '?'; } struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph]; - struct GUIFont* mutfont = (struct GUIFont*) font; if (font->currentGlyph >= MAX_GLYPHS) { - GUIFontDrawSubmit(mutfont); + GUIFontDrawSubmit(font); } int offset = font->currentGlyph; - mutfont->originData[offset][0] = x; - mutfont->originData[offset][1] = y - GLYPH_HEIGHT + metric.padding.top * 2; - mutfont->originData[offset][2] = 0; - mutfont->glyphData[offset][0] = (glyph & 15) * CELL_WIDTH + metric.padding.left * 2; - mutfont->glyphData[offset][1] = (glyph >> 4) * CELL_HEIGHT + metric.padding.top * 2; - mutfont->dimsData[offset][0] = CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2; - mutfont->dimsData[offset][1] = CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2; - mutfont->transformData[0][offset][0] = 1.0f; - mutfont->transformData[0][offset][1] = 0.0f; - mutfont->transformData[1][offset][0] = 0.0f; - mutfont->transformData[1][offset][1] = 1.0f; - mutfont->colorData[offset][0] = (color & 0xFF) / 255.0f; - mutfont->colorData[offset][1] = ((color >> 8) & 0xFF) / 255.0f; - mutfont->colorData[offset][2] = ((color >> 16) & 0xFF) / 255.0f; - mutfont->colorData[offset][3] = ((color >> 24) & 0xFF) / 255.0f; + font->originData[offset][0] = x; + font->originData[offset][1] = y - GLYPH_HEIGHT + metric.padding.top * 2; + font->originData[offset][2] = 0; + font->glyphData[offset][0] = (glyph & 15) * CELL_WIDTH + metric.padding.left * 2; + font->glyphData[offset][1] = (glyph >> 4) * CELL_HEIGHT + metric.padding.top * 2; + font->dimsData[offset][0] = CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2; + font->dimsData[offset][1] = CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2; + font->transformData[0][offset][0] = 1.0f; + font->transformData[0][offset][1] = 0.0f; + font->transformData[1][offset][0] = 0.0f; + font->transformData[1][offset][1] = 1.0f; + font->colorData[offset][0] = (color & 0xFF) / 255.0f; + font->colorData[offset][1] = ((color >> 8) & 0xFF) / 255.0f; + font->colorData[offset][2] = ((color >> 16) & 0xFF) / 255.0f; + font->colorData[offset][3] = ((color >> 24) & 0xFF) / 255.0f; - ++mutfont->currentGlyph; + ++font->currentGlyph; } -void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIcon(struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { if (icon >= GUI_ICON_MAX) { return; }@@ -371,34 +370,32 @@ default:
// TODO: Rotate break; } - - struct GUIFont* mutfont = (struct GUIFont*) font; if (font->currentGlyph >= MAX_GLYPHS) { - GUIFontDrawSubmit(mutfont); + GUIFontDrawSubmit(font); } int offset = font->currentGlyph; - mutfont->originData[offset][0] = x; - mutfont->originData[offset][1] = y; - mutfont->originData[offset][2] = 0; - mutfont->glyphData[offset][0] = metric.x * 2; - mutfont->glyphData[offset][1] = metric.y * 2 + 256; - mutfont->dimsData[offset][0] = metric.width * 2; - mutfont->dimsData[offset][1] = metric.height * 2; - mutfont->transformData[0][offset][0] = hFlip; - mutfont->transformData[0][offset][1] = 0.0f; - mutfont->transformData[1][offset][0] = 0.0f; - mutfont->transformData[1][offset][1] = vFlip; - mutfont->colorData[offset][0] = (color & 0xFF) / 255.0f; - mutfont->colorData[offset][1] = ((color >> 8) & 0xFF) / 255.0f; - mutfont->colorData[offset][2] = ((color >> 16) & 0xFF) / 255.0f; - mutfont->colorData[offset][3] = ((color >> 24) & 0xFF) / 255.0f; + font->originData[offset][0] = x; + font->originData[offset][1] = y; + font->originData[offset][2] = 0; + font->glyphData[offset][0] = metric.x * 2; + font->glyphData[offset][1] = metric.y * 2 + 256; + font->dimsData[offset][0] = metric.width * 2; + font->dimsData[offset][1] = metric.height * 2; + font->transformData[0][offset][0] = hFlip; + font->transformData[0][offset][1] = 0.0f; + font->transformData[1][offset][0] = 0.0f; + font->transformData[1][offset][1] = vFlip; + font->colorData[offset][0] = (color & 0xFF) / 255.0f; + font->colorData[offset][1] = ((color >> 8) & 0xFF) / 255.0f; + font->colorData[offset][2] = ((color >> 16) & 0xFF) / 255.0f; + font->colorData[offset][3] = ((color >> 24) & 0xFF) / 255.0f; - ++mutfont->currentGlyph; + ++font->currentGlyph; } -void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIconSize(struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { if (icon >= GUI_ICON_MAX) { return; }@@ -411,30 +408,29 @@ if (!h) {
h = metric.height * 2; } - struct GUIFont* mutfont = (struct GUIFont*) font; if (font->currentGlyph >= MAX_GLYPHS) { - GUIFontDrawSubmit(mutfont); + GUIFontDrawSubmit(font); } int offset = font->currentGlyph; - mutfont->originData[offset][0] = x + w / 2 - metric.width; - mutfont->originData[offset][1] = y + h / 2 - metric.height; - mutfont->originData[offset][2] = 0; - mutfont->glyphData[offset][0] = metric.x * 2; - mutfont->glyphData[offset][1] = metric.y * 2 + 256; - mutfont->dimsData[offset][0] = metric.width * 2; - mutfont->dimsData[offset][1] = metric.height * 2; - mutfont->transformData[0][offset][0] = w * 0.5f / metric.width; - mutfont->transformData[0][offset][1] = 0.0f; - mutfont->transformData[1][offset][0] = 0.0f; - mutfont->transformData[1][offset][1] = h * 0.5f / metric.height; - mutfont->colorData[offset][0] = (color & 0xFF) / 255.0f; - mutfont->colorData[offset][1] = ((color >> 8) & 0xFF) / 255.0f; - mutfont->colorData[offset][2] = ((color >> 16) & 0xFF) / 255.0f; - mutfont->colorData[offset][3] = ((color >> 24) & 0xFF) / 255.0f; + font->originData[offset][0] = x + w / 2 - metric.width; + font->originData[offset][1] = y + h / 2 - metric.height; + font->originData[offset][2] = 0; + font->glyphData[offset][0] = metric.x * 2; + font->glyphData[offset][1] = metric.y * 2 + 256; + font->dimsData[offset][0] = metric.width * 2; + font->dimsData[offset][1] = metric.height * 2; + font->transformData[0][offset][0] = w * 0.5f / metric.width; + font->transformData[0][offset][1] = 0.0f; + font->transformData[1][offset][0] = 0.0f; + font->transformData[1][offset][1] = h * 0.5f / metric.height; + font->colorData[offset][0] = (color & 0xFF) / 255.0f; + font->colorData[offset][1] = ((color >> 8) & 0xFF) / 255.0f; + font->colorData[offset][2] = ((color >> 16) & 0xFF) / 255.0f; + font->colorData[offset][3] = ((color >> 24) & 0xFF) / 255.0f; - ++mutfont->currentGlyph; + ++font->currentGlyph; } void GUIFontDrawSubmit(struct GUIFont* font) {
M
src/platform/wii/gui-font.c
→
src/platform/wii/gui-font.c
@@ -84,12 +84,10 @@ }
} } -void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { +void GUIFontDrawGlyph(struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) { color = (color >> 24) | (color << 8); GXTexObj tex; - // Grumble grumble, libogc is bad about const-correctness - struct GUIFont* ncfont = font; - TPL_GetTexture(&ncfont->tdf, 0, &tex); + TPL_GetTexture(&font->tdf, 0, &tex); GX_LoadTexObj(&tex, GX_TEXMAP0); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP);@@ -120,7 +118,7 @@ GX_TexCoord2f32(tx / 512.f, (ty + CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2) / 256.f);
GX_End(); } -void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIcon(struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) { if (icon >= GUI_ICON_MAX) { return; }@@ -128,8 +126,7 @@
color = (color >> 24) | (color << 8); GXTexObj tex; - struct GUIFont* ncfont = font; - TPL_GetTexture(&ncfont->iconsTdf, 0, &tex); + TPL_GetTexture(&font->iconsTdf, 0, &tex); GX_LoadTexObj(&tex, GX_TEXMAP0); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP);@@ -198,7 +195,7 @@ GX_TexCoord2f32(u[3], v[3]);
GX_End(); } -void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { +void GUIFontDrawIconSize(struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { if (icon >= GUI_ICON_MAX) { return; }@@ -206,8 +203,7 @@
color = (color >> 24) | (color << 8); GXTexObj tex; - struct GUIFont* ncfont = font; - TPL_GetTexture(&ncfont->iconsTdf, 0, &tex); + TPL_GetTexture(&font->iconsTdf, 0, &tex); GX_LoadTexObj(&tex, GX_TEXMAP0); GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP);
M
src/util/gui/font.c
→
src/util/gui/font.c
@@ -26,7 +26,7 @@ }
return width; } -void GUIFontPrint(const struct GUIFont* font, int x, int y, enum GUIAlignment align, uint32_t color, const char* text) { +void GUIFontPrint(struct GUIFont* font, int x, int y, enum GUIAlignment align, uint32_t color, const char* text) { switch (align & GUI_ALIGN_HCENTER) { case GUI_ALIGN_HCENTER: x -= GUIFontSpanWidth(font, text) / 2;@@ -55,7 +55,7 @@ }
} } -void GUIFontPrintf(const struct GUIFont* font, int x, int y, enum GUIAlignment align, uint32_t color, const char* text, ...) { +void GUIFontPrintf(struct GUIFont* font, int x, int y, enum GUIAlignment align, uint32_t color, const char* text, ...) { char buffer[256]; va_list args; va_start(args, text);