[NUI] CanvasView: Add Exception handling and license
[platform/core/csapi/tizenfx.git] / src / Tizen.NUI / src / public / BaseComponents / VectorGraphcis / Shape.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.ComponentModel;
19 using System.Collections.Generic;
20
21 namespace Tizen.NUI.BaseComponents.VectorGraphics
22 {
23     /// <summary>
24     /// Shape is a command list for drawing one shape groups It has own path data and properties for sync/asynchronous drawing
25     /// </summary>
26     [EditorBrowsable(EditorBrowsableState.Never)]
27     public class Shape : Drawable
28     {
29         /// <summary>
30         /// Creates an initialized Shape.
31         /// </summary>
32         [EditorBrowsable(EditorBrowsableState.Never)]
33         public Shape() : this(Interop.Shape.New(), true)
34         {
35             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
36         }
37
38         internal Shape(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
39         {
40         }
41
42         /// <summary>
43         /// Enumeration for The cap style to be used for stroking the path.
44         /// </summary>
45         [EditorBrowsable(EditorBrowsableState.Never)]
46         public enum StrokeCap
47         {
48             /// <summary>
49             /// The end of lines is rendered as a square around the last point.
50             /// </summary>
51             Square = 0,
52             /// <summary>
53             /// The end of lines is rendered as a half-circle around the last point.
54             /// </summary>
55             Round,
56             /// <summary>
57             /// The end of lines is rendered as a full stop on the last point itself.
58             /// </summary>
59             Butt
60         }
61
62         /// <summary>
63         /// numeration for The join style to be used for stroking the path.
64         /// </summary>
65         [EditorBrowsable(EditorBrowsableState.Never)]
66         public enum StrokeJoin
67         {
68             /// <summary>
69             /// Used to render beveled line joins. The outer corner of the joined lines is filled by enclosing the triangular region of the corner with a straight line between the outer corners of each stroke.
70             /// </summary>
71             Bevel = 0,
72             /// <summary>
73             /// Used to render rounded line joins. Circular arcs are used to join two lines smoothly.
74             /// </summary>
75             Round,
76             /// <summary>
77             /// Used to render mitered line joins. The intersection of the strokes is clipped at a line perpendicular to the bisector of the angle between the strokes, at the distance from the intersection of the segments equal to the product of the miter limit value and the border radius.  This prevents long spikes being created.
78             /// </summary>
79             Miter
80         }
81
82         /// <summary>
83         /// Enumeration for The fill rule of shape.
84         /// </summary>
85         [EditorBrowsable(EditorBrowsableState.Never)]
86         public enum FillRule
87         {
88             /// <summary>
89             /// Draw a horizontal line from the point to a location outside the shape. Determine whether the direction of the line at each intersection point is up or down. The winding number is determined by summing the direction of each intersection. If the number is non zero, the point is inside the shape.
90             /// </summary>
91             Winding = 0,
92             /// <summary>
93             /// Draw a horizontal line from the point to a location outside the shape, and count the number of intersections. If the number of intersections is an odd number, the point is inside the shape.
94             /// </summary>
95             EvenOdd
96         }
97
98         /// <summary>
99         /// Append the given rectangle with rounded corner to the path.
100         /// The roundedCorner arguments specify the radii of the ellipses defining the
101         /// corners of the rounded rectangle.
102         ///
103         /// roundedCorner are specified in terms of width and height respectively.
104         ///
105         /// If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
106         /// </summary>
107         /// <param name="x">X co-ordinate of the rectangle.</param>
108         /// <param name="y">Y co-ordinate of the rectangle.</param>
109         /// <param name="width">Width of the rectangle.</param>
110         /// <param name="height">Height of the rectangle.</param>
111         /// <param name="roundedCornerX">The x radius of the rounded corner and should be in range [ 0 to w/2 ].</param>
112         /// <param name="roundedCornerY">The y radius of the rounded corner and should be in range [ 0 to w/2 ].</param>
113         /// <returns>True when it's successful. False otherwise.</returns>
114         [EditorBrowsable(EditorBrowsableState.Never)]
115         public bool AddRect(float x, float y, float width, float height, float roundedCornerX, float roundedCornerY)
116         {   
117             bool ret = Interop.Shape.AddRect(BaseHandle.getCPtr(this), x, y, width, height, roundedCornerX, roundedCornerY);
118             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119             return ret;
120         }
121
122         /// <summary>
123         /// Append a circle with given center and x,y-axis radius
124         /// </summary>
125         /// <param name="x">X co-ordinate of the center of the circle.</param>
126         /// <param name="y">Y co-ordinate of the center of the circle.</param>
127         /// <param name="radiusX">X axis radius of the circle.</param>
128         /// <param name="radiusY">X axis radius of the circle.</param>
129         /// <returns>True when it's successful. False otherwise.</returns>
130         [EditorBrowsable(EditorBrowsableState.Never)]
131         public bool AddCircle(float x, float y, float radiusX, float radiusY)
132         {
133             bool ret = Interop.Shape.AddCircle(BaseHandle.getCPtr(this), x, y, radiusX, radiusY);
134             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
135             return ret;
136         }
137
138         /// <summary>
139         /// Append the arcs.
140         /// </summary>
141         /// <param name="x">X co-ordinate of end point of the arc.</param>
142         /// <param name="y">Y co-ordinate of end point of the arc.</param>
143         /// <param name="radius">Radius of arc</param>
144         /// <param name="startAngle">Start angle (in degrees) where the arc begins.</param>
145         /// <param name="sweep">The Angle measures how long the arc will be drawn.</param>
146         /// <param name="pie">If True, the area is created by connecting start angle point and sweep angle point of the drawn arc. If false, it doesn't.</param>
147         /// <returns>True when it's successful. False otherwise.</returns>
148         [EditorBrowsable(EditorBrowsableState.Never)]
149         public bool AddArc(float x, float y, float radius, float startAngle, float sweep, bool pie)
150         {
151             bool ret = Interop.Shape.AddArc(BaseHandle.getCPtr(this), x, y, radius, startAngle, sweep, pie);
152             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153             return ret;
154         }
155
156         /// <summary>
157         /// Add a point that sets the given point as the current point,
158         /// implicitly starting a new subpath and closing the previous one.
159         /// </summary>
160         /// <param name="x">X co-ordinate of the current point.</param>
161         /// <param name="y">Y co-ordinate of the current point.</param>
162         /// <returns>True when it's successful. False otherwise.</returns>
163         [EditorBrowsable(EditorBrowsableState.Never)]
164         public bool AddMoveTo(float x, float y)
165         {
166             bool ret = Interop.Shape.AddMoveTo(BaseHandle.getCPtr(this), x, y);
167             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
168             return ret;
169         }
170
171         /// <summary>
172         /// Adds a straight line from the current position to the given end point.
173         /// After the line is drawn, the current position is updated to be at the
174         /// end point of the line.
175         /// If no current position present, it draws a line to itself, basically * a point.
176         /// </summary>
177         /// <param name="x">X co-ordinate of end point of the line.</param>
178         /// <param name="y">Y co-ordinate of end point of the line.</param>
179         /// <returns>True when it's successful. False otherwise.</returns>
180         [EditorBrowsable(EditorBrowsableState.Never)]
181         public bool AddLineTo(float x, float y)
182         {
183             bool ret = Interop.Shape.AddLineTo(BaseHandle.getCPtr(this), x, y);
184             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
185             return ret;
186         }
187
188         /// <summary>
189         /// Adds a cubic Bezier curve between the current position and the
190         /// given end point (lineEndPoint) using the control points specified by
191         /// (controlPoint1), and (controlPoint2). After the path is drawn,
192         /// the current position is updated to be at the end point of the path.
193         /// </summary>
194         /// <param name="controlPoint1X">X co-ordinate of 1st control point.</param>
195         /// <param name="controlPoint1Y">Y co-ordinate of 1st control point.</param>
196         /// <param name="controlPoint2X">X co-ordinate of 2nd control point.</param>
197         /// <param name="controlPoint2Y">Y co-ordinate of 2nd control point.</param>
198         /// <param name="endPointX">X co-ordinate of end point of the line.</param>
199         /// <param name="endPointY">Y co-ordinate of end point of the line.</param>
200         /// <returns>True when it's successful. False otherwise.</returns>
201         [EditorBrowsable(EditorBrowsableState.Never)]
202         public bool AddCubicTo(float controlPoint1X, float controlPoint1Y, float controlPoint2X, float controlPoint2Y, float endPointX, float endPointY)
203         {
204             bool ret = Interop.Shape.AddCubicTo(BaseHandle.getCPtr(this),  controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPointX, endPointY);
205             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206             return ret;
207         }
208
209         /// <summary>
210         /// Closes the current subpath by drawing a line to the beginning of the
211         /// subpath, automatically starting a new path. The current point of the
212         /// new path is (0, 0).
213         /// If the subpath does not contain any points, this function does nothing.
214         /// </summary>
215         /// <returns>True when it's successful. False otherwise.</returns>
216         [EditorBrowsable(EditorBrowsableState.Never)]
217         public bool Close()
218         {
219             bool ret = Interop.Shape.Close(BaseHandle.getCPtr(this));
220             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
221             return ret;
222         }
223
224         /// <summary>
225         /// Set the color to use for filling the path.
226         /// </summary>
227         /// <param name="color">The color value.</param>
228         /// <returns>True when it's successful. False otherwise.</returns>
229         [EditorBrowsable(EditorBrowsableState.Never)]
230         public bool SetFillColor(Color color)
231         {   
232             bool ret = Interop.Shape.SetFillColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color));
233             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
234             return ret;
235         }
236
237         /// <summary>
238         /// Get the color to use for filling the path.
239         /// </summary>
240         /// <returns>Returns the color value.</returns>
241         [EditorBrowsable(EditorBrowsableState.Never)]
242         public Color GetFillColor()
243         {   
244             global::System.IntPtr cPtr = Interop.Shape.GetFillColor(BaseHandle.getCPtr(this));
245             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
246             Color ret = Vector4.GetVector4FromPtr(cPtr);
247             return ret;
248         }
249
250         /// <summary>
251         /// Set the fill rule.
252         /// </summary>
253         /// <param name="rule">The current fill rule of the shape.</param>
254         /// <returns>True when it's successful. False otherwise.</returns>
255         [EditorBrowsable(EditorBrowsableState.Never)]
256         public bool SetFillRule(FillRule rule)
257         {
258             bool ret = Interop.Shape.SetFillRule(BaseHandle.getCPtr(this), (int)rule);
259             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
260             return ret;
261         }
262
263         /// <summary>
264         /// Get the fill rule.
265         /// </summary>
266         /// <returns>Returns the current fill rule of the shape.</returns>
267         [EditorBrowsable(EditorBrowsableState.Never)]
268         public FillRule GetFillRule()
269         {
270             FillRule ret = (FillRule)Interop.Shape.GetFillRule(BaseHandle.getCPtr(this));
271             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
272             return ret;
273         }
274
275         /// <summary>
276         /// Set the stroke width to use for stroking the path.
277         /// </summary>
278         /// <param name="width">Stroke width to be used.</param>
279         /// <returns>True when it's successful. False otherwise.</returns>
280         [EditorBrowsable(EditorBrowsableState.Never)]
281         public bool SetStrokeWidth(float width)
282         {
283             bool ret = Interop.Shape.SetStrokeWidth(BaseHandle.getCPtr(this), width);
284             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
285             return ret;
286         }
287
288         /// <summary>
289         /// Get the stroke width to use for stroking the path.
290         /// </summary>
291         /// <returns>Returns stroke width to be used.</returns>
292         [EditorBrowsable(EditorBrowsableState.Never)]
293         public float GetStrokeWidth()
294         {
295             float ret = Interop.Shape.GetStrokeWidth(BaseHandle.getCPtr(this));
296             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
297             return ret;
298         }
299         
300         /// <summary>
301         /// Set the color to use for stroking the path.
302         /// </summary>
303         /// <param name="color">The stroking color.</param>
304         /// <returns>True when it's successful. False otherwise.</returns>
305         [EditorBrowsable(EditorBrowsableState.Never)]
306         public bool SetStrokeColor(Color color)
307         {
308             bool ret = Interop.Shape.SetStrokeColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color));
309             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
310             return ret;
311         }
312
313         /// <summary>
314         /// Get the color to use for stroking the path.
315         /// </summary>
316         /// <returns>Returns the stroking color.</returns>
317         [EditorBrowsable(EditorBrowsableState.Never)]
318         public Color GetStrokeColor()
319         {
320             global::System.IntPtr cPtr = Interop.Shape.GetStrokeColor(BaseHandle.getCPtr(this));
321             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
322             Color ret = Vector4.GetVector4FromPtr(cPtr);
323             return ret;
324         }
325
326         /// <summary>
327         /// Sets the stroke dash pattern. The dash pattern is specified dash pattern.
328         /// </summary>
329         /// <param name="dashPattern">Length and a gap list.</param>
330         /// <param name="count">Pattern list length</param>
331         /// <returns>True when it's successful. False otherwise.</returns>
332         [EditorBrowsable(EditorBrowsableState.Never)]
333         public bool SetStrokeDash(float[] dashPattern, int count)
334         {
335             bool ret = Interop.Shape.SetStrokeDash(BaseHandle.getCPtr(this), dashPattern, count);
336             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
337             return ret;
338         }
339
340         /// <summary>
341         /// Gets the stroke dash pattern.
342         /// </summary>
343         /// <returns>Returns the stroke dash pattern. The dash pattern is specified dash pattern.</returns>
344         [EditorBrowsable(EditorBrowsableState.Never)]
345         public List<float> GetStrokeDash()
346         {
347             List<float> ret = new List<float>();
348
349             int patternCount = Interop.Shape.GetStrokeDashCount(BaseHandle.getCPtr(this));
350             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
351             for (int i = 0; i < patternCount; i++)
352             {
353                 ret.Add(Interop.Shape.GetStrokeDashIndexOf(BaseHandle.getCPtr(this), i));
354                 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
355             }
356             return ret;
357         }
358
359         /// <summary>
360         /// Set the cap style to use for stroking the path. The cap will be used for capping the end point of a open subpath.
361         /// </summary>
362         /// <param name="cap">Cap style to use.</param>
363         /// <returns>True when it's successful. False otherwise.</returns>
364         [EditorBrowsable(EditorBrowsableState.Never)]
365         public bool SetStrokeCap(StrokeCap cap)
366         {
367             bool ret = Interop.Shape.SetStrokeCap(BaseHandle.getCPtr(this), (int)cap);
368             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
369             return ret;
370         }
371
372         /// <summary>
373         /// Get the cap style to use for stroking the path.
374         /// </summary>
375         /// <returns>Returns the cap style.</returns>
376         [EditorBrowsable(EditorBrowsableState.Never)]
377         public StrokeCap GetStrokeCap()
378         {
379             StrokeCap ret = (StrokeCap)Interop.Shape.GetStrokeCap(BaseHandle.getCPtr(this));
380             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
381             return ret;
382         }
383
384         /// <summary>
385         /// Set the join style to use for stroking the path.
386         /// The join style will be used for joining the two line segment while stroking the path.
387         /// </summary>
388         /// <param name="join">Join style to use.</param>
389         /// <returns>True when it's successful. False otherwise.</returns>
390         [EditorBrowsable(EditorBrowsableState.Never)]
391         public bool SetStrokeJoin(StrokeJoin join)
392         {
393             bool ret = Interop.Shape.SetStrokeJoin(BaseHandle.getCPtr(this), (int)join);
394             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
395             return ret;
396         }
397
398         /// <summary>
399         /// Get the join style to use for stroking the path.
400         /// </summary>
401         /// <returns>Returns join style to use.</returns>
402         [EditorBrowsable(EditorBrowsableState.Never)]
403         public StrokeJoin GetStrokeJoin()
404         {
405             StrokeJoin ret = (StrokeJoin)Interop.Shape.GetStrokeJoin(BaseHandle.getCPtr(this));
406             if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
407             return ret;
408         }
409     }
410 }