private void InitGrid() { Path myPath = new Path(); myPath.Name = "MyCanvas_Grid"; myPath.Stroke = Brushes.Blue; myPath.StrokeThickness = 0.1; StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { for (int i = 0; i <= 500; i += 50) { ctx.BeginFigure(new Point(0, i), false, false); ctx.LineTo(new Point(500, i), true, false); ctx.BeginFigure(new Point(i, 0), false, false); ctx.LineTo(new Point(i, 500), true, false); } } geometry.Freeze(); myPath.Data = geometry; MyCanvas.Children.Add(myPath); }
private void DrawLine(StreamGeometryContext context) { var theta = Math.Atan2(Y1 - Y2, X1 - X2); var sint = Math.Sin(theta); var cost = Math.Cos(theta); var x2WithOffset = X2 + Radius * cost; var y2WithOffset = Y2 + Radius * sint; var pt1 = new Point(X1, Y1); var pt2 = new Point(x2WithOffset, y2WithOffset); context.BeginFigure(pt1, true, false); context.LineTo(pt2, true, true); }
private void InternalDrawArrowGeometry(StreamGeometryContext context) { this.Height = 8; Point pt1 = new Point(0, 4); Point pt2 = new Point(Width - 1, 4); Point pt3 = new Point(Width - 5, 0); Point pt4 = new Point(Width - 5, 8); Point pt5 = new Point(Width - 1, 4); context.BeginFigure(pt1, true, false); context.LineTo(pt2, true, true); context.LineTo(pt3, true, true); context.LineTo(pt4, false, false); context.LineTo(pt5, true, true); }
private void drawPoint(StreamGeometryContext streamGeometryContext, double[,] dataSerie, int dataPointIndex, double width, double height, ref bool isFirstPoint) { Point valuePoint = TranslateValueXYToPoint(dataSerie, dataPointIndex, width, height); if (isFirstPoint) { isFirstPoint = false; streamGeometryContext.BeginFigure(valuePoint, isFilled: true, isClosed: true); } else { streamGeometryContext.LineTo(valuePoint, isStroked: true, isSmoothJoin: false); } }
private Geometry GetMyShapeGeometry() { StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext context = geometry.Open()) { context.BeginFigure(new Point(0, 0), true, true); context.LineTo(new Point(50, 50), false, true); context.LineTo(new Point(75, 25), true, true); } geometry.Freeze(); return(geometry); }
private Geometry CreateGeometry(Rect rect) { StreamGeometry geom = new StreamGeometry(); Rect containerRect = new Rect(RenderSize); using (StreamGeometryContext context = geom.Open()) { context.BeginFigure(new Point(rect.Left, 0), true, true); context.LineTo(containerRect.BottomLeft, true, true); context.LineTo(containerRect.BottomRight, true, true); context.LineTo(new Point(rect.Right, 0), true, true); } return(geom); }
private void InternalDrawArrowGeometry(StreamGeometryContext context, Point sp, Point ep) { double theta = Math.Atan2(sp.Y - ep.Y, sp.X - ep.X); double sint = Math.Sin(theta); double cost = Math.Cos(theta); Point pm = new Point((sp.X + ep.X) / 2, (sp.Y + ep.Y) / 2); Point pt3 = new Point( pm.X + (HeadWidth * cost - HeadHeight * sint), pm.Y + (HeadWidth * sint + HeadHeight * cost)); Point pt4 = new Point( pm.X + (HeadWidth * cost + HeadHeight * sint), pm.Y - (HeadHeight * cost - HeadWidth * sint)); //begin draw line context.BeginFigure(sp, true, false); context.LineTo(ep, true, true); context.BeginFigure(pt3, true, false); context.LineTo(pm, true, true); context.LineTo(pt4, true, true); }
private Geometry GetGeometry() { StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext context = streamGeometry.Open()) { context.BeginFigure(new Point(0, 0), true, true); context.LineTo(new Point(250, 250), false, true); context.LineTo(new Point(350, 150), true, true); } streamGeometry.Freeze(); return(streamGeometry); }
private void InternalDrawArrowGeometry(StreamGeometryContext context) { //因为线宽的不同会导致区域显示不全,因此在计算时需考虑线宽 Point ptStart = new Point(this.StrokeThickness / 2, this.StrokeThickness / 2); Point pt2 = new Point(this.Width - this.StrokeThickness / 2, this.StrokeThickness / 2); Point pt3 = new Point(this.Width - this.StrokeThickness / 2, this.Height - this.StrokeThickness / 2); Point pt4 = new Point(this.StrokeThickness / 2, this.Height - this.StrokeThickness / 2); Point ptEnd = new Point(this.StrokeThickness / 2, 0); context.BeginFigure(ptStart, true, false); context.LineTo(pt2, true, true); context.LineTo(pt3, true, true); context.LineTo(pt4, true, true); context.LineTo(ptEnd, true, true); }
public StreamGeometry GetClipGeometry(Size arrangeBounds) { StreamGeometry clip = new StreamGeometry(); StreamGeometryContext clipGC = clip.Open(); clipGC.BeginFigure(BeginFigurePoint, true, true); clipGC.LineTo(LineToPoint, false, true); Vector v = LineToPoint - BeginFigurePoint; RotateTransform rt = new RotateTransform(WedgeAngle, BeginFigurePoint.X, BeginFigurePoint.Y); bool isLargeArc = WedgeAngle > 180.0; clipGC.ArcTo(rt.Transform(LineToPoint), new Size(v.Length, v.Length), WedgeAngle, isLargeArc, SweepDirection.Clockwise, false, true); clipGC.Close(); return(clip); }
public void Draw(DrawingContext dc, List <Point> filteredPoints, ChartStyle chartStyle) { var geometry = new StreamGeometry(); using (StreamGeometryContext context = geometry.Open()) { context.BeginFigure(filteredPoints[0], false, false); context.PolyLineTo(filteredPoints, true, true); } geometry.Freeze(); Pen pen = new Pen(chartStyle.LineColor, 1); dc.DrawGeometry(null, pen, geometry); }
private void InternalDrawArrowGeometry(StreamGeometryContext context) { double radiu = 1.5; this.Height = radiu * 2 + 2; this.Width = radiu * 2 + 2; Point pt1 = new Point(0 + 1, radiu + 1); Point pt2 = new Point(2 * radiu + 1, radiu + 1); Size size = new Size(radiu, radiu); context.BeginFigure(pt1, true, true); context.ArcTo(pt2, size, 180, false, SweepDirection.Clockwise, true, true); context.ArcTo(pt1, size, 180, false, SweepDirection.Clockwise, true, true); }
private void InternalDrawArrowGeometry(StreamGeometryContext context) { double angle = Math.Atan(this.Height / (this.Width / 2)); double offsetTop = this.StrokeThickness / Math.Cos(angle); double offsetLeft = this.StrokeThickness / Math.Tan(angle) + this.StrokeThickness / Math.Sign(angle); Point pt1 = new Point(this.Width / 2, this.StrokeThickness); Point pt2 = new Point(offsetLeft, this.Height - this.StrokeThickness); Point pt3 = new Point(this.Width - offsetLeft, this.Height - this.StrokeThickness); context.BeginFigure(pt1, true, true); context.LineTo(pt2, true, true); context.LineTo(pt3, true, true); context.LineTo(pt1, true, true); }
private void InternalDrawLineGeometry(StreamGeometryContext context) { double theta = Math.Atan2(Y1 - Y2, X1 - X2); double sint = Math.Sin(theta); double cost = Math.Cos(theta); Point pt1 = new Point(X1, this.Y1); Point pt2 = new Point(X2, this.Y2); context.BeginFigure(pt1, true, false); context.LineTo(pt2, true, true); context.LineTo(pt2, true, true); }
/// <summary> /// 画y轴 /// </summary> private void ProduceYaxis() { if (_rootCanvas == null || CommonData.ViewPortWidth == 0 || CommonData.ViewPortHeight == 0) { return; } _rootCanvas.ClearVisual(); //y轴刻度位置集合 List <Point> YaxisPoints = new List <Point>(); //y轴刻度值集合 List <double> YValues = new List <double>(); double ymax = CommonData.YMaxValue; double ymin = CommonData.YMinValue; if (ymax == 0 && ymin == 0) { return; } CommonData.Scale = CommonData.ViewPortHeight / (ymax - ymin); //y轴刻度之间的间隔,这里始终显示5个刻度 double span = Math.Round((ymax - ymin) / 5, NumberPointCount); double yaxis = ymin; //y轴路径 StreamGeometry axispathStream = new StreamGeometry(); StreamGeometryContext axisContext = axispathStream.Open(); while (Math.Round(ymax - yaxis, 2) >= 0) { //循环画路径 YValues.Add(Math.Round(yaxis, 2)); double yvalue = CommonData.ViewPortHeight - (yaxis - ymin) * CommonData.Scale + CommonData.HeightOffet / 2; Point p = new Point(CommonData.ViewPortWidth, yvalue); YaxisPoints.Add(p); axisContext.BeginFigure(new Point(0, p.Y), false, false); axisContext.LineTo(p, true, false); yaxis += span; if (span == 0) { break; } } axisContext.Close(); //在画布画路径 _rootCanvas.DrawingYaxis(axispathStream, 1, YaxisPoints, YValues); }
/// <summary> /// Draws the line segments by stream geometry. /// </summary> /// <param name="points"> /// The points. /// </param> /// <param name="stroke"> /// The stroke. /// </param> /// <param name="thickness"> /// The thickness. /// </param> /// <param name="dashArray"> /// The dash array. /// </param> /// <param name="lineJoin"> /// The line join. /// </param> /// <param name="aliased"> /// Draw aliased line if set to <c>true</c> . /// </param> private void DrawLineSegmentsByStreamGeometry( IList <ScreenPoint> points, OxyColor stroke, double thickness, double[] dashArray, OxyPenLineJoin lineJoin, bool aliased) { StreamGeometry streamGeometry = null; StreamGeometryContext streamGeometryContext = null; int count = 0; for (int i = 0; i + 1 < points.Count; i += 2) { if (streamGeometry == null) { streamGeometry = new StreamGeometry(); streamGeometryContext = streamGeometry.Open(); } streamGeometryContext.BeginFigure(points[i].ToPoint(aliased), false, false); streamGeometryContext.LineTo(points[i + 1].ToPoint(aliased), true, false); count++; // Must limit the number of figures, otherwise drawing errors... if (count > MaxFiguresPerGeometry || dashArray != null) { streamGeometryContext.Close(); var path = new Path(); this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased); path.Data = streamGeometry; this.Add(path); streamGeometry = null; count = 0; } } if (streamGeometry != null) { streamGeometryContext.Close(); var path = new Path(); this.SetStroke(path, stroke, thickness, lineJoin, dashArray, aliased); path.Data = streamGeometry; this.Add(path); } }
/// <summary> /// Draws the pie piece /// </summary> private void DrawGeometry(StreamGeometryContext context) { if (WedgeAngle == 0) { return; } if (WedgeAngle == 360) { context.DrawGeometry(new EllipseGeometry(new Point(CentreX, CentreY), Radius, Radius)); return; } Point innerArcStartPoint = ComputeCartesianCoordinate(RotationAngle, InnerRadius); innerArcStartPoint.Offset(CentreX, CentreY); Point innerArcEndPoint = ComputeCartesianCoordinate(RotationAngle + WedgeAngle, InnerRadius); innerArcEndPoint.Offset(CentreX, CentreY); Point outerArcStartPoint = ComputeCartesianCoordinate(RotationAngle, Radius); outerArcStartPoint.Offset(CentreX, CentreY); Point outerArcEndPoint = ComputeCartesianCoordinate(RotationAngle + WedgeAngle, Radius); outerArcEndPoint.Offset(CentreX, CentreY); bool largeArc = WedgeAngle > 180.0; if (PushOut > 0) { Point offset = ComputeCartesianCoordinate(RotationAngle + WedgeAngle / 2, PushOut); innerArcStartPoint.Offset(offset.X, offset.Y); innerArcEndPoint.Offset(offset.X, offset.Y); outerArcStartPoint.Offset(offset.X, offset.Y); outerArcEndPoint.Offset(offset.X, offset.Y); } Size outerArcSize = new Size(Radius, Radius); Size innerArcSize = new Size(InnerRadius, InnerRadius); context.BeginFigure(innerArcStartPoint, true, true); context.LineTo(outerArcStartPoint, true, true); context.ArcTo(outerArcEndPoint, outerArcSize, 0, largeArc, SweepDirection.Clockwise, true, true); context.LineTo(innerArcEndPoint, true, true); context.ArcTo(innerArcStartPoint, innerArcSize, 0, largeArc, SweepDirection.Counterclockwise, true, true); }
//Updates the set of points for a trace public void SetTracePoints(int traceNumber, List <Point> points) { if (traceNumber < visualChildren.Count) { DrawingVisual traceVisual = (DrawingVisual)visualChildren[traceNumber]; DrawingContext traceContext = traceVisual.RenderOpen(); Pen pen = new Pen(TraceBrushes[traceNumber], 2); pen.Freeze(); StreamGeometry streamGeo = new StreamGeometry(); StreamGeometryContext streamGeoCtx = streamGeo.Open(); if (points.Count > 1) { double lastX = points[0].X; double lastY = points[0].Y; streamGeoCtx.BeginFigure(points[0], false, false); List <Point> linePoints = new List <Point>(); for (int i = 1; i < points.Count; i++) { if ((Math.Abs(lastX - points[i].X) > 0.5) || (Math.Abs(lastY - points[i].Y) > 100)) { lastX = points[i].X; lastY = points[i].Y; if (points[i].X < 0) { Point endPoint = new Point(); endPoint.Y = points[i].Y; endPoint.X = 0; linePoints.Add(endPoint); break; } else { linePoints.Add(points[i]); } } } streamGeoCtx.PolyLineTo(linePoints, true, false); } streamGeoCtx.Close(); streamGeo.Freeze(); traceContext.DrawGeometry(null, pen, streamGeo); traceContext.Close(); } }
public static Canvas GetCanvas() { Canvas canvas = new Canvas(); canvas.Height = 595; canvas.Width = 520; Grid grid = GetBackground(); VisualBrush visualbrush = new VisualBrush(grid); DrawingBrush drawingBrushAll = new DrawingBrush( new GeometryDrawing( visualbrush, new Pen(new SolidColorBrush(Colors.Gray), double.NaN) { //DashStyle = dashstyle }, new RectangleGeometry( new Rect(0, 0, 85, 65) ) ) ); drawingBrushAll.Stretch = Stretch.Fill; drawingBrushAll.TileMode = TileMode.Tile; drawingBrushAll.Viewbox = new Rect(0, 0, 85, 65); drawingBrushAll.ViewboxUnits = BrushMappingMode.Absolute; drawingBrushAll.Viewport = new Rect(0, 0, 85, 65); drawingBrushAll.ViewportUnits = BrushMappingMode.Absolute; canvas.Background = drawingBrushAll; Path path = new Path(); StreamGeometry streamGeomety = new StreamGeometry(); StreamGeometryContext sgc = streamGeomety.Open(); sgc.BeginFigure(new Point(0, 425), true, true); sgc.LineTo(new Point(520, 425), true, true); sgc.Close(); path.Data = streamGeomety; path.Fill = new SolidColorBrush(Colors.Red); path.Stroke = new SolidColorBrush(Colors.Red); path.StrokeThickness = 2; canvas.Children.Add(path); return(canvas); }
public void DrawPath(IEnumerable <PathOp> ops, Pen pen = null, Brush brush = null) { StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext geometryContext = streamGeometry.Open()) { foreach (var op in ops) { var mt = op as MoveTo; if (mt != null) { geometryContext.BeginFigure(mt.Point.GetPoint(), false, false); continue; } var lt = op as LineTo; if (lt != null) { geometryContext.LineTo(lt.Point.GetPoint(), true, false); continue; } var at = op as ArcTo; if (at != null) { /* * Point c1, c2; * at.GetCircles(pp, out c1, out c2); * var circleCenter = at.LargeArc ^ !at.SweepClockwise ? c2 : c1; * var rotationAngle = (float)Math.Atan2(at.Point.Y - circleCenter.Y, at.Point.X - circleCenter.X); * geometryContext.ArcTo(at.Point.GetPoint(), at.Radius.GetSize(), rotationAngle, * at.LargeArc, at.SweepClockwise ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, * true, false * );*/ throw new NotImplementedException(); } var ct = op as CurveTo; if (ct != null) { geometryContext.BezierTo(ct.Control1.GetPoint(), ct.Control2.GetPoint(), ct.Point.GetPoint(), true, false); } throw new NotSupportedException(); } } dc.DrawGeometry(brush?.GetBrush(), pen?.GetPen(), streamGeometry); }
/// <summary> /// Draws the line segments by stream geometry. /// </summary> /// <param name="points">The points.</param> /// <param name="stroke">The stroke color.</param> /// <param name="thickness">The thickness.</param> /// <param name="edgeRenderingMode">The edge rendering mode.</param> /// <param name="dashArray">The dash array. Use <c>null</c> to get a solid line.</param> /// <param name="lineJoin">The line join.</param> private void DrawLineSegmentsByStreamGeometry( IList <ScreenPoint> points, OxyColor stroke, double thickness, EdgeRenderingMode edgeRenderingMode, double[] dashArray, LineJoin lineJoin) { bool aliased = edgeRenderingMode == EdgeRenderingMode.PreferSpeed; StreamGeometry streamGeometry = null; StreamGeometryContext streamGeometryContext = null; var count = 0; for (int i = 0; i + 1 < points.Count; i += 2) { if (streamGeometry == null) { streamGeometry = new StreamGeometry(); streamGeometryContext = streamGeometry.Open(); } streamGeometryContext.BeginFigure(ToPoint(points[i], aliased), false); streamGeometryContext.LineTo(ToPoint(points[i + 1], aliased)); count++; // Must limit the number of figures, otherwise drawing errors... if (count > MaxFiguresPerGeometry || dashArray != null) { streamGeometryContext.Dispose(); var path = CreateAndAdd <Path>(); SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); path.Data = streamGeometry; streamGeometry = null; count = 0; } } if (streamGeometry != null) { streamGeometryContext.Dispose(); var path = CreateAndAdd <Path>(); SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, null, 0); path.Data = streamGeometry; } }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); var blackSolidBrush = new SolidColorBrush(Colors.Black); var pen = new Pen(blackSolidBrush, 3); pen.Freeze(); double halfPenWidth = pen.Thickness / 2; Rect rangeBorderRect = rect; rangeBorderRect.Offset(-1, -1); GuidelineSet guidelines = new GuidelineSet(); guidelines.GuidelinesX.Add(rangeBorderRect.Left + halfPenWidth); guidelines.GuidelinesX.Add(rangeBorderRect.Right + halfPenWidth); guidelines.GuidelinesY.Add(rangeBorderRect.Top + halfPenWidth); guidelines.GuidelinesY.Add(rangeBorderRect.Bottom + halfPenWidth); Point p1 = rangeBorderRect.BottomRight; p1.Offset(0, -4); guidelines.GuidelinesY.Add(p1.Y + halfPenWidth); Point p2 = rangeBorderRect.BottomRight; p2.Offset(-4, 0); guidelines.GuidelinesX.Add(p2.X + halfPenWidth); drawingContext.PushGuidelineSet(guidelines); var geometry = new StreamGeometry(); using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(p1, true, false); ctx.LineTo(rangeBorderRect.TopRight, true, false); ctx.LineTo(rangeBorderRect.TopLeft, true, false); ctx.LineTo(rangeBorderRect.BottomLeft, true, false); ctx.LineTo(p2, true, false); } geometry.Freeze(); drawingContext.DrawGeometry(null, pen, geometry); drawingContext.Pop(); }
public static void DrawFigure(this StreamGeometryContext ctx, PathFigure figure) { ctx.BeginFigure(figure.StartPoint, figure.IsFilled, figure.IsClosed); foreach (var segment in figure.Segments) { if (segment is LineSegment lineSegment) { ctx.LineTo(lineSegment.Point, lineSegment.IsStroked, lineSegment.IsSmoothJoin); continue; } if (segment is BezierSegment bezierSegment) { ctx.BezierTo(bezierSegment.Point1, bezierSegment.Point2, bezierSegment.Point3, bezierSegment.IsStroked, bezierSegment.IsSmoothJoin); continue; } if (segment is QuadraticBezierSegment quadraticSegment) { ctx.QuadraticBezierTo(quadraticSegment.Point1, quadraticSegment.Point2, quadraticSegment.IsStroked, quadraticSegment.IsSmoothJoin); continue; } if (segment is PolyLineSegment polyLineSegment) { ctx.PolyLineTo(polyLineSegment.Points, polyLineSegment.IsStroked, polyLineSegment.IsSmoothJoin); continue; } if (segment is PolyBezierSegment polyBezierSegment) { ctx.PolyBezierTo(polyBezierSegment.Points, polyBezierSegment.IsStroked, polyBezierSegment.IsSmoothJoin); continue; } if (segment is PolyQuadraticBezierSegment polyQuadraticSegment) { ctx.PolyQuadraticBezierTo(polyQuadraticSegment.Points, polyQuadraticSegment.IsStroked, polyQuadraticSegment.IsSmoothJoin); continue; } if (segment is ArcSegment arcSegment) { ctx.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, arcSegment.IsStroked, arcSegment.IsSmoothJoin); continue; } } }
public void Draw() { drawXOffset = 0; drawYOffset = (int)canvasTracing.ActualHeight / 2; drawXMultiplier = (int)canvasTracing.ActualWidth / wfStrip.lengthSeconds; drawYMultiplier = -(int)canvasTracing.ActualHeight / 2; if (wfStrip.Points.Count < 2) { return; } wfStrip.RemoveNull(); wfStrip.Sort(); drawPath = new Path { Stroke = drawBrush, StrokeThickness = 1 }; drawGeometry = new StreamGeometry { FillRule = FillRule.EvenOdd }; using (drawContext = drawGeometry.Open()) { drawContext.BeginFigure(new System.Windows.Point( (int)(wfStrip.Points [0].X * drawXMultiplier) + drawXOffset, (int)(wfStrip.Points [0].Y * drawYMultiplier) + drawYOffset), true, false); for (int i = 1; i < wfStrip.Points.Count; i++) { if (wfStrip.Points [i].X > wfStrip.lengthSeconds * 2) { continue; } drawContext.LineTo(new System.Windows.Point( (int)(wfStrip.Points [i].X * drawXMultiplier) + drawXOffset, (int)(wfStrip.Points [i].Y * drawYMultiplier) + drawYOffset), true, true); } } drawGeometry.Freeze(); drawPath.Data = drawGeometry; canvasTracing.Children.Clear(); canvasTracing.Children.Add(drawPath); }
public static void DrawFigure(StreamGeometryContext ctx, PathFigure figure) { ctx.BeginFigure(figure.StartPoint, figure.IsFilled, figure.IsClosed); foreach (var segment in figure.Segments) { var lineSegment = segment as WpfLineSegment; if (lineSegment != null) { ctx.LineTo(lineSegment.Point, lineSegment.IsStroked, lineSegment.IsSmoothJoin); continue; } var bezierSegment = segment as BezierSegment; if (bezierSegment != null) { ctx.BezierTo(bezierSegment.Point1, bezierSegment.Point2, bezierSegment.Point3, bezierSegment.IsStroked, bezierSegment.IsSmoothJoin); continue; } var quadraticSegment = segment as QuadraticBezierSegment; if (quadraticSegment != null) { ctx.QuadraticBezierTo(quadraticSegment.Point1, quadraticSegment.Point2, quadraticSegment.IsStroked, quadraticSegment.IsSmoothJoin); continue; } var polyLineSegment = segment as PolyLineSegment; if (polyLineSegment != null) { ctx.PolyLineTo(polyLineSegment.Points, polyLineSegment.IsStroked, polyLineSegment.IsSmoothJoin); continue; } var polyBezierSegment = segment as PolyBezierSegment; if (polyBezierSegment != null) { ctx.PolyBezierTo(polyBezierSegment.Points, polyBezierSegment.IsStroked, polyBezierSegment.IsSmoothJoin); continue; } var polyQuadraticSegment = segment as PolyQuadraticBezierSegment; if (polyQuadraticSegment != null) { ctx.PolyQuadraticBezierTo(polyQuadraticSegment.Points, polyQuadraticSegment.IsStroked, polyQuadraticSegment.IsSmoothJoin); continue; } var arcSegment = segment as ArcSegment; if (arcSegment != null) { ctx.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, arcSegment.IsStroked, arcSegment.IsSmoothJoin); continue; } } }
private StreamGeometry GetTriangle(Point p1, Point p2, Point p3) { StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext geometryContext = streamGeometry.Open()) { geometryContext.BeginFigure(p1, true, true); PointCollection points = new PointCollection { p2, p3 }; geometryContext.PolyLineTo(points, true, true); } streamGeometry.Freeze(); return(streamGeometry); }
public Triangle(Brush nColour, double nScaleX, double nScaleY) : base(nColour, nScaleX, nScaleY) { using (StreamGeometryContext geometryContext = base.BGGeometry.Open()) { geometryContext.BeginFigure(new Point(-16.0d, -16.0d), true, true); pc = new PointCollection(); pc.Add(new Point(16.0d, -16.0d)); pc.Add(new Point(16.0d, 16.0d)); geometryContext.PolyLineTo(pc, true, true); } _NextElementID++; name = "Triangle " + _NextElementID; _FEType = "Triangle"; }
private Geometry GetArcGeometry() { Point startPoint = ConvertToPoint(Math.Min(StartAngle, EndAngle)); Point endPoint = ConvertToPoint(Math.Max(StartAngle, EndAngle)); Size arcSize = new Size(Math.Max(0, (RenderSize.Width - StrokeThickness) / 2), Math.Max(0, (RenderSize.Height - StrokeThickness) / 2)); bool isLargeArc = Math.Abs(EndAngle - StartAngle) > 180; StreamGeometry streamGeometry = new StreamGeometry(); using (StreamGeometryContext context = streamGeometry.Open()) { context.BeginFigure(startPoint, false, false); context.ArcTo(endPoint, arcSize, 0, isLargeArc, SweepDirection.Counterclockwise, true, false); } streamGeometry.Transform = new TranslateTransform(StrokeThickness / 2, StrokeThickness / 2); return(streamGeometry); }
public static Geometry GetGenericGeometry(MarkersType markersType, double width, double height) { StreamGeometry geometry = new StreamGeometry(); GenericMarker markerSpecification = GenericMarkerLookup[markersType]; using (StreamGeometryContext ctx = geometry.Open()) { ctx.BeginFigure(new Point(markerSpecification.X[0] * width, markerSpecification.Y[0] * height), false /* is filled */, true /* is closed */); int n = markerSpecification.X.Length; for (int i = 1; i < n; ++i) { ctx.LineTo(new Point(markerSpecification.X[i] * width, markerSpecification.Y[i] * height), true /* is stroked */, false /* is smooth join */); } } return(geometry); }
private static void CreateThinEdgeArrow(StreamGeometryContext context, GeometryPoint start, GeometryPoint end, double pathStrokeThickness) { GeometryPoint dir = end - start; double dl = dir.Length; //take into account the widths double delta = Math.Min(dl / 2, pathStrokeThickness + pathStrokeThickness / 2); dir *= (dl - delta) / dl; end = start + dir; dir = dir.Rotate(Math.PI / 2); GeometryPoint s = dir * HalfArrowAngleTan; context.BeginFigure((start + s).ToWpf(), true, true); context.LineTo(end.ToWpf(), true, true); context.LineTo((start - s).ToWpf(), true, true); }
private static void DeserializeBeginFigure(BinaryReader br, Byte firstByte, StreamGeometryContext sc) { Point point; bool isFilled; bool isClosed; DeserializePointAndTwoBools(br, firstByte, out point, out isFilled, out isClosed); sc.BeginFigure(point, isFilled, isClosed); }