public void DrawLineString(LineString lineString, LineStyle lineStyle, PointStyle vertexStyle, bool fast) { LineString viewLineString = (LineString)Viewport.GetViewGeometry(lineString); AM.PolylineGeometry geometry = new AM.PolylineGeometry( viewLineString.Coordinates.Select(c => new A.Point(c.X, c.Y)), false); m_Context.DrawGeometry(null, GetPen(lineStyle), geometry); DrawCoordinates(viewLineString.Coordinates, vertexStyle, fast); }
private static void DrawEllipseInternal(AM.DrawingContext dc, AM.IBrush brush, AM.Pen pen, bool isStroked, bool isFilled, ref Rect2 rect) { if (!isFilled && !isStroked) { return; } var r = new A.Rect(rect.X, rect.Y, rect.Width, rect.Height); var g = new AM.EllipseGeometry(r); dc.DrawGeometry( isFilled ? brush : null, isStroked ? pen : null, g); }
public void TransformLine(TextView textView, DrawingContext drawingContext, VisualLine line) { if (markers == null) { return; } var markersInLine = markers.FindOverlappingSegments(line); foreach (var marker in markersInLine) { if (marker.EndOffset < textView.TextDocument.TextLength) { foreach (var r in VisualLineGeometryBuilder.GetRectsForSegment(textView, marker)) { var startPoint = r.BottomLeft; var endPoint = r.BottomRight; var usedPen = new Pen(new SolidColorBrush(marker.MarkerColor), 1); const double offset = 2.5; var count = Math.Max((int) ((endPoint.X - startPoint.X)/offset) + 1, 4); var geometry = new StreamGeometry(); using (var ctx = geometry.Open()) { ctx.BeginFigure(startPoint, false); foreach (var point in CreatePoints(startPoint, endPoint, offset, count)) { ctx.LineTo(point); } ctx.EndFigure(false); } drawingContext.DrawGeometry(Brushes.Transparent, usedPen, geometry); break; } } } }
private static void DrawLineCurveInternal(AM.DrawingContext _dc, AM.Pen pen, bool isStroked, ref A.Point pt1, ref A.Point pt2, double curvature, CurveOrientation orientation, PointAlignment pt1a, PointAlignment pt2a) { if (isStroked) { var sg = new AM.StreamGeometry(); using (var sgc = sg.Open()) { sgc.BeginFigure(new A.Point(pt1.X, pt1.Y), false); double p1x = pt1.X; double p1y = pt1.Y; double p2x = pt2.X; double p2y = pt2.Y; LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt1a, pt2a, ref p1x, ref p1y, ref p2x, ref p2y); sgc.CubicBezierTo( new A.Point(p1x, p1y), new A.Point(p2x, p2y), new A.Point(pt2.X, pt2.Y)); sgc.EndFigure(false); } _dc.DrawGeometry(null, pen, sg); } }
private void Draw(AM.DrawingContext context, DrawCommand command, Stack <Stack <IDisposable> > pushedStates) { switch (command) { case GeometryClipDrawCommand geometryClipDrawCommand: { var geometryPushedState = context.PushGeometryClip(geometryClipDrawCommand.Clip); var currentPushedStates = pushedStates.Peek(); currentPushedStates.Push(geometryPushedState); } break; case ClipDrawCommand clipDrawCommand: { var clipPushedState = context.PushClip(clipDrawCommand.Clip); var currentPushedStates = pushedStates.Peek(); currentPushedStates.Push(clipPushedState); } break; case SaveDrawCommand _: { pushedStates.Push(new Stack <IDisposable>()); } break; case RestoreDrawCommand _: { var currentPushedStates = pushedStates.Pop(); while (currentPushedStates.Count > 0) { var pushedState = currentPushedStates.Pop(); pushedState.Dispose(); } } break; case SetTransformDrawCommand setTransformDrawCommand: { var transformPreTransform = context.PushSetTransform(setTransformDrawCommand.Matrix); var currentPushedStates = pushedStates.Peek(); currentPushedStates.Push(transformPreTransform); } break; case SaveLayerDrawCommand saveLayerDrawCommand: { pushedStates.Push(new Stack <IDisposable>()); } break; case ImageDrawCommand imageDrawCommand: { context.DrawImage( imageDrawCommand.Source, imageDrawCommand.SourceRect, imageDrawCommand.DestRect, imageDrawCommand.BitmapInterpolationMode); } break; case GeometryDrawCommand geometryDrawCommand: { context.DrawGeometry( geometryDrawCommand.Brush, geometryDrawCommand.Pen, geometryDrawCommand.Geometry); } break; case LineDrawCommand lineDrawCommand: { context.DrawLine( lineDrawCommand.Pen, lineDrawCommand.P1, lineDrawCommand.P2); } break; case RectangleDrawCommand rectangleDrawCommand: { context.DrawRectangle( rectangleDrawCommand.Brush, rectangleDrawCommand.Pen, rectangleDrawCommand.Rect, rectangleDrawCommand.RadiusX, rectangleDrawCommand.RadiusY); } break; case TextDrawCommand textDrawCommand: { context.DrawText( textDrawCommand.Brush, textDrawCommand.Origin, textDrawCommand.FormattedText); } break; } }
private void DrawSpiroShape(DrawingContext dc, SpiroShape shape, bool isSelected) { string data; var result = SpiroEditor.Data.TryGetValue(shape, out data); if (result && !string.IsNullOrEmpty(data)) { var geometry = StreamGeometry.Parse(data); if (isSelected) { var cache = FromCache(_hitGeometryStyle); dc.DrawGeometry( shape.IsFilled ? cache.FillBrush : null, shape.IsStroked ? cache.StrokePen : null, geometry); } else { var cache = FromCache(_geometryStyle); dc.DrawGeometry( shape.IsFilled ? cache.FillBrush : null, shape.IsStroked ? cache.StrokePen : null, geometry); } } }
private void DrawSpiroPoint(DrawingContext dc, IBrush brush, Pen pen, SpiroControlPoint point) { switch (point.Type) { case SpiroPointType.Corner: dc.FillRectangle(brush, new Rect(point.X - 3.5, point.Y - 3.5, 7, 7)); break; case SpiroPointType.G4: case SpiroPointType.G2: case SpiroPointType.Left: case SpiroPointType.Right: case SpiroPointType.End: case SpiroPointType.OpenContour: case SpiroPointType.EndOpenContour: var tm = Translate(point.X, point.Y); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, EndKnot); tt.Dispose(); break; } }
private void DrawSpiroKnot(DrawingContext dc, IBrush brush, Pen pen, SpiroKnot knot) { switch (knot.Type) { case SpiroPointType.Corner: dc.FillRectangle(brush, new Rect(knot.X - 3.5, knot.Y - 3.5, 7, 7)); break; case SpiroPointType.G4: FillEllipse(dc, brush, new GuidePoint(knot.X, knot.Y), 3.5, 3.5); break; case SpiroPointType.G2: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var rt = dc.PushPreTransform(rm); dc.FillRectangle(brush, new Rect(knot.X - 1.5, knot.Y - 3.5, 3, 7)); rt.Dispose(); } break; case SpiroPointType.Left: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(brush, null, LeftKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.Right: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(brush, null, RightKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.End: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, EndKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.OpenContour: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, OpenContourKnot); tt.Dispose(); rt.Dispose(); } break; case SpiroPointType.EndOpenContour: { var rm = Rotation(ToRadians(knot.Theta), new Vector(knot.X, knot.Y)); var tm = Translate(knot.X, knot.Y); var rt = dc.PushPreTransform(rm); var tt = dc.PushPreTransform(tm); dc.DrawGeometry(null, pen, EndOpenContourKnot); tt.Dispose(); rt.Dispose(); } break; } }
private static void FillEllipse(DrawingContext dc, IBrush brush, GuidePoint point, double radiusX, double radiusY) { var g = new EllipseGeometry(new Rect(point.X - radiusX, point.Y - radiusY, 2.0 * radiusX, 2.0 * radiusY)); dc.DrawGeometry(brush, null, g); }
protected internal override void OnRender(DrawingContext drawingContext) { Pen pen = (this.Stroke != null) ? new Pen(this.Stroke, this.StrokeThickness) : null; Rect shapeBounds = this.RenderedGeometry.GetRenderBounds(pen); Matrix matrix = Matrix.Identity; if (this.Stretch != Stretch.None) { double scaleX = this.ActualWidth / shapeBounds.Width; double scaleY = this.ActualHeight / shapeBounds.Height; switch (this.Stretch) { case Stretch.Uniform: scaleX = scaleY = Math.Min(scaleX, scaleY); break; case Stretch.UniformToFill: // Hmm, in WPF appears to be the same as Uniform. This can't be right... scaleX = scaleY = Math.Min(scaleX, scaleY); break; } matrix.Translate(-shapeBounds.X, -shapeBounds.Y); matrix.Scale(scaleX, scaleY); matrix.Translate( (this.ActualWidth - (shapeBounds.Width * scaleX)) / 2, (this.ActualHeight - (shapeBounds.Height * scaleY)) / 2); } drawingContext.DrawGeometry(this.Fill, pen, this.RenderedGeometry, matrix); }