From 055064d9f8060b147e65a26714cb37a4e2d85ac8 Mon Sep 17 00:00:00 2001 From: rexim Date: Sun, 22 Jul 2018 23:39:30 +0700 Subject: [PATCH] (#249) Make size factor of sprite_font_render_text float --- src/game/camera.c | 2 +- src/game/camera.h | 2 +- src/game/sprite_font.c | 17 ++++++++--------- src/game/sprite_font.h | 2 +- 4 files changed, 11 insertions(+), 12 deletions(-) diff --git a/src/game/camera.c b/src/game/camera.c index 45c63455..fc3cdcd6 100644 --- a/src/game/camera.c +++ b/src/game/camera.c @@ -174,7 +174,7 @@ int camera_fill_triangle(camera_t *camera, int camera_render_text(camera_t *camera, const char *text, - int size, + float size, color_t color, vec_t position) { diff --git a/src/game/camera.h b/src/game/camera.h index b3fe4749..68b764ce 100644 --- a/src/game/camera.h +++ b/src/game/camera.h @@ -34,7 +34,7 @@ int camera_fill_triangle(camera_t *camera, int camera_render_text(camera_t *camera, const char *text, - int size, + float size, color_t color, vec_t position); diff --git a/src/game/sprite_font.c b/src/game/sprite_font.c index ac0a7d29..08dc6fa2 100644 --- a/src/game/sprite_font.c +++ b/src/game/sprite_font.c @@ -3,6 +3,7 @@ #include #include +#include "math/rect.h" #include "sdl/renderer.h" #include "sprite_font.h" #include "system/error.h" @@ -91,7 +92,7 @@ static SDL_Rect sprite_font_char_rect(const sprite_font_t *sprite_font, char x) int sprite_font_render_text(const sprite_font_t *sprite_font, SDL_Renderer *renderer, vec_t position, - int size, + float size, color_t color, const char *text) { @@ -107,16 +108,14 @@ int sprite_font_render_text(const sprite_font_t *sprite_font, } const size_t text_size = strlen(text); - const int px = (int) roundf(position.x); - const int py = (int) roundf(position.y); for (size_t i = 0; i < text_size; ++i) { const SDL_Rect char_rect = sprite_font_char_rect(sprite_font, text[i]); - const SDL_Rect dest_rect = { - .x = px + CHAR_WIDTH * (int) i * size, - .y = py, - .w = char_rect.w * size, - .h = char_rect.h * size - }; + const SDL_Rect dest_rect = rect_for_sdl( + rect( + position.x + (float) CHAR_WIDTH * (float) i * size, + position.y, + (float) char_rect.w * size, + (float) char_rect.h * size)); if (SDL_RenderCopy(renderer, sprite_font->texture, &char_rect, &dest_rect) < 0) { return -1; } diff --git a/src/game/sprite_font.h b/src/game/sprite_font.h index 1c9ab947..d516a5f3 100644 --- a/src/game/sprite_font.h +++ b/src/game/sprite_font.h @@ -13,7 +13,7 @@ void destroy_sprite_font(sprite_font_t *sprite_font); int sprite_font_render_text(const sprite_font_t *sprite_font, SDL_Renderer *renderer, vec_t position, - int size, + float size, color_t color, const char *text); -- 2.44.0