diff options
author | Paul Duncan <pabs@pablotron.org> | 2019-01-21 22:59:20 -0500 |
---|---|---|
committer | Paul Duncan <pabs@pablotron.org> | 2019-01-21 22:59:20 -0500 |
commit | 57d7bdc68b774c1e55ebc281786b93c7336eb4e4 (patch) | |
tree | d112af1f16958425b109b884728aa3f70880d8e2 /src | |
parent | 119e48bfa0f20686bc7cb0fd43323a7648aa598a (diff) | |
download | sok-57d7bdc68b774c1e55ebc281786b93c7336eb4e4.tar.bz2 sok-57d7bdc68b774c1e55ebc281786b93c7336eb4e4.zip |
add src/sdl/font.[hc]
Diffstat (limited to 'src')
-rw-r--r-- | src/sdl/font.c | 31 | ||||
-rw-r--r-- | src/sdl/font.h | 9 | ||||
-rw-r--r-- | src/sdl/main.c | 29 |
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); |