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.
19 using System.ComponentModel;
20 using System.Collections.ObjectModel;
21 using System.Collections.Generic;
23 namespace Tizen.NUI.BaseComponents.VectorGraphics
26 /// Shape is a command list for drawing one shape groups It has own path data and properties for sync/asynchronous drawing
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class Shape : Drawable
32 /// Creates an initialized Shape.
34 [EditorBrowsable(EditorBrowsableState.Never)]
35 public Shape() : this(Interop.Shape.New(), true)
37 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
40 internal Shape(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
45 /// Enumeration for The fill rule of shape.
47 [EditorBrowsable(EditorBrowsableState.Never)]
48 public enum FillRuleType
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.
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.
61 /// Enumeration for The cap style to be used for stroking the path.
63 [EditorBrowsable(EditorBrowsableState.Never)]
64 public enum StrokeCapType
67 /// The end of lines is rendered as a square around the last point.
71 /// The end of lines is rendered as a half-circle around the last point.
75 /// The end of lines is rendered as a full stop on the last point itself.
81 /// numeration for The join style to be used for stroking the path.
83 [EditorBrowsable(EditorBrowsableState.Never)]
84 public enum StrokeJoinType
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.
91 /// Used to render rounded line joins. Circular arcs are used to join two lines smoothly.
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.
101 /// The color to use for filling the path.
103 [EditorBrowsable(EditorBrowsableState.Never)]
104 public Color FillColor
108 global::System.IntPtr cPtr = Interop.Shape.GetFillColor(BaseHandle.getCPtr(this));
109 return Vector4.GetVector4FromPtr(cPtr);
113 Interop.Shape.SetFillColor(BaseHandle.getCPtr(this), Vector4.getCPtr(value));
114 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
119 /// The current fill rule of the shape.
121 [EditorBrowsable(EditorBrowsableState.Never)]
122 public FillRuleType FillRule
126 return (FillRuleType)Interop.Shape.GetFillRule(BaseHandle.getCPtr(this));
130 Interop.Shape.SetFillRule(BaseHandle.getCPtr(this), (int)value);
131 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
136 /// The stroke width to use for stroking the path.
138 [EditorBrowsable(EditorBrowsableState.Never)]
139 public float StrokeWidth
143 return Interop.Shape.GetStrokeWidth(BaseHandle.getCPtr(this));
147 Interop.Shape.SetStrokeWidth(BaseHandle.getCPtr(this), value);
148 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
153 /// The color to use for stroking the path.
155 [EditorBrowsable(EditorBrowsableState.Never)]
156 public Color StrokeColor
160 global::System.IntPtr cPtr = Interop.Shape.GetStrokeColor(BaseHandle.getCPtr(this));
161 return Vector4.GetVector4FromPtr(cPtr);
165 Interop.Shape.SetStrokeColor(BaseHandle.getCPtr(this), Vector4.getCPtr(value));
166 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
171 /// The cap style to use for stroking the path. The cap will be used for capping the end point of a open subpath.
173 [EditorBrowsable(EditorBrowsableState.Never)]
174 public StrokeCapType StrokeCap
178 return (StrokeCapType)Interop.Shape.GetStrokeCap(BaseHandle.getCPtr(this));
182 Interop.Shape.SetStrokeCap(BaseHandle.getCPtr(this), (int)value);
183 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
191 [EditorBrowsable(EditorBrowsableState.Never)]
192 public StrokeJoinType StrokeJoin
196 return (StrokeJoinType)Interop.Shape.GetStrokeJoin(BaseHandle.getCPtr(this));
200 Interop.Shape.SetStrokeJoin(BaseHandle.getCPtr(this), (int)value);
201 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
206 /// The stroke dash pattern. The dash pattern is specified dash pattern.
208 /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
209 [EditorBrowsable(EditorBrowsableState.Never)]
210 public ReadOnlyCollection<float> StrokeDash
214 List<float> retList = new List<float>();
215 int patternCount = Interop.Shape.GetStrokeDashCount(BaseHandle.getCPtr(this));
216 for (int i = 0; i < patternCount; i++)
218 retList.Add(Interop.Shape.GetStrokeDashIndexOf(BaseHandle.getCPtr(this), i));
221 ReadOnlyCollection<float> ret = new ReadOnlyCollection<float>(retList);
228 throw new ArgumentNullException(nameof(value));
230 float[] pattern = new float[value.Count];
231 for (int i = 0; i < value.Count; i++)
233 pattern[i] = value[i];
235 Interop.Shape.SetStrokeDash(BaseHandle.getCPtr(this), pattern, value.Count);
236 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
245 /// roundedCorner are specified in terms of width and height respectively.
247 /// If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
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)
259 bool ret = Interop.Shape.AddRect(BaseHandle.getCPtr(this), x, y, width, height, roundedCornerX, roundedCornerY);
260 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
265 /// Append a circle with given center and x,y-axis radius
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)
275 bool ret = Interop.Shape.AddCircle(BaseHandle.getCPtr(this), x, y, radiusX, radiusY);
276 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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)
293 bool ret = Interop.Shape.AddArc(BaseHandle.getCPtr(this), x, y, radius, startAngle, sweep, pie);
294 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
299 /// Add a point that sets the given point as the current point,
300 /// implicitly starting a new subpath and closing the previous one.
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)
308 bool ret = Interop.Shape.AddMoveTo(BaseHandle.getCPtr(this), x, y);
309 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
325 bool ret = Interop.Shape.AddLineTo(BaseHandle.getCPtr(this), x, y);
326 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
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)
346 bool ret = Interop.Shape.AddCubicTo(BaseHandle.getCPtr(this), controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPointX, endPointY);
347 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
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.
357 /// <returns>True when it's successful. False otherwise.</returns>
358 [EditorBrowsable(EditorBrowsableState.Never)]
361 bool ret = Interop.Shape.Close(BaseHandle.getCPtr(this));
362 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
367 /// Reset the added path(rect, circle, path, etc...) information.
368 /// Color and Stroke information are keeped.
370 /// <returns>True when it's successful. False otherwise.</returns>
371 [EditorBrowsable(EditorBrowsableState.Never)]
372 public bool ResetPath()
374 bool ret = Interop.Shape.ResetPath(BaseHandle.getCPtr(this));
375 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();