diff options
author | crupest <crupest@outlook.com> | 2019-04-10 19:42:46 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2019-04-10 19:42:46 +0800 |
commit | 7351020a582d70a1495249fba87d342c8a1fb634 (patch) | |
tree | e80f225041dc3816b3dce21c7e15aadbb211602e /src/win/native/timer.hpp | |
parent | a94a806f69586e08a30fff0cdb3e52b0ce7acfa5 (diff) | |
download | cru-7351020a582d70a1495249fba87d342c8a1fb634.tar.gz cru-7351020a582d70a1495249fba87d342c8a1fb634.tar.bz2 cru-7351020a582d70a1495249fba87d342c8a1fb634.zip |
Refactor.
Diffstat (limited to 'src/win/native/timer.hpp')
-rw-r--r-- | src/win/native/timer.hpp | 34 |
1 files changed, 34 insertions, 0 deletions
diff --git a/src/win/native/timer.hpp b/src/win/native/timer.hpp new file mode 100644 index 00000000..f30d9b91 --- /dev/null +++ b/src/win/native/timer.hpp @@ -0,0 +1,34 @@ +#pragma once +#include "cru/win/win_pre_config.hpp" + +#include "cru/common/base.hpp" +#include "cru/win/native/god_window.hpp" + +#include <chrono> +#include <functional> +#include <map> +#include <optional> + +namespace cru::win::native { +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::win::native |