1 #ifndef __DALI_IMAGE_ACTOR_H__
2 #define __DALI_IMAGE_ACTOR_H__
5 * Copyright (c) 2015 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/actor.h>
26 #include <dali/public-api/math/rect.h>
27 #include <dali/public-api/images/image.h>
28 #include <dali/public-api/shader-effects/shader-effect.h>
29 #include <dali/public-api/actors/blending.h>
30 #include <dali/public-api/actors/sampling.h>
35 namespace Internal DALI_INTERNAL
41 * @brief An actor for displaying images.
43 * Allows the developer to add an actor to stage which displays the content of an Image object.
45 * By default ImageActor can be viewed from all angles.
47 * If an ImageActor is created without setting size, then the actor takes the size of the image -
48 * this is the natural size.
49 * Setting a size on the ImageActor, e.g through the SetSize api or through an animation will
50 * stop the natural size being used.
52 * If a pixel area is set on an ImageActor with natural size, the actor size will change
53 * to match the pixel area. If a pixel area is set on an ImageActor that has had it's size set,
54 * then the size doesn't change, and the partial image will be stretched to fill the set size.
56 * Clearing the pixel area on an Image actor with natural size will cause the actor to show the
57 * whole image again, and will change size back to that of the image.
59 * Clearing the pixel area on an Image actor with a set size will cause the actor to show the
60 * whole image again, but will not change the image size.
62 class DALI_IMPORT_API ImageActor : public Actor
67 * @brief An enumeration of properties belonging to the ImageActor class.
68 * Properties additional to RenderableActor.
74 PIXEL_AREA = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "pixel-area", type Rect<int>
75 STYLE, ///< name "style", type std::string
76 BORDER, ///< name "border", type Vector4
77 IMAGE, ///< name "image", type Map {"filename":"", "load-policy":...}
82 * @brief Style determines how the Image is rendered.
87 * 0---------2 0-----------------2
91 * | / | SCALE (X) | / |
92 * | / | --------> | / |
97 * 1---------3 1-----------------3
99 * Image is rendered as a textured rectangle. The texture
100 * is scaled uniformly as the quad is resized.
104 * |---|---------------|---| |---|-----------------------------|---|
105 * | 1 | 2 | 3 | | 1 | 2 | 3 |
106 * |---|---------------|---| |---|-----------------------------|---|
109 * | 4 | 5 | 6 | SCALE | | | |
110 * | | | | ----> | | | |
111 * | | | | | 4 | 5 | 6 |
112 * |-------------------|---| | | | |
113 * | 7 | 8 | 9 | | | | |
114 * |---|---------------|---| | | | |
115 * |---------------------------------|---|
117 * |---|-----------------------------|---|
119 * Image is rendered as a textured rectangle. The texture
120 * is scaled differently over each of the 9 sections.
122 * STYLE_NINE_PATCH_NO_CENTER:
124 * Image is rendered in the same way as STYLE_NINE_PATCH,
125 * but the Center Section (5) is not rendered.
128 * Visualise a Picture Frame:
130 * - Corner sections (1,3,7,9) are not scaled, regardless
131 * of how big the Image is.
132 * - Horizontal edge sections (2,8) are scaled only in the
133 * X axis as the image increases in width.
134 * - Vertical edge sections (4,6) are scaled only in the
135 * Y axis as the image increases in height.
136 * - Center section (5) is scaled in both X and Y axes as
137 * the image increases in width and/or height.
139 * Note: If GRID hints are enabled (via a Shader that requires it),
140 * the above geometry will be further subdivided into rectangles of
141 * approx. 40x40 in size. STYLE_NINE_PATCH_NO_CENTER is not supported
142 * yet when GRID hints are enabled.
146 STYLE_QUAD, ///< As a simple quad.
147 STYLE_NINE_PATCH, ///< As a nine-patch.
148 STYLE_NINE_PATCH_NO_CENTER ///< As a nine-patch without center section being rendered.
152 * @brief Pixel area is relative to the top-left (0,0) of the image.
154 typedef Rect<int> PixelArea;
156 static const BlendingMode::Type DEFAULT_BLENDING_MODE; ///< default value is BlendingMode::AUTO
159 * @brief Create an uninitialized ImageActor handle.
161 * This can be initialized with ImageActor::New(...)
162 * Calling member functions with an uninitialized Dali::Object is not allowed.
167 * @brief Create an empty image actor object.
169 * @return A handle to a newly allocated actor.
171 static ImageActor New();
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 * @return A handle to a newly allocated actor.
183 static ImageActor New(Image image);
186 * @brief Create a image actor object.
188 * The actor will take the image's natural size unless a custom size
189 * is chosen, e.g. via Actor:SetSize()
190 * If the handle is empty, ImageActor will display nothing
191 * @pre ImageActor must be initialized.
192 * @param [in] image The image to display.
193 * @param [in] pixelArea The area of the image to display.
194 * This in pixels, relative to the top-left (0,0) of the image.
195 * @return A handle to a newly allocated actor.
197 static ImageActor New(Image image, PixelArea pixelArea);
200 * @brief Downcast an Object handle to ImageActor.
203 * If handle points to a ImageActor the downcast produces valid
204 * handle. If not the returned handle is left uninitialized.
206 * @param[in] handle to An object
207 * @return handle to a ImageActor or an uninitialized handle
209 static ImageActor DownCast( BaseHandle handle );
214 * This is non-virtual since derived Handle types must not contain data or virtual methods.
219 * @brief Copy constructor
221 * @param [in] copy The actor to copy.
223 ImageActor(const ImageActor& copy);
226 * @brief Assignment operator
228 * @param [in] rhs The actor to copy.
230 ImageActor& operator=(const ImageActor& rhs);
233 * @brief Set the image rendered by the actor.
234 * Set the image rendered by the actor.
235 * If actor was already displaying a different image, the old image is dropped and actor may
236 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
237 * dropped and actor displays nothing.
238 * The actor will take the image's natural size unless a custom size
239 * is chosen, e.g. via Actor:SetSize()
241 * @pre ImageActor must be initialized.
242 * @param [in] image The image to display.
244 void SetImage(Image image);
247 * @brief Retrieve the image rendered by the actor.
249 * If no image is assigned, an empty handle is returned
255 * @brief Set a region of the image to display, in pixels.
257 * When the image is loaded the actor's size will be reset to the pixelArea,
258 * unless a custom size was chosen, e.g. via Actor:SetSize().
259 * Note! PixelArea should be inside the image data size. It gets clamped by GL
260 * @pre image must be initialized.
261 * @param [in] pixelArea The area of the image to display.
262 * This in pixels, relative to the top-left (0,0) of the image.
264 void SetPixelArea(const PixelArea& pixelArea);
267 * @brief Retrieve the region of the image to display, in pixels.
269 * @pre image must be initialized.
270 * @return The pixel area, or a default-constructed area if none was set.
272 PixelArea GetPixelArea() const;
275 * @brief Set how the image is rendered; the default is STYLE_QUAD.
277 * @pre image must be initialized.
278 * @param [in] style The new style.
280 void SetStyle(Style style);
283 * @brief Query how the image is rendered.
285 * @pre image must be initialized.
286 * @return The rendering style.
288 Style GetStyle() const;
291 * @brief Set the border used with STYLE_NINE_PATCH.
293 * The values are in pixels from the left, top, right, and bottom of the image respectively.
294 * 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.
295 * @param [in] border The new nine-patch border.
297 void SetNinePatchBorder(const Vector4& border);
300 * @brief Retrieve the border used with STYLE_NINE_PATCH.
302 * @return The nine-patch border.
304 Vector4 GetNinePatchBorder() const;
308 * @brief Allows modification of an actors position in the depth sort algorithm.
310 * The offset can be altered for each coplanar actor hence allowing an order of painting.
311 * @pre The Actor has been initialized.
312 * @param [in] depthOffset the offset to be given to the actor. Positive values pushing it further back.
314 void SetSortModifier(float depthOffset);
317 * @brief Retrieves the offset used to modify an actors position in the depth sort algorithm.
319 * The offset can be altered for each coplanar actor hence allowing an order of painting.
320 * @pre The Actor has been initialized.
321 * @return the offset that has been given to the actor. Positive values pushing it further back.
323 float GetSortModifier() const;
326 * @brief Sets the blending mode.
328 * Possible values are: BlendingMode::OFF, BlendingMode::AUTO and BlendingMode::ON. Default is BlendingMode::AUTO.
330 * If blending is disabled (BlendingMode::OFF) fade in and fade out animations do not work.
333 * <li> \e OFF Blending is disabled.
334 * <li> \e AUTO Blending is enabled only if the renderable actor has alpha channel.
335 * <li> \e ON Blending is enabled.
338 * @param[in] mode The blending mode.
340 void SetBlendMode( BlendingMode::Type mode );
343 * @brief Retrieves the blending mode.
345 * @return The blending mode, one of BlendingMode::OFF, BlendingMode::AUTO or BlendingMode::ON.
347 BlendingMode::Type GetBlendMode() const;
350 * @brief Specify the pixel arithmetic used when the actor is blended.
352 * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
353 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
354 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
355 * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
357 * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
358 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
359 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
360 * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
362 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
365 * @brief Specify the pixel arithmetic used when the actor is blended.
367 * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
368 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
369 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
370 * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
372 * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
373 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
374 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
375 * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
377 * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
378 * The options are the same as for srcFactorRgb.
380 * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
381 * The options are the same as for destFactorRgb.
383 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
384 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
387 * @brief Query the pixel arithmetic used when the actor is blended.
389 * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
390 * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
391 * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
392 * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
394 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
395 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
398 * @brief Specify the equation used when the actor is blended.
400 * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
401 * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
403 void SetBlendEquation( BlendingEquation::Type equationRgba );
406 * @brief Specify the equation used when the actor is blended.
408 * @param[in] equationRgb The equation used for combining red, green, and blue components.
409 * @param[in] equationAlpha The equation used for combining the alpha component.
410 * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
412 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
415 * @brief Query the equation used when the actor is blended.
417 * @param[out] equationRgb The equation used for combining red, green, and blue components.
418 * @param[out] equationAlpha The equation used for combining the alpha component.
420 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
423 * @brief Specify the color used when the actor is blended; the default is Vector4::ZERO.
425 * @param[in] color The blend color.
427 void SetBlendColor( const Vector4& color );
430 * @brief Query the color used when the actor is blended.
432 * @return The blend color.
434 const Vector4& GetBlendColor() const;
437 * @brief Sets the filtering mode.
439 * Possible values are: FilterMode::NEAREST and FilterMode::LINEAR. Default is FilterMode::LINEAR.
442 * <li> \e NEAREST Use nearest filtering
443 * <li> \e LINEAR Use linear filtering
446 * @param[in] minFilter The minification filtering mode.
447 * @param[in] magFilter The magnification filtering mode.
449 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
452 * @brief Retrieves the filtering mode.
454 * @param[out] minFilter The return minification value
455 * @param[out] magFilter The return magnification value
457 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter) const;
460 * @brief Sets the shader effect for the RenderableActor.
462 * Shader effects provide special effects like ripple and bend.
463 * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
464 * @pre The actor has been initialized.
465 * @pre effect has been initialized.
466 * @param [in] effect The shader effect.
468 void SetShaderEffect( ShaderEffect effect );
471 * @brief Retrieve the custom shader effect for the RenderableActor.
472 * If default shader is used an empty handle is returned.
474 * @pre The Actor has been initialized.
475 * @return The shader effect
477 ShaderEffect GetShaderEffect() const;
480 * @brief Removes the current shader effect.
482 * @pre The Actor has been initialized.
484 void RemoveShaderEffect();
487 public: // Not intended for application developers
489 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
494 * @brief Sets the shader effect for all ImageActors in a tree of Actors.
496 * @see ImageActor::SetShaderEffect
498 * @param [in] actor root of a tree of actors.
499 * @param [in] effect The shader effect.
501 DALI_IMPORT_API void SetShaderEffectRecursively( Actor actor, ShaderEffect effect );
504 * @brief Removes the shader effect from all ImageActors in a tree of Actors.
506 * @see ImageActor::RemoveShaderEffect
508 * @param [in] actor root of a tree of actors.
510 DALI_IMPORT_API void RemoveShaderEffectRecursively( Actor actor );
514 #endif // __DALI_IMAGE_ACTOR_H__