[NUI] VectorGraphics: Add list of added drawable object in DrawableGroup
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / VectorGraphics / DrawableGroup.cs
1 /* 
2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
3 *
4 * Licensed under the Apache License, Version 2.0 (the "License");
5 * you may not use this file except in compliance with the License.
6 * You may obtain a copy of the License at
7 *
8 * http://www.apache.org/licenses/LICENSE-2.0
9 *
10 * Unless required by applicable law or agreed to in writing, software
11 * distributed under the License is distributed on an "AS IS" BASIS,
12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 * See the License for the specific language governing permissions and
14 * limitations under the License.
15 *
16 */
17
18 using System;
19 using System.Collections.Generic;
20 using System.ComponentModel;
21
22 namespace Tizen.NUI.BaseComponents.VectorGraphics
23 {
24     /// <summary>
25     /// A class enabling to hold many Drawable objects. As a whole they can be transformed, their transparency can be changed.
26     /// </summary>
27     [EditorBrowsable(EditorBrowsableState.Never)]
28     public class DrawableGroup : Drawable
29     {
30         private List<Drawable> drawables; //The list of added drawables
31
32         /// <summary>
33         /// Creates an initialized DrawableGroup.
34         /// </summary>
35         [EditorBrowsable(EditorBrowsableState.Never)]
36         public DrawableGroup() : this(Interop.DrawableGroup.New(), true)
37         {
38             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
39         }
40
41         internal DrawableGroup(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
42         {
43             drawables = new List<Drawable>();
44         }
45
46         /// <summary>
47         /// Add drawable object to the DrawableGroup. This method is similar to registration.
48         /// </summary>
49         /// <param name="drawable">Drawable object</param>
50         /// <exception cref="ArgumentNullException"> Thrown when drawable is null. </exception>
51         [EditorBrowsable(EditorBrowsableState.Never)]
52         public void AddDrawable(Drawable drawable)
53         {
54             if (drawable == null)
55             {
56                 throw new ArgumentNullException(nameof(drawable));
57             }
58             Interop.DrawableGroup.AddDrawable(View.getCPtr(this), BaseHandle.getCPtr(drawable));
59             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
60             if (!drawables.Contains(drawable))
61             {
62                 drawables.Add(drawable);
63             }
64         }
65
66         /// <summary>
67         /// Clears the drawable object added to the DrawableGroup. 
68         /// This method does not free the memory of the added drawable object.
69         /// </summary>
70         /// <returns>True when it's successful. False otherwise.</returns>
71         [EditorBrowsable(EditorBrowsableState.Never)]
72         public bool Clear()
73         {
74             bool ret = Interop.DrawableGroup.Clear(BaseHandle.getCPtr(this));
75             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
76             if (ret)
77             {
78                 drawables.Clear();
79             }
80             return ret;
81         }
82     }
83 }