]> git.lizzy.rs Git - nothing.git/blob - src/ui/wiggly_text.c
(#903) Make color of wiggly_text customizable
[nothing.git] / src / ui / wiggly_text.c
1 #include <SDL.h>
2
3 #include "math/point.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 int wiggly_text_render(const WigglyText *wiggly_text,
13                       Camera *camera)
14 {
15     trace_assert(wiggly_text);
16     trace_assert(camera);
17
18     const size_t n = strlen(wiggly_text->text);
19     char buf[2] = {0, 0};
20
21     for (size_t i = 0; i < n; ++i) {
22         buf[0] = wiggly_text->text[i];
23
24         if (camera_render_text_screen(
25                 camera,
26                 buf,
27                 wiggly_text->scale,
28                 wiggly_text->color,
29                 vec_sum(
30                     wiggly_text->position,
31                     vec(
32                         (float) (i * FONT_CHAR_WIDTH) * wiggly_text->scale.x,
33                         sinf(wiggly_text->angle + (float) i / (float) n * 10.0f) * 20.0f))) < 0) {
34             return -1;
35         }
36     }
37
38     return 0;
39 }
40
41 int wiggly_text_update(WigglyText *wiggly_text, float delta_time)
42 {
43     trace_assert(wiggly_text);
44     wiggly_text->angle = fmodf(wiggly_text->angle + 10.0f * delta_time, 2 * PI);
45     return 0;
46 }
47
48 Vec wiggly_text_size(const WigglyText *wiggly_text, const Camera *camera)
49 {
50     trace_assert(wiggly_text);
51
52     const Rect boundary = camera_text_boundary_box(
53         camera,
54         vec(0.0f, 0.0f),
55         wiggly_text->scale,
56         wiggly_text->text);
57
58     return vec(boundary.w, boundary.h);
59 }
60
61 int fading_wiggly_text_render(const FadingWigglyText *fading_wiggle_text,
62                               Camera *camera)
63 {
64     trace_assert(fading_wiggle_text);
65     trace_assert(camera);
66     return 0;
67 }
68
69 int fading_wiggly_text_update(FadingWigglyText *fading_wiggle_text,
70                               float delta_time)
71 {
72     trace_assert(fading_wiggle_text);
73     (void) delta_time;
74     return 0;
75 }