diff --git a/include/GameEngine.h b/include/GameEngine.h index f2fbfcf..8389cb2 100644 --- a/include/GameEngine.h +++ b/include/GameEngine.h @@ -78,8 +78,9 @@ void render_texture_asset(AssetID id, RenderRect *src, RenderRect *dest); 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, RenderRect dest, - SDL_Color color, const RenderRect *clip); +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); diff --git a/include/math_utils.h b/include/math_utils.h index dc02e8b..fa0cd9d 100644 --- a/include/math_utils.h +++ b/include/math_utils.h @@ -9,6 +9,8 @@ extern "C" { i32 max_int(i32 a, i32 b); i32 min_int(i32 a, i32 b); +f32 max_float(f32 a, f32 b); +f32 min_float(f32 a, f32 b); #ifdef __cplusplus } diff --git a/src/GameEngine.c b/src/GameEngine.c index 1529ec5..b7380c8 100644 --- a/src/GameEngine.c +++ b/src/GameEngine.c @@ -372,8 +372,9 @@ 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, RenderRect dest, - SDL_Color color, const RenderRect *clip) { +void render_text_with_font_asset(AssetID id, const char *text, + const RenderRect *src, RenderRect dest, + SDL_Color color) { if (id < 0) { return; } @@ -388,23 +389,7 @@ void render_text_with_font_asset(AssetID id, const char *text, RenderRect dest, return; } - RenderRect src = {}; - - bool clip_text = clip && (dest.width > clip->width); - - if (clip_text) { - f32 width_difference = dest.width - clip->width; - - // Offset the src rect so the text input displays where the text cursor is - src.x += width_difference; - src.width = clip->width; - src.height = clip->height; - - dest.width = clip->width; - } - - render_surface(GameEngine.window.renderer, surface, clip_text ? &src : NULL, - &dest); + render_surface(GameEngine.window.renderer, surface, src, &dest); SDL_FreeSurface(surface); surface = NULL; diff --git a/src/math_utils.c b/src/math_utils.c index d32c321..dd99fa8 100644 --- a/src/math_utils.c +++ b/src/math_utils.c @@ -4,3 +4,7 @@ i32 max_int(i32 a, i32 b) { return a >= b ? a : b; } i32 min_int(i32 a, i32 b) { return a <= b ? a : b; } + +f32 max_float(f32 a, f32 b) { return a >= b ? a : b; } + +f32 min_float(f32 a, f32 b) { return a <= b ? a : b; }