39 lines
893 B
C
39 lines
893 B
C
#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;
|
|
};
|
|
|
|
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();
|
|
}
|
|
}
|