-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathcatgl_ui_slider.h
41 lines (35 loc) · 1.06 KB
/
catgl_ui_slider.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
void caDrawSlider(NVGcontext* vg, float pos, float x, float y, float w, float h)
{
NVGpaint bg, knob;
float cy = y+(int)(h*0.5f);
float kr = (int)(h*0.25f);
nvgSave(vg);
// nvgClearState(vg);
// Slot
bg = nvgBoxGradient(vg, x,cy-2+1, w,4, 2,2, nvgRGBA(0,0,0,32), nvgRGBA(0,0,0,128));
nvgBeginPath(vg);
nvgRoundedRect(vg, x,cy-2, w,4, 2);
nvgFillPaint(vg, bg);
nvgFill(vg);
// Knob Shadow
bg = nvgRadialGradient(vg, x+(int)(pos*w),cy+1, kr-3,kr+3, nvgRGBA(0,0,0,64), nvgRGBA(0,0,0,0));
nvgBeginPath(vg);
nvgRect(vg, x+(int)(pos*w)-kr-5,cy-kr-5,kr*2+5+5,kr*2+5+5+3);
nvgCircle(vg, x+(int)(pos*w),cy, kr);
nvgPathWinding(vg, NVG_HOLE);
nvgFillPaint(vg, bg);
nvgFill(vg);
// Knob
knob = nvgLinearGradient(vg, x,cy-kr,x,cy+kr, nvgRGBA(255,255,255,16), nvgRGBA(0,0,0,16));
nvgBeginPath(vg);
nvgCircle(vg, x+(int)(pos*w),cy, kr-1);
nvgFillColor(vg, nvgRGBA(40,43,48,255));
nvgFill(vg);
nvgFillPaint(vg, knob);
nvgFill(vg);
nvgBeginPath(vg);
nvgCircle(vg, x+(int)(pos*w),cy, kr-0.5f);
nvgStrokeColor(vg, nvgRGBA(0,0,0,92));
nvgStroke(vg);
nvgRestore(vg);
}