Adding support for multiple images in AnimatedImageVisual
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-factory-impl.cpp
index 909cfcc..469ead5 100644 (file)
@@ -27,6 +27,7 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/public-api/visuals/image-visual-properties.h>
+#include <dali-toolkit/devel-api/visuals/image-visual-properties-devel.h>
 #include <dali-toolkit/devel-api/visuals/text-visual-properties.h>
 #include <dali-toolkit/devel-api/visuals/visual-properties-devel.h>
 #include <dali-toolkit/internal/visuals/border/border-visual.h>
@@ -41,7 +42,7 @@
 #include <dali-toolkit/internal/visuals/animated-image/animated-image-visual.h>
 #include <dali-toolkit/internal/visuals/wireframe/wireframe-visual.h>
 #include <dali-toolkit/internal/visuals/visual-factory-cache.h>
-#include <dali-toolkit/internal/visuals/visual-factory-resolve-url.h>
+#include <dali-toolkit/internal/visuals/visual-url.h>
 #include <dali-toolkit/internal/visuals/visual-string-constants.h>
 
 namespace Dali
@@ -118,28 +119,45 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property
     {
       Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
       std::string imageUrl;
-      if( imageURLValue && imageURLValue->Get( imageUrl ) )
+      if( imageURLValue )
       {
-        // first resolve url type to know which visual to create
-        UrlType::Type type = ResolveUrlType( imageUrl );
-        if( UrlType::N_PATCH == type )
-        {
-          visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
-        }
-        else if( UrlType::SVG == type )
+        if( imageURLValue->Get( imageUrl ) )
         {
-          visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
+          VisualUrl visualUrl( imageUrl );
+
+          switch( visualUrl.GetType() )
+          {
+            case VisualUrl::N_PATCH:
+            {
+              visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+              break;
+            }
+            case VisualUrl::SVG:
+            {
+              visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+              break;
+            }
+            case VisualUrl::GIF:
+            {
+              visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+              break;
+            }
+            case VisualUrl::REGULAR_IMAGE:
+            {
+              visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, propertyMap );
+              break;
+            }
+          }
         }
-        else if( UrlType::GIF == type )
+        else
         {
-          visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
-        }
-        else // Regular image
-        {
-          visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
+          Property::Array* array = imageURLValue->GetArray();
+          if( array )
+          {
+            visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), *array, propertyMap );
+          }
         }
       }
-
       break;
     }
 
@@ -166,6 +184,50 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const Property::Map& property
       visualPtr = TextVisual::New( *( mFactoryCache.Get() ), propertyMap );
       break;
     }
+
+    case Toolkit::DevelVisual::N_PATCH:
+    {
+      Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
+      std::string imageUrl;
+      if( imageURLValue && imageURLValue->Get( imageUrl ) )
+      {
+        visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
+      }
+      break;
+    }
+
+    case Toolkit::DevelVisual::SVG:
+    {
+      Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
+      std::string imageUrl;
+      if( imageURLValue && imageURLValue->Get( imageUrl ) )
+      {
+        visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
+      }
+      break;
+    }
+
+    case Toolkit::DevelVisual::ANIMATED_IMAGE:
+    {
+      Property::Value* imageURLValue = propertyMap.Find( Toolkit::ImageVisual::Property::URL, IMAGE_URL_NAME );
+      std::string imageUrl;
+      if( imageURLValue )
+      {
+        if( imageURLValue->Get( imageUrl ) )
+        {
+          visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), imageUrl, propertyMap );
+        }
+        else
+        {
+          Property::Array* array = imageURLValue->GetArray();
+          if( array )
+          {
+            visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), *array, propertyMap );
+          }
+        }
+      }
+      break;
+    }
   }
 
   if( !visualPtr )
@@ -220,22 +282,29 @@ Toolkit::Visual::Base VisualFactory::CreateVisual( const std::string& url, Image
   Visual::BasePtr visualPtr;
 
   // first resolve url type to know which visual to create
-  UrlType::Type type = ResolveUrlType( url );
-  if( UrlType::N_PATCH == type )
-  {
-    visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), url );
-  }
-  else if( UrlType::SVG == type )
-  {
-    visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), url );
-  }
-  else if( UrlType::GIF == type )
+  VisualUrl visualUrl( url );
+  switch( visualUrl.GetType() )
   {
-    visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), url );
-  }
-  else // Regular image
-  {
-    visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), url, size );
+    case VisualUrl::N_PATCH:
+    {
+      visualPtr = NPatchVisual::New( *( mFactoryCache.Get() ), visualUrl );
+      break;
+    }
+    case VisualUrl::SVG:
+    {
+      visualPtr = SvgVisual::New( *( mFactoryCache.Get() ), visualUrl );
+      break;
+    }
+    case VisualUrl::GIF:
+    {
+      visualPtr = AnimatedImageVisual::New( *( mFactoryCache.Get() ), visualUrl );
+      break;
+    }
+    case VisualUrl::REGULAR_IMAGE:
+    {
+      visualPtr = ImageVisual::New( *( mFactoryCache.Get() ), visualUrl, size );
+      break;
+    }
   }
 
   if( mDebugEnabled )