mirror of https://github.com/mgba-emu/mgba.git
mGUI: De-constify fonts
This commit is contained in:
parent
1426adfaa3
commit
00531d1180
|
@ -60,7 +60,7 @@ struct GUIBackground {
|
|||
struct GUIParams {
|
||||
unsigned width;
|
||||
unsigned height;
|
||||
const struct GUIFont* font;
|
||||
struct GUIFont* font;
|
||||
const char* basePath;
|
||||
|
||||
void (*drawStart)(void);
|
||||
|
|
|
@ -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);
|
||||
|
|
|
@ -89,7 +89,7 @@ void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned*
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ void GUIFontDrawGlyph(const struct GUIFont* font, int glyph_x, int glyph_y, uint
|
|||
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 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
|
|||
}
|
||||
}
|
||||
|
||||
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) {
|
||||
|
|
|
@ -65,13 +65,13 @@ void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned*
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
|
|||
}
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
|
@ -302,39 +302,38 @@ void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned*
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
|
|||
// 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 @@ void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int 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) {
|
||||
|
|
|
@ -84,12 +84,10 @@ void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned*
|
|||
}
|
||||
}
|
||||
|
||||
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 @@ void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color,
|
|||
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 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
|
|||
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 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
|
|||
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 @@ void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h,
|
|||
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);
|
||||
|
|
|
@ -26,7 +26,7 @@ unsigned GUIFontSpanWidth(const struct GUIFont* font, const char* text) {
|
|||
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 GUIFontPrint(const struct GUIFont* font, int x, int y, enum GUIAlignment al
|
|||
}
|
||||
}
|
||||
|
||||
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);
|
||||
|
|
Loading…
Reference in New Issue