PSP2: Use PGF fonts
Jeffrey Pfau jeffrey@endrift.com
Fri, 29 Jul 2016 21:11:49 -0700
3 files changed,
11 insertions(+),
17 deletions(-)
M
src/platform/psp2/CMakeLists.txt
→
src/platform/psp2/CMakeLists.txt
@@ -15,7 +15,7 @@
list(APPEND CORE_VFS_SRC ${CMAKE_CURRENT_SOURCE_DIR}/sce-vfs.c) set(CORE_VFS_SRC ${CORE_VFS_SRC} PARENT_SCOPE) -set(OS_LIB -lvita2d -lSceCtrl_stub -lSceGxm_stub -lSceDisplay_stub -lSceAudio_stub -lSceCommonDialog_stub -lSceMotion_stub -lScePower_stub -lSceSysmodule_stub -lSceTouch_stub -l${M_LIBRARY}) +set(OS_LIB -lvita2d -lSceCtrl_stub -lScePgf_stub -lSceGxm_stub -lSceDisplay_stub -lSceAudio_stub -lSceCommonDialog_stub -lSceMotion_stub -lScePower_stub -lSceSysmodule_stub -lSceTouch_stub -l${M_LIBRARY}) set(OBJCOPY_CMD ${OBJCOPY} -I binary -O elf32-littlearm -B arm) list(APPEND GUI_SRC ${CMAKE_CURRENT_SOURCE_DIR}/gui-font.c)
M
src/platform/psp2/gui-font.c
→
src/platform/psp2/gui-font.c
@@ -10,13 +10,12 @@ #include <vita2d.h>
#define CELL_HEIGHT 32 #define CELL_WIDTH 32 -#define GLYPH_HEIGHT 24 +#define FONT_SIZE 1.2f -extern const uint8_t _binary_font2x_png_start[]; extern const uint8_t _binary_icons2x_png_start[]; struct GUIFont { - vita2d_texture* tex; + vita2d_pgf* pgf; vita2d_texture* icons; };@@ -25,28 +24,27 @@ struct GUIFont* font = malloc(sizeof(struct GUIFont));
if (!font) { return 0; } - font->tex = vita2d_load_PNG_buffer(_binary_font2x_png_start); + font->pgf = vita2d_load_default_pgf(); font->icons = vita2d_load_PNG_buffer(_binary_icons2x_png_start); return font; } void GUIFontDestroy(struct GUIFont* font) { - vita2d_free_texture(font->tex); + vita2d_free_pgf(font->pgf); vita2d_free_texture(font->icons); free(font); } unsigned GUIFontHeight(const struct GUIFont* font) { - UNUSED(font); - return GLYPH_HEIGHT; + return vita2d_pgf_text_height(font->pgf, FONT_SIZE, "M") + 8; } unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) { - UNUSED(font); if (glyph > 0x7F) { glyph = '?'; } - return defaultFontMetrics[glyph].width * 2; + char base[5] = { glyph }; + return vita2d_pgf_text_width(font->pgf, FONT_SIZE, base); } void GUIFontIconMetrics(const struct GUIFont* font, enum GUIIcon icon, unsigned* w, unsigned* h) {@@ -72,13 +70,8 @@ void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
if (glyph > 0x7F) { glyph = '?'; } - struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph]; - 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, - color); + char base[5] = { glyph }; + vita2d_pgf_draw_text(font->pgf, x, y, color, FONT_SIZE, base); } void GUIFontDrawIcon(const struct GUIFont* font, int x, int y, enum GUIAlignment align, enum GUIOrientation orient, uint32_t color, enum GUIIcon icon) {