Make ImageVisual::Property::PIXEL_AREA animatable
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image / image-visual.cpp
index 2f0e800..e6e07e8 100644 (file)
@@ -152,6 +152,7 @@ ImageVisual::ImageVisual(VisualFactoryCache&       factoryCache,
                          Dali::SamplingMode::Type  samplingMode)
 : Visual::Base(factoryCache, Visual::FittingMode::FILL, Toolkit::Visual::IMAGE),
   mPixelArea(FULL_TEXTURE_RECT),
+  mPixelAreaIndex(Property::INVALID_INDEX),
   mPlacementActor(),
   mImageUrl(imageUrl),
   mMaskingData(),
@@ -372,6 +373,13 @@ void ImageVisual::DoSetProperty(Property::Index index, const Property::Value& va
     case Toolkit::ImageVisual::Property::PIXEL_AREA:
     {
       value.Get(mPixelArea);
+
+      if(DALI_UNLIKELY(mImpl->mRenderer))
+      {
+        // Unusual case. SetProperty called after OnInitialize().
+        // Assume that DoAction call UPDATE_PROPERTY.
+        mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
+      }
       break;
     }
 
@@ -864,7 +872,7 @@ void ImageVisual::DoSetOnScene(Actor& actor)
 
   if(mPixelArea != FULL_TEXTURE_RECT)
   {
-    mImpl->mRenderer.RegisterProperty(PIXEL_AREA_UNIFORM_NAME, mPixelArea);
+    mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
   }
 
   if(mLoadState == TextureManager::LoadState::LOAD_FINISHED)
@@ -924,7 +932,17 @@ void ImageVisual::DoCreatePropertyMap(Property::Map& map) const
   map.Insert(Toolkit::ImageVisual::Property::FITTING_MODE, mFittingMode);
   map.Insert(Toolkit::ImageVisual::Property::SAMPLING_MODE, mSamplingMode);
 
-  map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea);
+  if(mImpl->mRenderer && mPixelAreaIndex != Property::INVALID_INDEX)
+  {
+    // Update values from Renderer
+    Vector4 pixelArea = mImpl->mRenderer.GetProperty<Vector4>(mPixelAreaIndex);
+    map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, pixelArea);
+  }
+  else
+  {
+    map.Insert(Toolkit::ImageVisual::Property::PIXEL_AREA, mPixelArea);
+  }
+
   map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_U, mWrapModeU);
   map.Insert(Toolkit::ImageVisual::Property::WRAP_MODE_V, mWrapModeV);
 
@@ -1329,6 +1347,24 @@ Shader ImageVisual::GenerateShader() const
   return shader;
 }
 
+Dali::Property ImageVisual::OnGetPropertyObject(Dali::Property::Key key)
+{
+  if((key.type == Property::Key::INDEX && key.indexKey == Toolkit::ImageVisual::Property::PIXEL_AREA) || (key.type == Property::Key::STRING && key.stringKey == PIXEL_AREA_UNIFORM_NAME))
+  {
+    if(DALI_LIKELY(mImpl->mRenderer))
+    {
+      if(mPixelAreaIndex == Property::INVALID_INDEX)
+      {
+        mPixelAreaIndex = mImpl->mRenderer.RegisterProperty(mPixelAreaIndex, PIXEL_AREA_UNIFORM_NAME, mPixelArea);
+      }
+      return Dali::Property(mImpl->mRenderer, mPixelAreaIndex);
+    }
+  }
+
+  Handle handle;
+  return Dali::Property(handle, Property::INVALID_INDEX);
+}
+
 void ImageVisual::CheckMaskTexture()
 {
   if(mMaskingData && !mMaskingData->mPreappliedMasking)