2 * Copyright(c) 2019 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.
17 using System.ComponentModel;
18 using System.Collections.Generic;
20 namespace Tizen.NUI.BaseComponents
23 namespace VectorGraphics
26 /// Shape is a command list for drawing one shape groups It has own path data & properties for sync/asynchronous drawing
28 [EditorBrowsable(EditorBrowsableState.Never)]
29 public class Shape : Paint
32 /// Enumeration for The cap style to be used for stroking the path.
34 [EditorBrowsable(EditorBrowsableState.Never)]
38 /// The end of lines is rendered as a square around the last point.
42 /// The end of lines is rendered as a half-circle around the last point.
46 /// The end of lines is rendered as a full stop on the last point itself.
52 /// numeration for The join style to be used for stroking the path.
54 [EditorBrowsable(EditorBrowsableState.Never)]
55 public enum StrokeJoin
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.
62 /// Used to render rounded line joins. Circular arcs are used to join two lines smoothly.
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.
72 /// Enumeration for The fill rule of shape.
74 [EditorBrowsable(EditorBrowsableState.Never)]
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.
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.
87 public Shape() : this(Interop.Shape.New(), true)
89 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
92 internal Shape(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
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.
101 /// roundedCorner are specified in terms of width and height respectively.
103 /// If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
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)
115 if (Interop.Shape.AddRect(BaseHandle.getCPtr(this), x, y, width, height, roundedCornerX, roundedCornerY))
121 /// Append a circle with given center and x,y-axis radius
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)
131 if (Interop.Shape.AddCircle(BaseHandle.getCPtr(this), x, y, radiusX, radiusY))
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)
149 if (Interop.Shape.AddArc(BaseHandle.getCPtr(this), x, y, radius, startAngle, sweep, pie))
155 /// Add a point that sets the given point as the current point,
156 /// implicitly starting a new subpath and closing the previous one.
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)
164 if (Interop.Shape.AddMoveTo(BaseHandle.getCPtr(this), x, y))
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.
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)
181 if (Interop.Shape.AddLineTo(BaseHandle.getCPtr(this), x, y))
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.
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)
202 if (Interop.Shape.AddCubicTo(BaseHandle.getCPtr(this), controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPointX, endPointY))
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.
213 /// <returns>True when it's successful. False otherwise.</returns>
214 [EditorBrowsable(EditorBrowsableState.Never)]
217 if (Interop.Shape.Close(BaseHandle.getCPtr(this)))
223 /// Set the color to use for filling the path.
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)
230 if (Interop.Shape.SetFillColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color)))
236 /// Get the color to use for filling the path.
238 /// <returns>Returns the color value.</returns>
239 [EditorBrowsable(EditorBrowsableState.Never)]
240 public Color GetFillColor()
242 global::System.IntPtr cPtr = Interop.Shape.GetFillColor(BaseHandle.getCPtr(this));
243 Color color = Vector4.GetVector4FromPtr(cPtr);
248 /// Set the fill rule.
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)
255 if (Interop.Shape.SetFillRule(BaseHandle.getCPtr(this), (int)rule))
261 /// Get the fill rule.
263 /// <returns>Returns the current fill rule of the shape.</returns>
264 [EditorBrowsable(EditorBrowsableState.Never)]
265 public FillRule GetFillRule()
267 return (FillRule)Interop.Shape.GetFillRule(BaseHandle.getCPtr(this));
271 /// Set the stroke width to use for stroking the path.
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)
278 if (Interop.Shape.SetStrokeWidth(BaseHandle.getCPtr(this), width))
284 /// Get the stroke width to use for stroking the path.
286 /// <returns>Returns stroke width to be used.</returns>
287 [EditorBrowsable(EditorBrowsableState.Never)]
288 public float GetStrokeWidth()
290 return Interop.Shape.GetStrokeWidth(BaseHandle.getCPtr(this));
294 /// Set the color to use for stroking the path.
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)
301 if (Interop.Shape.SetStrokeColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color)))
307 /// Get the color to use for stroking the path.
309 /// <returns>Returns the stroking color.</returns>
310 [EditorBrowsable(EditorBrowsableState.Never)]
311 public Color GetStrokeColor()
313 global::System.IntPtr cPtr = Interop.Shape.GetStrokeColor(BaseHandle.getCPtr(this));
314 Color color = Vector4.GetVector4FromPtr(cPtr);
319 /// Sets the stroke dash pattern. The dash pattern is specified dash pattern.
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)
327 if (Interop.Shape.SetStrokeDash(BaseHandle.getCPtr(this), dashPattern, count))
333 /// Gets the stroke dash pattern.
335 /// <returns>Returns the stroke dash pattern. The dash pattern is specified dash pattern.</returns>
336 [EditorBrowsable(EditorBrowsableState.Never)]
337 public List<float> GetStrokeDash()
339 List<float> pattern = new List<float>();
341 int patternCount = Interop.Shape.GetStrokeDashCount(BaseHandle.getCPtr(this));
342 for(int i = 0; i < patternCount; i++)
344 pattern.Add(Interop.Shape.GetStrokeDashIndexOf(BaseHandle.getCPtr(this), i));
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.
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)
357 if (Interop.Shape.SetStrokeCap(BaseHandle.getCPtr(this), (int)cap))
363 /// Get the cap style to use for stroking the path.
365 /// <returns>Returns the cap style.</returns>
366 [EditorBrowsable(EditorBrowsableState.Never)]
367 public StrokeCap GetStrokeCap()
369 return (StrokeCap)Interop.Shape.GetStrokeCap(BaseHandle.getCPtr(this));
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.
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)
381 if (Interop.Shape.SetStrokeJoin(BaseHandle.getCPtr(this), (int)join))
387 /// Get the join style to use for stroking the path.
389 /// <returns>Returns join style to use.</returns>
390 [EditorBrowsable(EditorBrowsableState.Never)]
391 public StrokeJoin GetStrokeJoin()
393 return (StrokeJoin)Interop.Shape.GetStrokeJoin(BaseHandle.getCPtr(this));