public static XIR.Image RemoteRepresentation(this NSLineJoinStyle obj)
        {
            // Customize the line cap style for the new object.
            var aPath       = new NSBezierPath();
            var lineWidth   = 10;
            var sampleWidth = 50;

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

            switch ((NSLineJoinStyle)obj)
            {
            case NSLineJoinStyle.Bevel:
                aPath.LineJoinStyle = NSLineJoinStyle.Bevel;
                break;

            case NSLineJoinStyle.Miter:
                aPath.LineJoinStyle = NSLineJoinStyle.Miter;
                break;

            case NSLineJoinStyle.Round:
                aPath.LineJoinStyle = NSLineJoinStyle.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();

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

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

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

            nsimage.UnlockFocus();
            return(nsimage.RemoteRepresentation());
        }
Exemple #2
0
        public static void DrawResults(NSImage img, MultiboxGraph.Result result, float scoreThreshold)
        {
            Rectangle[] locations = ScaleLocation(result.DecodedLocations, (int)img.Size.Width, (int)img.Size.Height);
            img.LockFocus();

            NSColor redColor = NSColor.Red;

            redColor.Set();
            var context   = NSGraphicsContext.CurrentContext;
            var cgcontext = context.CGContext;

            cgcontext.ScaleCTM(1, -1);
            cgcontext.TranslateCTM(0, -img.Size.Height);
            //context.IsFlipped = !context.IsFlipped;
            for (int i = 0; i < result.Scores.Length; i++)
            {
                if (result.Scores[i] > scoreThreshold)
                {
                    Rectangle rect = locations[result.Indices[i]];
                    //img.Draw()
                    //Trace.WriteLine(String.Format("x: {0}, y: {1}, w: {2}, h: {3}", rect.X, rect.Y, rect.Width, rect.Height));
                    CGRect cgRect = new CGRect(rect.X, rect.Y, rect.Width, rect.Height);
                    //img.Draw(cgRect);
                    //CGPath path = CGPath.FromRect(cgRect);
                    //NSBezierPath path = NSBezierPath.FromOvalInRect(cgRect);
                    //path.Fill();
                    //path.Stroke();
                    NSBezierPath.StrokeRect(cgRect);
                    //img.Draw(cgRect, );
                }
            }
            img.UnlockFocus();
        }
Exemple #3
0
        // Draw the view
        public override void DrawRect(CoreGraphics.CGRect dirtyRect)
        {
            CGRect bounds = this.Bounds;

            // Using the system focus ring instead. Achieved by overriding DrawFocusRingMask and FocusRingMaskBounds
//			// Am I the window's first responder?
//			if (this.Window.FirstResponder == this) {
//				NSColor.KeyboardFocusIndicator.Set();
//				NSBezierPath.DefaultLineWidth = 4.0f;
//				NSBezierPath.StrokeRect(bounds);
//			}

            if (Highlighted)
            {
                NSGradient gr = new NSGradient(NSColor.White, mBgColor);
                gr.DrawInRect(bounds, new CGPoint(0.0f, 0.0f));
            }
            else
            {
                mBgColor.Set();
                NSBezierPath.FillRect(bounds);
            }

            DrawStringCenteredInRectangle(mLetter, bounds);
        }
Exemple #4
0
        public static void DrawAnnotations(NSImage img, Annotation[] annotations)
        {
            img.LockFocus();

            NSColor redColor = NSColor.Red;

            redColor.Set();
            var context   = NSGraphicsContext.CurrentContext;
            var cgcontext = context.CGContext;

            cgcontext.ScaleCTM(1, -1);
            cgcontext.TranslateCTM(0, -img.Size.Height);
            //context.IsFlipped = !context.IsFlipped;
            for (int i = 0; i < annotations.Length; i++)
            {
                float[] rects  = ScaleLocation(annotations[i].Rectangle, (int)img.Size.Width, (int)img.Size.Height);
                CGRect  cgRect = new CGRect(
                    rects[0],
                    rects[1],
                    rects[2] - rects[0],
                    rects[3] - rects[1]);
                NSBezierPath.StrokeRect(cgRect);
            }
            img.UnlockFocus();
        }
Exemple #5
0
        private void DrawString(string str, NSDictionary fontInfo, NSColor color, int xpos, int ypos)
        {
            color.Set();
            NSString tmp = new NSString(str);

            tmp.DrawString(new CGPoint(xpos, ypos), fontInfo);
        }
        public override void DrawRect(CGRect dirtyRect)
        {
            NSColorList colors = NSColorList.ColorListNamed("System");
            CGRect      rect   = Bounds;

            rect.Height = 12;
            var style = (NSMutableParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy();

            style.Alignment = NSTextAlignment.Right;
            var attrs = new NSStringAttributes {
                Font            = NSFont.SystemFontOfSize(8),
                ForegroundColor = NSColor.LabelColor,
                ParagraphStyle  = style
            };

            foreach (NSString key in colors.AllKeys())
            {
                if (DrawColors)
                {
                    NSColor color = colors.ColorWithKey(key);
                    color.Set();
                    NSGraphics.RectFill(rect);
                }

                if (DrawTitles)
                {
                    key.DrawString(rect, attrs.Dictionary);
                }

                rect.Y += 12;
            }
        }
Exemple #7
0
        public void SetColor(object backend, Xwt.Drawing.Color color)
        {
            NSColor col = NSColor.FromDeviceRgba((float)color.Red, (float)color.Green, (float)color.Blue, (float)color.Alpha);

            col.Set();
            col.SetFill();
        }
Exemple #8
0
 public override void DrawRect(CGRect dirtyRect)
 {
     if (dirtyRect.Y <= 0)
     {
         BorderColor.Set();
         NSBezierPath.FillRect(new CGRect(dirtyRect.X, 0, dirtyRect.Width, 1));
     }
 }
Exemple #9
0
 public override void DrawRect(CGRect dirtyRect)
 {
     if (DrawsBackground && BackgroundColor != null && BackgroundColor.AlphaComponent > 0)
     {
         BackgroundColor.Set();
         NSGraphics.RectFill(dirtyRect);
     }
     base.DrawRect(dirtyRect);
 }
Exemple #10
0
        // This is called repeatedly to draw the contents of the view.
        // As an optimization, you can only redrawn the elements in the dirtyRect (not done here)
        public override void DrawRect(CGRect dirtyRect)
        {
            lineColor.Set();              // You call set on each color to set it as the current global color
            var path = CreatePathForOval(this.Bounds);

            path.Stroke();            // This uses the color set above
            fillColor.Set();          // Now this is the global color
            path.Fill();              // Which is used by this fill.
        }
Exemple #11
0
        public override void DrawRect(RectangleF dirtyRect)
        {
            var context = NSGraphicsContext.CurrentContext.GraphicsPort;

            context.SetFillColor(new CGColor(1, 1, 1));           //White
            context.FillRect(dirtyRect);

            for (int i = 1; i < this.Bounds.Size.Height / 10; i++)
            {
                if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.3f);
                    colorWithSRGBRed.Set();
                }
                else if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.2f);
                    colorWithSRGBRed.Set();
                }
                else
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.1f);
                    colorWithSRGBRed.Set();
                }
                var pointFrom = new PointF(0, (i * GridSize - 0.5f));
                var pointTo   = new PointF(this.Bounds.Size.Width, (i * GridSize - 0.5f));

                NSBezierPath.StrokeLine(pointFrom, pointTo);
            }


            for (int i = 1; i < this.Bounds.Size.Width / 10; i++)
            {
                if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.3f);
                    colorWithSRGBRed.Set();
                }
                else if (i % 10 == 0)
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.2f);
                    colorWithSRGBRed.Set();
                }
                else
                {
                    NSColor colorWithSRGBRed = NSColor.FromSrgb(100 / 255.0f, 149 / 255.0f, 237 / 255.0f, 0.1f);
                    colorWithSRGBRed.Set();
                }
                var pointFrom = new PointF((i * GridSize - 0.5f), 0);
                var pointTo   = new PointF((i * GridSize - 0.5f), this.Bounds.Size.Height);

                NSBezierPath.StrokeLine(pointFrom, pointTo);
            }
        }
Exemple #12
0
        public static NSImage Tint(this NSImage image, NSColor color)
        {
            var copy = image.Copy() as NSImage;

            copy.LockFocus();
            {
                color.Set();
                var imageRect = new CGRect(CGPoint.Empty, image.Size);
                NSGraphics.RectFill(imageRect, NSCompositingOperation.SourceAtop);
            }
            copy.UnlockFocus();

            return(copy);
        }
        public static void DrawAnnotations(NSImage img, Annotation[] annotations)
        {
            img.LockFocus();

            NSColor redColor = NSColor.Red;

            redColor.Set();

            var context = NSGraphicsContext.CurrentContext;

            if (context == null)
            {
                return;
            }
            var cgcontext = context.CGContext;

            for (int i = 0; i < annotations.Length; i++)
            {
                float[] rects  = ScaleLocation(annotations[i].Rectangle, (int)img.Size.Width, (int)img.Size.Height);
                CGRect  cgRect = new CGRect(
                    rects[0],
                    rects[1],
                    rects[2] - rects[0],
                    rects[3] - rects[1]);
                NSFont font           = NSFont.FromFontName("Arial", 20);
                var    fontDictionary = Foundation.NSDictionary.FromObjectsAndKeys(
                    new Foundation.NSObject[] { font, NSColor.Red },
                    new Foundation.NSObject[] { NSStringAttributeKey.Font, NSStringAttributeKey.ForegroundColor });
                //CGSize size = text.StringSize(fontDictionary);
                CGPoint p = new CGPoint(cgRect.Location.X, img.Size.Height - cgRect.Location.Y);
                annotations[i].Label.DrawAtPoint(p, fontDictionary);
            }

            cgcontext.ScaleCTM(1, -1);
            cgcontext.TranslateCTM(0, -img.Size.Height);
            //context.IsFlipped = !context.IsFlipped;
            for (int i = 0; i < annotations.Length; i++)
            {
                float[] rects  = ScaleLocation(annotations[i].Rectangle, (int)img.Size.Width, (int)img.Size.Height);
                CGRect  cgRect = new CGRect(
                    rects[0],
                    rects[1],
                    rects[2] - rects[0],
                    rects[3] - rects[1]);
                NSBezierPath.StrokeRect(cgRect);
            }

            img.UnlockFocus();
        }
Exemple #14
0
 public static NSImage TintColor(this NSImage image, NSColor color)
 {
     try
     {
         image.LockFocus();
         color.Set();
         var rect = new CGRect(0, 0, image.Size.Width, image.Size.Height);
         NSGraphics.RectFill(rect, NSCompositingOperation.SourceAtop);
     }
     finally
     {
         image.UnlockFocus();
     }
     return(image);
 }
Exemple #15
0
        // Based on http://stackoverflow.com/a/43235
        NSImage TintImage(NSImage image)
        {
            int     r         = random.Next(128, 255);
            int     g         = random.Next(128, 255);
            int     b         = random.Next(128, 255);
            NSColor baseColor = NSColor.White.UsingColorSpace(NSColorSpace.CalibratedRGB);

            r = (int)(r + baseColor.RedComponent) / 2;
            g = (int)(g + baseColor.GreenComponent) / 2;
            b = (int)(b + baseColor.BlueComponent) / 2;
            NSColor color = NSColor.FromRgb(r, g, b);

            NSImage tintedImage = (NSImage)image.Copy();

            tintedImage.LockFocus();
            color.Set();
            NSGraphics.RectFill(new CGRect(0, 0, image.Size.Width, image.Size.Height), NSCompositingOperation.SourceAtop);
            tintedImage.UnlockFocus();

            return(tintedImage);
        }
Exemple #16
0
        public void Fill(object backend)
        {
            var ctx = GetContext(backend);

            if (ctx.Pattern is GradientInfo)
            {
                GradientInfo gr = (GradientInfo)ctx.Pattern;
                NSGradient   g  = new NSGradient(gr.Colors.ToArray(), gr.Stops.ToArray());
                g.DrawInBezierPath(ctx.Path, 0f);
            }
            else if (ctx.Pattern is NSColor)
            {
                NSColor col = (NSColor)ctx.Pattern;
                col.Set();
                col.SetFill();
            }
            else
            {
                ctx.Path.Fill();
            }
            ctx.Pattern = null;
            ctx.Path.Dispose();
            ctx.Path = new NSBezierPath();
        }
Exemple #17
0
		public static SCNNode SCBoxNode (string title, CGRect frame, NSColor color, float cornerRadius, bool centered)
		{
			NSMutableDictionary titleAttributes = null;
			NSMutableDictionary centeredTitleAttributes = null;

			// create and extrude a bezier path to build the box
			var path = NSBezierPath.FromRoundedRect (frame, cornerRadius, cornerRadius);
			path.Flatness = 0.05f;

			var shape = SCNShape.Create (path, 20);
			shape.ChamferRadius = 0.0f;

			var node = SCNNode.Create ();
			node.Geometry = shape;

			// create an image and fill with the color and text
			var textureSize = new CGSize ();
			textureSize.Width = NMath.Ceiling (frame.Size.Width * 1.5f);
			textureSize.Height = NMath.Ceiling (frame.Size.Height * 1.5f);

			var texture = new NSImage (textureSize);
			texture.LockFocus ();

			var drawFrame = new CGRect (0, 0, textureSize.Width, textureSize.Height);

			nfloat hue, saturation, brightness, alpha;

			(color.UsingColorSpace (NSColorSpace.DeviceRGBColorSpace)).GetHsba (out hue, out saturation, out brightness, out alpha);
			var lightColor = NSColor.FromDeviceHsba (hue, saturation - 0.2f, brightness + 0.3f, alpha);
			lightColor.Set ();

			NSGraphics.RectFill (drawFrame);

			NSBezierPath fillpath = null;

			if (cornerRadius == 0 && centered == false) {
				//special case for the "labs" slide
				drawFrame.Offset (0, -2);
				fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius);
			} else {
				drawFrame.Inflate (-3, -3);
				fillpath = NSBezierPath.FromRoundedRect (drawFrame, cornerRadius, cornerRadius);
			}

			color.Set ();
			fillpath.Fill ();

			// draw the title if any
			if (title != null) {
				if (titleAttributes == null) {
					var paraphStyle = new NSMutableParagraphStyle ();
					paraphStyle.LineBreakMode = NSLineBreakMode.ByWordWrapping;
					paraphStyle.Alignment = NSTextAlignment.Center;
					paraphStyle.MinimumLineHeight = 38;
					paraphStyle.MaximumLineHeight = 38;

					var font = NSFont.FromFontName ("Myriad Set Semibold", 34) != null ? NSFont.FromFontName ("Myriad Set Semibold", 34) : NSFont.FromFontName ("Avenir Medium", 34);

					var shadow = new NSShadow ();
					shadow.ShadowOffset = new CGSize (0, -2);
					shadow.ShadowBlurRadius = 4;
					shadow.ShadowColor = NSColor.FromDeviceWhite (0.0f, 0.5f);

					titleAttributes = new NSMutableDictionary ();
					titleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName);
					titleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
					titleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName);
					titleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName);

					var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy ();
					centeredParaphStyle.Alignment = NSTextAlignment.Center;

					centeredTitleAttributes = new NSMutableDictionary ();
					centeredTitleAttributes.SetValueForKey (font, NSAttributedString.FontAttributeName);
					centeredTitleAttributes.SetValueForKey (NSColor.White, NSAttributedString.ForegroundColorAttributeName);
					centeredTitleAttributes.SetValueForKey (shadow, NSAttributedString.ShadowAttributeName);
					centeredTitleAttributes.SetValueForKey (paraphStyle, NSAttributedString.ParagraphStyleAttributeName);
				}

				var attrString = new NSAttributedString (title, centered ? centeredTitleAttributes : titleAttributes);
				var textSize = attrString.Size;

				//check if we need two lines to draw the text
				var twoLines = title.Contains ("\n");
				if (!twoLines)
					twoLines = textSize.Width > frame.Size.Width && title.Contains (" ");

				//if so, we need to adjust the size to center vertically
				if (twoLines)
					textSize.Height += 38;

				if (!centered)
					drawFrame.Inflate (-15, 0);

				//center vertically
				var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f;
				var drawFrameHeight = drawFrame.Size.Height;
				drawFrame.Size = new CGSize (drawFrame.Size.Width, drawFrame.Size.Height - dy);
				attrString.DrawString (drawFrame);
			}

			texture.UnlockFocus ();

			//set the created image as the diffuse texture of our 3D box
			var front = SCNMaterial.Create ();
			front.Diffuse.Contents = texture;
			front.LocksAmbientWithDiffuse = true;

			//use a lighter color for the chamfer and sides
			var sides = SCNMaterial.Create ();
			sides.Diffuse.Contents = lightColor;
			node.Geometry.Materials = new SCNMaterial[] {
				front,
				sides,
				sides,
				sides,
				sides
			};

			return node;
		}
Exemple #18
0
        public override void DrawRect(CGRect dirtyRect)
        {
            if (Gradient != null)
            {
                Gradient.DrawInRect(dirtyRect, GradientAngle);
            }

            // -----------------------------------------
            nfloat textOffset   = 0f;
            nfloat imageXOffset = 0f;
            nfloat imageWidth   = 0f;

            if (Image != null)
            {
                if (Image.Size.Height > dirtyRect.Height)
                {
                    Image.Size = new CGSize(Image.Size.Height, dirtyRect.Height);
                }
                if (Image.Size.Width > dirtyRect.Width)
                {
                    Image.Size = new CGSize(dirtyRect.Width, Image.Size.Width);
                }

                imageWidth = Image.Size.Width;

                nfloat minXOffset = (dirtyRect.Height - Image.Size.Height) / 2f;

                imageXOffset = CornerRadius;
                if (imageXOffset < minXOffset)
                {
                    imageXOffset = minXOffset;
                }

                if (AttributedTitle == null)
                {
                    imageXOffset = dirtyRect.Width / 2f - Image.Size.Width / 2f;
                }
                else if (IconLocation == IconLocationEnum.Right_BeforeCenteredText)
                {
                    imageXOffset = dirtyRect.Width / 2f - AttributedTitle.Size.Width / 2f - Image.Size.Width - minXOffset / 2f;
                }
                else if (IconLocation == IconLocationEnum.Left_AfterCenteredText)
                {
                    imageXOffset = dirtyRect.Width / 2f + AttributedTitle.Size.Width / 2f + minXOffset / 2f;
                }
                else if (IconLocation == IconLocationEnum.Right_AfterCenteredText)
                {
                    imageXOffset = dirtyRect.Width - minXOffset / 2f - Image.Size.Width;
                }
                else if (IconLocation == IconLocationEnum.Right)
                {
                    nfloat space = (dirtyRect.Width - AttributedTitle.Size.Width - Image.Size.Width) / 3;
                    textOffset   = space;
                    imageXOffset = space + AttributedTitle.Size.Width + space;
                }
                else if (IconLocation == IconLocationEnum.Left)
                {
                    nfloat space = (dirtyRect.Width - AttributedTitle.Size.Width - Image.Size.Width) / 3;
                    imageXOffset = space;
                    textOffset   = space + Image.Size.Width + space;
                }

                CGRect imgRect = new CGRect(dirtyRect.X + imageXOffset,
                                            dirtyRect.Y + dirtyRect.Height / 2f - Image.Size.Height / 2f,
                                            Image.Size.Width,
                                            Image.Size.Height);
                Image.Draw(imgRect);
            }

            if (AttributedTitle != null)
            {
                if (IconLocation == IconLocationEnum.Right_BeforeCenteredText || IconLocation == IconLocationEnum.Left_BeforeCenteredText)
                {
                    if ((imageXOffset + imageWidth) > (dirtyRect.Width - AttributedTitle.Size.Width) / 2f)
                    {
                        textOffset = imageXOffset + imageWidth;
                    }
                }

                CGRect titleRect = new CGRect(dirtyRect.X + textOffset,
                                              dirtyRect.Y + dirtyRect.Height / 2f - AttributedTitle.Size.Height / 2f - 1f,
                                              dirtyRect.Width - textOffset,
                                              AttributedTitle.Size.Height);

                this.AttributedTitle.DrawInRect(titleRect);
            }

            if (Highlighted)
            {
                NSColor fillColor = HighlitedColorOverlay;
                if (fillColor == null)
                {
                    fillColor = NSColor.FromRgba(0, 0, 0, 0.1f);
                }
                fillColor.Set();

                NSBezierPath highlitedFill = new NSBezierPath();
                highlitedFill.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
                highlitedFill.Fill();
            }

            if (!this.Enabled && DoNotChangeColorWhenDisabled != true)
            {
                NSColor fillColor = HighlitedColorOverlay;
                if (fillColor == null)
                {
                    fillColor = NSColor.FromRgba(0, 0, 0, 0.1f);
                }
                fillColor.Set();

                NSBezierPath highlitedFill = new NSBezierPath();
                highlitedFill.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
                highlitedFill.Fill();
            }
            // -----------------------------------------
            //base.DrawRect (dirtyRect);

            if (!Highlighted && BorderShadow != null)
            {
                BorderShadow.Set();
            }


            NSBezierPath bounds = new NSBezierPath();

            bounds.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius);
            bounds.AddClip();

            bounds.LineWidth = BorderLineWidth;

            if (BorderColor != null)
            {
                BorderColor.SetStroke();
            }

            bounds.Stroke();
        }
Exemple #19
0
 private void DrawLine(NSColor color, PointF p1, PointF p2)
 {
     color.Set();
     NSBezierPath.StrokeLine(Invert(p1), Invert(p2));
 }
Exemple #20
0
        public static SCNNode SCBoxNode(string title, CGRect frame, NSColor color, float cornerRadius, bool centered)
        {
            NSMutableDictionary titleAttributes         = null;
            NSMutableDictionary centeredTitleAttributes = null;

            // create and extrude a bezier path to build the box
            var path = NSBezierPath.FromRoundedRect(frame, cornerRadius, cornerRadius);

            path.Flatness = 0.05f;

            var shape = SCNShape.Create(path, 20);

            shape.ChamferRadius = 0.0f;

            var node = SCNNode.Create();

            node.Geometry = shape;

            // create an image and fill with the color and text
            var textureSize = new CGSize();

            textureSize.Width  = (float)Math.Ceiling((double)frame.Size.Width * 1.5);
            textureSize.Height = (float)Math.Ceiling((double)frame.Size.Height * 1.5);

            var texture = new NSImage(textureSize);

            texture.LockFocus();

            var drawFrame = new CGRect(0, 0, textureSize.Width, textureSize.Height);

            nfloat hue, saturation, brightness, alpha;

            (color.UsingColorSpace(NSColorSpace.DeviceRGBColorSpace)).GetHsba(out hue, out saturation, out brightness, out alpha);
            var lightColor = NSColor.FromDeviceHsba(hue, saturation - 0.2f, brightness + 0.3f, alpha);

            lightColor.Set();

            NSGraphics.RectFill(drawFrame);

            NSBezierPath fillpath = null;

            if (cornerRadius == 0 && centered == false)
            {
                //special case for the "labs" slide
                drawFrame.Offset(0, -2);
                fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius);
            }
            else
            {
                drawFrame.Inflate(-3, -3);
                fillpath = NSBezierPath.FromRoundedRect(drawFrame, cornerRadius, cornerRadius);
            }

            color.Set();
            fillpath.Fill();

            // draw the title if any
            if (title != null)
            {
                if (titleAttributes == null)
                {
                    var paraphStyle = new NSMutableParagraphStyle();
                    paraphStyle.LineBreakMode     = NSLineBreakMode.ByWordWrapping;
                    paraphStyle.Alignment         = NSTextAlignment.Center;
                    paraphStyle.MinimumLineHeight = 38;
                    paraphStyle.MaximumLineHeight = 38;

                    var font = NSFont.FromFontName("Myriad Set Semibold", 34) != null?NSFont.FromFontName("Myriad Set Semibold", 34) : NSFont.FromFontName("Avenir Medium", 34);

                    var shadow = new NSShadow();
                    shadow.ShadowOffset     = new CGSize(0, -2);
                    shadow.ShadowBlurRadius = 4;
                    shadow.ShadowColor      = NSColor.FromDeviceWhite(0.0f, 0.5f);

                    titleAttributes = new NSMutableDictionary();
                    titleAttributes.SetValueForKey(font, NSAttributedString.FontAttributeName);
                    titleAttributes.SetValueForKey(NSColor.White, NSAttributedString.ForegroundColorAttributeName);
                    titleAttributes.SetValueForKey(shadow, NSAttributedString.ShadowAttributeName);
                    titleAttributes.SetValueForKey(paraphStyle, NSAttributedString.ParagraphStyleAttributeName);

                    var centeredParaphStyle = (NSMutableParagraphStyle)paraphStyle.MutableCopy();
                    centeredParaphStyle.Alignment = NSTextAlignment.Center;

                    centeredTitleAttributes = new NSMutableDictionary();
                    centeredTitleAttributes.SetValueForKey(font, NSAttributedString.FontAttributeName);
                    centeredTitleAttributes.SetValueForKey(NSColor.White, NSAttributedString.ForegroundColorAttributeName);
                    centeredTitleAttributes.SetValueForKey(shadow, NSAttributedString.ShadowAttributeName);
                    centeredTitleAttributes.SetValueForKey(paraphStyle, NSAttributedString.ParagraphStyleAttributeName);
                }

                var attrString = new NSAttributedString(title, centered ? centeredTitleAttributes : titleAttributes);
                var textSize   = attrString.Size;

                //check if we need two lines to draw the text
                var twoLines = title.Contains("\n");
                if (!twoLines)
                {
                    twoLines = textSize.Width > frame.Size.Width && title.Contains(" ");
                }

                //if so, we need to adjust the size to center vertically
                if (twoLines)
                {
                    textSize.Height += 38;
                }

                if (!centered)
                {
                    drawFrame.Inflate(-15, 0);
                }

                //center vertically
                var dy = (drawFrame.Size.Height - textSize.Height) * 0.5f;
                var drawFrameHeight = drawFrame.Size.Height;
                drawFrame.Size = new CGSize(drawFrame.Size.Width, drawFrame.Size.Height - dy);
                attrString.DrawString(drawFrame);
            }

            texture.UnlockFocus();

            //set the created image as the diffuse texture of our 3D box
            var front = SCNMaterial.Create();

            front.Diffuse.Contents        = texture;
            front.LocksAmbientWithDiffuse = true;

            //use a lighter color for the chamfer and sides
            var sides = SCNMaterial.Create();

            sides.Diffuse.Contents  = lightColor;
            node.Geometry.Materials = new SCNMaterial[] {
                front,
                sides,
                sides,
                sides,
                sides
            };

            return(node);
        }