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;
21 namespace Tizen.NUI.BaseComponents.VectorGraphics
24 /// Shape is a command list for drawing one shape groups It has own path data and properties for sync/asynchronous drawing
26 [EditorBrowsable(EditorBrowsableState.Never)]
27 public class Shape : Drawable
30 /// Creates an initialized Shape.
32 [EditorBrowsable(EditorBrowsableState.Never)]
33 public Shape() : this(Interop.Shape.New(), true)
35 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
38 internal Shape(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
43 /// Enumeration for The cap style to be used for stroking the path.
45 [EditorBrowsable(EditorBrowsableState.Never)]
49 /// The end of lines is rendered as a square around the last point.
53 /// The end of lines is rendered as a half-circle around the last point.
57 /// The end of lines is rendered as a full stop on the last point itself.
63 /// numeration for The join style to be used for stroking the path.
65 [EditorBrowsable(EditorBrowsableState.Never)]
66 public enum StrokeJoin
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.
73 /// Used to render rounded line joins. Circular arcs are used to join two lines smoothly.
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.
83 /// Enumeration for The fill rule of shape.
85 [EditorBrowsable(EditorBrowsableState.Never)]
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.
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.
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.
103 /// roundedCorner are specified in terms of width and height respectively.
105 /// If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
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)
117 bool ret = Interop.Shape.AddRect(BaseHandle.getCPtr(this), x, y, width, height, roundedCornerX, roundedCornerY);
118 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
123 /// Append a circle with given center and x,y-axis radius
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)
133 bool ret = Interop.Shape.AddCircle(BaseHandle.getCPtr(this), x, y, radiusX, radiusY);
134 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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)
151 bool ret = Interop.Shape.AddArc(BaseHandle.getCPtr(this), x, y, radius, startAngle, sweep, pie);
152 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
157 /// Add a point that sets the given point as the current point,
158 /// implicitly starting a new subpath and closing the previous one.
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)
166 bool ret = Interop.Shape.AddMoveTo(BaseHandle.getCPtr(this), x, y);
167 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
183 bool ret = Interop.Shape.AddLineTo(BaseHandle.getCPtr(this), x, y);
184 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
204 bool ret = Interop.Shape.AddCubicTo(BaseHandle.getCPtr(this), controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPointX, endPointY);
205 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
215 /// <returns>True when it's successful. False otherwise.</returns>
216 [EditorBrowsable(EditorBrowsableState.Never)]
219 bool ret = Interop.Shape.Close(BaseHandle.getCPtr(this));
220 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
225 /// Set the color to use for filling the path.
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)
232 bool ret = Interop.Shape.SetFillColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color));
233 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
238 /// Get the color to use for filling the path.
240 /// <returns>Returns the color value.</returns>
241 [EditorBrowsable(EditorBrowsableState.Never)]
242 public Color GetFillColor()
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);
251 /// Set the fill rule.
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)
258 bool ret = Interop.Shape.SetFillRule(BaseHandle.getCPtr(this), (int)rule);
259 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
264 /// Get the fill rule.
266 /// <returns>Returns the current fill rule of the shape.</returns>
267 [EditorBrowsable(EditorBrowsableState.Never)]
268 public FillRule GetFillRule()
270 FillRule ret = (FillRule)Interop.Shape.GetFillRule(BaseHandle.getCPtr(this));
271 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
276 /// Set the stroke width to use for stroking the path.
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)
283 bool ret = Interop.Shape.SetStrokeWidth(BaseHandle.getCPtr(this), width);
284 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
289 /// Get the stroke width to use for stroking the path.
291 /// <returns>Returns stroke width to be used.</returns>
292 [EditorBrowsable(EditorBrowsableState.Never)]
293 public float GetStrokeWidth()
295 float ret = Interop.Shape.GetStrokeWidth(BaseHandle.getCPtr(this));
296 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
301 /// Set the color to use for stroking the path.
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)
308 bool ret = Interop.Shape.SetStrokeColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color));
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
314 /// Get the color to use for stroking the path.
316 /// <returns>Returns the stroking color.</returns>
317 [EditorBrowsable(EditorBrowsableState.Never)]
318 public Color GetStrokeColor()
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);
327 /// Sets the stroke dash pattern. The dash pattern is specified dash pattern.
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)
335 bool ret = Interop.Shape.SetStrokeDash(BaseHandle.getCPtr(this), dashPattern, count);
336 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
341 /// Gets the stroke dash pattern.
343 /// <returns>Returns the stroke dash pattern. The dash pattern is specified dash pattern.</returns>
344 [EditorBrowsable(EditorBrowsableState.Never)]
345 public List<float> GetStrokeDash()
347 List<float> ret = new List<float>();
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++)
353 ret.Add(Interop.Shape.GetStrokeDashIndexOf(BaseHandle.getCPtr(this), i));
354 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
367 bool ret = Interop.Shape.SetStrokeCap(BaseHandle.getCPtr(this), (int)cap);
368 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
373 /// Get the cap style to use for stroking the path.
375 /// <returns>Returns the cap style.</returns>
376 [EditorBrowsable(EditorBrowsableState.Never)]
377 public StrokeCap GetStrokeCap()
379 StrokeCap ret = (StrokeCap)Interop.Shape.GetStrokeCap(BaseHandle.getCPtr(this));
380 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
393 bool ret = Interop.Shape.SetStrokeJoin(BaseHandle.getCPtr(this), (int)join);
394 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
399 /// Get the join style to use for stroking the path.
401 /// <returns>Returns join style to use.</returns>
402 [EditorBrowsable(EditorBrowsableState.Never)]
403 public StrokeJoin GetStrokeJoin()
405 StrokeJoin ret = (StrokeJoin)Interop.Shape.GetStrokeJoin(BaseHandle.getCPtr(this));
406 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();