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.
22 * @addtogroup CAPI_DALI_ACTORS_MODULE
30 #include <dali/public-api/actors/renderable-actor.h>
31 #include <dali/public-api/math/rect.h>
32 #include <dali/public-api/images/image.h>
34 namespace Dali DALI_IMPORT_API
37 namespace Internal DALI_INTERNAL
43 * @brief An actor for displaying images.
45 * Allows the developer to add an actor to stage which displays the content of an Image object.
47 * By default CullFaceMode is set to CullNone to enable the ImageActor to be viewed from all angles.
49 * If an ImageActor is created without setting size, then the actor takes the size of the image -
50 * this is the natural size.
51 * Setting a size on the ImageActor, e.g through the SetSize api or through an animation will
52 * stop the natural size being used.
54 * Such a set size can be changed back to the image's size by calling SetToNaturalSize().
56 * If a pixel area is set on an ImageActor with natural size, the actor size will change
57 * to match the pixel area. If a pixel area is set on an ImageActor that has had it's size set,
58 * then the size doesn't change, and the partial image will be stretched to fill the set size.
60 * Clearing the pixel area on an Image actor with natural size will cause the actor to show the
61 * whole image again, and will change size back to that of the image.
63 * Clearing the pixel area on an Image actor with a set size will cause the actor to show the
64 * whole image again, but will not change the image size.
66 class DALI_IMPORT_API ImageActor : public RenderableActor
70 // Default Properties additional to RenderableActor
71 static const Property::Index PIXEL_AREA; ///< name "pixel-area", type RECTANGLE
72 static const Property::Index FADE_IN; ///< name "fade-in", type BOOLEAN
73 static const Property::Index FADE_IN_DURATION; ///< name "fade-in-duration", type FLOAT
74 static const Property::Index STYLE; ///< name "style", type STRING
75 static const Property::Index BORDER; ///< name "border", type VECTOR4
76 static const Property::Index IMAGE; ///< name "image", type MAP {"filename":"", "load-policy":...}
79 * @brief Style determines how the Image is rendered.
84 * 0---------2 0-----------------2
88 * | / | SCALE (X) | / |
89 * | / | --------> | / |
94 * 1---------3 1-----------------3
96 * Image is rendered as a textured rectangle. The texture
97 * is scaled uniformly as the quad is resized.
101 * |---|---------------|---| |---|-----------------------------|---|
102 * | 1 | 2 | 3 | | 1 | 2 | 3 |
103 * |---|---------------|---| |---|-----------------------------|---|
106 * | 4 | 5 | 6 | SCALE | | | |
107 * | | | | ----> | | | |
108 * | | | | | 4 | 5 | 6 |
109 * |-------------------|---| | | | |
110 * | 7 | 8 | 9 | | | | |
111 * |---|---------------|---| | | | |
112 * |---------------------------------|---|
114 * |---|-----------------------------|---|
117 * Image is rendered as a textured rectangle. The texture
118 * is scaled differently over each of the 9 sections.
120 * Visualise a Picture Frame:
122 * - Corner sections (1,3,7,9) are not scaled, regardless
123 * of how big the Image is.
124 * - Horizontal edge sections (2,8) are scaled only in the
125 * X axis as the image increases in width.
126 * - Vertical edge sections (4,6) are scaled only in the
127 * Y axis as the image increases in height.
128 * - Center section (5) is scaled in both X and Y axes as
129 * the image increases in width and/or height.
131 * Note: If GRID hints are enabled (via a Shader that requires it),
132 * the above geometry will be further subdivided into rectangles of
133 * approx. 40x40 in size.
138 STYLE_QUAD, ///< As a simple quad.
139 STYLE_NINE_PATCH ///< As a nine-patch.
143 * @brief Pixel area is relative to the top-left (0,0) of the image.
145 typedef Rect<int> PixelArea;
148 * @brief Create an uninitialized ImageActor handle.
150 * This can be initialized with ImageActor::New(...)
151 * Calling member functions with an uninitialized Dali::Object is not allowed.
156 * @brief Create an empty image actor object.
158 * @return A handle to a newly allocated actor.
160 static ImageActor New();
163 * @brief Create a image actor object.
165 * The actor will take the image's natural size unless a custom size
166 * is chosen, e.g. via Actor:SetSize()
167 * @pre image 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 * When the image is loaded the actor's size will reset to the pixelArea,
177 * unless a custom size was chosen, e.g. via Actor:SetSize().
178 * @pre image must be initialized.
179 * @param [in] image The image to display.
180 * @param [in] pixelArea The area of the image to display.
181 * This in pixels, relative to the top-left (0,0) of the image.
182 * @return A handle to a newly allocated actor.
184 static ImageActor New(Image image, PixelArea pixelArea);
187 * @brief Downcast an Object handle to ImageActor.
190 * If handle points to a ImageActor the downcast produces valid
191 * handle. If not the returned handle is left uninitialized.
193 * @param[in] handle to An object
194 * @return handle to a ImageActor or an uninitialized handle
196 static ImageActor DownCast( BaseHandle handle );
199 * @brief Virtual destructor.
201 * Dali::Object derived classes typically do not contain member data.
203 virtual ~ImageActor();
206 * @copydoc Dali::BaseHandle::operator=
208 using BaseHandle::operator=;
211 * @brief Set the image rendered by the actor.
213 * When the image is loaded the actor's size will be reset to the image size,
214 * unless a custom size was chosen, e.g. via Actor:SetSize() or a pixel area
216 * @note The old image will continue to be displayed until the given image has loaded.
217 * @pre image must be initialized.
218 * @param [in] image The image to display.
220 void SetImage(Image image);
223 * @brief Retrieve the image rendered by the actor's attachment.
230 * @brief Tell the image actor to use the natural size of the current image
233 * Calling SetSize on this actor or animating the size of the actor
234 * overrides this behaviour.
236 * @post The image actor uses the natural image size after an image
238 * @note Actor::SetSizeSignal() will be triggered if there is a current image.
240 void SetToNaturalSize();
243 * @brief Set a region of the image to display, in pixels.
245 * When the image is loaded the actor's size will be reset to the pixelArea,
246 * unless a custom size was chosen, e.g. via Actor:SetSize().
247 * Note! PixelArea should be inside the image data size. It gets clamped by GL
248 * @pre image must be initialized.
249 * @param [in] pixelArea The area of the image to display.
250 * This in pixels, relative to the top-left (0,0) of the image.
252 void SetPixelArea(const PixelArea& pixelArea);
255 * @brief Retrieve the region of the image to display, in pixels.
257 * @pre image must be initialized.
258 * @return The pixel area, or a default-constructed area if none was set.
260 PixelArea GetPixelArea() const;
263 * @brief Query whether a pixel area has been set.
265 * @pre image must be initialized.
266 * @return True if a pixel area has been set.
268 bool IsPixelAreaSet() const;
271 * @brief Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
273 * The actor size will change to that of the Image unless a custom size was set, e.g. via
275 * @pre image must be initialized.
277 void ClearPixelArea();
280 * @brief Set how the image is rendered; the default is STYLE_QUAD.
282 * @pre image must be initialized.
283 * @param [in] style The new style.
285 void SetStyle(Style style);
288 * @brief Query how the image is rendered.
290 * @pre image must be initialized.
291 * @return The rendering style.
293 Style GetStyle() const;
296 * @brief Set the border used with STYLE_NINE_PATCH.
298 * The values are in pixels from the left, top, right, and bottom of the image respectively.
299 * 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.
300 * @param [in] border The new nine-patch border.
302 void SetNinePatchBorder(const Vector4& border);
305 * @brief Retrieve the border used with STYLE_NINE_PATCH.
307 * @return The nine-patch border.
309 Vector4 GetNinePatchBorder() const;
312 * @brief Set whether the image should gradually fade in when first rendered.
314 * @pre image must be initialized.
315 * @param [in] enableFade True if the image should fade in.
317 void SetFadeIn(bool enableFade);
320 * @brief Query whether the image will gradually fade in when first rendered.
322 * @pre image must be initialized.
323 * @return True if the image will fade in.
325 bool GetFadeIn() const;
328 * @brief Set the duration of the fade-in effect; the default is 1 second.
330 * @pre image must be initialized.
331 * @param [in] durationSeconds The duration in seconds.
333 void SetFadeInDuration(float durationSeconds);
336 * @brief Retrieve the duration of the fade-in effect.
338 * @pre image must be initialized.
339 * @return The duration in seconds.
341 float GetFadeInDuration() const;
344 * @brief Retrieve the size of the displayed image within the image actor.
346 * The size of the image may be different to that of the image actor
347 * size depending on the geometry scaling used.
348 * @pre image must be initialized.
349 * @return The actual size of the image shown.
350 * @note If a pixel area is set then this returns the size of the pixel area shown.
352 Vector2 GetCurrentImageSize() const;
354 public: // Not intended for application developers
356 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
364 #endif // __DALI_IMAGE_ACTOR_H__