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