1 #ifndef __DALI_NINE_PATCH_IMAGE_H__
2 #define __DALI_NINE_PATCH_IMAGE_H__
5 * Copyright (c) 2015 Samsung Electronics Co., Ltd.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
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>
29 * @addtogroup dali_core_images
33 namespace Internal DALI_INTERNAL
39 * @brief NinePatchImage represents a stretchable image resource
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
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
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.
54 class DALI_IMPORT_API NinePatchImage : public ResourceImage
57 typedef Vector< Uint16Pair > StretchRanges;
61 * @brief Constructor which creates an uninitialized NinePatchImage object.
63 * Use Image::New(...) to create an initialised object.
69 * @brief Create a new NinePatchImage.
71 * A pixel buffer for image data is allocated and loaded from the filesystem.
72 * Dali has ownership of the buffer.
73 * @note: default resource management policies are Immediate and Never
76 * @param [in] filename File to load synchronously into buffer
77 * @return a handle to a new instance of NinePatchImage
79 static NinePatchImage New( const std::string& filename );
82 * @brief Downcast an Object handle to NinePatchImage.
84 * If handle points to a NinePatchImage the downcast produces valid
85 * handle. If not the returned handle is left uninitialized.
88 * @param[in] handle to An object
89 * @return handle to a NinePatchImage or an uninitialized handle
91 static NinePatchImage DownCast( BaseHandle handle );
96 * This is non-virtual since derived Handle types must not contain data or virtual methods.
102 * @brief This copy constructor is required for (smart) pointer semantics.
105 * @param [in] handle A reference to the copied handle
107 NinePatchImage(const NinePatchImage& handle);
110 * @brief This assignment operator is required for (smart) pointer semantics.
113 * @param [in] rhs A reference to the copied handle
114 * @return A reference to this
116 NinePatchImage& operator=(const NinePatchImage& rhs);
119 * @DEPRECATED_1_1.4. Use GetStretchPixelsX and GetStretchPixelsY instead.
121 * @brief Get the stretch borders
124 * @return The border in pixels from the left, top, right, and bottom of the image respectively.
126 Vector4 GetStretchBorders();
129 * @brief Retrieves the horizontal stretch pixel ranges in the cropped image space
132 * @return the horizontal stretch pixel ranges in the cropped image space
134 const StretchRanges& GetStretchPixelsX();
137 * @brief Retrieves the vertical stretch pixel ranges in the cropped image space
140 * @return the vertical stretch pixel ranges in the cropped image space
142 const StretchRanges& GetStretchPixelsY();
145 * @brief Get the child rectangle
148 * @return the position and size of the child rectangle
150 Rect<int> GetChildRectangle();
153 * @brief Creates a buffer image from the bitmap with the 1 pixel border cropped off.
155 * This does not change the internal bitmap.
158 * @return The cropped BufferImage
160 BufferImage CreateCroppedBufferImage();
163 * @brief Helper method to determine if the filename indicates that the image has a 9 patch or n patch border.
166 * @param [in] url The URL of the image file.
167 * @return true if it is a 9 patch or n patch image
169 static bool IsNinePatchUrl( const std::string& url );
171 public: // Not intended for application developers
173 explicit DALI_INTERNAL NinePatchImage(Internal::NinePatchImage*);
181 #endif // __DALI_NINE_PATCH_IMAGE_H__