public override void DrawRect(RectangleF dirtyRect) { int radius = 5, arrowHeight = 10, arrowWidth = 20; var roundedRectangleRect = new RectangleF(0, 0, this.Bounds.Width, this.Bounds.Height - arrowHeight); var path = new NSBezierPath(); path.AppendPathWithRoundedRect(roundedRectangleRect, radius, radius); // Draw the triangle path.MoveTo(new PointF((this.Bounds.Width / 2) - (arrowWidth / 2), this.Bounds.Height - arrowHeight)); path.LineTo(new PointF((this.Bounds.Width / 2), this.Bounds.Height)); path.LineTo(new PointF((this.Bounds.Width / 2) + (arrowWidth / 2), this.Bounds.Height - arrowHeight)); path.ClosePath(); NSColor.Control.SetFill(); path.Fill(); }
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 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 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 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(); }