all repos — mgba @ fee9fc688f6ddb9b7abac63044c3799279d61db4

mGBA Game Boy Advance Emulator

src/platform/psp2/gui-font.c (view raw)

 1/* Copyright (c) 2013-2015 Jeffrey Pfau
 2 *
 3 * This Source Code Form is subject to the terms of the Mozilla Public
 4 * License, v. 2.0. If a copy of the MPL was not distributed with this
 5 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 6#include "util/gui/font.h"
 7#include "util/gui/font-metrics.h"
 8#include "font.h"
 9
10#include <vita2d.h>
11
12#define CELL_HEIGHT 16
13#define CELL_WIDTH 16
14#define GLYPH_HEIGHT 12
15
16struct GUIFont {
17	vita2d_texture* tex;
18};
19
20struct GUIFont* GUIFontCreate(void) {
21	struct GUIFont* guiFont = malloc(sizeof(struct GUIFont));
22	if (!guiFont) {
23		return 0;
24	}
25	guiFont->tex = vita2d_load_PNG_buffer(font);
26	return guiFont;
27}
28
29void GUIFontDestroy(struct GUIFont* font) {
30	vita2d_free_texture(font->tex);
31	free(font);
32}
33
34unsigned GUIFontHeight(const struct GUIFont* font) {
35	UNUSED(font);
36	return GLYPH_HEIGHT;
37}
38
39unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
40	UNUSED(font);
41	if (glyph > 0x7F) {
42		glyph = 0;
43	}
44	return defaultFontMetrics[glyph].width;
45}
46
47void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
48	if (glyph > 0x7F) {
49		glyph = 0;
50	}
51	struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph];
52	vita2d_draw_texture_tint_part(font->tex, x, y - GLYPH_HEIGHT + metric.padding.top,
53		                          (glyph & 15) * CELL_WIDTH + metric.padding.left,
54		                          (glyph >> 4) * CELL_HEIGHT + metric.padding.top,
55		                          CELL_WIDTH - (metric.padding.left + metric.padding.right),
56		                          CELL_HEIGHT - (metric.padding.top + metric.padding.bottom),
57		                          color);
58}