-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathsystem_button.cpp
147 lines (118 loc) · 3.33 KB
/
system_button.cpp
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
#pragma once
#include "system_button.hpp"
namespace firefly
{
system_button::system_button(window& parent_window)
: button(parent_window)
{
this->set_default_message_handlers();
}
system_button::system_button(widget& parent_widget)
: button(parent_widget)
{
this->set_default_message_handlers();
}
system_button::~system_button()
{
if (this->arrow_font)
DeleteFont(this->arrow_font);
}
void system_button::create(system_button_type type, rectangle& rect)
{
button::create("", rect);
this->type = type;
if (type == system_button_type::scrollbar_up || type == system_button_type::scrollbar_down)
this->arrow_font = this->create_font("Arial", 12, 6, FW_DONTCARE);
else
this->arrow_font = NULL;
}
void system_button::set_default_message_handlers()
{
this->add_message_handler(CUSTOM_NOTIFY, [this](HWND hWnd, WPARAM wParam, LPARAM lParam) -> LRESULT
{
NMHDR* custom_notify = reinterpret_cast<NMHDR*>(lParam);
if (custom_notify->code == NM_CUSTOMDRAW)
return this->try_custom_draw_item(reinterpret_cast<NMCUSTOMDRAW*>(lParam));
return 0;
});
}
LRESULT system_button::try_custom_draw_item(NMCUSTOMDRAW* custom_draw)
{
if (custom_draw->dwDrawStage != CDDS_PREPAINT)
return CDRF_DODEFAULT;
/* Draw background */
COLORREF background_color = 0;
COLORREF foreground_color = 0;
switch (this->type)
{
case system_button_type::minimize:
case system_button_type::add:
case system_button_type::remove:
{
background_color = this->background();
if (custom_draw->uItemState & CDIS_SELECTED)
foreground_color = RGB(99, 100, 102);
else if (custom_draw->uItemState & CDIS_HOT)
foreground_color = RGB(223, 225, 229);
else
foreground_color = RGB(136, 137, 140);
}
break;
case system_button_type::close:
{
if (custom_draw->uItemState & CDIS_SELECTED)
background_color = RGB(94, 25, 0);
else if (custom_draw->uItemState & CDIS_HOT)
background_color = RGB(189, 50, 0);
else
background_color = RGB(143, 38, 0);
foreground_color = RGB(255, 255, 255);
}
break;
case system_button_type::scrollbar_up:
case system_button_type::scrollbar_down:
{
background_color = this->background();
if (custom_draw->uItemState & CDIS_SELECTED)
foreground_color = RGB(99, 100, 102);
else if (custom_draw->uItemState & CDIS_HOT)
foreground_color = RGB(223, 225, 229);
else
foreground_color = RGB(136, 137, 140);
}
break;
default:
break;
}
this->draw_rectangle(&custom_draw->rc, background_color);
/* Draw text label */
wchar_t* p = 0;
switch (this->type)
{
case system_button_type::minimize:
p = L"\u0336";
break;
case system_button_type::close:
case system_button_type::remove:
p = L"\u00D7";
break;
case system_button_type::scrollbar_up:
p = L"\u25B2";
break;
case system_button_type::scrollbar_down:
p = L"\u25BC";
break;
case system_button_type::add:
p = L"\uFF0B";
break;
default:
break;
}
if (this->arrow_font)
this->draw_text_wide(p, &custom_draw->rc, foreground_color, DT_CENTER | DT_SINGLELINE | DT_VCENTER, this->arrow_font);
else
this->draw_text_wide(p, &custom_draw->rc, foreground_color, DT_CENTER | DT_SINGLELINE | DT_VCENTER);
this->commit_drawing(custom_draw->hdc, &custom_draw->rc);
return CDRF_SKIPDEFAULT;
}
}