CanvasRenderer: Add Drawable::SetMask() API
[platform/core/uifw/dali-adaptor.git] / dali / devel-api / adaptor-framework / canvas-renderer-drawable.h
1 #ifndef DALI_CANVAS_RENDERER_DRAWABLE_H
2 #define DALI_CANVAS_RENDERER_DRAWABLE_H
3
4 /*
5  * Copyright (c) 2021 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 <dali/public-api/object/base-handle.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/canvas-renderer.h>
26 #include <dali/public-api/dali-adaptor-common.h>
27
28 namespace Dali
29 {
30 /**
31  * @addtogroup dali_adaptor_framework
32  * @{
33  */
34
35 namespace Internal DALI_INTERNAL
36 {
37 namespace Adaptor
38 {
39 class CanvasRenderer;
40 class Drawable;
41 class Shape;
42 } // namespace Adaptor
43 } // namespace DALI_INTERNAL
44
45 /**
46  * @brief Drawable is a object class for drawing a vector primitive.
47  */
48 class DALI_ADAPTOR_API CanvasRenderer::Drawable : public BaseHandle
49 {
50 public:
51   /**
52    * @brief Constructor
53    */
54   Drawable();
55
56   /**
57    * @brief Destructor.
58    */
59   ~Drawable();
60
61   /**
62    * @brief This copy constructor is required for (smart) pointer semantics.
63    *
64    * @param[in] handle A reference to the copied handle
65    */
66   Drawable(const Drawable& handle) = default;
67
68 public:
69   /**
70    * @brief Enumeration indicating the type used in the masking of two objects - the mask drawable and the own drawable.
71    */
72   enum class MaskType
73   {
74     ALPHA = 0,    ///< The pixels of the own drawable and the mask drawable are alpha blended. As a result, only the part of the own drawable, which intersects with the mask drawable is visible.
75     ALPHA_INVERSE ///< The pixels of the own drawable and the complement to the mask drawable's pixels are alpha blended. As a result, only the part of the own which is not covered by the mask is visible.
76   };
77
78 public:
79   /**
80    * @brief Set the transparency value
81    * @param[in] opacity The transparency level [0 ~ 1.0], 0 means totally transparent, while 1 means opaque.
82    * @return Returns True when it's successful. False otherwise.
83    */
84   bool SetOpacity(float opacity);
85
86   /**
87    * @brief Get the transparency value
88    * @return Returns the transparency level
89    */
90   float GetOpacity() const;
91
92   /**
93    * @brief Set the angle of rotation transformation.
94    * @param[in] degree The degree value of angle.
95    * @return Returns True when it's successful. False otherwise.
96    */
97   bool Rotate(Degree degree);
98
99   /**
100    * @brief Set the scale value of scale transformation.
101    * @param[in] factor The scale factor value.
102    * @return Returns True when it's successful. False otherwise.
103    */
104   bool Scale(float factor);
105
106   /**
107    * @brief Set the x, y movement value of translate transformation.
108    * @param[in] translate The x and y-axis movement value.
109    * @return Returns True when it's successful. False otherwise.
110    */
111   bool Translate(Vector2 translate);
112
113   /**
114    * @brief Set the matrix value for affine transform.
115    * @param[in] matrix The 3x3 matrix value.
116    * @return Returns True when it's successful. False otherwise.
117    */
118   bool Transform(const Dali::Matrix3& matrix);
119
120   /**
121    * @brief Gets the bounding box of the drawable object before any transformation.
122    * @note The bounding box doesn't indicate the rendering region in the result but primitive region of the object.
123    * @return Returns the bounding box information.
124    */
125   Rect<float> GetBoundingBox() const;
126
127   /**
128    * @brief The intersection with clip drawable is determined and only the resulting pixels from own drawable are rendered.
129    * @param[in] clip The clip drawable object.
130    * @return Returns True when it's successful. False otherwise.
131    */
132   bool SetClipPath(Drawable& clip);
133
134   /**
135    * @brief The pixels of mask drawable and own drawable are blended according to MaskType.
136    * @param[in] mask The mask drawable object.
137    * @param[in] type The masking type.
138    * @return Returns True when it's successful. False otherwise.
139    */
140   bool SetMask(Drawable& mask, MaskType type);
141
142   /**
143    * @brief Downcast a handle to Drawable handle.
144    *
145    * If handle points to an InputMethodContext the downcast produces valid
146    * handle. If not the returned handle is left uninitialized.
147    *
148    * @param[in] handle Handle to an object.
149    * @return Handle to an Drawable or an uninitialized handle.
150    */
151   static Drawable DownCast(BaseHandle handle);
152
153 public: // Not intended for application developers
154   /// @cond internal
155   /**
156    * @brief The constructor.
157    * @note  Not intended for application developers.
158    *
159    * @param[in] pointer A pointer to a newly allocated CanvasRenderer::Drawable
160    */
161   explicit DALI_INTERNAL Drawable(Internal::Adaptor::Drawable* pImpl);
162   /// @endcond
163 };
164
165 /**
166  * @}
167  */
168 } // namespace Dali
169
170 #endif // DALI_CANVAS_RENDERER_DRAWABLE_H