[dali_2.3.20] Merge branch 'devel/master'
[platform/core/uifw/dali-toolkit.git] / dali-toolkit / devel-api / controls / canvas-view / canvas-view.h
1 #ifndef DALI_TOOLKIT_CANVAS_VIEW_H
2 #define DALI_TOOLKIT_CANVAS_VIEW_H
3
4 /*
5  * Copyright (c) 2022 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 // INTERNAL INCLUDES
22 #include <dali-toolkit/public-api/controls/control.h>
23
24 // EXTERNAL INCLUDES
25 #include <dali/devel-api/adaptor-framework/canvas-renderer/canvas-renderer-drawable.h>
26 #include <dali/devel-api/adaptor-framework/canvas-renderer/canvas-renderer-shape.h>
27
28 namespace Dali
29 {
30 namespace Toolkit
31 {
32 namespace Internal DALI_INTERNAL
33 {
34 class CanvasView;
35 }
36 /**
37  * @addtogroup dali_toolkit_controls_canvas_view
38  * @{
39  */
40
41 /**
42  * @brief CanvasView is a class for displaying an vector primitives.
43  *
44  * @code
45  *    auto myCanvasView = CanvasView::New( viewBox ) ); //The viewBox is the size of viewbox of CanvasView.
46  *
47  *    //Create shape and set properties.
48  *    auto shape = Dali::CanvasRenderer::Shape::New();
49  *    shape.AddRect( 0, 0, 10, 10, 0, 0 );
50  *    shape.SetFillColor( Vector4( 1.0, 1.0, 1.0, 1.0 ) );
51  *    myCanvasView.AddDrawable( shape );
52  * @endcode
53  *
54  * @section CanvasViewProperties Properties
55  * |%Property enum                    |String name          |Type            |Writable|Animatable|
56  * |----------------------------------|---------------------|----------------|--------|----------|
57  * | Property::VIEW_BOX               | viewBox             |  Vector2       | O      | X        |
58  *
59  */
60 class DALI_TOOLKIT_API CanvasView : public Control
61 {
62 public:
63   /**
64    * @brief The start and end property ranges for this control.
65    */
66   enum PropertyRange
67   {
68     PROPERTY_START_INDEX = Control::CONTROL_PROPERTY_END_INDEX + 1,
69   };
70
71   /**
72    * @brief An enumeration of properties belonging to the CanvasView class.
73    */
74   struct Property
75   {
76     /**
77      * @brief An enumeration of properties belonging to the CanvasView class.
78      */
79     enum
80     {
81       /**
82        * @brief the viewbox of the CanvasView.
83        * @details Name "viewBox", type Property::VECTOR2.
84        */
85       VIEW_BOX = PROPERTY_START_INDEX,
86
87       /**
88        * @brief Whether to load the canvas synchronously.
89        * @details Name "synchronousLoading", type Property::BOOLEAN.
90        */
91       SYNCHRONOUS_LOADING,
92     };
93   };
94 public:
95   /**
96    * @brief Creates an uninitialized CanvasView.
97    */
98   CanvasView();
99
100   /**
101    * @brief Creates an initialized CanvasView
102    *
103    * @return A handle to a newly allocated CanvasView
104    */
105   static CanvasView New();
106
107   /**
108    * @brief Creates an initialized CanvasView
109    *
110    * @param [in] viewBox The width and height.
111    * @return A handle to a newly allocated CanvasView
112    */
113   static CanvasView New(const Vector2& viewBox);
114
115   /**
116    * @brief Destructor.
117    *
118    * This is non-virtual since derived Handle types must not contain data or virtual methods.
119    */
120   ~CanvasView();
121
122   /**
123    * @brief Copy constructor.
124    *
125    * @param[in] canvasView CanvasView to copy. The copied CanvasView will point at the same implementation
126    */
127   CanvasView(const CanvasView& canvasView);
128
129   /**
130    * @brief Move constructor
131    *
132    * @param[in] rhs A reference to the moved handle
133    */
134   CanvasView(CanvasView&& rhs);
135
136   /**
137    * @brief Assignment operator.
138    *
139    * @param[in] canvasView The CanvasView to assign from
140    * @return The updated CanvasView
141    */
142   CanvasView& operator=(const CanvasView& canvasView);
143
144   /**
145    * @brief Move assignment
146    *
147    * @param[in] rhs A reference to the moved handle
148    * @return A reference to this
149    */
150   CanvasView& operator=(CanvasView&& rhs);
151
152   /**
153    * @brief Downcasts a handle to CanvasView handle.
154    *
155    * If handle points to a CanvasView, the downcast produces valid handle.
156    * If not, the returned handle is left uninitialized.
157    *
158    * @param[in] handle Handle to an object
159    * @return Handle to a CanvasView or an uninitialized handle
160    */
161   static CanvasView DownCast(BaseHandle handle);
162
163   /**
164    * @brief Add drawable object to the CanvasView.
165    * This method is similar to registration. The added shape is drawn on the inner canvas.
166    * @param[in] drawable the drawable object.
167    */
168   void AddDrawable(Dali::CanvasRenderer::Drawable& drawable);
169
170   /**
171    * @brief Remove drawable object to the CanvasView.
172    * This method is similar to deregistration.
173    * @param[in] drawable the drawable object.
174    * @return Returns True when it's successful. False otherwise.
175    */
176   bool RemoveDrawable(Dali::CanvasRenderer::Drawable& drawable);
177
178   /**
179    * @brief Remove all drawable objects added to the CanvasView.
180    */
181   void RemoveAllDrawables();
182
183 public: // Not intended for application developers
184   /// @cond internal
185   /**
186    * @brief Creates a handle using the Toolkit::Internal implementation.
187    *
188    * @param[in] implementation The CanvasView implementation
189    */
190   DALI_INTERNAL CanvasView(Internal::CanvasView& implementation);
191
192   /**
193    * @brief Allows the creation of this CanvasView from an Internal::CustomActor pointer.
194    *
195    * @param[in] internal A pointer to the internal CustomActor
196    */
197   DALI_INTERNAL CanvasView(Dali::Internal::CustomActor* internal);
198   /// @endcond
199 };
200
201 /**
202  * @}
203  */
204 } // namespace Toolkit
205
206 } // namespace Dali
207
208 #endif // DALI_TOOLKIT_CANVAS_VIEW_H