-
Notifications
You must be signed in to change notification settings - Fork 4
/
catgl_ui_button.h
50 lines (45 loc) · 1.56 KB
/
catgl_ui_button.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
42
43
44
45
46
47
48
49
50
void caDrawButton(NVGcontext* vg, int preicon, const char* text, float x, float y, float w, float h, NVGcolor col, int f)
{
NVGpaint bg;
char icon[8];
float cornerRadius = 4.0f;
float tw = 0, iw = 0;
if (!f) {
bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(255,255,255,isBlack(col)?16:32), nvgRGBA(0,0,0,isBlack(col)?16:32));
} else {
bg = nvgLinearGradient(vg, x,y,x,y+h, nvgRGBA(0,0,0,isBlack(col)?16:32), nvgRGBA(255,255,255,isBlack(col)?16:32));
}
nvgBeginPath(vg);
nvgRoundedRect(vg, x+1,y+1, w-2,h-2, cornerRadius-1);
if (!isBlack(col)) {
nvgFillColor(vg, col);
nvgFill(vg);
}
nvgFillPaint(vg, bg);
nvgFill(vg);
nvgBeginPath(vg);
nvgRoundedRect(vg, x+0.5f,y+0.5f, w-1,h-1, cornerRadius-0.5f);
nvgStrokeColor(vg, nvgRGBA(0,0,0,48));
nvgStroke(vg);
nvgFontSize(vg, 20.0f);
nvgFontFace(vg, "sans-bold");
tw = nvgTextBounds(vg, 0,0, text, NULL, NULL);
if (preicon != 0) {
nvgFontSize(vg, h*1.3f);
nvgFontFace(vg, "icons");
iw = nvgTextBounds(vg, 0,0, cpToUTF8(preicon,icon), NULL, NULL);
iw += h*0.15f;
nvgFontSize(vg, h*1.3f);
nvgFontFace(vg, "icons");
nvgFillColor(vg, nvgRGBA(255,255,255,96));
nvgTextAlign(vg,NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
nvgText(vg, x+w*0.5f-tw*0.5f-iw*0.75f, y+h*0.5f, cpToUTF8(preicon,icon), NULL);
}
nvgFontSize(vg, 20.0f);
nvgFontFace(vg, "sans-bold");
nvgTextAlign(vg, NVG_ALIGN_LEFT|NVG_ALIGN_MIDDLE);
nvgFillColor(vg, nvgRGBA(0,0,0,160));
nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f-1,text, NULL);
nvgFillColor(vg, nvgRGBA(255,255,255,160));
nvgText(vg, x+w*0.5f-tw*0.5f+iw*0.25f,y+h*0.5f,text, NULL);
}