1 #ifndef DALI_INTERNAL_NINE_PATCH_IMAGE_H
2 #define DALI_INTERNAL_NINE_PATCH_IMAGE_H
5 * Copyright (c) 2019 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/devel-api/images/nine-patch-image.h>
23 #include <dali/internal/event/images/resource-image-impl.h>
24 #include <dali/internal/event/images/buffer-image-impl.h>
33 typedef IntrusivePtr<NinePatchImage> NinePatchImagePtr;
41 * NinePatchImage represents an image resource that can be added to actors etc.
42 * It's image data has a border which determines stretch and fill areas
43 * Its pixel buffer data is loaded synchronously from file.
45 class NinePatchImage : public ResourceImage
48 typedef Dali::Vector< Uint16Pair > StretchRanges;
53 * Create a new NinePatchImage.
54 * Also a pixel buffer for image data is allocated.
55 * Dali has ownership of the buffer.
56 * @param [in] filename File to load synchronously into buffer
58 static NinePatchImagePtr New( const std::string& filename );
61 * Create a new NinePatchImage
62 * For better performance and portability use power of two dimensions.
63 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
64 * @param [in] filename File to load synchronously into buffer
66 NinePatchImage( const std::string& filename );
69 * Convert Image object to a 9 patch image object if possible.
70 * @param[in] image The image to convert
71 * @return A pointer to the 9 patch image object, or NULL
72 * if the conversion is not possible.
74 static NinePatchImage* DownCast( Image* image);
79 * A reference counted object may only be deleted by calling Unreference()
81 virtual ~NinePatchImage();
85 * @copydoc Dali::NinePatchImage::GetStretchPixelsX
87 const StretchRanges& GetStretchPixelsX();
90 * @copydoc Dali::NinePatchImage::GetStretchPixelsY
92 const StretchRanges& GetStretchPixelsY();
95 * Get the child rectangle
96 * @return the position and size of the child rectangle
98 Rect<int> GetChildRectangle();
101 * @brief Create a cropped image from the bitmap with the 1 pixel border cropped off.
102 * This does not change the internal bitmap.
104 * @return the cropped bitmap.
106 BufferImagePtr CreateCroppedBufferImage();
110 * @copydoc Dali::NinePatchImage::
112 static bool IsNinePatchUrl( const std::string& url );
114 private: // from ResourceImage
117 * @copydoc ResourceImage::GetUrl()
119 virtual const std::string& GetUrl() const;
122 * Read the borders of the bitmap and determine the child area
123 * and stretch borders
127 Uint16Pair ParseRange( unsigned int& index, unsigned int width, const PixelBuffer* & pixel, unsigned int pixelStride, int testByte, int testBits, int testValue );
130 Integration::BitmapPtr mBitmap;
132 StretchRanges mStretchPixelsX; //< The horizontal stretchable pixels in the cropped image space
133 StretchRanges mStretchPixelsY; //< The vertical stretchable pixels in the cropped image space
134 Rect<int> mChildRectangle;
138 } // namespace Internal
141 * Helper methods for public API.
143 inline Internal::NinePatchImage& GetImplementation(Dali::NinePatchImage& handle)
145 DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
147 BaseObject& image = handle.GetBaseObject();
149 return static_cast<Internal::NinePatchImage&>(image);
152 inline const Internal::NinePatchImage& GetImplementation(const Dali::NinePatchImage& handle)
154 DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
156 const BaseObject& image = handle.GetBaseObject();
158 return static_cast<const Internal::NinePatchImage&>(image);
163 #endif // DALI_INTERNAL_NINE_PATCH_IMAGE_H