Merge "Support animation of Visual transform properties" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
index ce31fb1..e8e984f 100755 (executable)
@@ -323,7 +323,7 @@ void Visual::Base::SetOnScene( Actor& actor )
 
       if( IsRoundedCornerRequired() )
       {
-        mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty( CORNER_RADIUS, mImpl->mCornerRadius );
+        mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
         mImpl->mRenderer.RegisterProperty( CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy );
 
         mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_MODE, BlendMode::ON );
@@ -340,6 +340,25 @@ void Visual::Base::SetOffScene( Actor& actor )
 {
   if( IsOnScene() )
   {
+    if(mImpl->mRenderer)
+    {
+      // Update values from Renderer
+      mImpl->mMixColor   = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
+      mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
+      if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
+      {
+        mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
+      }
+      if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
+      {
+        mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
+      }
+      if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
+      {
+        mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<float>(mImpl->mCornerRadiusIndex);
+      }
+    }
+
     DoSetOffScene( actor );
     mImpl->mMixColorIndex = Property::INVALID_INDEX;
     mImpl->mCornerRadiusIndex = Property::INVALID_INDEX;
@@ -349,11 +368,30 @@ void Visual::Base::SetOffScene( Actor& actor )
 
 void Visual::Base::CreatePropertyMap( Property::Map& map ) const
 {
-  DoCreatePropertyMap( map );
+  if(mImpl->mRenderer)
+  {
+    // Update values from Renderer
+    mImpl->mMixColor   = mImpl->mRenderer.GetProperty<Vector3>(mImpl->mMixColorIndex);
+    mImpl->mMixColor.a = mImpl->mRenderer.GetProperty<float>(DevelRenderer::Property::OPACITY);
+    if(mImpl->mTransform.mOffsetIndex != Property::INVALID_INDEX)
+    {
+      mImpl->mTransform.mOffset = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mOffsetIndex);
+    }
+    if(mImpl->mTransform.mSizeIndex != Property::INVALID_INDEX)
+    {
+      mImpl->mTransform.mSize = mImpl->mRenderer.GetProperty<Vector2>(mImpl->mTransform.mSizeIndex);
+    }
+    if(mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
+    {
+      mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<float>(mImpl->mCornerRadiusIndex);
+    }
+  }
 
-  if( mImpl->mCustomShader )
+  DoCreatePropertyMap(map);
+
+  if(mImpl->mCustomShader)
   {
-    mImpl->mCustomShader->CreatePropertyMap( map );
+    mImpl->mCustomShader->CreatePropertyMap(map);
   }
 
   Property::Map transform;
@@ -413,11 +451,6 @@ bool Visual::Base::IsPreMultipliedAlphaEnabled() const
   return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
 }
 
-bool Visual::Base::IsAdvancedBlendEquationApplied() const
-{
-  return IsPreMultipliedAlphaEnabled() && DevelRenderer::IsAdvancedBlendEquationApplied( mImpl->mRenderer );
-}
-
 void Visual::Base::DoSetOffScene( Actor& actor )
 {
   actor.RemoveRenderer( mImpl->mRenderer );
@@ -431,7 +464,12 @@ bool Visual::Base::IsOnScene() const
 
 bool Visual::Base::IsRoundedCornerRequired() const
 {
-  return !EqualsZero( mImpl->mCornerRadius );
+  if(mImpl->mRenderer && mImpl->mCornerRadiusIndex != Property::INVALID_INDEX)
+  {
+    // Update values from Renderer
+    mImpl->mCornerRadius = mImpl->mRenderer.GetProperty<float>(mImpl->mCornerRadiusIndex);
+  }
+  return !EqualsZero(mImpl->mCornerRadius) || mImpl->mNeedCornerRadius;
 }
 
 void Visual::Base::OnDoAction( const Property::Index actionId, const Property::Value& attributes )
@@ -484,11 +522,6 @@ void Visual::Base::SetMixColor( const Vector3& color )
   }
 }
 
-const Vector4& Visual::Base::GetMixColor() const
-{
-  return mImpl->mMixColor;
-}
-
 void Visual::Base::AddEventObserver( Visual::EventObserver& observer)
 {
   mImpl->mEventObserver = &observer;
@@ -629,21 +662,12 @@ void Visual::Base::AnimateProperty(
   }
 #endif
 
-  Property::Map map;
-  DoCreatePropertyMap( map );
-  Property::Value* valuePtr = map.Find( Toolkit::Visual::Property::TYPE );
-  int visualType = -1;
-  if( valuePtr )
-  {
-    valuePtr->Get( visualType );
-  }
-
-  if( animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
-      animator.propertyKey == MIX_COLOR ||
-      ( visualType == Toolkit::Visual::COLOR &&
-        animator.propertyKey == ColorVisual::Property::MIX_COLOR ) ||
-      ( visualType == Toolkit::Visual::PRIMITIVE &&
-        animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR ) )
+  if(animator.propertyKey == Toolkit::Visual::Property::MIX_COLOR ||
+     animator.propertyKey == MIX_COLOR ||
+     (mImpl->mType == Toolkit::Visual::COLOR &&
+      animator.propertyKey == ColorVisual::Property::MIX_COLOR) ||
+     (mImpl->mType == Toolkit::Visual::PRIMITIVE &&
+      animator.propertyKey == PrimitiveVisual::Property::MIX_COLOR))
   {
     AnimateMixColorProperty( transition, animator );
   }
@@ -750,6 +774,83 @@ void Visual::Base::AnimateMixColorProperty(
   }
 }
 
+Dali::Property Visual::Base::GetPropertyObject(Dali::Property::Key key)
+{
+  if(!mImpl->mRenderer)
+  {
+    Handle handle;
+    return Dali::Property(handle, Property::INVALID_INDEX);
+  }
+
+  // Mix color or opacity cases
+  if(key.type == Property::Key::INDEX)
+  {
+    if(key.indexKey == Toolkit::Visual::Property::MIX_COLOR || (mImpl->mType == Toolkit::Visual::COLOR && key.indexKey == ColorVisual::Property::MIX_COLOR) || (mImpl->mType == Toolkit::Visual::PRIMITIVE && key.indexKey == PrimitiveVisual::Property::MIX_COLOR))
+    {
+      return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
+    }
+    else if(key.indexKey == Toolkit::Visual::Property::OPACITY)
+    {
+      return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
+    }
+    else if(key.indexKey == Toolkit::Visual::Transform::Property::OFFSET)
+    {
+      return Dali::Property(mImpl->mRenderer, OFFSET);
+    }
+    else if(key.indexKey == Toolkit::Visual::Transform::Property::SIZE)
+    {
+      return Dali::Property(mImpl->mRenderer, SIZE);
+    }
+  }
+  else
+  {
+    if(key.stringKey == MIX_COLOR)
+    {
+      return Dali::Property(mImpl->mRenderer, mImpl->mMixColorIndex);
+    }
+    else if(key.stringKey == OPACITY)
+    {
+      return Dali::Property(mImpl->mRenderer, DevelRenderer::Property::OPACITY);
+    }
+    else if(key.stringKey == OFFSET)
+    {
+      return Dali::Property(mImpl->mRenderer, OFFSET);
+    }
+    else if(key.stringKey == SIZE)
+    {
+      return Dali::Property(mImpl->mRenderer, SIZE);
+    }
+  }
+
+  // Other cases
+  Property::Index index = GetPropertyIndex(key);
+  if(index == Property::INVALID_INDEX)
+  {
+    if((key.type == Property::Key::INDEX && key.indexKey == DevelVisual::Property::CORNER_RADIUS) || (key.type == Property::Key::STRING && key.stringKey == CORNER_RADIUS))
+    {
+      // Register CORNER_RADIUS property
+      mImpl->mCornerRadiusIndex = mImpl->mRenderer.RegisterProperty(DevelVisual::Property::CORNER_RADIUS, CORNER_RADIUS, mImpl->mCornerRadius);
+      mImpl->mRenderer.RegisterProperty(CORNER_RADIUS_POLICY, mImpl->mCornerRadiusPolicy);
+
+      mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_MODE, BlendMode::ON);
+
+      index = mImpl->mCornerRadiusIndex;
+      mImpl->mNeedCornerRadius = true;
+
+      // Change shader
+      UpdateShader();
+    }
+    else
+    {
+      // We can't find the property in the base class.
+      // Request to child class
+      return OnGetPropertyObject(key);
+    }
+  }
+
+  return Dali::Property(mImpl->mRenderer, index);
+}
+
 } // namespace Internal
 
 } // namespace Toolkit