Expose bitmap font rendering in the GameEngine API
This commit is contained in:
1 parent
fe427689cf
commit
0e18dd0705
2 files changed
+52
-26
No files matched your search
+42
-23
@@ -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) {
|
||||
|
||||
Reference in new issue
Block a user