public CombinedGeometry GetOct(int i, int j, int radius) { int standX = i; int standY = j; StreamGeometry g = new StreamGeometry(); g.FillRule = FillRule.EvenOdd; StreamGeometryContext ctx = g.Open(); ctx.BeginFigure(new Point(standX - radius, standY), true, true); ctx.LineTo(new Point(standX, standY - radius), true, false); ctx.LineTo(new Point(standX + radius, standY), true, false); ctx.LineTo(new Point(standX, standY + radius), true, false); ctx.Close(); StreamGeometry h = new StreamGeometry(); h.FillRule = FillRule.EvenOdd; ctx = h.Open(); ctx.BeginFigure(new Point(standX - radius / 1.414, standY - radius / 1.414), true, true); ctx.LineTo(new Point(standX + radius / 1.414, standY - radius / 1.414), true, false); ctx.LineTo(new Point(standX + radius / 1.414, standY + radius / 1.414), true, false); ctx.LineTo(new Point(standX - radius / 1.414, standY + radius / 1.414), true, false); ctx.Close(); CombinedGeometry cg = new CombinedGeometry(g, h); return(cg); }
/// <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="dashArray">The dash array. Use <c>null</c> to get a solid line.</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, LineJoin lineJoin, bool aliased) { DrawResult drawResult = this.Draw(new DrawLine(points, stroke, thickness, dashArray, lineJoin, aliased, DrawLineType.StreamGeometry)); if (drawResult == DrawResult.Equal) { return; } 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(this.ToPoint(points[i], aliased), false, false); streamGeometryContext.LineTo(this.ToPoint(points[i + 1], aliased), true, false); count++; // Must limit the number of figures, otherwise drawing errors... if (count > MaxFiguresPerGeometry || dashArray != null) { streamGeometryContext.Close(); var path = this.CreateAndAdd <Path>(); this.SetStroke(path, stroke, thickness, lineJoin, dashArray, 0, aliased); path.Data = streamGeometry; streamGeometry = null; count = 0; } } if (streamGeometry != null) { streamGeometryContext.Close(); var path = this.CreateAndAdd <Path>(); this.SetStroke(path, stroke, thickness, lineJoin, null, 0, aliased); path.Data = 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) { StreamGeometry streamGeometry = null; StreamGeometryContext streamGeometryContext = null; int count = 0; var actualStrokeThickness = this.GetActualStrokeThickness(thickness, edgeRenderingMode); for (int i = 0; i + 1 < points.Count; i += 2) { if (streamGeometry == null) { streamGeometry = new StreamGeometry(); streamGeometryContext = streamGeometry.Open(); } var actualPoints = this.GetActualPoints(new[] { points[i], points[i + 1] }, actualStrokeThickness, edgeRenderingMode).ToList(); streamGeometryContext.BeginFigure(actualPoints[0], false, false); streamGeometryContext.LineTo(actualPoints[1], true, false); count++; // Must limit the number of figures, otherwise drawing errors... if (count > MaxFiguresPerGeometry || dashArray != null) { streamGeometryContext.Close(); var path = this.CreateAndAdd <Path>(); this.SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, dashArray, 0); path.Data = streamGeometry; streamGeometry = null; count = 0; } } if (streamGeometry != null) { streamGeometryContext.Close(); var path = this.CreateAndAdd <Path>(); this.SetStroke(path, stroke, thickness, edgeRenderingMode, lineJoin, null, 0); path.Data = streamGeometry; } }
/// <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 crossed double bond to indicate indeterminate geometry /// </summary> /// <param name="startPoint"></param> /// <param name="endPoint"></param> /// <param name="enclosingPoly"></param> /// <returns></returns> public static Geometry CrossedDoubleGeometry(Point startPoint, Point endPoint, ref List <Point> enclosingPoly) { Vector v = endPoint - startPoint; Vector normal = v.Perpendicular(); normal.Normalize(); Point point1, point2, point3, point4; double distance = Globals.Offset; point1 = startPoint + normal * distance; point2 = point1 + v; point3 = startPoint - normal * distance; point4 = point3 + v; enclosingPoly = new List <Point>() { point1, point2, point4, point3 }; StreamGeometry sg = new StreamGeometry(); using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(point1, false, false); sgc.LineTo(point4, true, false); sgc.BeginFigure(point2, false, false); sgc.LineTo(point3, true, false); sgc.Close(); } sg.Freeze(); return(sg); }
/// <summary> /// draws the two parallel lines of a double bond /// These bonds can either straddle the atom-atom line or fall to one or other side of it /// </summary> /// <param name="startPoint"></param> /// <param name="endPoint"></param> /// <param name="doubleBondPlacement"></param> /// <param name="ringCentroid"></param> /// <param name="enclosingPoly"></param> /// <returns></returns> public static System.Windows.Media.Geometry DoubleBondGeometry(Point startPoint, Point endPoint, BondDirection doubleBondPlacement, ref List <Point> enclosingPoly, Point?ringCentroid = null) { Point point1; Point point2; Point point3; Point point4; enclosingPoly = GetDoubleBondPoints(startPoint, endPoint, doubleBondPlacement, ringCentroid, out point1, out point2, out point3, out point4); ; StreamGeometry sg = new StreamGeometry(); using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(point1, false, false); sgc.LineTo(point2, true, false); sgc.BeginFigure(point3, false, false); sgc.LineTo(point4, true, false); sgc.Close(); } sg.Freeze(); return(sg); }
private Geometry CreateGeometry(Point p, double radius, double startDegrees, double deltaDegrees) { // Create a StreamGeometry for describing the shape StreamGeometry geometry = new StreamGeometry(); using (StreamGeometryContext context = geometry.Open()) { var rad1 = Deg2Rad(startDegrees); var drad = Deg2Rad(deltaDegrees); var rad2 = rad1 + drad; var p1 = new Point((Math.Cos(rad1) + 1) * radius + p.X, -(Math.Sin(rad1) - 1) * radius + p.Y); var p2 = new Point((Math.Cos(rad2) + 1) * radius + p.X, -(Math.Sin(rad2) - 1) * radius + p.Y); context.BeginFigure(p, true, true); if (deltaDegrees >= 360) { context.DrawGeometry(new EllipseGeometry(new Rect(p.X - radius, p.Y - radius, radius * 2, radius * 2))); } else if (deltaDegrees >= 0) { context.LineTo(p1, true, true); context.ArcTo(p2, new Size(radius, radius), drad, deltaDegrees > 180, SweepDirection.Counterclockwise, true, true); context.Close(); } } // Freeze the geometry for performance benefits geometry.Freeze(); return(geometry); }
/// <summary> /// Gets a <see cref="MapView.GridGeometry"/> for the specified <see cref="MapView"/>. /// </summary> /// <param name="mapView"> /// The <see cref="MapView"/> whose <see cref="MapView.GridGeometry"/> to return.</param> /// <returns> /// A frozen optimized <see cref="StreamGeometry"/> created from all <see /// cref="RegularPolygon"/> outlines contained in the <see cref="CatalogManager.MapGrid"/> /// of the specified <paramref name="mapView"/>.</returns> /// <exception cref="ArgumentNullException"> /// <paramref name="mapView"/> is a null reference.</exception> /// <remarks><para> /// <b>GetGridGeometry</b> assumes that during the lifetime of a <see /// cref="MapViewManager"/>, the <see cref="CatalogManager.MapGrid"/> of any given <paramref /// name="mapView"/> is identical except for the current <see cref="MapView.Scale"/>. /// </para><para> /// Once a <see cref="StreamGeometry"/> has been created for a given <paramref /// name="mapView"/>, it is cached with the the corresponding <see cref="MapView.Scale"/>. /// The cached value is returned for subsequent <paramref name="mapView"/> arguments using /// the same <see cref="MapView.Scale"/>.</para></remarks> internal StreamGeometry GetGridGeometry(MapView mapView) { if (mapView == null) { ThrowHelper.ThrowArgumentNullException("mapView"); } // return existing geometry, if any StreamGeometry geometry; if (this._gridGeometries.TryGetValue(mapView.Scale, out geometry)) { return(geometry); } // create new geometry at specified scale geometry = new StreamGeometry(); StreamGeometryContext context = geometry.Open(); mapView.MapGrid.DrawOptimized(context, MapView.MapBorder); context.Close(); geometry.Freeze(); // store geometry with specified scale this._gridGeometries.Add(mapView.Scale, geometry); return(geometry); }
private void DrawCornerAdorner(DrawingContext drawingContext, Point anchorPoint, Matrix matrix, Brush brush, Pen pen) { Vector vector1 = new Vector(1.0, 0.0) * matrix; Vector vector2 = new Vector(0.0, 1.0) * matrix; vector1.Normalize(); vector2.Normalize(); anchorPoint += (15.0 - 0.5 * pen.Thickness) * vector2; anchorPoint += (5.0 + 0.5 * pen.Thickness) * vector1; double num = 10.0 - pen.Thickness; Vector vector3 = vector1 * num; Vector vector4 = vector2 * num; StreamGeometry streamGeometry = new StreamGeometry(); StreamGeometryContext streamGeometryContext = streamGeometry.Open(); streamGeometryContext.BeginFigure(anchorPoint, true, true); streamGeometryContext.LineTo(anchorPoint + vector3, true, false); streamGeometryContext.LineTo(anchorPoint + vector3 - vector4, true, false); streamGeometryContext.Close(); streamGeometry.Freeze(); if (this.IsEnabled) { drawingContext.DrawGeometry(brush, pen, (System.Windows.Media.Geometry)streamGeometry); } else { drawingContext.DrawGeometry((Brush)Brushes.Transparent, (Pen)null, (System.Windows.Media.Geometry)streamGeometry); drawingContext.DrawLine(pen, anchorPoint, anchorPoint + vector3); drawingContext.DrawLine(pen, anchorPoint + vector3, anchorPoint + vector3 - vector4); } }
public static StreamGeometry StreamGeometryFromCurve(Curve curve, MatrixTransform graphToCanvas) { double[] tempX; double[] tempY; if (graphToCanvas != null) { tempX = curve.xTransformed.MultiplyBy(graphToCanvas.Matrix.M11).SumWith(graphToCanvas.Matrix.OffsetX); tempY = curve.yTransformed.MultiplyBy(graphToCanvas.Matrix.M22).SumWith(graphToCanvas.Matrix.OffsetY); } else { tempX = curve.xTransformed; tempY = curve.yTransformed; } StreamGeometry streamGeometry = new StreamGeometry(); StreamGeometryContext context = streamGeometry.Open(); int lines = 0; for (int i = 0; i < curve.x.Length; ++i) { if (i == 0) { context.BeginFigure(new Point(tempX[i], tempY[i]), false, false); } else { if (curve.includeLinePoint[i]) { context.LineTo(new Point(tempX[i], tempY[i]), true, false); lines++; } } } context.Close(); return(streamGeometry); }
protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); StreamGeometry sg = new StreamGeometry(); Rect atomBounds = _targetedVisual.Bounds; atomBounds.Inflate(2.0, 2.0); Vector twiddle = new Vector(3, 0.0); using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(atomBounds.TopLeft + twiddle, false, false); sgc.LineTo(atomBounds.TopLeft, true, true); sgc.LineTo(atomBounds.BottomLeft, true, true); sgc.LineTo(atomBounds.BottomLeft + twiddle, true, true); sgc.BeginFigure(atomBounds.TopRight - twiddle, false, false); sgc.LineTo(atomBounds.TopRight, true, true); sgc.LineTo(atomBounds.BottomRight, true, true); sgc.LineTo(atomBounds.BottomRight - twiddle, true, true); sgc.Close(); } drawingContext.DrawGeometry(_solidColorBrush, _bracketPen, sg); }
protected void DrawArrowTail(DrawingContext context, Matrix matrix, Point startPoint, Point endPoint) { startPoint *= matrix; endPoint *= matrix; Matrix identity = Matrix.Identity; identity.RotateAt(Math.Atan2(endPoint.Y - startPoint.Y, endPoint.X - startPoint.X) * 180.0 / Math.PI, startPoint.X, startPoint.Y); Point startPoint1 = new Point(startPoint.X - 8.0 - 7.0, startPoint.Y) * identity; Point point1 = new Point(startPoint.X - 12.0 - 7.0, startPoint.Y - 4.0) * identity; Point point2 = new Point(startPoint.X - 4.0 - 7.0, startPoint.Y - 4.0) * identity; Point point3 = new Point(startPoint.X - 7.0, startPoint.Y) * identity; Point point4 = new Point(startPoint.X - 4.0 - 7.0, startPoint.Y + 4.0) * identity; Point point5 = new Point(startPoint.X - 12.0 - 7.0, startPoint.Y + 4.0) * identity; StreamGeometry streamGeometry = new StreamGeometry(); StreamGeometryContext streamGeometryContext = streamGeometry.Open(); streamGeometryContext.BeginFigure(startPoint1, true, true); streamGeometryContext.PolyLineTo((IList <Point>) new Point[5] { point1, point2, point3, point4, point5 }, 1 != 0, 0 != 0); streamGeometryContext.Close(); streamGeometry.Freeze(); this.DrawArrowBackdrop(context, identity, new Point(startPoint.X, startPoint.Y - 6.0), new Point(startPoint.X - 12.0 - 7.0, startPoint.Y + 6.0)); Brush brush = this.IsActive ? this.ActiveBrush : this.InactiveBrush; context.DrawGeometry(brush, this.ThinPen, (System.Windows.Media.Geometry)streamGeometry); }
public static Canvas GetArc() { Canvas canvas = new Canvas(); canvas.Height = 200; canvas.Width = 200; Path pathArc = new Path(); PathGeometry pathGeometry = new PathGeometry(); ArcSegment arc = new ArcSegment(new Point(0, 50), new Size(50, 50), 0, false, SweepDirection.Clockwise, true); PathFigure figureArc = new PathFigure(); figureArc.StartPoint = new Point(50, 0); figureArc.Segments.Add(arc); LineSegment line1 = new LineSegment(new Point(50, 0), true); LineSegment line2 = new LineSegment(new Point(0, 50), true); PathFigure figureLine = new PathFigure(); figureLine.StartPoint = new Point(50, 50); figureLine.Segments.Add(line1); figureLine.Segments.Add(line2); pathGeometry.Figures.Add(figureArc); pathGeometry.Figures.Add(figureLine); pathArc.Data = pathGeometry; pathArc.Fill = new SolidColorBrush(Colors.LightGray); canvas.Children.Add(pathArc); Path pathLine1 = new Path(); StreamGeometry streamGeomety1 = new StreamGeometry(); StreamGeometryContext sgc1 = streamGeomety1.Open(); sgc1.BeginFigure(new Point(0, 50), true, true); sgc1.LineTo(new Point(50, 50), true, true); sgc1.LineTo(new Point(0, 200), true, true); sgc1.Close(); pathLine1.Data = streamGeomety1; pathLine1.Fill = new SolidColorBrush(Colors.LightGray); canvas.Children.Add(pathLine1); Path pathLine2 = new Path(); StreamGeometry streamGeomety2 = new StreamGeometry(); StreamGeometryContext sgc2 = streamGeomety2.Open(); sgc2.BeginFigure(new Point(50, 0), true, true); sgc2.LineTo(new Point(50, 50), true, true); sgc2.LineTo(new Point(200, 0), true, true); sgc2.Close(); pathLine2.Data = streamGeomety2; pathLine2.Fill = new SolidColorBrush(Colors.LightGray); canvas.Children.Add(pathLine2); return(canvas); }
public static System.Windows.Media.Geometry GetTransformedRectangleGeometry(Rect rect, Matrix matrix, double thickness) { if (rect.IsEmpty) { return((System.Windows.Media.Geometry)null); } Vector vector1 = new Vector(1.0, 0.0) * matrix; Vector vector2 = new Vector(0.0, 1.0) * matrix; Vector v1 = new Vector(vector2.Y, -vector2.X); Vector v2 = new Vector(vector1.Y, -vector1.X); if (v1 * vector1 < 0.0) { v1 *= -1.0; } if (v2 * vector2 < 0.0) { v2 *= -1.0; } double length1 = v1.Length; if (length1 > 0.0) { v1 /= length1; } double length2 = v2.Length; if (length2 > 0.0) { v2 /= length2; } Vector vector3 = (Vector)(rect.TopLeft * matrix); Vector vector4 = (Vector)(rect.BottomRight * matrix); double num = thickness / 2.0; double c1_1 = v1 * vector3 - num; double c2_1 = v2 * vector3 - num; double c1_2 = v1 * vector4 + num; double c2_2 = v2 * vector4 + num; Point intersection1 = Adorner.GetIntersection(v1, c1_1, v2, c2_1); Point intersection2 = Adorner.GetIntersection(v1, c1_2, v2, c2_1); Point intersection3 = Adorner.GetIntersection(v1, c1_1, v2, c2_2); Point intersection4 = Adorner.GetIntersection(v1, c1_2, v2, c2_2); StreamGeometry streamGeometry = new StreamGeometry(); StreamGeometryContext streamGeometryContext = streamGeometry.Open(); streamGeometryContext.BeginFigure(intersection1, true, true); streamGeometryContext.PolyLineTo((IList <Point>) new Point[3] { intersection2, intersection4, intersection3 }, 1 != 0, 0 != 0); streamGeometryContext.Close(); streamGeometry.Freeze(); return((System.Windows.Media.Geometry)streamGeometry); }
internal StreamGeometry Close() { if (m_context != null) { m_context.Close(); m_geometry.Freeze(); } return(m_geometry); }
internal override void RenderAxis() { YAxisPosition position = (YAxisPosition)GetValue(YAxisPositionProperty); Point tickPosition; StreamGeometryContext lineContext = axisLineGeometry.Open(); if (!IsInnermost) { Point axisStart = new Point(xPosition, AxisTotalLength - MinTransformed * Scale + Offset - axisLine.StrokeThickness / 2); lineContext.BeginFigure(axisStart, false, false); lineContext.LineTo(new Point(xPosition, AxisTotalLength - MaxTransformed * Scale + Offset + axisLine.StrokeThickness / 2), true, false); } lineContext.Close(); StreamGeometryContext context = axisTicksGeometry.Open(); if (TicksVisible) { for (int i = 0; i < Ticks.Length; ++i) { if (position == YAxisPosition.Left) { tickPosition = TickStartPosition(i); context.BeginFigure(tickPosition, false, false); tickPosition.X = tickPosition.X - TickLength; context.LineTo(tickPosition, true, false); } if (position == YAxisPosition.Right) { tickPosition = TickStartPosition(i); context.BeginFigure(tickPosition, false, false); tickPosition.X = tickPosition.X + TickLength; context.LineTo(tickPosition, true, false); } } } context.Close(); interactionPad.Height = AxisTotalLength - AxisPadding.Total(); interactionPad.Width = AxisThickness; if (position == YAxisPosition.Left) { interactionPad.SetValue(Canvas.LeftProperty, xPosition - AxisThickness); } else { interactionPad.SetValue(Canvas.LeftProperty, xPosition); } double yPosition = AxisTotalLength - MaxTransformed * Scale + Offset; interactionPad.SetValue(Canvas.TopProperty, yPosition); base.RenderAxis(); }
internal void Render(Rect position) { StreamGeometryContext context = geometry.Open(); Point contextPoint = new Point(position.X, position.Y); context.BeginFigure(contextPoint, false, true); contextPoint.Y = contextPoint.Y + position.Height; context.LineTo(contextPoint, true, false); contextPoint.X = contextPoint.X + position.Width; context.LineTo(contextPoint, true, false); contextPoint.Y = contextPoint.Y - position.Height; context.LineTo(contextPoint, true, false); context.Close(); }
internal override void RenderAxis() { XAxisPosition position = (XAxisPosition)GetValue(XAxisPositionProperty); Point tickPosition; StreamGeometryContext lineContext = axisLineGeometry.Open(); if (!IsInnermost) { Point axisStart = new Point(MinTransformed * Scale - Offset - axisLine.StrokeThickness / 2, yPosition); lineContext.BeginFigure(axisStart, false, false); lineContext.LineTo(new Point(MaxTransformed * Scale - Offset + axisLine.StrokeThickness / 2, yPosition), true, false); } lineContext.Close(); StreamGeometryContext ticksContext = axisTicksGeometry.Open(); if (TicksVisible) { for (int i = 0; i < TicksTransformed.Length; ++i) { tickPosition = TickStartPosition(i); ticksContext.BeginFigure(tickPosition, false, false); if (position == XAxisPosition.Bottom) { tickPosition.Y = tickPosition.Y + TickLength; } if (position == XAxisPosition.Top) { tickPosition.Y = tickPosition.Y - TickLength; } ticksContext.LineTo(tickPosition, true, false); ticksContext.BeginFigure(tickPosition, false, false); tickPosition.Y = tickPosition.Y; ticksContext.LineTo(tickPosition, true, false); } } ticksContext.Close(); interactionPad.Width = Math.Max(AxisTotalLength - AxisPadding.Total(), 1); interactionPad.Height = AxisThickness; if (position == XAxisPosition.Bottom) { interactionPad.SetValue(Canvas.TopProperty, yPosition); } else { interactionPad.SetValue(Canvas.TopProperty, yPosition - AxisThickness); } double xPosition = Scale * MinTransformed - Offset; interactionPad.SetValue(Canvas.LeftProperty, xPosition); base.RenderAxis(); }
public override void Draw(DrawingContext ctx, Matrix matrix) { if (!this.IsValid) { return; } PathFigureEditor pathFigureEditor = new PathFigureEditor(this.PathGeometry.Figures[this.FigureIndex]); StreamGeometry streamGeometry = new StreamGeometry(); StreamGeometryContext streamGeometryContext = streamGeometry.Open(); switch (this.PathPointKind) { case PathPointKind.Start: throw new InvalidOperationException(ExceptionStringTable.PathSegmentAdornerIsolatedPointSegment); case PathPointKind.Arc: ArcSegment arcSegment = (ArcSegment)pathFigureEditor.PathFigure.Segments[this.SegmentIndex]; streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -1), false, false); streamGeometryContext.ArcTo(arcSegment.Point, arcSegment.Size, arcSegment.RotationAngle, arcSegment.IsLargeArc, arcSegment.SweepDirection, true, false); break; case PathPointKind.Line: streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -1), false, false); streamGeometryContext.LineTo(this.GetPoint(pathFigureEditor, 0), true, false); break; case PathPointKind.Quadratic: streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -2), false, false); streamGeometryContext.QuadraticBezierTo(this.GetPoint(pathFigureEditor, -1), this.GetPoint(pathFigureEditor, 0), true, false); break; case PathPointKind.Cubic: streamGeometryContext.BeginFigure(this.GetPoint(pathFigureEditor, -3), false, false); streamGeometryContext.BezierTo(this.GetPoint(pathFigureEditor, -2), this.GetPoint(pathFigureEditor, -1), this.GetPoint(pathFigureEditor, 0), true, false); break; case PathPointKind.BezierHandle: throw new InvalidOperationException(ExceptionStringTable.PathSegmentAdornerLastPointIsBezier); default: throw new NotImplementedException(ExceptionStringTable.PathSegmentAdornerUnknownPathPoint); } streamGeometryContext.Close(); MatrixTransform matrixTransform = new MatrixTransform(matrix); matrixTransform.Freeze(); streamGeometry.Transform = (Transform)matrixTransform; streamGeometry.Freeze(); Pen pen = this.IsActive ? this.ThickPathSegmentPen : this.ThinPathSegmentPen; ctx.DrawGeometry((Brush)null, pen, (System.Windows.Media.Geometry)streamGeometry); ctx.DrawGeometry((Brush)null, PathSegmentAdorner.HitTestPen, (System.Windows.Media.Geometry)streamGeometry); }
static LayoutAdorner() { StreamGeometry streamGeometry = new StreamGeometry(); StreamGeometryContext streamGeometryContext = streamGeometry.Open(); streamGeometryContext.BeginFigure(new Point(0.0, 4.5), true, true); streamGeometryContext.LineTo(new Point(3.0, -3.0), true, false); streamGeometryContext.LineTo(new Point(-3.0, -3.0), true, false); streamGeometryContext.Close(); LayoutAdorner.TriangleGeometry = (System.Windows.Media.Geometry)streamGeometry; LayoutAdorner.TriangleGeometry.Freeze(); }
private void Window_Loaded(object sender, RoutedEventArgs e) { Path pathArc = new Path(); PathGeometry pathGeometry = new PathGeometry(); ArcSegment arc = new ArcSegment(new Point(0, 50), new Size(50, 50), 0, false, SweepDirection.Clockwise, true); PathFigure figureArc = new PathFigure(); figureArc.StartPoint = new Point(50, 0); figureArc.Segments.Add(arc); LineSegment line1 = new LineSegment(new Point(50, 0), true); LineSegment line2 = new LineSegment(new Point(0, 50), true); PathFigure figureLine = new PathFigure(); figureLine.StartPoint = new Point(50, 50); figureLine.Segments.Add(line1); figureLine.Segments.Add(line2); pathGeometry.Figures.Add(figureArc); pathGeometry.Figures.Add(figureLine); pathArc.Data = pathGeometry; pathArc.Fill = new SolidColorBrush(Colors.LightGray); this.canvas.Children.Add(pathArc); Path pathLine1 = new Path(); StreamGeometry streamGeomety1 = new StreamGeometry(); StreamGeometryContext sgc1 = streamGeomety1.Open(); sgc1.BeginFigure(new Point(0, 50), true, true); sgc1.LineTo(new Point(50, 50), true, true); sgc1.LineTo(new Point(0, 200), true, true); sgc1.Close(); pathLine1.Data = streamGeomety1; pathLine1.Fill = new SolidColorBrush(Colors.LightGray); this.canvas.Children.Add(pathLine1); Path pathLine2 = new Path(); StreamGeometry streamGeomety2 = new StreamGeometry(); StreamGeometryContext sgc2 = streamGeomety2.Open(); sgc2.BeginFigure(new Point(50, 0), true, true); sgc2.LineTo(new Point(50, 50), true, true); sgc2.LineTo(new Point(200, 0), true, true); sgc2.Close(); pathLine2.Data = streamGeomety2; pathLine2.Fill = new SolidColorBrush(Colors.LightGray); this.canvas.Children.Add(pathLine2); }
public void ValidateGeometry(Rect renderRect, CornerRadius cornerRadius) { if (this.geometry != null) { return; } this.geometry = new StreamGeometry(); StreamGeometryContext ctx = this.geometry.Open(); SuperRoundedRectRenderer.GenerateGeometry(ctx, renderRect, new SuperRoundedRectRenderer.Radii(cornerRadius, SuperRoundedRectRenderer.zeroThickness, false)); ctx.Close(); this.geometry.Freeze(); }
public static Geometry SingleBondGeometry(Point startPoint, Point endPoint) { StreamGeometry sg = new StreamGeometry(); using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(startPoint, false, false); sgc.LineTo(endPoint, true, false); sgc.Close(); } sg.Freeze(); return(sg); }
/// <summary> /// /// </summary> /// <param name="arrangeBounds"></param> /// <returns></returns> 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; }
private void updateWaveFormPlayHead(double time) { long byteOffset = m_pcmFormat.GetByteForTime(new Time(time)); double pixels = byteOffset / m_bytesPerPixel; StreamGeometry geometry = null; if (WaveFormPlayHeadPath.Data == null) { geometry = new StreamGeometry(); } else { geometry = (StreamGeometry)WaveFormPlayHeadPath.Data; } using (StreamGeometryContext sgc = geometry.Open()) { sgc.BeginFigure(new Point(pixels, WaveFormCanvas.ActualHeight - 5), true, false); sgc.LineTo(new Point(pixels, 5), true, false); sgc.LineTo(new Point(pixels + 5, 5 + 5), true, false); sgc.LineTo(new Point(pixels, 5 + 5 + 5), true, false); sgc.Close(); } if (WaveFormPlayHeadPath.Data == null) { WaveFormPlayHeadPath.Data = geometry; } else { double left = WaveFormScroll.HorizontalOffset; double right = left + WaveFormScroll.ActualWidth; //bool b = WaveFormPlayHeadPath.IsVisible; if (pixels < left || pixels > right) { //WaveFormPlayHeadPath.BringIntoView(); double offset = pixels - 10; if (offset < 0) { offset = 0; } WaveFormScroll.ScrollToHorizontalOffset(offset); } else { WaveFormPlayHeadPath.InvalidateVisual(); } } }
/// <summary> /// 绘制坐标系 /// </summary> /// <param name="context"></param> /// <param name="coordinate"></param> private void DrawCoordinateSystem(StreamGeometryContext context, CoordinateSystem coordinate) { //画X轴 context.BeginFigure(coordinate.CenterPoint, true, false); context.LineTo(coordinate.XEndPoint, true, true); Point[] xPoints = new Point[3] { new Point(coordinate.XEndPoint.X - 10, coordinate.XEndPoint.Y - 10), new Point(coordinate.XEndPoint.X + 2, coordinate.XEndPoint.Y), new Point(coordinate.XEndPoint.X - 10, coordinate.XEndPoint.Y + 10) }; context.BeginFigure(xPoints[0], true, false); context.PolyLineTo(xPoints, true, true); //画Y轴 context.BeginFigure(coordinate.CenterPoint, true, false); context.LineTo(coordinate.YEndPoint, true, true); Point[] yPoints = new Point[3] { new Point(coordinate.YEndPoint.X - 10, coordinate.YEndPoint.Y + 10), new Point(coordinate.YEndPoint.X, coordinate.YEndPoint.Y), new Point(coordinate.YEndPoint.X + 10, coordinate.YEndPoint.Y + 10) }; context.BeginFigure(yPoints[0], true, false); context.PolyLineTo(yPoints, true, true); /***----画刻度----***/ //X方向 double XLength = coordinate.XEndPoint.X - coordinate.CenterPoint.X; XStaticValue = XLength / coordinate.XCoordinateTicks; double XTickInterval = (XLength - XStaticValue / 3) / coordinate.XCoordinateTicks; coordinate.XTickValue = XTickInterval; XTicks = new Point[coordinate.XCoordinateTicks]; for (int i = 0; i < XTicks.Length; i++) { XTicks[i] = new Point(coordinate.CenterPoint.X + (i + 1) * XTickInterval, coordinate.XEndPoint.Y); } DrawTicks(context, XTicks, 9.0, coordinate, "X"); //Y方向 double YLength = coordinate.CenterPoint.Y - coordinate.YEndPoint.Y; YStaticValue = YLength / coordinate.YCoordinateTicks; double YTickInterval = (YLength - YStaticValue / 3) / coordinate.YCoordinateTicks; coordinate.YTickValue = YTickInterval; YTicks = new Point[coordinate.YCoordinateTicks]; for (int i = 0; i < YTicks.Length; i++) { YTicks[i] = new Point(coordinate.CenterPoint.X, coordinate.CenterPoint.Y - (i + 1) * YTickInterval); } DrawTicks(context, YTicks, 9.0, coordinate, "Y"); context.Close(); }
/// <summary> /// 绘制图形 /// </summary> /// <param name="context"></param> /// <param name="arrowLine"></param> /// <remarks>返回Geometry类型</remarks> private void DrawArrowLine(StreamGeometryContext context, ArrowLine arrowLine) { Point startPoint = new Point(arrowLine.X1, arrowLine.Y1); context.BeginFigure(startPoint, true, false); Point endPoint = new Point(arrowLine.nX2, arrowLine.nY2); context.LineTo(endPoint, true, true); context.BeginFigure(arrowLine.ArrowPoints[0], true, false); context.PolyLineTo(arrowLine.ArrowPoints, true, true); context.Close(); }
/// <summary> /// Takes a list of points and builds a StreamGeometry object from it. /// Generally used for constructing masks /// </summary> /// <param name="hull"></param> /// <param name="isClosed"></param> /// <returns></returns> public static StreamGeometry BuildPolyPath(List <Point> hull, bool isClosed = true) { var points = hull.ToArray(); StreamGeometry geo = new StreamGeometry(); using (StreamGeometryContext c = geo.Open()) { c.BeginFigure(points[0], true, isClosed); c.PolyLineTo(points.Skip(1).ToArray(), true, true); c.Close(); } return(geo); }
//--------------------------------------------------------------------------------------------------------- /// <summary> /// Обновление данных дуги /// </summary> //--------------------------------------------------------------------------------------------------------- public override void Update() { using (StreamGeometryContext sgc = mGeometryArc.Open()) { sgc.BeginFigure(mStartPoint, mIsFilled, mIsClosed); sgc.ArcTo(mEndPoint, new Size(mRadiusX, mRadiusY), mRotationAngle, mIsLargeArc, mIsClockwiseDirection ? SweepDirection.Clockwise : SweepDirection.Counterclockwise, mIsStroked, true); sgc.Close(); } mBoundsRect = new Rect2Df(mGeometryArc.Bounds); }
/// <summary> /// Draws the adorner on top of the editor /// </summary> /// <param name="drawingContext"></param> protected override void OnRender(DrawingContext drawingContext) { base.OnRender(drawingContext); StreamGeometry sg = new StreamGeometry(); double orderValue; if (_targetedBond.OrderValue == null || _targetedBond.OrderValue < 1d) { orderValue = 1d; } else { orderValue = _targetedBond.OrderValue.Value; } double offset = Globals.BondOffsetPercentage * _targetedBond.BondLength * orderValue; //this tells us how much to rotate the brackets at the end of the bond double bondAngle = _targetedBond.Angle; Vector offsetVector1 = new Vector(offset, 0d); Matrix rotator = new Matrix(); rotator.Rotate(bondAngle); offsetVector1 = offsetVector1 * rotator; Vector twiddle = -offsetVector1.Perpendicular(); twiddle.Normalize(); twiddle *= 3.0; using (StreamGeometryContext sgc = sg.Open()) { sgc.BeginFigure(_targetedBond.StartAtom.Position + offsetVector1 + twiddle, false, false); sgc.LineTo(_targetedBond.StartAtom.Position + offsetVector1, true, true); sgc.LineTo(_targetedBond.StartAtom.Position - offsetVector1, true, true); sgc.LineTo(_targetedBond.StartAtom.Position - offsetVector1 + twiddle, true, true); sgc.BeginFigure(_targetedBond.EndAtom.Position + offsetVector1 - twiddle, false, false); sgc.LineTo(_targetedBond.EndAtom.Position + offsetVector1, true, true); sgc.LineTo(_targetedBond.EndAtom.Position - offsetVector1, true, true); sgc.LineTo(_targetedBond.EndAtom.Position - offsetVector1 - twiddle, true, true); sgc.Close(); } drawingContext.DrawGeometry(_solidColorBrush, _bracketPen, sg); }