forked from notsecure/uTox
-
Notifications
You must be signed in to change notification settings - Fork 1
/
sysmenu.c
136 lines (111 loc) · 2.69 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
#include "main.h"
enum {
SYSMENU_NONE,
SYSMENU_MINI,
SYSMENU_SIZE,
SYSMENU_EXIT,
};
static void sysmenu_button(RECT *area, int bm, uint32_t bg_hover, uint32_t bg_down, uint32_t fg_hover, uint32_t fg_down, _Bool active, _Bool down)
{
if(active) {
if(down) {
fillrect(area, bg_down);
setcolor(bg_down);
setbkcolor(fg_down);
} else {
fillrect(area, bg_hover);
setcolor(bg_hover);
setbkcolor(fg_hover);
}
} else {
fillrect(area, COLOR_BG);
setcolor(COLOR_BG);
setbkcolor(COLOR_SYSMENU);
}
drawbitmap(bm, area->left + 7, area->top + 8, 16, 10);
}
void sysmenu_draw(SYSMENU *s, int x, int y, int width, int height)
{
RECT r = {x + width - 30, y, x + width, y + 26};
sysmenu_button(&r, BM_EXIT, RED, RED2, WHITE, WHITE, s->active == SYSMENU_EXIT, s->mdown);
r.left -= 30;
r.right -= 30;
sysmenu_button(&r, maximized ? BM_RESTORE : BM_MAXIMIZE, GRAY, BLUE, 0x333333, WHITE, s->active == SYSMENU_SIZE, s->mdown);
r.left -= 30;
r.right -= 30;
sysmenu_button(&r, BM_MINIMIZE, GRAY, BLUE, 0x333333, WHITE, s->active == SYSMENU_MINI, s->mdown);
//commitdraw(width - BORDER - 90, BORDER, width - BORDER, BORDER + 26);
}
_Bool sysmenu_mmove(SYSMENU *s, int x, int y, int dy, int width, int height)
{
uint8_t sm = 0;
if(inrect(x, y, 0, 0, width, height))
{
sm = 1 + x / 30;
}
s->mover = sm;
if(!(GetKeyState(VK_LBUTTON) & 0x80)) {
if(sm != s->active) {
s->active = sm;
return 1;
}
} else {
_Bool md = (sm == s->active);
if(md != s->mdown) {
s->mdown = md;
return 1;
}
}
return 0;
}
_Bool sysmenu_mdown(SYSMENU *s)
{
if(s->active) {
if(!s->mdown) {
s->mdown = 1;
return 1;
}
}
return 0;
}
_Bool sysmenu_mright(SYSMENU *s)
{
return 0;
}
_Bool sysmenu_mwheel(SYSMENU *s, int height, double d)
{
return 0;
}
_Bool sysmenu_mup(SYSMENU *s)
{
if(s->active == s->mover) {
switch(s->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;
}
}
}
s->mdown = 0;
if(s->active || s->mover) {
s->active = s->mover;
return 1;
}
return 0;
}
_Bool sysmenu_mleave(SYSMENU *s)
{
if(s->active) {
s->active = 0;
return 1;
}
return 0;
}