예제 #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);
                }
            }
        }
예제 #2
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
                        );
                }
            }
        }