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 * |---|-----------------------------|---|
109 * Image is rendered as a textured rectangle. The texture
110 * is scaled differently over each of the 9 sections.
112 * STYLE_NINE_PATCH_NO_CENTER:
114 * Image is rendered in the same way as STYLE_NINE_PATCH,
115 * but the Center Section (5) is not rendered.
118 * Visualise a Picture Frame:
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.
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.
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.
142 * @brief Pixel area is relative to the top-left (0,0) of the image.
144 typedef Rect<int> PixelArea;
147 * @brief Create an uninitialized ImageActor handle.
149 * This can be initialized with ImageActor::New(...)
150 * Calling member functions with an uninitialized Dali::Object is not allowed.
155 * @brief Create an empty image actor object.
157 * @return A handle to a newly allocated actor.
159 static ImageActor New();
162 * @brief Create a image actor object.
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.
171 static ImageActor New(Image image);
174 * @brief Create a image actor object.
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.
185 static ImageActor New(Image image, PixelArea pixelArea);
188 * @brief Downcast an Object handle to ImageActor.
191 * If handle points to a ImageActor the downcast produces valid
192 * handle. If not the returned handle is left uninitialized.
194 * @param[in] handle to An object
195 * @return handle to a ImageActor or an uninitialized handle
197 static ImageActor DownCast( BaseHandle handle );
202 * This is non-virtual since derived Handle types must not contain data or virtual methods.
207 * @brief Copy constructor
209 * @param [in] copy The actor to copy.
211 ImageActor(const ImageActor& copy);
214 * @brief Assignment operator
216 * @param [in] rhs The actor to copy.
218 ImageActor& operator=(const ImageActor& rhs);
221 * @brief This method is defined to allow assignment of the NULL value,
222 * and will throw an exception if passed any other value.
224 * Assigning to NULL is an alias for Reset().
225 * @param [in] rhs A NULL pointer
226 * @return A reference to this handle
228 ImageActor& operator=(BaseHandle::NullType* rhs);
231 * @brief Set the image rendered by the actor.
232 * Set the image rendered by the actor.
233 * If actor was already displaying a different image, the old image is dropped and actor may
234 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
235 * dropped and actor displays nothing.
236 * The actor will take the image's natural size unless a custom size
237 * is chosen, e.g. via Actor:SetSize()
239 * @pre ImageActor must be initialized.
240 * @param [in] image The image to display.
242 void SetImage(Image image);
245 * @brief Retrieve the image rendered by the actor.
247 * If no image is assigned, an empty handle is returned
253 * @brief Tell the image actor to use the natural size of the current image
256 * Calling SetSize on this actor or animating the size of the actor
257 * overrides this behaviour.
259 * @post The image actor uses the natural image size after an image
261 * @note Actor::SetSizeSignal() will be triggered if there is a current image.
263 void SetToNaturalSize();
266 * @brief Set a region of the image to display, in pixels.
268 * When the image is loaded the actor's size will be reset to the pixelArea,
269 * unless a custom size was chosen, e.g. via Actor:SetSize().
270 * Note! PixelArea should be inside the image data size. It gets clamped by GL
271 * @pre image must be initialized.
272 * @param [in] pixelArea The area of the image to display.
273 * This in pixels, relative to the top-left (0,0) of the image.
275 void SetPixelArea(const PixelArea& pixelArea);
278 * @brief Retrieve the region of the image to display, in pixels.
280 * @pre image must be initialized.
281 * @return The pixel area, or a default-constructed area if none was set.
283 PixelArea GetPixelArea() const;
286 * @brief Query whether a pixel area has been set.
288 * @pre image must be initialized.
289 * @return True if a pixel area has been set.
291 bool IsPixelAreaSet() const;
294 * @brief Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
296 * The actor size will change to that of the Image unless a custom size was set, e.g. via
298 * @pre image must be initialized.
300 void ClearPixelArea();
303 * @brief Set how the image is rendered; the default is STYLE_QUAD.
305 * @pre image must be initialized.
306 * @param [in] style The new style.
308 void SetStyle(Style style);
311 * @brief Query how the image is rendered.
313 * @pre image must be initialized.
314 * @return The rendering style.
316 Style GetStyle() const;
319 * @brief Set the border used with STYLE_NINE_PATCH.
321 * The values are in pixels from the left, top, right, and bottom of the image respectively.
322 * 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.
323 * @param [in] border The new nine-patch border.
325 void SetNinePatchBorder(const Vector4& border);
328 * @brief Retrieve the border used with STYLE_NINE_PATCH.
330 * @return The nine-patch border.
332 Vector4 GetNinePatchBorder() const;
334 public: // Not intended for application developers
336 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
341 #endif // __DALI_IMAGE_ACTOR_H__