GUI: Show icons in key remapping

This commit is contained in:
Jeffrey Pfau 2016-01-31 20:09:50 -08:00
parent d53004650d
commit 8e99508717
9 changed files with 111 additions and 20 deletions

View File

@ -70,6 +70,25 @@ unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
return defaultFontMetrics[glyph].width;
}
void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned* w, unsigned* h) {
UNUSED(font);
if (icon >= GUI_ICON_MAX) {
if (w) {
*w = 0;
}
if (h) {
*h = 0;
}
} else {
if (w) {
*w = defaultIconMetrics[icon].width;
}
if (h) {
*h = defaultIconMetrics[icon].height;
}
}
}
void GUIFontDrawGlyph(const struct GUIFont* font, int glyph_x, int glyph_y, uint32_t color, uint32_t glyph) {
ctrActivateTexture(&font->texture);
@ -133,5 +152,5 @@ void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h,
}
struct GUIIconMetric metric = defaultIconMetrics[icon];
ctrAddRectScaled(color, x, y, w, h, metric.x, metric.y, metric.width, metric.height);
ctrAddRectScaled(color, x, y, w ? w : metric.width, h ? h : metric.height, metric.x, metric.y, metric.width, metric.height);
}

View File

@ -49,6 +49,25 @@ unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
return defaultFontMetrics[glyph].width * 2;
}
void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned* w, unsigned* h) {
UNUSED(font);
if (icon >= GUI_ICON_MAX) {
if (w) {
*w = 0;
}
if (h) {
*h = 0;
}
} else {
if (w) {
*w = defaultIconMetrics[icon].width * 2;
}
if (h) {
*h = defaultIconMetrics[icon].height * 2;
}
}
}
void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
if (glyph > 0x7F) {
glyph = '?';
@ -116,5 +135,5 @@ void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h,
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);
w ? (w / (float) metric.width) : 1, h ? (h / (float) metric.height) : 1, color);
}

View File

@ -136,10 +136,10 @@ int main() {
"R",
0, // L2?
0, // R2?
"Triangle",
"Circle",
"Cross",
"Square"
"\1\xC",
"\1\xA",
"\1\xB",
"\1\xD"
},
.nKeys = 16
},

View File

@ -65,6 +65,25 @@ unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
return defaultFontMetrics[glyph].width * 2;
}
void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned* w, unsigned* h) {
UNUSED(font);
if (icon >= GUI_ICON_MAX) {
if (w) {
*w = 0;
}
if (h) {
*h = 0;
}
} else {
if (w) {
*w = defaultIconMetrics[icon].width * 2;
}
if (h) {
*h = defaultIconMetrics[icon].height * 2;
}
}
}
void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
color = (color >> 24) | (color << 8);
GXTexObj tex;
@ -202,6 +221,13 @@ void GUIFontDrawIconSize(const struct GUIFont* font, int x, int y, int w, int h,
float u[4];
float v[4];
if (!h) {
h = metric.height * 2;
}
if (!w) {
w = metric.width * 2;
}
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;

View File

@ -264,15 +264,15 @@ int main(int argc, char* argv[]) {
"1",
"B",
"A",
"Minus",
"-",
0,
0,
"Home",
"\1\xE",
"Left",
"Right",
"Down",
"Up",
"Plus",
"+",
0,
0,
0,
@ -311,9 +311,9 @@ int main(int argc, char* argv[]) {
"ZL",
0,
"R",
"Plus",
"Home",
"Minus",
"+",
"\1\xE",
"-",
"L",
"Down",
"Right",

View File

@ -151,5 +151,5 @@ struct GUIIconMetric defaultIconMetrics[] = {
[GUI_ICON_BUTTON_CROSS] = { 18, 34, 12, 11 },
[GUI_ICON_BUTTON_TRIANGLE] = { 34, 34, 12, 11 },
[GUI_ICON_BUTTON_SQUARE] = { 50, 34, 12, 11 },
[GUI_ICON_BUTTON_HOME] = { 66, 34, 16, 16 },
[GUI_ICON_BUTTON_HOME] = { 66, 34, 12, 11 },
};

View File

@ -5,12 +5,23 @@
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
#include "util/gui/font.h"
#include "util/string.h"
unsigned GUIFontSpanWidth(const struct GUIFont* font, const char* text) {
unsigned width = 0;
size_t i;
for (i = 0; text[i]; ++i) {
char c = text[i];
width += GUIFontGlyphWidth(font, c);
size_t len = strlen(text);
while (len) {
uint32_t c = utf8Char(&text, &len);
if (c == '\1') {
c = utf8Char(&text, &len);
if (c < GUI_ICON_MAX) {
unsigned w;
GUIFontIconMetrics(font, c, &w, 0);
width += w;
}
} else {
width += GUIFontGlyphWidth(font, c);
}
}
return width;
}
@ -29,8 +40,18 @@ void GUIFontPrint(const struct GUIFont* font, int x, int y, enum GUIAlignment al
size_t len = strlen(text);
while (len) {
uint32_t c = utf8Char(&text, &len);
GUIFontDrawGlyph(font, x, y, color, c);
x += GUIFontGlyphWidth(font, c);
if (c == '\1') {
c = utf8Char(&text, &len);
if (c < GUI_ICON_MAX) {
GUIFontDrawIcon(font, x, y, GUI_ALIGN_BOTTOM, GUI_ORIENT_0, color, c);
unsigned w;
GUIFontIconMetrics(font, c, &w, 0);
x += w;
}
} else {
GUIFontDrawGlyph(font, x, y, color, c);
x += GUIFontGlyphWidth(font, c);
}
}
}

View File

@ -75,6 +75,7 @@ struct GUIIconMetric {
unsigned GUIFontHeight(const struct GUIFont*);
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);
ATTRIBUTE_FORMAT(printf, 6, 7)
void GUIFontPrintf(const struct GUIFont*, int x, int y, enum GUIAlignment, uint32_t color, const char* text, ...);

View File

@ -165,8 +165,13 @@ enum GUIMenuExitReason GUIShowMenu(struct GUIParams* params, struct GUIMenu* men
if (itemsPerScreen < GUIMenuItemListSize(&menu->items)) {
size_t top = 2 * lineHeight;
size_t bottom = params->height - 8;
unsigned w;
unsigned right;
GUIFontIconMetrics(params->font, GUI_ICON_SCROLLBAR_BUTTON, &right, 0);
GUIFontIconMetrics(params->font, GUI_ICON_SCROLLBAR_TRACK, &w, 0);
right = (right - w) / 2;
GUIFontDrawIcon(params->font, params->width - 8, top, GUI_ALIGN_HCENTER | GUI_ALIGN_BOTTOM, GUI_ORIENT_VMIRROR, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_BUTTON);
GUIFontDrawIconSize(params->font, params->width - 9, top, 2, bottom - top, 0xFFFFFFFF, GUI_ICON_SCROLLBAR_TRACK);
GUIFontDrawIconSize(params->font, params->width - right - 8, top, 0, 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);