#include <rive/artboard.hpp>
#include <rive/file.hpp>
#include <rive/animation/linear_animation_instance.hpp>
-#include <rive/animation/state_machine.hpp>
class RiveTizen {
public:
bool setNodeScale(const std::string &name, float scale_x, float scale_y);
bool setNodeRotation(const std::string &name, float degree);
bool setNodePosition(const std::string &name, float position_x, float position_y);
-
- void pointerMove(float x, float y);
- void pointerDown(float x, float y);
- void pointerUp(float x, float y);
-
- bool setNumberState(const std::string& stateMachineName, const std::string& inputName, float value);
- bool setBooleanState(const std::string& stateMachineName, const std::string& inputName, bool value);
- bool fireState(const std::string& stateMachineName, const std::string& inputName);
-
- private:
- rive::StateMachine* getStateMachine(const std::string& stateMachineName);
- void useDefaultStateMachine();
};
#endif // _RIVE_TIZEN_HPP_
#include <rive/shapes/paint/stroke.hpp>
#include <rive/shapes/paint/fill.hpp>
#include <rive/artboard.hpp>
-#include <rive/animation/state_machine_instance.hpp>
-#include <rive/animation/state_machine_input_instance.hpp>
-#include <rive/animation/state_machine_bool.hpp>
-#include <rive/animation/state_machine_number.hpp>
-#include <rive/animation/state_machine_trigger.hpp>
#ifdef LOG_TAG
#undef LOG_TAG
static rive::SkiaFactory mSkiaFactory;
static std::unique_ptr<rive::File> mFile;
static std::unique_ptr<rive::ArtboardInstance> mArtboardInstance;
-static std::unique_ptr<rive::StateMachineInstance> mCurrentScene;
-rive::Mat2D mInverseViewTransform;
#ifdef USE_GL
static sk_sp<GrDirectContext> mContext;
return mArtboardInstance.get();
}
-rive::LinearAnimationInstance *RiveTizen::createLinearAnimationInstance(size_t index)
+void RiveTizen::animationAdvanceApply(rive::LinearAnimationInstance *animation, double elapsed)
{
- auto animation = mArtboardInstance->animation(index);
-
if (!animation)
{
LOGE("[Invalid parameter][animation == nullptr]");
- return nullptr;
+ return;
}
-
- rive::LinearAnimationInstance *instance = new rive::LinearAnimationInstance(animation, mArtboardInstance.get());
- return instance;
+ animation->advanceAndApply(elapsed);
+ animation->apply();
}
-void RiveTizen::animationAdvanceApply(rive::LinearAnimationInstance *animation, double elapsed)
+void RiveTizen::animationApply(rive::LinearAnimationInstance *animation, double elapsed)
{
if (!animation)
{
LOGE("[Invalid parameter][animation == nullptr]");
return;
}
- animation->advanceAndApply(elapsed);
+ animation->time(elapsed);
animation->apply();
}
-void RiveTizen::animationApply(rive::LinearAnimationInstance *animation, double elapsed)
+rive::LinearAnimationInstance *RiveTizen::createLinearAnimationInstance(size_t index)
{
+ auto animation = mArtboardInstance->animation(index);
+
if (!animation)
{
LOGE("[Invalid parameter][animation == nullptr]");
- return;
+ return nullptr;
}
- animation->time(elapsed);
+
+ rive::LinearAnimationInstance *instance = new rive::LinearAnimationInstance(animation, mArtboardInstance.get());
+ return instance;
}
bool RiveTizen::loadRiveResource(uint8_t *bytes, size_t size)
mArtboardInstance = mFile->artboardDefault();
mArtboardInstance->advance(0.0f);
- useDefaultStateMachine();
-
return true;
}
rive::AABB(0, 0, width, height), mArtboardInstance->bounds());
renderer.transform(viewTransform);
- mInverseViewTransform = viewTransform.invertOrIdentity();
-
- if (mCurrentScene) {
- mCurrentScene->advanceAndApply(elapsed);
- mCurrentScene->draw(&renderer);
- } else {
- mArtboardInstance->draw(&renderer);
- }
-
+ mArtboardInstance->draw(&renderer);
renderer.restore();
#ifdef USE_GL
nodeInstance->y(position_y);
return true;
}
-
-void RiveTizen::pointerMove(float x, float y) {
- if (!mCurrentScene) return;
- auto pointer = mInverseViewTransform * rive::Vec2D(x, y);
- mCurrentScene->pointerMove(pointer);
-}
-
-void RiveTizen::pointerDown(float x, float y) {
- if (!mCurrentScene) return;
- auto pointer = mInverseViewTransform * rive::Vec2D(x, y);
- mCurrentScene->pointerDown(pointer);
-}
-
-void RiveTizen::pointerUp(float x, float y) {
- if (!mCurrentScene) return;
- auto pointer = mInverseViewTransform * rive::Vec2D(x, y);
- mCurrentScene->pointerUp(pointer);
-}
-
-bool RiveTizen::setNumberState(const std::string& stateMachineName, const std::string& inputName, float value) {
- auto sm = getStateMachine(stateMachineName);
- if (!sm) return false;
-
- auto smi = std::make_unique<rive::StateMachineInstance>(sm, mArtboardInstance.get());
- auto number = smi->getNumber(inputName);
- if (!number) {
- LOGE("Number state \"%s\" not found.", inputName.c_str());
- return false;
- }
-
- number->value(value);
- mCurrentScene = std::move(smi);
- return true;
-}
-
-bool RiveTizen::setBooleanState(const std::string& stateMachineName, const std::string& inputName, bool value) {
- auto sm = getStateMachine(stateMachineName);
- if (!sm) return false;
-
- auto smi = std::make_unique<rive::StateMachineInstance>(sm, mArtboardInstance.get());
- auto boolean = smi->getBool(inputName);
- if (!boolean) {
- LOGE("Boolean state \"%s\" not found.", inputName.c_str());
- return false;
- }
-
- boolean->value(value);
- mCurrentScene = std::move(smi);
- return true;
-}
-
-bool RiveTizen::fireState(const std::string& stateMachineName, const std::string& inputName) {
- auto sm = getStateMachine(stateMachineName);
- if (!sm) return false;
-
- auto smi = std::make_unique<rive::StateMachineInstance>(sm, mArtboardInstance.get());
- auto trigger = smi->getTrigger(inputName);
- if (!trigger) {
- LOGE("Trigger state \"%s\" not found.", inputName.c_str());
- return false;
- }
-
- trigger->fire();
- mCurrentScene = std::move(smi);
- return true;
-}
-
-rive::StateMachine* RiveTizen::getStateMachine(const std::string& stateMachineName) {
- rive::StateMachine* sm = nullptr;
- if (!stateMachineName.empty()) {
- sm = mArtboardInstance->stateMachine(stateMachineName);
- if (!sm) {
- LOGE("StateMachine named \"%s\" not found.", stateMachineName.c_str());
- }
- } else {
- const int index = mArtboardInstance->defaultStateMachineIndex();
- if (index >= 0) {
- sm = mArtboardInstance->stateMachine(index);
- } else {
- LOGE("No default stateMachine.");
- }
- }
- return sm;
-}
-
-void RiveTizen::useDefaultStateMachine() {
- mCurrentScene = mArtboardInstance->defaultStateMachine();
- if (!mCurrentScene) {
- int index = mArtboardInstance->defaultStateMachineIndex();
- if (index >= mArtboardInstance->stateMachineCount()) index = 0;
- if (index >= 0) mCurrentScene = mArtboardInstance->stateMachineAt(index);
- }
- if (mCurrentScene) {
- mCurrentScene->inputCount();
- } else {
- LOGE("No default stateMachine");
- }
-}