1 #ifndef __DALI_IMAGE_ACTOR_H__
2 #define __DALI_IMAGE_ACTOR_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.
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>
29 namespace Dali DALI_IMPORT_API
32 namespace Internal DALI_INTERNAL
38 * @brief An actor for displaying images.
40 * Allows the developer to add an actor to stage which displays the content of an Image object.
42 * By default CullFaceMode is set to CullNone to enable the ImageActor to be viewed from all angles.
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.
49 * Such a set size can be changed back to the image's size by calling SetToNaturalSize().
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.
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.
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.
61 class DALI_IMPORT_API ImageActor : public RenderableActor
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":...}
72 * @brief Style determines how the Image is rendered.
77 * 0---------2 0-----------------2
81 * | / | SCALE (X) | / |
82 * | / | --------> | / |
87 * 1---------3 1-----------------3
89 * Image is rendered as a textured rectangle. The texture
90 * is scaled uniformly as the quad is resized.
94 * |---|---------------|---| |---|-----------------------------|---|
95 * | 1 | 2 | 3 | | 1 | 2 | 3 |
96 * |---|---------------|---| |---|-----------------------------|---|
99 * | 4 | 5 | 6 | SCALE | | | |
100 * | | | | ----> | | | |
101 * | | | | | 4 | 5 | 6 |
102 * |-------------------|---| | | | |
103 * | 7 | 8 | 9 | | | | |
104 * |---|---------------|---| | | | |
105 * |---------------------------------|---|
107 * |---|-----------------------------|---|
110 * Image is rendered as a textured rectangle. The texture
111 * is scaled differently over each of the 9 sections.
113 * Visualise a Picture Frame:
115 * - Corner sections (1,3,7,9) are not scaled, regardless
116 * of how big the Image is.
117 * - Horizontal edge sections (2,8) are scaled only in the
118 * X axis as the image increases in width.
119 * - Vertical edge sections (4,6) are scaled only in the
120 * Y axis as the image increases in height.
121 * - Center section (5) is scaled in both X and Y axes as
122 * the image increases in width and/or height.
124 * Note: If GRID hints are enabled (via a Shader that requires it),
125 * the above geometry will be further subdivided into rectangles of
126 * approx. 40x40 in size.
131 STYLE_QUAD, ///< As a simple quad.
132 STYLE_NINE_PATCH ///< As a nine-patch.
136 * @brief Pixel area is relative to the top-left (0,0) of the image.
138 typedef Rect<int> PixelArea;
141 * @brief Create an uninitialized ImageActor handle.
143 * This can be initialized with ImageActor::New(...)
144 * Calling member functions with an uninitialized Dali::Object is not allowed.
149 * @brief Create an empty image actor object.
151 * @return A handle to a newly allocated actor.
153 static ImageActor New();
156 * @brief Create a image actor object.
158 * The actor will take the image's natural size unless a custom size
159 * is chosen, e.g. via Actor:SetSize().
160 * If the handle is empty, ImageActor will display nothing
161 * @pre ImageActor must be initialized.
162 * @param[in] image The image to display.
163 * @return A handle to a newly allocated actor.
165 static ImageActor New(Image image);
168 * @brief Create a image actor object.
170 * The actor will take the image's natural size unless a custom size
171 * is chosen, e.g. via Actor:SetSize()
172 * If the handle is empty, ImageActor will display nothing
173 * @pre ImageActor must be initialized.
174 * @param [in] image The image to display.
175 * @param [in] pixelArea The area of the image to display.
176 * This in pixels, relative to the top-left (0,0) of the image.
177 * @return A handle to a newly allocated actor.
179 static ImageActor New(Image image, PixelArea pixelArea);
182 * @brief Downcast an Object handle to ImageActor.
185 * If handle points to a ImageActor the downcast produces valid
186 * handle. If not the returned handle is left uninitialized.
188 * @param[in] handle to An object
189 * @return handle to a ImageActor or an uninitialized handle
191 static ImageActor DownCast( BaseHandle handle );
196 * This is non-virtual since derived Handle types must not contain data or virtual methods.
201 * @brief Copy constructor
203 * @param [in] copy The actor to copy.
205 ImageActor(const ImageActor& copy);
208 * @brief Assignment operator
210 * @param [in] rhs The actor to copy.
212 ImageActor& operator=(const ImageActor& rhs);
215 * @brief This method is defined to allow assignment of the NULL value,
216 * and will throw an exception if passed any other value.
218 * Assigning to NULL is an alias for Reset().
219 * @param [in] rhs A NULL pointer
220 * @return A reference to this handle
222 ImageActor& operator=(BaseHandle::NullType* rhs);
225 * @brief Set the image rendered by the actor.
226 * Set the image rendered by the actor.
227 * If actor was already displaying a different image, the old image is dropped and actor may
228 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
229 * dropped and actor displays nothing.
230 * The actor will take the image's natural size unless a custom size
231 * is chosen, e.g. via Actor:SetSize()
233 * @pre ImageActor must be initialized.
234 * @param [in] image The image to display.
236 void SetImage(Image image);
239 * @brief Retrieve the image rendered by the actor.
241 * If no image is assigned, an empty handle is returned
247 * @brief Tell the image actor to use the natural size of the current image
250 * Calling SetSize on this actor or animating the size of the actor
251 * overrides this behaviour.
253 * @post The image actor uses the natural image size after an image
255 * @note Actor::SetSizeSignal() will be triggered if there is a current image.
257 void SetToNaturalSize();
260 * @brief Set a region of the image to display, in pixels.
262 * When the image is loaded the actor's size will be reset to the pixelArea,
263 * unless a custom size was chosen, e.g. via Actor:SetSize().
264 * Note! PixelArea should be inside the image data size. It gets clamped by GL
265 * @pre image must be initialized.
266 * @param [in] pixelArea The area of the image to display.
267 * This in pixels, relative to the top-left (0,0) of the image.
269 void SetPixelArea(const PixelArea& pixelArea);
272 * @brief Retrieve the region of the image to display, in pixels.
274 * @pre image must be initialized.
275 * @return The pixel area, or a default-constructed area if none was set.
277 PixelArea GetPixelArea() const;
280 * @brief Query whether a pixel area has been set.
282 * @pre image must be initialized.
283 * @return True if a pixel area has been set.
285 bool IsPixelAreaSet() const;
288 * @brief Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
290 * The actor size will change to that of the Image unless a custom size was set, e.g. via
292 * @pre image must be initialized.
294 void ClearPixelArea();
297 * @brief Set how the image is rendered; the default is STYLE_QUAD.
299 * @pre image must be initialized.
300 * @param [in] style The new style.
302 void SetStyle(Style style);
305 * @brief Query how the image is rendered.
307 * @pre image must be initialized.
308 * @return The rendering style.
310 Style GetStyle() const;
313 * @brief Set the border used with STYLE_NINE_PATCH.
315 * The values are in pixels from the left, top, right, and bottom of the image respectively.
316 * 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.
317 * @param [in] border The new nine-patch border.
319 void SetNinePatchBorder(const Vector4& border);
322 * @brief Retrieve the border used with STYLE_NINE_PATCH.
324 * @return The nine-patch border.
326 Vector4 GetNinePatchBorder() const;
328 public: // Not intended for application developers
330 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
335 #endif // __DALI_IMAGE_ACTOR_H__