Updated doxygen comments in scroll-view constraints
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / image / batch-image-visual.cpp
index 46244aa..47f0316 100644 (file)
@@ -24,6 +24,7 @@
 #include <dali/public-api/images/native-image.h>
 #include <dali/integration-api/debug.h>
 #include <dali/devel-api/adaptor-framework/bitmap-loader.h>
+#include <dali/devel-api/rendering/renderer-devel.h>
 #include <dali/public-api/images/pixel-data.h>
 #include <dali/public-api/rendering/texture.h>
 #include <dali/public-api/rendering/texture-set.h>
@@ -31,6 +32,7 @@
 
 // INTERNAL HEADER
 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/internal/visuals/visual-factory-impl.h>
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
 #include <dali-toolkit/internal/visuals/visual-base-impl.h>
@@ -77,19 +79,34 @@ const char* FRAGMENT_SHADER = DALI_COMPOSE_SHADER(
   varying mediump vec2 vTexCoord;\n
   uniform sampler2D sTexture;\n
   uniform lowp vec4 uColor;\n
-  uniform lowp float uAlphaBlending; // Set to 1.0 for conventional alpha blending; if pre-multiplied alpha blending, set to 0.0
+  uniform lowp vec4 mixColor;\n
+  uniform lowp float preMultipliedAlpha;\n
+  lowp vec4 visualMixColor()\n
+  {\n
+    return vec4( mixColor.rgb * mix( 1.0, mixColor.a, preMultipliedAlpha ), mixColor.a );\n
+  }\n
   \n
   void main()\n
   {\n
-    gl_FragColor = texture2D( sTexture, vTexCoord ) * vec4( uColor.rgb*max( uAlphaBlending, uColor.a ), uColor.a );\n
+    gl_FragColor = texture2D( sTexture, vTexCoord ) * uColor * visualMixColor();
   }\n
 );
 
-} //unnamed namespace
+} // unnamed namespace
+
+BatchImageVisualPtr BatchImageVisual::New( VisualFactoryCache& factoryCache, const std::string& url, const Property::Map& properties )
+{
+  BatchImageVisualPtr visual = new BatchImageVisual( factoryCache );
+  visual->mImageUrl = url;
+  visual->SetProperties( properties );
+
+  return visual;
+}
 
 BatchImageVisual::BatchImageVisual( VisualFactoryCache& factoryCache )
-  : Visual::Base( factoryCache ),
-    mDesiredSize()
+: Visual::Base( factoryCache ),
+  mImageUrl(""),
+  mDesiredSize()
 {
 }
 
@@ -97,58 +114,65 @@ BatchImageVisual::~BatchImageVisual()
 {
 }
 
-void BatchImageVisual::DoInitialize( Actor& actor, const Property::Map& propertyMap )
+void BatchImageVisual::DoSetProperties( const Property::Map& propertyMap )
 {
-  std::string oldImageUrl = mImageUrl;
-  Property::Value* imageURLValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::URL, Dali::Toolkit::Internal::IMAGE_URL_NAME );
+  // url already passed in constructor
 
-  if( imageURLValue )
+  for( Property::Map::SizeType iter = 0; iter < propertyMap.Count(); ++iter )
   {
-    imageURLValue->Get( mImageUrl );
-
-    int desiredWidth = 0;
-    Property::Value* desiredWidthValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::DESIRED_WIDTH, DESIRED_WIDTH );
-    if( desiredWidthValue )
+    KeyValuePair keyValue = propertyMap.GetKeyValue( iter );
+    if( keyValue.first.type == Property::Key::INDEX )
     {
-      desiredWidthValue->Get( desiredWidth );
+      DoSetProperty( keyValue.first.indexKey, keyValue.second );
     }
-
-    int desiredHeight = 0;
-    Property::Value* desiredHeightValue = propertyMap.Find( Dali::Toolkit::ImageVisual::Property::DESIRED_HEIGHT, DESIRED_HEIGHT );
-    if( desiredHeightValue )
+    else
     {
-      desiredHeightValue->Get( desiredHeight );
+      if( keyValue.first == DESIRED_WIDTH )
+      {
+        DoSetProperty( Toolkit::ImageVisual::Property::DESIRED_WIDTH, keyValue.second );
+      }
+      else if( keyValue.first == DESIRED_HEIGHT )
+      {
+        DoSetProperty( Toolkit::ImageVisual::Property::DESIRED_HEIGHT, keyValue.second );
+      }
     }
-
-    mDesiredSize = ImageDimensions( desiredWidth, desiredHeight );
   }
+}
 
-  // Remove old renderer if exit.
-  if( mImpl->mRenderer )
+void BatchImageVisual::DoSetProperty( Property::Index index, const Property::Value& value )
+{
+  switch( index )
   {
-    if( actor ) // Remove old renderer from actor.
+    case Dali::Toolkit::ImageVisual::Property::DESIRED_WIDTH:
     {
-      actor.RemoveRenderer( mImpl->mRenderer );
+      int width;
+      if( value.Get( width ) )
+      {
+        mDesiredSize.SetWidth( width );
+      }
+      else
+      {
+        DALI_LOG_ERROR("BatchImageVisual: width property has incorrect type\n");
+      }
+      break;
     }
-    if( !oldImageUrl.empty() ) // Clean old renderer from cache.
+    case Dali::Toolkit::ImageVisual::Property::DESIRED_HEIGHT:
     {
-      CleanCache( oldImageUrl );
+      int height;
+      if( value.Get( height ) )
+      {
+        mDesiredSize.SetHeight( height );
+      }
+      else
+      {
+        DALI_LOG_ERROR("BatchImageVisual: height property has incorrect type\n");
+      }
+      break;
     }
   }
-
-  // If actor is on stage, create new renderer and apply to actor.
-  if( actor && actor.OnStage() )
-  {
-    SetOnStage( actor );
-  }
 }
 
-void BatchImageVisual::SetSize( const Vector2& size )
-{
-  Visual::Base::SetSize( size );
-}
-
-void BatchImageVisual::GetNaturalSize( Vector2& naturalSize ) const
+void BatchImageVisual::GetNaturalSize( Vector2& naturalSize )
 {
   if( mDesiredSize.GetWidth() > 0 && mDesiredSize.GetHeight() > 0 )
   {
@@ -212,7 +236,7 @@ void BatchImageVisual::InitializeRenderer( const std::string& imageUrl )
       mImpl->mRenderer.SetTextures( textureSet );
 
       // Turn batching on, to send message it must be on stage.
-      mImpl->mRenderer.SetProperty( Dali::Renderer::Property::BATCHING_ENABLED, true );
+      mImpl->mRenderer.SetProperty( Dali::DevelRenderer::Property::BATCHING_ENABLED, true );
     }
     mImpl->mFlags |= Impl::IS_FROM_CACHE;
   }
@@ -225,7 +249,7 @@ void BatchImageVisual::DoSetOnStage( Actor& actor )
     InitializeRenderer( mImageUrl );
   }
   // Turn batching on, to send message it must be on stage
-  mImpl->mRenderer.SetProperty( Dali::Renderer::Property::BATCHING_ENABLED, true );
+  mImpl->mRenderer.SetProperty( Dali::DevelRenderer::Property::BATCHING_ENABLED, true );
 
   actor.AddRenderer( mImpl->mRenderer );
 }
@@ -248,7 +272,7 @@ void BatchImageVisual::DoSetOffStage( Actor& actor )
 void BatchImageVisual::DoCreatePropertyMap( Property::Map& map ) const
 {
   map.Clear();
-  map.Insert( Toolkit::Visual::Property::TYPE, Toolkit::Visual::IMAGE );
+  map.Insert( Toolkit::DevelVisual::Property::TYPE, Toolkit::Visual::IMAGE );
 
   if( !mImageUrl.empty() )
   {
@@ -259,17 +283,6 @@ void BatchImageVisual::DoCreatePropertyMap( Property::Map& map ) const
   }
 }
 
-void BatchImageVisual::DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue )
-{
-  // TODO
-}
-
-Dali::Property::Value BatchImageVisual::DoGetProperty( Dali::Property::Index index )
-{
-  // TODO
-  return Dali::Property::Value();
-}
-
 Shader BatchImageVisual::GetBatchShader( VisualFactoryCache& factoryCache )
 {
   Shader shader = factoryCache.GetShader( VisualFactoryCache::BATCH_IMAGE_SHADER );
@@ -291,6 +304,14 @@ void BatchImageVisual::CleanCache(const std::string& url)
   }
 }
 
+void BatchImageVisual::OnSetTransform()
+{
+  if( mImpl->mRenderer )
+  {
+    //Register transform properties
+    mImpl->mTransform.RegisterUniforms( mImpl->mRenderer, Direction::LEFT_TO_RIGHT );
+  }
+}
 
 } // namespace Internal