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 * If a pixel area is set on an ImageActor with natural size, the actor size will change
50 * to match the pixel area. If a pixel area is set on an ImageActor that has had it's size set,
51 * then the size doesn't change, and the partial image will be stretched to fill the set size.
53 * Clearing the pixel area on an Image actor with natural size will cause the actor to show the
54 * whole image again, and will change size back to that of the image.
56 * Clearing the pixel area on an Image actor with a set size will cause the actor to show the
57 * whole image again, but will not change the image size.
59 class DALI_IMPORT_API ImageActor : public RenderableActor
64 * @brief An enumeration of properties belonging to the ImageActor class.
65 * Properties additional to RenderableActor.
71 PIXEL_AREA = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "pixel-area", type Rect<int>
72 STYLE, ///< name "style", type std::string
73 BORDER, ///< name "border", type Vector4
74 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 * |---|-----------------------------|---|
116 * Image is rendered as a textured rectangle. The texture
117 * is scaled differently over each of the 9 sections.
119 * STYLE_NINE_PATCH_NO_CENTER:
121 * Image is rendered in the same way as STYLE_NINE_PATCH,
122 * but the Center Section (5) is not rendered.
125 * Visualise a Picture Frame:
127 * - Corner sections (1,3,7,9) are not scaled, regardless
128 * of how big the Image is.
129 * - Horizontal edge sections (2,8) are scaled only in the
130 * X axis as the image increases in width.
131 * - Vertical edge sections (4,6) are scaled only in the
132 * Y axis as the image increases in height.
133 * - Center section (5) is scaled in both X and Y axes as
134 * the image increases in width and/or height.
136 * Note: If GRID hints are enabled (via a Shader that requires it),
137 * the above geometry will be further subdivided into rectangles of
138 * approx. 40x40 in size. STYLE_NINE_PATCH_NO_CENTER is not supported
139 * yet when GRID hints are enabled.
143 STYLE_QUAD, ///< As a simple quad.
144 STYLE_NINE_PATCH, ///< As a nine-patch.
145 STYLE_NINE_PATCH_NO_CENTER ///< As a nine-patch without center section being rendered.
149 * @brief Pixel area is relative to the top-left (0,0) of the image.
151 typedef Rect<int> PixelArea;
154 * @brief Create an uninitialized ImageActor handle.
156 * This can be initialized with ImageActor::New(...)
157 * Calling member functions with an uninitialized Dali::Object is not allowed.
162 * @brief Create an empty image actor object.
164 * @return A handle to a newly allocated actor.
166 static ImageActor New();
169 * @brief Create a image actor object.
171 * The actor will take the image's natural size unless a custom size
172 * is chosen, e.g. via Actor:SetSize().
173 * If the handle is empty, ImageActor will display nothing
174 * @pre ImageActor must be initialized.
175 * @param[in] image The image to display.
176 * @return A handle to a newly allocated actor.
178 static ImageActor New(Image image);
181 * @brief Create a image actor object.
183 * The actor will take the image's natural size unless a custom size
184 * is chosen, e.g. via Actor:SetSize()
185 * If the handle is empty, ImageActor will display nothing
186 * @pre ImageActor must be initialized.
187 * @param [in] image The image to display.
188 * @param [in] pixelArea The area of the image to display.
189 * This in pixels, relative to the top-left (0,0) of the image.
190 * @return A handle to a newly allocated actor.
192 static ImageActor New(Image image, PixelArea pixelArea);
195 * @brief Downcast an Object handle to ImageActor.
198 * If handle points to a ImageActor the downcast produces valid
199 * handle. If not the returned handle is left uninitialized.
201 * @param[in] handle to An object
202 * @return handle to a ImageActor or an uninitialized handle
204 static ImageActor DownCast( BaseHandle handle );
209 * This is non-virtual since derived Handle types must not contain data or virtual methods.
214 * @brief Copy constructor
216 * @param [in] copy The actor to copy.
218 ImageActor(const ImageActor& copy);
221 * @brief Assignment operator
223 * @param [in] rhs The actor to copy.
225 ImageActor& operator=(const ImageActor& rhs);
228 * @brief Set the image rendered by the actor.
229 * Set the image rendered by the actor.
230 * If actor was already displaying a different image, the old image is dropped and actor may
231 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
232 * dropped and actor displays nothing.
233 * The actor will take the image's natural size unless a custom size
234 * is chosen, e.g. via Actor:SetSize()
236 * @pre ImageActor must be initialized.
237 * @param [in] image The image to display.
239 void SetImage(Image image);
242 * @brief Retrieve the image rendered by the actor.
244 * If no image is assigned, an empty handle is returned
250 * @brief Set a region of the image to display, in pixels.
252 * When the image is loaded the actor's size will be reset to the pixelArea,
253 * unless a custom size was chosen, e.g. via Actor:SetSize().
254 * Note! PixelArea should be inside the image data size. It gets clamped by GL
255 * @pre image must be initialized.
256 * @param [in] pixelArea The area of the image to display.
257 * This in pixels, relative to the top-left (0,0) of the image.
259 void SetPixelArea(const PixelArea& pixelArea);
262 * @brief Retrieve the region of the image to display, in pixels.
264 * @pre image must be initialized.
265 * @return The pixel area, or a default-constructed area if none was set.
267 PixelArea GetPixelArea() const;
270 * @brief Query whether a pixel area has been set.
272 * @pre image must be initialized.
273 * @return True if a pixel area has been set.
275 bool IsPixelAreaSet() const;
278 * @brief Remove any pixel areas specified with SetPixelArea; the entire image will be displayed.
280 * The actor size will change to that of the Image unless a custom size was set, e.g. via
282 * @pre image must be initialized.
284 void ClearPixelArea();
287 * @brief Set how the image is rendered; the default is STYLE_QUAD.
289 * @pre image must be initialized.
290 * @param [in] style The new style.
292 void SetStyle(Style style);
295 * @brief Query how the image is rendered.
297 * @pre image must be initialized.
298 * @return The rendering style.
300 Style GetStyle() const;
303 * @brief Set the border used with STYLE_NINE_PATCH.
305 * The values are in pixels from the left, top, right, and bottom of the image respectively.
306 * 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.
307 * @param [in] border The new nine-patch border.
309 void SetNinePatchBorder(const Vector4& border);
312 * @brief Retrieve the border used with STYLE_NINE_PATCH.
314 * @return The nine-patch border.
316 Vector4 GetNinePatchBorder() const;
318 public: // Not intended for application developers
320 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
325 #endif // __DALI_IMAGE_ACTOR_H__