all repos — mgba @ 4d24b16735001b96dcee2bebc49560185f969b03

mGBA Game Boy Advance Emulator

src/platform/3ds/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 "util/png-io.h"
 9#include "util/vfs.h"
10#include "font.h"
11
12#include <sf2d.h>
13
14#define CELL_HEIGHT 16
15#define CELL_WIDTH 16
16#define GLYPH_HEIGHT 12
17
18struct GUIFont {
19	sf2d_texture* tex;
20};
21
22struct GUIFont* GUIFontCreate(void) {
23	struct GUIFont* guiFont = malloc(sizeof(struct GUIFont));
24	if (!guiFont) {
25		return 0;
26	}
27	guiFont->tex = sf2d_create_texture(256, 128, TEXFMT_RGB5A1, SF2D_PLACE_RAM);
28	memcpy(guiFont->tex->data, font, font_size);
29	guiFont->tex->tiled = 1;
30	return guiFont;
31}
32
33void GUIFontDestroy(struct GUIFont* font) {
34	sf2d_free_texture(font->tex);
35	free(font);
36}
37
38unsigned GUIFontHeight(const struct GUIFont* font) {
39	UNUSED(font);
40	return GLYPH_HEIGHT;
41}
42
43unsigned GUIFontGlyphWidth(const struct GUIFont* font, uint32_t glyph) {
44	UNUSED(font);
45	if (glyph > 0x7F) {
46		glyph = 0;
47	}
48	return defaultFontMetrics[glyph].width;
49}
50
51void GUIFontDrawGlyph(const struct GUIFont* font, int x, int y, uint32_t color, uint32_t glyph) {
52	if (glyph > 0x7F) {
53		glyph = 0;
54	}
55	color = (color >> 24) | (color << 8);
56	struct GUIFontGlyphMetric metric = defaultFontMetrics[glyph];
57	sf2d_draw_texture_part_blend(font->tex,
58	                             x - metric.padding.left,
59	                             y - GLYPH_HEIGHT,
60	                             (glyph & 15) * CELL_WIDTH,
61	                             (glyph >> 4) * CELL_HEIGHT,
62	                             CELL_WIDTH,
63	                             CELL_HEIGHT,
64	                             color);
65}