diff options
Diffstat (limited to 'include/llmr/util')
-rw-r--r-- | include/llmr/util/animation.hpp | 44 | ||||
-rw-r--r-- | include/llmr/util/pbf.hpp | 4 |
2 files changed, 43 insertions, 5 deletions
diff --git a/include/llmr/util/animation.hpp b/include/llmr/util/animation.hpp index 4095fcba1e..2024fb8753 100644 --- a/include/llmr/util/animation.hpp +++ b/include/llmr/util/animation.hpp @@ -2,6 +2,7 @@ #define LLMR_UTIL_ANIMATION #include <llmr/util/noncopyable.hpp> +#include <llmr/platform/platform.hpp> namespace llmr { namespace util { @@ -12,14 +13,51 @@ public: running, complete }; + animation(double duration) + : start(platform::time()), + duration(duration) {} - animation(double from, double to, double &value, double duration); + double progress() const { + return (platform::time() - start) / duration; + } + + virtual state update() const = 0; + virtual ~animation(); + +protected: + const double start, duration; +}; + +class ease_animation : public animation { +public: + ease_animation(double from, double to, double& value, double duration); state update() const; private: - const double start, duration; const double from, to; - double &value; + double& value; +}; + +template <typename T> +class timeout : public animation { +public: + timeout(T final_value, T& value, double duration) + : animation(duration), + final_value(final_value), + value(value) {} + + state update() const { + if (progress() >= 1) { + value = final_value; + return complete; + } else { + return running; + } + } + +private: + const T final_value; + T& value; }; } diff --git a/include/llmr/util/pbf.hpp b/include/llmr/util/pbf.hpp index 132cc14354..2e99cd91cb 100644 --- a/include/llmr/util/pbf.hpp +++ b/include/llmr/util/pbf.hpp @@ -20,7 +20,7 @@ struct pbf { struct unknown_field_type_exception : exception {}; struct end_of_buffer_exception : exception {}; - inline pbf(const unsigned char *data, uint32_t length); + inline pbf(const unsigned char *data, size_t length); inline pbf(); inline operator bool() const; @@ -49,7 +49,7 @@ struct pbf { uint32_t tag = 0; }; -pbf::pbf(const unsigned char *data, uint32_t length) +pbf::pbf(const unsigned char *data, size_t length) : data(data), end(data + length), value(0), |