-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtime_window.h
More file actions
84 lines (63 loc) · 2.22 KB
/
time_window.h
File metadata and controls
84 lines (63 loc) · 2.22 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
#pragma once
#include <chrono>
// 时间显示窗口类
constexpr auto TIMER_CLASS_NAME = L"TimeWindowClass";
// 标题栏名
constexpr auto TIMER_WINDOW_TITLE = L"Timer";
// 窗口尺寸
constexpr auto TIMER_WINDOW_WIDTH = 320;
constexpr auto TIMER_WINDOW_HEIGHT = 100;
// 窗口坐标
constexpr auto TIMER_WINDOW_X = 10;
constexpr auto TIMER_WINDOW_Y = 10;
// 窗口椭圆坐标
constexpr auto TIMER_WINDOW_ROUND_X = 0;
constexpr auto TIMER_WINDOW_ROUND_Y = 0;
// 窗口椭圆的宽度和高度
constexpr auto TIMER_WINDOW_ROUND_W = 10;
constexpr auto TIMER_WINDOW_ROUND_H = 10;
// 窗口的元素间距
constexpr auto TIMER_WINDOW_MARGIN = 10;
// 时间显示容器的圆角宽度和高度
constexpr auto TIMER_DISPLAY_ROUND_W = 10;
constexpr auto TIMER_DISPLAY_ROUND_H = 10;
// 时间的更新定时器
constexpr auto DATE_TIMER_ID = 0x0001;
// 动画的更新定时器
constexpr auto ANIMATION_TIMER_ID = 0x0002;
// 窗口显示时间半径: 秒
constexpr auto WINDOWS_SHOW_TIME_RADIUS_SEC = 30;
// 动画的淡入淡速度
constexpr auto FADE_DURATION = 5;
int CreateTimeClassAndWindow(_In_ HINSTANCE hInstance, _In_ int nCmdShow);
// 计步器: 并非时间倒计时,由手动调用step步进来计数
// 需要设置起点和目标点,更具distance来计算和目标点的距离
// 抵达目标点后不会停止,可以继续调用step来继续步进
class StepCountDown {
public:
explicit StepCountDown(const long long down, const long long count = 0) : count(count), down(down) {
}
explicit StepCountDown(const std::chrono::seconds down,
const std::chrono::seconds count = std::chrono::seconds(0)) : count(count.count()),
down(down.count()) {
}
StepCountDown() : StepCountDown(0, 0) {
};
void step(UINT i = 1) {
this->count += i;
}
long long distance() const {
return abs(static_cast<int>(this->down - this->count));
}
void reset(const long long end, const long long start = 0) {
this->count = start;
this->down = end;
}
void reset(const std::chrono::seconds end, const long long start = 0) {
this->count = start;
this->down = end.count();
}
private:
long long count;
long long down;
};