Debian Codegraph @

phoenix/windows/timer.cpp

raw
1 namespace phoenix {
2
3 static vector<pTimer*> timers;
4
5 static void CALLBACK Timer_timeoutProc(HWND hwnd, UINT msg, UINT_PTR timerID, DWORD time) {
6 for(auto& timer : timers) {
7 if(timer->htimer == timerID) {
8 if(timer->timer.onActivate) timer->timer.onActivate();
9 return;
10 }
11 }
12 }
13
14 void pTimer::setEnabled(bool enabled) {
15 if(htimer) {
16 KillTimer(NULL, htimer);
17 htimer = 0;
18 }
19
20 if(enabled == true) {
21 htimer = SetTimer(NULL, 0u, timer.state.interval, Timer_timeoutProc);
22 }
23 }
24
25 void pTimer::setInterval(unsigned interval) {
26 //destroy and recreate timer if interval changed
27 setEnabled(timer.state.enabled);
28 }
29
30 void pTimer::constructor() {
31 timers.append(this);
32 htimer = 0;
33 }
34
35 }