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>
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
66 * @brief An enumeration of properties belonging to the ImageActor class.
67 * Properties additional to RenderableActor.
73 PixelArea = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "pixel-area", type RECTANGLE
74 Style, ///< name "style", type STRING
75 Border, ///< name "border", type VECTOR4
76 Image, ///< name "image", type MAP {"filename":"", "load-policy":...}
81 * @brief Style determines how the Image is rendered.
86 * 0---------2 0-----------------2
90 * | / | SCALE (X) | / |
91 * | / | --------> | / |
96 * 1---------3 1-----------------3
98 * Image is rendered as a textured rectangle. The texture
99 * is scaled uniformly as the quad is resized.
103 * |---|---------------|---| |---|-----------------------------|---|
104 * | 1 | 2 | 3 | | 1 | 2 | 3 |
105 * |---|---------------|---| |---|-----------------------------|---|
108 * | 4 | 5 | 6 | SCALE | | | |
109 * | | | | ----> | | | |
110 * | | | | | 4 | 5 | 6 |
111 * |-------------------|---| | | | |
112 * | 7 | 8 | 9 | | | | |
113 * |---|---------------|---| | | | |
114 * |---------------------------------|---|
116 * |---|-----------------------------|---|
118 * Image is rendered as a textured rectangle. The texture
119 * is scaled differently over each of the 9 sections.
121 * STYLE_NINE_PATCH_NO_CENTER:
123 * Image is rendered in the same way as STYLE_NINE_PATCH,
124 * but the Center Section (5) is not rendered.
127 * Visualise a Picture Frame:
129 * - Corner sections (1,3,7,9) are not scaled, regardless
130 * of how big the Image is.
131 * - Horizontal edge sections (2,8) are scaled only in the
132 * X axis as the image increases in width.
133 * - Vertical edge sections (4,6) are scaled only in the
134 * Y axis as the image increases in height.
135 * - Center section (5) is scaled in both X and Y axes as
136 * the image increases in width and/or height.
138 * Note: If GRID hints are enabled (via a Shader that requires it),
139 * the above geometry will be further subdivided into rectangles of
140 * approx. 40x40 in size. STYLE_NINE_PATCH_NO_CENTER is not supported
141 * yet when GRID hints are enabled.
145 STYLE_QUAD, ///< As a simple quad.
146 STYLE_NINE_PATCH, ///< As a nine-patch.
147 STYLE_NINE_PATCH_NO_CENTER ///< As a nine-patch without center section being rendered.
151 * @brief Pixel area is relative to the top-left (0,0) of the image.
153 typedef Rect<int> PixelArea;
156 * @brief Create an uninitialized ImageActor handle.
158 * This can be initialized with ImageActor::New(...)
159 * Calling member functions with an uninitialized Dali::Object is not allowed.
164 * @brief Create an empty image actor object.
166 * @return A handle to a newly allocated actor.
168 static ImageActor New();
171 * @brief Create a image actor object.
173 * The actor will take the image's natural size unless a custom size
174 * is chosen, e.g. via Actor:SetSize().
175 * If the handle is empty, ImageActor will display nothing
176 * @pre ImageActor must be initialized.
177 * @param[in] image The image to display.
178 * @return A handle to a newly allocated actor.
180 static ImageActor New(Image image);
183 * @brief Create a image actor object.
185 * The actor will take the image's natural size unless a custom size
186 * is chosen, e.g. via Actor:SetSize()
187 * If the handle is empty, ImageActor will display nothing
188 * @pre ImageActor must be initialized.
189 * @param [in] image The image to display.
190 * @param [in] pixelArea The area of the image to display.
191 * This in pixels, relative to the top-left (0,0) of the image.
192 * @return A handle to a newly allocated actor.
194 static ImageActor New(Image image, PixelArea pixelArea);
197 * @brief Downcast an Object handle to ImageActor.
200 * If handle points to a ImageActor the downcast produces valid
201 * handle. If not the returned handle is left uninitialized.
203 * @param[in] handle to An object
204 * @return handle to a ImageActor or an uninitialized handle
206 static ImageActor DownCast( BaseHandle handle );
211 * This is non-virtual since derived Handle types must not contain data or virtual methods.
216 * @brief Copy constructor
218 * @param [in] copy The actor to copy.
220 ImageActor(const ImageActor& copy);
223 * @brief Assignment operator
225 * @param [in] rhs The actor to copy.
227 ImageActor& operator=(const ImageActor& rhs);
230 * @brief Set the image rendered by the actor.
231 * Set the image rendered by the actor.
232 * If actor was already displaying a different image, the old image is dropped and actor may
233 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
234 * dropped and actor displays nothing.
235 * The actor will take the image's natural size unless a custom size
236 * is chosen, e.g. via Actor:SetSize()
238 * @pre ImageActor must be initialized.
239 * @param [in] image The image to display.
241 void SetImage(Image image);
244 * @brief Retrieve the image rendered by the actor.
246 * If no image is assigned, an empty handle is returned
252 * @brief Tell the image actor to use the natural size of the current image
255 * Calling SetSize on this actor or animating the size of the actor
256 * overrides this behaviour.
258 * @post The image actor uses the natural image size after an image
261 void SetToNaturalSize();
264 * @brief Set a region of the image to display, in pixels.
266 * When the image is loaded the actor's size will be reset to the pixelArea,
267 * unless a custom size was chosen, e.g. via Actor:SetSize().
268 * Note! PixelArea should be inside the image data size. It gets clamped by GL
269 * @pre image must be initialized.
270 * @param [in] pixelArea The area of the image to display.
271 * This in pixels, relative to the top-left (0,0) of the image.
273 void SetPixelArea(const PixelArea& pixelArea);
276 * @brief Retrieve the region of the image to display, in pixels.
278 * @pre image must be initialized.
279 * @return The pixel area, or a default-constructed area if none was set.
281 PixelArea GetPixelArea() const;
284 * @brief Query whether a pixel area has been set.
286 * @pre image must be initialized.
287 * @return True if a pixel area has been set.
289 bool IsPixelAreaSet() const;
292 * @brief Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
294 * The actor size will change to that of the Image unless a custom size was set, e.g. via
296 * @pre image must be initialized.
298 void ClearPixelArea();
301 * @brief Set how the image is rendered; the default is STYLE_QUAD.
303 * @pre image must be initialized.
304 * @param [in] style The new style.
306 void SetStyle(Style style);
309 * @brief Query how the image is rendered.
311 * @pre image must be initialized.
312 * @return The rendering style.
314 Style GetStyle() const;
317 * @brief Set the border used with STYLE_NINE_PATCH.
319 * The values are in pixels from the left, top, right, and bottom of the image respectively.
320 * 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.
321 * @param [in] border The new nine-patch border.
323 void SetNinePatchBorder(const Vector4& border);
326 * @brief Retrieve the border used with STYLE_NINE_PATCH.
328 * @return The nine-patch border.
330 Vector4 GetNinePatchBorder() const;
332 public: // Not intended for application developers
334 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
339 #endif // __DALI_IMAGE_ACTOR_H__