Remove obsolete and non functional SizeChanged signal from actor
[platform/core/uifw/dali-core.git] / dali / public-api / actors / image-actor.h
1 #ifndef __DALI_IMAGE_ACTOR_H__
2 #define __DALI_IMAGE_ACTOR_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 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
25 #include <dali/public-api/actors/renderable-actor.h>
26 #include <dali/public-api/math/rect.h>
27 #include <dali/public-api/images/image.h>
28
29 namespace Dali
30 {
31
32 namespace Internal DALI_INTERNAL
33 {
34 class ImageActor;
35 }
36
37 /**
38  * @brief An actor for displaying images.
39  *
40  * Allows the developer to add an actor to stage which displays the content of an Image object.
41  *
42  * By default CullFaceMode is set to CullNone to enable the ImageActor to be viewed from all angles.
43  *
44  * If an ImageActor is created without setting size, then the actor takes the size of the image -
45  * this is the natural size.
46  * Setting a size on the ImageActor, e.g through the SetSize api or through an animation will
47  * stop the natural size being used.
48  *
49  * Such a set size can be changed back to the image's size by calling SetToNaturalSize().
50  *
51  * If a pixel area is set on an ImageActor with natural size, the actor size will change
52  * to match the pixel area. If a pixel area is set on an ImageActor that has had it's size set,
53  * then the size doesn't change, and the partial image will be stretched to fill the set size.
54  *
55  * Clearing the pixel area on an Image actor with natural size will cause the actor to show the
56  * whole image again, and will change size back to that of the image.
57  *
58  * Clearing the pixel area on an Image actor with a set size will cause the actor to show the
59  * whole image again, but will not change the image size.
60  */
61 class DALI_IMPORT_API ImageActor : public RenderableActor
62 {
63 public:
64
65   // Default Properties additional to RenderableActor
66   static const Property::Index PIXEL_AREA;           ///< name "pixel-area",          type RECTANGLE
67   static const Property::Index STYLE;                ///< name "style",               type STRING
68   static const Property::Index BORDER;               ///< name "border",              type VECTOR4
69   static const Property::Index IMAGE;                ///< name "image",               type MAP {"filename":"", "load-policy":...}
70
71   /**
72    * @brief Style determines how the Image is rendered.
73    *
74    * @code
75    * STYLE_QUAD:
76    *
77    *  0---------2           0-----------------2
78    *  |        /|           |                /|
79    *  |  A    / |           |      A       /  |
80    *  |      /  |           |            /    |
81    *  |     /   | SCALE (X) |          /      |
82    *  |    /    | --------> |        /        |
83    *  |   /     |           |      /          |
84    *  |  /      |           |    /            |
85    *  | /    B  |           |  /        B     |
86    *  |/        |           |/                |
87    *  1---------3           1-----------------3
88    *
89    * Image is rendered as a textured rectangle. The texture
90    * is scaled uniformly as the quad is resized.
91    *
92    * STYLE_NINE_PATCH:
93    *
94    *  |---|---------------|---|       |---|-----------------------------|---|
95    *  | 1 |       2       | 3 |       | 1 |              2              | 3 |
96    *  |---|---------------|---|       |---|-----------------------------|---|
97    *  |   |               |   |       |   |                             |   |
98    *  |   |               |   |       |   |                             |   |
99    *  | 4 |       5       | 6 | SCALE |   |                             |   |
100    *  |   |               |   | ----> |   |                             |   |
101    *  |   |               |   |       | 4 |              5              | 6 |
102    *  |-------------------|---|       |   |                             |   |
103    *  | 7 |       8       | 9 |       |   |                             |   |
104    *  |---|---------------|---|       |   |                             |   |
105    *                                  |---------------------------------|---|
106    *                                  | 7 |              8              | 9 |
107    *                                  |---|-----------------------------|---|
108    *
109    * Image is rendered as a textured rectangle. The texture
110    * is scaled differently over each of the 9 sections.
111    *
112    * STYLE_NINE_PATCH_NO_CENTER:
113    *
114    * Image is rendered in the same way as STYLE_NINE_PATCH,
115    * but the Center Section (5) is not rendered.
116    * @endcode
117    *
118    * Visualise a Picture Frame:
119    *
120    * - Corner sections (1,3,7,9) are not scaled, regardless
121    * of how big the Image is.
122    * - Horizontal edge sections (2,8) are scaled only in the
123    * X axis as the image increases in width.
124    * - Vertical edge sections (4,6) are scaled only in the
125    * Y axis as the image increases in height.
126    * - Center section (5) is scaled in both X and Y axes as
127    * the image increases in width and/or height.
128    *
129    * Note: If GRID hints are enabled (via a Shader that requires it),
130    * the above geometry will be further subdivided into rectangles of
131    * approx. 40x40 in size. STYLE_NINE_PATCH_NO_CENTER is not supported
132    * yet when GRID hints are enabled.
133    */
134   enum Style
135   {
136     STYLE_QUAD,                 ///< As a simple quad.
137     STYLE_NINE_PATCH,           ///< As a nine-patch.
138     STYLE_NINE_PATCH_NO_CENTER  ///< As a nine-patch without center section being rendered.
139   };
140
141   /**
142    * @brief Pixel area is relative to the top-left (0,0) of the image.
143    */
144   typedef Rect<int> PixelArea;
145
146   /**
147    * @brief Create an uninitialized ImageActor handle.
148    *
149    * This can be initialized with ImageActor::New(...)
150    * Calling member functions with an uninitialized Dali::Object is not allowed.
151    */
152   ImageActor();
153
154   /**
155    * @brief Create an empty image actor object.
156    *
157    * @return A handle to a newly allocated actor.
158    */
159   static ImageActor New();
160
161   /**
162    * @brief Create a image actor object.
163    *
164    * The actor will take the image's natural size unless a custom size
165    * is chosen, e.g. via Actor:SetSize().
166    * If the handle is empty, ImageActor will display nothing
167    * @pre ImageActor must be initialized.
168    * @param[in] image The image to display.
169    * @return A handle to a newly allocated actor.
170    */
171   static ImageActor New(Image image);
172
173   /**
174    * @brief Create a image actor object.
175    *
176    * The actor will take the image's natural size unless a custom size
177    * is chosen, e.g. via Actor:SetSize()
178    * If the handle is empty, ImageActor will display nothing
179    * @pre ImageActor must be initialized.
180    * @param [in] image The image to display.
181    * @param [in] pixelArea The area of the image to display.
182    * This in pixels, relative to the top-left (0,0) of the image.
183    * @return A handle to a newly allocated actor.
184    */
185   static ImageActor New(Image image, PixelArea pixelArea);
186
187   /**
188    * @brief Downcast an Object handle to ImageActor.
189    *
190    *
191    * If handle points to a ImageActor the downcast produces valid
192    * handle. If not the returned handle is left uninitialized.
193    *
194    * @param[in] handle to An object
195    * @return handle to a ImageActor or an uninitialized handle
196    */
197   static ImageActor DownCast( BaseHandle handle );
198
199   /**
200    * @brief Destructor
201    *
202    * This is non-virtual since derived Handle types must not contain data or virtual methods.
203    */
204   ~ImageActor();
205
206   /**
207    * @brief Copy constructor
208    *
209    * @param [in] copy The actor to copy.
210    */
211   ImageActor(const ImageActor& copy);
212
213   /**
214    * @brief Assignment operator
215    *
216    * @param [in] rhs The actor to copy.
217    */
218   ImageActor& operator=(const ImageActor& rhs);
219
220   /**
221    * @brief Set the image rendered by the actor.
222    * Set the image rendered by the actor.
223    * If actor was already displaying a different image, the old image is dropped and actor may
224    * temporarily display nothing. Setting an empty image (handle) causes the current image to be
225    * dropped and actor displays nothing.
226    * The actor will take the image's natural size unless a custom size
227    * is chosen, e.g. via Actor:SetSize()
228    *
229    * @pre ImageActor must be initialized.
230    * @param [in] image The image to display.
231    */
232   void SetImage(Image image);
233
234   /**
235    * @brief Retrieve the image rendered by the actor.
236    *
237    * If no image is assigned, an empty handle is returned
238    * @return The image.
239    */
240   Image GetImage();
241
242   /**
243    * @brief Tell the image actor to use the natural size of the current image
244    * or future images.
245    *
246    * Calling SetSize on this actor or animating the size of the actor
247    * overrides this behaviour.
248    *
249    * @post The image actor uses the natural image size after an image
250    * has been loaded.
251    */
252   void SetToNaturalSize();
253
254   /**
255    * @brief Set a region of the image to display, in pixels.
256    *
257    * When the image is loaded the actor's size will be reset to the pixelArea,
258    * unless a custom size was chosen, e.g. via Actor:SetSize().
259    * Note! PixelArea should be inside the image data size. It gets clamped by GL
260    * @pre image must be initialized.
261    * @param [in] pixelArea The area of the image to display.
262    * This in pixels, relative to the top-left (0,0) of the image.
263    */
264   void SetPixelArea(const PixelArea& pixelArea);
265
266   /**
267    * @brief Retrieve the region of the image to display, in pixels.
268    *
269    * @pre image must be initialized.
270    * @return The pixel area, or a default-constructed area if none was set.
271    */
272   PixelArea GetPixelArea() const;
273
274   /**
275    * @brief Query whether a pixel area has been set.
276    *
277    * @pre image must be initialized.
278    * @return True if a pixel area has been set.
279    */
280   bool IsPixelAreaSet() const;
281
282   /**
283    * @brief Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
284    *
285    * The actor size will change to that of the Image unless a custom size was set, e.g. via
286    * Actor::SetSize().
287    * @pre image must be initialized.
288    */
289   void ClearPixelArea();
290
291   /**
292    * @brief Set how the image is rendered; the default is STYLE_QUAD.
293    *
294    * @pre image must be initialized.
295    * @param [in] style The new style.
296    */
297   void SetStyle(Style style);
298
299   /**
300    * @brief Query how the image is rendered.
301    *
302    * @pre image must be initialized.
303    * @return The rendering style.
304    */
305   Style GetStyle() const;
306
307   /**
308    * @brief Set the border used with STYLE_NINE_PATCH.
309    *
310    * The values are in pixels from the left, top, right, and bottom of the image respectively.
311    * i.e. SetNinePatchBorder( Vector4(1,2,3,4) ) sets the left-border to 1, top-border to 2, right-border to 3, and bottom-border to 4 pixels.
312    * @param [in] border The new nine-patch border.
313    */
314   void SetNinePatchBorder(const Vector4& border);
315
316   /**
317    * @brief Retrieve the border used with STYLE_NINE_PATCH.
318    *
319    * @return The nine-patch border.
320    */
321   Vector4 GetNinePatchBorder() const;
322
323 public: // Not intended for application developers
324
325   explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
326 };
327
328 } // namespace Dali
329
330 #endif // __DALI_IMAGE_ACTOR_H__