forked from organicmaps/organicmaps
added callbacks for certain evens into anim::Task.
This commit is contained in:
parent
67371fb10b
commit
e02d4165ce
2 changed files with 27 additions and 0 deletions
|
@ -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;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
};
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue