904ec72b2d8b002b70bb7fd35243374ff4b37761
[platform/core/uifw/dali-core.git] / dali / devel-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) 2017 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 an nine-patch 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  * If you don't retain a handle to this object, it will be automatically destroyed.
50  * @SINCE_1_0.0
51  */
52 class DALI_IMPORT_API NinePatchImage : public ResourceImage
53 {
54 public:
55   typedef Vector< Uint16Pair > StretchRanges;
56
57 public:
58   /**
59    * @brief Constructor which creates an uninitialized NinePatchImage object.
60    *
61    * Use @ref NinePatchImage::New to create an initialised object.
62    * @SINCE_1_0.0
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    * @SINCE_1_0.0
72    * @param [in] filename File to load synchronously into buffer
73    * @return A handle to a new instance of NinePatchImage
74    */
75   static NinePatchImage New( const std::string& filename );
76
77   /**
78    * @brief Downcast a handle to NinePatchImage handle.
79    *
80    * If handle points to a NinePatchImage the downcast produces valid
81    * handle. If not the returned handle is left uninitialized.
82    *
83    * @SINCE_1_0.0
84    * @param[in] handle 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    * @SINCE_1_0.0
94    */
95   ~NinePatchImage();
96
97   /**
98    * @brief This copy constructor is required for (smart) pointer semantics.
99    *
100    * @SINCE_1_0.0
101    * @param [in] handle A reference to the copied handle
102    */
103   NinePatchImage(const NinePatchImage& handle);
104
105   /**
106    * @brief This assignment operator is required for (smart) pointer semantics.
107    *
108    * @SINCE_1_0.0
109    * @param [in] rhs  A reference to the copied handle
110    * @return A reference to this
111    */
112   NinePatchImage& operator=(const NinePatchImage& rhs);
113
114   /**
115    * @DEPRECATED_1_1.4. Use GetStretchPixelsX and GetStretchPixelsY instead.
116    *
117    * @brief Get the stretch borders
118    *
119    * @SINCE_1_0.0
120    * @return The border in pixels from the left, top, right, and bottom of the image respectively.
121    */
122   Vector4 GetStretchBorders();
123
124   /**
125    * @brief Retrieves the horizontal stretch pixel ranges in the cropped image space
126    *
127    * @SINCE_1_1.4
128    * @return the horizontal stretch pixel ranges in the cropped image space
129    */
130   const StretchRanges& GetStretchPixelsX();
131
132   /**
133    * @brief Retrieves the vertical stretch pixel ranges in the cropped image space
134    *
135    * @SINCE_1_1.4
136    * @return the vertical stretch pixel ranges in the cropped image space
137    */
138   const StretchRanges& GetStretchPixelsY();
139
140   /**
141    * @brief Get the child rectangle
142    *
143    * @SINCE_1_0.0
144    * @return The position and size of the child rectangle
145    */
146   Rect<int> GetChildRectangle();
147
148   /**
149    * @brief Creates a buffer image from the bitmap with the 1 pixel border cropped off.
150    *
151    * This does not change the internal bitmap.
152    *
153    * @SINCE_1_0.0
154    * @return The cropped BufferImage
155    */
156   BufferImage CreateCroppedBufferImage();
157
158   /**
159    * @brief Helper method to determine if the filename indicates that the image has a 9 patch or n patch border.
160    *
161    * @SINCE_1_1.4
162    * @param [in] url The URL of the image file.
163    * @return true if it is a 9 patch or n patch image
164    */
165   static bool IsNinePatchUrl( const std::string& url );
166
167 public: // Not intended for application developers
168
169   explicit DALI_INTERNAL NinePatchImage(Internal::NinePatchImage*);
170 };
171
172 /**
173  * @}
174  */
175 } // namespace Dali
176
177 #endif // __DALI_NINE_PATCH_IMAGE_H__