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 * @addtogroup dali_core_actors
39 namespace Internal DALI_INTERNAL
45 * @brief An actor for displaying images.
47 * Allows the developer to add an actor to stage which displays the content of an Image object.
49 * By default ImageActor can be viewed from all angles.
51 * If an ImageActor is created without setting size, then the actor takes the size of the image -
52 * this is the natural size.
53 * Setting a size on the ImageActor, e.g through the SetSize api or through an animation will
54 * stop the natural size being used.
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 Actor
71 * @brief An enumeration of properties belonging to the ImageActor class.
72 * Properties additional to RenderableActor.
78 PIXEL_AREA = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX, ///< name "pixelArea", type Rect<int>
79 STYLE, ///< @deprecated Dali 1.1.11 name "style", type std::string
80 BORDER, ///< @deprecated Dali 1.1.11 name "border", type Vector4
81 IMAGE, ///< name "image", type Map {"filename":"", "loadPolicy":...}
86 * @deprecated DALi 1.1.11, only quad style supported, use ImageView instead for nine patch
88 * @brief Style determines how the Image is rendered.
92 * 0---------2 0-----------------2
96 * | / | SCALE (X) | / |
97 * | / | --------> | / |
102 * 1---------3 1-----------------3
104 * Image is rendered as a textured rectangle. The texture
105 * is scaled uniformly as the quad is resized.
110 STYLE_QUAD, ///< As a simple quad.
111 STYLE_NINE_PATCH, ///< @deprecated Dali 1.1.11 As a nine-patch.
112 STYLE_NINE_PATCH_NO_CENTER ///< @deprecated Dali 1.1.11 As a nine-patch without center section being rendered.
116 * @brief Pixel area is relative to the top-left (0,0) of the image.
118 typedef Rect<int> PixelArea;
120 static const BlendingMode::Type DEFAULT_BLENDING_MODE; ///< default value is BlendingMode::AUTO
123 * @brief Create an uninitialized ImageActor handle.
125 * This can be initialized with ImageActor::New(...)
126 * Calling member functions with an uninitialized Dali::Object is not allowed.
131 * @brief Create an empty image actor object.
133 * @return A handle to a newly allocated actor.
135 static ImageActor New();
138 * @brief Create a image actor object.
140 * The actor will take the image's natural size unless a custom size
141 * is chosen, e.g. via Actor:SetSize().
142 * If the handle is empty, ImageActor will display nothing
143 * @pre ImageActor must be initialized.
144 * @param[in] image The image to display.
145 * @return A handle to a newly allocated actor.
147 static ImageActor New(Image image);
150 * @brief Create a image actor object.
152 * The actor will take the image's natural size unless a custom size
153 * is chosen, e.g. via Actor:SetSize()
154 * If the handle is empty, ImageActor will display nothing
155 * @pre ImageActor must be initialized.
156 * @param [in] image The image to display.
157 * @param [in] pixelArea The area of the image to display.
158 * This in pixels, relative to the top-left (0,0) of the image.
159 * @return A handle to a newly allocated actor.
161 static ImageActor New(Image image, PixelArea pixelArea);
164 * @brief Downcast an Object handle to ImageActor.
167 * If handle points to a ImageActor the downcast produces valid
168 * handle. If not the returned handle is left uninitialized.
170 * @param[in] handle to An object
171 * @return handle to a ImageActor or an uninitialized handle
173 static ImageActor DownCast( BaseHandle handle );
178 * This is non-virtual since derived Handle types must not contain data or virtual methods.
183 * @brief Copy constructor
185 * @param [in] copy The actor to copy.
187 ImageActor(const ImageActor& copy);
190 * @brief Assignment operator
192 * @param [in] rhs The actor to copy.
194 ImageActor& operator=(const ImageActor& rhs);
197 * @brief Set the image rendered by the actor.
198 * Set the image rendered by the actor.
199 * If actor was already displaying a different image, the old image is dropped and actor may
200 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
201 * dropped and actor displays nothing.
202 * The actor will take the image's natural size unless a custom size
203 * is chosen, e.g. via Actor:SetSize()
205 * @pre ImageActor must be initialized.
206 * @param [in] image The image to display.
208 void SetImage(Image image);
211 * @brief Retrieve the image rendered by the actor.
213 * If no image is assigned, an empty handle is returned
219 * @brief Set a region of the image to display, in pixels.
221 * When the image is loaded the actor's size will be reset to the pixelArea,
222 * unless a custom size was chosen, e.g. via Actor:SetSize().
223 * Note! PixelArea should be inside the image data size. It gets clamped by GL
224 * @pre image must be initialized.
225 * @param [in] pixelArea The area of the image to display.
226 * This in pixels, relative to the top-left (0,0) of the image.
228 void SetPixelArea(const PixelArea& pixelArea);
231 * @brief Retrieve the region of the image to display, in pixels.
233 * @pre image must be initialized.
234 * @return The pixel area, or a default-constructed area if none was set.
236 PixelArea GetPixelArea() const;
239 * @deprecated DALi 1.1.11, use ImageView instead
241 * @brief Set how the image is rendered; the default is STYLE_QUAD.
243 * @pre image must be initialized.
244 * @param [in] style The new style.
246 * @note The style specified is set (so GetStyle will return what's set) but ignored internally.
248 void SetStyle(Style style);
251 * @deprecated DALi 1.1.11, use ImageView instead
253 * @brief Query how the image is rendered.
255 * @pre image must be initialized.
256 * @return The rendering style.
258 * @note This just returns the style set by SetStyle. In reality, only STYLE_QUAD is supported.
260 Style GetStyle() const;
263 * @deprecated DALi 1.1.11, use ImageView instead
265 * @brief Set the border used with STYLE_NINE_PATCH.
267 * The values are in pixels from the left, top, right, and bottom of the image respectively.
268 * 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.
269 * @param [in] border The new nine-patch border.
271 void SetNinePatchBorder(const Vector4& border);
274 * @deprecated DALi 1.1.11, use ImageView instead
276 * @brief Retrieve the border used with STYLE_NINE_PATCH.
278 * @return The nine-patch border.
280 Vector4 GetNinePatchBorder() const;
284 * @brief Allows modification of an actors position in the depth sort algorithm.
286 * The offset can be altered for each coplanar actor hence allowing an order of painting.
287 * @pre The Actor has been initialized.
288 * @param [in] depthOffset the offset to be given to the actor. Positive values pushing it further back.
290 void SetSortModifier(float depthOffset);
293 * @brief Retrieves the offset used to modify an actors position in the depth sort algorithm.
295 * The offset can be altered for each coplanar actor hence allowing an order of painting.
296 * @pre The Actor has been initialized.
297 * @return the offset that has been given to the actor. Positive values pushing it further back.
299 float GetSortModifier() const;
302 * @brief Sets the blending mode.
304 * Possible values are: BlendingMode::OFF, BlendingMode::AUTO and BlendingMode::ON. Default is BlendingMode::AUTO.
306 * If blending is disabled (BlendingMode::OFF) fade in and fade out animations do not work.
309 * <li> \e OFF Blending is disabled.
310 * <li> \e AUTO Blending is enabled only if the renderable actor has alpha channel.
311 * <li> \e ON Blending is enabled.
314 * @param[in] mode The blending mode.
316 void SetBlendMode( BlendingMode::Type mode );
319 * @brief Retrieves the blending mode.
321 * @return The blending mode, one of BlendingMode::OFF, BlendingMode::AUTO or BlendingMode::ON.
323 BlendingMode::Type GetBlendMode() const;
326 * @brief Specify the pixel arithmetic used when the actor is blended.
328 * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
329 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
330 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
331 * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
333 * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
334 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
335 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
336 * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
338 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
341 * @brief Specify the pixel arithmetic used when the actor is blended.
343 * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
344 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
345 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
346 * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
348 * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
349 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
350 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
351 * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
353 * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
354 * The options are the same as for srcFactorRgb.
356 * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
357 * The options are the same as for destFactorRgb.
359 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
360 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
363 * @brief Query the pixel arithmetic used when the actor is blended.
365 * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
366 * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
367 * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
368 * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
370 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
371 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
374 * @brief Specify the equation used when the actor is blended.
376 * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
377 * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
379 void SetBlendEquation( BlendingEquation::Type equationRgba );
382 * @brief Specify the equation used when the actor is blended.
384 * @param[in] equationRgb The equation used for combining red, green, and blue components.
385 * @param[in] equationAlpha The equation used for combining the alpha component.
386 * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
388 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
391 * @brief Query the equation used when the actor is blended.
393 * @param[out] equationRgb The equation used for combining red, green, and blue components.
394 * @param[out] equationAlpha The equation used for combining the alpha component.
396 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
399 * @brief Specify the color used when the actor is blended; the default is Vector4::ZERO.
401 * @param[in] color The blend color.
403 void SetBlendColor( const Vector4& color );
406 * @brief Query the color used when the actor is blended.
408 * @return The blend color.
410 const Vector4& GetBlendColor() const;
413 * @brief Sets the filtering mode.
415 * Possible values are: FilterMode::NEAREST and FilterMode::LINEAR. Default is FilterMode::LINEAR.
418 * <li> \e NEAREST Use nearest filtering
419 * <li> \e LINEAR Use linear filtering
422 * @param[in] minFilter The minification filtering mode.
423 * @param[in] magFilter The magnification filtering mode.
425 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
428 * @brief Retrieves the filtering mode.
430 * @param[out] minFilter The return minification value
431 * @param[out] magFilter The return magnification value
433 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter) const;
436 * @brief Sets the shader effect for the RenderableActor.
438 * Shader effects provide special effects like ripple and bend.
439 * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
440 * @pre The actor has been initialized.
441 * @pre effect has been initialized.
442 * @param [in] effect The shader effect.
444 void SetShaderEffect( ShaderEffect effect );
447 * @brief Retrieve the custom shader effect for the RenderableActor.
448 * If default shader is used an empty handle is returned.
450 * @pre The Actor has been initialized.
451 * @return The shader effect
453 ShaderEffect GetShaderEffect() const;
456 * @brief Removes the current shader effect.
458 * @pre The Actor has been initialized.
460 void RemoveShaderEffect();
463 public: // Not intended for application developers
465 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
470 * @brief Sets the shader effect for all ImageActors in a tree of Actors.
472 * @see ImageActor::SetShaderEffect
474 * @param [in] actor root of a tree of actors.
475 * @param [in] effect The shader effect.
477 DALI_IMPORT_API void SetShaderEffectRecursively( Actor actor, ShaderEffect effect );
480 * @brief Removes the shader effect from all ImageActors in a tree of Actors.
482 * @see ImageActor::RemoveShaderEffect
484 * @param [in] actor root of a tree of actors.
486 DALI_IMPORT_API void RemoveShaderEffectRecursively( Actor actor );
493 #endif // __DALI_IMAGE_ACTOR_H__