aboutsummaryrefslogtreecommitdiff
path: root/src/ui/animations/animation.h
diff options
context:
space:
mode:
authorcrupest <crupest@outlook.com>2018-09-25 13:37:33 +0800
committercrupest <crupest@outlook.com>2018-09-25 13:37:33 +0800
commitccbc293c0158d4450c0db344474193f17925403f (patch)
tree1ecde3132b3299ab2f272f541a76bced67f983b1 /src/ui/animations/animation.h
parent184c3b2b39d3fa34f9349a7d7fbebe49bc62f7fc (diff)
parentea4b0966d8eb5a8e76dfbe4d833a07a4797a3284 (diff)
downloadcru-ccbc293c0158d4450c0db344474193f17925403f.tar.gz
cru-ccbc293c0158d4450c0db344474193f17925403f.tar.bz2
cru-ccbc293c0158d4450c0db344474193f17925403f.zip
Merge branch 'master' into issue4-dev
Diffstat (limited to 'src/ui/animations/animation.h')
-rw-r--r--src/ui/animations/animation.h107
1 files changed, 107 insertions, 0 deletions
diff --git a/src/ui/animations/animation.h b/src/ui/animations/animation.h
new file mode 100644
index 00000000..69b08b0c
--- /dev/null
+++ b/src/ui/animations/animation.h
@@ -0,0 +1,107 @@
+#pragma once
+
+#include <unordered_map>
+
+#include "base.h"
+#include "application.h"
+#include "timer.h"
+
+namespace cru::ui::animations
+{
+ using AnimationTimeUnit = FloatSecond;
+
+
+ using IAnimationDelegate = ICancelable;
+ using AnimationDelegatePtr = CancelablePtr;
+
+ using AnimationStepHandlerPtr = FunctionPtr<void(AnimationDelegatePtr, double)>;
+ using AnimationStartHandlerPtr = FunctionPtr<void(AnimationDelegatePtr)>;
+
+
+ namespace details
+ {
+ class Animation;
+ using AnimationPtr = std::unique_ptr<Animation>;
+
+ class AnimationManager : public Object
+ {
+ public:
+ static AnimationManager* GetInstance()
+ {
+ return Application::GetInstance()->GetAnimationManager();
+ }
+
+ public:
+ AnimationManager();
+ AnimationManager(const AnimationManager& other) = delete;
+ AnimationManager(AnimationManager&& other) = delete;
+ AnimationManager& operator=(const AnimationManager& other) = delete;
+ AnimationManager& operator=(AnimationManager&& other) = delete;
+ ~AnimationManager() override;
+
+ AnimationDelegatePtr CreateAnimation(
+ String tag,
+ AnimationTimeUnit duration,
+ Vector<AnimationStepHandlerPtr> step_handlers,
+ Vector<AnimationStartHandlerPtr> start_handlers,
+ Vector<ActionPtr> finish_handlers,
+ Vector<ActionPtr> cancel_handlers
+ );
+ void RemoveAnimation(const String& tag);
+
+ private:
+ void SetTimer();
+ void KillTimer();
+
+ private:
+ std::unordered_map<String, AnimationPtr> animations_;
+ std::shared_ptr<ICancelable> timer_;
+ ActionPtr timer_action_;
+ };
+ }
+
+ class AnimationBuilder : public Object
+ {
+ public:
+ AnimationBuilder(String tag, const AnimationTimeUnit duration)
+ : tag(std::move(tag)), duration(duration)
+ {
+
+ }
+
+ String tag;
+ AnimationTimeUnit duration;
+
+ AnimationBuilder& AddStepHandler(AnimationStepHandlerPtr handler)
+ {
+ step_handlers_.push_back(std::move(handler));
+ return *this;
+ }
+
+ AnimationBuilder& AddStartHandler(AnimationStartHandlerPtr handler)
+ {
+ start_handlers_.push_back(std::move(handler));
+ return *this;
+ }
+
+ AnimationBuilder& AddFinishHandler(ActionPtr handler)
+ {
+ finish_handlers_.push_back(std::move(handler));
+ return *this;
+ }
+
+ AnimationBuilder& AddCancelHandler(ActionPtr handler)
+ {
+ cancel_handlers_.push_back(std::move(handler));
+ return *this;
+ }
+
+ AnimationDelegatePtr Start() const;
+
+ private:
+ Vector<AnimationStepHandlerPtr> step_handlers_;
+ Vector<AnimationStartHandlerPtr> start_handlers_;
+ Vector<ActionPtr> finish_handlers_;
+ Vector<ActionPtr> cancel_handlers_;
+ };
+}