Fixed SVACE error in Internal::Visual::Base
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-base-impl.cpp
index 9d0c964..92cadd7 100644 (file)
@@ -23,7 +23,7 @@
 #include <dali/integration-api/debug.h>
 
 //INTERNAL HEARDER
-#include <dali-toolkit/public-api/visuals/visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/internal/visuals/visual-base-data-impl.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 
@@ -36,21 +36,18 @@ namespace Toolkit
 namespace Internal
 {
 
-namespace Visual
-{
-
-Base::Base( VisualFactoryCache& factoryCache )
+Visual::Base::Base( VisualFactoryCache& factoryCache )
 : mImpl( new Impl() ),
   mFactoryCache( factoryCache )
 {
 }
 
-Base::~Base()
+Visual::Base::~Base()
 {
   delete mImpl;
 }
 
-void Base::SetCustomShader( const Property::Map& shaderMap )
+void Visual::Base::SetCustomShader( const Property::Map& shaderMap )
 {
   if( mImpl->mCustomShader )
   {
@@ -58,50 +55,82 @@ void Base::SetCustomShader( const Property::Map& shaderMap )
   }
   else
   {
-   mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
+    mImpl->mCustomShader = new Impl::CustomShader( shaderMap );
   }
 }
 
-void Base::Initialize( Actor& actor, const Property::Map& propertyMap )
+void Visual::Base::SetProperties( const Property::Map& propertyMap )
 {
-  Property::Value* customShaderValue = propertyMap.Find( Toolkit::Visual::Property::SHADER, CUSTOM_SHADER );
-  if( customShaderValue )
+  for( size_t i = 0; i < propertyMap.Count(); ++i )
   {
-    Property::Map shaderMap;
-    if( customShaderValue->Get( shaderMap ) )
+    const KeyValuePair& pair = propertyMap.GetKeyValue( i );
+    const Property::Key& key = pair.first;
+    const Property::Value& value = pair.second;
+    switch( key.indexKey )
     {
-      SetCustomShader( shaderMap );
+      case DevelVisual::Property::SHADER:
+      {
+        Property::Map shaderMap;
+        if( value.Get( shaderMap ) )
+        {
+          SetCustomShader( shaderMap );
+        }
+        break;
+      }
+
+      case DevelVisual::Property::TRANSFORM:
+      {
+        Property::Map map;
+        if( value.Get( map ) )
+        {
+          mImpl->mTransform.SetPropertyMap( map );
+        }
+        break;
+      }
+
+      case DevelVisual::Property::PREMULTIPLIED_ALPHA:
+      {
+        bool premultipliedAlpha = false;
+        if( value.Get( premultipliedAlpha ) )
+        {
+          EnablePreMultipliedAlpha( premultipliedAlpha );
+        }
+        break;
+      }
     }
   }
 
-  DoInitialize( actor, propertyMap );
+  DoSetProperties( propertyMap );
 }
 
-void Base::SetSize( const Vector2& size )
+void Visual::Base::SetTransformAndSize( const Property::Map& transform, Size controlSize )
 {
-  mImpl->mSize = size;
+  mImpl->mControlSize = controlSize;
+  mImpl->mTransform.SetPropertyMap( transform );
+  OnSetTransform();
 }
 
-const Vector2& Base::GetSize() const
+void Visual::Base::SetName( const std::string& name )
 {
-  return mImpl->mSize;
+  mImpl->mName = name;
 }
 
-void Base::GetNaturalSize( Vector2& naturalSize ) const
+const std::string& Visual::Base::GetName()
 {
-  naturalSize = Vector2::ZERO;
+  return mImpl->mName;
 }
 
-void Base::SetClipRect( const Rect<int>& clipRect )
+float Visual::Base::GetHeightForWidth( float width ) const
 {
+  return 0.f;
 }
 
-void Base::SetOffset( const Vector2& offset )
+void Visual::Base::GetNaturalSize( Vector2& naturalSize )
 {
-  mImpl->mOffset = offset;
+  naturalSize = Vector2::ZERO;
 }
 
-void Base::SetDepthIndex( float index )
+void Visual::Base::SetDepthIndex( float index )
 {
   mImpl->mDepthIndex = index;
   if( mImpl->mRenderer )
@@ -110,25 +139,31 @@ void Base::SetDepthIndex( float index )
   }
 }
 
-float Base::GetDepthIndex() const
+float Visual::Base::GetDepthIndex() const
 {
   return mImpl->mDepthIndex;
 }
 
-void Base::SetOnStage( Actor& actor )
+void Visual::Base::SetOnStage( Actor& actor )
 {
-  DoSetOnStage( actor );
-
-  mImpl->mRenderer.SetProperty(Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
-  mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
-  actor.AddRenderer( mImpl->mRenderer );
+  if( !IsOnStage() )
+  {
+    // To display the actor correctly, renderer should not be added to actor until all required resources are ready.
+    // Thus the calling of actor.AddRenderer() should happen inside derived class as base class does not know the exact timing.
+    DoSetOnStage( actor );
 
-  mImpl->mFlags |= Impl::IS_ON_STAGE;
+    if( mImpl->mRenderer )
+    {
+      mImpl->mRenderer.SetProperty( Renderer::Property::BLEND_PRE_MULTIPLIED_ALPHA, IsPreMultipliedAlphaEnabled());
+      mImpl->mRenderer.SetProperty( Renderer::Property::DEPTH_INDEX, mImpl->mDepthIndex );
+      mImpl->mFlags |= Impl::IS_ON_STAGE; // Only sets the flag if renderer exists
+    }
+  }
 }
 
-void Base::SetOffStage( Actor& actor )
+void Visual::Base::SetOffStage( Actor& actor )
 {
-  if( GetIsOnStage() )
+  if( IsOnStage() )
   {
     DoSetOffStage( actor );
 
@@ -136,9 +171,26 @@ void Base::SetOffStage( Actor& actor )
   }
 }
 
-void Base::EnablePreMultipliedAlpha( bool preMultipled )
+void Visual::Base::CreatePropertyMap( Property::Map& map ) const
 {
-  if(preMultipled)
+  DoCreatePropertyMap( map );
+
+  if( mImpl->mCustomShader )
+  {
+    mImpl->mCustomShader->CreatePropertyMap( map );
+  }
+
+  Property::Map transform;
+  mImpl->mTransform.GetPropertyMap( transform );
+  map.Insert( DevelVisual::Property::TRANSFORM, transform );
+
+  bool premultipliedAlpha( IsPreMultipliedAlphaEnabled() );
+  map.Insert( DevelVisual::Property::PREMULTIPLIED_ALPHA, premultipliedAlpha );
+}
+
+void Visual::Base::EnablePreMultipliedAlpha( bool preMultipled )
+{
+  if( preMultipled )
   {
     mImpl->mFlags |= Impl::IS_PREMULTIPLIED_ALPHA;
   }
@@ -153,43 +205,27 @@ void Base::EnablePreMultipliedAlpha( bool preMultipled )
   }
 }
 
-bool Base::IsPreMultipliedAlphaEnabled() const
+bool Visual::Base::IsPreMultipliedAlphaEnabled() const
 {
   return mImpl->mFlags & Impl::IS_PREMULTIPLIED_ALPHA;
 }
 
-void Base::DoSetOnStage( Actor& actor )
-{
-}
-
-void Base::DoSetOffStage( Actor& actor )
+void Visual::Base::DoSetOffStage( Actor& actor )
 {
   actor.RemoveRenderer( mImpl->mRenderer );
   mImpl->mRenderer.Reset();
 }
 
-void Base::CreatePropertyMap( Property::Map& map ) const
-{
-  DoCreatePropertyMap( map );
-
-  if( mImpl->mCustomShader )
-  {
-    mImpl->mCustomShader->CreatePropertyMap( map );
-  }
-}
-
-bool Base::GetIsOnStage() const
+bool Visual::Base::IsOnStage() const
 {
   return mImpl->mFlags & Impl::IS_ON_STAGE;
 }
 
-bool Base::GetIsFromCache() const
+bool Visual::Base::IsFromCache() const
 {
   return mImpl->mFlags & Impl::IS_FROM_CACHE;
 }
 
-} // namespace Visual
-
 } // namespace Internal
 
 } // namespace Toolkit