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 /// <since_tizen> 9 </since_tizen>
29 public class Shape : Drawable
31 private Gradient fillGradient; //Added gradient
32 private Gradient strokeGradient; //Added gradient
35 /// Creates an initialized Shape.
37 /// <since_tizen> 9 </since_tizen>
38 public Shape() : this(Interop.Shape.New(), true)
40 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
43 internal Shape(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn)
48 /// Enumeration for The fill rule of shape.
50 /// <since_tizen> 9 </since_tizen>
51 public enum FillRuleType
54 /// 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.
58 /// 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.
64 /// Enumeration for The cap style to be used for stroking the path.
66 /// <since_tizen> 9 </since_tizen>
67 public enum StrokeCapType
70 /// The end of lines is rendered as a square around the last point.
74 /// The end of lines is rendered as a half-circle around the last point.
78 /// The end of lines is rendered as a full stop on the last point itself.
84 /// numeration for The join style to be used for stroking the path.
86 /// <since_tizen> 9 </since_tizen>
87 public enum StrokeJoinType
90 /// 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.
94 /// Used to render rounded line joins. Circular arcs are used to join two lines smoothly.
98 /// 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.
104 /// The color to use for filling the path.
106 /// <since_tizen> 9 </since_tizen>
107 public Color FillColor
111 global::System.IntPtr cPtr = Interop.Shape.GetFillColor(BaseHandle.getCPtr(this));
112 return Vector4.GetVector4FromPtr(cPtr);
116 Interop.Shape.SetFillColor(BaseHandle.getCPtr(this), Vector4.getCPtr(value));
117 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
122 /// The gradient to use for filling the path.
123 /// Even if FillColor is set, Gradient setting takes precedence.
125 [EditorBrowsable(EditorBrowsableState.Never)]
126 public Gradient FillGradient
130 global::System.IntPtr cPtr = Interop.Shape.GetFillGradient(BaseHandle.getCPtr(this));
131 Gradient ret = new Gradient(cPtr, true);
138 Interop.Shape.SetFillGradient(BaseHandle.getCPtr(this), BaseHandle.getCPtr(value));
139 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
140 fillGradient = value;
146 /// The current fill rule of the shape.
148 /// <since_tizen> 9 </since_tizen>
149 public FillRuleType FillRule
153 return (FillRuleType)Interop.Shape.GetFillRule(BaseHandle.getCPtr(this));
157 Interop.Shape.SetFillRule(BaseHandle.getCPtr(this), (int)value);
158 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
163 /// The stroke width to use for stroking the path.
165 /// <since_tizen> 9 </since_tizen>
166 public float StrokeWidth
170 return Interop.Shape.GetStrokeWidth(BaseHandle.getCPtr(this));
174 Interop.Shape.SetStrokeWidth(BaseHandle.getCPtr(this), value);
175 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
180 /// The color to use for stroking the path.
182 /// <since_tizen> 9 </since_tizen>
183 public Color StrokeColor
187 global::System.IntPtr cPtr = Interop.Shape.GetStrokeColor(BaseHandle.getCPtr(this));
188 return Vector4.GetVector4FromPtr(cPtr);
192 Interop.Shape.SetStrokeColor(BaseHandle.getCPtr(this), Vector4.getCPtr(value));
193 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
198 /// The gradient to use for stroking the path.
199 /// Even if StrokeColor is set, Gradient setting takes precedence.
201 [EditorBrowsable(EditorBrowsableState.Never)]
202 public Gradient StrokeGradient
206 global::System.IntPtr cPtr = Interop.Shape.GetStrokeGradient(BaseHandle.getCPtr(this));
207 Gradient ret = new Gradient(cPtr, true);
214 Interop.Shape.SetStrokeGradient(BaseHandle.getCPtr(this), BaseHandle.getCPtr(value));
215 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
216 strokeGradient = value;
222 /// The cap style to use for stroking the path. The cap will be used for capping the end point of a open subpath.
224 /// <since_tizen> 9 </since_tizen>
225 public StrokeCapType StrokeCap
229 return (StrokeCapType)Interop.Shape.GetStrokeCap(BaseHandle.getCPtr(this));
233 Interop.Shape.SetStrokeCap(BaseHandle.getCPtr(this), (int)value);
234 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
239 /// The join style to use for stroking the path.
240 /// The join style will be used for joining the two line segment while stroking the path.
242 /// <since_tizen> 9 </since_tizen>
243 public StrokeJoinType StrokeJoin
247 return (StrokeJoinType)Interop.Shape.GetStrokeJoin(BaseHandle.getCPtr(this));
251 Interop.Shape.SetStrokeJoin(BaseHandle.getCPtr(this), (int)value);
252 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
257 /// The stroke dash pattern. The dash pattern is specified dash pattern.
259 /// <exception cref="ArgumentNullException"> Thrown when value is null. </exception>
260 /// <since_tizen> 9 </since_tizen>
261 public ReadOnlyCollection<float> StrokeDash
265 List<float> retList = new List<float>();
266 int patternCount = Interop.Shape.GetStrokeDashCount(BaseHandle.getCPtr(this));
267 for (int i = 0; i < patternCount; i++)
269 retList.Add(Interop.Shape.GetStrokeDashIndexOf(BaseHandle.getCPtr(this), i));
272 ReadOnlyCollection<float> ret = new ReadOnlyCollection<float>(retList);
279 throw new ArgumentNullException(nameof(value));
281 float[] pattern = new float[value.Count];
282 for (int i = 0; i < value.Count; i++)
284 pattern[i] = value[i];
286 Interop.Shape.SetStrokeDash(BaseHandle.getCPtr(this), pattern, value.Count);
287 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
292 /// Append the given rectangle with rounded corner to the path.
293 /// The roundedCorner arguments specify the radii of the ellipses defining the
294 /// corners of the rounded rectangle.
296 /// roundedCorner are specified in terms of width and height respectively.
298 /// If roundedCorner's values are 0, then it will draw a rectangle without rounded corner.
300 /// <param name="x">X co-ordinate of the rectangle.</param>
301 /// <param name="y">Y co-ordinate of the rectangle.</param>
302 /// <param name="width">Width of the rectangle.</param>
303 /// <param name="height">Height of the rectangle.</param>
304 /// <param name="roundedCornerX">The x radius of the rounded corner and should be in range [ 0 to w/2 ].</param>
305 /// <param name="roundedCornerY">The y radius of the rounded corner and should be in range [ 0 to w/2 ].</param>
306 /// <returns>True when it's successful. False otherwise.</returns>
307 /// <since_tizen> 9 </since_tizen>
308 public bool AddRect(float x, float y, float width, float height, float roundedCornerX, float roundedCornerY)
310 bool ret = Interop.Shape.AddRect(BaseHandle.getCPtr(this), x, y, width, height, roundedCornerX, roundedCornerY);
311 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
316 /// Append a circle with given center and x,y-axis radius
318 /// <param name="x">X co-ordinate of the center of the circle.</param>
319 /// <param name="y">Y co-ordinate of the center of the circle.</param>
320 /// <param name="radiusX">X axis radius.</param>
321 /// <param name="radiusY">Y axis radius.</param>
322 /// <returns>True when it's successful. False otherwise.</returns>
323 /// <since_tizen> 9 </since_tizen>
324 public bool AddCircle(float x, float y, float radiusX, float radiusY)
326 bool ret = Interop.Shape.AddCircle(BaseHandle.getCPtr(this), x, y, radiusX, radiusY);
327 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
334 /// <param name="x">X co-ordinate of end point of the arc.</param>
335 /// <param name="y">Y co-ordinate of end point of the arc.</param>
336 /// <param name="radius">Radius of arc</param>
337 /// <param name="startAngle">Start angle (in degrees) where the arc begins.</param>
338 /// <param name="sweep">The Angle measures how long the arc will be drawn.</param>
339 /// <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>
340 /// <returns>True when it's successful. False otherwise.</returns>
341 /// <since_tizen> 9 </since_tizen>
342 public bool AddArc(float x, float y, float radius, float startAngle, float sweep, bool pie)
344 bool ret = Interop.Shape.AddArc(BaseHandle.getCPtr(this), x, y, radius, startAngle, sweep, pie);
345 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
350 /// Add a point that sets the given point as the current point,
351 /// implicitly starting a new subpath and closing the previous one.
353 /// <param name="x">X co-ordinate of the current point.</param>
354 /// <param name="y">Y co-ordinate of the current point.</param>
355 /// <returns>True when it's successful. False otherwise.</returns>
356 /// <since_tizen> 9 </since_tizen>
357 public bool AddMoveTo(float x, float y)
359 bool ret = Interop.Shape.AddMoveTo(BaseHandle.getCPtr(this), x, y);
360 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
365 /// Adds a straight line from the current position to the given end point.
366 /// After the line is drawn, the current position is updated to be at the
367 /// end point of the line.
368 /// If no current position present, it draws a line to itself, basically * a point.
370 /// <param name="x">X co-ordinate of end point of the line.</param>
371 /// <param name="y">Y co-ordinate of end point of the line.</param>
372 /// <returns>True when it's successful. False otherwise.</returns>
373 /// <since_tizen> 9 </since_tizen>
374 public bool AddLineTo(float x, float y)
376 bool ret = Interop.Shape.AddLineTo(BaseHandle.getCPtr(this), x, y);
377 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
382 /// Adds a cubic Bezier curve between the current position and the
383 /// given end point (lineEndPoint) using the control points specified by
384 /// (controlPoint1), and (controlPoint2). After the path is drawn,
385 /// the current position is updated to be at the end point of the path.
387 /// <param name="controlPoint1X">X co-ordinate of 1st control point.</param>
388 /// <param name="controlPoint1Y">Y co-ordinate of 1st control point.</param>
389 /// <param name="controlPoint2X">X co-ordinate of 2nd control point.</param>
390 /// <param name="controlPoint2Y">Y co-ordinate of 2nd control point.</param>
391 /// <param name="endPointX">X co-ordinate of end point of the line.</param>
392 /// <param name="endPointY">Y co-ordinate of end point of the line.</param>
393 /// <returns>True when it's successful. False otherwise.</returns>
394 /// <since_tizen> 9 </since_tizen>
395 public bool AddCubicTo(float controlPoint1X, float controlPoint1Y, float controlPoint2X, float controlPoint2Y, float endPointX, float endPointY)
397 bool ret = Interop.Shape.AddCubicTo(BaseHandle.getCPtr(this), controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPointX, endPointY);
398 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
403 /// Closes the current subpath by drawing a line to the beginning of the
404 /// subpath, automatically starting a new path. The current point of the
405 /// new path is (0, 0).
406 /// If the subpath does not contain any points, this function does nothing.
408 /// <returns>True when it's successful. False otherwise.</returns>
409 /// <since_tizen> 9 </since_tizen>
412 bool ret = Interop.Shape.Close(BaseHandle.getCPtr(this));
413 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();
418 /// Reset the added path(rect, circle, path, etc...) information.
419 /// Color and Stroke information are keeped.
421 /// <returns>True when it's successful. False otherwise.</returns>
422 /// <since_tizen> 9 </since_tizen>
423 public bool ResetPath()
425 bool ret = Interop.Shape.ResetPath(BaseHandle.getCPtr(this));
426 if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve();