/// <summary> /// Cache a flattened path. /// </summary> /// <param name="flattenedPath">The flattened path to cache.</param> protected virtual void CacheFlatPath(GraphicsPath flattenedPath) { bool isClosed; GraphicsPathIterator pi = new GraphicsPathIterator(flattenedPath); PointF[] points = flattenedPath.PathPoints; while (pi.NextSubpath(flattenedPath, out isClosed) != 0) { byte type; int start, end; int oldCount = renderList.Count; while (pi.NextPathType(out type, out start, out end) != 0) { for (int i = start; i <= end; i++) { renderList.Add(points[i]); } if (isClosed) { renderList.Add(points[start]); } renderListTypes.Add(new PrimitiveTypeInfo(oldCount, renderList.Count - 1, pen.Color.ToArgb(), PrimitiveType.LineStrip)); } } }
/// <summary> /// Renders the flattened path to the device using the specified color. /// </summary> /// <param name="device">The device to use for rendering the path.</param> /// <param name="color">The color to use for the vertices.</param> /// <param name="flattenedPath">The path to render.</param> protected virtual void Render(Device device, int color, GraphicsPath flattenedPath) { PointF[] points = flattenedPath.PathPoints; device.VertexFormat = CustomVertex.PositionColored.Format; bool isClosed; GraphicsPathIterator pi = new GraphicsPathIterator(flattenedPath); while (pi.NextSubpath(flattenedPath, out isClosed) != 0) { byte type; int start, end; while (pi.NextPathType(out type, out start, out end) != 0) { int numDistinctPoints = end - start + 1; int totNumPoints = numDistinctPoints; if (isClosed) { totNumPoints++; } CustomVertex.PositionColored[] colVerts = new CustomVertex.PositionColored[totNumPoints]; P3Util.CreateColoredVertexList(colVerts, points, start, 0, numDistinctPoints, color); if (isClosed) { colVerts[numDistinctPoints] = colVerts[0]; } device.DrawUserPrimitives(PrimitiveType.LineStrip, totNumPoints - 1, colVerts); } } }
// </snippet5> // Snippet for: M:System.Drawing.Drawing2D.GraphicsPathIterator.NextPathType(System.Byte@,System.Int32@,System.Int32@) // <snippet6> public void NextPathTypeExample(PaintEventArgs e) { // Create the GraphicsPath. GraphicsPath myPath = new GraphicsPath(); Point[] myPoints = { new Point(20, 20), new Point(120, 120), new Point(20, 120), new Point(20, 20) }; Rectangle myRect = new Rectangle(120, 120, 100, 100); // Add 3 lines, a rectangle, and an ellipse. myPath.AddLines(myPoints); myPath.AddRectangle(myRect); myPath.AddEllipse(220, 220, 100, 100); // List all of the path points to the screen. ListPathPoints(e, myPath, null, 20, 1); // Create a GraphicsPathIterator. GraphicsPathIterator myPathIterator = new GraphicsPathIterator(myPath); // Rewind the Iterator. myPathIterator.Rewind(); // Iterate the subpaths and types, and list the results to // the screen. int i, j = 20; int mySubPaths, subPathStartIndex, subPathEndIndex; Boolean IsClosed; byte subPathPointType; int pointTypeStartIndex, pointTypeEndIndex, numPointsFound; Font myFont = new Font("Arial", 8); SolidBrush myBrush = new SolidBrush(Color.Black); j = 20; for (i = 0; i < 3; i++) { mySubPaths = myPathIterator.NextSubpath( out subPathStartIndex, out subPathEndIndex, out IsClosed); numPointsFound = myPathIterator.NextPathType( out subPathPointType, out pointTypeStartIndex, out pointTypeEndIndex); e.Graphics.DrawString( "SubPath: " + i + " Points Found: " + numPointsFound.ToString() + " Type of Points: " + subPathPointType.ToString(), myFont, myBrush, 200, j); j += 20; } // List the total number of path points to the screen. ListPathPoints(e, myPath, myPathIterator, 200, 2); }
/// <summary> /// Tesselates the specified path, notifying the /// <see cref="UMD.HCIL.PiccoloDirect3D.Util.TesselationVisitor">TesselationVisitor</see> /// as each new triangle primitive is added. /// </summary> /// <param name="path">The path to tesselate.</param> /// <param name="visitor">The tesselation visitor to notify.</param> public virtual void Tesselate(GraphicsPath path, TesselationVisitor visitor) { this.visitor = visitor; switch (path.FillMode) { case FillMode.Alternate: //even/odd P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingOdd); break; case FillMode.Winding: //nonzero P3Util.SetWindingRule(tess, P3Util.GlTessWinding.WindingNonzero); break; } P3Util.GluTessBeginPolygon(tess, IntPtr.Zero); bool isClosed; GraphicsPathIterator pi = new GraphicsPathIterator(path); PointF[] points = path.PathPoints; while (pi.NextSubpath(path, out isClosed) != 0) { byte type; int start, end; while (pi.NextPathType(out type, out start, out end) != 0) { PathPointType ppType = (PathPointType)type; P3Util.GluTessBeginContour(tess); for (int i = start; i <= end; i++) { PointF point = points[i]; double[] coords = new double[3]; coords[0] = point.X; coords[1] = point.Y; coords[2] = 0; GCHandle handle = GCHandle.Alloc(coords, GCHandleType.Pinned); P3Util.GluTessVertex(tess, coords, (IntPtr)handle); handles.Add(handle); } P3Util.GluTessEndContour(tess); } } P3Util.GluTessEndPolygon(tess); ClearHandles(); }
public virtual void NextPathType() { GraphicsPath path = new GraphicsPath(); path.AddLine(new Point(100, 100), new Point(400, 100)); path.AddBezier(100, 100, 500, 250, 100, 50, 250, 280); path.AddLine(new Point(400, 200), new Point(10, 100)); path.StartFigure(); path.SetMarkers(); path.AddBezier(10, 10, 50, 250, 100, 5, 200, 280); path.StartFigure(); path.SetMarkers(); path.AddRectangle(new Rectangle(10, 20, 300, 400)); path.StartFigure(); path.SetMarkers(); path.AddLine(new Point(400, 400), new Point(400, 10)); GraphicsPathIterator iterator = new GraphicsPathIterator(path); byte pathType; int start; int end; bool isClosed; int count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(0, count); Assert.AreEqual((byte)PathPointType.Start, pathType); Assert.AreEqual(0, start); Assert.AreEqual(0, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(3, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(0, start); Assert.AreEqual(2, end); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(4, count); Assert.AreEqual((byte)PathPointType.Bezier3, pathType); Assert.AreEqual(2, start); Assert.AreEqual(5, end); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(3, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(5, start); Assert.AreEqual(7, end); // we don't want to be a bug compliant with .net /* * count = iterator.NextPathType (out pathType, out start, out end); * Assert.AreEqual (0, count); * Assert.AreEqual ((byte)PathPointType.Line, pathType); * Assert.AreEqual (5, start); * Assert.AreEqual (7, end); */ iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(4, count); Assert.AreEqual((byte)PathPointType.Bezier3, pathType); Assert.AreEqual(8, start); Assert.AreEqual(11, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(4, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(12, start); Assert.AreEqual(15, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(2, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(16, start); Assert.AreEqual(17, end); iterator.NextSubpath(out start, out end, out isClosed); count = iterator.NextPathType(out pathType, out start, out end); Assert.AreEqual(0, count); Assert.AreEqual((byte)PathPointType.Line, pathType); Assert.AreEqual(0, start); Assert.AreEqual(0, end); }