RiveAnimationView: add more APIs for setting animation and modifying path and node... 51/260151/11
authorTaehyub Kim <taehyub.kim@samsung.com>
Mon, 21 Jun 2021 09:07:12 +0000 (18:07 +0900)
committerTaehyub Kim <taehyub.kim@samsung.com>
Mon, 5 Jul 2021 08:16:52 +0000 (17:16 +0900)
Change-Id: Iae9c03faa7214c514cd27b46eb296366ef3dca87

dali-extension/devel-api/rive-animation-view/rive-animation-view.cpp
dali-extension/devel-api/rive-animation-view/rive-animation-view.h
dali-extension/internal/rive-animation-view/animation-renderer/rive-animation-renderer.cpp
dali-extension/internal/rive-animation-view/animation-renderer/rive-animation-renderer.h
dali-extension/internal/rive-animation-view/rive-animation-task.cpp
dali-extension/internal/rive-animation-view/rive-animation-task.h
dali-extension/internal/rive-animation-view/rive-animation-view-impl.cpp
dali-extension/internal/rive-animation-view/rive-animation-view-impl.h

index 508b8c5..a8cf0c4 100644 (file)
@@ -88,6 +88,41 @@ void RiveAnimationView::PauseAnimation()
   Extension::GetImplementation(*this).PauseAnimation();
 }
 
+void RiveAnimationView::EnableAnimation(const std::string& animationName, bool enable)
+{
+  Extension::GetImplementation(*this).EnableAnimation(animationName, enable);
+}
+
+void RiveAnimationView::SetShapeFillColor(const std::string& fillName, Vector4 color)
+{
+  Extension::GetImplementation(*this).SetShapeFillColor(fillName, color);
+}
+
+void RiveAnimationView::SetShapeStrokeColor(const std::string& strokeName, Vector4 color)
+{
+  Extension::GetImplementation(*this).SetShapeStrokeColor(strokeName, color);
+}
+
+void RiveAnimationView::SetNodeOpacity(const std::string& nodeName, float opacity)
+{
+  Extension::GetImplementation(*this).SetNodeOpacity(nodeName, opacity);
+}
+
+void RiveAnimationView::SetNodeScale(const std::string& nodeName, Vector2 scale)
+{
+  Extension::GetImplementation(*this).SetNodeScale(nodeName, scale);
+}
+
+void RiveAnimationView::SetNodeRotation(const std::string& nodeName, Degree degree)
+{
+  Extension::GetImplementation(*this).SetNodeRotation(nodeName, degree);
+}
+
+void RiveAnimationView::SetNodePosition(const std::string& nodeName, Vector2 position)
+{
+  Extension::GetImplementation(*this).SetNodePosition(nodeName, position);
+}
+
 RiveAnimationView::AnimationSignalType& RiveAnimationView::AnimationFinishedSignal()
 {
   return Extension::GetImplementation(*this).AnimationFinishedSignal();
index d52077f..f0bf489 100644 (file)
@@ -172,6 +172,62 @@ public:
   void PauseAnimation();
 
   /**
+   * @brief Enables the animation state of given animation.
+   *
+   * @param[in] animationName The animation name
+   * @param[in] enable The state of animation
+   */
+  void EnableAnimation(const std::string& animationName, bool enable);
+
+  /**
+   * @brief Sets the shape fill color of given fill name.
+   *
+   * @param[in] fillName The fill name
+   * @param[in] color The rgba color
+   */
+  void SetShapeFillColor(const std::string& fillName, Vector4 color);
+
+  /**
+   * @brief Sets the shape stroke color of given stroke name.
+   *
+   * @param[in] strokeName The stroke name
+   * @param[in] color The rgba color
+   */
+  void SetShapeStrokeColor(const std::string& strokeName, Vector4 color);
+
+  /**
+   * @brief Sets the opacity of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] opacity The opacity of given node
+   */
+  void SetNodeOpacity(const std::string& nodeName, float opacity);
+
+  /**
+   * @brief Sets the scale of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] scale The scale of given node
+   */
+  void SetNodeScale(const std::string& nodeName, Vector2 scale);
+
+  /**
+   * @brief Sets the rotation of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] degree The degree of given node
+   */
+  void SetNodeRotation(const std::string& nodeName, Degree degree);
+
+  /**
+   * @brief Sets the position of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] position The position of given node
+   */
+  void SetNodePosition(const std::string& nodeName, Vector2 position);
+
+  /**
    * @brief Connects to this signal to be notified when animations have finished.
    *
    * @return A signal object to connect with
index 0e841d0..0d9904c 100644 (file)
 #include <time.h>
 #include <cmath>
 #include <cstring> // for strlen()
+#include <rive/node.hpp>
 #include <rive/file.hpp>
 #include <rive/tvg_renderer.hpp>
+#include <rive/shapes/paint/fill.hpp>
+#include <rive/shapes/paint/stroke.hpp>
+#include <rive/shapes/paint/color.hpp>
+#include <rive/shapes/paint/solid_color.hpp>
 
 // INTERNAL INCLUDES
 #include <dali-extension/internal/rive-animation-view/animation-renderer/rive-animation-renderer-manager.h>
@@ -65,7 +70,6 @@ RiveAnimationRenderer::RiveAnimationRenderer()
   mFile(nullptr),
   mArtboard(nullptr),
   mAnimation(nullptr),
-  mAnimationInstance(nullptr),
   mStartFrameNumber(0),
   mTotalFrameNumber(0),
   mWidth(0),
@@ -84,10 +88,7 @@ RiveAnimationRenderer::~RiveAnimationRenderer()
 {
   Dali::Mutex::ScopedLock lock(mMutex);
 
-  if(mAnimationInstance)
-  {
-    delete mAnimationInstance;
-  }
+  ClearRiveAnimations();
 
   if(mFile)
   {
@@ -100,6 +101,11 @@ RiveAnimationRenderer::~RiveAnimationRenderer()
   DALI_LOG_INFO(gRiveAnimationLogFilter, Debug::Verbose, "RiveAnimationRenderer::~RiveAnimationRenderer: this = %p\n", this);
 }
 
+void RiveAnimationRenderer::ClearRiveAnimations()
+{
+  mAnimations.clear();
+}
+
 void RiveAnimationRenderer::LoadRiveFile(const std::string& filename)
 {
   std::streampos        length = 0;
@@ -128,16 +134,18 @@ void RiveAnimationRenderer::LoadRiveFile(const std::string& filename)
   mArtboard = mFile->artboard();
   mArtboard->advance(0.0f);
 
-  if(mAnimationInstance)
+  ClearRiveAnimations();
+
+  for(unsigned int i = 0; i < mArtboard->animationCount(); i++)
   {
-    delete mAnimationInstance;
-    mAnimationInstance = nullptr;
+    auto animation = mArtboard->animation(i);
+    const std::string& name = animation->name();
+    mAnimations.emplace_back(Animation(new rive::LinearAnimationInstance(animation), name, false));
   }
 
   mAnimation = mArtboard->firstAnimation();
   if(mAnimation)
   {
-    mAnimationInstance = new rive::LinearAnimationInstance(mAnimation);
     mStartFrameNumber = mAnimation->enableWorkArea() ? mAnimation->workStart() : 0;
     mTotalFrameNumber = mAnimation->enableWorkArea() ? mAnimation->workEnd() : mAnimation->duration();
     mTotalFrameNumber -= mStartFrameNumber;
@@ -229,7 +237,7 @@ void RiveAnimationRenderer::SetSize(uint32_t width, uint32_t height)
 bool RiveAnimationRenderer::Render(uint32_t frameNumber)
 {
   Dali::Mutex::ScopedLock lock(mMutex);
-  if(!mTbmQueue || !mTargetSurface || !mArtboard || !mAnimationInstance)
+  if(!mTbmQueue || !mTargetSurface || !mArtboard || mAnimations.empty())
   {
     return false;
   }
@@ -289,10 +297,15 @@ bool RiveAnimationRenderer::Render(uint32_t frameNumber)
   frameNumber    = mStartFrameNumber + frameNumber;
   double elapsed = (float)frameNumber / 60.0f;
 
-  mAnimationInstance->time(elapsed);
-  mAnimationInstance->advance(0.0);
-  mAnimationInstance->apply(mArtboard);
-
+  for (auto& animation : mAnimations)
+  {
+    if(animation.enable)
+    {
+      animation.instance->time(elapsed);
+      animation.instance->advance(0.0);
+      animation.instance->apply(mArtboard);
+    }
+  }
   mArtboard->advance(0.0);
 
   rive::TvgRenderer renderer(mSwCanvas.get());
@@ -350,6 +363,97 @@ void RiveAnimationRenderer::GetDefaultSize(uint32_t& width, uint32_t& height) co
   height = mDefaultHeight;
 }
 
+void RiveAnimationRenderer::EnableAnimation(const std::string& animationName, bool enable)
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+
+  for(auto& animation :  mAnimations)
+  {
+    if(animation.name == animationName)
+    {
+      animation.enable = enable;
+      return;
+    }
+  }
+}
+
+void RiveAnimationRenderer::SetShapeFillColor(const std::string& fillName, Vector4 color)
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+
+  auto colorInstance = mArtboard->find<rive::Fill>(fillName.c_str());
+  if(!colorInstance)
+  {
+    return;
+  }
+  colorInstance->paint()->as<rive::SolidColor>()->colorValue(rive::colorARGB(color.a, color.r, color.g, color.b));
+}
+
+void RiveAnimationRenderer::SetShapeStrokeColor(const std::string& strokeName, Vector4 color)
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+
+  auto colorInstance = mArtboard->find<rive::Stroke>(strokeName.c_str());
+  if(!colorInstance)
+  {
+    return;
+  }
+  colorInstance->paint()->as<rive::SolidColor>()->colorValue(rive::colorARGB(color.a, color.r, color.g, color.b));
+}
+
+void RiveAnimationRenderer::SetNodeOpacity(const std::string& nodeName, float opacity)
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+
+  auto node = mArtboard->find(nodeName.c_str());
+  if(!node)
+  {
+    return;
+  }
+  auto nodeInstance = node->as<rive::Node>();
+  nodeInstance->opacity(opacity);
+}
+
+void RiveAnimationRenderer::SetNodeScale(const std::string& nodeName, Vector2 scale)
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+
+  auto node = mArtboard->find(nodeName.c_str());
+  if(!node)
+  {
+    return;
+  }
+  auto nodeInstance = node->as<rive::Node>();
+  nodeInstance->scaleX(scale.x);
+  nodeInstance->scaleY(scale.y);
+}
+
+void RiveAnimationRenderer::SetNodeRotation(const std::string& nodeName, Degree degree)
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+  auto node = mArtboard->find(nodeName.c_str());
+  if(!node)
+  {
+    return;
+  }
+  auto nodeInstance = node->as<rive::Node>();
+  nodeInstance->rotation(degree.degree);
+}
+
+void RiveAnimationRenderer::SetNodePosition(const std::string& nodeName, Vector2 position)
+{
+  Dali::Mutex::ScopedLock lock(mMutex);
+
+  auto node = mArtboard->find(nodeName.c_str());
+  if(!node)
+  {
+    return;
+  }
+  auto nodeInstance = node->as<rive::Node>();
+  nodeInstance->x(position.x);
+  nodeInstance->y(position.y);
+}
+
 void RiveAnimationRenderer::IgnoreRenderedFrame()
 {
   Dali::Mutex::ScopedLock lock(mMutex);
index 98225af..05ae829 100755 (executable)
@@ -125,6 +125,62 @@ public:
   void GetDefaultSize(uint32_t& width, uint32_t& height) const;
 
   /**
+   * @brief Enables the animation state of given rive animation.
+   *
+   * @param[in] animationName The animation name
+   * @param[in] enable The state of animation
+   */
+  void EnableAnimation(const std::string& animationName, bool enable);
+
+  /**
+   * @brief Sets the shape fill color of given fill name.
+   *
+   * @param[in] fillName The fill name
+   * @param[in] color The rgba color
+   */
+  void SetShapeFillColor(const std::string& fillName, Vector4 color);
+
+  /**
+   * @brief Sets the shape stroke color of given stroke name.
+   *
+   * @param[in] strokeName The stroke name
+   * @param[in] color The rgba color
+   */
+  void SetShapeStrokeColor(const std::string& strokeName, Vector4 color);
+
+  /**
+   * @brief Sets the opacity of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] opacity The opacity of given node
+   */
+  void SetNodeOpacity(const std::string& nodeName, float opacity);
+
+  /**
+   * @brief Sets the scale of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] scale The scale of given node
+   */
+  void SetNodeScale(const std::string& nodeName, Vector2 scale);
+
+  /**
+   * @brief Sets the rotation of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] degree The degree of given node
+   */
+  void SetNodeRotation(const std::string& nodeName, Degree degree);
+
+  /**
+   * @brief Sets the position of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] position The position of given node
+   */
+  void SetNodePosition(const std::string& nodeName, Vector2 position);
+
+  /**
    * @brief Ignores a rendered frame which is not shown yet.
    */
   void IgnoreRenderedFrame();
@@ -146,6 +202,23 @@ protected: // Implementation of RiveAnimationRendererEventHandler
 private:
 
   /**
+   * @brief Structure used to manage rive animations.
+   */
+  struct Animation
+  {
+  public:
+     Animation(rive::LinearAnimationInstance *animationInstance, const std::string& animationName, bool animationEnable)
+     : instance(animationInstance),
+       name(animationName),
+       enable(animationEnable)
+     {
+     }
+     std::unique_ptr<rive::LinearAnimationInstance> instance;
+     const std::string& name;
+     bool enable;
+  };
+
+  /**
    * @brief Set shader for NativeImageSourceQueue with custom sampler type and prefix.
    */
   void SetShader();
@@ -160,6 +233,11 @@ private:
    */
   void LoadRiveFile(const std::string& filename);
 
+  /**
+   * @brief Clear Loaded Animations.
+   */
+  void ClearRiveAnimations();
+
 private:
 
   std::string                            mUrl;                   ///< The content file path
@@ -174,8 +252,8 @@ private:
   std::unique_ptr<tvg::SwCanvas>         mSwCanvas;              ///< ThorVG SW canvas handle
   rive::File                             *mFile;                 ///< Rive file handle
   rive::Artboard                         *mArtboard;             ///< Rive artboard handle
+  std::vector<Animation>                 mAnimations;            ///< Rive animations
   rive::LinearAnimation                  *mAnimation;            ///< Rive animation handle
-  rive::LinearAnimationInstance          *mAnimationInstance;    ///< Rive animation instance
   uint32_t                               mStartFrameNumber;      ///< The start frame number
   uint32_t                               mTotalFrameNumber;      ///< The total frame number
   uint32_t                               mWidth;                 ///< The width of the surface
index eec39f8..b3a87ff 100644 (file)
@@ -190,6 +190,41 @@ void RiveAnimationTask::PauseAnimation()
   }
 }
 
+void RiveAnimationTask::EnableAnimation(const std::string& animationName, bool enable)
+{
+  mVectorRenderer->EnableAnimation(animationName, enable);
+}
+
+void RiveAnimationTask::SetShapeFillColor(const std::string& fillName, Vector4 color)
+{
+  mVectorRenderer->SetShapeFillColor(fillName, color);
+}
+
+void RiveAnimationTask::SetShapeStrokeColor(const std::string& strokeName, Vector4 color)
+{
+  mVectorRenderer->SetShapeStrokeColor(strokeName, color);
+}
+
+void RiveAnimationTask::SetNodeOpacity(const std::string& nodeName, float opacity)
+{
+  mVectorRenderer->SetNodeOpacity(nodeName, opacity);
+}
+
+void RiveAnimationTask::SetNodeScale(const std::string& nodeName, Vector2 scale)
+{
+  mVectorRenderer->SetNodeScale(nodeName, scale);
+}
+
+void RiveAnimationTask::SetNodeRotation(const std::string& nodeName, Degree degree)
+{
+  mVectorRenderer->SetNodeRotation(nodeName, degree);
+}
+
+void RiveAnimationTask::SetNodePosition(const std::string& nodeName, Vector2 position)
+{
+  mVectorRenderer->SetNodePosition(nodeName, position);
+}
+
 void RiveAnimationTask::SetAnimationFinishedCallback(EventThreadCallback* callback)
 {
   ConditionalWait::ScopedLock lock(mConditionalWait);
@@ -362,6 +397,62 @@ void RiveAnimationTask::ApplyAnimationData()
     }
   }
 
+  if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_ENABLE_ANIMATION)
+  {
+    for(auto& animation : mAnimationData[index].animations)
+    {
+      EnableAnimation(animation.first, animation.second);
+    }
+  }
+
+  if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_FILL_COLOR)
+  {
+    for(auto& fillColor : mAnimationData[index].fillColors)
+    {
+      SetShapeFillColor(fillColor.first, fillColor.second);
+    }
+  }
+
+  if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_STROKE_COLOR)
+  {
+    for(auto& strokeColor : mAnimationData[index].strokeColors)
+    {
+      SetShapeStrokeColor(strokeColor.first, strokeColor.second);
+    }
+  }
+
+  if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_OPACITY)
+  {
+    for(auto& opacity : mAnimationData[index].opacities)
+    {
+      SetNodeOpacity(opacity.first, opacity.second);
+    }
+  }
+
+  if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_SCALE)
+  {
+    for(auto& scale : mAnimationData[index].scales)
+    {
+      SetNodeScale(scale.first, scale.second);
+    }
+  }
+
+  if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_ROTATION)
+  {
+    for(auto& rotation : mAnimationData[index].rotations)
+    {
+      SetNodeRotation(rotation.first, rotation.second);
+    }
+  }
+
+  if(mAnimationData[index].resendFlag & RiveAnimationTask::RESEND_POSITION)
+  {
+    for(auto& position : mAnimationData[index].positions)
+    {
+      SetNodePosition(position.first, position.second);
+    }
+  }
+
   mAnimationData[index].resendFlag = 0;
 }
 
index 0098b98..0181e38 100644 (file)
@@ -53,13 +53,20 @@ public:
    */
   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_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,
   };
 
   /**
@@ -69,26 +76,48 @@ public:
   {
     AnimationData()
     : resendFlag(0),
-      playState(),
       width(0),
-      height(0)
+      height(0),
+      playState()
     {
     }
 
     AnimationData& operator=(const AnimationData& rhs)
     {
-      resendFlag |= rhs.resendFlag; // OR resend flag
-      playState    = rhs.playState;
-      width        = rhs.width;
-      height       = rhs.height;
+      resendFlag     |= rhs.resendFlag; // OR resend flag
+      width           = rhs.width;
+      height          = rhs.height;
+      playState       = rhs.playState;
+      animations.resize(rhs.animations.size());
+      std::copy(rhs.animations.begin(), rhs.animations.end(), animations.begin());
+      fillColors.resize(rhs.fillColors.size());
+      std::copy(rhs.fillColors.begin(), rhs.fillColors.end(), fillColors.begin());
+      strokeColors.resize(rhs.strokeColors.size());
+      std::copy(rhs.strokeColors.begin(), rhs.strokeColors.end(), strokeColors.begin());
+      opacities.resize(rhs.opacities.size());
+      std::copy(rhs.opacities.begin(), rhs.opacities.end(), opacities.begin());
+      scales.resize(rhs.scales.size());
+      std::copy(rhs.scales.begin(), rhs.scales.end(), scales.begin());
+      rotations.resize(rhs.rotations.size());
+      std::copy(rhs.rotations.begin(), rhs.rotations.end(), rotations.begin());
+      positions.resize(rhs.positions.size());
+      std::copy(rhs.positions.begin(), rhs.positions.end(), positions.begin());
+
       return *this;
     }
 
-    uint32_t                                   resendFlag;
-    Extension::RiveAnimationView::PlayState    playState;
-    uint32_t                                   width;
-    uint32_t                                   height;
-  };
+    uint32_t                                      resendFlag;
+    uint32_t                                      width;
+    uint32_t                                      height;
+    Extension::RiveAnimationView::PlayState       playState;
+    std::vector<std::pair<std::string, bool>>     animations;
+    std::vector<std::pair<std::string, Vector4>>  fillColors;
+    std::vector<std::pair<std::string, Vector4>>  strokeColors;
+    std::vector<std::pair<std::string, float>>    opacities;
+    std::vector<std::pair<std::string, Vector2>>  scales;
+    std::vector<std::pair<std::string, Degree>>   rotations;
+    std::vector<std::pair<std::string, Vector2>>  positions;
+    };
 
   /**
    * @brief Constructor.
@@ -179,6 +208,62 @@ private:
   void PauseAnimation();
 
   /**
+   * @brief Enables the animation state of given rive animation.
+   *
+   * @param[in] animationName The animation name
+   * @param[in] enable The state of animation
+   */
+  void EnableAnimation(const std::string& animationName, bool enable);
+
+  /**
+   * @brief Sets the shape fill color of given fill name.
+   *
+   * @param[in] fillName The fill name
+   * @param[in] color The rgba color
+   */
+  void SetShapeFillColor(const std::string& fillName, Vector4 color);
+
+  /**
+   * @brief Sets the shape stroke color of given stroke name.
+   *
+   * @param[in] strokeName The stroke name
+   * @param[in] color The rgba color
+   */
+  void SetShapeStrokeColor(const std::string& strokeName, Vector4 color);
+
+  /**
+   * @brief Sets the opacity of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] opacity The opacity of given node
+   */
+  void SetNodeOpacity(const std::string& nodeName, float opacity);
+
+  /**
+   * @brief Sets the scale of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] scale The scale of given node
+   */
+  void SetNodeScale(const std::string& nodeName, Vector2 scale);
+
+  /**
+   * @brief Sets the rotation of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] degree The degree of given node
+   */
+  void SetNodeRotation(const std::string& nodeName, Degree degree);
+
+  /**
+   * @brief Sets the position of given node.
+   *
+   * @param[in] nodeName The node name
+   * @param[in] position The position of given node
+   */
+  void SetNodePosition(const std::string& nodeName, Vector2 position);
+
+  /**
    * @brief Sets the target image size.
    *
    * @param[in] width The target image width
index 86db74d..c9da73d 100644 (file)
@@ -355,6 +355,62 @@ void RiveAnimationView::PauseAnimation()
   TriggerVectorRasterization();
 }
 
+void RiveAnimationView::EnableAnimation(const std::string& animationName, bool enable)
+{
+  mAnimationData.animations.push_back(std::pair<std::string, bool>(animationName, enable));
+  mAnimationData.resendFlag |= RiveAnimationTask::RESEND_ENABLE_ANIMATION;
+
+  TriggerVectorRasterization();
+}
+
+void RiveAnimationView::SetShapeFillColor(const std::string& fillName, Vector4 color)
+{
+  mAnimationData.fillColors.push_back(std::pair<std::string, Vector4>(fillName, color));
+  mAnimationData.resendFlag |= RiveAnimationTask::RESEND_FILL_COLOR;
+
+  TriggerVectorRasterization();
+}
+
+void RiveAnimationView::SetShapeStrokeColor(const std::string& strokeName, Vector4 color)
+{
+  mAnimationData.strokeColors.push_back(std::pair<std::string, Vector4>(strokeName, color));
+  mAnimationData.resendFlag |= RiveAnimationTask::RESEND_STROKE_COLOR;
+
+  TriggerVectorRasterization();
+}
+
+void RiveAnimationView::SetNodeOpacity(const std::string& nodeName, float opacity)
+{
+  mAnimationData.opacities.push_back(std::pair<std::string, float>(nodeName, opacity));
+  mAnimationData.resendFlag |= RiveAnimationTask::RESEND_OPACITY;
+
+  TriggerVectorRasterization();
+}
+
+void RiveAnimationView::SetNodeScale(const std::string& nodeName, Vector2 scale)
+{
+  mAnimationData.scales.push_back(std::pair<std::string, Vector2>(nodeName, scale));
+  mAnimationData.resendFlag |= RiveAnimationTask::RESEND_SCALE;
+
+  TriggerVectorRasterization();
+}
+
+void RiveAnimationView::SetNodeRotation(const std::string& nodeName, Degree degree)
+{
+  mAnimationData.rotations.push_back(std::pair<std::string, Degree>(nodeName, degree));
+  mAnimationData.resendFlag |= RiveAnimationTask::RESEND_ROTATION;
+
+  TriggerVectorRasterization();
+}
+
+void RiveAnimationView::SetNodePosition(const std::string& nodeName, Vector2 position)
+{
+  mAnimationData.positions.push_back(std::pair<std::string, Vector2>(nodeName, position));
+  mAnimationData.resendFlag |= RiveAnimationTask::RESEND_POSITION;
+
+  TriggerVectorRasterization();
+}
+
 Dali::Extension::RiveAnimationView::AnimationSignalType& RiveAnimationView::AnimationFinishedSignal()
 {
   return mFinishedSignal;
@@ -432,6 +488,7 @@ void RiveAnimationView::SendAnimationData()
   if(mAnimationData.resendFlag)
   {
     mRiveAnimationTask->SetAnimationData(mAnimationData);
+    ClearAnimationsData();
 
     if(mRenderer)
     {
@@ -449,6 +506,17 @@ void RiveAnimationView::SendAnimationData()
   }
 }
 
+void RiveAnimationView::ClearAnimationsData()
+{
+    mAnimationData.animations.clear();
+    mAnimationData.fillColors.clear();
+    mAnimationData.strokeColors.clear();
+    mAnimationData.opacities.clear();
+    mAnimationData.scales.clear();
+    mAnimationData.rotations.clear();
+    mAnimationData.positions.clear();
+}
+
 void RiveAnimationView::SetVectorImageSize()
 {
   uint32_t width  = static_cast<uint32_t>(mSize.width * mScale.width);
index 2ee61a7..557b313 100644 (file)
@@ -74,6 +74,41 @@ public:
   void PauseAnimation();
 
   /**
+   * @copydoc Dali::Extension::RiveAnimationView::EnableAnimation
+   */
+  void EnableAnimation(const std::string& animationName, bool enable);
+
+  /**
+   * @copydoc Dali::Extension::RiveAnimationView::SetShapeFillColor
+   */
+  void SetShapeFillColor(const std::string& fillName, Vector4 color);
+
+  /**
+   * @copydoc Dali::Extension::RiveAnimationView::SetShapeStrokeColor
+   */
+  void SetShapeStrokeColor(const std::string& strokeName, Vector4 color);
+
+  /**
+   * @copydoc Dali::Extension::RiveAnimationView::SetNodeOpacity
+   */
+  void SetNodeOpacity(const std::string& nodeName, float opacity);
+
+  /**
+   * @copydoc Dali::Extension::RiveAnimationView::SetNodeScale
+   */
+  void SetNodeScale(const std::string& nodeName, Vector2 scale);
+
+  /**
+   * @copydoc Dali::Extension::RiveAnimationView::SetNodeRotation
+   */
+  void SetNodeRotation(const std::string& nodeName, Degree degree);
+
+  /**
+   * @copydoc Dali::Extension::RiveAnimationView::SetNodePosition
+   */
+  void SetNodePosition(const std::string& nodeName, Vector2 position);
+
+  /**
    * @copydoc Dali::Extension::RiveAnimationView::AnimationFinishedSignal
    */
   Dali::Extension::RiveAnimationView::AnimationSignalType& AnimationFinishedSignal();
@@ -152,6 +187,11 @@ private:
   void SendAnimationData();
 
   /**
+   * @brief Clear animations data.
+   */
+  void ClearAnimationsData();
+
+  /**
    * @brief Set the vector image size.
    */
   void SetVectorImageSize();