#if defined(STFU_MAIN) && !defined(STFU_SLIDER) #define STFU_SLIDER #include #include "../config.h" #include "border.c" #define STFU_SLIDER_WIDTH 16 struct stfu_slider { float x, y; float width, height; float r, g, b; float min, max, cur; bool integeric; }; static void stfu_draw_slider(struct stfu_slider slider) { /* Border */ stfu_draw_border((struct stfu_border){ .x = slider.x, .y = slider.y, .width = slider.width, .height = slider.height, .r = slider.r, .g = slider.g, .b = slider.b, }); /* Slider */ { float progress = (slider.cur - slider.min) / (slider.max - slider.min); float x = slider.x + (slider.width - STFU_SLIDER_WIDTH) * progress; sgl_begin_quads(); sgl_c3f(slider.r, slider.g, slider.b); sgl_v2f(x, slider.y); sgl_v2f(x + STFU_SLIDER_WIDTH, slider.y); sgl_v2f(x + STFU_SLIDER_WIDTH, slider.y + slider.height); sgl_v2f(x, slider.y + slider.height); sgl_end(); } } static struct stfu_slider stfu_press_slider(struct stfu_slider slider, float x, float y) { if (x < slider.x || x > slider.x + slider.width) return slider; if (y < slider.y || y > slider.y + slider.height) return slider; slider.cur = slider.min + ((x - slider.x) / (slider.width)) * (slider.max - slider.min); if (slider.integeric) slider.cur = floorf(slider.cur); return slider; } #endif