-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathTimerNotification.cpp
More file actions
162 lines (127 loc) · 4.13 KB
/
Copy pathTimerNotification.cpp
File metadata and controls
162 lines (127 loc) · 4.13 KB
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
155
156
157
158
159
160
161
162
#include "TimerNotification.h"
#include "SDF.h"
#include <cmath>
using namespace std;
TimerNotification::TimerNotification()
{
is_visible = false;
bar_height = 60;
replay_btn_hovered = false;
close_btn_hovered = false;
}
TimerNotification::~TimerNotification()
{
}
void TimerNotification::show(const Timer& timer)
{
finished_timer = timer;
is_visible = true;
}
void TimerNotification::hide()
{
is_visible = false;
}
void TimerNotification::draw_replay_button()
{
int btn_x = 520 - 100;
int btn_y = 30;
int btn_radius = 18;
COLORREF btn_color = replay_btn_hovered ? RGB(100, 100, 100) : RGB(80, 80, 80);
SDF::draw_aa_circle(btn_x, btn_y, btn_radius, btn_color);
setlinecolor(WHITE);
setlinestyle(PS_SOLID, 2);
int arc_radius = 8;
for (int i = 0; i < 270; i++)
{
//从3点钟位置顺时针画270度
int angle1 = -i; //从0度开始顺时针
int angle2 = -i - 1;
double a1 = angle1 * 3.14159265 / 180.0;
double a2 = angle2 * 3.14159265 / 180.0;
int x1 = btn_x + (int)(arc_radius * cos(a1));
int y1 = btn_y - (int)(arc_radius * sin(a1));
int x2 = btn_x + (int)(arc_radius * cos(a2));
int y2 = btn_y - (int)(arc_radius * sin(a2));
line(x1, y1, x2, y2);
}
//箭头在12点钟位置(圆弧结束端),指向右边
//12点钟位置是圆的最上方
int arrow_x = btn_x; //圆心x
int arrow_y = btn_y - arc_radius; //12点钟位置,圆的最上方
//箭头指向右边
line(arrow_x, arrow_y, arrow_x + 5, arrow_y);
line(arrow_x + 5, arrow_y, arrow_x + 2, arrow_y - 3);
line(arrow_x + 5, arrow_y, arrow_x + 2, arrow_y + 3);
}
void TimerNotification::draw_close_button()
{
int btn_x = 520 - 40;
int btn_y = 30;
int btn_radius = 18;
COLORREF btn_color = close_btn_hovered ? RGB(100, 100, 100) : RGB(80, 80, 80);
SDF::draw_aa_circle(btn_x, btn_y, btn_radius, btn_color);
int cross_size = 6;
COLORREF cross_color = WHITE;
SDF::draw_aa_line(btn_x - cross_size, btn_y - cross_size, btn_x + cross_size, btn_y + cross_size, 2, cross_color);
SDF::draw_aa_line(btn_x - cross_size, btn_y + cross_size, btn_x + cross_size, btn_y - cross_size, 2, cross_color);
}
void TimerNotification::draw_notification_bar()
{
setfillcolor(RGB(50, 50, 50));
solidroundrect(0, 0, 520, bar_height, 0, 0);
setlinecolor(RGB(100, 100, 100));
setlinestyle(PS_SOLID, 1);
line(0, bar_height, 520, bar_height);
settextcolor(RGB(240, 151, 72));
settextstyle(22, 0, L"微软雅黑");
setbkmode(TRANSPARENT);
outtextxy(20, 18, finished_timer.label.c_str());
}
void TimerNotification::draw()
{
if (!is_visible) return;
draw_notification_bar();
draw_replay_button();
draw_close_button();
}
bool TimerNotification::check_replay_button_click(int mouse_x, int mouse_y)
{
int btn_x = 520 - 100;
int btn_y = 30;
int btn_radius = 18;
int dx = mouse_x - btn_x;
int dy = mouse_y - btn_y;
return (dx * dx + dy * dy <= btn_radius * btn_radius);
}
bool TimerNotification::check_close_button_click(int mouse_x, int mouse_y)
{
int btn_x = 520 - 40;
int btn_y = 30;
int btn_radius = 18;
int dx = mouse_x - btn_x;
int dy = mouse_y - btn_y;
return (dx * dx + dy * dy <= btn_radius * btn_radius);
}
bool TimerNotification::handle_mouse_click(int mouse_x, int mouse_y, bool& replay_clicked, bool& close_clicked)
{
if (!is_visible) return false;
replay_clicked = false;
close_clicked = false;
if (check_replay_button_click(mouse_x, mouse_y))
{
replay_clicked = true;
return true;
}
if (check_close_button_click(mouse_x, mouse_y))
{
close_clicked = true;
return true;
}
return false;
}
void TimerNotification::handle_mouse_move(int mouse_x, int mouse_y)
{
if (!is_visible) return;
replay_btn_hovered = check_replay_button_click(mouse_x, mouse_y);
close_btn_hovered = check_close_button_click(mouse_x, mouse_y);
}