]> git.lizzy.rs Git - nothing.git/blob - src/ui/wiggly_text.c
(#358) implement console shortcuts for copy, cut, paste, clear
[nothing.git] / src / ui / wiggly_text.c
1 #include <SDL.h>
2
3 #include "math/vec.h"
4
5 #include "./wiggly_text.h"
6 #include "system/lt.h"
7 #include "system/stacktrace.h"
8 #include "system/nth_alloc.h"
9 #include "system/str.h"
10 #include "game/camera.h"
11
12 void wiggly_text_render(const WigglyText *wiggly_text,
13                         const Camera *camera,
14                         Vec2f position)
15 {
16     trace_assert(wiggly_text);
17     trace_assert(camera);
18
19     const size_t n = strlen(wiggly_text->text);
20     char buf[2] = {0, 0};
21
22     for (size_t i = 0; i < n; ++i) {
23         buf[0] = wiggly_text->text[i];
24
25         camera_render_text_screen(
26             camera,
27             buf,
28             wiggly_text->scale,
29             wiggly_text->color,
30             vec_sum(
31                 position,
32                 vec(
33                     (float) (i * FONT_CHAR_WIDTH) * wiggly_text->scale.x,
34                     sinf(wiggly_text->angle + (float) i / (float) n * 10.0f) * 20.0f)));
35     }
36 }
37
38 int wiggly_text_update(WigglyText *wiggly_text, float delta_time)
39 {
40     trace_assert(wiggly_text);
41     wiggly_text->angle = fmodf(wiggly_text->angle + 10.0f * delta_time, 2 * PI);
42     return 0;
43 }
44
45 Vec2f wiggly_text_size(const WigglyText *wiggly_text)
46 {
47     trace_assert(wiggly_text);
48
49     const Rect boundary = sprite_font_boundary_box(
50         vec(0.0f, 0.0f),
51         wiggly_text->scale,
52         strlen(wiggly_text->text));
53
54     return vec(boundary.w, boundary.h);
55 }