From 8e99508717c7c5e2316c50a03dd156d4d86bceeb Mon Sep 17 00:00:00 2001 From: Jeffrey Pfau Date: Sun, 31 Jan 2016 20:09:50 -0800 Subject: [PATCH] GUI: Show icons in key remapping --- src/platform/3ds/gui-font.c | 21 ++++++++++++++++++++- src/platform/psp2/gui-font.c | 21 ++++++++++++++++++++- src/platform/psp2/main.c | 8 ++++---- src/platform/wii/gui-font.c | 26 ++++++++++++++++++++++++++ src/platform/wii/main.c | 12 ++++++------ src/util/gui/font-metrics.c | 2 +- src/util/gui/font.c | 33 +++++++++++++++++++++++++++------ src/util/gui/font.h | 1 + src/util/gui/menu.c | 7 ++++++- 9 files changed, 111 insertions(+), 20 deletions(-) diff --git a/src/platform/3ds/gui-font.c b/src/platform/3ds/gui-font.c index aca90e9a7..7bec4ab44 100644 --- a/src/platform/3ds/gui-font.c +++ b/src/platform/3ds/gui-font.c @@ -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); } diff --git a/src/platform/psp2/gui-font.c b/src/platform/psp2/gui-font.c index 1878b039a..aa1e6cdc1 100644 --- a/src/platform/psp2/gui-font.c +++ b/src/platform/psp2/gui-font.c @@ -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); } diff --git a/src/platform/psp2/main.c b/src/platform/psp2/main.c index 708d9dd36..b16abeae3 100644 --- a/src/platform/psp2/main.c +++ b/src/platform/psp2/main.c @@ -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 }, diff --git a/src/platform/wii/gui-font.c b/src/platform/wii/gui-font.c index b4f6ffae4..8ca4c6550 100644 --- a/src/platform/wii/gui-font.c +++ b/src/platform/wii/gui-font.c @@ -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; diff --git a/src/platform/wii/main.c b/src/platform/wii/main.c index c44092198..e3b2b9524 100644 --- a/src/platform/wii/main.c +++ b/src/platform/wii/main.c @@ -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", diff --git a/src/util/gui/font-metrics.c b/src/util/gui/font-metrics.c index 3430e3b4b..684635d26 100644 --- a/src/util/gui/font-metrics.c +++ b/src/util/gui/font-metrics.c @@ -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 }, }; diff --git a/src/util/gui/font.c b/src/util/gui/font.c index a24ca9466..03965bf24 100644 --- a/src/util/gui/font.c +++ b/src/util/gui/font.c @@ -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); + } } } diff --git a/src/util/gui/font.h b/src/util/gui/font.h index 91dac288a..7c936ffb9 100644 --- a/src/util/gui/font.h +++ b/src/util/gui/font.h @@ -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, ...); diff --git a/src/util/gui/menu.c b/src/util/gui/menu.c index 65c2d038f..a64de2c48 100644 --- a/src/util/gui/menu.c +++ b/src/util/gui/menu.c @@ -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);