From 956a401f9c955f26b7e661dc80f76bfc43fc4124 Mon Sep 17 00:00:00 2001 From: crupest Date: Sat, 1 Sep 2018 23:28:28 +0800 Subject: Initial commit --- CruUI/timer.h | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 49 insertions(+) create mode 100644 CruUI/timer.h (limited to 'CruUI/timer.h') diff --git a/CruUI/timer.h b/CruUI/timer.h new file mode 100644 index 00000000..1a512a44 --- /dev/null +++ b/CruUI/timer.h @@ -0,0 +1,49 @@ +#pragma once + + +#include "system_headers.h" +#include +#include +#include +#include + +#include "base.h" +#include "application.h" + +namespace cru +{ + using TimerAction = std::function; + + class TimerManager : public Object + { + friend class cru::Application; + private: + static TimerManager* instance_; + + public: + static TimerManager* GetInstance(); + + public: + TimerManager(); + TimerManager(const TimerManager& other) = delete; + TimerManager(TimerManager&& other) = delete; + TimerManager& operator=(const TimerManager& other) = delete; + TimerManager& operator=(TimerManager&& other) = delete; + ~TimerManager() override; + + UINT_PTR CreateTimer(UINT microseconds, bool loop, const TimerAction& action); + void KillTimer(UINT_PTR id); + std::optional GetAction(UINT_PTR id); + + private: + std::map map_{}; + }; + + struct ITimerTask : virtual Interface + { + virtual void Cancel() = 0; + }; + + std::shared_ptr SetTimeout(double seconds, const TimerAction& action); + std::shared_ptr SetInterval(double seconds, const TimerAction& action); +} -- cgit v1.2.3