Commit 084c5879 authored by Ole Untzelmann's avatar Ole Untzelmann

[Animations] Feature #8

Removed the Interfaces.hh and modified the AnimationEvent class to either
call function pointers or member function pointers using class templates.
parent 0fd425a2
......@@ -8,7 +8,6 @@
#include <ACGL/Types.hh>
#include <ACGL/Base/Macros.hh>
#include <ACGL/Base/Interfaces.hh>
#include <ACGL/Animations/EaseFunctions.hh>
#include <ACGL/Animations/Interpolator.hh>
......@@ -64,25 +63,90 @@ private:
};
class AnimationEventCallbackFunction
{
public:
typedef void (*Function)(uint_t);
AnimationEventCallbackFunction(Function _pFunction,uint_t _id) :
mpFunction(_pFunction),
mId(_id) { }
inline void call()
{
mpFunction(mId);
}
private:
Function mpFunction;
uint_t mId;
};
template <class T>
class AnimationEventCallbackMemberFunction
{
public:
typedef void (T::*Function)(uint_t);
AnimationEventCallbackMemberFunction(const T* _pTarget, Function _pFunction,uint_t _id) :
mpTarget(_pTarget),
mpFunction(_pFunction),
mId(_id) { }
inline void call()
{
mpTarget->mpFunction(mId);
}
private:
const T* mpTarget;
Function mpFunction;
uint_t mId;
};
// AnimationEvent *************************************************************************************
template <class Callback>
class AnimationEvent : public Animation
{
public:
AnimationEvent(const uint_t _id, const ACGL::Base::SharedINotifiable& _event);
AnimationEvent(const Callback& _callback) :
Animation(),
mCallback(_callback),
mEventCalled(false) { }
virtual void init();
virtual long update(uint_t _msec);
virtual bool finished();
virtual void init()
{
mEventCalled = false;
mInited = true;
}
virtual long update(uint_t _msec)
{
mCallback.call();
mEventCalled = true;
return _msec;
}
virtual bool finished()
{
return mEventCalled;
}
Callback& getCallback()
{
return mCallback;
}
private:
ACGL::Base::SharedINotifiable mEvent;
uint_t mId;
Callback mCallback;
bool mEventCalled;
};
ACGL_SHARED_TYPEDEF(AnimationEvent)
// AnimationWait *************************************************************************************
......
////////////////////////////////////////////////////////////////////////////////
// Copyright (c) 2011, Computer Graphics Group RWTH Aachen University //
// All rights reserved. //
////////////////////////////////////////////////////////////////////////////////
#ifndef ACGL_BASE_INTERFACES_HH
#define ACGL_BASE_INTERFACES_HH
#include <ACGL/Types.hh>
#include <ACGL/Base/Macros.hh>
#include <tr1/memory>
namespace ACGL{
namespace Base{
class INotifiable
{
public:
virtual void notify(uint_t _id) = 0;
};
ACGL_SHARED_TYPEDEF(INotifiable)
}
}
#endif // ACGL_BASE_INTERFACES_HH
......@@ -64,36 +64,6 @@ void AnimationManager::cleanUp()
mAnimations.clear();
}
AnimationEvent::AnimationEvent(const uint_t _id, const ACGL::Base::SharedINotifiable& _event) :
Animation(),
mEvent(_event),
mId(_id),
mEventCalled(false)
{
}
void AnimationEvent::init()
{
mEventCalled = false;
mInited = true;
}
long AnimationEvent::update(uint_t _msec)
{
if(mEvent)
mEvent->notify(mId);
mEventCalled = true;
return _msec;
}
bool AnimationEvent::finished()
{
return mEventCalled;
}
AnimationWait::AnimationWait(const uint_t _duration) :
mTimeLeft(0),
mDuration(_duration)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment