Merge "C# Bindings for Transition Policy properties" into devel/master
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / internal / visuals / npatch / npatch-visual.h
index 07918ee..a36f780 100644 (file)
@@ -50,7 +50,8 @@ typedef IntrusivePtr< NPatchVisual > NPatchVisualPtr;
  * | %Property Name           | Type             |
  * |--------------------------|------------------|
  * | url                      | STRING           |
- * | borderOnly               | BOOLEAN
+ * | borderOnly               | BOOLEAN          |
+ * | border                   | RECTANGLE        |
  *
  */
 class NPatchVisual: public Visual::Base
@@ -58,12 +59,16 @@ class NPatchVisual: public Visual::Base
 public:
 
   /**
-   * @brief Create a new n-patch visual.
+   * @brief Create an N-patch visual using an image URL.
+   *
+   * The visual will load the image synchronously when the associated actor is put on stage, and destroy the image when it is off stage
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
+   * @param[in] imageUrl The URL to 9 patch image resource to use
+   * @param[in] properties A Property::Map containing settings for this visual
    * @return A smart-pointer to the newly allocated visual.
    */
-  static NPatchVisualPtr New( VisualFactoryCache& factoryCache );
+  static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, const Property::Map& properties );
 
   /**
    * @brief Create an N-patch visual using an image URL.
@@ -72,25 +77,24 @@ public:
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
    * @param[in] imageUrl The URL to 9 patch image resource to use
-   * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
+   * @return A smart-pointer to the newly allocated visual.
    */
-  static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl, bool borderOnly = false );
+  static NPatchVisualPtr New( VisualFactoryCache& factoryCache, const std::string& imageUrl );
 
   /**
    * @brief Create an N-patch visual with a NinePatchImage resource.
    *
    * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
    * @param[in] image The NinePatchImage to use
-   * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
    */
-  static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image, bool borderOnly = false );
+  static NPatchVisualPtr New( VisualFactoryCache& factoryCache, NinePatchImage image );
 
 public:  // from Visual
 
   /**
    * @copydoc Visual::Base::GetNaturalSize
    */
-  virtual void GetNaturalSize( Vector2& naturalSize ) const;
+  virtual void GetNaturalSize( Vector2& naturalSize );
 
   /**
    * @copydoc Visual::Base::CreatePropertyMap
@@ -98,24 +102,18 @@ public:  // from Visual
   virtual void DoCreatePropertyMap( Property::Map& map ) const;
 
   /**
-   * @copydoc Visual::Base::DoSetProperty
+   * @copydoc Visual::Base::CreateInstancePropertyMap
    */
-  virtual void DoSetProperty( Dali::Property::Index index, const Dali::Property::Value& propertyValue );
-
-  /**
-   * @copydoc Visual::Base::DoGetProperty
-   */
-  virtual Dali::Property::Value DoGetProperty( Dali::Property::Index index );
+  virtual void DoCreateInstancePropertyMap( Property::Map& map ) const;
 
 protected:
 
   /**
    * @brief Constructor.
    *
-   * @param[in] factoryCache A pointer pointing to the VisualFactoryCache object
-   * @param[in] borderOnly A Flag to indicate if the image should omit the centre of the n-patch and only render the border
+   * @param[in] factoryCache Reference to the VisualFactoryCache object
    */
-  NPatchVisual( VisualFactoryCache& factoryCache, bool borderOnly = false );
+  NPatchVisual( VisualFactoryCache& factoryCache );
 
   /**
    * @brief A reference counted object may only be deleted by calling Unreference().
@@ -123,9 +121,9 @@ protected:
   virtual ~NPatchVisual();
 
   /**
-   * @copydoc Visual::Base::DoInitialize
+   * @copydoc Visual::Base::DoSetProperties
    */
-  virtual void DoInitialize( Actor& actor, const Property::Map& propertyMap );
+  virtual void DoSetProperties( const Property::Map& propertyMap );
 
   /**
    * @copydoc Visual::Base::DoSetOnStage
@@ -137,12 +135,12 @@ protected:
    */
   virtual void DoSetOffStage( Actor& actor );
 
-private:
-
   /**
-   * @brief Initialize the renderer with the geometry and shader from the cache, if not available, create and save to the cache for sharing.
+   * @copydoc Visual::Base::OnSetTransform
    */
-  void InitializeRenderer();
+  virtual void OnSetTransform();
+
+private:
 
   /**
    * @brief Creates a geometry for this renderer's grid size
@@ -159,12 +157,24 @@ private:
   Shader CreateShader();
 
   /**
+   * @brief Applies texture and related uniforms
+   */
+  void ApplyTextureAndUniforms();
+
+  /**
+   * Helper method to get the default Nine patch geometry from cache or create and store it there
+   * @param subType to use
+   * @return the geometry
+   */
+  Geometry GetNinePatchGeometry( VisualFactoryCache::GeometryType subType );
+
+  /**
    * @brief Creates a geometry for the grid size to be used by this visuals' shaders
    *
    * @param[in] gridSize The grid size of the solid geometry to create
    * @return Returns the created geometry for the grid size
    */
-  Geometry CreateGeometry( Uint16Pair gridSize );
+  Geometry CreateGridGeometry( Uint16Pair gridSize );
 
   /**
    * @brief Creates a geometry with the border only for the grid size to be used by this visuals' shaders
@@ -187,45 +197,15 @@ private:
    * @param[in] gridSize The grid size of the solid geometry to create
    * @return Returns the created geometry for the grid size
    */
-  Geometry CreateGeometryBorder( Uint16Pair gridSize );
-
-  /**
-   * @brief Creates Image from the image url and parses the image for the stretch borders. Will create a error image if the n patch image is invalid
-   *
-   * @param[in] nPatchImage The NinePatchImage to base our cropped images and stretch borders from
-   */
-  void InitializeFromImage( NinePatchImage nPatchImage );
-
-  /**
-   * @brief Creates an error Image to indicate that there was an error in either the image url or the parsing of the image
-   *
-   */
-  void InitializeFromBrokenImage();
-
-  /**
-   * @brief Applies this renderer's image to the sampler to the texture set used for this renderer
-   */
-  void ApplyImageToSampler();
-
-  /**
-   * @brief Changes the current renderer if the n-patch meta data has changed
-   *
-   * @param[in] oldBorderOnly The old flag indicating if the image should omit the centre of the n-patch and only render the border
-   * @param[in] oldGridX The old horizontal grid size of the solid geometry
-   * @param[in] oldGridY The old vertical grid size of the solid geometry
-   */
-  void ChangeRenderer( bool oldBorderOnly, size_t oldGridX, size_t oldGridY );
+  Geometry CreateBorderGeometry( Uint16Pair gridSize );
 
 private:
 
-  NinePatchImage mImage; ///< The image to render if the visual was set from an NinePatchImage, empty otherwise
-  Image mCroppedImage;
-
-  std::string mImageUrl; ///< The url to the image resource to render if the visual was set from an image resource url, empty otherwise
-  NinePatchImage::StretchRanges mStretchPixelsX;
-  NinePatchImage::StretchRanges mStretchPixelsY;
-  ImageDimensions mImageSize;
-  bool mBorderOnly;
+  NPatchLoader& mLoader;      ///< reference to N patch loader for fast access
+  std::string mImageUrl;      ///< The url to the N patch to load
+  std::size_t mId;            ///< id of the N patch (from loader/cache)
+  bool mBorderOnly;           ///< if only border is desired
+  Rect< int > mBorder;        ///< The size of the border
 };
 
 } // namespace Internal