51 lines
1.3 KiB
C++
51 lines
1.3 KiB
C++
// Copyright (c) 2023 Dominic Masters
|
|
//
|
|
// This software is released under the MIT License.
|
|
// https://opensource.org/licenses/MIT
|
|
|
|
#pragma once
|
|
#include "SimpleAnimation.hpp"
|
|
|
|
namespace Dawn {
|
|
template<typename T, class I>
|
|
struct SimpleCallbackAnimation : public SimpleAnimation<T> {
|
|
protected:
|
|
I *instance;
|
|
void (I::*callback)(T arg);
|
|
T value;
|
|
|
|
/**
|
|
* Internally invoke the function that this animation is owning.
|
|
*/
|
|
void invoke() {
|
|
assertNotNull(this->instance);
|
|
((*this->instance).*(this->callback))(this->value);
|
|
}
|
|
|
|
void onValueModified() override {
|
|
SimpleAnimation<T>::onValueModified();
|
|
this->invoke();
|
|
}
|
|
|
|
public:
|
|
/**
|
|
* Construct a new Simple Function Animation object
|
|
*/
|
|
SimpleCallbackAnimation() :
|
|
SimpleAnimation<T>(&value)
|
|
{
|
|
}
|
|
|
|
/**
|
|
* Sets the callback for the animation to use.
|
|
*
|
|
* @param instance Instance of the object that has the callback.
|
|
* @param callback Callback method to be invoked.
|
|
*/
|
|
void setCallback(I *instance, void (I::*callback)(T arg)) {
|
|
assertNotNull(instance);
|
|
this->instance = instance;
|
|
this->callback = callback;
|
|
}
|
|
};
|
|
} |