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
+10
-3
@@ -2,6 +2,7 @@
|
|||||||
#define GAME_H
|
#define GAME_H
|
||||||
|
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
|
#include "BitmapFont.h"
|
||||||
#include "ObjectStore.h"
|
#include "ObjectStore.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "SDL_pixels.h"
|
#include "SDL_pixels.h"
|
||||||
@@ -42,6 +43,9 @@ void remove_object(ObjectID *id);
|
|||||||
// ASSET MANAGEMENT API
|
// ASSET MANAGEMENT API
|
||||||
AssetID load_asset(const char *path, AssetType type);
|
AssetID load_asset(const char *path, AssetType type);
|
||||||
void unload_asset(AssetID *id);
|
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
|
// END ASSET MANAGEMENT API
|
||||||
|
|
||||||
// RENDERING 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_color(AssetID id, SDL_Color color);
|
||||||
void modulate_texture_alpha(AssetID id, u8 alpha);
|
void modulate_texture_alpha(AssetID id, u8 alpha);
|
||||||
TextSize get_text_size_from_font_asset(AssetID id, const char *text);
|
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);
|
void set_font_asset_size(AssetID id, u32 size);
|
||||||
i32 set_font_direction(AssetID id, FontDirection direction);
|
i32 set_font_direction(AssetID id, FontDirection direction);
|
||||||
i32 set_font_script_name(AssetID id, const char *script);
|
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
|
// END RENDERING API
|
||||||
|
|
||||||
// AUDIO API
|
// AUDIO API
|
||||||
|
|||||||
+42
-23
@@ -1,5 +1,6 @@
|
|||||||
#include "GameEngine.h"
|
#include "GameEngine.h"
|
||||||
#include "AssetManager.h"
|
#include "AssetManager.h"
|
||||||
|
#include "BitmapFont.h"
|
||||||
#include "ObjectStore.h"
|
#include "ObjectStore.h"
|
||||||
#include "Renderer.h"
|
#include "Renderer.h"
|
||||||
#include "SDL.h"
|
#include "SDL.h"
|
||||||
@@ -215,6 +216,17 @@ void unload_asset(AssetID *id) {
|
|||||||
remove_asset_from_manager(GameEngine.asset_manager, 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_defined_size() { return GameEngine.window.defined_size; }
|
||||||
|
|
||||||
WindowSize get_window_real_size() { return GameEngine.window.real_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;
|
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) {
|
void set_font_asset_size(AssetID id, u32 size) {
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
return;
|
return;
|
||||||
@@ -438,6 +427,36 @@ i32 set_font_script_name(AssetID id, const char *script) {
|
|||||||
return TTF_SetFontScriptName(font, 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,
|
i8 play_audio_asset(AssetID id, i16 loops, bool fade_in,
|
||||||
u32 fade_length_in_ms) {
|
u32 fade_length_in_ms) {
|
||||||
if (id < 0) {
|
if (id < 0) {
|
||||||
|
|||||||
Reference in new issue
Block a user