Switching SceneItems to smarts
This commit is contained in:
51
archive/animation/SimpleCallbackAnimation.hpp
Normal file
51
archive/animation/SimpleCallbackAnimation.hpp
Normal file
@ -0,0 +1,51 @@
|
||||
// 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;
|
||||
}
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user