public override void DrawRect(CoreGraphics.CGRect dirtyRect)
        {
            NSBezierPath path = NSBezierPath.FromRect(new CoreGraphics.CGRect(-200, -200, 200, 200));

            var rotation = new NSAffineTransform();

            rotation.RotateByDegrees((System.nfloat) 30);

            var transtation = new NSAffineTransform();

            transtation.Translate(250, 300);
            rotation.AppendTransform(transtation);

            path.TransformUsingAffineTransform(rotation);

            DrawPath(path);
        }
        public static XIR.Image RemoteRepresentation(this NSBezierPath nsbezierpath)
        {
            nfloat width  = 1f;
            nfloat height = 1f;

            // We check here for the element count.  If it is zero an error is being thrown if you access ControlPointBounds.
            if (nsbezierpath.ElementCount > 0)
            {
                // let's make sure we leave a little room for the line width drawing as well by adding the LineWidth of the
                // bezier path.
                width  = nsbezierpath.ControlPointBounds.Width + nsbezierpath.LineWidth * 2;
                height = nsbezierpath.ControlPointBounds.Height + nsbezierpath.LineWidth * 2;
            }
            else
            {
                return(new NSImage(new CGSize(width, height)).RemoteRepresentation());
            }

            var nsimage = new NSImage(new CGSize(width, height));

            nsimage.LockFocus();
            var transform = new NSAffineTransform();

            // We need to offset the image a little, specifically by the line width, so it will not be cut off
            var offsetXZero = -nsbezierpath.ControlPointBounds.X;
            var offsetYZero = -nsbezierpath.ControlPointBounds.Y;

            transform.Translate(offsetXZero + nsbezierpath.LineWidth / 2, offsetYZero + nsbezierpath.LineWidth / 2);
            nsbezierpath.TransformUsingAffineTransform(transform);

            brush.SetFill();
            nsbezierpath.Fill();

            pen.SetStroke();
            nsbezierpath.Stroke();

            nsimage.UnlockFocus();

            return(nsimage.RemoteRepresentation());
        }
        public static XIR.Image RemoteRepresentation(this NSLineCapStyle obj)
        {
            // Customize the line cap style for the new object.
            var aPath       = new NSBezierPath();
            var lineWidth   = 16;
            var sampleWidth = 100;

            // First we draw the presentation line
            aPath.LineWidth = lineWidth;
            aPath.MoveTo(new CGPoint(lineWidth, lineWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth, lineWidth));

            switch ((NSLineCapStyle)obj)
            {
            case NSLineCapStyle.Square:
                aPath.LineCapStyle = NSLineCapStyle.Square;
                break;

            case NSLineCapStyle.Butt:
                aPath.LineCapStyle = NSLineCapStyle.Butt;
                break;

            case NSLineCapStyle.Round:
                aPath.LineCapStyle = NSLineCapStyle.Round;
                break;
            }

            // let's make sure we leave a little room for the line width drawing as well by adding the lineWidth as well
            var width  = aPath.ControlPointBounds.Right + lineWidth;
            var height = aPath.ControlPointBounds.Bottom + lineWidth;

            var nsimage = new NSImage(new CGSize(width, height));

            nsimage.LockFocus();

            // We need to offset the image a little so it will not be cut off
            var transform = new NSAffineTransform();

            transform.Translate(aPath.LineWidth / 2, aPath.LineWidth / 2);
            aPath.TransformUsingAffineTransform(transform);

            brush.Set();
            aPath.Stroke();

            // Second, we draw the inset line to demonstrate the bounds
            aPath.RemoveAllPoints();
            lineWidth      += lineWidth / 2;
            aPath.LineWidth = 2;
            aPath.MoveTo(new CGPoint(lineWidth, lineWidth));
            aPath.LineTo(new CGPoint(lineWidth + sampleWidth, lineWidth));

            pen.Set();
            aPath.Stroke();

            // Third, we draw the inset line endings which are two circles
            aPath.RemoveAllPoints();
            var circleWidth = 2;

            aPath.LineWidth    = circleWidth;
            aPath.LineCapStyle = NSLineCapStyle.Butt;
            aPath.AppendPathWithOvalInRect(new CGRect(lineWidth - (int)(circleWidth / 2), lineWidth - (int)(circleWidth / 2), circleWidth, circleWidth));
            aPath.AppendPathWithOvalInRect(new CGRect(lineWidth + sampleWidth - (int)(circleWidth / 2), lineWidth - (int)(circleWidth / 2), circleWidth, circleWidth));

            pen.Set();
            aPath.Stroke();
            nsimage.UnlockFocus();
            return(nsimage.RemoteRepresentation());
        }