From efdce672123284847bd7fb6f12ac1ec96f28f3ef Mon Sep 17 00:00:00 2001 From: crupest Date: Wed, 7 Nov 2018 21:40:04 +0800 Subject: Make all header *.hpp . --- src/ui/animations/animation.cpp | 2 +- src/ui/animations/animation.h | 131 ---------------------------------------- src/ui/animations/animation.hpp | 131 ++++++++++++++++++++++++++++++++++++++++ 3 files changed, 132 insertions(+), 132 deletions(-) delete mode 100644 src/ui/animations/animation.h create mode 100644 src/ui/animations/animation.hpp (limited to 'src/ui/animations') diff --git a/src/ui/animations/animation.cpp b/src/ui/animations/animation.cpp index ca0fe8bc..33c743cf 100644 --- a/src/ui/animations/animation.cpp +++ b/src/ui/animations/animation.cpp @@ -1,4 +1,4 @@ -#include "animation.h" +#include "animation.hpp" #include diff --git a/src/ui/animations/animation.h b/src/ui/animations/animation.h deleted file mode 100644 index 91a666c9..00000000 --- a/src/ui/animations/animation.h +++ /dev/null @@ -1,131 +0,0 @@ -#pragma once - -#include - -#include "base.h" -#include "application.h" -#include "timer.h" - -namespace cru::ui::animations -{ - using AnimationTimeUnit = FloatSecond; - - struct IAnimationDelegate : virtual Interface - { - virtual void Cancel() = 0; - }; - - using AnimationDelegatePtr = std::shared_ptr; - - using AnimationStepHandler = std::function; - using AnimationStartHandler = std::function; - using AnimationFinishHandler = std::function; - using AnimationCancelHandler = std::function; - - namespace details - { - class Animation; - using AnimationPtr = std::unique_ptr; - - class AnimationInfo - { - public: - AnimationInfo(String tag, const AnimationTimeUnit duration) - : tag(std::move(tag)), - duration(duration) - { - - } - AnimationInfo(const AnimationInfo& other) = default; - AnimationInfo(AnimationInfo&& other) = default; - AnimationInfo& operator=(const AnimationInfo& other) = default; - AnimationInfo& operator=(AnimationInfo&& other) = default; - ~AnimationInfo() = default; - - String tag; - AnimationTimeUnit duration; - std::vector step_handlers{}; - std::vector start_handlers{}; - std::vector finish_handlers{}; - std::vector cancel_handlers{}; - }; - - 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(AnimationInfo info); - void RemoveAnimation(const String& tag); - - private: - void SetTimer(); - void KillTimer(); - - private: - std::unordered_map animations_; - std::optional timer_; - }; - } - - class AnimationBuilder : public Object - { - public: - AnimationBuilder(String tag, const AnimationTimeUnit duration) - : info_(std::move(tag), duration) - { - - } - - AnimationBuilder& AddStepHandler(const AnimationStepHandler& handler) - { - CheckValid(); - info_.step_handlers.push_back(handler); - return *this; - } - - AnimationBuilder& AddStartHandler(const AnimationStartHandler& handler) - { - CheckValid(); - info_.start_handlers.push_back(handler); - return *this; - } - - AnimationBuilder& AddFinishHandler(const AnimationFinishHandler& handler) - { - CheckValid(); - info_.finish_handlers.push_back(handler); - return *this; - } - - AnimationBuilder& AddCancelHandler(const AnimationCancelHandler& handler) - { - CheckValid(); - info_.cancel_handlers.push_back(handler); - return *this; - } - - AnimationDelegatePtr Start(); - - private: - void CheckValid() const - { - if (!valid_) - throw std::runtime_error("The animation builder is invalid."); - } - - bool valid_ = true; - details::AnimationInfo info_; - }; -} diff --git a/src/ui/animations/animation.hpp b/src/ui/animations/animation.hpp new file mode 100644 index 00000000..99389f33 --- /dev/null +++ b/src/ui/animations/animation.hpp @@ -0,0 +1,131 @@ +#pragma once + +#include + +#include "base.hpp" +#include "application.hpp" +#include "timer.hpp" + +namespace cru::ui::animations +{ + using AnimationTimeUnit = FloatSecond; + + struct IAnimationDelegate : virtual Interface + { + virtual void Cancel() = 0; + }; + + using AnimationDelegatePtr = std::shared_ptr; + + using AnimationStepHandler = std::function; + using AnimationStartHandler = std::function; + using AnimationFinishHandler = std::function; + using AnimationCancelHandler = std::function; + + namespace details + { + class Animation; + using AnimationPtr = std::unique_ptr; + + class AnimationInfo + { + public: + AnimationInfo(String tag, const AnimationTimeUnit duration) + : tag(std::move(tag)), + duration(duration) + { + + } + AnimationInfo(const AnimationInfo& other) = default; + AnimationInfo(AnimationInfo&& other) = default; + AnimationInfo& operator=(const AnimationInfo& other) = default; + AnimationInfo& operator=(AnimationInfo&& other) = default; + ~AnimationInfo() = default; + + String tag; + AnimationTimeUnit duration; + std::vector step_handlers{}; + std::vector start_handlers{}; + std::vector finish_handlers{}; + std::vector cancel_handlers{}; + }; + + 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(AnimationInfo info); + void RemoveAnimation(const String& tag); + + private: + void SetTimer(); + void KillTimer(); + + private: + std::unordered_map animations_; + std::optional timer_; + }; + } + + class AnimationBuilder : public Object + { + public: + AnimationBuilder(String tag, const AnimationTimeUnit duration) + : info_(std::move(tag), duration) + { + + } + + AnimationBuilder& AddStepHandler(const AnimationStepHandler& handler) + { + CheckValid(); + info_.step_handlers.push_back(handler); + return *this; + } + + AnimationBuilder& AddStartHandler(const AnimationStartHandler& handler) + { + CheckValid(); + info_.start_handlers.push_back(handler); + return *this; + } + + AnimationBuilder& AddFinishHandler(const AnimationFinishHandler& handler) + { + CheckValid(); + info_.finish_handlers.push_back(handler); + return *this; + } + + AnimationBuilder& AddCancelHandler(const AnimationCancelHandler& handler) + { + CheckValid(); + info_.cancel_handlers.push_back(handler); + return *this; + } + + AnimationDelegatePtr Start(); + + private: + void CheckValid() const + { + if (!valid_) + throw std::runtime_error("The animation builder is invalid."); + } + + bool valid_ = true; + details::AnimationInfo info_; + }; +} -- cgit v1.2.3