public override void DrawWithFrame(CGRect cellFrame, NSView inView) { if (BetterBackgroundColor != null) { BetterBackgroundColor.SetFill(); NSGraphics.RectFill(cellFrame); } base.DrawWithFrame(cellFrame, inView); }
public override void DrawRect(CGRect dirtyRect) { if (BackgroundColor != null && BackgroundColor.AlphaComponent > 0) { BackgroundColor.Set(); NSGraphics.RectFill(dirtyRect); } base.DrawRect(dirtyRect); }
public override void DrawRect(CGRect dirtyRect) { NSGraphicsContext.GlobalSaveGraphicsState(); NSColor.White.Set(); NSGraphics.RectFill(dirtyRect); Subviews[1].Hidden = !this.IsSelected; Subviews [2].Hidden = !this.IsSelected; NSGraphicsContext.GlobalRestoreGraphicsState(); }
public override void DrawRect(System.Drawing.RectangleF dirtyRect) { dirtyRect.Inflate(-1, -1); if (selected) { var color = NSColor.SelectedControl; color.Set(); NSGraphics.RectFill(dirtyRect); } }
public override void Draw(PdfDisplayBox box) { //base.Draw (box); CGRect sourceRect = new CGRect(0, 0, 0, 0); CGRect topHalf; CGRect destRect; // Drag image. // ........... // Source rectangle. sourceRect.Size = PdfImage.Size; // Represent the top half of the page. topHalf = GetBoundsForBox(box); Utility.ColorWithHexColorValue("#ffffff", 1.0f).Set(); NSGraphics.RectFill(topHalf); // Scale and center image within top half of page. destRect = sourceRect; destRect.Height -= 120; destRect.Y += 60; // Draw. //Console.WriteLine("left:{0},top:{1},width:{2},height:{3}",destRect.X,destRect.Y,destRect.Width,destRect.Height); PdfImage.DrawInRect(destRect, new CGRect(0, 0, 0, 0), NSCompositingOperation.SourceOver, 1.0f); // Draw name. // ........... destRect = GetBoundsForBox(box); destRect.Y = destRect.Height - 44.0f; destRect.Height = 34.0f; destRect.X = 30.0f; destRect.Width -= 60.0f; // Draw label. NSStringAttributes attributes = new NSStringAttributes(); attributes.Font = NSFont.SystemFontOfSize(11); Label.DrawInRect(destRect, attributes); // Draw name. // ........... destRect = GetBoundsForBox(box); destRect.Y = 10.0f; destRect.Height = 17.0f; destRect.X = 30.0f; destRect.Width -= 60.0f; PageFooter.DrawInRect(destRect, attributes); }
public override void DrawRect(CGRect dirtyRect) { NSColor.Clear.Set(); NSGraphics.RectFill(Frame); var image = Window.AlphaValue > 0.7 ? circle : pentagon; image.Draw(new CGPoint(0, 0), Frame, NSCompositingOperation.SourceOver, 1); NeedsDisplay = true; Window.InvalidateShadow(); }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { NSColor.Green.SetFill(); NSGraphics.RectFill(this.Bounds); NSMutableAttributedString attributes = new NSMutableAttributedString("Hello, World."); attributes.AddAttribute(NSStringAttributeKey.Font, NSFont.FromFontName("Helvetica", 26), new NSRange(0, 13)); attributes.AddAttribute(NSStringAttributeKey.ForegroundColor, NSColor.Brown, new NSRange(0, 13)); attributes.DrawAtPoint(new CoreGraphics.CGPoint(0, 0)); }
public override void DrawRect(CGRect dirtyRect) { if (Handler.HasFocus) { NSGraphicsContext.CurrentContext.SaveGraphicsState(); GraphicsExtensions.SetFocusRingStyle(NSFocusRingPlacement.RingOnly); NSGraphics.RectFill(this.Bounds); NSGraphicsContext.CurrentContext.RestoreGraphicsState(); } base.DrawRect(dirtyRect); }
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); }
/// <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 backgroundColor = Handler.BackgroundColor; if (backgroundColor != Colors.Transparent) { backgroundColor.ToNSUI().Set(); NSGraphics.RectFill(clipRect); } else { base.DrawBackground(clipRect); } }
public override void DrawWithFrame(RectangleF cellFrame, NSView inView) { borderColor.SetFill(); NSGraphics.RectFill( new RectangleF( cellFrame.X + padding / 2, cellFrame.Y + padding / 2, cellFrame.Width - padding, cellFrame.Height - padding ) ); base.DrawWithFrame(cellFrame, inView); }
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); }
void DrawTitleRect() { Utility.ColorWithHexColorValue(BookInfo.ColorSecondary, 1.0f).Set(); NSGraphics.RectFill(titleBorderFrame); var oPath = NSBezierPath.FromRect(wideBorderLineFrame); Utility.ColorWithHexColorValue(BookInfo.FontColor, 1.0f).Set(); oPath.LineWidth = 3; oPath.Stroke(); var iPath = NSBezierPath.FromRect(thinBorderLineFrame); Utility.ColorWithHexColorValue(BookInfo.ColorSecondary, 1.0f).Set(); iPath.LineWidth = 1; iPath.Stroke(); }
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 h = Handler; if (h == null) { return; } var size = h._fontUtility.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 override void DrawRect(CGRect dirtyRect) { var nscontext = NSGraphicsContext.CurrentContext; var isFirstResponder = Window.FirstResponder == this; if (DrawsBackground) { var context = nscontext.GraphicsPort; context.SetFillColor(BackgroundColor.ToCG()); context.FillRect(dirtyRect); } var cellFrame = Bounds; var handler = Handler; if (handler == null) { return; } var graphicsHandler = new GraphicsHandler(null, nscontext, (float)cellFrame.Height, flipped: true); using (var graphics = new Graphics(graphicsHandler)) { var rowView = this.Superview as NSTableRowView; var state = CellStates.None; if (rowView != null && rowView.Selected) { state |= CellStates.Selected; } if (isFirstResponder) { state |= CellStates.Editing; SetKeyboardFocusRingNeedsDisplay(cellFrame); nscontext.SaveGraphicsState(); GraphicsExtensions.SetFocusRingStyle(NSFocusRingPlacement.RingOnly); NSGraphics.RectFill(cellFrame); nscontext.RestoreGraphicsState(); } var item = val as EtoCellValue; #pragma warning disable 618 var args = new DrawableCellPaintEventArgs(graphics, cellFrame.ToEto(), state, item != null ? item.Item : null); handler.Callback.OnPaint(handler.Widget, args); #pragma warning restore 618 } }
public override void DrawRect(RectangleF dirtyRect) { NSColor.White.Set(); NSGraphics.RectFill(dirtyRect); foreach (ColorRect thisRect in rects) { if (thisRect.Frame.IntersectsWith(dirtyRect)) { thisRect.DrawRect(dirtyRect, thisRect == selectedItem); } } // 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)); }
private void DrawBaselineSeparator(CGRect separatorFrame) { var window = (AppStoreWindow)Window; var drawsAsMainWindow = window.DrawsAsMainWindow(); var bottomColor = drawsAsMainWindow ? window.BaselineSeparatorColor : window.InactiveBaselineSeparatorColor; if (bottomColor == default(NSColor)) { bottomColor = AppStoreWindow.DefaultBaselineSeparatorColor(drawsAsMainWindow); } bottomColor.Set(); NSGraphics.RectFill(separatorFrame); separatorFrame.Y += separatorFrame.Height; separatorFrame.Height = 1.0f; NSColor.FromDeviceWhite(1.0f, 0.12f).SetFill(); NSBezierPath.FromRect(separatorFrame).Fill(); }
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)); } }
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 DrawRect(CoreGraphics.CGRect dirtyRect) { NSColor.Magenta.Set(); NSGraphics.RectFill(Bounds); }
public override void DrawFocusRingMask() { 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 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); }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { NSColor.Gray.SetFill(); NSGraphics.RectFill(this.Bounds); }
// // void DrawCoverRect() { Utility.ColorWithHexColorValue(BookInfo.ColorPrimary, 1.0f).Set(); NSGraphics.RectFill(coverFrame); }