GUI: UI refinements, fixes

This commit is contained in:
Jeffrey Pfau 2016-01-30 14:02:35 -08:00
parent f1fba59152
commit 6ee60dd79b
5 changed files with 81 additions and 15 deletions

View File

@ -124,3 +124,14 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
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);
}

View File

@ -54,12 +54,12 @@ void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color,
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 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
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 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
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);
}

View File

@ -180,3 +180,48 @@ void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment
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();
}

View File

@ -81,5 +81,6 @@ void GUIFontPrintf(const struct GUIFont*, int x, int y, enum GUIAlignment, uint3
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

View File

@ -97,7 +97,7 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
++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 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
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 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
}
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;
y = menu->index * (y - top - 16) / GUIMenuItemListSize(&menu->items);
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);
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);
}