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
46 * @brief An actor for displaying images.
48 * Allows the developer to add an actor to stage which displays the content of an Image object.
50 * By default ImageActor can be viewed from all angles.
52 * If an ImageActor is created without setting size, then the actor takes the size of the image -
53 * this is the natural size.
54 * Setting a size on the ImageActor, e.g through the SetSize api or through an animation will
55 * stop the natural size being used.
57 * If a pixel area is set on an ImageActor with natural size, the actor size will change
58 * to match the pixel area. If a pixel area is set on an ImageActor that has had it's size set,
59 * then the size doesn't change, and the partial image will be stretched to fill the set size.
61 * Clearing the pixel area on an Image actor with natural size will cause the actor to show the
62 * whole image again, and will change size back to that of the image.
64 * Clearing the pixel area on an Image actor with a set size will cause the actor to show the
65 * whole image again, but will not change the image size.
68 class DALI_IMPORT_API ImageActor : public Actor
74 * @brief An enumeration of properties belonging to the ImageActor class.
75 * Properties additional to RenderableActor.
84 * @brief name "pixelArea", type Rect<int>
87 PIXEL_AREA = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX,
90 * @brief name "style", type std::string
96 * @brief name "border", type Vector4
102 * @brief name "image", type Map {"filename":"", "loadPolicy":...}
110 * @DEPRECATED_1_1.11. Only quad style supported, use ImageView instead for nine patch.
112 * @brief Style determines how the Image is rendered.
116 * 0---------2 0-----------------2
120 * | / | SCALE (X) | / |
121 * | / | --------> | / |
126 * 1---------3 1-----------------3
128 * Image is rendered as a textured rectangle. The texture
129 * is scaled uniformly as the quad is resized.
137 * @brief As a simple quad.
143 * @brief As a nine-patch.
149 * @brief As a nine-patch without center section being rendered.
152 STYLE_NINE_PATCH_NO_CENTER
157 * @brief Pixel area is relative to the top-left (0,0) of the image.
160 typedef Rect<int> PixelArea;
162 static const BlendingMode::Type DEFAULT_BLENDING_MODE; ///< default value is BlendingMode::AUTO
166 * @brief Create an uninitialized ImageActor handle.
168 * This can be initialized with ImageActor::New(...)
169 * Calling member functions with an uninitialized Dali::Object is not allowed.
176 * @brief Create an empty image actor object.
179 * @return A handle to a newly allocated actor.
181 static ImageActor New();
185 * @brief Create a image actor object.
187 * The actor will take the image's natural size unless a custom size
188 * is chosen, e.g. via Actor:SetSize().
189 * If the handle is empty, ImageActor will display nothing
191 * @param[in] image The image to display.
192 * @return A handle to a newly allocated actor.
193 * @pre ImageActor must be initialized.
195 static ImageActor New(Image image);
199 * @brief Create a image actor object.
201 * The actor will take the image's natural size unless a custom size
202 * is chosen, e.g. via Actor:SetSize()
203 * If the handle is empty, ImageActor will display nothing
205 * @param [in] image The image to display.
206 * @param [in] pixelArea The area of the image to display.
207 * This in pixels, relative to the top-left (0,0) of the image.
208 * @return A handle to a newly allocated actor.
209 * @pre ImageActor must be initialized.
211 static ImageActor New(Image image, PixelArea pixelArea);
215 * @brief Downcast an Object handle to ImageActor.
218 * If handle points to a ImageActor the downcast produces valid
219 * handle. If not the returned handle is left uninitialized.
222 * @param[in] handle to An object
223 * @return handle to a ImageActor or an uninitialized handle
225 static ImageActor DownCast( BaseHandle handle );
231 * This is non-virtual since derived Handle types must not contain data or virtual methods.
238 * @brief Copy constructor
241 * @param [in] copy The actor to copy.
243 ImageActor(const ImageActor& copy);
247 * @brief Assignment operator
250 * @param [in] rhs The actor to copy.
252 ImageActor& operator=(const ImageActor& rhs);
256 * @brief Set the image rendered by the actor.
258 * Set the image rendered by the actor.
259 * If actor was already displaying a different image, the old image is dropped and actor may
260 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
261 * dropped and actor displays nothing.
262 * The actor will take the image's natural size unless a custom size
263 * is chosen, e.g. via Actor:SetSize()
266 * @param [in] image The image to display.
267 * @pre ImageActor must be initialized.
269 void SetImage(Image image);
273 * @brief Retrieve the image rendered by the actor.
275 * If no image is assigned, an empty handle is returned
283 * @brief Set a region of the image to display, in pixels.
285 * When the image is loaded the actor's size will be reset to the pixelArea,
286 * unless a custom size was chosen, e.g. via Actor:SetSize().
287 * Note! PixelArea should be inside the image data size. It gets clamped by GL
289 * @param [in] pixelArea The area of the image to display.
290 * This in pixels, relative to the top-left (0,0) of the image.
291 * @pre image must be initialized.
293 void SetPixelArea(const PixelArea& pixelArea);
297 * @brief Retrieve the region of the image to display, in pixels.
300 * @return The pixel area, or a default-constructed area if none was set.
301 * @pre image must be initialized.
303 PixelArea GetPixelArea() const;
306 * @DEPRECATED_1_1.11. Use ImageView instead.
308 * @brief Set how the image is rendered; the default is STYLE_QUAD.
311 * @param [in] style The new style.
313 * @pre image must be initialized.
314 * @note The style specified is set (so GetStyle will return what's set) but ignored internally.
316 void SetStyle(Style style);
319 * @DEPRECATED_1_1.11. Use ImageView instead.
321 * @brief Query how the image is rendered.
324 * @return The rendering style.
326 * @pre image must be initialized.
327 * @note This just returns the style set by SetStyle. In reality, only STYLE_QUAD is supported.
329 Style GetStyle() const;
332 * @DEPRECATED_1_1.11. Use ImageView instead.
334 * @brief Set the border used with STYLE_NINE_PATCH.
336 * The values are in pixels from the left, top, right, and bottom of the image respectively.
337 * 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.
339 * @param [in] border The new nine-patch border.
341 void SetNinePatchBorder(const Vector4& border);
344 * @DEPRECATED_1_1.11. Use ImageView instead.
346 * @brief Retrieve the border used with STYLE_NINE_PATCH.
349 * @return The nine-patch border.
351 Vector4 GetNinePatchBorder() const;
356 * @brief Allows modification of an actors position in the depth sort algorithm.
358 * The offset can be altered for each coplanar actor hence allowing an order of painting.
360 * @param [in] depthOffset the offset to be given to the actor. Positive values pushing it further back.
361 * @pre The Actor has been initialized.
363 void SetSortModifier(float depthOffset);
367 * @brief Retrieves the offset used to modify an actors position in the depth sort algorithm.
369 * The offset can be altered for each coplanar actor hence allowing an order of painting.
371 * @return the offset that has been given to the actor. Positive values pushing it further back.
372 * @pre The Actor has been initialized.
374 float GetSortModifier() const;
378 * @brief Sets the blending mode.
380 * Possible values are: BlendingMode::OFF, BlendingMode::AUTO and BlendingMode::ON. Default is BlendingMode::AUTO.
382 * If blending is disabled (BlendingMode::OFF) fade in and fade out animations do not work.
385 * <li> \e OFF Blending is disabled.
386 * <li> \e AUTO Blending is enabled only if the renderable actor has alpha channel.
387 * <li> \e ON Blending is enabled.
391 * @param[in] mode The blending mode.
393 void SetBlendMode( BlendingMode::Type mode );
397 * @brief Retrieves the blending mode.
400 * @return The blending mode, one of BlendingMode::OFF, BlendingMode::AUTO or BlendingMode::ON.
402 BlendingMode::Type GetBlendMode() const;
406 * @brief Specify the pixel arithmetic used when the actor is blended.
409 * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
410 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
411 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
412 * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
414 * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
415 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
416 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
417 * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
419 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
423 * @brief Specify the pixel arithmetic used when the actor is blended.
426 * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
427 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
428 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
429 * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
431 * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
432 * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
433 * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
434 * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
436 * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
437 * The options are the same as for srcFactorRgb.
439 * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
440 * The options are the same as for destFactorRgb.
442 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
443 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
447 * @brief Query the pixel arithmetic used when the actor is blended.
450 * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
451 * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
452 * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
453 * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
455 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
456 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
460 * @brief Specify the equation used when the actor is blended.
462 * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
464 * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
466 void SetBlendEquation( BlendingEquation::Type equationRgba );
470 * @brief Specify the equation used when the actor is blended.
473 * @param[in] equationRgb The equation used for combining red, green, and blue components.
474 * @param[in] equationAlpha The equation used for combining the alpha component.
475 * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
477 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
481 * @brief Query the equation used when the actor is blended.
484 * @param[out] equationRgb The equation used for combining red, green, and blue components.
485 * @param[out] equationAlpha The equation used for combining the alpha component.
487 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
491 * @brief Specify the color used when the actor is blended; the default is Vector4::ZERO.
494 * @param[in] color The blend color.
496 void SetBlendColor( const Vector4& color );
500 * @brief Query the color used when the actor is blended.
503 * @return The blend color.
505 const Vector4& GetBlendColor() const;
509 * @brief Sets the filtering mode.
511 * Possible values are: FilterMode::NEAREST and FilterMode::LINEAR. Default is FilterMode::LINEAR.
514 * <li> \e NEAREST Use nearest filtering
515 * <li> \e LINEAR Use linear filtering
519 * @param[in] minFilter The minification filtering mode.
520 * @param[in] magFilter The magnification filtering mode.
522 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
526 * @brief Retrieves the filtering mode.
529 * @param[out] minFilter The return minification value
530 * @param[out] magFilter The return magnification value
532 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter) const;
536 * @brief Sets the shader effect for the RenderableActor.
538 * Shader effects provide special effects like ripple and bend.
539 * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
541 * @param [in] effect The shader effect.
542 * @pre The actor has been initialized.
543 * @pre effect has been initialized.
545 void SetShaderEffect( ShaderEffect effect );
549 * @brief Retrieve the custom shader effect for the RenderableActor.
550 * If default shader is used an empty handle is returned.
553 * @return The shader effect
554 * @pre The Actor has been initialized.
556 ShaderEffect GetShaderEffect() const;
560 * @brief Removes the current shader effect.
563 * @pre The Actor has been initialized.
565 void RemoveShaderEffect();
568 public: // Not intended for application developers
570 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
576 * @brief Sets the shader effect for all ImageActors in a tree of Actors.
579 * @param [in] actor root of a tree of actors.
580 * @param [in] effect The shader effect.
581 * @see ImageActor::SetShaderEffect
584 DALI_IMPORT_API void SetShaderEffectRecursively( Actor actor, ShaderEffect effect );
588 * @brief Removes the shader effect from all ImageActors in a tree of Actors.
591 * @param [in] actor root of a tree of actors.
592 * @see ImageActor::RemoveShaderEffect
595 DALI_IMPORT_API void RemoveShaderEffectRecursively( Actor actor );
602 #endif // __DALI_IMAGE_ACTOR_H__