Added min and max functions for floats and modified the text rendering code
This commit is contained in:
1 parent
d429262aaa
commit
ad88083f53
4 files changed
+13
-21
No files matched your search
+4
-19
@@ -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;
|
||||
|
||||
@@ -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; }
|
||||
Reference in new issue
Block a user