Ejemplo n.º 1
0
        private void DrawNormalGridLayer(CALayer layer, bool isMajor)
        {
            if (isMajor && MajorGridLineInterval == 0)
            {
                return;
            }

            using (var path = CreatePath(isMajor ? MajorGridLineInterval : 0))
            {
                layer = new CAShapeLayer
                {
                    LineWidth   = isMajor ? (nfloat)MajorGridLineThickness : (nfloat)GridLineThickness,
                    Path        = path.CGPath,
                    StrokeColor = isMajor ? MajorGridLineColor.ToCGColor() : GridLineColor.ToCGColor(),
                    Opacity     = isMajor ? (float)MajorGridLineOpacity : (float)GridLineOpacity,
                    Frame       = new CGRect(0, 0, Bounds.Size.Width, Bounds.Size.Height)
                };

                if (!MakeGridRainbows)
                {
                    this.Layer.AddSublayer(layer);
                }
                else
                {
                    var gradientLayer = new CAGradientLayer
                    {
                        StartPoint = new CGPoint(0.5, 0.0),
                        EndPoint   = new CGPoint(0.5, 1.0),
                        Frame      = new CGRect(0, 0, Bounds.Size.Width, Bounds.Size.Height),
                        Colors     = rainbowColors,
                        Mask       = layer
                    };

                    this.Layer.AddSublayer(gradientLayer);
                }
            }
        }
Ejemplo n.º 2
0
        private void DrawInverse(Canvas canvas, Paint majorPaint, global::Android.Graphics.Color[] colors)
        {
            majorPaint.StrokeWidth = 0;
            majorPaint.Color       = GridLineColor.ToAndroid();
            majorPaint.Alpha       = (int)(255 * GridLineOpacity);

            if (GridOrigin == DebugGridOrigin.TopLeft)
            {
                var horizontalTotal = 0;
                for (int i = 1; horizontalTotal < screenWidth; i++)
                {
                    var verticalTotal        = 0;
                    var horizontalSpacerSize = MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;

                    for (int j = 1; verticalTotal < screenHeight; j++)
                    {
                        var verticalSpacerSize = MajorGridLineInterval > 0 && j % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;

                        var rectangle = new Rect(
                            (int)horizontalTotal,
                            (int)verticalTotal,
                            (int)(horizontalTotal + HorizontalItemSize),
                            (int)(verticalTotal + VerticalItemSize)
                            );

                        if (MakeGridRainbows)
                        {
                            var color = colors[(i + j) % colors.Length];
                            majorPaint.Color = color;
                        }

                        canvas.DrawRect(rectangle, majorPaint);

                        verticalTotal += (int)(VerticalItemSize + verticalSpacerSize);
                    }

                    horizontalTotal += (int)(HorizontalItemSize + horizontalSpacerSize);
                }
            }
            else if (GridOrigin == DebugGridOrigin.Center)
            {
                var horizontalRightTotal = (screenWidth / 2) + (int)((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2);
                var horizontalLeftTotal  = (screenWidth / 2) - (int)(HorizontalItemSize + ((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2));

                for (int i = 1; horizontalRightTotal < screenWidth; i++)
                {
                    var horizontalSpacerSize = MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;
                    var verticalBottomTotal  = (screenHeight / 2) + (int)((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2);
                    var verticalTopTotal     = (screenHeight / 2) - (int)(VerticalItemSize + ((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2));

                    for (int j = 1; verticalBottomTotal < screenHeight; j++)
                    {
                        if (MakeGridRainbows)
                        {
                            var color = colors[(i + j) % colors.Length];
                            majorPaint.Color = color;
                        }

                        var verticalSpacerSize = MajorGridLineInterval > 0 && j % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;

                        var rectangle = new Rect(horizontalRightTotal, verticalBottomTotal, (int)(horizontalRightTotal + HorizontalItemSize), (int)(verticalBottomTotal + VerticalItemSize));
                        canvas.DrawRect(rectangle, majorPaint);

                        var rectangle2 = new Rect(horizontalLeftTotal, verticalTopTotal, (int)(horizontalLeftTotal + HorizontalItemSize), (int)(verticalTopTotal + VerticalItemSize));
                        canvas.DrawRect(rectangle2, majorPaint);

                        var rectangle3 = new Rect(horizontalRightTotal, verticalTopTotal, (int)(horizontalRightTotal + HorizontalItemSize), (int)(verticalTopTotal + VerticalItemSize));
                        canvas.DrawRect(rectangle3, majorPaint);

                        var rectangle4 = new Rect(horizontalLeftTotal, verticalBottomTotal, (int)(horizontalLeftTotal + HorizontalItemSize), (int)(verticalBottomTotal + VerticalItemSize));
                        canvas.DrawRect(rectangle4, majorPaint);

                        verticalTopTotal    -= (int)(VerticalItemSize + verticalSpacerSize);
                        verticalBottomTotal += (int)(VerticalItemSize + verticalSpacerSize);
                    }

                    horizontalRightTotal += (int)(HorizontalItemSize + horizontalSpacerSize);
                    horizontalLeftTotal  -= (int)(HorizontalItemSize + horizontalSpacerSize);
                }
            }
        }
Ejemplo n.º 3
0
        private void DrawInverseGridLayer(CGRect rect)
        {
            var context = UIGraphics.GetCurrentContext();

            context.SetFillColor(GridLineColor.ToCGColor());
            context.SetAlpha((nfloat)GridLineOpacity);

            if (GridOrigin == DebugGridOrigin.TopLeft)
            {
                var horizontalTotal = 0;

                for (int i = 1; horizontalTotal < Bounds.Size.Width; i++)
                {
                    var verticalTotal        = 0;
                    var horizontalSpacerSize = MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;

                    for (int j = 1; verticalTotal < Bounds.Size.Height; j++)
                    {
                        var verticalSpacerSize = MajorGridLineInterval > 0 && j % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;
                        var rectangle          = new CGRect(horizontalTotal, verticalTotal, HorizontalItemSize, VerticalItemSize);

                        if (MakeGridRainbows)
                        {
                            var color = rainbowColors[(i + j) % rainbowColors.Length];
                            context.SetFillColor(color);
                        }

                        context.FillRect(rectangle);

                        verticalTotal += (int)(VerticalItemSize + verticalSpacerSize);
                    }

                    horizontalTotal += (int)(HorizontalItemSize + horizontalSpacerSize);
                }
            }
            else if (GridOrigin == DebugGridOrigin.Center)
            {
                var horizontalRightTotal = (Bounds.Size.Width / 2) + ((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2);
                var horizontalLeftTotal  = (Bounds.Size.Width / 2) - (int)(HorizontalItemSize + ((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2));

                for (int i = 1; horizontalRightTotal < Bounds.Size.Width; i++)
                {
                    var horizontalSpacerSize = MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;
                    var verticalBottomTotal  = (Bounds.Size.Height / 2) + ((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2);
                    var verticalTopTotal     = (Bounds.Size.Height / 2) - (int)(VerticalItemSize + ((MajorGridLineInterval > 0 ? MajorGridLineThickness : GridLineThickness) / 2));

                    for (int j = 1; verticalBottomTotal < Bounds.Size.Height; j++)
                    {
                        if (MakeGridRainbows)
                        {
                            var color = rainbowColors[(i + j) % rainbowColors.Length];
                            context.SetFillColor(color);
                        }

                        var verticalSpacerSize = MajorGridLineInterval > 0 && j % MajorGridLineInterval == 0 ? MajorGridLineThickness : GridLineThickness;

                        var rectangle = new CGRect(horizontalRightTotal, verticalBottomTotal, HorizontalItemSize, VerticalItemSize);
                        context.FillRect(rectangle);

                        var rectangle2 = new CGRect(horizontalLeftTotal, verticalTopTotal, HorizontalItemSize, VerticalItemSize);
                        context.FillRect(rectangle2);

                        var rectangle3 = new CGRect(horizontalRightTotal, verticalTopTotal, HorizontalItemSize, VerticalItemSize);
                        context.FillRect(rectangle3);

                        var rectangle4 = new CGRect(horizontalLeftTotal, verticalBottomTotal, HorizontalItemSize, VerticalItemSize);
                        context.FillRect(rectangle4);

                        verticalTopTotal    -= (int)(VerticalItemSize + verticalSpacerSize);
                        verticalBottomTotal += (int)(VerticalItemSize + verticalSpacerSize);
                    }

                    horizontalRightTotal += (int)(HorizontalItemSize + horizontalSpacerSize);
                    horizontalLeftTotal  -= (int)(HorizontalItemSize + horizontalSpacerSize);
                }
            }
        }
Ejemplo n.º 4
0
        private void DrawNormal(Canvas canvas, Paint majorPaint, Paint minorPaint)
        {
            majorPaint.StrokeWidth = MajorGridLineThickness;
            majorPaint.Color       = MajorGridLineColor.ToAndroid();
            majorPaint.Alpha       = (int)(255 * MajorGridLineOpacity);

            minorPaint.StrokeWidth = GridLineThickness;
            minorPaint.Color       = GridLineColor.ToAndroid();
            minorPaint.Alpha       = (int)(255 * GridLineOpacity);

            if (GridOrigin == DebugGridOrigin.TopLeft)
            {
                float verticalPosition = 0;
                int   i = 0;
                while (verticalPosition <= screenHeight)
                {
                    canvas.DrawLine(0, verticalPosition, screenWidth, verticalPosition, MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? majorPaint : minorPaint);
                    verticalPosition += VerticalItemSize;
                    i++;
                }

                float horizontalPosition = 0;
                i = 0;
                while (horizontalPosition <= screenWidth)
                {
                    canvas.DrawLine(horizontalPosition, 0, horizontalPosition, screenHeight, MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? majorPaint : minorPaint);
                    horizontalPosition += HorizontalItemSize;
                    i++;
                }
            }
            else if (GridOrigin == DebugGridOrigin.Center)
            {
                var gridLinesHorizontalCenter = screenWidth / 2;
                var gridLinesVerticalCenter   = screenHeight / 2;
                var amountOfVerticalLines     = screenWidth / HorizontalItemSize;
                var amountOfHorizontalLines   = screenHeight / VerticalItemSize;

                // Draw the horizontal lines.
                for (int i = 0; i < (amountOfHorizontalLines / 2); i++)
                {
                    canvas.DrawLine(
                        startX: 0,
                        startY: gridLinesVerticalCenter + (i * VerticalItemSize),
                        stopX: screenWidth,
                        stopY: gridLinesVerticalCenter + (i * VerticalItemSize),
                        paint: MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? majorPaint : minorPaint
                        );

                    canvas.DrawLine(
                        startX: 0,
                        startY: gridLinesVerticalCenter - (i * VerticalItemSize),
                        stopX: screenWidth,
                        stopY: gridLinesVerticalCenter - (i * VerticalItemSize),
                        paint: MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? majorPaint : minorPaint
                        );
                }

                // Draw vertical lines.
                for (int i = 0; i < (amountOfVerticalLines / 2); i++)
                {
                    canvas.DrawLine(
                        startX: gridLinesHorizontalCenter + (i * HorizontalItemSize),
                        startY: 0,
                        stopX: gridLinesHorizontalCenter + (i * HorizontalItemSize),
                        stopY: screenHeight,
                        paint: MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? majorPaint : minorPaint
                        );

                    canvas.DrawLine(
                        startX: gridLinesHorizontalCenter - (i * HorizontalItemSize),
                        startY: 0,
                        stopX: gridLinesHorizontalCenter - (i * HorizontalItemSize),
                        stopY: screenHeight,
                        paint: MajorGridLineInterval > 0 && i % MajorGridLineInterval == 0 ? majorPaint : minorPaint
                        );
                }
            }
        }