2015-06-12 13:14:38 +00:00
|
|
|
#if defined(Hiro_Timer)
|
|
|
|
|
|
|
|
namespace hiro {
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2012-08-07 13:28:00 +00:00
|
|
|
static vector<pTimer*> timers;
|
2011-06-05 03:45:04 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
static auto CALLBACK Timer_timeoutProc(HWND hwnd, UINT msg, UINT_PTR timerID, DWORD time) -> void {
|
2013-05-02 11:25:45 +00:00
|
|
|
for(auto& timer : timers) {
|
2015-06-12 13:14:38 +00:00
|
|
|
if(timer->htimer == timerID) return timer->self().doActivate();
|
2011-06-05 03:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pTimer::construct() -> void {
|
|
|
|
timers.append(this);
|
|
|
|
htimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pTimer::destruct() -> void {
|
|
|
|
}
|
|
|
|
|
|
|
|
auto pTimer::setEnabled(bool enabled) -> void {
|
2011-06-05 03:45:04 +00:00
|
|
|
if(htimer) {
|
|
|
|
KillTimer(NULL, htimer);
|
|
|
|
htimer = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
if(enabled == true) {
|
2015-06-12 13:14:38 +00:00
|
|
|
htimer = SetTimer(NULL, 0u, state().interval, Timer_timeoutProc);
|
2011-06-05 03:45:04 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
auto pTimer::setInterval(unsigned interval) -> void {
|
2011-06-05 03:45:04 +00:00
|
|
|
//destroy and recreate timer if interval changed
|
2015-06-12 13:14:38 +00:00
|
|
|
setEnabled(self().enabled(true));
|
2011-06-05 03:45:04 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
}
|
2013-03-15 13:11:33 +00:00
|
|
|
|
2015-06-12 13:14:38 +00:00
|
|
|
#endif
|