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()); }
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 override void DrawWithFrame(CGRect cellFrame, NSView inView) { if (IdeApp.Preferences.UserInterfaceTheme == Theme.Dark) { var inset = cellFrame.Inset(0.25f, 0.25f); inset = new CGRect(inset.X, inset.Y + 2, inset.Width, inset.Height - 2); var path = NSBezierPath.FromRoundedRect(inset, 3, 3); path.LineWidth = 0.5f; Styles.DarkBorderColor.ToNSColor().SetStroke(); path.Stroke(); inset = new CGRect(inset.X + 3, inset.Y, inset.Width, inset.Height); DrawInteriorWithFrame(inset, inView); path = new NSBezierPath(); // Draw the separators for (int segment = 1; segment < SegmentCount; segment++) { nfloat x = inset.X + (33 * segment); path.MoveTo(new CGPoint(x, 0)); path.LineTo(new CGPoint(x, inset.Y + inset.Height)); } path.LineWidth = 0.5f; path.Stroke(); } else { base.DrawWithFrame(cellFrame, inView); } }
private NSImage CreateImageWithColor(string colorValue) { NSGraphicsContext.GlobalSaveGraphicsState(); CGSize size = new CGSize(12, 12); NSImage tintImage = new NSImage(size); tintImage.LockFocus(); float cornerRadius = 5f; CGRect rect = new CGRect(0, 0, 10, 10); NSBezierPath path = NSBezierPath.FromRoundedRect(rect, cornerRadius, cornerRadius); if (string.IsNullOrEmpty(colorValue)) { NSColor.Grid.Set(); path.Stroke(); } else { Utility.ColorWithHexColorValue(colorValue, 1.0f).SetFill(); path.Fill(); } tintImage.UnlockFocus(); CGContext context = NSGraphicsContext.CurrentContext.CGContext; return(tintImage); }
public void DrawRect(CGRect aRect, bool selected) { NSGraphics.RectClip(aRect); aRect.Intersect(Frame); Color.Set(); NSGraphics.RectFill(aRect); if (selected) { NSColor.Black.Set(); NSGraphics.FrameRectWithWidth(Frame, 4.0f); } if (IsLocked) { float xSize = (Frame.Width > 10.0f) ? 5.0f : 3.0f; NSBezierPath path = new NSBezierPath(); NSColor.Black.Set(); path.LineWidth = 3.0f; path.MoveTo(new CGPoint(MidX(Frame) - xSize, MidY(Frame) - xSize)); path.LineTo(new CGPoint(MidX(Frame) + xSize, MidY(Frame) + xSize)); path.MoveTo(new CGPoint(MidX(Frame) - xSize, MidY(Frame) + xSize)); path.LineTo(new CGPoint(MidX(Frame) + xSize, MidY(Frame) - xSize)); path.Stroke(); } }
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 DrawWithFrame (CGRect cellFrame, NSView inView) { if (IdeApp.Preferences.UserInterfaceTheme == Theme.Dark) { var inset = cellFrame.Inset (0.25f, 0.25f); inset = new CGRect (inset.X, inset.Y + 2, inset.Width, inset.Height - 2); var path = NSBezierPath.FromRoundedRect (inset, 3, 3); path.LineWidth = 0.5f; Styles.DarkBorderColor.ToNSColor ().SetStroke (); path.Stroke (); inset = new CGRect (inset.X + 3, inset.Y, inset.Width, inset.Height); DrawInteriorWithFrame (inset, inView); path = new NSBezierPath (); // Draw the separators for (int segment = 1; segment < SegmentCount; segment++) { nfloat x = inset.X + (33 * segment); path.MoveTo (new CGPoint (x, 0)); path.LineTo (new CGPoint (x, inset.Y + inset.Height)); } path.LineWidth = 0.5f; path.Stroke (); } else { base.DrawWithFrame (cellFrame, inView); } }
public override void DrawRect(NSRect aRect) { // draw background NSRect slotRect = RectForPart(NSScrollerPart.NSScrollerKnobSlot); NSColor.BlackColor.Set(); AppKitFramework.NSRectFill(slotRect); AppKitFramework.NSRectFill(aRect); NSColor.ColorWithCalibratedWhiteAlpha(0.1f, 1.0f).Set(); NSBezierPath path = new NSBezierPath(); path.AppendBezierPathWithRoundedRectXRadiusYRadius(slotRect, 2.0f, 2.0f); path.LineWidth = 3.0f; path.Stroke(); path.Release(); // draw know DrawKnob(); // draw the arrow button backgrounds DrawArrow(NSScrollerPart.NSScrollerIncrementLine); DrawArrow(NSScrollerPart.NSScrollerDecrementLine); }
public override void DrawRect(CGRect dirtyRect) { //TODO: uncomment code https://bugzilla.xamarin.com/show_bug.cgi?id=24144 // if (EffectiveAppearance.AllowsVibrancy) { // // Vibrant drawing codepath. // NSColor.LabelColor.Set (); // NSBezierPath path = NSBezierPath.FromOvalInRect (Bounds.Inset (5, 5)); // path.LineWidth = 5; // path.Stroke (); // // NSColor.SecondaryLabelColor.Set (); // path = NSBezierPath.FromOvalInRect (Bounds.Inset (10, 10)); // path.Fill (); // } else { NSColor.Red.Set(); NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5f, 5f)); path.LineWidth = 5; path.Stroke(); NSColor.Purple.Set(); path = NSBezierPath.FromOvalInRect(Bounds.Inset(10f, 10f)); path.Fill(); // } }
public void DrawLayer(CALayer layer, CoreGraphics.CGContext context) { NSGraphicsContext.GlobalSaveGraphicsState(); NSGraphicsContext graphicsContext = NSGraphicsContext.FromGraphicsPort(context, true); NSGraphicsContext.CurrentContext = graphicsContext; NSBezierPath path = new NSBezierPath(); //ベジェ曲線 var x1 = this.Frame.Left; var y1 = this.Frame.Top; var x2 = this.Frame.Right; var y2 = this.Frame.Bottom; path.MoveTo(new CoreGraphics.CGPoint(x1, y1)); path.CurveTo(new CoreGraphics.CGPoint(x2, y1), new CoreGraphics.CGPoint(x1, y2), new CoreGraphics.CGPoint(x2, y2)); //背景は白 NSColor.White.Set(); path.Fill(); //線は青 NSColor.Blue.Set(); //線の太さ path.LineWidth = 2; path.Stroke(); NSGraphicsContext.GlobalRestoreGraphicsState(); }
public override void DrawRect(CGRect dirtyRect) { if (EffectiveAppearance.AllowsVibrancy) { // Vibrant drawing codepath. NSColor.LabelColor.Set(); NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5, 5)); path.LineWidth = 5; path.Stroke(); NSColor.SecondaryLabelColor.Set(); path = NSBezierPath.FromOvalInRect(Bounds.Inset(10, 10)); path.Fill(); } else { NSColor.Red.Set(); NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5f, 5f)); path.LineWidth = 5; path.Stroke(); NSColor.Purple.Set(); path = NSBezierPath.FromOvalInRect(Bounds.Inset(10f, 10f)); path.Fill(); } }
public override void DrawRect(CGRect dirtyRect) { CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort; context.SetFillColor(__BackgroundColor); context.FillRect(dirtyRect); base.DrawRect(dirtyRect); if (BorderLineWidth > 0) { NSBezierPath bounds = new NSBezierPath(); bounds.AppendPathWithRect(dirtyRect); bounds.AddClip(); bounds.LineWidth = BorderLineWidth; if (BorderColor != null) { BorderColor.SetStroke(); } bounds.Stroke(); } }
public override void DrawRow(nint row, CGRect clipRect) { if (row >= RowCount) { return; } base.DrawRow(row, clipRect); NSGraphicsContext.GlobalSaveGraphicsState(); NSGraphicsContext.CurrentContext.ShouldAntialias = false; CGRect rectRow = RectForRow(row); CGRect rectColumn = RectForColumn(0); CGRect rect = Frame; CGPoint start = new CGPoint(rectColumn.Left, rectRow.Top); CGPoint end = new CGPoint(rectRow.Right, rectRow.Top); var linePath = new NSBezierPath(); GridColor.Set(); linePath.MoveTo(start); linePath.LineTo(end); linePath.ClosePath(); linePath.Stroke(); NSGraphicsContext.GlobalRestoreGraphicsState(); }
public void DrawRect(CGRect aRect, bool selected) { NSGraphics.RectClip (aRect); aRect.Intersect (Frame); Color.Set (); NSGraphics.RectFill (aRect); if (selected) { NSColor.Black.Set (); NSGraphics.FrameRectWithWidth (Frame, 4.0f); } if (IsLocked){ float xSize = (Frame.Width > 10.0f) ? 5.0f : 3.0f; NSBezierPath path = new NSBezierPath (); NSColor.Black.Set (); path.LineWidth = 3.0f; path.MoveTo (new CGPoint (MidX (Frame) - xSize, MidY (Frame) - xSize)); path.LineTo (new CGPoint (MidX (Frame) + xSize, MidY (Frame) + xSize)); path.MoveTo (new CGPoint (MidX (Frame) - xSize, MidY (Frame) + xSize)); path.LineTo (new CGPoint (MidX (Frame) + xSize, MidY (Frame) - xSize)); path.Stroke (); } }
// void DrawBottomLine() { var linePath = new NSBezierPath(); Utility.ColorWithHexColorValue(BookInfo.FontColor, 1.0f).SetStroke(); linePath.LineWidth = 2; linePath.MoveTo(bottomLineTS); linePath.LineTo(bottomLineTE); linePath.ClosePath(); linePath.Stroke(); //var lineTPath = new NSBezierPath (); linePath.MoveTo(bottomLineBS); linePath.LineTo(bottomLineBE); linePath.ClosePath(); linePath.Stroke(); }
private void DrawArrow(NSScrollerPart aScrollPart) { NSRect rect = RectForPart(aScrollPart); // draw background NSColor.BlackColor.Set(); AppKitFramework.NSRectFill(rect); // draw button background if (aScrollPart == HitPart) { NSColor.WhiteColor.Set(); } else { NSColor.ColorWithCalibratedWhiteAlpha(0.1f, 1.0f).Set(); } NSBezierPath path = new NSBezierPath(); path.AppendBezierPathWithRoundedRectXRadiusYRadius(rect.InsetRect(1.0f, 1.0f), 2.0f, 2.0f); path.LineWidth = 2.0f; path.Stroke(); path.Release(); // draw arrow NSColor.WhiteColor.Set(); float arrowSize = 6.0f; NSRect arrowRect = new NSRect(rect.MidX - (arrowSize * 0.5f), rect.MidY - (arrowSize * 0.5f), arrowSize, arrowSize); path = new NSBezierPath(); if (aScrollPart == NSScrollerPart.NSScrollerDecrementLine) { path.MoveToPoint(new NSPoint(arrowRect.MinX, arrowRect.MaxY)); path.LineToPoint(new NSPoint(arrowRect.MaxX, arrowRect.MaxY)); path.LineToPoint(new NSPoint(arrowRect.MidX, arrowRect.MinY)); path.LineToPoint(new NSPoint(arrowRect.MinX, arrowRect.MaxY)); } else { path.MoveToPoint(new NSPoint(arrowRect.MinX, arrowRect.MinY)); path.LineToPoint(new NSPoint(arrowRect.MaxX, arrowRect.MinY)); path.LineToPoint(new NSPoint(arrowRect.MidX, arrowRect.MaxY)); path.LineToPoint(new NSPoint(arrowRect.MinX, arrowRect.MinY)); } path.ClosePath(); path.Fill(); path.Release(); }
private static void DrawHand(NSBezierPath path, PointF center, double radians, float radius) { path.MoveTo(center); path.LineTo(new PointF { X = center.X + (float)Math.Sin(radians) * radius, Y = center.Y + (float)Math.Cos(radians) * radius, }); path.Stroke(); }
public override void DrawRect(CGRect dirtyRect) { base.DrawRect(dirtyRect); var line = new NSBezierPath(); line.MoveTo(new CGPoint(Frame.Width / 2, 0)); line.LineTo(new CGPoint(Frame.Width / 2, Frame.Height)); line.LineWidth = 1; NSColor.Gray.Set(); line.Stroke(); }
public override void DrawRect(NSRect aRect) { float left = Bounds.MinX + iPadding; float right = Bounds.MaxX - iPadding; float top = Bounds.MaxY - iPadding - iAnchorHeight; float bottom = Bounds.MinY + iPadding + iAnchorHeight; NSBezierPath path = new NSBezierPath(); // start the path in the bottom left corner, just past the arc of the corner and go clockwise path.MoveToPoint(new NSPoint(left, bottom + iCornerRadius)); path.LineToPoint(new NSPoint(left, top - iCornerRadius)); path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(left, top), new NSPoint(left + iCornerRadius, top), iCornerRadius); if (iAnchorOnTop) { path.LineToPoint(new NSPoint(iAnchorApex - iAnchorWidth * 0.5f, top)); path.LineToPoint(new NSPoint(iAnchorApex, top + iAnchorHeight)); path.LineToPoint(new NSPoint(iAnchorApex + iAnchorWidth * 0.5f, top)); } path.LineToPoint(new NSPoint(right - iCornerRadius, top)); path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(right, top), new NSPoint(right, top - iCornerRadius), iCornerRadius); path.LineToPoint(new NSPoint(right, bottom + iCornerRadius)); path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(right, bottom), new NSPoint(right - iCornerRadius, bottom), iCornerRadius); if (!iAnchorOnTop) { path.LineToPoint(new NSPoint(iAnchorApex + iAnchorWidth * 0.5f, bottom)); path.LineToPoint(new NSPoint(iAnchorApex, bottom - iAnchorHeight)); path.LineToPoint(new NSPoint(iAnchorApex - iAnchorWidth * 0.5f, bottom)); } path.LineToPoint(new NSPoint(left + iCornerRadius, bottom)); path.AppendBezierPathWithArcFromPointToPointRadius(new NSPoint(left, bottom), new NSPoint(left, bottom + iCornerRadius), iCornerRadius); path.ClosePath(); NSColor.WhiteColor.SetStroke(); path.LineWidth = 4.0f; path.Stroke(); NSColor.ColorWithCalibratedWhiteAlpha(0.0f, 0.9f).SetFill(); path.Fill(); path.Release(); }
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(); }
public override void DrawRect(CGRect dirtyRect) { base.DrawRect(dirtyRect); StrokeColor.SetStroke(); var path = new NSBezierPath(); path.MoveTo(Start); path.LineTo(End); path.LineWidth = LineThickness; if (LineDash.Length > 0) { path.SetLineDash(LineDash.Select(w => w * LineThickness).ToArray(), 0); } path.Stroke(); }
/// <summary> /// We are using separate layer for higliting elements on a main view /// This method is highliting GUI element depends on current introduction step /// </summary> public void DrawLayer(NSView view, CGRect dirtyRect) { var bg = Colors.WindowBackground; NSColor fillColor = NSColor.FromRgba(bg.RedComponent, bg.GreenComponent, bg.BlueComponent, 0.4f); NSColor strokeColor = NSColor.FromRgb(50, 158, 230); nfloat strokeWidth = 2; if (__InotroductionStage != IntroductionStageEnum.Finished) { NSBezierPath fillRect = NSBezierPath.FromRect(dirtyRect); fillColor.SetFill(); fillRect.Fill(); } if (__InotroductionStage == IntroductionStageEnum.Firewall) { CGRect fwRect = __MainViewController.GetFirewallControlViewRect(); NSBezierPath firewallPath = NSBezierPath.FromRoundedRect(fwRect, fwRect.Height / 2, fwRect.Height / 2); firewallPath.LineWidth = strokeWidth; strokeColor.SetStroke(); firewallPath.Stroke(); } if (__InotroductionStage == IntroductionStageEnum.ConnectBtn) { // CONNECT BUTTON CGRect circleRect = __MainViewController.GetConnectButtonViewRect(); NSBezierPath connectBthPth = NSBezierPath.FromRoundedRect(circleRect, circleRect.Width / 2, circleRect.Height / 2); connectBthPth.LineWidth = strokeWidth; strokeColor.SetStroke(); connectBthPth.Stroke(); } if (__InotroductionStage == IntroductionStageEnum.Servers) { // SERVERS SELECTION CGRect serversRect = __MainViewController.GetServerSelectionViewRect(); serversRect = new CGRect(serversRect.X + 3, serversRect.Y + 3, serversRect.Width - 6, serversRect.Height - 6); NSBezierPath serversViewPath = NSBezierPath.FromRoundedRect(serversRect, 4, 4); serversViewPath.LineWidth = strokeWidth; strokeColor.SetStroke(); serversViewPath.Stroke(); } }
protected void DrawPath(NSBezierPath path) { NSColor.Black.SetStroke(); path.LineWidth = 3; path.Stroke(); NSColor.Red.SetStroke(); var boundsPath = NSBezierPath.FromRect(path.Bounds); boundsPath.LineWidth = 4; boundsPath.Stroke(); NSColor.Green.SetStroke(); var controlPointBoundsPath = NSBezierPath.FromRect(path.ControlPointBounds); controlPointBoundsPath.LineWidth = 2; controlPointBoundsPath.Stroke(); }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { var rect = this.Bounds; var x1 = rect.Left; var y1 = rect.Top; var x2 = rect.Right; var y2 = rect.Bottom; NSBezierPath path = new NSBezierPath(); path.MoveTo(new CoreGraphics.CGPoint(x1, y1)); path.CurveTo(new CoreGraphics.CGPoint(x2, y1), new CoreGraphics.CGPoint(x1, y2), new CoreGraphics.CGPoint(x2, y2)); path.LineWidth = 5; NSColor.Red.SetStroke(); path.Stroke(); }
public override void DrawRect(CGRect dirtyRect) { /* * Things look good no matter where the view is located; either a vibrant appearance or * a non-vibrant appearance. Since the view says YES to allowsVibrancy, everything drawn in * drawRect will be vibrant; all colors, images, etc. */ NSColor.FromDeviceWhite(0f, 0.85f).Set(); NSBezierPath path = NSBezierPath.FromOvalInRect(Bounds.Inset(5f, 5f)); path.LineWidth = 5; path.Stroke(); NSColor.FromDeviceWhite(0f, 0.48f).Set(); path = NSBezierPath.FromOvalInRect(Bounds.Inset(10f, 10f)); path.Fill(); }
private void DrawArc(float aStartValue, float aEndValue, bool aClockwise) { // The angles for this path: // 0 => along +ve x-axis // 90 => along +ve y-axis // i.e. +ve angles go anti-clockwise NSBezierPath path = new NSBezierPath(); path.LineWidth = iLineWidth; float startAngle = iZeroAngle - (360.0f * aStartValue / iMaxValue); float endAngle = iZeroAngle - (360.0f * aEndValue / iMaxValue); path.AppendBezierPathWithArcWithCenterRadiusStartAngleEndAngleClockwise( new NSPoint(Bounds.Width * 0.5f, Bounds.Height * 0.5f), iRadius, startAngle, endAngle, aClockwise); path.Stroke(); path.Release(); }
public override void DrawRect(CGRect dirtyRect) { base.DrawRect(dirtyRect); if (!Colors.IsDarkMode) { NSBezierPath betterBounds = new NSBezierPath(); betterBounds.AppendPathWithRoundedRect(dirtyRect, CornerRadius, CornerRadius); betterBounds.AddClip(); betterBounds.LineWidth = BorderLineWidth; if (BorderColor != null) { BorderColor.SetStroke(); } betterBounds.Stroke(); } }
public override void DrawRect(CoreGraphics.CGRect dirtyRect) { CGRect bounds = this.Bounds; // Fill view with green NSColor.Green.Set(); NSBezierPath.FillRect(bounds); // Draw the path in white NSColor.Red.Set(); mPath.Stroke(); if (mImages.Count > 0) { foreach (StretchImage image in mImages) { StretchImage drawImage = image.GetFlippedImage(); CGRect imageRect = new CGRect(0, 0, drawImage.Size.Width, drawImage.Size.Height); drawImage.DrawInRect(image.DrawingRect(), imageRect, NSCompositingOperation.SourceOver, image.Opacity); } } }
public override void DrawKnob(CGRect knobRect) { // Mimick the dimensions of the original slider knobRect.Width -= 6; knobRect.Height -= 6; knobRect.Y += 3; knobRect.X += 3; var radius = 7.5f; var path = new NSBezierPath(); path.AppendPathWithRoundedRect(knobRect, radius, radius); // Draw inside var knobColor = ThumbColor.IsDefault ? NSColor.ControlLightHighlight : ThumbColor.ToNSColor(); knobColor.SetFill(); path.Fill(); // Draw border NSColor.ControlShadow.SetStroke(); path.Stroke(); }
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 override void DrawKnob(CGRect knobRect) { // Mimick the dimensions of the original slider knobRect.Width -= 6; knobRect.Height -= 6; knobRect.Y += 3; knobRect.X += 3; var radius = 7.5f; var path = new NSBezierPath(); path.AppendPathWithRoundedRect(knobRect, radius, radius); // Draw inside var defaultKnobColor = NSColor.ControlLightHighlight; if (Forms.IsMojaveOrNewer) { defaultKnobColor = NSColor.Highlight; } var knobColor = ThumbColor.IsDefault ? defaultKnobColor : ThumbColor.ToNSColor(); knobColor.SetFill(); path.Fill(); // Draw border if (Forms.IsMojaveOrNewer) { NSColor.ControlShadow.SetStroke(); } else { NSColor.SeparatorColor.SetStroke(); } path.Stroke(); }
public static void DrawUISwitch(CGRect dirtyRect, bool isEnabled, bool isSwitchOn, int BorderWidth, NSColor SwitchOnBackgroundColor, NSColor SwitchOffBackgroundColor, NSColor SwitchOffBorderColor, NSColor InternalSwitcherColor, NSColor InternalSwitcherShadowColor ) { NSGraphicsContext context = NSGraphicsContext.CurrentContext; context.CGContext.SaveState(); NSColor switchOnBackgroundColor = SwitchOnBackgroundColor; NSColor switchOffBackgroundColor = SwitchOffBackgroundColor; NSColor switchOffBorderColor = SwitchOffBorderColor; NSColor internalSwitcherColor = InternalSwitcherColor; NSColor internalSwitcherShadowColor = InternalSwitcherShadowColor; if (isEnabled == false) { // if disabled - set background color darker switchOnBackgroundColor = SetColorDarker(switchOnBackgroundColor); switchOffBackgroundColor = SetColorDarker(switchOffBackgroundColor); switchOffBorderColor = SetColorDarker(switchOffBorderColor); internalSwitcherColor = SetColorDarker(internalSwitcherColor); internalSwitcherShadowColor = SetColorDarker(internalSwitcherShadowColor); } nfloat offset = dirtyRect.Height * 0.1f; dirtyRect = new CGRect(dirtyRect.X + offset, dirtyRect.Y + offset, dirtyRect.Width - offset * 2, dirtyRect.Height - offset * 2); // set backgrund color NSColor bodyColor = (isSwitchOn)? switchOnBackgroundColor : switchOffBackgroundColor; bodyColor.SetFill(); // draw background NSBezierPath bodyPath = NSBezierPath.FromRoundedRect(dirtyRect, dirtyRect.Height / 2, dirtyRect.Height / 2); bodyPath.Fill(); // draw border if (!isSwitchOn) { bodyPath.AddClip(); bodyPath.LineWidth = BorderWidth; if (switchOffBorderColor != null) { switchOffBorderColor.SetStroke(); } bodyPath.Stroke(); } //restore \ save context status context.CGContext.RestoreState(); context.CGContext.SaveState(); // DRAW CIRCLE CGRect circleRect; if (!isSwitchOn) { circleRect = new CGRect(dirtyRect.X, dirtyRect.Y, dirtyRect.Height, dirtyRect.Height); } else { circleRect = new CGRect((dirtyRect.Width - dirtyRect.Height + dirtyRect.X), dirtyRect.Y, dirtyRect.Height, dirtyRect.Height); } // draw circle with shadow (no shadow for dark mode) if (!Colors.IsDarkMode) { CGRect circleShadowRect = new CGRect(circleRect.X + offset / 3, circleRect.Y + offset / 3, circleRect.Height - 2 * offset / 3, circleRect.Height - 2 * offset / 3); NSBezierPath circleShadowPath = NSBezierPath.FromRoundedRect(circleShadowRect, circleShadowRect.Height / 2, circleShadowRect.Height / 2); context.CGContext.SetShadow(new CGSize(offset / 3, -offset), offset * 1f, new CGColor(internalSwitcherShadowColor.RedComponent, internalSwitcherShadowColor.GreenComponent, internalSwitcherShadowColor.BlueComponent)); circleShadowPath.Fill(); } // restore context state context.CGContext.RestoreState(); // set circle color NSColor circleColor = internalSwitcherColor; circleColor.SetFill(); // draw circle without shadow to fill internal area filled by shadow NSBezierPath circlePath = NSBezierPath.FromRoundedRect(circleRect, circleRect.Height / 2, circleRect.Height / 2); circlePath.Fill(); // circle border circlePath.AddClip(); circlePath.LineWidth = 1; if (Colors.IsDarkMode) { // no border for Dark mode internalSwitcherColor.SetStroke(); } else { if (switchOffBorderColor != null) { switchOffBorderColor.SetStroke(); } } circlePath.Stroke(); }
public override void DrawRect(CGRect dirtyRect) { var path = new NSBezierPath (); path.AppendPathWithRect (dirtyRect); NSColor.Clear.SetFill (); path.Fill (); path.AppendPathWithRect (highlightRect); NSColor.Red.SetStroke (); path.Stroke (); }