CanvasRenderer: Refactoring tvgObject management
[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 #ifdef THORVG_SUPPORT
23 #include <thorvg.h>
24 #endif
25 #include <dali/public-api/object/base-object.h>
26
27 // INTERNAL INCLUDES
28 #include <dali/devel-api/adaptor-framework/canvas-renderer-drawable.h>
29 #include <dali/devel-api/adaptor-framework/canvas-renderer.h>
30
31 namespace Dali
32 {
33 namespace Internal
34 {
35 namespace Adaptor
36 {
37 /**
38  * Dali internal Drawable.
39  */
40 class Drawable : public Dali::BaseObject
41 {
42 public:
43   /**
44    * @brief Enumeration for type of drawable.
45    */
46   enum class Types
47   {
48     NONE = 0,      ///< Means that type is not defined.
49     SHAPE,         ///< Meaning of Shape class that inherits Drawable.
50     DRAWABLE_GROUP ///< Meaning of DrawableGorup class that inherits Drawable.
51   };
52
53 public:
54   /**
55    * @brief Constructor
56    */
57   Drawable();
58
59   /**
60    * @brief Destructor.
61    */
62   virtual ~Drawable() override;
63
64   /**
65    * @brief Create factory item(implementation) object.
66    */
67   void Create();
68
69   /**
70    * @copydoc Dali::CanvasRenderer::Drawable::SetOpacity
71    */
72   virtual bool SetOpacity(float opacity);
73
74   /**
75    * @copydoc Dali::CanvasRenderer::Drawable::GetOpacity
76    */
77   virtual float GetOpacity() const;
78
79   /**
80    * @copydoc Dali::CanvasRenderer::Drawable::Rotate
81    */
82   virtual bool Rotate(Degree degree);
83
84   /**
85    * @copydoc Dali::CanvasRenderer::Drawable::Scale
86    */
87   virtual bool Scale(float factor);
88
89   /**
90    * @copydoc Dali::CanvasRenderer::Drawable::Translate
91    */
92   virtual bool Translate(Vector2 translate);
93
94   /**
95    * @copydoc Dali::CanvasRenderer::Drawable::Transform
96    */
97   virtual bool Transform(const Dali::Matrix3& matrix);
98
99   /**
100    * @copydoc Dali::CanvasRenderer::Drawable::GetBoundingBox
101    */
102   virtual Rect<float> GetBoundingBox() const;
103
104   /**
105    * @brief Set whether this drawable object was added to other object(CanvasRenderer or DrawableGroup) or not.
106    * @param[in] added Ture if added, false otherwise.
107    */
108   virtual void SetAdded(bool added);
109
110   /**
111    * @brief Returns whether this drawable object was added to another object(CanvasRenderer or DrawableGroup).
112    * @return Returns Ture if added, false otherwise.
113    */
114   virtual bool IsAdded() const;
115
116   /**
117    * @brief Returns a drawable object pointer.
118    * @return Returns a drawable object pointer.
119    */
120   virtual void* GetObject() const;
121
122   /**
123    * @brief Set a drawable object
124    * @param[in] object drawable object
125    */
126   virtual void SetObject(const void* object);
127
128   /**
129    * @brief Set a changed state.
130    * @param[in] changed The state of changed.
131    */
132   virtual void SetChanged(bool changed);
133
134   /**
135    * @brief Get a changed state.
136    * @return Returns state of changed.
137    */
138   virtual bool GetChanged() const;
139
140   /**
141    * @brief Set drawable's type.
142    * @param[in] type Type of drawable.
143    */
144   virtual void SetType(Types type);
145
146   /**
147    * @brief Get drawable's type.
148    * @return Returns type of drawable.
149    */
150   virtual Types GetType() const;
151
152   /**
153    * @brief Returns a drawable's implements object pointer.
154    * @return Returns a drawable's implements object pointer.
155    */
156   Dali::Internal::Adaptor::Drawable* GetImplementation();
157
158   Drawable(const Drawable&) = delete;
159   Drawable& operator=(Drawable&) = delete;
160   Drawable(Drawable&&)           = delete;
161   Drawable& operator=(Drawable&&) = delete;
162
163 private:
164   Dali::Internal::Adaptor::Drawable* mImpl = nullptr;
165 };
166
167 } // namespace Adaptor
168
169 } // namespace Internal
170
171 inline static Internal::Adaptor::Drawable& GetImplementation(Dali::CanvasRenderer::Drawable& drawable)
172 {
173   DALI_ASSERT_ALWAYS(drawable && "Drawable handle is empty.");
174
175   BaseObject& handle = drawable.GetBaseObject();
176
177   return static_cast<Internal::Adaptor::Drawable&>(handle);
178 }
179
180 inline static const Internal::Adaptor::Drawable& GetImplementation(const Dali::CanvasRenderer::Drawable& drawable)
181 {
182   DALI_ASSERT_ALWAYS(drawable && "Drawable handle is empty.");
183
184   const BaseObject& handle = drawable.GetBaseObject();
185
186   return static_cast<const Internal::Adaptor::Drawable&>(handle);
187 }
188
189 } // namespace Dali
190
191 #endif // DALI_INTERNAL_DRAWABLE_IMPL_H