public override void DrawRect(CoreGraphics.CGRect dirtyRect) { if (DarkTheme) { NSColor.Clear.Set(); NSGraphics.RectFill(dirtyRect, NSCompositingOperation.SourceOver); return; } else { NSColor.FromRgb(245, 245, 245).Set(); NSBezierPath.FillRect(dirtyRect); } if (dirtyRect.Y == 0 && !DarkTheme) { NSColor.FromRgb(233, 233, 233).Set(); NSBezierPath.FillRect(new CGRect(dirtyRect.X, 0, dirtyRect.Width, 1)); } }
/// <summary> /// The area to the right and below the rows is not filled with the background /// color. This fixes that. See http://orangejuiceliberationfront.com/themeing-nstableview/ /// </summary> public override void DrawBackground(CGRect clipRect) { var h = Handler; if (h == null) { return; } var backgroundColor = h.BackgroundColor; if (backgroundColor != Colors.Transparent) { backgroundColor.ToNSUI().Set(); NSGraphics.RectFill(clipRect); } else { base.DrawBackground(clipRect); } }
public override void DrawRect(CGRect dirtyRect) { CGRect bounds = Bounds; CGSize stripeSize = bounds.Size; stripeSize.Width = bounds.Width / 10.0f; CGRect stripe = bounds; stripe.Size = stripeSize; NSColor[] colors = new NSColor[2] { NSColor.White, NSColor.Blue }; for (int i = 0; i < 10; i++) { colors[i % 2].Set(); NSGraphics.RectFill(stripe); CGPoint origin = stripe.Location; origin.X += stripe.Size.Width; stripe.Location = origin; } }
// 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); }
public override void DrawRect(CGRect dirtyRect) { NSColor.White.Set(); NSGraphics.RectFill(this.VisibleRect()); OnPaint(); // draw a little cross in our view /* NSColor.Black.Set (); * NSBezierPath.StrokeLine (new PointF (-10.0f,0.0f), new PointF (10.0f,0.0f)); * NSBezierPath.StrokeLine (new PointF (0.0f,-10.0f), new PointF (0.0f,10.0f)); * * NSColor.Yellow.Set(); * NSGraphics.RectFill(new RectangleF(20,20,40,60)); * NSColor.Black.Set (); * NSGraphics.FrameRect(new RectangleF(20, 20, 40, 60)); * * var objects = new object [] { NSFont.FromFontName ("Menlo", 48) }; * var keys = new object [] { NSAttributedString.FontAttributeName }; * var attributes = NSDictionary.FromObjectsAndKeys (objects, keys); * NSString tmp = new NSString("A label"); * tmp.DrawString(new PointF(150, 150), attributes); * NSGraphics.FrameRect(new RectangleF(150, 150, 40, 48));*/ }
public override void DrawWithFrame(CGRect cellFrame, NSView inView) { if (DrawsBackground && BackgroundColor != null && BackgroundColor.AlphaComponent > 0) { BackgroundColor.Set(); NSGraphics.RectFill(cellFrame); } base.DrawWithFrame(cellFrame, inView); var progress = FloatValue; if (float.IsNaN((float)progress)) { return; } string progressText = (int)(progress * 100f) + "%"; var str = new NSMutableAttributedString(progressText, NSDictionary.FromObjectAndKey(TextColor, NSStringAttributeKey.ForegroundColor)); var range = new NSRange(0, str.Length); if (Font != null) { str.AddAttributes(NSDictionary.FromObjectAndKey(Font, NSStringAttributeKey.Font), range); } var size = FontExtensions.MeasureString(str, cellFrame.Size.ToEto()); var rect = cellFrame.ToEto(); var offset = (rect.Size - size) / 2; if (!NSGraphicsContext.CurrentContext.IsFlipped) { offset.Height = -offset.Height; } rect.Offset(offset); str.DrawString(rect.ToNS()); }
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); }
// // void DrawCoverRect() { Utility.ColorWithHexColorValue(BookInfo.ColorPrimary, 1.0f).Set(); NSGraphics.RectFill(coverFrame); }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { NSColor.Gray.SetFill(); NSGraphics.RectFill(this.Bounds); }
private void OnPaint() { int textHeight = (int)(this.Frame.Height / 15); var objects = new object [] { NSFont.FromFontName("Menlo", textHeight) }; var keys = new object [] { "Helvetica" }; NSDictionary txtFont = NSDictionary.FromObjectsAndKeys(objects, keys); if ((theData != null) && (theData.Count > 0)) { // calculate sizes int colWidth = (int)(this.Frame.Width / (theData.Count + 2)); int maxval = 1; foreach (KeyValuePair <string, int> dp in theData) { maxval = (dp.Value > maxval) ? dp.Value : maxval; } int baseline = (int)(2 * textHeight); float heightMultiplier = ((float)this.Frame.Height - (4 * textHeight)) / maxval; CGSize stringSize = textSize(maxval.ToString(), txtFont); int lxpos = colWidth - (int)stringSize.Width - 10; int lypos = (int)(baseline + (heightMultiplier * maxval) - (stringSize.Height / 2)); DrawString(maxval.ToString(), txtFont, NSColor.Black, lxpos, lypos); NSColor.Black.Set(); NSBezierPath.StrokeLine(new CGPoint(colWidth, baseline), new CGPoint(colWidth * (theData.Count + 1), baseline)); NSBezierPath.StrokeLine(new CGPoint(colWidth, baseline), new CGPoint(colWidth, baseline + (heightMultiplier * maxval))); NSBezierPath.StrokeLine(new CGPoint(colWidth - 5, baseline + (heightMultiplier * maxval)), new CGPoint(colWidth, baseline + (heightMultiplier * maxval))); DrawString(title, txtFont, NSColor.Black, 5, lypos + (int)stringSize.Height); int colPos = 0; foreach (KeyValuePair <string, int> dp in theData) { colPos += colWidth; int colCentre = colPos + colWidth / 2; stringSize = textSize(dp.Key, txtFont); lxpos = colCentre - (int)(stringSize.Width / 2); lypos = baseline - -textHeight - textHeight / 4; DrawString(dp.Key, txtFont, NSColor.Black, lxpos, lypos); if (dp.Value > 0) { CGRect colRect = new CGRect(colPos, baseline, colWidth - 1, heightMultiplier * dp.Value); NSColor.Blue.Set(); NSGraphics.RectFill(colRect); NSColor.Black.Set(); NSGraphics.FrameRect(colRect); //e.Graphics.FillRectangle(Brushes.Blue, colPos, baseline - heightMultiplier * dp.Value, colWidth - 1, heightMultiplier * dp.Value); } } } else { CGSize stringSize = textSize("Ay", txtFont); int lypos = (int)this.Frame.Height - 2 * (int)stringSize.Height; if (title != null) { DrawString(title, txtFont, NSColor.Black, 5, lypos + (int)stringSize.Height); } DrawString("No data to display", txtFont, NSColor.Black, 5, lypos + 2 * (int)stringSize.Height); } }
public override void DrawFocusRingMask() { NSGraphics.RectFill(this.Bounds); }
public override void DrawRect(CGRect dirtyRect) { NSColor.SecondaryLabelColor.Set(); NSGraphics.FrameRectWithWidth(Bounds, 10); }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { NSColor.Magenta.Set(); NSGraphics.RectFill(Bounds); }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { NSColor.Red.Set(); NSGraphics.FrameRect(Bounds); }