/* * Copyright(c) 2021 Samsung Electronics Co., Ltd. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. * You may obtain a copy of the License at * * http://www.apache.org/licenses/LICENSE-2.0 * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. * See the License for the specific language governing permissions and * limitations under the License. * */ using System.ComponentModel; using System.Collections.Generic; namespace Tizen.NUI.BaseComponents.VectorGraphics { /// /// Shape is a command list for drawing one shape groups It has own path data and properties for sync/asynchronous drawing /// [EditorBrowsable(EditorBrowsableState.Never)] public class Shape : Drawable { /// /// Creates an initialized Shape. /// [EditorBrowsable(EditorBrowsableState.Never)] public Shape() : this(Interop.Shape.New(), true) { if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } internal Shape(global::System.IntPtr cPtr, bool cMemoryOwn) : base(cPtr, cMemoryOwn) { } /// /// Enumeration for The cap style to be used for stroking the path. /// [EditorBrowsable(EditorBrowsableState.Never)] public enum StrokeCap { /// /// The end of lines is rendered as a square around the last point. /// Square = 0, /// /// The end of lines is rendered as a half-circle around the last point. /// Round, /// /// The end of lines is rendered as a full stop on the last point itself. /// Butt } /// /// numeration for The join style to be used for stroking the path. /// [EditorBrowsable(EditorBrowsableState.Never)] public enum StrokeJoin { /// /// 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. /// Bevel = 0, /// /// Used to render rounded line joins. Circular arcs are used to join two lines smoothly. /// Round, /// /// 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. /// Miter } /// /// Enumeration for The fill rule of shape. /// [EditorBrowsable(EditorBrowsableState.Never)] public enum FillRule { /// /// 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. /// Winding = 0, /// /// 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. /// EvenOdd } /// /// Append the given rectangle with rounded corner to the path. /// The roundedCorner arguments specify the radii of the ellipses defining the /// corners of the rounded rectangle. /// /// roundedCorner are specified in terms of width and height respectively. /// /// If roundedCorner's values are 0, then it will draw a rectangle without rounded corner. /// /// X co-ordinate of the rectangle. /// Y co-ordinate of the rectangle. /// Width of the rectangle. /// Height of the rectangle. /// The x radius of the rounded corner and should be in range [ 0 to w/2 ]. /// The y radius of the rounded corner and should be in range [ 0 to w/2 ]. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool AddRect(float x, float y, float width, float height, float roundedCornerX, float roundedCornerY) { bool ret = Interop.Shape.AddRect(BaseHandle.getCPtr(this), x, y, width, height, roundedCornerX, roundedCornerY); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Append a circle with given center and x,y-axis radius /// /// X co-ordinate of the center of the circle. /// Y co-ordinate of the center of the circle. /// X axis radius of the circle. /// X axis radius of the circle. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool AddCircle(float x, float y, float radiusX, float radiusY) { bool ret = Interop.Shape.AddCircle(BaseHandle.getCPtr(this), x, y, radiusX, radiusY); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Append the arcs. /// /// X co-ordinate of end point of the arc. /// Y co-ordinate of end point of the arc. /// Radius of arc /// Start angle (in degrees) where the arc begins. /// The Angle measures how long the arc will be drawn. /// If True, the area is created by connecting start angle point and sweep angle point of the drawn arc. If false, it doesn't. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool AddArc(float x, float y, float radius, float startAngle, float sweep, bool pie) { bool ret = Interop.Shape.AddArc(BaseHandle.getCPtr(this), x, y, radius, startAngle, sweep, pie); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Add a point that sets the given point as the current point, /// implicitly starting a new subpath and closing the previous one. /// /// X co-ordinate of the current point. /// Y co-ordinate of the current point. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool AddMoveTo(float x, float y) { bool ret = Interop.Shape.AddMoveTo(BaseHandle.getCPtr(this), x, y); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Adds a straight line from the current position to the given end point. /// After the line is drawn, the current position is updated to be at the /// end point of the line. /// If no current position present, it draws a line to itself, basically * a point. /// /// X co-ordinate of end point of the line. /// Y co-ordinate of end point of the line. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool AddLineTo(float x, float y) { bool ret = Interop.Shape.AddLineTo(BaseHandle.getCPtr(this), x, y); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Adds a cubic Bezier curve between the current position and the /// given end point (lineEndPoint) using the control points specified by /// (controlPoint1), and (controlPoint2). After the path is drawn, /// the current position is updated to be at the end point of the path. /// /// X co-ordinate of 1st control point. /// Y co-ordinate of 1st control point. /// X co-ordinate of 2nd control point. /// Y co-ordinate of 2nd control point. /// X co-ordinate of end point of the line. /// Y co-ordinate of end point of the line. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool AddCubicTo(float controlPoint1X, float controlPoint1Y, float controlPoint2X, float controlPoint2Y, float endPointX, float endPointY) { bool ret = Interop.Shape.AddCubicTo(BaseHandle.getCPtr(this), controlPoint1X, controlPoint1Y, controlPoint2X, controlPoint2Y, endPointX, endPointY); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Closes the current subpath by drawing a line to the beginning of the /// subpath, automatically starting a new path. The current point of the /// new path is (0, 0). /// If the subpath does not contain any points, this function does nothing. /// /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool Close() { bool ret = Interop.Shape.Close(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Set the color to use for filling the path. /// /// The color value. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool SetFillColor(Color color) { bool ret = Interop.Shape.SetFillColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Get the color to use for filling the path. /// /// Returns the color value. [EditorBrowsable(EditorBrowsableState.Never)] public Color GetFillColor() { global::System.IntPtr cPtr = Interop.Shape.GetFillColor(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); Color ret = Vector4.GetVector4FromPtr(cPtr); return ret; } /// /// Set the fill rule. /// /// The current fill rule of the shape. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool SetFillRule(FillRule rule) { bool ret = Interop.Shape.SetFillRule(BaseHandle.getCPtr(this), (int)rule); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Get the fill rule. /// /// Returns the current fill rule of the shape. [EditorBrowsable(EditorBrowsableState.Never)] public FillRule GetFillRule() { FillRule ret = (FillRule)Interop.Shape.GetFillRule(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Set the stroke width to use for stroking the path. /// /// Stroke width to be used. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool SetStrokeWidth(float width) { bool ret = Interop.Shape.SetStrokeWidth(BaseHandle.getCPtr(this), width); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Get the stroke width to use for stroking the path. /// /// Returns stroke width to be used. [EditorBrowsable(EditorBrowsableState.Never)] public float GetStrokeWidth() { float ret = Interop.Shape.GetStrokeWidth(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Set the color to use for stroking the path. /// /// The stroking color. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool SetStrokeColor(Color color) { bool ret = Interop.Shape.SetStrokeColor(BaseHandle.getCPtr(this), Vector4.getCPtr(color)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Get the color to use for stroking the path. /// /// Returns the stroking color. [EditorBrowsable(EditorBrowsableState.Never)] public Color GetStrokeColor() { global::System.IntPtr cPtr = Interop.Shape.GetStrokeColor(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); Color ret = Vector4.GetVector4FromPtr(cPtr); return ret; } /// /// Sets the stroke dash pattern. The dash pattern is specified dash pattern. /// /// Length and a gap list. /// Pattern list length /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool SetStrokeDash(float[] dashPattern, int count) { bool ret = Interop.Shape.SetStrokeDash(BaseHandle.getCPtr(this), dashPattern, count); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Gets the stroke dash pattern. /// /// Returns the stroke dash pattern. The dash pattern is specified dash pattern. [EditorBrowsable(EditorBrowsableState.Never)] public List GetStrokeDash() { List ret = new List(); int patternCount = Interop.Shape.GetStrokeDashCount(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); for (int i = 0; i < patternCount; i++) { ret.Add(Interop.Shape.GetStrokeDashIndexOf(BaseHandle.getCPtr(this), i)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); } return ret; } /// /// Set the cap style to use for stroking the path. The cap will be used for capping the end point of a open subpath. /// /// Cap style to use. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool SetStrokeCap(StrokeCap cap) { bool ret = Interop.Shape.SetStrokeCap(BaseHandle.getCPtr(this), (int)cap); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Get the cap style to use for stroking the path. /// /// Returns the cap style. [EditorBrowsable(EditorBrowsableState.Never)] public StrokeCap GetStrokeCap() { StrokeCap ret = (StrokeCap)Interop.Shape.GetStrokeCap(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Set the join style to use for stroking the path. /// The join style will be used for joining the two line segment while stroking the path. /// /// Join style to use. /// True when it's successful. False otherwise. [EditorBrowsable(EditorBrowsableState.Never)] public bool SetStrokeJoin(StrokeJoin join) { bool ret = Interop.Shape.SetStrokeJoin(BaseHandle.getCPtr(this), (int)join); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } /// /// Get the join style to use for stroking the path. /// /// Returns join style to use. [EditorBrowsable(EditorBrowsableState.Never)] public StrokeJoin GetStrokeJoin() { StrokeJoin ret = (StrokeJoin)Interop.Shape.GetStrokeJoin(BaseHandle.getCPtr(this)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); return ret; } } }