Removed DepthIndex methods from public-api
[platform/core/uifw/dali-core.git] / dali / public-api / actors / image-actor.h
1 #ifndef __DALI_IMAGE_ACTOR_H__
2 #define __DALI_IMAGE_ACTOR_H__
3
4 /*
5  * Copyright (c) 2015 Samsung Electronics Co., Ltd.
6  *
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
10  *
11  * http://www.apache.org/licenses/LICENSE-2.0
12  *
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.
18  *
19  */
20
21 // EXTERNAL INCLUDES
22 #include <string>
23
24 // INTERNAL INCLUDES
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>
28
29 namespace Dali
30 {
31
32 namespace Internal DALI_INTERNAL
33 {
34 class ImageActor;
35 }
36
37 /**
38  * @brief An actor for displaying images.
39  *
40  * Allows the developer to add an actor to stage which displays the content of an Image object.
41  *
42  * By default CullFaceMode is set to CullNone to enable the ImageActor to be viewed from all angles.
43  *
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.
48  *
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.
52  *
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.
55  *
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.
58  */
59 class DALI_IMPORT_API ImageActor : public RenderableActor
60 {
61 public:
62
63   /**
64    * @brief An enumeration of properties belonging to the ImageActor class.
65    * Properties additional to RenderableActor.
66    */
67   struct Property
68   {
69     enum
70     {
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":...}
75     };
76   };
77
78   /**
79    * @brief Style determines how the Image is rendered.
80    *
81    * @code
82    * STYLE_QUAD:
83    *
84    *  0---------2           0-----------------2
85    *  |        /|           |                /|
86    *  |  A    / |           |      A       /  |
87    *  |      /  |           |            /    |
88    *  |     /   | SCALE (X) |          /      |
89    *  |    /    | --------> |        /        |
90    *  |   /     |           |      /          |
91    *  |  /      |           |    /            |
92    *  | /    B  |           |  /        B     |
93    *  |/        |           |/                |
94    *  1---------3           1-----------------3
95    *
96    * Image is rendered as a textured rectangle. The texture
97    * is scaled uniformly as the quad is resized.
98    *
99    * STYLE_NINE_PATCH:
100    *
101    *  |---|---------------|---|       |---|-----------------------------|---|
102    *  | 1 |       2       | 3 |       | 1 |              2              | 3 |
103    *  |---|---------------|---|       |---|-----------------------------|---|
104    *  |   |               |   |       |   |                             |   |
105    *  |   |               |   |       |   |                             |   |
106    *  | 4 |       5       | 6 | SCALE |   |                             |   |
107    *  |   |               |   | ----> |   |                             |   |
108    *  |   |               |   |       | 4 |              5              | 6 |
109    *  |-------------------|---|       |   |                             |   |
110    *  | 7 |       8       | 9 |       |   |                             |   |
111    *  |---|---------------|---|       |   |                             |   |
112    *                                  |---------------------------------|---|
113    *                                  | 7 |              8              | 9 |
114    *                                  |---|-----------------------------|---|
115    *
116    * Image is rendered as a textured rectangle. The texture
117    * is scaled differently over each of the 9 sections.
118    *
119    * STYLE_NINE_PATCH_NO_CENTER:
120    *
121    * Image is rendered in the same way as STYLE_NINE_PATCH,
122    * but the Center Section (5) is not rendered.
123    * @endcode
124    *
125    * Visualise a Picture Frame:
126    *
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.
135    *
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.
140    */
141   enum Style
142   {
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.
146   };
147
148   /**
149    * @brief Pixel area is relative to the top-left (0,0) of the image.
150    */
151   typedef Rect<int> PixelArea;
152
153   /**
154    * @brief Create an uninitialized ImageActor handle.
155    *
156    * This can be initialized with ImageActor::New(...)
157    * Calling member functions with an uninitialized Dali::Object is not allowed.
158    */
159   ImageActor();
160
161   /**
162    * @brief Create an empty image actor object.
163    *
164    * @return A handle to a newly allocated actor.
165    */
166   static ImageActor New();
167
168   /**
169    * @brief Create a image actor object.
170    *
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.
177    */
178   static ImageActor New(Image image);
179
180   /**
181    * @brief Create a image actor object.
182    *
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.
191    */
192   static ImageActor New(Image image, PixelArea pixelArea);
193
194   /**
195    * @brief Downcast an Object handle to ImageActor.
196    *
197    *
198    * If handle points to a ImageActor the downcast produces valid
199    * handle. If not the returned handle is left uninitialized.
200    *
201    * @param[in] handle to An object
202    * @return handle to a ImageActor or an uninitialized handle
203    */
204   static ImageActor DownCast( BaseHandle handle );
205
206   /**
207    * @brief Destructor
208    *
209    * This is non-virtual since derived Handle types must not contain data or virtual methods.
210    */
211   ~ImageActor();
212
213   /**
214    * @brief Copy constructor
215    *
216    * @param [in] copy The actor to copy.
217    */
218   ImageActor(const ImageActor& copy);
219
220   /**
221    * @brief Assignment operator
222    *
223    * @param [in] rhs The actor to copy.
224    */
225   ImageActor& operator=(const ImageActor& rhs);
226
227   /**
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()
235    *
236    * @pre ImageActor must be initialized.
237    * @param [in] image The image to display.
238    */
239   void SetImage(Image image);
240
241   /**
242    * @brief Retrieve the image rendered by the actor.
243    *
244    * If no image is assigned, an empty handle is returned
245    * @return The image.
246    */
247   Image GetImage();
248
249   /**
250    * @brief Set a region of the image to display, in pixels.
251    *
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.
258    */
259   void SetPixelArea(const PixelArea& pixelArea);
260
261   /**
262    * @brief Retrieve the region of the image to display, in pixels.
263    *
264    * @pre image must be initialized.
265    * @return The pixel area, or a default-constructed area if none was set.
266    */
267   PixelArea GetPixelArea() const;
268
269   /**
270    * @brief Set how the image is rendered; the default is STYLE_QUAD.
271    *
272    * @pre image must be initialized.
273    * @param [in] style The new style.
274    */
275   void SetStyle(Style style);
276
277   /**
278    * @brief Query how the image is rendered.
279    *
280    * @pre image must be initialized.
281    * @return The rendering style.
282    */
283   Style GetStyle() const;
284
285   /**
286    * @brief Set the border used with STYLE_NINE_PATCH.
287    *
288    * The values are in pixels from the left, top, right, and bottom of the image respectively.
289    * 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.
290    * @param [in] border The new nine-patch border.
291    */
292   void SetNinePatchBorder(const Vector4& border);
293
294   /**
295    * @brief Retrieve the border used with STYLE_NINE_PATCH.
296    *
297    * @return The nine-patch border.
298    */
299   Vector4 GetNinePatchBorder() const;
300
301
302   /**
303    * @brief Allows modification of an actors position in the depth sort algorithm.
304    *
305    * The offset can be altered for each coplanar actor hence allowing an order of painting.
306    * @pre The Actor has been initialized.
307    * @param [in] depthOffset the offset to be given to the actor. Positive values pushing it further back.
308    */
309   void SetSortModifier(float depthOffset);
310
311   /**
312    * @brief Retrieves the offset used to modify an actors position in the depth sort algorithm.
313    *
314    * The offset can be altered for each coplanar actor hence allowing an order of painting.
315    * @pre The Actor has been initialized.
316    * @return  the offset that has been given to the actor. Positive values pushing it further back.
317    */
318   float GetSortModifier() const;
319
320   /**
321    * @brief Set the face-culling mode for this actor.
322    *
323    * @param[in] mode The culling mode.
324    */
325   void SetCullFace(CullFaceMode mode);
326
327   /**
328    * @brief Retrieve the face-culling mode for this actor.
329    *
330    * @return mode The culling mode.
331    */
332   CullFaceMode GetCullFace() const;
333
334   /**
335    * @brief Sets the blending mode.
336    *
337    * Possible values are: BlendingMode::OFF, BlendingMode::AUTO and BlendingMode::ON. Default is BlendingMode::AUTO.
338    *
339    * If blending is disabled (BlendingMode::OFF) fade in and fade out animations do not work.
340    *
341    * <ul>
342    *   <li> \e OFF Blending is disabled.
343    *   <li> \e AUTO Blending is enabled only if the renderable actor has alpha channel.
344    *   <li> \e ON Blending is enabled.
345    * </ul>
346    *
347    * @param[in] mode The blending mode.
348    */
349   void SetBlendMode( BlendingMode::Type mode );
350
351   /**
352    * @brief Retrieves the blending mode.
353    *
354    * @return The blending mode, one of BlendingMode::OFF, BlendingMode::AUTO or BlendingMode::ON.
355    */
356   BlendingMode::Type GetBlendMode() const;
357
358   /**
359    * @brief Specify the pixel arithmetic used when the actor is blended.
360    *
361    * @param[in] srcFactorRgba Specifies how the red, green, blue, and alpha source blending factors are computed.
362    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
363    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
364    * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
365    *
366    * @param[in] destFactorRgba Specifies how the red, green, blue, and alpha destination blending factors are computed.
367    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
368    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
369    * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
370    */
371   void SetBlendFunc( BlendingFactor::Type srcFactorRgba, BlendingFactor::Type destFactorRgba );
372
373   /**
374    * @brief Specify the pixel arithmetic used when the actor is blended.
375    *
376    * @param[in] srcFactorRgb Specifies how the red, green, and blue source blending factors are computed.
377    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
378    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
379    * GL_CONSTANT_ALPHA, GL_ONE_MINUS_CONSTANT_ALPHA, and GL_SRC_ALPHA_SATURATE.
380    *
381    * @param[in] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
382    * The options are BlendingFactor::ZERO, ONE, SRC_COLOR, ONE_MINUS_SRC_COLOR, DST_COLOR, ONE_MINUS_DST_COLOR,
383    * SRC_ALPHA, ONE_MINUS_SRC_ALPHA, DST_ALPHA, ONE_MINUS_DST_ALPHA, CONSTANT_COLOR, ONE_MINUS_CONSTANT_COLOR,
384    * GL_CONSTANT_ALPHA, and GL_ONE_MINUS_CONSTANT_ALPHA.
385    *
386    * @param[in] srcFactorAlpha Specifies how the alpha source blending factor is computed.
387    * The options are the same as for srcFactorRgb.
388    *
389    * @param[in] destFactorAlpha Specifies how the alpha source blending factor is computed.
390    * The options are the same as for destFactorRgb.
391    */
392   void SetBlendFunc( BlendingFactor::Type srcFactorRgb,   BlendingFactor::Type destFactorRgb,
393                      BlendingFactor::Type srcFactorAlpha, BlendingFactor::Type destFactorAlpha );
394
395   /**
396    * @brief Query the pixel arithmetic used when the actor is blended.
397    *
398    * @param[out] srcFactorRgb Specifies how the red, green, blue, and alpha source blending factors are computed.
399    * @param[out] destFactorRgb Specifies how the red, green, blue, and alpha destination blending factors are computed.
400    * @param[out] srcFactorAlpha Specifies how the red, green, blue, and alpha source blending factors are computed.
401    * @param[out] destFactorAlpha Specifies how the red, green, blue, and alpha destination blending factors are computed.
402    */
403   void GetBlendFunc( BlendingFactor::Type& srcFactorRgb,   BlendingFactor::Type& destFactorRgb,
404                      BlendingFactor::Type& srcFactorAlpha, BlendingFactor::Type& destFactorAlpha ) const;
405
406   /**
407    * @brief Specify the equation used when the actor is blended.
408    *
409    * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
410    * @param[in] equationRgba The equation used for combining red, green, blue, and alpha components.
411    */
412   void SetBlendEquation( BlendingEquation::Type equationRgba );
413
414   /**
415    * @brief Specify the equation used when the actor is blended.
416    *
417    * @param[in] equationRgb The equation used for combining red, green, and blue components.
418    * @param[in] equationAlpha The equation used for combining the alpha component.
419    * The options are BlendingEquation::ADD, SUBTRACT, or REVERSE_SUBTRACT.
420    */
421   void SetBlendEquation( BlendingEquation::Type equationRgb, BlendingEquation::Type equationAlpha );
422
423   /**
424    * @brief Query the equation used when the actor is blended.
425    *
426    * @param[out] equationRgb The equation used for combining red, green, and blue components.
427    * @param[out] equationAlpha The equation used for combining the alpha component.
428    */
429   void GetBlendEquation( BlendingEquation::Type& equationRgb, BlendingEquation::Type& equationAlpha ) const;
430
431   /**
432    * @brief Specify the color used when the actor is blended; the default is Vector4::ZERO.
433    *
434    * @param[in] color The blend color.
435    */
436   void SetBlendColor( const Vector4& color );
437
438   /**
439    * @brief Query the color used when the actor is blended.
440    *
441    * @return The blend color.
442    */
443   const Vector4& GetBlendColor() const;
444
445   /**
446    * @brief Sets the filtering mode.
447    *
448    * Possible values are: FilterMode::NEAREST and FilterMode::LINEAR. Default is FilterMode::LINEAR.
449    *
450    * <ul>
451    *   <li> \e NEAREST Use nearest filtering
452    *   <li> \e LINEAR Use linear filtering
453    * </ul>
454    *
455    * @param[in] minFilter The minification filtering mode.
456    * @param[in] magFilter The magnification filtering mode.
457    */
458   void SetFilterMode( FilterMode::Type minFilter, FilterMode::Type magFilter );
459
460   /**
461    * @brief Retrieves the filtering mode.
462    *
463    * @param[out] minFilter The return minification value
464    * @param[out] magFilter The return magnification value
465    */
466   void GetFilterMode( FilterMode::Type& minFilter, FilterMode::Type& magFilter) const;
467
468   /**
469    * @brief Sets the shader effect for the RenderableActor.
470    *
471    * Shader effects provide special effects like ripple and bend.
472    * Setting a shader effect removes any shader effect previously set by SetShaderEffect.
473    * @pre The actor has been initialized.
474    * @pre effect has been initialized.
475    * @param [in] effect The shader effect.
476    */
477   void SetShaderEffect( ShaderEffect effect );
478
479   /**
480    * @brief Retrieve the custom shader effect for the RenderableActor.
481    * If default shader is used an empty handle is returned.
482    *
483    * @pre The Actor has been initialized.
484    * @return The shader effect
485    */
486   ShaderEffect GetShaderEffect() const;
487
488   /**
489    * @brief Removes the current shader effect.
490    *
491    * @pre The Actor has been initialized.
492    */
493   void RemoveShaderEffect();
494
495
496 public: // Not intended for application developers
497
498   explicit DALI_INTERNAL ImageActor(Internal::ImageActor*);
499 };
500
501
502 /**
503  * @brief Sets the shader effect for all ImageActors in a tree of Actors.
504  *
505  * @see ImageActor::SetShaderEffect
506  *
507  * @param [in] actor root of a tree of actors.
508  * @param [in] effect The shader effect.
509  */
510 DALI_IMPORT_API void SetShaderEffectRecursively( Actor actor, ShaderEffect effect );
511
512 /**
513  * @brief Removes the shader effect from all ImageActors in a tree of Actors.
514  *
515  * @see ImageActor::RemoveShaderEffect
516  *
517  * @param [in] actor root of a tree of actors.
518  */
519 DALI_IMPORT_API void RemoveShaderEffectRecursively( Actor actor );
520
521 } // namespace Dali
522
523 #endif // __DALI_IMAGE_ACTOR_H__