CanvasRenderer: Add Drawable::SetClipPath() Api
[platform/core/uifw/dali-adaptor.git] / dali / internal / canvas-renderer / common / drawable-impl.h
1 #ifndef DALI_INTERNAL_DRAWABLE_IMPL_H
2 #define DALI_INTERNAL_DRAWABLE_IMPL_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-object.h>
23
24 // INTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/canvas-renderer-drawable.h>
26 #include <dali/devel-api/adaptor-framework/canvas-renderer.h>
27
28 namespace Dali
29 {
30 namespace Internal
31 {
32 namespace Adaptor
33 {
34 /**
35  * Dali internal Drawable.
36  */
37 class Drawable : public Dali::BaseObject
38 {
39 public:
40   /**
41    * @brief Enumeration for type of drawable.
42    */
43   enum class Types
44   {
45     NONE = 0,      ///< Means that type is not defined.
46     SHAPE,         ///< Meaning of Shape class that inherits Drawable.
47     DRAWABLE_GROUP ///< Meaning of DrawableGorup class that inherits Drawable.
48   };
49
50   /**
51    * @brief Enumeration indicating type used in the composition of two objects - the target and the source.
52    */
53   enum class CompositionType
54   {
55     NONE = 0,          ///< Means that type is not defined.
56     CLIP_PATH,         ///< The intersection of the source and the target is determined and only the resulting pixels from the source are rendered.
57     ALPHA_MASK,        ///< The pixels of the source and the target are alpha blended. As a result, only the part of the source, which intersects with the target is visible.
58     ALPHA_MASK_INVERSE ///< The pixels of the source and the complement to the target's pixels are alpha blended. As a result, only the part of the source which is not covered by the target is visible.
59   };
60
61 public:
62   /**
63    * @brief Constructor
64    */
65   Drawable();
66
67   /**
68    * @brief Destructor.
69    */
70   virtual ~Drawable() override;
71
72   /**
73    * @brief Create factory item(implementation) object.
74    */
75   void Create();
76
77   /**
78    * @copydoc Dali::CanvasRenderer::Drawable::SetOpacity()
79    */
80   virtual bool SetOpacity(float opacity);
81
82   /**
83    * @copydoc Dali::CanvasRenderer::Drawable::GetOpacity()
84    */
85   virtual float GetOpacity() const;
86
87   /**
88    * @copydoc Dali::CanvasRenderer::Drawable::Rotate()
89    */
90   virtual bool Rotate(Degree degree);
91
92   /**
93    * @copydoc Dali::CanvasRenderer::Drawable::Scale()
94    */
95   virtual bool Scale(float factor);
96
97   /**
98    * @copydoc Dali::CanvasRenderer::Drawable::Translate()
99    */
100   virtual bool Translate(Vector2 translate);
101
102   /**
103    * @copydoc Dali::CanvasRenderer::Drawable::Transform()
104    */
105   virtual bool Transform(const Dali::Matrix3& matrix);
106
107   /**
108    * @copydoc Dali::CanvasRenderer::Drawable::GetBoundingBox
109    */
110   virtual Rect<float> GetBoundingBox() const;
111
112   /**
113    * @copydoc Dali::CanvasRenderer::Drawable::SetClipPath()
114    */
115   virtual bool SetClipPath(Dali::CanvasRenderer::Drawable& clip);
116
117   /**
118    * @brief Returns a composition drawble object.
119    * @return Returns a composition drawble object.
120    */
121   virtual Dali::CanvasRenderer::Drawable GetCompositionDrawable() const;
122
123   /**
124    * @brief Returns a composition type
125    * @return Returns a composition type
126    */
127   virtual CompositionType GetCompositionType() const;
128
129   /**
130    * @brief Set whether this drawable object was added to other object(CanvasRenderer or DrawableGroup) or not.
131    * @param[in] added Ture if added, false otherwise.
132    */
133   virtual void SetAdded(bool added);
134
135   /**
136    * @brief Returns whether this drawable object was added to another object(CanvasRenderer or DrawableGroup).
137    * @return Returns Ture if added, false otherwise.
138    */
139   virtual bool IsAdded() const;
140
141   /**
142    * @brief Returns a drawable object pointer.
143    * @return Returns a drawable object pointer.
144    */
145   virtual void* GetObject() const;
146
147   /**
148    * @brief Set a drawable object
149    * @param[in] object drawable object
150    */
151   virtual void SetObject(const void* object);
152
153   /**
154    * @brief Set a changed state.
155    * @param[in] changed The state of changed.
156    */
157   virtual void SetChanged(bool changed);
158
159   /**
160    * @brief Get a changed state.
161    * @return Returns state of changed.
162    */
163   virtual bool GetChanged() const;
164
165   /**
166    * @brief Set drawable's type.
167    * @param[in] type Type of drawable.
168    */
169   virtual void SetType(Types type);
170
171   /**
172    * @brief Get drawable's type.
173    * @return Returns type of drawable.
174    */
175   virtual Types GetType() const;
176
177   /**
178    * @brief Returns a drawable's implements object pointer.
179    * @return Returns a drawable's implements object pointer.
180    */
181   Dali::Internal::Adaptor::Drawable* GetImplementation();
182
183   Drawable(const Drawable&) = delete;
184   Drawable& operator=(Drawable&) = delete;
185   Drawable(Drawable&&)           = delete;
186   Drawable& operator=(Drawable&&) = delete;
187
188 private:
189   Dali::Internal::Adaptor::Drawable* mImpl = nullptr;
190 };
191
192 } // namespace Adaptor
193
194 } // namespace Internal
195
196 inline static Internal::Adaptor::Drawable& GetImplementation(Dali::CanvasRenderer::Drawable& drawable)
197 {
198   DALI_ASSERT_ALWAYS(drawable && "Drawable handle is empty.");
199
200   BaseObject& handle = drawable.GetBaseObject();
201
202   return static_cast<Internal::Adaptor::Drawable&>(handle);
203 }
204
205 inline static const Internal::Adaptor::Drawable& GetImplementation(const Dali::CanvasRenderer::Drawable& drawable)
206 {
207   DALI_ASSERT_ALWAYS(drawable && "Drawable handle is empty.");
208
209   const BaseObject& handle = drawable.GetBaseObject();
210
211   return static_cast<const Internal::Adaptor::Drawable&>(handle);
212 }
213
214 } // namespace Dali
215
216 #endif // DALI_INTERNAL_DRAWABLE_IMPL_H