forked from notsecure/uTox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sysmenu.c
155 lines (131 loc) · 2.91 KB
/
sysmenu.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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
enum
{
SYSMENU_NONE,
SYSMENU_EXIT,
SYSMENU_SIZE,
SYSMENU_MINI,
};
static _Bool sysmenu_down;
static uint8_t sysmenu_active, sysmenu_over;
static void sysmenu_button(RECT *r, HBITMAP bm, uint32_t c1, uint32_t c2, uint32_t c3, uint32_t c4, uint8_t menu)
{
if(sysmenu_active == menu)
{
if(sysmenu_down)
{
fillrect(r, c2);
SetTextColor(hdc, c2);
SetBkColor(hdc, c4);
}
else
{
fillrect(r, c1);
SetTextColor(hdc, c1);
SetBkColor(hdc, c3);
}
}
else
{
fillrect(r, WHITE);
SetBkColor(hdc, 0xCCCCCC);
SetTextColor(hdc, WHITE);
}
SelectObject(hdcMem, bm);
BitBlt(hdc, r->left + 7, r->top + 8, 16, 10, hdcMem, 0, 0, SRCCOPY);
}
static uint8_t sysmenu_hit(int x, int y)
{
y = y - 1;
x = (width - BORDER) - x - 1;
if(y >= 26 || y < 0 || x < 0)
{
return 0;
}
x /= 30;
if(x >= SYSMENU_MINI)
{
return 0;
}
return x + 1;
}
void sysmenu_draw(void)
{
RECT r = {width - BORDER - 30, BORDER, width - BORDER, BORDER + 26};
sysmenu_button(&r, bm_exit, RED, RED2, WHITE, WHITE, SYSMENU_EXIT);
r.left -= 30; r.right -= 30;
sysmenu_button(&r, maximized ? bm_restore : bm_maximize, GRAY, BLUE, 0x333333, WHITE, SYSMENU_SIZE);
r.left -= 30; r.right -= 30;
sysmenu_button(&r, bm_minimize, GRAY, BLUE, 0x333333, WHITE, SYSMENU_MINI);
commitdraw(width - BORDER - 90, BORDER, width - BORDER, BORDER + 26);
}
void sysmenu_mousemove(int x, int y)
{
uint8_t sm = sysmenu_hit(x, y);
if(!(GetKeyState(VK_LBUTTON) & 0x80))
{
if(sm != sysmenu_active)
{
sysmenu_active = sm;
sysmenu_draw();
}
}
else
{
_Bool md = (sm == sysmenu_active);
if(md != sysmenu_down)
{
sysmenu_down = md;
sysmenu_draw();
}
}
sysmenu_over = sm;
}
void sysmenu_mousedown(void)
{
if(sysmenu_active)
{
if(!sysmenu_down)
{
sysmenu_down = 1;
sysmenu_draw();
}
}
}
void sysmenu_mouseup(void)
{
if(sysmenu_active == sysmenu_over)
{
switch(sysmenu_active)
{
case SYSMENU_EXIT:
{
PostQuitMessage(0);
break;
}
case SYSMENU_SIZE:
{
ShowWindow(hwnd, maximized ? SW_RESTORE : SW_MAXIMIZE);
break;
}
case SYSMENU_MINI:
{
ShowWindow(hwnd, SW_MINIMIZE);
break;
}
}
}
if(sysmenu_active || sysmenu_over)
{
sysmenu_active = sysmenu_over;
sysmenu_draw();
}
sysmenu_down = 0;
}
void sysmenu_mouseleave(void)
{
if(sysmenu_active)
{
sysmenu_active = 0;
sysmenu_draw();
}
}