Beispiel #1
0
        void DrawFillPath(ICanvas canvas, RectF dirtyRect, PathF path)
        {
            if (ShapeView == null || ShapeView.Shape == null)
            {
                return;
            }

            if (!path.Closed)
            {
                return;
            }

            canvas.SaveState();

            ClipPath(canvas, path);

            // Set Fill
            var fillPaint = ShapeView.Fill;

            canvas.SetFillPaint(fillPaint, dirtyRect);

            canvas.FillPath(path);

            canvas.RestoreState();
        }
        void DrawBoxView(ICanvas canvas, RectangleF dirtyRect, PathF path)
        {
            if (BoxView == null)
            {
                return;
            }

            if (!path.Closed)
            {
                return;
            }

            canvas.SaveState();

            // Set BackgroundColor
            if (BoxView.Color != null)
            {
                canvas.FillColor = BoxView.Color;
            }
            else
            {
                canvas.SetFillPaint(BoxView.Background, dirtyRect);
            }

            canvas.FillPath(path);

            canvas.RestoreState();
        }
        public void Draw(ICanvas canvas, RectangleF dirtyRect)
        {
            var rect = dirtyRect;

            var path = new PathF();

            float x = dirtyRect.X;
            float y = dirtyRect.Y;
            float w = dirtyRect.Width;
            float h = dirtyRect.Height;

            float topLeftCornerRadius     = 0;
            float topRightCornerRadius    = 0;
            float bottomLeftCornerRadius  = 0;
            float bottomRightCornerRadius = 0;

            if (BoxView?.CornerRadius != null)
            {
                topLeftCornerRadius     = (float)BoxView.CornerRadius.TopLeft;
                topRightCornerRadius    = (float)BoxView.CornerRadius.TopRight;
                bottomLeftCornerRadius  = (float)BoxView.CornerRadius.BottomLeft;
                bottomRightCornerRadius = (float)BoxView.CornerRadius.BottomRight;
            }

            path.AppendRoundedRectangle(x, y, w, h, topLeftCornerRadius, topRightCornerRadius, bottomLeftCornerRadius, bottomRightCornerRadius);

            DrawBoxView(canvas, rect, path);
        }
Beispiel #4
0
        void ApplyTransform(PathF path)
        {
            if (RenderTransform == null)
            {
                return;
            }

            path.Transform(RenderTransform.Value);
        }
        public static PathF AsScaledPath(
            this PathF target,
            float scale)
        {
            var scaledPath = new PathF(target);
            var transform  = AffineTransform.GetScaleInstance(scale, scale);

            scaledPath.Transform(transform);
            return(scaledPath);
        }
Beispiel #6
0
        public PathF(PathF path) : this()
        {
            _operations.AddRange(path._operations);
            _points = new List <PointF>(path._points);

            _arcAngles.AddRange(path._arcAngles);
            _arcClockwise.AddRange(path._arcClockwise);

            _subPathCount   = path._subPathCount;
            _subPathsClosed = new List <bool>(path._subPathsClosed);
        }
Beispiel #7
0
        void DrawStrokePath(ICanvas canvas, RectF dirtyRect, PathF path)
        {
            if (ShapeView == null || ShapeView.Shape == null || ShapeView.StrokeThickness <= 0 || ShapeView.Stroke == null)
            {
                return;
            }

            canvas.SaveState();

            // Set StrokeThickness
            float strokeThickness = (float)ShapeView.StrokeThickness;

            canvas.StrokeSize = strokeThickness;

            // Set Stroke
            var stroke = ShapeView.Stroke;

            // TODO: Add Paint support for Stroke in Microsoft.Maui.Graphics.
            // For now, only support a solid color.
            canvas.StrokeColor = stroke.ToColor();

            // Set StrokeLineCap
            var strokeLineCap = ShapeView.StrokeLineCap;

            canvas.StrokeLineCap = strokeLineCap;

            // Set StrokeLineJoin
            var strokeLineJoin = ShapeView.StrokeLineJoin;

            canvas.StrokeLineJoin = strokeLineJoin;

            // Set StrokeDashPattern
            var strokeDashPattern = ShapeView.StrokeDashPattern;

            canvas.StrokeDashPattern = strokeDashPattern;

            // Set StrokeDashOffset
            var strokeDashOffset = ShapeView.StrokeDashOffset;

            canvas.StrokeDashOffset = strokeDashOffset;

            // Set StrokeMiterLimit
            var strokeMiterLimit = ShapeView.StrokeMiterLimit;

            canvas.MiterLimit = strokeMiterLimit;

            canvas.DrawPath(path);

            canvas.RestoreState();
        }
        public static string ToDefinitionString(this PathF path, float ppu = 1)
        {
            var writer = new StringWriter();

            for (var i = 0; i < path.OperationCount; i++)
            {
                var type   = path.GetSegmentType(i);
                var points = path.GetPointsForSegment(i);

                if (type == PathOperation.Move)
                {
                    writer.Write("M");
                    WritePoint(writer, points[0], ppu);
                }
                else if (type == PathOperation.Line)
                {
                    writer.Write(" L");
                    WritePoint(writer, points[0], ppu);
                }
                else if (type == PathOperation.Quad)
                {
                    writer.Write(" Q");
                    WritePoint(writer, points[0], ppu);
                    writer.Write(" ");
                    WritePoint(writer, points[1], ppu);
                }
                else if (type == PathOperation.Cubic)
                {
                    writer.Write(" C");
                    WritePoint(writer, points[0], ppu);
                    writer.Write(" ");
                    WritePoint(writer, points[1], ppu);
                    writer.Write(" ");
                    WritePoint(writer, points[2], ppu);
                }
                else if (type == PathOperation.Close)
                {
                    writer.Write(" Z ");
                }
            }

            return(writer.ToString());
        }
Beispiel #9
0
        private void ArcTo(bool isRelative)
        {
            var startPoint = _relativePoint ?? default;

            var rx = NextValue;
            var ry = NextValue;

            var r            = NextValue;
            var largeArcFlag = NextBoolValue;
            var sweepFlag    = NextBoolValue;
            var endPoint     = NewPoint(NextValue, NextValue, isRelative, false);

            var arcPath = new PathF(startPoint);

            arcPath.SVGArcTo(rx, ry, r, largeArcFlag, sweepFlag, endPoint.X, endPoint.Y, startPoint.X, startPoint.Y);

            for (int s = 0; s < arcPath.OperationCount; s++)
            {
                var segmentType     = arcPath.GetSegmentType(s);
                var pointsInSegment = arcPath.GetPointsForSegment(s);

                if (segmentType == PathOperation.Move)
                {
                    // do nothing
                }
                else if (segmentType == PathOperation.Line)
                {
                    _path.LineTo(pointsInSegment[0]);
                }
                else if (segmentType == PathOperation.Cubic)
                {
                    _path.CurveTo(pointsInSegment[0], pointsInSegment[1], pointsInSegment[2]);
                }
                else if (segmentType == PathOperation.Quad)
                {
                    _path.QuadTo(pointsInSegment[0], pointsInSegment[1]);
                }
            }

            _relativePoint = _path.LastPoint;
        }
Beispiel #10
0
 public RectangleF GetPathBounds(PathF path)
 {
     throw new NotImplementedException();
 }
Beispiel #11
0
 void ClipPath(ICanvas canvas, PathF path)
 {
     canvas.ClipPath(path, WindingMode);
 }
Beispiel #12
0
 public void DrawPath(PathF path)
 {
     _commands.Add(canvas => canvas.DrawPath(path));
 }
Beispiel #13
0
 protected abstract void NativeDrawPath(PathF path);
Beispiel #14
0
 public void FillPath(PathF path, WindingMode windingMode)
 {
     _commands.Add(canvas => canvas.FillPath(path, windingMode));
 }
Beispiel #15
0
 public List <PathF> ConvertToPaths(PathF aPath, string text, ITextAttributes textAttributes, float ppu, float zoom)
 {
     return(new List <PathF>());
 }
Beispiel #16
0
 public void ClipPath(PathF path, WindingMode windingMode = WindingMode.NonZero)
 {
     _commands.Add(canvas => canvas.ClipPath(path, windingMode));
 }
Beispiel #17
0
 public bool PointIsOnPathSegment(PathF path, int segmentIndex, PointF point, float ppu, float zoom, float strokeWidth)
 {
     throw new NotImplementedException();
 }
Beispiel #18
0
 public bool PathContainsPoint(PathF path, PointF point, float ppu, float zoom, float strokeWidth)
 {
     throw new NotImplementedException();
 }
Beispiel #19
0
 public static void SVGArcTo(this PathF aTarget, float rx, float ry, float angle, bool largeArcFlag, bool sweepFlag, float x, float y, float lastPointX, float lastPointY)
 {
     float[] vValues = ComputeSvgArc(rx, ry, angle, largeArcFlag, sweepFlag, x, y, lastPointX, lastPointY);
     DrawArc(vValues[0], vValues[1], vValues[2], vValues[3], vValues[4], vValues[5], vValues[6], aTarget);
 }
Beispiel #20
0
        public PathF BuildPath(string pathAsString)
        {
            try
            {
                _lastCommand           = '~';
                _lastCurveControlPoint = null;
                _path = null;
                _commandStack.Clear();
                _relativePoint = new PointF(0, 0);
                _closeWhenDone = false;

#if DEBUG_PATH
                Logger.Debug(aPathString);
#endif
                pathAsString = pathAsString.Replace("Infinity", "0");
                pathAsString = Regex.Replace(pathAsString, "([a-zA-Z])", " $1 ");
                pathAsString = pathAsString.Replace("-", " -");
                pathAsString = pathAsString.Replace(" E  -", "E-");
                pathAsString = pathAsString.Replace(" e  -", "e-");
#if DEBUG_PATH
                Logger.Debug(aPathString);
#endif
                string[] args = pathAsString.Split(new[] { ' ', '\r', '\n', '\t', ',' }, StringSplitOptions.RemoveEmptyEntries);
                for (int i = args.Length - 1; i >= 0; i--)
                {
                    string entry = args[i];
                    char   c     = entry[0];
                    if (char.IsLetter(c))
                    {
                        if (entry.Length > 1)
                        {
                            entry = entry.Substring(1);
                            if (char.IsLetter(entry[0]))
                            {
                                if (entry.Length > 1)
                                {
                                    _commandStack.Push(entry.Substring(1));
#if DEBUG_PATH
                                    Logger.Debug(vEntry.Substring(1));
#endif
                                }

                                _commandStack.Push(entry[0].ToInvariantString());
#if DEBUG_PATH
                                Logger.Debug(vEntry[0].ToString());
#endif
                            }
                            else
                            {
                                _commandStack.Push(entry);
#if DEBUG_PATH
                                Logger.Debug(vEntry);
#endif
                            }
                        }

                        _commandStack.Push(c.ToInvariantString());
#if DEBUG_PATH
                        Logger.Debug(vChar.ToString());
#endif
                    }
                    else
                    {
                        _commandStack.Push(entry);
#if DEBUG_PATH
                        Logger.Debug(vEntry);
#endif
                    }
                }

                while (_commandStack.Count > 0)
                {
                    if (_path == null)
                    {
                        _path = new PathF();
                    }

                    string topCommand  = _commandStack.Pop();
                    var    firstLetter = topCommand[0];

                    if (IsCommand(firstLetter))
                    {
                        HandleCommand(topCommand);
                    }
                    else
                    {
                        _commandStack.Push(topCommand);
                        HandleCommand(_lastCommand.ToString());
                    }
                }

                if (_path != null && !_path.Closed)
                {
                    if (_closeWhenDone)
                    {
                        _path.Close();
                    }
                }
            }
            catch (Exception exc)
            {
#if DEBUG
                Logger.Debug("=== An error occured parsing the path. ===", exc);
                Logger.Debug(pathAsString);
                throw;
#endif
            }

            return(_path);
        }
Beispiel #21
0
 public void LayoutText(PathF path, string text, ITextAttributes textAttributes, LayoutLine callback)
 {
     // Do nothing
 }
Beispiel #22
0
 public RectangleF GetPathBoundsWhenRotated(PointF center, PathF path, float angle)
 {
     throw new NotImplementedException();
 }
Beispiel #23
0
        /**
         * Draws an arc of type "open" only. Accepts an optional x axis rotation value
         **/

        public static void DrawArc(float x, float y, float startAngle, float arc, float radius, float yRadius, float xAxisRotation, PathF aPath)
        {
            // Circumvent drawing more than is needed
            if (Math.Abs(arc) > 360)
            {
                arc = 360;
            }

            // Draw in a maximum of 45 degree segments. First we calculate how many
            // segments are needed for our arc.
            float segs = (float)Math.Ceiling(Math.Abs(arc) / 45);

            // Now calculate the sweep of each segment
            float segAngle = arc / segs;

            float theta = Geometry.DegreesToRadians(segAngle);
            float angle = Geometry.DegreesToRadians(startAngle);

            // Draw as 45 degree segments
            if (segs > 0)
            {
                float beta    = Geometry.DegreesToRadians(xAxisRotation);
                float sinbeta = (float)Math.Sin(beta);
                float cosbeta = (float)Math.Cos(beta);

                // Loop for drawing arc segments
                for (int i = 0; i < segs; i++)
                {
                    angle += theta;

                    float sinangle = (float)Math.Sin(angle - theta / 2);
                    float cosangle = (float)Math.Cos(angle - theta / 2);

                    float div = (float)Math.Cos(theta / 2);
                    float cx  = x + (radius * cosangle * cosbeta - yRadius * sinangle * sinbeta) / div;
                    //Why divide by Math.cos(theta/2)? - FIX THIS
                    float cy = y + (radius * cosangle * sinbeta + yRadius * sinangle * cosbeta) / div;
                    //Why divide by Math.cos(theta/2)? - FIX THIS

                    sinangle = (float)Math.Sin(angle);
                    cosangle = (float)Math.Cos(angle);

                    float x1 = x + (radius * cosangle * cosbeta - yRadius * sinangle * sinbeta);
                    float y1 = y + (radius * cosangle * sinbeta + yRadius * sinangle * cosbeta);

                    aPath.QuadTo(cx, cy, x1, y1);
                }
            }
        }