static void FillContexForPolyline(WStreamGeometryContext context, MPolyline poly) { for (PolylinePoint pp = poly.StartPoint.Next; pp != null; pp = pp.Next) { context.LineTo(Common.WpfPoint(pp.Point), true, false); } }
static void AddArrow(WStreamGeometryContext context, MPoint start, MPoint end, double thickness) { if (thickness > 1) { MPoint dir = end - start; MPoint h = dir; double dl = dir.Length; if (dl < 0.001) { return; } dir /= dl; var s = new MPoint(-dir.Y, dir.X); double w = 0.5 * thickness; MPoint s0 = w * s; s *= h.Length * HalfArrowAngleTan; s += s0; double rad = w / HalfArrowAngleCos; context.BeginFigure(Common.WpfPoint(start + s), true, true); context.LineTo(Common.WpfPoint(start - s), true, false); context.LineTo(Common.WpfPoint(end - s0), true, false); context.ArcTo(Common.WpfPoint(end + s0), new WSize(rad, rad), Math.PI - ArrowAngle, false, WSweepDirection.Clockwise, true, false); } else { MPoint dir = end - start; double dl = dir.Length; //take into account the widths double delta = Math.Min(dl / 2, thickness + thickness / 2); dir *= (dl - delta) / dl; end = start + dir; dir = dir.Rotate(Math.PI / 2); MPoint s = dir * HalfArrowAngleTan; context.BeginFigure(Common.WpfPoint(start + s), true, true); context.LineTo(Common.WpfPoint(end), true, true); context.LineTo(Common.WpfPoint(start - s), true, true); } }
public void StreamGeometryTriangleExample(List <System.Windows.Point> arrPoints) { // Create a path to draw a geometry with. System.Windows.Shapes.Path myPath = new System.Windows.Shapes.Path(); myPath.Stroke = System.Windows.Media.Brushes.Black; myPath.StrokeThickness = 1; System.Windows.Media.Color cl = new System.Windows.Media.Color(); byte[] arr = new byte[4]; rand.NextBytes(arr); //cl.A = System.Windows.Media.Brush br = new System.Windows.Media.SolidColorBrush(System.Windows.Media.Color.FromArgb(arr[0], arr[1], arr[2], arr[3])); #region для заполнение разкоментировать // myPath.Fill = br; #endregion // Create a StreamGeometry to use to specify myPath. System.Windows.Media.StreamGeometry geometry = new System.Windows.Media.StreamGeometry(); // geometry.FillRule = System.Windows.Media.FillRule.EvenOdd; // Open a StreamGeometryContext that can be used to describe this StreamGeometry // object's contents. using (System.Windows.Media.StreamGeometryContext ctx = geometry.Open()) { // Begin the triangle at the point specified. Notice that the shape is set to // be closed so only two lines need to be specified below to make the triangle. //ctx.BeginFigure(arrPoints[0], true /* is filled */, true /* is closed */); ctx.BeginFigure(arrPoints[0], true /* is filled */, false /* is closed */); for (int i = 1; i < arrPoints.Count; i++) { ctx.LineTo(arrPoints[i], true /* is stroked */, false /* is smooth join */); } // Draw a line to the next specified point. // ctx.LineTo(new System.Windows.Point(100, 100), true /* is stroked */, false /* is smooth join */); // Draw another line to the next specified point. // ctx.LineTo(new System.Windows.Point(100, 50), true /* is stroked */, false /* is smooth join */); } // Freeze the geometry (make it unmodifiable) // for additional performance benefits. geometry.Freeze(); // Specify the shape (triangle) of the Path using the StreamGeometry. myPath.Data = geometry; // Add path shape to the UI. StackPanel mainPanel = new StackPanel(); Canvas ss = cv; ss.Children.Clear(); ss.Children.Add(myPath); }
static void FillContexForCurve(WStreamGeometryContext context, Curve c) { foreach (ICurve seg in c.Segments) { var bezSeg = seg as CubicBezierSegment; if (bezSeg != null) { context.BezierTo(Common.WpfPoint(bezSeg.B(1)), Common.WpfPoint(bezSeg.B(2)), Common.WpfPoint(bezSeg.B(3)), true, false); } else { var ls = seg as MLineSegment; if (ls != null) { context.LineTo(Common.WpfPoint(ls.End), true, false); } else { var ellipse = seg as MEllipse; if (ellipse != null) { double sweepAngle = EllipseSweepAngle(ellipse); bool largeArc = Math.Abs(sweepAngle) >= Math.PI; MRectangle box = ellipse.FullBox(); context.ArcTo(Common.WpfPoint(ellipse.End), new WSize(box.Width / 2, box.Height / 2), sweepAngle, largeArc, sweepAngle < 0 ? WSweepDirection.Counterclockwise : WSweepDirection.Clockwise, true, true); } else { throw new NotImplementedException(); } } } } }
internal static void FillContextForICurve(WStreamGeometryContext context, ICurve iCurve) { context.BeginFigure(Common.WpfPoint(iCurve.Start), false, false); var c = iCurve as Curve; if (c != null) { FillContexForCurve(context, c); } else { var cubicBezierSeg = iCurve as CubicBezierSegment; if (cubicBezierSeg != null) { context.BezierTo(Common.WpfPoint(cubicBezierSeg.B(1)), Common.WpfPoint(cubicBezierSeg.B(2)), Common.WpfPoint(cubicBezierSeg.B(3)), true, false); } else { var ls = iCurve as MLineSegment; if (ls != null) { context.LineTo(Common.WpfPoint(ls.End), true, false); } else { var rr = iCurve as RoundedRect; if (rr != null) { FillContexForCurve(context, rr.Curve); } else { var poly = iCurve as MPolyline; if (poly != null) { FillContexForPolyline(context, poly); } else { var ellipse = iCurve as MEllipse; if (ellipse != null) { double sweepAngle = EllipseSweepAngle(ellipse); bool largeArc = Math.Abs(sweepAngle) >= Math.PI; MRectangle box = ellipse.FullBox(); context.ArcTo(Common.WpfPoint(ellipse.End), new WSize(box.Width / 2, box.Height / 2), sweepAngle, largeArc, sweepAngle < 0 ? WSweepDirection.Counterclockwise : WSweepDirection.Clockwise, true, true); } else { throw new NotImplementedException(); } } } } } } }