GUI: Show icons in key remapping
Jeffrey Pfau jeffrey@endrift.com
Sun, 31 Jan 2016 20:09:50 -0800
9 files changed,
111 insertions(+),
20 deletions(-)
M
src/platform/3ds/gui-font.c
→
src/platform/3ds/gui-font.c
@@ -70,6 +70,25 @@ }
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 @@ return;
} 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); }
M
src/platform/psp2/gui-font.c
→
src/platform/psp2/gui-font.c
@@ -49,6 +49,25 @@ }
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 @@ 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); + w ? (w / (float) metric.width) : 1, h ? (h / (float) metric.height) : 1, color); }
M
src/platform/psp2/main.c
→
src/platform/psp2/main.c
@@ -136,10 +136,10 @@ "L",
"R", 0, // L2? 0, // R2? - "Triangle", - "Circle", - "Cross", - "Square" + "\1\xC", + "\1\xA", + "\1\xB", + "\1\xD" }, .nKeys = 16 },
M
src/platform/wii/gui-font.c
→
src/platform/wii/gui-font.c
@@ -65,6 +65,25 @@ }
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;@@ -201,6 +220,13 @@ struct GUIIconMetric metric = defaultIconMetrics[icon];
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;
M
src/platform/wii/main.c
→
src/platform/wii/main.c
@@ -264,15 +264,15 @@ "2",
"1", "B", "A", - "Minus", + "-", 0, 0, - "Home", + "\1\xE", "Left", "Right", "Down", "Up", - "Plus", + "+", 0, 0, 0,@@ -311,9 +311,9 @@ "B",
"ZL", 0, "R", - "Plus", - "Home", - "Minus", + "+", + "\1\xE", + "-", "L", "Down", "Right",
M
src/util/gui/font-metrics.c
→
src/util/gui/font-metrics.c
@@ -151,5 +151,5 @@ [GUI_ICON_BUTTON_CIRCLE] = { 2, 34, 12, 11 },
[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 }, };
M
src/util/gui/font.c
→
src/util/gui/font.c
@@ -5,12 +5,23 @@ * License, v. 2.0. If a copy of the MPL was not distributed with this
* 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 @@ }
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); + } } }
M
src/util/gui/font.h
→
src/util/gui/font.h
@@ -75,6 +75,7 @@
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, ...);