aboutsummaryrefslogtreecommitdiff
path: root/src/win/native/timer.hpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/win/native/timer.hpp')
-rw-r--r--src/win/native/timer.hpp34
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