diff --git a/include/GameEngine.h b/include/GameEngine.h index a2b1e1c..8b01bc8 100644 --- a/include/GameEngine.h +++ b/include/GameEngine.h @@ -2,6 +2,7 @@ #define GAME_H #include "AssetManager.h" +#include "BitmapFont.h" #include "ObjectStore.h" #include "Renderer.h" #include "SDL_pixels.h" @@ -42,6 +43,9 @@ void remove_object(ObjectID *id); // ASSET MANAGEMENT API AssetID load_asset(const char *path, AssetType type); void unload_asset(AssetID *id); +BitmapFont *load_bitmap_font(const char *filepath, u64 tile_width, + u64 tile_height); +void unload_bitmap_font(BitmapFont **font); // END ASSET MANAGEMENT API // RENDERING API @@ -80,12 +84,15 @@ void render_texture_asset(AssetID id, const RenderRect *src, void modulate_texture_color(AssetID id, SDL_Color color); void modulate_texture_alpha(AssetID id, u8 alpha); TextSize get_text_size_from_font_asset(AssetID id, const char *text); -void render_text_with_font_asset(AssetID id, const char *text, - const RenderRect *src, RenderRect dest, - SDL_Color color); void set_font_asset_size(AssetID id, u32 size); i32 set_font_direction(AssetID id, FontDirection direction); i32 set_font_script_name(AssetID id, const char *script); +void render_text_with_font_asset(AssetID id, const char *text, + const RenderRect *src, RenderRect dest, + SDL_Color color); +void render_text_with_bitmap_font(BitmapFont *font, const char *text, + u64 font_size, u64 start_index, + RenderRect dest, SDL_Color color); // END RENDERING API // AUDIO API diff --git a/src/GameEngine.c b/src/GameEngine.c index 9739271..60f8554 100644 --- a/src/GameEngine.c +++ b/src/GameEngine.c @@ -1,5 +1,6 @@ #include "GameEngine.h" #include "AssetManager.h" +#include "BitmapFont.h" #include "ObjectStore.h" #include "Renderer.h" #include "SDL.h" @@ -215,6 +216,17 @@ void unload_asset(AssetID *id) { remove_asset_from_manager(GameEngine.asset_manager, id); } +BitmapFont *load_bitmap_font(const char *filepath, u64 tile_width, + u64 tile_height) { + return create_bitmap_font(GameEngine.asset_manager, + GameEngine.window.renderer, filepath, tile_width, + tile_height); +} + +void unload_bitmap_font(BitmapFont **font) { + destroy_bitmap_font(GameEngine.asset_manager, font); +} + WindowSize get_window_defined_size() { return GameEngine.window.defined_size; } WindowSize get_window_real_size() { return GameEngine.window.real_size; } @@ -376,29 +388,6 @@ TextSize get_text_size_from_font_asset(AssetID id, const char *text) { return output; } -void render_text_with_font_asset(AssetID id, const char *text, - const RenderRect *src, RenderRect dest, - SDL_Color color) { - if (id < 0) { - return; - } - - TTF_Font *font = get_font(GameEngine.asset_manager, id); - if (!font) { - return; - } - - SDL_Surface *surface = TTF_RenderUTF8_Solid(font, text, color); - if (!surface) { - return; - } - - render_surface(GameEngine.window.renderer, surface, src, &dest); - - SDL_FreeSurface(surface); - surface = NULL; -} - void set_font_asset_size(AssetID id, u32 size) { if (id < 0) { return; @@ -438,6 +427,36 @@ i32 set_font_script_name(AssetID id, const char *script) { return TTF_SetFontScriptName(font, script); } +void render_text_with_font_asset(AssetID id, const char *text, + const RenderRect *src, RenderRect dest, + SDL_Color color) { + if (id < 0) { + return; + } + + TTF_Font *font = get_font(GameEngine.asset_manager, id); + if (!font) { + return; + } + + SDL_Surface *surface = TTF_RenderUTF8_Solid(font, text, color); + if (!surface) { + return; + } + + render_surface(GameEngine.window.renderer, surface, src, &dest); + + SDL_FreeSurface(surface); + surface = NULL; +} + +void render_text_with_bitmap_font(BitmapFont *font, const char *text, + u64 font_size, u64 start_index, + RenderRect dest, SDL_Color color) { + render_bitmap_font_text(GameEngine.asset_manager, GameEngine.window.renderer, + font, font_size, text, start_index, dest, color); +} + i8 play_audio_asset(AssetID id, i16 loops, bool fade_in, u32 fade_length_in_ms) { if (id < 0) {