Cleaning up RendererFactory API
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / renderer-factory / renderer-factory.h
index 3c3cec7..52e0d5c 100644 (file)
 
 // EXTERNAL INCLUDES
 #include <dali/public-api/object/base-handle.h>
+#include <dali/public-api/images/image-operations.h>
+#include <dali/public-api/object/property-map.h>
 
 // INTERNAK INCLUDES
 #include <dali-toolkit/devel-api/controls/renderer-factory/control-renderer.h>
 
 namespace Dali
 {
+class Image;
+class Vector4;
 
 namespace Toolkit
 {
@@ -35,13 +39,15 @@ class RendererFactory;
 }
 
 /**
- * RendererFactory is a singleton object that provides and shares renderers for controls
+ * @brief RendererFactory is a singleton object that provides and shares renderers for controls
+ *
+ * By setting environment variable 'DALI_DEBUG_RENDERING', all concrete renderer is replaced with the debug renderer which renders a quad wireframe.
  *
  * The renderer type is required in the property map for requesting a control renderer.
  *
- * | %Property Name            | Type             |
- * |---------------------------|------------------|
- * | renderer-type             | STRING           |
+ * | %Property Name           | Type             |
+ * |--------------------------|------------------|
+ * | rendererType             | STRING           |
  */
 class DALI_IMPORT_API RendererFactory : public BaseHandle
 {
@@ -84,12 +90,30 @@ public:
   RendererFactory& operator=( const RendererFactory& handle );
 
   /**
-   * Request the control renderer
+   * @brief Request the control renderer
+   *
    * @param[in] propertyMap The map contains the properties required by the control renderer
    *            Depends on the content of the map, different kind of renderer would be returned.
-   * @return the  pointer pointing to control renderer
+   * @return The pointer pointing to control renderer
+   */
+  ControlRenderer CreateControlRenderer( const Property::Map& propertyMap  );
+
+  /**
+   * @brief Request the control renderer to render the image.
+   *
+   * @param[in] image The image to be rendered.
+   * @return The pointer pointing to the control renderer
    */
-  ControlRenderer GetControlRenderer( const Property::Map& propertyMap  );
+  ControlRenderer CreateControlRenderer( const Image& image );
+
+  /**
+   * @brief Request the control renderer to render the given resource at the url.
+   *
+   * @param[in] url The URL to the resource to be rendered.
+   * @param[in] size The width and height to fit the loaded image to.
+   * @return The pointer pointing to the control renderer
+   */
+  ControlRenderer CreateControlRenderer( const std::string& url, ImageDimensions size );
 
 private:
 
@@ -97,8 +121,52 @@ private:
 
 };
 
+
+/**
+ * @brief Template to allow discard old renderer, get new one and set it on stage if possible
+ *
+ * @tparam ParameterType0 The type of first argument passed to the CreateControlRenderer()
+ * @tparam ParameterType1 The type of second argument passed to the CreateControlRenderer()
+ * @SINCE_1_0.39
+ * @param[in] actor Actor for which the renderer will be replaced
+ * @param[in,out] renderer The renderer object to be replaced
+ * @param[in] param0 First template based argument passed to the renderer factory
+ * @param[in] param1 Second template based argument passed to the renderer factory
+ */
+template< class ParameterType0, class ParameterType1 >
+void InitializeControlRenderer( Actor& actor, ControlRenderer& renderer, ParameterType0& param0, ParameterType1& param1 )
+{
+  renderer.RemoveAndReset( actor );
+  renderer = Toolkit::RendererFactory::Get().CreateControlRenderer( param0, param1 );
+  if( renderer && actor && actor.OnStage() )
+  {
+    renderer.SetOnStage( actor );
+  }
+}
+
+/**
+ * @brief Template to allow discard old renderer, get new one and set it on stage if possible
+ *
+ * @tparam ParameterType The type of argument passed to the CreateControlRenderer()
+ * @SINCE_1_0.39
+ * @param[in] actor Actor for which the renderer will be replaced
+ * @param[in,out] renderer The renderer object to be replaced
+ * @param[in] param Template based argument passed to the renderer factory
+ */
+template< class ParameterType >
+void InitializeControlRenderer( Actor& actor, ControlRenderer& renderer, ParameterType& param )
+{
+  renderer.RemoveAndReset( actor );
+  renderer =  Toolkit::RendererFactory::Get().CreateControlRenderer( param );
+  if( renderer && actor && actor.OnStage() )
+  {
+    renderer.SetOnStage( actor );
+  }
+}
+
 } // namespace Toolkit
 
 } // namespace Dali
 
+
 #endif /* __DALI_TOOLKIT_RENDERER_FACTORY_H__ */