2015-07-28 07:59:28 +00:00
|
|
|
/* Copyright (c) 2013-2015 Jeffrey Pfau
|
|
|
|
*
|
|
|
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
|
|
|
* 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"
|
2015-08-23 07:57:34 +00:00
|
|
|
#include "util/gui/font-metrics.h"
|
2015-07-28 07:59:28 +00:00
|
|
|
|
|
|
|
#include <vita2d.h>
|
|
|
|
|
|
|
|
#define CELL_HEIGHT 16
|
|
|
|
#define CELL_WIDTH 16
|
2015-08-23 07:57:34 +00:00
|
|
|
#define GLYPH_HEIGHT 12
|
2015-07-28 07:59:28 +00:00
|
|
|
|
2015-08-29 02:44:12 +00:00
|
|
|
extern const uint8_t _binary_font_png_start[];
|
|
|
|
|
2015-07-28 07:59:28 +00:00
|
|
|
struct GUIFont {
|
|
|
|
vita2d_texture* tex;
|
|
|
|
};
|
|
|
|
|
|
|
|
struct GUIFont* GUIFontCreate(void) {
|
2015-08-29 02:44:12 +00:00
|
|
|
struct GUIFont* font = malloc(sizeof(struct GUIFont));
|
|
|
|
if (!font) {
|
2015-07-28 07:59:28 +00:00
|
|
|
return 0;
|
|
|
|
}
|
2015-08-29 02:44:12 +00:00
|
|
|
font->tex = vita2d_load_PNG_buffer(_binary_font_png_start);
|
|
|
|
return font;
|
2015-07-28 07:59:28 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFontDestroy(struct GUIFont* font) {
|
|
|
|
vita2d_free_texture(font->tex);
|
|
|
|
free(font);
|
|
|
|
}
|
|
|
|
|
2015-08-27 03:11:51 +00:00
|
|
|
unsigned GUIFontHeight(const struct GUIFont* font) {
|
2015-07-28 07:59:28 +00:00
|
|
|
UNUSED(font);
|
|
|
|
return GLYPH_HEIGHT;
|
|
|
|
}
|
|
|
|
|
2015-08-27 04:41:49 +00:00
|
|
|
unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
|
|
|
|
UNUSED(font);
|
|
|
|
if (glyph > 0x7F) {
|
|
|
|
glyph = 0;
|
|
|
|
}
|
|
|
|
return defaultFontMetrics[glyph].width;
|
|
|
|
}
|
|
|
|
|
|
|
|
void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
|
|
|
|
if (glyph > 0x7F) {
|
|
|
|
glyph = 0;
|
2015-07-28 07:59:28 +00:00
|
|
|
}
|
2015-08-27 04:41:49 +00:00
|
|
|
struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph];
|
|
|
|
vita2d_draw_texture_tint_part(font->tex, x, y - GLYPH_HEIGHT + metric.padding.top,
|
|
|
|
(glyph & 15) * CELL_WIDTH + metric.padding.left,
|
|
|
|
(glyph >> 4) * CELL_HEIGHT + metric.padding.top,
|
|
|
|
CELL_WIDTH - (metric.padding.left + metric.padding.right),
|
|
|
|
CELL_HEIGHT - (metric.padding.top + metric.padding.bottom),
|
|
|
|
color);
|
2015-07-28 07:59:28 +00:00
|
|
|
}
|