]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/sprite_font.c
Add TODO(#521)
[nothing.git] / src / game / sprite_font.c
index c42a724b9d6dfed2767bdfdb88538e7fde65cdb9..82c53ce485b20c01f3bfff7390977e9baad3ee7f 100644 (file)
@@ -6,37 +6,37 @@
 #include "math/rect.h"
 #include "sdl/renderer.h"
 #include "sprite_font.h"
-#include "system/error.h"
 #include "system/lt.h"
+#include "system/nth_alloc.h"
+#include "system/log.h"
 
 #define FONT_ROW_SIZE 18
 
-struct sprite_font_t
+struct Sprite_font
 {
-    lt_t *lt;
+    Lt *lt;
     SDL_Texture *texture;
 };
 
-sprite_font_t *create_sprite_font_from_file(const char *bmp_file_path,
+Sprite_font *create_sprite_font_from_file(const char *bmp_file_path,
                                             SDL_Renderer *renderer)
 {
     assert(bmp_file_path);
     assert(renderer);
 
-    lt_t * const lt = create_lt();
+    Lt * const lt = create_lt();
     if (lt == NULL) {
         return NULL;
     }
 
-    sprite_font_t * const sprite_font = PUSH_LT(lt, malloc(sizeof(sprite_font_t)), free);
+    Sprite_font * const sprite_font = PUSH_LT(lt, nth_alloc(sizeof(Sprite_font)), free);
     if (sprite_font == NULL) {
-        throw_error(ERROR_TYPE_LIBC);
         RETURN_LT(lt, NULL);
     }
 
     SDL_Surface * const surface = PUSH_LT(lt, SDL_LoadBMP(bmp_file_path), SDL_FreeSurface);
     if (surface == NULL) {
-        throw_error(ERROR_TYPE_SDL2);
+        log_fail("Could not load %s: %s\n", bmp_file_path, SDL_GetError());
         RETURN_LT(lt, NULL);
     }
 
@@ -44,7 +44,7 @@ sprite_font_t *create_sprite_font_from_file(const char *bmp_file_path,
                         SDL_TRUE,
                         SDL_MapRGB(surface->format,
                                    0, 0, 0)) < 0) {
-        throw_error(ERROR_TYPE_SDL2);
+        log_fail("SDL_SetColorKey: %s\n", SDL_GetError());
         RETURN_LT(lt, NULL);
     }
 
@@ -53,7 +53,7 @@ sprite_font_t *create_sprite_font_from_file(const char *bmp_file_path,
         SDL_CreateTextureFromSurface(renderer, surface),
         SDL_DestroyTexture);
     if (sprite_font->texture == NULL) {
-        throw_error(ERROR_TYPE_SDL2);
+        log_fail("SDL_CreateTextureFromSurface: %s\n", SDL_GetError());
         RETURN_LT(lt, NULL);
     }
 
@@ -64,13 +64,13 @@ sprite_font_t *create_sprite_font_from_file(const char *bmp_file_path,
     return sprite_font;
 }
 
-void destroy_sprite_font(sprite_font_t *sprite_font)
+void destroy_sprite_font(Sprite_font *sprite_font)
 {
     assert(sprite_font);
     RETURN_LT0(sprite_font->lt);
 }
 
-static SDL_Rect sprite_font_char_rect(const sprite_font_t *sprite_font, char x)
+static SDL_Rect sprite_font_char_rect(const Sprite_font *sprite_font, char x)
 {
     assert(sprite_font);
 
@@ -87,11 +87,11 @@ 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,
+int sprite_font_render_text(const Sprite_font *sprite_font,
                             SDL_Renderer *renderer,
-                            vec_t position,
-                            vec_t size,
-                            color_t color,
+                            Vec position,
+                            Vec size,
+                            Color color,
                             const char *text)
 {
     assert(sprite_font);
@@ -101,12 +101,12 @@ int sprite_font_render_text(const sprite_font_t *sprite_font,
     const SDL_Color sdl_color = color_for_sdl(color);
 
     if (SDL_SetTextureColorMod(sprite_font->texture, sdl_color.r, sdl_color.g, sdl_color.b) < 0) {
-        throw_error(ERROR_TYPE_SDL2);
+        log_fail("SDL_SetTextureColorMod: %s\n", SDL_GetError());
         return -1;
     }
 
     if (SDL_SetTextureAlphaMod(sprite_font->texture, sdl_color.a) < 0) {
-        throw_error(ERROR_TYPE_SDL2);
+        log_fail("SDL_SetTextureAlphaMod: %s\n", SDL_GetError());
         return -1;
     }
 
@@ -127,9 +127,9 @@ int sprite_font_render_text(const sprite_font_t *sprite_font,
     return 0;
 }
 
-rect_t sprite_font_boundary_box(const sprite_font_t *sprite_font,
-                                vec_t position,
-                                vec_t size,
+Rect sprite_font_boundary_box(const Sprite_font *sprite_font,
+                                Vec position,
+                                Vec size,
                                 const char *text)
 {
     assert(sprite_font);