Merge "Added RenderTask WorldToViewport coordinates" into devel/master
[platform/core/uifw/dali-core.git] / dali / public-api / images / nine-patch-image.h
1 #ifndef __DALI_NINE_PATCH_IMAGE_H__
2 #define __DALI_NINE_PATCH_IMAGE_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
7  * Licensed under the Apache License, Version 2.0 (the "License");
8  * you may not use this file except in compliance with the License.
9  * You may obtain a copy of the License at
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
13  * Unless required by applicable law or agreed to in writing, software
14  * distributed under the License is distributed on an "AS IS" BASIS,
15  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * See the License for the specific language governing permissions and
17  * limitations under the License.
18  *
19  */
20
21 // INTERNAL INCLUDES
22 #include <dali/public-api/images/resource-image.h>
23 #include <dali/public-api/images/buffer-image.h>
24 #include <dali/public-api/math/rect.h>
25
26 namespace Dali
27 {
28 /**
29  * @addtogroup dali_core_images
30  * @{
31  */
32
33 namespace Internal DALI_INTERNAL
34 {
35 class NinePatchImage;
36 }
37
38 /**
39  * @brief NinePatchImage represents a stretchable image resource
40  *
41  * It contains a bitmap that is synchronously loaded from the file system that contains
42  * a 9 patch border - a 1 pixel border that describes the stretch borders and the child
43  * area.
44  *
45  * The class offers an API to read the stretch area and child area, but it does not
46  * remove the border from it's bitmap. An API can be used to obtain a BufferImage with
47  * the border removed.
48  *
49  * Adding this image to an ImageActor using an Image handle will automatically convert
50  * to use the cropped BufferImage - if you don't retain a handle to this object, it will
51  * be automatically destroyed.
52  */
53 class DALI_IMPORT_API NinePatchImage : public ResourceImage
54 {
55 public:
56   typedef Vector< Uint16Pair > StretchRanges;
57
58 public:
59   /**
60    * @brief Constructor which creates an uninitialized NinePatchImage object.
61    *
62    * Use Image::New(...) to create an initialised object.
63    */
64   NinePatchImage();
65
66   /**
67    * @brief Create a new NinePatchImage.
68    *
69    * A pixel buffer for image data is allocated and loaded from the filesystem.
70    * Dali has ownership of the buffer.
71    * @note: default resource management policies are Immediate and Never
72    *
73    * @param [in] filename    File to load synchronously into buffer
74    * @return a handle to a new instance of NinePatchImage
75    */
76   static NinePatchImage New( const std::string& filename );
77
78   /**
79    * @brief Downcast an Object handle to NinePatchImage.
80    *
81    * If handle points to a NinePatchImage the downcast produces valid
82    * handle. If not the returned handle is left uninitialized.
83    *
84    * @param[in] handle to An object
85    * @return handle to a NinePatchImage or an uninitialized handle
86    */
87   static NinePatchImage DownCast( BaseHandle handle );
88
89   /**
90    * @brief Destructor
91    *
92    * This is non-virtual since derived Handle types must not contain data or virtual methods.
93    */
94   ~NinePatchImage();
95
96   /**
97    * @brief This copy constructor is required for (smart) pointer semantics.
98    *
99    * @param [in] handle A reference to the copied handle
100    */
101   NinePatchImage(const NinePatchImage& handle);
102
103   /**
104    * @brief This assignment operator is required for (smart) pointer semantics.
105    *
106    * @param [in] rhs  A reference to the copied handle
107    * @return A reference to this
108    */
109   NinePatchImage& operator=(const NinePatchImage& rhs);
110
111   /**
112    * @deprecated DALi 1.1.4 use GetStretchPixelsX and GetStretchPixelsY instead
113    *
114    * @brief Get the stretch borders
115    *
116    * @return The border in pixels from the left, top, right, and bottom of the image respectively.
117    */
118   Vector4 GetStretchBorders();
119
120   /**
121    * @brief Retrieves the horizontal stretch pixel ranges in the cropped image space
122    *
123    * @since DALi 1.1.4
124    *
125    * @return the horizontal stretch pixel ranges in the cropped image space
126    */
127   const StretchRanges& GetStretchPixelsX();
128
129   /**
130    * @brief Retrieves the vertical stretch pixel ranges in the cropped image space
131    *
132    * @since DALi 1.1.4
133    *
134    * @return the vertical stretch pixel ranges in the cropped image space
135    */
136   const StretchRanges& GetStretchPixelsY();
137
138   /**
139    * @brief Get the child rectangle
140    *
141    * @return the position and size of the child rectangle
142    */
143   Rect<int> GetChildRectangle();
144
145   /**
146    * @brief Creates a buffer image from the bitmap with the 1 pixel border cropped off.
147    *
148    * This does not change the internal bitmap.
149    *
150    * @return The cropped BufferImage
151    */
152   BufferImage CreateCroppedBufferImage();
153
154   /**
155    * @brief Helper method to determine if the filename indicates that the image has a 9 patch or n patch border.
156    *
157    * @since DALi 1.1.4
158    *
159    * @param [in] url The URL of the image file.
160    * @return true if it is a 9 patch or n patch image
161    */
162   static bool IsNinePatchUrl( const std::string& url );
163
164 public: // Not intended for application developers
165
166   explicit DALI_INTERNAL NinePatchImage(Internal::NinePatchImage*);
167 };
168
169 /**
170  * @}
171  */
172 } // namespace Dali
173
174 #endif // __DALI_NINE_PATCH_IMAGE_H__