Merge "Move ModelUpdating method outside of Text::Controller::Impl class to reduce...
authorAdeel Kazmi <adeel.kazmi@samsung.com>
Fri, 5 Nov 2021 09:57:57 +0000 (09:57 +0000)
committerGerrit Code Review <gerrit@review>
Fri, 5 Nov 2021 09:57:57 +0000 (09:57 +0000)
dali-toolkit/internal/visuals/text/text-visual.cpp
dali-toolkit/internal/visuals/text/text-visual.h

index 19ecb5c..a4903c5 100644 (file)
@@ -23,7 +23,6 @@
 #include <dali/devel-api/images/pixel-data-devel.h>
 #include <dali/devel-api/rendering/renderer-devel.h>
 #include <dali/devel-api/text-abstraction/text-abstraction-definitions.h>
-#include <dali/public-api/animation/constraints.h>
 #include <string.h>
 
 // INTERNAL HEADER
@@ -240,6 +239,7 @@ TextVisual::TextVisual(VisualFactoryCache& factoryCache)
   mController(Text::Controller::New()),
   mTypesetter(Text::Typesetter::New(mController->GetTextModel())),
   mAnimatableTextColorPropertyIndex(Property::INVALID_INDEX),
+  mTextColorAnimatableIndex(Property::INVALID_INDEX),
   mRendererUpdateNeeded(false)
 {
 }
@@ -291,23 +291,36 @@ void TextVisual::DoSetOnScene(Actor& actor)
   // Enable the pre-multiplied alpha to improve the text quality
   EnablePreMultipliedAlpha(true);
 
-  const Vector4&        defaultColor         = mController->GetTextModel()->GetDefaultColor();
-  Dali::Property::Index shaderTextColorIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor);
+  const Vector4& defaultColor = mController->GetTextModel()->GetDefaultColor();
+  if(mTextColorAnimatableIndex == Property::INVALID_INDEX)
+  {
+    mTextColorAnimatableIndex = mImpl->mRenderer.RegisterProperty("uTextColorAnimatable", defaultColor);
+  }
+  else
+  {
+    mImpl->mRenderer.SetProperty(mTextColorAnimatableIndex, defaultColor);
+  }
 
   if(mAnimatableTextColorPropertyIndex != Property::INVALID_INDEX)
   {
     // Create constraint for the animatable text's color Property with uTextColorAnimatable in the renderer.
-    if(shaderTextColorIndex != Property::INVALID_INDEX)
+    if(mTextColorAnimatableIndex != Property::INVALID_INDEX)
     {
-      Constraint colorConstraint = Constraint::New<Vector4>(mImpl->mRenderer, shaderTextColorIndex, TextColorConstraint);
-      colorConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex));
-      colorConstraint.Apply();
-
-      // Make zero if the alpha value of text color is zero to skip rendering text
-      Constraint opacityConstraint = Constraint::New<float>(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint);
-      opacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex));
-      opacityConstraint.Apply();
+      if(!mColorConstraint)
+      {
+        mColorConstraint = Constraint::New<Vector4>(mImpl->mRenderer, mTextColorAnimatableIndex, TextColorConstraint);
+        mColorConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex));
+      }
+      mColorConstraint.Apply();
     }
+
+    // Make zero if the alpha value of text color is zero to skip rendering text
+    if(!mOpacityConstraint)
+    {
+      mOpacityConstraint = Constraint::New<float>(mImpl->mRenderer, Dali::DevelRenderer::Property::OPACITY, OpacityConstraint);
+      mOpacityConstraint.AddSource(Source(actor, mAnimatableTextColorPropertyIndex));
+    }
+    mOpacityConstraint.Apply();
   }
 
   // Renderer needs textures and to be added to control
@@ -335,6 +348,15 @@ void TextVisual::RemoveRenderer(Actor& actor)
 
 void TextVisual::DoSetOffScene(Actor& actor)
 {
+  if(mColorConstraint)
+  {
+    mColorConstraint.Remove();
+  }
+  if(mOpacityConstraint)
+  {
+    mOpacityConstraint.Remove();
+  }
+
   RemoveRenderer(actor);
 
   // Resets the control handle.
index 7ae5e4e..f9d6c79 100644 (file)
@@ -19,6 +19,7 @@
  */
 
 // EXTERNAL INCLUDES
+#include <dali/public-api/animation/constraint.h>
 #include <dali/public-api/object/base-object.h>
 #include <dali/public-api/object/weak-handle.h>
 
@@ -332,7 +333,10 @@ private:
   Text::ControllerPtr mController;                       ///< The text's controller.
   Text::TypesetterPtr mTypesetter;                       ///< The text's typesetter.
   WeakHandle<Actor>   mControl;                          ///< The control where the renderer is added.
+  Constraint          mColorConstraint{};                ///< Color constraint
+  Constraint          mOpacityConstraint{};              ///< Opacity constraint
   Property::Index     mAnimatableTextColorPropertyIndex; ///< The index of animatable text color property registered by the control.
+  Property::Index     mTextColorAnimatableIndex;         ///< The index of uTextColorAnimatable property.
   bool                mRendererUpdateNeeded : 1;         ///< The flag to indicate whether the renderer needs to be updated.
   RendererContainer   mRendererList;
 };