Revert "Revert TextVisual in TextLabel Patches"
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / visual-factory-impl.h
index 5a54a68..030512e 100644 (file)
@@ -2,7 +2,7 @@
 #define DALI_TOOLKIT_VISUAL_FACTORY_IMPL_H
 
 /*
- * Copyright (c) 2015 Samsung Electronics Co., Ltd.
+ * Copyright (c) 2016 Samsung Electronics Co., Ltd.
  *
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
@@ -22,7 +22,8 @@
 
 // INTERNAL INCLUDES
 #include <dali-toolkit/devel-api/visual-factory/visual-factory.h>
-#include <dali-toolkit/devel-api/visual-factory/visual.h>
+#include <dali-toolkit/devel-api/visual-factory/visual-base.h>
+#include <dali-toolkit/internal/visuals/visual-base-impl.h>
 
 namespace Dali
 {
@@ -36,9 +37,6 @@ namespace Internal
 class VisualFactoryCache;
 typedef IntrusivePtr<VisualFactoryCache> VisualFactoryCachePtr;
 
-class ImageAtlasManager;
-typedef IntrusivePtr<ImageAtlasManager> ImageAtlasManagerPtr;
-
 /**
  * @copydoc Toolkit::VisualFactory
  */
@@ -46,19 +44,6 @@ class VisualFactory : public BaseObject
 {
 public:
 
-  enum RendererType
-  {
-    COLOR,
-    BORDER,
-    GRADIENT,
-    IMAGE,
-    N_PATCH,
-    SVG,
-    MESH,
-    PRIMITIVE,
-    UNDEFINED
-  };
-
   /**
    * @brief Constructor
    *
@@ -69,23 +54,17 @@ public:
   /**
    * @copydoc Toolkit::RenderFactory::CreateVisual( const Property::Map& )
    */
-  Toolkit::Visual CreateVisual( const Property::Map& propertyMap );
+  Toolkit::Visual::Base CreateVisual( const Property::Map& propertyMap );
 
   /**
    * @copydoc Toolkit::RenderFactory::CreateVisual( const Image& )
    */
-  Toolkit::Visual CreateVisual( const Image& image );
+  Toolkit::Visual::Base CreateVisual( const Image& image );
 
   /**
    * @copydoc Toolkit::RenderFactory::CreateVisual( const std::string&, ImageDimensions )
    */
-  Toolkit::Visual CreateVisual( const std::string& image, ImageDimensions size );
-
-public:
-  /**
-   * @brief Returns an image to be used when a renderer has failed to correctly render
-   */
-  static Image GetBrokenRendererImage();
+  Toolkit::Visual::Base CreateVisual( const std::string& image, ImageDimensions size );
 
 protected:
 
@@ -97,19 +76,6 @@ protected:
 private:
 
   /**
-   * Get the visual type from the property map.
-   *
-   * @param[in] propertyMap The map contains the properties of the visual
-   * @return The rendererType
-   */
-  RendererType GetRendererType( const Property::Map& propertyMap );
-
-  /**
-   * Prepare the atlas manager
-   */
-  void CreateAtlasManager();
-
-  /**
    * Undefined copy constructor.
    */
   VisualFactory(const VisualFactory&);
@@ -122,10 +88,57 @@ private:
 private:
 
   VisualFactoryCachePtr   mFactoryCache;
-  ImageAtlasManagerPtr    mAtlasManager;
   bool                    mDebugEnabled;
 };
 
+/**
+ * @brief Template to allow discard old visual, get new one and set it on stage if possible
+ *
+ * @tparam ParameterType0 The type of first argument passed to the CreateVisual()
+ * @tparam ParameterType1 The type of second argument passed to the CreateVisual()
+ * @SINCE_1_0.39
+ * @param[in] actor Actor for which the visual will be replaced
+ * @param[in,out] visual The visual to be replaced
+ * @param[in] param0 First template based argument passed to the visual factory
+ * @param[in] param1 Second template based argument passed to the visual factory
+ */
+template< class ParameterType0, class ParameterType1 >
+void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType0& param0, ParameterType1& param1 )
+{
+  if( actor )
+  {
+    Toolkit::GetImplementation(visual).SetOffStage( actor );
+  }
+  visual = Toolkit::VisualFactory::Get().CreateVisual( param0, param1 );
+  if( visual && actor && actor.OnStage() )
+  {
+    Toolkit::GetImplementation(visual).SetOnStage(actor);
+  }
+}
+
+/**
+ * @brief Template to allow discard old visual, get new one and set it on stage if possible
+ *
+ * @tparam ParameterType The type of argument passed to the CreateVisual()
+ * @SINCE_1_0.39
+ * @param[in] actor Actor for which the visual will be replaced
+ * @param[in,out] visual The visual to be replaced
+ * @param[in] param Template based argument passed to the visual factory
+ */
+template< class ParameterType >
+void InitializeVisual( Actor& actor, Toolkit::Visual::Base& visual, ParameterType& param )
+{
+  if( actor && visual )
+  {
+    Toolkit::GetImplementation(visual).SetOffStage( actor );
+  }
+  visual =  Toolkit::VisualFactory::Get().CreateVisual( param );
+  if( visual && actor && actor.OnStage() )
+  {
+    Toolkit::GetImplementation(visual).SetOnStage(actor);
+  }
+}
+
 } // namespace Internal
 
 inline const Internal::VisualFactory& GetImplementation(const Toolkit::VisualFactory& factory)