Example #1
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            var rectFactory = CreateRectFactory(CornerRadius);

            if (!IsHidden(FillColor))
            {
                FillColor.SetFill();
                rectFactory(Bounds).Fill();
            }

            if (LineThickness > 0 && !IsHidden(StrokeColor))
            {
                StrokeColor.SetStroke();
                var halfLineThickness = LineThickness * 0.5f;
                var path = rectFactory(CGRect.Inflate(Bounds, -halfLineThickness, -halfLineThickness));
                path.LineWidth = LineThickness;
                if (LineDash.Length > 0)                // The API doesn't expect an empty line dash array (for some reason)
                {
                    path.SetLineDash(LineDash.Select(w => w * LineThickness).ToArray(), 0);
                }

                path.Stroke();
            }
        }
        /// <summary>
        /// Overrides the <see cref="UIView.Draw"/> method to draw the shape view within the passed-in <paramref name="rect"/>.
        /// </summary>
        /// <param name="rect">The rectangle to draw.</param>
        public override void Draw(CGRect rect)
        {
            float x      = (float)rect.X;
            float y      = (float)rect.Y;
            float width  = (float)rect.Width;
            float height = (float)rect.Height;
            var   cx     = width / 2f;
            var   cy     = height / 2f;

            var context = UIGraphics.GetCurrentContext();

            var hasFill   = false;
            var hasStroke = false;

            var strokeWidth = 0f;

            if (BorderWidth > 0 && BorderColor.CGColor.Alpha > 0)
            {
                context.SetLineWidth(BorderWidth);
                BorderColor.SetStroke();

                hasStroke   = true;
                strokeWidth = BorderWidth;

                x      += strokeWidth / 2f;
                y      += strokeWidth / 2f;
                width  -= strokeWidth;
                height -= strokeWidth;
            }

            if (FillColor.CGColor.Alpha > 0)
            {
                FillColor.SetFill();
                hasFill = true;
            }

            switch (ShapeType)
            {
            case ShapeType.Rectangle:
            {
                DrawBox(context, x, y, width, height, CornerRadius, hasFill, hasStroke);
                break;
            }

            case ShapeType.Circle:
            {
                DrawCircle(context, cx, cy, Math.Min(height, width) / 2f, hasFill, hasStroke);
                break;
            }

            case ShapeType.Triangle:
            {
                DrawTriangle(context, rect, hasFill, hasStroke);
                break;
            }
            }
        }
Example #3
0
        public override void DrawRect(CGRect dirtyRect)
        {
            base.DrawRect(dirtyRect);

            FillColor.SetFill();
            NSBezierPath.FromOvalInRect(Bounds).Fill();

            if (LineThickness > 0)
            {
                StrokeColor.SetStroke();
                var halfLineThickness = LineThickness * 0.5f;
                var path = NSBezierPath.FromOvalInRect(CGRect.Inflate(Bounds, -halfLineThickness, -halfLineThickness));
                path.LineWidth = LineThickness;
                if (LineDash.Length > 0)                // The API doesn't expect an empty line dash array (for some reason)
                {
                    path.SetLineDash(LineDash.Select(w => w * LineThickness).ToArray(), 0);
                }

                path.Stroke();
            }
        }