// 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 struct SimpleCallbackAnimation : public SimpleAnimation { 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::onValueModified(); this->invoke(); } public: /** * Construct a new Simple Function Animation object */ SimpleCallbackAnimation() : SimpleAnimation(&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; } }; }