]> git.lizzy.rs Git - nothing.git/blobdiff - src/game/camera.c
(#265) sprite_font_boundary_box
[nothing.git] / src / game / camera.c
index bd0824c9df23a38a99f00b589a10a4512a716412..508f8dc040feb1f244573cc8b4730336c00b7947 100644 (file)
@@ -152,7 +152,6 @@ int camera_fill_triangle(camera_t *camera,
     const SDL_Color sdl_color = color_for_sdl(camera->blackwhite_mode ? color_desaturate(color) : color);
 
 
-
     if (camera->debug_mode) {
         if (SDL_SetRenderDrawColor(camera->renderer, sdl_color.r, sdl_color.g, sdl_color.b, sdl_color.a / 2) < 0) {
             throw_error(ERROR_TYPE_SDL2);
@@ -172,6 +171,31 @@ int camera_fill_triangle(camera_t *camera,
     return 0;
 }
 
+int camera_render_text(camera_t *camera,
+                       const char *text,
+                       vec_t size,
+                       color_t color,
+                       vec_t position)
+{
+    SDL_Rect view_port;
+    SDL_RenderGetViewport(camera->renderer, &view_port);
+
+    const vec_t scale = effective_scale(&view_port);
+    const vec_t screen_position = camera_point(camera, &view_port, position);
+
+    if (sprite_font_render_text(
+            camera->font,
+            camera->renderer,
+            screen_position,
+            vec(size.x * scale.x, size.y * scale.y),
+            camera->blackwhite_mode ? color_desaturate(color) : color,
+            text) < 0) {
+        return -1;
+    }
+
+    return 0;
+}
+
 int camera_clear_background(camera_t *camera,
                             color_t color)
 {
@@ -240,6 +264,20 @@ rect_t camera_view_port(const camera_t *camera)
                 w, h);
 }
 
+int camera_is_text_visible(const camera_t *camera,
+                           vec_t size,
+                           vec_t position,
+                           const char *text)
+{
+    assert(camera);
+    assert(text);
+    (void) size;
+    (void) position;
+
+    /* TODO: camera_is_text_visible not implemented */
+
+    return 0;
+}
 
 /* ---------- Private Function ---------- */
 
@@ -295,19 +333,3 @@ static rect_t camera_rect(const camera_t *camera,
             effective_scale(view_port),
             vec(rect.w, rect.h)));
 }
-
-int camera_render_text(camera_t *camera,
-                       const char *text,
-                       vec_t position)
-{
-    SDL_Rect view_port;
-    SDL_RenderGetViewport(camera->renderer, &view_port);
-
-    const vec_t screen_position = camera_point(camera, &view_port, position);
-
-    if (sprite_font_render_text(camera->font, camera->renderer, screen_position, 4, text) < 0) {
-        return -1;
-    }
-
-    return 0;
-}