all repos — mgba @ 6ee60dd79b6106385c5b2b26cfab00257fccf19a

mGBA Game Boy Advance Emulator

GUI: UI refinements, fixes
Jeffrey Pfau jeffrey@endrift.com
Sat, 30 Jan 2016 14:02:35 -0800
commit

6ee60dd79b6106385c5b2b26cfab00257fccf19a

parent

f1fba591524169276a95043354601b969d4deeb4

M src/platform/3ds/gui-font.csrc/platform/3ds/gui-font.c

@@ -124,3 +124,14 @@ ctrAddRect(color, x, y, metric.x, metric.y, metric.width, metric.height);

break; } } + +void GUIFontDrawIconSize(const 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) { + return; + } + + struct GUIIconMetric metric = defaultIconMetrics[icon]; + ctrAddRectScaled(color, x, y, w, h, metric.x, metric.y, metric.width, metric.height); +}
M src/platform/psp2/gui-font.csrc/platform/psp2/gui-font.c

@@ -54,12 +54,12 @@ if (glyph > 0x7F) {

glyph = '?'; } struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph]; - vita2d_draw_texture_tint_part_scale(font->tex, x, y - GLYPH_HEIGHT + metric.padding.top * 2, + vita2d_draw_texture_tint_part(font->tex, x, y - GLYPH_HEIGHT + metric.padding.top * 2, (glyph & 15) * CELL_WIDTH + metric.padding.left * 2, (glyph >> 4) * CELL_HEIGHT + metric.padding.top * 2, CELL_WIDTH - (metric.padding.left + metric.padding.right) * 2, CELL_HEIGHT - (metric.padding.top + metric.padding.bottom) * 2, - 1, 1, color); + color); } void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) {

@@ -86,13 +86,13 @@ }

switch (orient) { case GUI_ORIENT_HMIRROR: - vita2d_draw_texture_tint_part_scale(font->icons, x, y, + vita2d_draw_texture_tint_part_scale(font->icons, x + metric.width * 2, y, metric.x * 2, metric.y * 2, metric.width * 2, metric.height * 2, -1, 1, color); return; case GUI_ORIENT_VMIRROR: - vita2d_draw_texture_tint_part_scale(font->icons, x, y, + vita2d_draw_texture_tint_part_scale(font->icons, x, y + metric.height * 2, metric.x * 2, metric.y * 2, metric.width * 2, metric.height * 2, 1, -1, color);

@@ -107,3 +107,14 @@ color);

break; } } + +void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h, uint32_t color, enum GUIIcon icon) { + if (icon >= GUI_ICON_MAX) { + return; + } + struct GUIIconMetric metric = defaultIconMetrics[icon]; + vita2d_draw_texture_tint_part_scale(font->icons, x, y, + metric.x * 2, metric.y * 2, + metric.width * 2, metric.height * 2, + w / (float) metric.width, h / (float) metric.height, color); +}
M src/platform/wii/gui-font.csrc/platform/wii/gui-font.c

@@ -180,3 +180,48 @@ GX_Color1u32(color);

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) { + if (icon >= GUI_ICON_MAX) { + return; + } + + color = (color >> 24) | (color << 8); + GXTexObj tex; + + struct GUIFont* ncfont = font; + TPL_GetTexture(&ncfont->iconsTdf, 0, &tex); + GX_LoadTexObj(&tex, GX_TEXMAP0); + + GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_NOOP); + GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0); + GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_CLR0, GX_CLR_RGBA, GX_RGBA8, 0); + + struct GUIIconMetric metric = defaultIconMetrics[icon]; + + float u[4]; + float v[4]; + + u[0] = u[3] = metric.x / 256.f; + u[1] = u[2] = (metric.x + metric.width) / 256.f; + v[0] = v[1] = (metric.y + metric.height) / 64.f; + v[2] = v[3] = metric.y / 64.f; + + GX_Begin(GX_QUADS, GX_VTXFMT0, 4); + GX_Position2s16(x, y + h); + GX_Color1u32(color); + GX_TexCoord2f32(u[0], v[0]); + + GX_Position2s16(x + w, y + h); + GX_Color1u32(color); + GX_TexCoord2f32(u[1], v[1]); + + GX_Position2s16(x + w, y); + GX_Color1u32(color); + GX_TexCoord2f32(u[2], v[2]); + + GX_Position2s16(x, y); + GX_Color1u32(color); + GX_TexCoord2f32(u[3], v[3]); + GX_End(); +}
M src/util/gui/font.hsrc/util/gui/font.h

@@ -81,5 +81,6 @@ 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); #endif
M src/util/gui/menu.csrc/util/gui/menu.c

@@ -97,7 +97,7 @@ } else if (cy <= params->height && cy > params->height - lineHeight && menu->index < GUIMenuItemListSize(&menu->items) - 1) {

++menu->index; } else if (cy <= params->height - lineHeight && cy > 2 * lineHeight) { size_t location = cy - 2 * lineHeight; - location *= GUIMenuItemListSize(&menu->items); + location *= GUIMenuItemListSize(&menu->items) - 1; menu->index = location / (params->height - 3 * lineHeight); } }

@@ -149,10 +149,10 @@ for (i = start; i < GUIMenuItemListSize(&menu->items); ++i) {

int color = 0xE0A0A0A0; if (i == menu->index) { color = 0xFFFFFFFF; - GUIFontDrawIcon(params->font, 2, y, GUI_ALIGN_BOTTOM | GUI_ALIGN_LEFT, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_POINTER); + GUIFontDrawIcon(params->font, lineHeight * 0.8f, y, GUI_ALIGN_BOTTOM | GUI_ALIGN_RIGHT, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_POINTER); } struct GUIMenuItem* item = GUIMenuItemListGetPointer(&menu->items, i); - GUIFontPrintf(params->font, 0, y, GUI_ALIGN_LEFT, color, " %s", item->title); + GUIFontPrint(params->font, lineHeight, y, GUI_ALIGN_LEFT, color, item->title); if (item->validStates && item->validStates[item->state]) { GUIFontPrintf(params->font, params->width, y, GUI_ALIGN_RIGHT, color, "%s ", item->validStates[item->state]); }

@@ -163,15 +163,13 @@ }

} if (itemsPerScreen < GUIMenuItemListSize(&menu->items)) { - y = 2 * lineHeight; - GUIFontDrawIcon(params->font, params->width - 8, y, GUI_ALIGN_HCENTER | GUI_ALIGN_BOTTOM, GUI_ORIENT_VMIRROR, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_BUTTON); - for (; y < params->height - 16; y += 16) { - GUIFontDrawIcon(params->font, params->width - 8, y, GUI_ALIGN_HCENTER | GUI_ALIGN_TOP, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_TRACK); - } - GUIFontDrawIcon(params->font, params->width - 8, y, GUI_ALIGN_HCENTER | GUI_ALIGN_TOP, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_BUTTON); + size_t top = 2 * lineHeight; + size_t bottom = params->height - 8; + GUIFontDrawIcon(params->font, params->width - 8, top, GUI_ALIGN_HCENTER | GUI_ALIGN_BOTTOM, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_BUTTON); + GUIFontDrawIconSize(params->font, params->width - 9, top, 2, bottom - top, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_TRACK); + GUIFontDrawIcon(params->font, params->width - 8, bottom, GUI_ALIGN_HCENTER | GUI_ALIGN_TOP, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_BUTTON); - size_t top = 2 * lineHeight; - y = menu->index * (y - top - 16) / GUIMenuItemListSize(&menu->items); + y = menu->index * (bottom - top - 16) / GUIMenuItemListSize(&menu->items); GUIFontDrawIcon(params->font, params->width - 8, top + y, GUI_ALIGN_HCENTER | GUI_ALIGN_TOP, GUI_ORIENT_0, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_THUMB); }