aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/sdl/font.c31
-rw-r--r--src/sdl/font.h9
-rw-r--r--src/sdl/main.c29
3 files changed, 42 insertions, 27 deletions
diff --git a/src/sdl/font.c b/src/sdl/font.c
new file mode 100644
index 0000000..76cb160
--- /dev/null
+++ b/src/sdl/font.c
@@ -0,0 +1,31 @@
+#include <SDL.h>
+#include <SDL_ttf.h>
+#include "font.h"
+#include "util.h"
+
+TTF_Font *
+font_load(
+ const asset_id_t font_asset_id,
+ const int font_size
+) {
+ // get asset
+ const asset_t * const asset = asset_get(font_asset_id);
+ if (!asset) {
+ die("asset_get()");
+ }
+
+ // create io
+ SDL_RWops *rw = SDL_RWFromConstMem(asset->buf, asset->len);
+ if (!rw) {
+ die("SDL_RWFromConstMem(): %s", SDL_GetError());
+ }
+
+ // load font
+ TTF_Font *font = TTF_OpenFontIndexRW(rw, 1, font_size, 0);
+ if (!font) {
+ die("TTF_OpenFontIndex(): %s", TTF_GetError());
+ }
+
+ // return font
+ return font;
+}
diff --git a/src/sdl/font.h b/src/sdl/font.h
new file mode 100644
index 0000000..edc1a14
--- /dev/null
+++ b/src/sdl/font.h
@@ -0,0 +1,9 @@
+#ifndef FONT_H
+#define FONT_H
+
+#include <SDL_ttf.h>
+#include "assets.h"
+
+TTF_Font *font_load(const asset_id_t, const int);
+
+#endif /* FONT_H */
diff --git a/src/sdl/main.c b/src/sdl/main.c
index 852a5ae..7560d3f 100644
--- a/src/sdl/main.c
+++ b/src/sdl/main.c
@@ -15,37 +15,12 @@
#include "assets.h"
#include "solve.h"
#include "sounds.h"
+#include "font.h"
#define WINDOW_TITLE "Pablotron Sokoban"
#define WINDOW_WIDTH 800
#define WINDOW_HEIGHT 600
-static TTF_Font *
-load_font(
- const asset_id_t id
-) {
- // get asset
- const asset_t * const asset = asset_get(id);
- if (!asset) {
- die("asset_get()");
- }
-
- // create io
- SDL_RWops *rw = SDL_RWFromConstMem(asset->buf, asset->len);
- if (!rw) {
- die("SDL_RWFromConstMem(): %s", SDL_GetError());
- }
-
- // load font
- TTF_Font *font = TTF_OpenFontIndexRW(rw, 1, 16, 0);
- if (!font) {
- die("TTF_OpenFontIndex(): %s", TTF_GetError());
- }
-
- // return font
- return font;
-}
-
static void
on_resize(
draw_ctx_t * const draw_ctx
@@ -288,7 +263,7 @@ int main(int argc, char *argv[]) {
// init sprites, set window icon, load font
sprites_init(renderer, draw_ctx.sprites);
sprites_set_window_icon(win, SPRITE_HOME);
- draw_ctx.font = load_font(ASSET_ROBOTO_TTF);
+ draw_ctx.font = font_load(ASSET_ROBOTO_TTF, 16);
// register solve event
const Uint32 solve_event_type = SDL_RegisterEvents(1);