1 #include "system/stacktrace.h"
3 #include "game/camera.h"
6 int slider_render(const Slider *slider, Camera *camera, Rect boundary)
11 const Color core_color = rgba(0.0f, 0.0f, 0.0f, 1.0f);
12 const float core_height = boundary.h * 0.33f;
13 const Rect core = rect(
15 boundary.y + boundary.h * 0.5f - core_height * 0.5f,
18 if (camera_fill_rect_screen(camera, core, core_color) < 0) {
22 const float ratio = slider->value / slider->max_value;
23 const float cursor_width = boundary.w * 0.1f;
24 const Rect cursor = rect(
25 boundary.x + ratio * (boundary.w - cursor_width),
29 const Color cursor_color = rgba(1.0f, 0.0f, 0.0f, 0.5f);
30 if (camera_fill_rect_screen(camera, cursor, cursor_color) < 0) {
37 int slider_event(Slider *slider, const SDL_Event *event, Rect boundary)
42 switch (event->type) {
43 case SDL_MOUSEBUTTONDOWN: {
44 Point position = vec((float) event->button.x, (float) event->button.y);
45 if (rect_contains_point(boundary, position)) {
50 case SDL_MOUSEBUTTONUP: {
54 case SDL_MOUSEMOTION: {
56 const float x = fminf(fmaxf((float) event->button.x - boundary.x, 0.0f), (float) boundary.w);
57 const float ratio = x / (float) boundary.w;
58 slider->value = ratio * slider->max_value;