forked from notsecure/uTox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathbutton.c
92 lines (75 loc) · 1.76 KB
/
button.c
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#include "main.h"
void button_draw(BUTTON *b, int x, int y, int width, int height)
{
if(b->nodraw) {
return;
}
if(b->updatecolor) {
b->updatecolor(b);
}
uint32_t color = b->mousedown ? b->c3 : (b->mouseover ? b->c2 : b->c1);
if(b->bm) {
drawalpha(b->bm, x, y, width, height, color);
} else {
drawrectw(x, y, width, height, b->disabled ? LIST_MAIN : color);
//setfont(FONT_TEXT_LARGE);
//setcolor(b->mouseover ? 0x222222 : 0x555555);
//drawtext(x + 5, y, b->text, b->text_length);
}
if(b->bm2) {
int bx = width / 2 - b->bw * SCALE / 2, by = height / 2 - b->bh * SCALE / 2;
drawalpha(b->bm2, x + bx, y + by, b->bw * SCALE, b->bh * SCALE, WHITE);
}
if(b->str) {
setfont(FONT_SELF_NAME);
setcolor(WHITE);
drawtext(x + 3 * SCALE, y + SCALE, (uint8_t*)b->str, strlen(b->str));
}
}
_Bool button_mmove(BUTTON *b, int x, int y, int width, int height, int mx, int my, int dy)
{
_Bool mouseover = inrect(mx, my, 0, 0, width, height);
if(mouseover) {
hand = 1;
}
if(mouseover != b->mouseover) {
b->mouseover = mouseover;
return 1;
}
return 0;
}
_Bool button_mdown(BUTTON *b)
{
if(!b->mousedown && b->mouseover) {
b->mousedown = 1;
return 1;
}
return 0;
}
_Bool button_mright(BUTTON *b)
{
return 0;
}
_Bool button_mwheel(BUTTON *b, int height, double d)
{
return 0;
}
_Bool button_mup(BUTTON *b)
{
if(b->mousedown) {
if(b->mouseover) {
b->onpress();
}
b->mousedown = 0;
return 1;
}
return 0;
}
_Bool button_mleave(BUTTON *b)
{
if(b->mouseover) {
b->mouseover = 0;
return 1;
}
return 0;
}