]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/sprite_font.h
Remove Grid and ActionPicker
[nothing.git] / src / game / sprite_font.h
index 138a34ba5bb2d019509cf06440dec9625fe7c5b8..cd2db10ac9cfdaf84c8b19f2e268eaaab5793049 100644 (file)
@@ -15,20 +15,31 @@ typedef struct {
 SDL_Texture *load_bmp_font_texture(SDL_Renderer *renderer,
                                    const char *bmp_file_path);
 
-int sprite_font_render_text(const Sprite_font *sprite_font,
-                            SDL_Renderer *renderer,
-                            Vec2f position,
-                            Vec2f size,
-                            Color color,
-                            const char *text);
+void sprite_font_render_text(const Sprite_font *sprite_font,
+                             SDL_Renderer *renderer,
+                             Vec2f position,
+                             Vec2f size,
+                             Color color,
+                             const char *text);
 
 static inline
-Rect sprite_font_boundary_box(Vec2f position, Vec2f size, size_t text_size)
+Rect sprite_font_boundary_box(Vec2f position, Vec2f size, const char *text)
 {
+    size_t num_max_col = 1, num_row = 1;
+    for (size_t i = 0, num_col = 1; text[i] != '\0'; i++){
+        if (text[i] == '\n'){
+            num_col = 1;
+            num_row++;
+            continue;
+        }
+        if (num_col > num_max_col)
+            num_max_col = num_col;
+        num_col++;
+    }
     return rect(
         position.x, position.y,
-        size.x * FONT_CHAR_WIDTH * (float) text_size,
-        size.y * FONT_CHAR_HEIGHT);
+        size.x * FONT_CHAR_WIDTH * (float) num_max_col,
+        size.y * FONT_CHAR_HEIGHT * (float) num_row);
 }
 
 #endif  // SPRITE_FONT_H_