public static AM.Geometry ToGeometry(EllipseShapeViewModel ellipse) { var rect2 = Rect2.FromPoints(ellipse.TopLeft.X, ellipse.TopLeft.Y, ellipse.BottomRight.X, ellipse.BottomRight.Y); var rect = new A.Rect(rect2.X, rect2.Y, rect2.Width, rect2.Height); var g = new AM.EllipseGeometry(rect); return(g); }
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); }
private static void Record(CanvasCommand canvasCommand, AvaloniaPicture avaloniaPicture) { if (avaloniaPicture == null || avaloniaPicture._commands == null) { return; } switch (canvasCommand) { case ClipPathCanvasCommand clipPathCanvasCommand: { var path = clipPathCanvasCommand.ClipPath.ToGeometry(false); if (path != null) { // TODO: clipPathCanvasCommand.Operation; // TODO: clipPathCanvasCommand.Antialias; avaloniaPicture._commands.Add(new GeometryClipDrawCommand(path)); } } break; case ClipRectCanvasCommand clipRectCanvasCommand: { var rect = clipRectCanvasCommand.Rect.ToSKRect(); // TODO: clipRectCanvasCommand.Operation; // TODO: clipRectCanvasCommand.Antialias; avaloniaPicture._commands.Add(new ClipDrawCommand(rect)); } break; case SaveCanvasCommand _: { // TODO: avaloniaPicture._commands.Add(new SaveDrawCommand()); } break; case RestoreCanvasCommand _: { // TODO: avaloniaPicture._commands.Add(new RestoreDrawCommand()); } break; case SetMatrixCanvasCommand setMatrixCanvasCommand: { var matrix = setMatrixCanvasCommand.Matrix.ToMatrix(); avaloniaPicture._commands.Add(new SetTransformDrawCommand(matrix)); } break; case SaveLayerCanvasCommand saveLayerCanvasCommand: { // TODO: avaloniaPicture._commands.Add(new SaveLayerDrawCommand()); } break; case DrawImageCanvasCommand drawImageCanvasCommand: { if (drawImageCanvasCommand.Image != null) { var image = drawImageCanvasCommand.Image.ToBitmap(); if (image != null) { var source = drawImageCanvasCommand.Source.ToSKRect(); var dest = drawImageCanvasCommand.Dest.ToSKRect(); var bitmapInterpolationMode = drawImageCanvasCommand.Paint?.FilterQuality.ToBitmapInterpolationMode() ?? AVMI.BitmapInterpolationMode.Default; avaloniaPicture._commands.Add(new ImageDrawCommand(image, source, dest, bitmapInterpolationMode)); } } } break; case DrawPathCanvasCommand drawPathCanvasCommand: { if (drawPathCanvasCommand.Path != null && drawPathCanvasCommand.Paint != null) { (var brush, var pen) = drawPathCanvasCommand.Paint.ToBrushAndPen(); if (drawPathCanvasCommand.Path.Commands?.Count == 1) { var pathCommand = drawPathCanvasCommand.Path.Commands[0]; var success = false; switch (pathCommand) { case AddRectPathCommand addRectPathCommand: { var rect = addRectPathCommand.Rect.ToSKRect(); avaloniaPicture._commands.Add(new RectangleDrawCommand(brush, pen, rect, 0, 0)); success = true; } break; case AddRoundRectPathCommand addRoundRectPathCommand: { var rect = addRoundRectPathCommand.Rect.ToSKRect(); var rx = addRoundRectPathCommand.Rx; var ry = addRoundRectPathCommand.Ry; avaloniaPicture._commands.Add(new RectangleDrawCommand(brush, pen, rect, rx, ry)); success = true; } break; case AddOvalPathCommand addOvalPathCommand: { var rect = addOvalPathCommand.Rect.ToSKRect(); var ellipseGeometry = new AM.EllipseGeometry(rect); avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, ellipseGeometry)); success = true; } break; case AddCirclePathCommand addCirclePathCommand: { var x = addCirclePathCommand.X; var y = addCirclePathCommand.Y; var radius = addCirclePathCommand.Radius; var rect = new A.Rect(x - radius, y - radius, radius + radius, radius + radius); var ellipseGeometry = new AM.EllipseGeometry(rect); avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, ellipseGeometry)); success = true; } break; case AddPolyPathCommand addPolyPathCommand: { if (addPolyPathCommand.Points != null) { var points = addPolyPathCommand.Points.ToPoints(); var close = addPolyPathCommand.Close; var polylineGeometry = new AM.PolylineGeometry(points, close); avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, polylineGeometry)); success = true; } } break; } if (success) { break; } } if (drawPathCanvasCommand.Path.Commands?.Count == 2) { var pathCommand1 = drawPathCanvasCommand.Path.Commands[0]; var pathCommand2 = drawPathCanvasCommand.Path.Commands[1]; if (pathCommand1 is MoveToPathCommand moveTo && pathCommand2 is LineToPathCommand lineTo) { var p1 = new A.Point(moveTo.X, moveTo.Y); var p2 = new A.Point(lineTo.X, lineTo.Y); avaloniaPicture._commands.Add(new LineDrawCommand(pen, p1, p2)); break; } } var geometry = drawPathCanvasCommand.Path.ToGeometry(brush != null); if (geometry != null) { avaloniaPicture._commands.Add(new GeometryDrawCommand(brush, pen, geometry)); } } } break; case DrawTextBlobCanvasCommand drawPositionedTextCanvasCommand: { // TODO: } break; case DrawTextCanvasCommand drawTextCanvasCommand: { if (drawTextCanvasCommand.Paint != null) { (var brush, _) = drawTextCanvasCommand.Paint.ToBrushAndPen(); var text = drawTextCanvasCommand.Paint.ToFormattedText(drawTextCanvasCommand.Text); var x = drawTextCanvasCommand.X; var y = drawTextCanvasCommand.Y; var origin = new A.Point(x, y - drawTextCanvasCommand.Paint.TextSize); avaloniaPicture._commands.Add(new TextDrawCommand(brush, origin, text)); } } break; case DrawTextOnPathCanvasCommand drawTextOnPathCanvasCommand: { // TODO: } break; default: 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); }
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); }