diff options
author | crupest <crupest@outlook.com> | 2019-03-31 17:14:47 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-03-31 17:14:47 +0800 |
commit | fbfd90255731954fb80483f4ba7188d3611fafec (patch) | |
tree | 8e3283c911d7aec76130d6a1dc7f5d8a85512b59 /src/platform_win/timer.hpp | |
parent | 877f65e2e2c40eecc7cfeb194dc9d391af60711b (diff) | |
download | cru-fbfd90255731954fb80483f4ba7188d3611fafec.tar.gz cru-fbfd90255731954fb80483f4ba7188d3611fafec.tar.bz2 cru-fbfd90255731954fb80483f4ba7188d3611fafec.zip |
...
Diffstat (limited to 'src/platform_win/timer.hpp')
-rw-r--r-- | src/platform_win/timer.hpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/platform_win/timer.hpp b/src/platform_win/timer.hpp new file mode 100644 index 00000000..95468b8d --- /dev/null +++ b/src/platform_win/timer.hpp @@ -0,0 +1,34 @@ +#pragma once +#include "cru/platform/win/win_pre_config.hpp" + +#include <chrono> +#include <functional> +#include <map> +#include <optional> + +#include "cru/common/base.hpp" +#include "cru/platform/win/god_window.hpp" + +namespace cru::platform::win { +using TimerAction = std::function<void()>; + +class TimerManager : public Object { + public: + TimerManager(GodWindow* god_window); + TimerManager(const TimerManager& other) = delete; + TimerManager(TimerManager&& other) = delete; + TimerManager& operator=(const TimerManager& other) = delete; + TimerManager& operator=(TimerManager&& other) = delete; + ~TimerManager() override = default; + + UINT_PTR CreateTimer(UINT milliseconds, bool loop, const TimerAction& action); + void KillTimer(UINT_PTR id); + std::optional<std::pair<bool, TimerAction>> GetAction(UINT_PTR id); + + private: + GodWindow* god_window_; + + std::map<UINT_PTR, std::pair<bool, TimerAction>> map_{}; + UINT_PTR current_count_ = 0; +}; +} // namespace cru::platform::win |