Пример #1
0
#pragma warning restore CS0618

        private void MainImage_PointerMoved(object sender, PointerEventArgs e)
        {
            // allow to move cursor out leaving selection/hignlighting unchanged
            if (IgnorePointerMove(e))
            {
                return;
            }

            PointerPoint p = e.GetCurrentPoint(_mainImageControl);

            _pointerPos = p.Position;
            //
            if (p.Properties.IsMiddleButtonPressed)
            {
                TD.Point delta = ToPoint(_pointerPosDrag - _pointerPos);
                _pointerPosDrag = _pointerPos;
                _viewport.MoveOrigin(delta);
                UpdateDrawerBounds();
                MarkPresetChanged();
                InvalidateView(false); // viewport moved only
            }
            else
            {
                TD.Point u = _viewport.ToUser(ToPoint(_pointerPos));
                _gridDrawer.SetCursor(u.X, u.Y);
                var mode = e.KeyModifiers.HasFlag(KeyModifiers.Alt)
                    ? GridDrawer.CursorHighlightMode.Cents
                    : GridDrawer.CursorHighlightMode.NearestRational;
                _gridDrawer.SetCursorHighlightMode(mode);
                InvalidateView();
            }
        }
Пример #2
0
        private void UpdateMarkers()
        {
            double x1 = Line.Start.X;
            double y1 = Line.Start.Y;
            double x2 = Line.End.X;
            double y2 = Line.End.Y;

            if (Style.Stroke.StartArrow.ArrowType != ArrowType.None)
            {
                double a1 = Math.Atan2(y1 - y2, x1 - x2);
                StartMarker = CreatArrowMarker(x1, y1, a1, Style, Style.Stroke.StartArrow);
                StartMarker.UpdateStyle();
                P0 = (StartMarker as MarkerBase).Point;
            }
            else
            {
                StartMarker = null;
                P0          = new A.Point(x1, y1);
            }

            if (Style.Stroke.EndArrow.ArrowType != ArrowType.None)
            {
                double a2 = Math.Atan2(y2 - y1, x2 - x1);
                EndMarker = CreatArrowMarker(x2, y2, a2, Style, Style.Stroke.EndArrow);
                EndMarker.UpdateStyle();
                P1 = (EndMarker as MarkerBase).Point;
            }
            else
            {
                EndMarker = null;
                P1        = new A.Point(x2, y2);
            }
        }
Пример #3
0
 /// <summary>
 /// Convert from WPF point to core point.
 /// </summary>
 public static Point[] Convert(RPoint[] points)
 {
     Point[] myPoints = new Point[points.Length];
     for (int i = 0; i < points.Length; i++)
         myPoints[i] = Convert(points[i]);
     return myPoints;
 }
Пример #4
0
        private void SetColor(Point mousePosition)
        {
            var centerPoint = new Point(Bounds.Width / 2, Bounds.Height / 2);

            var radius = (Bounds.Height - _cursorEllipse.Height) / 2;

            var dx = Math.Abs(mousePosition.X - centerPoint.X);
            var dy = Math.Abs(mousePosition.Y - centerPoint.Y);

            var angle      = Math.Atan(dy / dx) / Math.PI * 180;
            var distance   = Math.Pow(Math.Pow(dx, 2) + Math.Pow(dy, 2), 0.5);
            var saturation = distance / radius;

            if (mousePosition.X < centerPoint.X)
            {
                angle = 180 - angle;
            }

            if (mousePosition.Y > centerPoint.Y)
            {
                angle = 360 - angle;
            }

            _colorManager.SetColorFromHsl(angle, saturation, 0.5);
        }
Пример #5
0
        private void DrawGridInternal(AM.DrawingContext dc, AM.Pen stroke, ref Rect2 rect, double offsetX, double offsetY, double cellWidth, double cellHeight, bool isStroked)
        {
            double ox = rect.X;
            double oy = rect.Y;
            double sx = ox + offsetX;
            double sy = oy + offsetY;
            double ex = ox + rect.Width;
            double ey = oy + rect.Height;

            for (double x = sx; x < ex; x += cellWidth)
            {
                var p0 = new A.Point(
                    _scaleToPage(x),
                    _scaleToPage(oy));
                var p1 = new A.Point(
                    _scaleToPage(x),
                    _scaleToPage(ey));
                DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1);
            }

            for (double y = sy; y < ey; y += cellHeight)
            {
                var p0 = new A.Point(
                    _scaleToPage(ox),
                    _scaleToPage(y));
                var p1 = new A.Point(
                    _scaleToPage(ex),
                    _scaleToPage(y));
                DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1);
            }
        }
Пример #6
0
        Avalonia.Point ScreenPointToDominoCoordinates(Avalonia.Point p)
        {
            var tempx = p.X / Zoom + ShiftX;
            var tempy = p.Y / Zoom + ShiftY;

            return(new Avalonia.Point(tempx, tempy));
        }
Пример #7
0
 public override void UpdateGeometry()
 {
     ScaleThickness = Line.State.HasFlag(ShapeStateFlags.Thickness);
     ScaleSize      = Line.State.HasFlag(ShapeStateFlags.Size);
     P0             = new A.Point(Line.Start.X, Line.Start.Y);
     P1             = new A.Point(Line.End.X, Line.End.Y);
     Center         = new A.Point((P0.X + P1.X) / 2.0, (P0.Y + P1.Y) / 2.0);
     UpdateMarkers();
 }
Пример #8
0
    private void UpdateMarkers()
    {
        if (Line.Start is null || Line.End is null)
        {
            StartMarker = null;
            P0          = new A.Point();

            EndMarker = null;
            P1        = new A.Point();
        }
Пример #9
0
        public static A.Point[] ToPoints(this IList <Point> points)
        {
            var skPoints = new A.Point[points.Count];

            for (int i = 0; i < points.Count; i++)
            {
                skPoints[i] = points[i].ToPoint();
            }

            return(skPoints);
        }
Пример #10
0
        public static A.Point[] ToPoints(this IList <global::Svg.Model.Primitives.Point> points)
        {
            var skPoints = new A.Point[points.Count];

            for (int i = 0; i < points.Count; i++)
            {
                skPoints[i] = points[i].ToPoint();
            }

            return(skPoints);
        }
Пример #11
0
        private void MainImage_PointerPressed(object sender, PointerPressedEventArgs e)
        {
            PointerPoint p = e.GetCurrentPoint(_mainImageControl);

            if (_pointerPos != p.Position)
            {
                return;
            }
            // _gridDrawer.SetCursor already called from OnMouseMove

            if (p.Properties.IsLeftButtonPressed)
            {
                // Get tempered note
                SomeInterval t = null;
                if (e.KeyModifiers.HasFlag(KeyModifiers.Alt))   // by cents
                {
                    float c = _gridDrawer.GetCursorCents();
                    t = new SomeInterval {
                        cents = c
                    };
                }
                else     // nearest rational
                {
                    _gridDrawer.UpdateCursorItem();
                    Rational r = _gridDrawer.GetCursorRational();
                    if (!r.IsDefault())
                    {
                        t = new SomeInterval {
                            rational = r
                        };
                    }
                }
                if (t != null)
                {
                    // Toggle selection
                    if (e.KeyModifiers.HasFlag(KeyModifiers.Control))
                    {
                        ToggleSelection(t);
                        //!!! invalidate image
                    }
                    // Play note
                    else
                    {
                        PlayNote(t);
                    }
                }
            }
            else if (p.Properties.IsMiddleButtonPressed)
            {
                _pointerPosDrag = _pointerPos;
            }
        }
Пример #12
0
        protected void RectangleBoundOnPointerMoved(object?sender, PointerEventArgs e)
        {
            Rect rect = RectangleBoundWindow.Bounds;

            PRectangleBoundClick = e.GetCurrentPoint(RectangleBoundWindow).Position;

            if (PRectangleBoundClick.Y < rect.Height - (RectangleBoundWindow.StrokeThickness + 3) &&
                PRectangleBoundClick.X <= RectangleBoundWindow.StrokeThickness)
            {
                if (!IsCursorCapture)
                {
                    Cursor = new Cursor(StandardCursorType.LeftSide);
                }
            }
            else if (PRectangleBoundClick.X >= rect.Width - RectangleBoundWindow.StrokeThickness &&
                     PRectangleBoundClick.Y < rect.Height - (RectangleBoundWindow.StrokeThickness + 3))
            {
                if (!IsCursorCapture)
                {
                    Cursor = new Cursor(StandardCursorType.RightSide);
                }
            }
            else if (PRectangleBoundClick.Y >= rect.Height - RectangleBoundWindow.StrokeThickness &&
                     PRectangleBoundClick.X > RectangleBoundWindow.StrokeThickness + 3 &&
                     PRectangleBoundClick.X < rect.Width - (RectangleBoundWindow.StrokeThickness + 3))
            {
                if (!IsCursorCapture)
                {
                    Cursor = new Cursor(StandardCursorType.BottomSide);
                }
            }
            else if (PRectangleBoundClick.X <= RectangleBoundWindow.StrokeThickness &&
                     PRectangleBoundClick.Y >= rect.Height - (RectangleBoundWindow.StrokeThickness + 3))
            {
                if (!IsCursorCapture)
                {
                    Cursor = new Cursor(StandardCursorType.BottomLeftCorner);
                }
            }
            else if (PRectangleBoundClick.X >= rect.Width - (RectangleBoundWindow.StrokeThickness + 3) &&
                     PRectangleBoundClick.Y >= rect.Height - (RectangleBoundWindow.StrokeThickness + 3))
            {
                if (!IsCursorCapture)
                {
                    Cursor = new Cursor(StandardCursorType.BottomRightCorner);
                }
            }
        }
Пример #13
0
        protected void RectangleBoundOnPointerPressed(object?sender, PointerPressedEventArgs e)
        {
            Rect rect = RectangleBoundWindow.Bounds;

            PPRectangleBoundClick             = e.GetCurrentPoint(null);
            PRectangleBoundClick              = PPRectangleBoundClick.Position;
            PointerPointRectangleBoundWindowX = PPRectangleBoundClick.Position.X;
            PointerPointRectangleBoundWindowY = PPRectangleBoundClick.Position.Y;
            RectangleBoundWindowWidth         = Position.Y;

            if (PRectangleBoundClick.Y < rect.Height - (RectangleBoundWindow.StrokeThickness + 3) &&
                PRectangleBoundClick.X <= RectangleBoundWindow.StrokeThickness)
            {
                IsCursorCapture = true;
                IsLeftClickRectangleBoundWindow = true;
            }
            else if (PRectangleBoundClick.X >= rect.Width - RectangleBoundWindow.StrokeThickness &&
                     PRectangleBoundClick.Y < rect.Height - (RectangleBoundWindow.StrokeThickness + 3))
            {
                IsCursorCapture = true;
                IsRightClickRectangleBoundWindow = true;
            }
            else if (PRectangleBoundClick.Y >= rect.Height - RectangleBoundWindow.StrokeThickness &&
                     PRectangleBoundClick.X > RectangleBoundWindow.StrokeThickness + 3 &&
                     PRectangleBoundClick.X < rect.Width - (RectangleBoundWindow.StrokeThickness + 3))
            {
                IsCursorCapture = true;
                IsBottomClickRectangleBoundWindow = true;
            }
            else if (PRectangleBoundClick.X <= RectangleBoundWindow.StrokeThickness &&
                     PRectangleBoundClick.Y >= rect.Height - (RectangleBoundWindow.StrokeThickness + 3))
            {
                IsCursorCapture = true;
                IsBottomLeftClickRectangleBoundWindow = true;
            }
            else if (PRectangleBoundClick.X >= rect.Width - (RectangleBoundWindow.StrokeThickness + 3) &&
                     PRectangleBoundClick.Y >= rect.Height - (RectangleBoundWindow.StrokeThickness + 3))
            {
                IsCursorCapture = true;
                IsBottomRightClickRectangleBoundWindow = true;
            }
        }
Пример #14
0
        private AM.StreamGeometry CreateCurveGeometry(A.Point p0, A.Point p1, double curvature, CurveOrientation orientation, PointAlignment pt0a, PointAlignment pt1a)
        {
            var curveGeometry = new AM.StreamGeometry();

            using (var geometryContext = curveGeometry.Open())
            {
                geometryContext.BeginFigure(new A.Point(p0.X, p0.Y), false);
                double p0x = p0.X;
                double p0y = p0.Y;
                double p1x = p1.X;
                double p1y = p1.Y;
                LineShapeExtensions.GetCurvedLineBezierControlPoints(orientation, curvature, pt0a, pt1a, ref p0x, ref p0y, ref p1x, ref p1y);
                var point1 = new A.Point(p0x, p0y);
                var point2 = new A.Point(p1x, p1y);
                var point3 = new A.Point(p1.X, p1.Y);
                geometryContext.CubicBezierTo(point1, point2, point3);
                geometryContext.EndFigure(false);
            }

            return(curveGeometry);
        }
Пример #15
0
        public override void OnDraw(object dc, double zoom)
        {
            var context = dc as AM.DrawingContext;

            if (Grid.GridStrokeColor != null)
            {
                if (Grid.IsGridEnabled)
                {
                    double ox = Rect.X;
                    double ex = Rect.X + Rect.Width;
                    double oy = Rect.Y;
                    double ey = Rect.Y + Rect.Height;
                    double cw = Grid.GridCellWidth;
                    double ch = Grid.GridCellHeight;

                    for (double x = ox + cw; x < ex; x += cw)
                    {
                        var p0 = new A.Point(x, oy);
                        var p1 = new A.Point(x, ey);
                        context.DrawLine(Stroke, p0, p1);
                    }

                    for (double y = oy + ch; y < ey; y += ch)
                    {
                        var p0 = new A.Point(ox, y);
                        var p1 = new A.Point(ex, y);
                        context.DrawLine(Stroke, p0, p1);
                    }
                }

                if (Grid.IsBorderEnabled)
                {
                    context.DrawRectangle(Stroke, Rect);
                }
            }
        }
Пример #16
0
        private static A.Point DrawLineArrowInternal(AM.DrawingContext dc, AM.Pen pen, AM.IBrush brush, float x, float y, double angle, ArrowStyle style)
        {
            A.Point pt = default(A.Point);
            var     rt = APAZ.MatrixHelper.Rotation(angle, new A.Vector(x, y));
            double  rx = style.RadiusX;
            double  ry = style.RadiusY;
            double  sx = 2.0 * rx;
            double  sy = 2.0 * ry;

            switch (style.ArrowType)
            {
            default:
            case ArrowType.None:
            {
                pt = new A.Point(x, y);
            }
            break;

            case ArrowType.Rectangle:
            {
                pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y));
                var rect = new Rect2(x - sx, y - ry, sx, sy);
                using (var d = dc.PushPreTransform(rt))
                {
                    DrawRectangleInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                }
            }
            break;

            case ArrowType.Ellipse:
            {
                pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y));
                using (var d = dc.PushPreTransform(rt))
                {
                    var rect = new Rect2(x - sx, y - ry, sx, sy);
                    DrawEllipseInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                }
            }
            break;

            case ArrowType.Arrow:
            {
                var pts = new A.Point[]
                {
                    new A.Point(x, y),
                    new A.Point(x - (float)sx, y + (float)sy),
                    new A.Point(x, y),
                    new A.Point(x - (float)sx, y - (float)sy),
                    new A.Point(x, y)
                };
                pt = APAZ.MatrixHelper.TransformPoint(rt, pts[0]);
                var p11 = APAZ.MatrixHelper.TransformPoint(rt, pts[1]);
                var p21 = APAZ.MatrixHelper.TransformPoint(rt, pts[2]);
                var p12 = APAZ.MatrixHelper.TransformPoint(rt, pts[3]);
                var p22 = APAZ.MatrixHelper.TransformPoint(rt, pts[4]);
                DrawLineInternal(dc, pen, style.IsStroked, ref p11, ref p21);
                DrawLineInternal(dc, pen, style.IsStroked, ref p12, ref p22);
            }
            break;
            }

            return(pt);
        }
Пример #17
0
        private void DrawLineArrowsInternal(AM.DrawingContext dc, LineShape line, double dx, double dy, out A.Point pt1, out A.Point pt2)
        {
            AM.IBrush fillStartArrow   = ToBrush(line.Style.StartArrowStyle.Fill);
            AM.Pen    strokeStartArrow = ToPen(line.Style.StartArrowStyle, _scaleToPage);

            AM.IBrush fillEndArrow   = ToBrush(line.Style.EndArrowStyle.Fill);
            AM.Pen    strokeEndArrow = ToPen(line.Style.EndArrowStyle, _scaleToPage);

            double _x1 = line.Start.X + dx;
            double _y1 = line.Start.Y + dy;
            double _x2 = line.End.X + dx;
            double _y2 = line.End.Y + dy;

            line.GetMaxLength(ref _x1, ref _y1, ref _x2, ref _y2);

            float x1 = _scaleToPage(_x1);
            float y1 = _scaleToPage(_y1);
            float x2 = _scaleToPage(_x2);
            float y2 = _scaleToPage(_y2);

            var    sas = line.Style.StartArrowStyle;
            var    eas = line.Style.EndArrowStyle;
            double a1  = Math.Atan2(y1 - y2, x1 - x2);
            double a2  = Math.Atan2(y2 - y1, x2 - x1);

            // Draw start arrow.
            pt1 = DrawLineArrowInternal(dc, strokeStartArrow, fillStartArrow, x1, y1, a1, sas);

            // Draw end arrow.
            pt2 = DrawLineArrowInternal(dc, strokeEndArrow, fillEndArrow, x2, y2, a2, eas);
        }
Пример #18
0
 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);
     }
 }
Пример #19
0
 private static void DrawLineInternal(AM.DrawingContext dc, AM.Pen pen, bool isStroked, ref A.Point p0, ref A.Point p1)
 {
     if (isStroked)
     {
         dc.DrawLine(pen, p0, p1);
     }
 }
Пример #20
0
        public static AM.Geometry?ToGeometry(this Path path, bool isFilled)
        {
            if (path.Commands == null)
            {
                return(null);
            }

            var streamGeometry = new AM.StreamGeometry();

            using var streamGeometryContext = streamGeometry.Open();

            streamGeometryContext.SetFillRule(path.FillType.ToSKPathFillType());

            bool endFigure  = false;
            bool haveFigure = false;

            for (int i = 0; i < path.Commands.Count; i++)
            {
                var pathCommand = path.Commands[i];
                var isLast      = i == path.Commands.Count - 1;

                switch (pathCommand)
                {
                case MoveToPathCommand moveToPathCommand:
                {
                    if (endFigure == true && haveFigure == false)
                    {
                        return(null);
                    }
                    if (haveFigure == true)
                    {
                        streamGeometryContext.EndFigure(false);
                    }
                    if (isLast == true)
                    {
                        return(streamGeometry);
                    }
                    else
                    {
                        if (path.Commands[i + 1] is MoveToPathCommand)
                        {
                            return(streamGeometry);
                        }

                        if (path.Commands[i + 1] is ClosePathCommand)
                        {
                            return(streamGeometry);
                        }
                    }
                    endFigure  = true;
                    haveFigure = false;
                    var x     = moveToPathCommand.X;
                    var y     = moveToPathCommand.Y;
                    var point = new A.Point(x, y);
                    streamGeometryContext.BeginFigure(point, isFilled);         // TODO: isFilled
                }
                break;

                case LineToPathCommand lineToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x     = lineToPathCommand.X;
                    var y     = lineToPathCommand.Y;
                    var point = new A.Point(x, y);
                    streamGeometryContext.LineTo(point);
                }
                break;

                case ArcToPathCommand arcToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x             = arcToPathCommand.X;
                    var y             = arcToPathCommand.Y;
                    var point         = new A.Point(x, y);
                    var rx            = arcToPathCommand.Rx;
                    var ry            = arcToPathCommand.Ry;
                    var size          = new A.Size(rx, ry);
                    var rotationAngle = arcToPathCommand.XAxisRotate;
                    var isLargeArc    = arcToPathCommand.LargeArc == PathArcSize.Large;
                    var sweep         = arcToPathCommand.Sweep.ToSweepDirection();
                    streamGeometryContext.ArcTo(point, size, rotationAngle, isLargeArc, sweep);
                }
                break;

                case QuadToPathCommand quadToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x0       = quadToPathCommand.X0;
                    var y0       = quadToPathCommand.Y0;
                    var x1       = quadToPathCommand.X1;
                    var y1       = quadToPathCommand.Y1;
                    var control  = new A.Point(x0, y0);
                    var endPoint = new A.Point(x1, y1);
                    streamGeometryContext.QuadraticBezierTo(control, endPoint);
                }
                break;

                case CubicToPathCommand cubicToPathCommand:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    haveFigure = true;
                    var x0     = cubicToPathCommand.X0;
                    var y0     = cubicToPathCommand.Y0;
                    var x1     = cubicToPathCommand.X1;
                    var y1     = cubicToPathCommand.Y1;
                    var x2     = cubicToPathCommand.X2;
                    var y2     = cubicToPathCommand.Y2;
                    var point1 = new A.Point(x0, y0);
                    var point2 = new A.Point(x1, y1);
                    var point3 = new A.Point(x2, y2);
                    streamGeometryContext.CubicBezierTo(point1, point2, point3);
                }
                break;

                case ClosePathCommand _:
                {
                    if (endFigure == false)
                    {
                        return(null);
                    }
                    if (haveFigure == false)
                    {
                        return(null);
                    }
                    endFigure  = false;
                    haveFigure = false;
                    streamGeometryContext.EndFigure(true);
                }
                break;

                default:
                    break;
                }
            }

            if (endFigure)
            {
                if (haveFigure == false)
                {
                    return(null);
                }
                streamGeometryContext.EndFigure(false);
            }

            return(streamGeometry);
        }
Пример #21
0
        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;
            }
        }
Пример #22
0
 private Ava.Point GetPixelPosition(PointerEventArgs e)
 {
     Ava.Point pos             = e.GetPosition(this);
     Ava.Point dpiCorrectedPos = new Ava.Point(pos.X * backend.dpiScaleInput, pos.Y * backend.dpiScaleInput);
     return(dpiCorrectedPos);
 }
Пример #23
0
 public static Vector2 ToStride(this AvaloniaPoint point)
 {
     return(new((float)point.X, (float)point.Y));
 }
 /// <summary>
 /// Transforms a point by this matrix.
 /// </summary>
 /// <param name="matrix">The matrix to use as a transformation matrix.</param>
 /// <param name="point">>The original point to apply the transformation.</param>
 /// <returns>The result of the transformation for the input point.</returns>
 public static Point TransformPoint(Matrix matrix, Point point)
 {
     return new Point(
         (point.X * matrix.M11) + (point.Y * matrix.M21) + matrix.M31,
         (point.X * matrix.M12) + (point.Y * matrix.M22) + matrix.M32);
 }
Пример #25
0
 public bool HitTest(Avalonia.Point p) => true;
Пример #26
0
        private static A.Point DrawLineArrowInternal(AM.DrawingContext dc, AM.Pen pen, AM.IBrush brush, float x, float y, double angle, ArrowStyle style)
        {
            A.Point pt = default(A.Point);
            var rt = APAZ.MatrixHelper.Rotation(angle, new A.Vector(x, y));
            double rx = style.RadiusX;
            double ry = style.RadiusY;
            double sx = 2.0 * rx;
            double sy = 2.0 * ry;

            switch (style.ArrowType)
            {
                default:
                case ArrowType.None:
                    {
                        pt = new A.Point(x, y);
                    }
                    break;
                case ArrowType.Rectangle:
                    {
                        pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y));
                        var rect = new Rect2(x - sx, y - ry, sx, sy);
                        using (var d = dc.PushPreTransform(rt))
                        {
                            DrawRectangleInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                        }
                    }
                    break;
                case ArrowType.Ellipse:
                    {
                        pt = APAZ.MatrixHelper.TransformPoint(rt, new A.Point(x - (float)sx, y));
                        using (var d = dc.PushPreTransform(rt))
                        {
                            var rect = new Rect2(x - sx, y - ry, sx, sy);
                            DrawEllipseInternal(dc, brush, pen, style.IsStroked, style.IsFilled, ref rect);
                        }
                    }
                    break;
                case ArrowType.Arrow:
                    {
                        var pts = new A.Point[]
                        {
                            new A.Point(x, y),
                            new A.Point(x - (float)sx, y + (float)sy),
                            new A.Point(x, y),
                            new A.Point(x - (float)sx, y - (float)sy),
                            new A.Point(x, y)
                        };
                        pt = APAZ.MatrixHelper.TransformPoint(rt, pts[0]);
                        var p11 = APAZ.MatrixHelper.TransformPoint(rt, pts[1]);
                        var p21 = APAZ.MatrixHelper.TransformPoint(rt, pts[2]);
                        var p12 = APAZ.MatrixHelper.TransformPoint(rt, pts[3]);
                        var p22 = APAZ.MatrixHelper.TransformPoint(rt, pts[4]);
                        DrawLineInternal(dc, pen, style.IsStroked, ref p11, ref p21);
                        DrawLineInternal(dc, pen, style.IsStroked, ref p12, ref p22);
                    }
                    break;
            }

            return pt;
        }
Пример #27
0
 public LineDrawCommand(AM.IPen?pen, A.Point p1, A.Point p2)
 {
     Pen = pen;
     P1  = p1;
     P2  = p2;
 }
Пример #28
0
        protected void UpdateTextGeometry()
        {
            BoundText = Text.GetProperty(nameof(TextShapeViewModel.Text)) is string boundText ? boundText : Text.Text;

            if (BoundText is null)
            {
                return;
            }

            if (Style.TextStyle.FontSize < 0.0)
            {
                return;
            }

            var fontStyle  = AM.FontStyle.Normal;
            var fontWeight = AM.FontWeight.Normal;

            if (Style.TextStyle.FontStyle.HasFlag(FontStyleFlags.Italic))
            {
                fontStyle |= AM.FontStyle.Italic;
            }

            if (Style.TextStyle.FontStyle.HasFlag(FontStyleFlags.Bold))
            {
                fontWeight |= AM.FontWeight.Bold;
            }

            // TODO: Cache Typeface
            // TODO: Cache FormattedText

            Typeface = new AM.Typeface(Style.TextStyle.FontName, fontStyle, fontWeight);

            var textAlignment = Style.TextStyle.TextHAlignment switch
            {
                TextHAlignment.Right => AM.TextAlignment.Right,
                TextHAlignment.Center => AM.TextAlignment.Center,
                _ => AM.TextAlignment.Left,
            };

            FormattedText = new AM.FormattedText()
            {
                Typeface      = Typeface,
                Text          = BoundText,
                TextAlignment = textAlignment,
                TextWrapping  = AM.TextWrapping.NoWrap,
                FontSize      = Style.TextStyle.FontSize,
                Constraint    = Rect.Size
            };

            var size = FormattedText.Bounds.Size;
            var rect = Rect;

            // NOTE: Using AM.TextAlignment
            var originX = rect.X;
            //var originX = Style.TextStyle.TextHAlignment switch
            //{
            //    TextHAlignment.Left => rect.X,
            //    TextHAlignment.Right => rect.Right - size.Width,
            //    _ => (rect.Left + rect.Width / 2.0) - (size.Width / 2.0)
            //};

            var originY = Style.TextStyle.TextVAlignment switch
            {
                TextVAlignment.Top => rect.Y,
                TextVAlignment.Bottom => rect.Bottom - size.Height,
                _ => (rect.Bottom - rect.Height / 2f) - (size.Height / 2f)
            };

            Origin = new A.Point(originX, originY);
        }
Пример #29
0
 private System.Drawing.PointF SDPointF(Ava.Point pt)
 {
     return(new System.Drawing.PointF((float)pt.X, (float)pt.Y));
 }
Пример #30
0
 public TextDrawCommand(AM.IBrush?brush, A.Point origin, AM.FormattedText?formattedText)
 {
     Brush         = brush;
     Origin        = origin;
     FormattedText = formattedText;
 }
Пример #31
0
        private void DrawGridInternal(AM.DrawingContext dc, AM.Pen stroke, ref Rect2 rect, double offsetX, double offsetY, double cellWidth, double cellHeight, bool isStroked)
        {
            double ox = rect.X;
            double oy = rect.Y;
            double sx = ox + offsetX;
            double sy = oy + offsetY;
            double ex = ox + rect.Width;
            double ey = oy + rect.Height;

            for (double x = sx; x < ex; x += cellWidth)
            {
                var p0 = new A.Point(
                    _scaleToPage(x),
                    _scaleToPage(oy));
                var p1 = new A.Point(
                    _scaleToPage(x),
                    _scaleToPage(ey));
                DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1);
            }

            for (double y = sy; y < ey; y += cellHeight)
            {
                var p0 = new A.Point(
                    _scaleToPage(ox),
                    _scaleToPage(y));
                var p1 = new A.Point(
                    _scaleToPage(ex),
                    _scaleToPage(y));
                DrawLineInternal(dc, stroke, isStroked, ref p0, ref p1);
            }
        }
Пример #32
0
 public Avalonia.Point PointToDisplayAvaloniaPoint(Avalonia.Point p)
 {
     return(new Avalonia.Point((float)((p.X - shift_x) * zoom), (float)((p.Y - shift_y) * zoom)));
 }
Пример #33
0
 /// <summary>
 /// Convert from WPF point to core point.
 /// </summary>
 public static RPoint Convert(Point p)
 {
     return new RPoint(p.X, p.Y);
 }