public override void DrawRect(CGRect dirtyRect) { base.DrawRect(dirtyRect); // Use Core Graphic routines to draw our UI NSBezierPath path = new NSBezierPath(); foreach (var p in _paths) { path.MoveTo(p.Item1); path.LineTo(p.Item2); } foreach (var n in _nodes) { path.AppendPathWithOvalInRect(new CGRect( n.X - NodeRadius, n.Y - NodeRadius, 2 * NodeRadius, 2 * NodeRadius)); } NSColor.Cyan.SetStroke(); path.Stroke(); NSColor.Orange.SetFill(); path.Fill(); }
public override void DrawRect(RectangleF dirtyRect) { base.DrawRect(dirtyRect); NSBezierPath path = new NSBezierPath { LineWidth = 1, }; var square = GetSquare(Bounds, 6); path.AppendPathWithOvalInRect(square); NSColor.Black.SetStroke(); path.Stroke(); var radius = square.Width / 2; var center = new PointF { X = Bounds.Width / 2, Y = Bounds.Height / 2, }; DrawHand(path, center, GetRadians(date_time.Hour, 24), radius * hour_hand_radius); DrawHand(path, center, GetRadians(date_time.Minute, 60), radius * minute_hand_radius); DrawHand(path, center, GetRadians(date_time.Second, 60), radius); }
public void CreateRandomOvals() { for (nint i = 0; i < 25; i++) { CGRect rect = new CGRect(mRandom.Next((int)this.Bounds.Width), mRandom.Next((int)this.Bounds.Height), mRandom.Next(200), mRandom.Next(200)); mPath.AppendPathWithOvalInRect(rect); } }
NSBezierPath CreatePathForOval(CGRect bounds) { CGRect rect = new CGRect(bounds.X + Offset, bounds.Y + Offset, bounds.Width - (2 * Offset), bounds.Height - (2 * Offset)); rect.X += StrokeWidth / 2; rect.Y += StrokeWidth / 2; rect.Size = new CGSize(rect.Size.Width - StrokeWidth / 2, rect.Size.Height - StrokeWidth / 2); NSBezierPath path = new NSBezierPath(); path.AppendPathWithOvalInRect(rect); path.LineWidth = StrokeWidth; return(path); }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { mPath.RemoveAllPoints(); CGRect bounds = this.Bounds; // Fill view with green NSColor.Green.Set(); NSBezierPath.FillRect(bounds); NSColor.White.Set(); foreach (Oval oval in Ovals) { mPath.AppendPathWithOvalInRect(oval.Rect); } mPath.Stroke(); }
NSBezierPath CreatePathForOval (CGRect bounds) { CGRect rect = new CGRect (bounds.X + Offset, bounds.Y + Offset, bounds.Width - (2 * Offset), bounds.Height - (2 * Offset)); rect.X += StrokeWidth / 2; rect.Y += StrokeWidth / 2; rect.Size = new CGSize (rect.Size.Width - StrokeWidth / 2, rect.Size.Height - StrokeWidth / 2); NSBezierPath path = new NSBezierPath (); path.AppendPathWithOvalInRect (rect); path.LineWidth = StrokeWidth; return path; }
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()); }