1 #ifndef __DALI_INTERNAL_NINE_PATCH_IMAGE_H__
2 #define __DALI_INTERNAL_NINE_PATCH_IMAGE_H__
5 * Copyright (c) 2014 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/nine-patch-image.h>
23 #include <dali/internal/event/images/bitmap-image-impl.h>
32 typedef IntrusivePtr<NinePatchImage> NinePatchImagePtr;
35 class ResourceManager;
43 * NinePatchImage represents an image resource that can be added to actors etc.
44 * It's image data has a border which determines stretch and fill areas
45 * Its pixel buffer data is loaded synchronously from file.
47 class NinePatchImage : public Image
52 * Create a new NinePatchImage.
53 * Also a pixel buffer for image data is allocated.
54 * Dali has ownership of the buffer.
55 * @param [in] filename File to load synchronously into buffer
56 * @param [in] attributes Image attributes of the file
57 * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created).
58 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
60 static NinePatchImagePtr New( const std::string& filename,
61 const ImageAttributes& attributes,
62 LoadPolicy loadPol = ImageLoadPolicyDefault,
63 ReleasePolicy releasePol = ImageReleasePolicyDefault );
66 * Create a new NinePatchImage
67 * For better performance and portability use power of two dimensions.
68 * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
69 * @param [in] filename File to load synchronously into buffer
70 * @param [in] attributes Image attributes of the file
71 * @param [in] loadPol controls time of loading a resource from the filesystem (default: load when Image is created).
72 * @param [in] releasePol optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
74 NinePatchImage( const std::string& filename,
75 const ImageAttributes& attributes,
76 LoadPolicy loadPol = ImageLoadPolicyDefault,
77 ReleasePolicy releasePol = ImageReleasePolicyDefault );
80 * Convert Image object to a 9 patch image object if possible.
81 * @param[in] image The image to convert
82 * @return A pointer to the 9 patch image object, or NULL
83 * if the conversion is not possible.
85 static NinePatchImage* GetNinePatchImage( Image* image);
90 * A reference counted object may only be deleted by calling Unreference()
92 virtual ~NinePatchImage();
96 * Get the stretch borders
97 * @return The border in pixels from the left, top, right, and bottom of the image respectively.
99 Vector4 GetStretchBorders();
102 * Get the child rectangle
103 * @return the position and size of the child rectangle
105 Rect<int> GetChildRectangle();
108 * @brief Create a cropped image from the bitmap with the 1 pixel border cropped off.
109 * This does not change the internal bitmap.
111 * @return the cropped bitmap.
113 BitmapImagePtr CreateCroppedBitmapImage();
116 protected: // From Resource
118 * @copydoc Dali::Internal::Image::Connect
120 virtual void Connect();
123 * @copydoc Dali::Internal::Image::Disconnect
125 virtual void Disconnect();
129 * Read the borders of the bitmap and determine the child area
130 * and stretch borders
135 ResourceClient* mResourceClient;
136 Integration::BitmapPtr mBitmap;
137 Vector4 mStretchBorders;
138 Rect<int> mChildRectangle;
142 } // namespace Internal
145 * Helper methods for public API.
147 inline Internal::NinePatchImage& GetImplementation(Dali::NinePatchImage& handle)
149 DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
151 BaseObject& image = handle.GetBaseObject();
153 return static_cast<Internal::NinePatchImage&>(image);
156 inline const Internal::NinePatchImage& GetImplementation(const Dali::NinePatchImage& handle)
158 DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
160 const BaseObject& image = handle.GetBaseObject();
162 return static_cast<const Internal::NinePatchImage&>(image);
167 #endif // __DALI_INTERNAL_NINE_PATCH_IMAGE_H__