From: JunsuChoi Date: Fri, 13 Aug 2021 08:26:38 +0000 (+0900) Subject: [NUI] VectorGraphics: Add Shape.AddPath API X-Git-Tag: accepted/tizen/unified/20231205.024657~1578 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=862d612c0a17498df3f38a25367caf261dd9c46c;p=platform%2Fcore%2Fcsapi%2Ftizenfx.git [NUI] VectorGraphics: Add Shape.AddPath API Adds an API that adds a large path information. The PathCommands has a PathCommandType array, a Point array and the number of each array. --- diff --git a/src/Tizen.NUI/src/internal/Interop/Interop.Shape.cs b/src/Tizen.NUI/src/internal/Interop/Interop.Shape.cs index 2327363..a8b842b 100755 --- a/src/Tizen.NUI/src/internal/Interop/Interop.Shape.cs +++ b/src/Tizen.NUI/src/internal/Interop/Interop.Shape.cs @@ -48,6 +48,10 @@ namespace Tizen.NUI [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] public static extern bool AddCubicTo(global::System.Runtime.InteropServices.HandleRef jarg1, float jarg2, float jarg3, float jarg4, float jarg5, float jarg6, float jarg7); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shape_AddPath")] + [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] + public static extern void AddPath(global::System.Runtime.InteropServices.HandleRef pShape, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)] BaseComponents.VectorGraphics.PathCommands.PathCommandType[] commands, uint commandCount, [global::System.Runtime.InteropServices.In, global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.LPArray)] float[] points, uint pointCount); + [global::System.Runtime.InteropServices.DllImport(NDalicPINVOKE.Lib, EntryPoint = "CSharp_Dali_Shape_Close")] [return: global::System.Runtime.InteropServices.MarshalAs(global::System.Runtime.InteropServices.UnmanagedType.U1)] public static extern bool Close(global::System.Runtime.InteropServices.HandleRef jarg1); diff --git a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/PathCommands.cs b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/PathCommands.cs new file mode 100755 index 0000000..a5b459f --- /dev/null +++ b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/PathCommands.cs @@ -0,0 +1,126 @@ +/* +* 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; +using System.ComponentModel; + +namespace Tizen.NUI.BaseComponents.VectorGraphics +{ + /// + /// Data class that contains information about a list of path commands. + /// For each command from the commands array, an appropriate number of points in points array should be specified. + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public class PathCommands + { + private PathCommandType[] commands; //The array of commands. + private uint commandCount; //The number of commands. + private float[] points; //The array of points. + private uint pointCount; //The number of points. + + /// + /// Initialize PathCommands. + /// + /// The array of commands. + /// The number of commands. + /// The array of points. + /// The number of points. + /// Thrown when commands or points are null. + [EditorBrowsable(EditorBrowsableState.Never)] + public PathCommands(PathCommandType[] commands, uint commandCount, float[] points, uint pointCount) + { + if (commands == null) + { + throw new ArgumentNullException(nameof(commands)); + } + if (points == null) + { + throw new ArgumentNullException(nameof(points)); + } + this.commands = commands; + this.commandCount = commandCount; + this.points = points; + this.pointCount = pointCount; + } + + /// + /// Enumeration specifying the values of the path commands. + /// Not to be confused with the path commands from the svg path element (like M, L, Q, H and many others). + /// + [EditorBrowsable(EditorBrowsableState.Never)] + public enum PathCommandType + { + /// + /// Ends the current sub-path and connects it with its initial point. This command doesn't expect any points. + /// + Close = 0, + /// + /// Sets a new initial point of the sub-path and a new current point. This command expects 1 point: the starting position. + /// + MoveTo, + /// + /// Draws a line from the current point to the given point and sets a new value of the current point. This command expects 1 point: the end-position of the line. + /// + LineTo, + /// + /// Draws a cubic Bezier curve from the current point to the given point using two given control points and sets a new value of the current point. This command expects 3 points: the 1st control-point, the 2nd control-point, the end-point of the curve. + /// + CubicTo + } + + /// + /// The commands array. + /// + /// The array of commands. + [EditorBrowsable(EditorBrowsableState.Never)] + public PathCommandType[] GetCommands() + { + return commands; + } + + /// + /// The number of commands. + /// + /// The number of commands. + [EditorBrowsable(EditorBrowsableState.Never)] + public uint GetCommandCount() + { + return commandCount; + } + + /// + /// The points array + /// + /// The array of points. + [EditorBrowsable(EditorBrowsableState.Never)] + public float[] GetPoints() + { + return points; + } + + /// + /// The number of points. + /// + /// The number of points. + [EditorBrowsable(EditorBrowsableState.Never)] + public uint GetPointCount() + { + return pointCount; + } + } +} + diff --git a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Shape.cs b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Shape.cs index d533e43..769b7ca 100755 --- a/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Shape.cs +++ b/src/Tizen.NUI/src/public/BaseComponents/VectorGraphics/Shape.cs @@ -138,7 +138,7 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics Interop.Shape.SetFillGradient(BaseHandle.getCPtr(this), BaseHandle.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); fillGradient = value; - } + } } } @@ -214,7 +214,7 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics Interop.Shape.SetStrokeGradient(BaseHandle.getCPtr(this), BaseHandle.getCPtr(value)); if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); strokeGradient = value; - } + } } } @@ -399,6 +399,26 @@ namespace Tizen.NUI.BaseComponents.VectorGraphics return ret; } + + /// + /// Appends a given sub-path to the path. + /// The current point value is set to the last point from the sub-path. + /// @note The interface is designed for optimal path setting if the caller has a completed path commands already. + /// + /// The command object that contain sub-path information. (This command information is copied internally.) + /// Thrown when pathCommands is null. + [EditorBrowsable(EditorBrowsableState.Never)] + public void AddPath(PathCommands pathCommands) + { + if (pathCommands == null) + { + throw new ArgumentNullException(nameof(pathCommands)); + } + + Interop.Shape.AddPath(BaseHandle.getCPtr(this), pathCommands.GetCommands(), pathCommands.GetCommandCount(), pathCommands.GetPoints(), pathCommands.GetPointCount()); + if (NDalicPINVOKE.SWIGPendingException.Pending) throw NDalicPINVOKE.SWIGPendingException.Retrieve(); + } + /// /// Closes the current subpath by drawing a line to the beginning of the /// subpath, automatically starting a new path. The current point of the diff --git a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs index ceff754..ab9f4e6 100644 --- a/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs +++ b/test/Tizen.NUI.Samples/Tizen.NUI.Samples/Samples/CanvasViewSamsple.cs @@ -107,14 +107,23 @@ namespace Tizen.NUI.Samples FillRule = Shape.FillRuleType.EvenOdd, StrokeJoin = Shape.StrokeJoinType.Round, }; + shape.Scale(0.5f); shape.Translate(350.0f, 300.0f); - shape.AddMoveTo(0.0f, -160.0f); - shape.AddLineTo(125.0f, 160.0f); - shape.AddLineTo(-180.0f, -45.0f); - shape.AddLineTo(180.0f, -45.0f); - shape.AddLineTo(-125.0f, 160.0f); - shape.Close(); + + shape.AddPath(new PathCommands(new PathCommands.PathCommandType[] { PathCommands.PathCommandType.MoveTo, + PathCommands.PathCommandType.LineTo, + PathCommands.PathCommandType.LineTo, + PathCommands.PathCommandType.LineTo, + PathCommands.PathCommandType.LineTo, + PathCommands.PathCommandType.Close }, + 6, + new float[] {0.0f, -160.0f, + 125.0f, 160.0f, + -180.0f, -45.0f, + 180.0f, -45.0f, + -125.0f, 160.0f }, + 10)); canvasView.AddDrawable(shape); @@ -184,7 +193,7 @@ namespace Tizen.NUI.Samples group2.AddDrawable(circleShape); canvasView.AddDrawable(group2); - Picture picture = new Picture(); + Picture picture = new Picture(); picture.Load(CommonResource.GetDaliResourcePath() + "DaliDemo/Kid1.svg"); picture.SetSize(new Size2D(150, 150)); picture.Translate(300.0f, 550.0f);