diff options
author | crupest <crupest@outlook.com> | 2022-02-08 16:53:51 +0800 |
---|---|---|
committer | crupest <crupest@outlook.com> | 2022-02-08 16:53:51 +0800 |
commit | 74bb9cd27242b9320f99ff4d2b50c3051576cc14 (patch) | |
tree | 744bac5799c593d1d6f81e7b09581bea626f2cde /src/win/gui/TimerManager.hpp | |
parent | b90c398de829d1ba5329651d75bae82f5e4085fe (diff) | |
download | cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.gz cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.tar.bz2 cru-74bb9cd27242b9320f99ff4d2b50c3051576cc14.zip |
...
Diffstat (limited to 'src/win/gui/TimerManager.hpp')
-rw-r--r-- | src/win/gui/TimerManager.hpp | 61 |
1 files changed, 0 insertions, 61 deletions
diff --git a/src/win/gui/TimerManager.hpp b/src/win/gui/TimerManager.hpp deleted file mode 100644 index a8db1075..00000000 --- a/src/win/gui/TimerManager.hpp +++ /dev/null @@ -1,61 +0,0 @@ -#pragma once -#include "cru/common/Event.hpp" -#include "cru/win/WinPreConfig.hpp" - -#include "cru/common/Base.hpp" -#include "cru/win/gui/GodWindow.hpp" -#include "cru/win/gui/WindowNativeMessageEventArgs.hpp" - -#include <chrono> -#include <functional> -#include <optional> -#include <unordered_map> - -namespace cru::platform::gui::win { -enum class TimerType { Immediate, Timeout, Interval }; - -struct TimerInfo { - TimerInfo(long long id, TimerType type, int period, - std::function<void()> action, UINT_PTR native_timer_id = 0) - : id(id), - type(type), - period(period), - action(std::move(action)), - native_timer_id(native_timer_id) {} - - long long id; - TimerType type; - int period; // in milliseconds - std::function<void()> action; - UINT_PTR native_timer_id; -}; - -class TimerManager : public Object { - public: - TimerManager(GodWindow* god_window); - - CRU_DELETE_COPY(TimerManager) - CRU_DELETE_MOVE(TimerManager) - - ~TimerManager() override = default; - - // Period is in milliseconds. When type is immediate, it is not checked and - // used. - long long SetTimer(TimerType type, int period, std::function<void()> action); - void CancelTimer(long long id); - - private: - void HandleGodWindowMessage(WindowNativeMessageEventArgs& args); - - void CreateNativeTimer(TimerInfo* info); - void KillNativeTimer(TimerInfo* info); - - private: - GodWindow* god_window_; - - EventRevokerListGuard event_guard_; - - long long next_id_ = 1; - std::unordered_map<long long, TimerInfo> info_map_; -}; -} // namespace cru::platform::gui::win |