Extension::GetImplementation(*this).EnableAnimation(animationName, enable);
}
+void RiveAnimationView::SetAnimationElapsedTime(const std::string& animationName, float elapsed)
+{
+ Extension::GetImplementation(*this).SetAnimationElapsedTime(animationName, elapsed);
+}
+
void RiveAnimationView::SetShapeFillColor(const std::string& fillName, Vector4 color)
{
Extension::GetImplementation(*this).SetShapeFillColor(fillName, color);
void EnableAnimation(const std::string& animationName, bool enable);
/**
+ * @brief Sets the animation elapsed time.
+ *
+ * @param[in] animationName The animation name
+ * @param[in] time The animation elapsed time (in second)
+ */
+ void SetAnimationElapsedTime(const std::string& animationName, float elapsed);
+
+ /**
* @brief Sets the shape fill color of given fill name.
*
* @param[in] fillName The fill name
// Render Rive Frame
frameNumber = mStartFrameNumber + frameNumber;
- double elapsed = (float)frameNumber / 60.0f;
- for (auto& animation : mAnimations)
+ //FIXME: This should be changed to the time based rendering
+ static float elapsed = 0.0f;
+ elapsed = 1.0f / 60.0f;
+
+ for(auto& animation : mAnimations)
{
- if(animation.enable)
+ if(animation.instance)
{
- animation.instance->time(elapsed);
- animation.instance->advance(0.0);
- animation.instance->apply(mArtboard);
+ if(animation.enable)
+ {
+ animation.instance->advance(elapsed);
+ animation.instance->apply(mArtboard);
+ }
+ else if(animation.elapsed >= 0.0f)
+ {
+ animation.instance->time(animation.elapsed);
+ animation.instance->apply(mArtboard);
+ }
}
}
- mArtboard->advance(0.0);
+ mArtboard->advance(elapsed);
rive::TvgRenderer renderer(mSwCanvas.get());
renderer.save();
{
Dali::Mutex::ScopedLock lock(mMutex);
- for(auto& animation : mAnimations)
+ for(unsigned int i = 0; i < mAnimations.size(); i++)
+ {
+ if(mAnimations[i].name == animationName)
+ {
+ if(mAnimations[i].instance)
+ {
+ auto animation = mArtboard->animation(i);
+ mAnimations[i].instance.reset(new rive::LinearAnimationInstance(animation));
+ }
+ mAnimations[i].enable = enable;
+ return;
+ }
+ }
+}
+
+void RiveAnimationRenderer::SetAnimationElapsedTime(const std::string& animationName, float elapsed)
+{
+ Dali::Mutex::ScopedLock lock(mMutex);
+
+ for(auto& animation : mAnimations)
{
if(animation.name == animationName)
{
- animation.enable = enable;
+ animation.elapsed = elapsed;
return;
}
}
void EnableAnimation(const std::string& animationName, bool enable);
/**
+ * @brief Sets the animation elapsed time.
+ *
+ * @param[in] animationName The animation name
+ * @param[in] time The animation elapsed time (in second)
+ */
+ void SetAnimationElapsedTime(const std::string& animationName, float elapsed);
+
+ /**
* @brief Sets the shape fill color of given fill name.
*
* @param[in] fillName The fill name
Animation(rive::LinearAnimationInstance *animationInstance, const std::string& animationName, bool animationEnable)
: instance(animationInstance),
name(animationName),
- enable(animationEnable)
+ enable(animationEnable),
+ elapsed(-1.0f)
{
}
std::unique_ptr<rive::LinearAnimationInstance> instance;
const std::string& name;
bool enable;
+ float elapsed;
};
/**
mVectorRenderer->EnableAnimation(animationName, enable);
}
+void RiveAnimationTask::SetAnimationElapsedTime(const std::string& animationName, float elapsed)
+{
+ mVectorRenderer->SetAnimationElapsedTime(animationName, elapsed);
+}
+
void RiveAnimationTask::SetShapeFillColor(const std::string& fillName, Vector4 color)
{
mVectorRenderer->SetShapeFillColor(fillName, color);
if(currentFrame >= mEndFrame) // last frame
{
- animationFinished = true; // end of animation
+ //FIXME: Rive animation can have more than two animations,
+ //so This is not suitable for rive animation.
+ //The animation finish policy should be changed.
+ //animationFinished = true; // end of animation
+ mCurrentFrame = mStartFrame;
}
if(animationFinished)
}
}
+ if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_ANIMATION_ELAPSED_TIME)
+ {
+ for(auto& elapsedTime : mAnimationData[index].elapsedTimes)
+ {
+ SetAnimationElapsedTime(elapsedTime.first, elapsedTime.second);
+ }
+ }
+
if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_FILL_COLOR)
{
for(auto& fillColor : mAnimationData[index].fillColors)
*/
enum ResendFlags
{
- RESEND_PLAY_RANGE = 1 << 0,
- RESEND_LOOP_COUNT = 1 << 1,
- RESEND_STOP_BEHAVIOR = 1 << 2,
- RESEND_LOOPING_MODE = 1 << 3,
- RESEND_CURRENT_FRAME = 1 << 4,
- RESEND_SIZE = 1 << 5,
- RESEND_PLAY_STATE = 1 << 6,
- RESEND_ENABLE_ANIMATION = 1 << 7,
- RESEND_FILL_COLOR = 1 << 8,
- RESEND_STROKE_COLOR = 1 << 9,
- RESEND_OPACITY = 1 << 10,
- RESEND_SCALE = 1 << 11,
- RESEND_ROTATION = 1 << 12,
- RESEND_POSITION = 1 << 13,
+ RESEND_PLAY_RANGE = 1 << 0,
+ RESEND_LOOP_COUNT = 1 << 1,
+ RESEND_STOP_BEHAVIOR = 1 << 2,
+ RESEND_LOOPING_MODE = 1 << 3,
+ RESEND_CURRENT_FRAME = 1 << 4,
+ RESEND_SIZE = 1 << 5,
+ RESEND_PLAY_STATE = 1 << 6,
+ RESEND_ENABLE_ANIMATION = 1 << 7,
+ RESEND_ANIMATION_ELAPSED_TIME = 1 << 8,
+ RESEND_FILL_COLOR = 1 << 9,
+ RESEND_STROKE_COLOR = 1 << 10,
+ RESEND_OPACITY = 1 << 11,
+ RESEND_SCALE = 1 << 12,
+ RESEND_ROTATION = 1 << 13,
+ RESEND_POSITION = 1 << 14
};
/**
playState = rhs.playState;
animations.resize(rhs.animations.size());
std::copy(rhs.animations.begin(), rhs.animations.end(), animations.begin());
+ elapsedTimes.resize(rhs.elapsedTimes.size());
+ std::copy(rhs.elapsedTimes.begin(), rhs.elapsedTimes.end(), elapsedTimes.begin());
fillColors.resize(rhs.fillColors.size());
std::copy(rhs.fillColors.begin(), rhs.fillColors.end(), fillColors.begin());
strokeColors.resize(rhs.strokeColors.size());
uint32_t height;
Extension::RiveAnimationView::PlayState playState;
std::vector<std::pair<std::string, bool>> animations;
+ std::vector<std::pair<std::string, float>> elapsedTimes;
std::vector<std::pair<std::string, Vector4>> fillColors;
std::vector<std::pair<std::string, Vector4>> strokeColors;
std::vector<std::pair<std::string, float>> opacities;
void EnableAnimation(const std::string& animationName, bool enable);
/**
+ * @brief Sets the animation elapsed time.
+ *
+ * @param[in] animationName The animation name
+ * @param[in] time The animation elapsed time (in second)
+ */
+ void SetAnimationElapsedTime(const std::string& animationName, float elapsed);
+
+ /**
* @brief Sets the shape fill color of given fill name.
*
* @param[in] fillName The fill name
TriggerVectorRasterization();
}
+void RiveAnimationView::SetAnimationElapsedTime(const std::string& animationName, float elapsed)
+{
+ mAnimationData.elapsedTimes.push_back(std::pair<std::string, float>(animationName, elapsed));
+ mAnimationData.resendFlag |= RiveAnimationTask::RESEND_ANIMATION_ELAPSED_TIME;
+
+ TriggerVectorRasterization();
+}
+
void RiveAnimationView::SetShapeFillColor(const std::string& fillName, Vector4 color)
{
mAnimationData.fillColors.push_back(std::pair<std::string, Vector4>(fillName, color));
void RiveAnimationView::ClearAnimationsData()
{
mAnimationData.animations.clear();
+ mAnimationData.elapsedTimes.clear();
mAnimationData.fillColors.clear();
mAnimationData.strokeColors.clear();
mAnimationData.opacities.clear();
void EnableAnimation(const std::string& animationName, bool enable);
/**
+ * @copydoc Dali::Extension::RiveAnimationView::SetAnimationElapsedTime
+ */
+ void SetAnimationElapsedTime(const std::string& animationName, float elapsed);
+
+ /**
* @copydoc Dali::Extension::RiveAnimationView::SetShapeFillColor
*/
void SetShapeFillColor(const std::string& fillName, Vector4 color);