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