Rename BitmapImage as BufferImage
[platform/core/uifw/dali-core.git] / dali / internal / event / images / nine-patch-image-impl.h
1 #ifndef __DALI_INTERNAL_NINE_PATCH_IMAGE_H__
2 #define __DALI_INTERNAL_NINE_PATCH_IMAGE_H__
3
4 /*
5  * Copyright (c) 2014 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/nine-patch-image.h>
23 #include <dali/internal/event/images/resource-image-impl.h>
24 #include <dali/internal/event/images/buffer-image-impl.h>
25
26 namespace Dali
27 {
28
29 namespace Internal
30 {
31
32 class NinePatchImage;
33 typedef IntrusivePtr<NinePatchImage> NinePatchImagePtr;
34
35 class ResourceClient;
36 class ResourceManager;
37
38 namespace SceneGraph
39 {
40 class UpdateManager;
41 }
42
43 /**
44  * NinePatchImage represents an image resource that can be added to actors etc.
45  * It's image data has a border which determines stretch and fill areas
46  * Its pixel buffer data is loaded synchronously from file.
47  */
48 class NinePatchImage : public ResourceImage
49 {
50 public:
51
52   /**
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
57    * @param [in] attributes  Image attributes of the file
58    * @param [in] releasePol  optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
59    */
60   static NinePatchImagePtr New( const std::string& filename,
61                                 const ImageAttributes& attributes,
62                                 ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT );
63
64   /**
65    * Create a new NinePatchImage
66    * For better performance and portability use power of two dimensions.
67    * The maximum size of the image is limited by GL_MAX_TEXTURE_SIZE.
68    * @param [in] filename    File to load synchronously into buffer
69    * @param [in] attributes  Image attributes of the file
70    * @param [in] releasePol  optionally relase memory when image is not visible on screen (default: keep image data until Image object is alive).
71    */
72   NinePatchImage( const std::string& filename,
73                   const ImageAttributes& attributes,
74                   ReleasePolicy releasePol = IMAGE_RELEASE_POLICY_DEFAULT );
75
76   /**
77    * Convert Image object to a 9 patch image object if possible.
78    * @param[in] image The image to convert
79    * @return A pointer to the 9 patch image object, or NULL
80    * if the conversion is not possible.
81    */
82   static NinePatchImage* DownCast( Image* image);
83
84
85 protected:
86   /**
87    * A reference counted object may only be deleted by calling Unreference()
88    */
89   virtual ~NinePatchImage();
90
91 public:
92   /**
93    * Get the stretch borders
94    * @return The border in pixels from the left, top, right, and bottom of the image respectively.
95    */
96   Vector4 GetStretchBorders();
97
98   /**
99    * Get the child rectangle
100    * @return the position and size of the child rectangle
101    */
102   Rect<int> GetChildRectangle();
103
104   /**
105    * @brief Create a cropped image from the bitmap with the 1 pixel border cropped off.
106    * This does not change the internal bitmap.
107    *
108    * @return the cropped bitmap.
109    */
110   BufferImagePtr CreateCroppedBufferImage();
111
112
113 protected: // From Resource
114   /**
115    * @copydoc Dali::Internal::Image::Connect
116    */
117   virtual void Connect();
118
119   /**
120    * @copydoc Dali::Internal::Image::Disconnect
121    */
122   virtual void Disconnect();
123
124 private:
125   /**
126    * Read the borders of the bitmap and determine the child area
127    * and stretch borders
128    */
129   void ParseBorders();
130
131 private:
132   ResourceClient*               mResourceClient;
133   Integration::BitmapPtr        mBitmap;
134   Vector4                       mStretchBorders;
135   Rect<int>                     mChildRectangle;
136   bool                          mParsedBorder;
137 };
138
139 } // namespace Internal
140
141 /**
142  * Helper methods for public API.
143  */
144 inline Internal::NinePatchImage& GetImplementation(Dali::NinePatchImage& handle)
145 {
146   DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
147
148   BaseObject& image = handle.GetBaseObject();
149
150   return static_cast<Internal::NinePatchImage&>(image);
151 }
152
153 inline const Internal::NinePatchImage& GetImplementation(const Dali::NinePatchImage& handle)
154 {
155   DALI_ASSERT_ALWAYS( handle && "NinePatchImage handle is empty" );
156
157   const BaseObject& image = handle.GetBaseObject();
158
159   return static_cast<const Internal::NinePatchImage&>(image);
160 }
161
162 } // namespace Dali
163
164 #endif // __DALI_INTERNAL_NINE_PATCH_IMAGE_H__