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