diff options
author | rachytski <siarhei.rachytski@gmail.com> | 2012-09-26 18:06:15 +0400 |
---|---|---|
committer | Alex Zolotarev <alex@maps.me> | 2015-09-23 01:44:15 +0300 |
commit | e02d4165cec23a5dca58866c5ca16397c17835a1 (patch) | |
tree | 49d6ef6b5bf19af2a00425d9afbf74ba111113ac /anim | |
parent | 67371fb10b67510773ee1ced4536b227e2d4dd6f (diff) |
added callbacks for certain evens into anim::Task.
Diffstat (limited to 'anim')
-rw-r--r-- | anim/task.cpp | 16 | ||||
-rw-r--r-- | anim/task.hpp | 11 |
2 files changed, 27 insertions, 0 deletions
diff --git a/anim/task.cpp b/anim/task.cpp index 01e548eef1..c921fc8789 100644 --- a/anim/task.cpp +++ b/anim/task.cpp @@ -19,21 +19,32 @@ namespace anim m_State = State; } + void Task::PerformCallback(EState state) + { + TCallback const & cb = m_callbacks[state]; + if (cb) + cb(); + } + void Task::OnStart(double ts) { + PerformCallback(EStarted); SetState(EInProgress); } void Task::OnStep(double ts) { + PerformCallback(EInProgress); } void Task::OnCancel(double ts) { + PerformCallback(ECancelled); } void Task::OnEnd(double ts) { + PerformCallback(EEnded); } void Task::Cancel() @@ -60,4 +71,9 @@ namespace anim { return State() == EInProgress; } + + void Task::SetCallback(EState state, TCallback const & cb) + { + m_callbacks[state] = cb; + } } diff --git a/anim/task.hpp b/anim/task.hpp index b1366e9c80..d898a972ef 100644 --- a/anim/task.hpp +++ b/anim/task.hpp @@ -1,5 +1,8 @@ #pragma once +#include "../std/map.hpp" +#include "../std/function.hpp" + namespace anim { // Interface for single animation task @@ -7,6 +10,8 @@ namespace anim { public: + typedef function<void()> TCallback; + enum EState { EStarted, @@ -19,6 +24,10 @@ namespace anim EState m_State; + map<EState, TCallback> m_callbacks; + + void PerformCallback(EState state); + protected: void SetState(EState state); @@ -41,5 +50,7 @@ namespace anim bool IsCancelled() const; bool IsEnded() const; bool IsRunning() const; + + void SetCallback(EState state, TCallback const & cb); }; } |