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