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 @ref Actor::SetSize api or through an animation will
54 * stop the natural size being used.
57 * @remarks Use of ImageActor should be avoided unless shader effects need to be applied.
58 * For general purpose, use Toolkit::ImageView which has much better performance.
59 * @see Toolkit::ImageView
61 class DALI_IMPORT_API ImageActor : public Actor
66 * @brief An enumeration of properties belonging to the ImageActor class.
74 * @brief name "pixel-area", type Rect<int>
76 * @remarks This is an experimental feature and might not be supported in the next release.
77 * We do recommend not to use it.
79 PIXEL_AREA = DEFAULT_DERIVED_ACTOR_PROPERTY_START_INDEX,
81 * @brief name "style", type std::string
86 * @brief name "border", type Vector4
88 * @remarks This is an experimental feature and might not be supported in the next release.
89 * We do recommend not to use it.
93 * @brief name "image", type Map {"filename":"", "load-policy":...}
101 * @brief Style determines how the Image is rendered.
107 * @brief As a simple quad.
112 * @brief As a nine-patch.
114 * @remarks This is an experimental feature and might not be supported in the next release.
115 * We do recommend not to use it.
119 * @brief As a nine-patch without center section being rendered.
121 * @remarks This is an experimental feature and might not be supported in the next release.
122 * We do recommend not to use it.
124 STYLE_NINE_PATCH_NO_CENTER
128 * @brief Pixel area is relative to the top-left (0,0) of the image.
130 * @remarks This is an experimental feature and might not be supported in the next release.
131 * We do recommend not to use it.
133 typedef Rect<int> PixelArea;
135 static const BlendingMode::Type DEFAULT_BLENDING_MODE; ///< default value is BlendingMode::AUTO
138 * @brief Create an uninitialized ImageActor handle.
140 * This can be initialized with ImageActor::New(...).
141 * Calling member functions with an unintialized ImageActor handle is not allowed.
147 * @brief Create an empty image actor object.
150 * @return A handle to a newly allocated actor.
152 static ImageActor New();
155 * @brief Create a image actor object.
157 * The actor will take the image's natural size unless a custom size
158 * is chosen, e.g. via Actor:SetSize().
159 * If the handle is empty, ImageActor will display nothing
161 * @param[in] image The image to display.
162 * @return A handle to a newly allocated actor.
163 * @pre ImageActor must be initialized.
165 static ImageActor New(Image image);
168 * @brief Create a image actor object.
170 * The actor will take the image's natural size unless a custom size
171 * is chosen, e.g. via Actor:SetSize()
172 * If the handle is empty, ImageActor will display nothing
174 * @param [in] image The image to display.
175 * @param [in] pixelArea The area of the image to display.
176 * This in pixels, relative to the top-left (0,0) of the image.
177 * @return A handle to a newly allocated actor.
178 * @pre ImageActor must be initialized.
180 static ImageActor New(Image image, PixelArea pixelArea);
183 * @brief Downcast a handle to ImageActor handle.
186 * If handle points to a ImageActor the downcast produces valid
187 * handle. If not the returned handle is left uninitialized.
190 * @param[in] handle Handle to an object
191 * @return Handle to a ImageActor or an uninitialized handle
193 static ImageActor DownCast( BaseHandle handle );
198 * This is non-virtual since derived Handle types must not contain data or virtual methods.
204 * @brief Copy constructor
207 * @param [in] copy The actor to copy.
209 ImageActor(const ImageActor& copy);
212 * @brief Assignment operator
215 * @param [in] rhs The actor to copy.
216 * @return A reference to this
218 ImageActor& operator=(const ImageActor& rhs);
221 * @brief Set the image rendered by the actor.
223 * Set the image rendered by the actor.
224 * If actor was already displaying a different image, the old image is dropped and actor may
225 * temporarily display nothing. Setting an empty image (handle) causes the current image to be
226 * dropped and actor displays nothing.
227 * The actor will take the image's natural size unless a custom size
228 * is chosen, e.g. via Actor::SetSize()
231 * @param [in] image The image to display.
232 * @pre ImageActor must be initialized.
234 void SetImage(Image image);
237 * @brief Retrieve the image rendered by the actor.
239 * If no image is assigned, an empty handle is returned
246 * @brief Set a region of the image to display, in pixels.
248 * When the image is loaded the actor's size will be reset to the pixelArea,
249 * unless a custom size was chosen, e.g. via Actor::SetSize().
251 * @remarks This is an experimental feature and might not be supported in the next release.
252 * We do recommend not to use it.
253 * @param [in] pixelArea The area of the image to display.
254 * This in pixels, relative to the top-left (0,0) of the image.
255 * @pre Image must be initialized.
256 * @note PixelArea should be inside the image data size. It gets clamped by GL
258 void SetPixelArea(const PixelArea& pixelArea);
261 * @brief Retrieve the region of the image to display, in pixels.
264 * @remarks This is an experimental feature and might not be supported in the next release.
265 * We do recommend not to use it.
266 * @return The pixel area, or a default-constructed area if none was set.
267 * @pre Image must be initialized.
269 PixelArea GetPixelArea() const;
272 * @brief Set how the image is rendered; the default is STYLE_QUAD.
275 * @param [in] style The new style.
276 * @pre Image must be initialized.
278 void SetStyle(Style style);
281 * @brief Query how the image is rendered.
284 * @return The rendering style.
285 * @pre Image must be initialized.
287 Style GetStyle() const;
290 * @brief Set the border used with ImageActor::STYLE_NINE_PATCH.
292 * The values are in pixels from the left, top, right, and bottom of the image respectively.
293 * i.e. ImageActor::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 * @remarks This is an experimental feature and might not be supported in the next release.
296 * We do recommend not to use it.
297 * @param [in] border The new nine-patch border.
299 void SetNinePatchBorder(const Vector4& border);
302 * @brief Retrieve the border used with ImageActor::STYLE_NINE_PATCH.
305 * @remarks This is an experimental feature and might not be supported in the next release.
306 * We do recommend not to use it.
307 * @return The nine-patch border.
309 Vector4 GetNinePatchBorder() const;
313 * @brief Allows modification of an actors position in the depth sort algorithm.
315 * The offset can be altered for each coplanar actor hence allowing an order of painting.
317 * @remarks Avoid using this method as it's a legacy code. Rendering order of actors on the same z position should be
318 * determined by the depth level in the scene graph tree, not by this method
319 * @param [in] depthOffset The offset to be given to the actor. Positive values pushing it further back.
320 * @pre The Actor has been initialized.
321 * @see Layer::Behavior
323 void SetSortModifier(float depthOffset);
326 * @brief Retrieves the offset used to modify an actors position in the depth sort algorithm.
328 * The offset can be altered for each coplanar actor hence allowing an order of painting.
330 * @remarks Avoid using this method as it's a legacy code. Rendering order of actors on the same z position should be
331 * determined by the depth level in the scene graph tree, not by this method
332 * @return The offset that has been given to the actor. Positive values pushing it further back.
333 * @pre The Actor has been initialized.
334 * @see Layer::Behavior
336 float GetSortModifier() const;
339 * @brief Sets the blending mode.
341 * Possible values are: BlendingMode::OFF, BlendingMode::AUTO and BlendingMode::ON. Default is BlendingMode::AUTO.
343 * If blending is disabled (BlendingMode::OFF) fade in and fade out animations do not work.
346 * <li> \e OFF Blending is disabled.
347 * <li> \e AUTO Blending is enabled only if the renderable actor has alpha channel.
348 * <li> \e ON Blending is enabled.
352 * @remarks This is an experimental feature and might not be supported in the next release.
353 * We do recommend not to use it.
354 * @param[in] mode The blending mode.
356 void SetBlendMode( BlendingMode::Type mode );
359 * @brief Retrieves the blending mode.
362 * @remarks This is an experimental feature and might not be supported in the next release.
363 * We do recommend not to use it.
364 * @return The blending mode, one of BlendingMode::OFF, BlendingMode::AUTO or BlendingMode::ON.
366 BlendingMode::Type GetBlendMode() const;
369 * @brief Specify the pixel arithmetic used when the actor is blended.
372 * @remarks This is an experimental feature and might not be supported in the next release.
373 * We do recommend not to use it.
374 * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
376 * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
378 void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
381 * @brief Specify the pixel arithmetic used when the actor is blended.
384 * @remarks This is an experimental feature and might not be supported in the next release.
385 * We do recommend not to use it.
386 * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
388 * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
390 * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
392 * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
394 void SetBlendFunc( BlendingFactor::Type srcFactorRgb, BlendingFactor::Type destFactorRgb,
395 BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
398 * @brief Query the pixel arithmetic used when the actor is blended.
401 * @remarks This is an experimental feature and might not be supported in the next release.
402 * We do recommend not to use it.
403 * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
404 * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
405 * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
406 * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
408 void GetBlendFunc( BlendingFactor::Type& srcFactorRgb, BlendingFactor::Type& destFactorRgb,
409 BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
412 * @brief Specify the equation used when the actor is blended.
414 * The options are BlendingEquation::ADD, BlendingEquation::SUBTRACT, or BlendingEquation::REVERSE_SUBTRACT.
416 * @remarks This is an experimental feature and might not be supported in the next release.
417 * We do recommend not to use it.
418 * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
420 void SetBlendEquation( BlendingEquation::Type equationRgba );
423 * @brief Specify the equation used when the actor is blended.
426 * @remarks This is an experimental feature and might not be supported in the next release.
427 * We do recommend not to use it.
428 * @param[in] equationRgb The equation used for combining red, green, and blue components.
429 * @param[in] equationAlpha The equation used for combining the alpha component.
430 * The options are BlendingEquation::ADD, BlendingEquation::SUBTRACT, or BlendingEquation::REVERSE_SUBTRACT.
432 void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
435 * @brief Query the equation used when the actor is blended.
438 * @remarks This is an experimental feature and might not be supported in the next release.
439 * We do recommend not to use it.
440 * @param[out] equationRgb The equation used for combining red, green, and blue components.
441 * @param[out] equationAlpha The equation used for combining the alpha component.
443 void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
446 * @brief Specify the color used when the actor is blended; the default is Vector4::ZERO.
449 * @remarks This is an experimental feature and might not be supported in the next release.
450 * We do recommend not to use it.
451 * @param[in] color The blend color.
453 void SetBlendColor( const Vector4& color );
456 * @brief Query the color used when the actor is blended.
459 * @remarks This is an experimental feature and might not be supported in the next release.
460 * We do recommend not to use it.
461 * @return The blend color.
463 const Vector4& GetBlendColor() const;
466 * @brief Sets the filtering mode.
468 * Possible values are: FilterMode::NEAREST and FilterMode::LINEAR. Default is FilterMode::LINEAR.
471 * <li> \e NEAREST Use nearest filtering
472 * <li> \e LINEAR Use linear filtering
476 * @remarks This is an experimental feature and might not be supported in the next release.
477 * We do recommend not to use it.
478 * @param[in] minFilter The minification filtering mode.
479 * @param[in] magFilter The magnification filtering mode.
481 void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
484 * @brief Retrieves the filtering mode.
487 * @remarks This is an experimental feature and might not be supported in the next release.
488 * We do recommend not to use it.
489 * @param[out] minFilter The return minification value
490 * @param[out] magFilter The return magnification value
492 void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter) const;
495 * @brief Sets the shader effect for the ImageActor.
497 * Shader effects provide special effects like ripple and bend.
498 * Setting a shader effect removes any shader effect previously set by @ref ImageActor::SetShaderEffect.
500 * @param [in] effect The shader effect.
501 * @pre The actor has been initialized.
502 * @pre Effect has been initialized.
504 void SetShaderEffect( ShaderEffect effect );
507 * @brief Retrieve the custom shader effect for the ImageActor.
509 * If default shader is used an empty handle is returned.
512 * @return The shader effect
513 * @pre The Actor has been initialized.
515 ShaderEffect GetShaderEffect() const;
518 * @brief Removes the current shader effect.
521 * @pre The Actor has been initialized.
523 void RemoveShaderEffect();
526 public: // Not intended for application developers
528 explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
533 * @brief Sets the shader effect for all ImageActors in a tree of Actors.
536 * @param [in] actor Root of a tree of actors.
537 * @param [in] effect The shader effect.
538 * @see ImageActor::SetShaderEffect
541 DALI_IMPORT_API void SetShaderEffectRecursively( Dali::Actor actor, Dali::ShaderEffect effect );
544 * @brief Removes the shader effect from all ImageActors in a tree of Actors.
547 * @param [in] actor Root of a tree of actors.
548 * @see ImageActor::RemoveShaderEffect
551 DALI_IMPORT_API void RemoveShaderEffectRecursively( Dali::Actor actor );
558 #endif // __DALI_IMAGE_ACTOR_H__