2 * Copyright(c) 2021 Samsung Electronics Co., Ltd.
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
8 * http://www.apache.org/licenses/LICENSE-2.0
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.
18 using System.ComponentModel;
19 using System.Collections.Generic;
20 using System.Diagnostics.CodeAnalysis;
21 using Tizen.NUI.Binding;
23 namespace Tizen.NUI.BaseComponents.VectorGraphics
26 /// CanvasView is a class for displaying vector primitives.
28 /// <since_tizen> 9 </since_tizen>
29 public class CanvasView : View
31 private List<Drawable> drawables; //The list of added drawables
33 static CanvasView() { }
38 [EditorBrowsable(EditorBrowsableState.Never)]
39 public static readonly BindableProperty ViewBoxProperty = BindableProperty.Create(nameof(ViewBox), typeof(Tizen.NUI.Size2D), typeof(Tizen.NUI.BaseComponents.VectorGraphics.CanvasView), null, propertyChanged: (bindable, oldValue, newValue) =>
41 var instance = (Tizen.NUI.BaseComponents.VectorGraphics.CanvasView)bindable;
44 instance.InternalViewBox = (Tizen.NUI.Size2D)newValue;
47 defaultValueCreator: (bindable) =>
49 var instance = (Tizen.NUI.BaseComponents.VectorGraphics.CanvasView)bindable;
50 return instance.InternalViewBox;
54 /// Creates an initialized CanvasView.
56 /// <since_tizen> 9 </since_tizen>
57 public CanvasView() : this(Interop.CanvasView.New(), true)
59 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
63 /// Creates an initialized CanvasView.
65 /// <param name="viewBox">The size of viewbox.</param>
66 /// <exception cref="ArgumentNullException"> Thrown when viewBox is null. </exception>
67 /// <since_tizen> 9 </since_tizen>
68 [SuppressMessage("Microsoft.Design", "CA2000: Dispose objects before losing scope", Justification = "It does not have dispose ownership.")]
69 public CanvasView(Size2D viewBox) : this(viewBox == null ? throw new ArgumentNullException(nameof(viewBox)) : Interop.CanvasView.New(Uint16Pair.getCPtr(new Uint16Pair((uint)viewBox.Width, (uint)viewBox.Height))), true)
71 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
74 internal CanvasView(global::System.IntPtr cPtr, bool shown = true) : base(cPtr, shown)
76 drawables = new List<Drawable>();
84 /// You can override it to clean-up your own resources.
86 /// <param name="type">DisposeTypes</param>
87 [EditorBrowsable(EditorBrowsableState.Never)]
88 protected override void Dispose(DisposeTypes type)
95 if (type == DisposeTypes.Explicit)
103 /// This will not be public opened.
104 [EditorBrowsable(EditorBrowsableState.Never)]
105 protected override void ReleaseSwigCPtr(System.Runtime.InteropServices.HandleRef swigCPtr)
107 Interop.CanvasView.DeleteCanvasView(swigCPtr);
108 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
112 /// The viewbox of the CanvasView.
113 /// The viewbox means the size of CanvasView's internal space.
114 /// If the size of the viewbox is larger than the size of the CanvasView, the shapes are displayed smaller than the specified size.
115 /// The default value of the viewbox is the same as the size of the canvasview.
117 /// <since_tizen> 9 </since_tizen>
118 public Size2D ViewBox
122 return GetValue(ViewBoxProperty) as Size2D;
126 SetValue(ViewBoxProperty, value);
127 NotifyPropertyChanged();
131 private Size2D InternalViewBox
135 Size2D retVal = new Size2D(0, 0);
136 PropertyValue viewBoxPropertyValue = GetProperty(Interop.CanvasView.PropertyViewBoxGet());
137 viewBoxPropertyValue?.Get(retVal);
138 viewBoxPropertyValue?.Dispose();
143 PropertyValue setVal = new Tizen.NUI.PropertyValue(value);
144 SetProperty(Interop.CanvasView.PropertyViewBoxGet(), setVal);
145 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
151 /// Add drawable object to the CanvasView.
152 /// This method is similar to registration. The added shape is drawn on the inner canvas.
154 /// <param name="drawable">Drawable object</param>
155 /// <exception cref="ArgumentNullException"> Thrown when drawable is null. </exception>
156 /// <since_tizen> 9 </since_tizen>
157 public void AddDrawable(Drawable drawable)
159 if (drawable == null)
161 throw new ArgumentNullException(nameof(drawable));
163 Interop.CanvasView.AddDrawable(View.getCPtr(this), BaseHandle.getCPtr(drawable));
164 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
165 if (!drawables.Contains(drawable))
167 drawables.Add(drawable);
172 /// Remove drawable object to the CanvasView.
173 /// This method is similar to deregistration.
175 /// <param name="drawable">Drawable object</param>
176 /// <exception cref="ArgumentNullException"> Thrown when drawable is null. </exception>
177 /// <since_tizen> 9 </since_tizen>
178 public void RemoveDrawable(Drawable drawable)
180 if (drawable == null)
182 throw new ArgumentNullException(nameof(drawable));
184 Interop.CanvasView.RemoveDrawable(View.getCPtr(this), BaseHandle.getCPtr(drawable));
185 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
186 drawables.Remove(drawable);
190 /// Remove all drawable objects added to the CanvasView.
192 /// <since_tizen> 9 </since_tizen>
193 public void RemoveAllDrawables()
195 Interop.CanvasView.RemoveAllDrawables(View.getCPtr(this));
196 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();