TextColor Animatable 00/139000/7
authorAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 14 Jul 2017 14:15:22 +0000 (15:15 +0100)
committerAgnelo Vaz <agnelo.vaz@samsung.com>
Fri, 28 Jul 2017 09:15:30 +0000 (10:15 +0100)
Change-Id: Id52feb84c3cf66037f9013f2832318b170543d76

dali-toolkit/devel-api/controls/text-controls/text-label-devel.h
dali-toolkit/internal/controls/text-controls/text-editor-impl.cpp
dali-toolkit/internal/controls/text-controls/text-field-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.cpp
dali-toolkit/internal/controls/text-controls/text-label-impl.h
dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.cpp
dali-toolkit/internal/text/rendering/atlas/text-atlas-renderer.h
dali-toolkit/internal/text/rendering/text-renderer.h
dali-toolkit/internal/text/rendering/vector-based/vector-based-renderer.cpp
dali-toolkit/internal/text/rendering/vector-based/vector-based-renderer.h

index 2b53fc5..c609d34 100644 (file)
@@ -30,6 +30,16 @@ namespace Toolkit
 namespace DevelTextLabel
 {
 
 namespace DevelTextLabel
 {
 
+/**
+ * @brief Enumeration for the start and end property ranges for this control.
+ * @SINCE_1_0.0
+ */
+enum PropertyRange
+{
+  ANIMATABLE_PROPERTY_START_INDEX = ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX,
+  ANIMATABLE_PROPERTY_END_INDEX =   ANIMATABLE_PROPERTY_REGISTRATION_START_INDEX + 1000 ///< Reserve animatable property indices
+};
+
 namespace Property
 {
   enum Type
 namespace Property
 {
   enum Type
@@ -98,7 +108,14 @@ namespace Property
        * @brief line wrap mode when the text lines over layout width.
        * @details name "lineWrapMode", type string.
        */
        * @brief line wrap mode when the text lines over layout width.
        * @details name "lineWrapMode", type string.
        */
-      LINE_WRAP_MODE = OUTLINE + 6
+      LINE_WRAP_MODE = OUTLINE + 6,
+
+      /*
+       * @brief Animatable text color
+       * @details text color property to use if required to animate the text color
+       */
+      TEXT_COLOR_ANIMATABLE = ANIMATABLE_PROPERTY_START_INDEX
+
   };
 } // namespace Property
 
   };
 } // namespace Property
 
index ccddda5..d089d97 100644 (file)
@@ -1354,7 +1354,11 @@ void TextEditor::RenderText( Text::Controller::UpdateTextType updateTextType )
   {
     if( mRenderer )
     {
   {
     if( mRenderer )
     {
+      Dali::Toolkit::TextEditor handle = Dali::Toolkit::TextEditor( GetOwner() );
+
       renderableActor = mRenderer->Render( mController->GetView(),
       renderableActor = mRenderer->Render( mController->GetView(),
+                                           handle,
+                                           Property::INVALID_INDEX, // Animatable property not supported
                                            mAlignmentOffset,
                                            DepthIndex::CONTENT );
     }
                                            mAlignmentOffset,
                                            DepthIndex::CONTENT );
     }
index d392b92..1ed87bd 100644 (file)
@@ -1390,7 +1390,11 @@ void TextField::RenderText( Text::Controller::UpdateTextType updateTextType )
   {
     if( mRenderer )
     {
   {
     if( mRenderer )
     {
+      Dali::Toolkit::TextField handle = Dali::Toolkit::TextField( GetOwner() );
+
       renderableActor = mRenderer->Render( mController->GetView(),
       renderableActor = mRenderer->Render( mController->GetView(),
+                                           handle,
+                                           Property::INVALID_INDEX, // Animatable property not supported
                                            mAlignmentOffset,
                                            DepthIndex::CONTENT );
     }
                                            mAlignmentOffset,
                                            DepthIndex::CONTENT );
     }
index f484bbf..a6fa7ea 100644 (file)
@@ -127,7 +127,7 @@ DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollLoopDelay", FLO
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE  )
 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode",        STRING,  LINE_WRAP_MODE         )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "autoScrollStopMode",  STRING,  AUTO_SCROLL_STOP_MODE  )
 DALI_DEVEL_PROPERTY_REGISTRATION_READ_ONLY( Toolkit, TextLabel, "lineCount", INTEGER, LINE_COUNT             )
 DALI_DEVEL_PROPERTY_REGISTRATION( Toolkit, TextLabel, "lineWrapMode",        STRING,  LINE_WRAP_MODE         )
-
+DALI_DEVEL_ANIMATABLE_PROPERTY_REGISTRATION_WITH_DEFAULT( Toolkit, TextLabel, "textColorAnimatable", Color::WHITE, TEXT_COLOR_ANIMATABLE )
 DALI_TYPE_REGISTRATION_END()
 
 } // namespace
 DALI_TYPE_REGISTRATION_END()
 
 } // namespace
@@ -258,15 +258,7 @@ void TextLabel::SetProperty( BaseObject* object, Property::Index index, const Pr
 
       case Toolkit::TextLabel::Property::TEXT_COLOR:
       {
 
       case Toolkit::TextLabel::Property::TEXT_COLOR:
       {
-        if( impl.mController )
-        {
-          const Vector4& textColor = value.Get< Vector4 >();
-          if( impl.mController->GetDefaultColor() != textColor )
-          {
-            impl.mController->SetDefaultColor( textColor );
-            impl.mRenderer.Reset();
-          }
-        }
+        SetProperty( object, DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE, value );
         break;
       }
 
         break;
       }
 
@@ -597,6 +589,7 @@ Property::Value TextLabel::GetProperty( BaseObject* object, Property::Index inde
         break;
       }
       case Toolkit::TextLabel::Property::TEXT_COLOR:
         break;
       }
       case Toolkit::TextLabel::Property::TEXT_COLOR:
+      case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
       {
         if ( impl.mController )
         {
       {
         if ( impl.mController )
         {
@@ -850,6 +843,31 @@ float TextLabel::GetHeightForWidth( float width )
   return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
 }
 
   return mController->GetHeightForWidth( width ) + padding.top + padding.bottom;
 }
 
+void TextLabel::OnPropertySet( Property::Index index, Property::Value propertyValue )
+{
+  DALI_LOG_INFO( gLogFilter, Debug::Verbose, "TextLabel::OnPropertySet index[%d]\n", index );
+
+  switch ( index )
+  {
+    case Toolkit::TextLabel::Property::TEXT_COLOR:
+    case Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE:
+    {
+      const Vector4& textColor = propertyValue.Get< Vector4 >();
+      if( mController->GetDefaultColor() != textColor )
+      {
+         mController->SetDefaultColor( textColor );
+         mRenderer.Reset();
+      }
+      break;
+    }
+    default:
+    {
+      Control::OnPropertySet( index, propertyValue ); // up call to control for non-handled properties
+      break;
+    }
+  }
+}
+
 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
 void TextLabel::OnRelayout( const Vector2& size, RelayoutContainer& container )
 {
   DALI_LOG_INFO( gLogFilter, Debug::General, "TextLabel::OnRelayout\n" );
@@ -887,7 +905,12 @@ void TextLabel::RenderText()
   float alignmentOffset = 0.f;
   if( mRenderer )
   {
   float alignmentOffset = 0.f;
   if( mRenderer )
   {
+
+    Dali::Toolkit::TextLabel handle = Dali::Toolkit::TextLabel( GetOwner() );
+
     renderableActor = mRenderer->Render( mController->GetView(),
     renderableActor = mRenderer->Render( mController->GetView(),
+                                         handle,
+                                         Toolkit::DevelTextLabel::Property::TEXT_COLOR_ANIMATABLE,
                                          alignmentOffset,
                                          DepthIndex::CONTENT );
   }
                                          alignmentOffset,
                                          DepthIndex::CONTENT );
   }
index bc2459f..f15acbf 100644 (file)
@@ -73,34 +73,39 @@ private: // From Control
   /**
    * @copydoc Control::OnInitialize()
    */
   /**
    * @copydoc Control::OnInitialize()
    */
-  virtual void OnInitialize();
+  virtual void OnInitialize() override ;
 
   /**
    * @copydoc Control::OnStyleChange()
    */
 
   /**
    * @copydoc Control::OnStyleChange()
    */
-  virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change );
+  virtual void OnStyleChange( Toolkit::StyleManager styleManager, StyleChange::Type change ) override ;
 
   /**
    * @copydoc Control::OnRelayout()
    */
 
   /**
    * @copydoc Control::OnRelayout()
    */
-  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container );
+  virtual void OnRelayout( const Vector2& size, RelayoutContainer& container ) override ;
 
   /**
    * @copydoc Control::GetNaturalSize()
    */
 
   /**
    * @copydoc Control::GetNaturalSize()
    */
-  virtual Vector3 GetNaturalSize();
+  virtual Vector3 GetNaturalSize() override ;
 
   /**
    * @copydoc Control::GetHeightForWidth()
    */
 
   /**
    * @copydoc Control::GetHeightForWidth()
    */
-  virtual float GetHeightForWidth( float width );
+  virtual float GetHeightForWidth( float width ) override ;
 
 
-// From ControlInterface
+  /**
+   * @copydoc Control::OnPropertySet()
+   */
+  virtual void OnPropertySet( Property::Index index, Property::Value propertyValue ) override ;
+
+  // From ControlInterface
 
   /**
    * @copydoc Text::ControlInterface::RequestTextRelayout()
    */
 
   /**
    * @copydoc Text::ControlInterface::RequestTextRelayout()
    */
-  virtual void RequestTextRelayout();
+  virtual void RequestTextRelayout() override ;
 
 private: // from TextScroller
 
 
 private: // from TextScroller
 
index 6fe86a4..c3663dd 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/public-api/images/frame-buffer-image.h>
 #include <dali/devel-api/text-abstraction/font-client.h>
 #include <dali/integration-api/debug.h>
 #include <dali/public-api/images/frame-buffer-image.h>
 #include <dali/devel-api/text-abstraction/font-client.h>
 #include <dali/integration-api/debug.h>
+#include <dali/public-api/animation/constraints.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/controls/control-depth-index-ranges.h>
@@ -64,6 +65,7 @@ void main()
 
 const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
 uniform lowp    vec4      uColor;
 
 const char* FRAGMENT_SHADER_L8 = MAKE_SHADER(
 uniform lowp    vec4      uColor;
+uniform lowp    vec4      textColorAnimatable;
 uniform         sampler2D sTexture;
 varying mediump vec2      vTexCoord;
 varying mediump vec4      vColor;
 uniform         sampler2D sTexture;
 varying mediump vec2      vTexCoord;
 varying mediump vec4      vColor;
@@ -71,18 +73,19 @@ varying mediump vec4      vColor;
 void main()
 {
   mediump vec4 color = texture2D( sTexture, vTexCoord );
 void main()
 {
   mediump vec4 color = texture2D( sTexture, vTexCoord );
-  gl_FragColor = vec4( vColor.rgb * uColor.rgb, vColor.a * uColor.a * color.r );
+  gl_FragColor = vec4( vColor.rgb * uColor.rgb * textColorAnimatable.rgb, vColor.a * textColorAnimatable.a * color.r );
 }
 );
 
 const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER(
 uniform lowp    vec4      uColor;
 }
 );
 
 const char* FRAGMENT_SHADER_RGBA = MAKE_SHADER(
 uniform lowp    vec4      uColor;
+uniform lowp    vec4      textColorAnimatable;
 uniform         sampler2D sTexture;
 varying mediump vec2      vTexCoord;
 
 void main()
 {
 uniform         sampler2D sTexture;
 varying mediump vec2      vTexCoord;
 
 void main()
 {
-  gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor;
+  gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * textColorAnimatable;
 }
 );
 
 }
 );
 
@@ -208,6 +211,8 @@ struct AtlasRenderer::Impl
   }
 
   void AddGlyphs( Text::ViewInterface& view,
   }
 
   void AddGlyphs( Text::ViewInterface& view,
+                  Actor textControl,
+                  Property::Index animatablePropertyIndex,
                   const Vector<Vector2>& positions,
                   const Vector<GlyphInfo>& glyphs,
                   const Vector4& defaultColor,
                   const Vector<Vector2>& positions,
                   const Vector<GlyphInfo>& glyphs,
                   const Vector4& defaultColor,
@@ -460,7 +465,7 @@ struct AtlasRenderer::Impl
       {
         MeshRecord& meshRecord = *it;
 
       {
         MeshRecord& meshRecord = *it;
 
-        Actor actor = CreateMeshActor( meshRecord, textSize, STYLE_NORMAL );
+        Actor actor = CreateMeshActor( textControl, animatablePropertyIndex, defaultColor, meshRecord, textSize, STYLE_NORMAL );
 
         // Whether the actor has renderers.
         const bool hasRenderer = actor.GetRendererCount() > 0u;
 
         // Whether the actor has renderers.
         const bool hasRenderer = actor.GetRendererCount() > 0u;
@@ -480,7 +485,7 @@ struct AtlasRenderer::Impl
             vertex.mColor = shadowColor;
           }
 
             vertex.mColor = shadowColor;
           }
 
-          Actor shadowActor = CreateMeshActor( meshRecord, textSize, STYLE_DROP_SHADOW );
+          Actor shadowActor = CreateMeshActor(textControl, animatablePropertyIndex, defaultColor, meshRecord, textSize, STYLE_DROP_SHADOW );
 #if defined(DEBUG_ENABLED)
           shadowActor.SetName( "Text Shadow renderable actor" );
 #endif
 #if defined(DEBUG_ENABLED)
           shadowActor.SetName( "Text Shadow renderable actor" );
 #endif
@@ -531,7 +536,8 @@ struct AtlasRenderer::Impl
     mTextCache.Resize( 0 );
   }
 
     mTextCache.Resize( 0 );
   }
 
-  Actor CreateMeshActor( const MeshRecord& meshRecord, const Vector2& actorSize, Style style )
+  Actor CreateMeshActor( Actor textControl, Property::Index animatablePropertyIndex, const Vector4& defaultColor, const MeshRecord& meshRecord,
+                         const Vector2& actorSize, Style style )
   {
     PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat );
     quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() );
   {
     PropertyBuffer quadVertices = PropertyBuffer::New( mQuadVertexFormat );
     quadVertices.SetData( const_cast< AtlasManager::Vertex2D* >( &meshRecord.mMesh.mVertices[ 0 ] ), meshRecord.mMesh.mVertices.Size() );
@@ -564,6 +570,26 @@ struct AtlasRenderer::Impl
       shader = mShaderL8;
     }
 
       shader = mShaderL8;
     }
 
+    DALI_LOG_INFO( gLogFilter, Debug::Verbose, "defaultColor[%f, %f, %f, %f ]\n", defaultColor.r, defaultColor.g, defaultColor.b, defaultColor.a  );
+
+    Dali::Property::Index shaderTextColorIndex = shader.RegisterProperty( "textColorAnimatable", defaultColor );
+
+    if ( animatablePropertyIndex != Property::INVALID_INDEX )
+    {
+      // create constraint for the animatable text's color Property with textColorAnimatable in the shader.
+      if( shaderTextColorIndex  )
+      {
+        Constraint constraint = Constraint::New<Vector4>( shader, shaderTextColorIndex, EqualToConstraint() );
+        constraint.AddSource( Source( textControl, animatablePropertyIndex ) );
+        constraint.Apply();
+      }
+    }
+    else
+    {
+      // If not animating the text colour then set to 1's so shader uses the current vertex color
+      shader.RegisterProperty( "textColorAnimatable", Vector4(1.0, 1.0, 1.0, 1.0 ) );
+    }
+
     Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, shader );
     renderer.SetTextures( textureSet );
     renderer.SetProperty( Dali::Renderer::Property::BLEND_MODE, BlendMode::ON );
     Dali::Renderer renderer = Dali::Renderer::New( quadGeometry, shader );
     renderer.SetTextures( textureSet );
     renderer.SetProperty( Dali::Renderer::Property::BLEND_MODE, BlendMode::ON );
@@ -814,6 +840,8 @@ Text::RendererPtr AtlasRenderer::New()
 }
 
 Actor AtlasRenderer::Render( Text::ViewInterface& view,
 }
 
 Actor AtlasRenderer::Render( Text::ViewInterface& view,
+                             Actor textControl,
+                             Property::Index animatablePropertyIndex,
                              float& alignmentOffset,
                              int depth )
 {
                              float& alignmentOffset,
                              int depth )
 {
@@ -845,6 +873,8 @@ Actor AtlasRenderer::Render( Text::ViewInterface& view,
     const Vector4& defaultColor = view.GetTextColor();
 
     mImpl->AddGlyphs( view,
     const Vector4& defaultColor = view.GetTextColor();
 
     mImpl->AddGlyphs( view,
+                      textControl,
+                      animatablePropertyIndex,
                       positions,
                       glyphs,
                       defaultColor,
                       positions,
                       glyphs,
                       defaultColor,
index 2872395..f114b02 100644 (file)
@@ -47,6 +47,8 @@ public:
    * @copydoc Renderer::Render()
    */
   virtual Actor Render( ViewInterface& view,
    * @copydoc Renderer::Render()
    */
   virtual Actor Render( ViewInterface& view,
+                        Actor textControl,
+                        Property::Index animatablePropertyIndex,
                         float& alignmentOffset,
                         int depth );
 
                         float& alignmentOffset,
                         int depth );
 
index 06781b8..1d473c5 100644 (file)
@@ -51,11 +51,15 @@ public:
    * @brief Render the glyphs from a ViewInterface.
    *
    * @param[in] view The interface to a view.
    * @brief Render the glyphs from a ViewInterface.
    *
    * @param[in] view The interface to a view.
+   * @param[in] textControl handle to the text control
+   * @param[in] animatablePropertyIndex textControl specific animatable property
    * @param[out] alignmentOffset Offset used to internally align the placement actor.
    * @param[in] depth The depth in the tree of the parent.
    * @return The Renderable actor used to position the text.
    */
   virtual Actor Render( ViewInterface& view,
    * @param[out] alignmentOffset Offset used to internally align the placement actor.
    * @param[in] depth The depth in the tree of the parent.
    * @return The Renderable actor used to position the text.
    */
   virtual Actor Render( ViewInterface& view,
+                        Actor textContol,
+                        Property::Index animatablePropertyIndex,
                         float& alignmentOffset,
                         int depth ) = 0;
 
                         float& alignmentOffset,
                         int depth ) = 0;
 
index 7f15b72..7fccc8d 100644 (file)
@@ -182,6 +182,8 @@ Text::RendererPtr VectorBasedRenderer::New()
 }
 
 Actor VectorBasedRenderer::Render( Text::ViewInterface& view,
 }
 
 Actor VectorBasedRenderer::Render( Text::ViewInterface& view,
+                                   Actor textControl,
+                                   Property::Index animatablePropertyIndex,
                                    float& alignmentOffset,
                                    int /*depth*/ )
 {
                                    float& alignmentOffset,
                                    int /*depth*/ )
 {
index 9d95655..9ba3930 100644 (file)
@@ -47,6 +47,8 @@ public:
    * @copydoc Renderer::Render()
    */
   virtual Actor Render( ViewInterface& view,
    * @copydoc Renderer::Render()
    */
   virtual Actor Render( ViewInterface& view,
+                        Actor textControl,  // Functionality not supported but defined in interface
+                        Property::Index animatablePropertyIndex, // Functionality not supported but defined in interface
                         float& alignmentOffset,
                         int depth );
 
                         float& alignmentOffset,
                         int depth );