internal static CGPath CreateClippingPath(RectangleF rect, float radius) { var path = new CGPath(); path.MoveToPoint(rect.GetMinX(), rect.GetMinY()); path.AddLineToPoint(rect.GetMinX(), rect.GetMaxY() - radius); path.AddArcToPoint(rect.GetMinX(), rect.GetMaxY(), rect.GetMinX() + radius, rect.GetMaxY(), radius); path.AddLineToPoint(rect.GetMaxX() - radius, rect.GetMaxY()); path.AddArcToPoint(rect.GetMaxX(), rect.GetMaxY(), rect.GetMaxX(), rect.GetMaxY() - radius, radius); path.AddLineToPoint(rect.GetMaxX(), rect.GetMinY()); path.CloseSubpath(); return path; }
private static float scale = 10000; //or 1 or 10 or 10000 etc for lesser or greater precision. #endregion Fields #region Constructors // An infinite region would cover the entire device region which is the same as // not having a clipping region. Note that this is not the same as having an // empty region, which when clipping to it has the effect of excluding the entire // device region. public Region() { // We set the default region to a very large regionObject = infinite; var path = RectangleToPath (infinite); solution.Add (path); regionList.Add (new RegionEntry (RegionType.Infinity, infinite, path)); regionPath = new CGPath (); regionPath.MoveToPoint (infinite.Left, infinite.Top); regionPath.AddLineToPoint (infinite.Right, infinite.Top); regionPath.AddLineToPoint (infinite.Right, infinite.Bottom); regionPath.AddLineToPoint (infinite.Left, infinite.Bottom); regionBounds = infinite; }
void PathsToInternalPath(Paths paths) { regionPath = new CGPath (); foreach (var poly in solution) { regionPath.MoveToPoint(IntPointToPointF(poly[0])); for (var p =1; p < poly.Count; p++) { regionPath.AddLineToPoint (IntPointToPointF (poly [p])); } } }
// public bool IsInfinite(Graphics g) // { // } public void MakeInfinite() { regionObject = infinite; var path = RectangleToPath (infinite); // clear out our containers. regionList.Clear (); solution.Clear (); solution.Add (path); regionList.Add (new RegionEntry (RegionType.Infinity, infinite, path)); regionPath = new CGPath (); regionPath.MoveToPoint (infinite.Left, infinite.Top); regionPath.AddLineToPoint (infinite.Right, infinite.Top); regionPath.AddLineToPoint (infinite.Right, infinite.Bottom); regionPath.AddLineToPoint (infinite.Left, infinite.Bottom); regionBounds = regionPath.BoundingBox; }
public Region(RectangleF rect) { regionObject = rect; var path = RectangleToPath (rect); solution.Add (path); regionList.Add (new RegionEntry (RegionType.Rectangle, rect, path)); regionPath = new CGPath (); regionPath.MoveToPoint (rect.Left, rect.Top); regionPath.AddLineToPoint (rect.Right, rect.Top); regionPath.AddLineToPoint (rect.Right, rect.Bottom); regionPath.AddLineToPoint (rect.Left, rect.Bottom); regionBounds = rect; }
public override void DrawRect(RectangleF dirtyRect) { float padding = 4; CGContext context = NSGraphicsContext.CurrentContext.GraphicsPort; if (RoundedRadius == 0) { if (!Enabled) CoreGraphicsHelper.FillRect(context, Bounds, DisabledBackgroundColor); else if (_isMouseDown) CoreGraphicsHelper.FillRect(context, Bounds, BackgroundMouseDownColor); else if (_isMouseOver) CoreGraphicsHelper.FillRect(context, Bounds, BackgroundMouseOverColor); else CoreGraphicsHelper.FillRect(context, Bounds, BackgroundColor); CoreGraphicsHelper.DrawRect(context, Bounds, BorderColor, 2); } else { var roundedPath = NSBezierPath.FromRoundedRect(Bounds, RoundedRadius, RoundedRadius); NSColor nsColor = null; if(!Enabled) nsColor = NSColor.FromCIColor(CIColor.FromCGColor(DisabledBackgroundColor)); else if (_isMouseDown) nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundMouseDownColor)); else if (_isMouseOver) nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundMouseOverColor)); else nsColor = NSColor.FromCIColor(CIColor.FromCGColor(BackgroundColor)); nsColor.SetFill(); roundedPath.Fill(); } //CoreGraphicsHelper.DrawRect(context, Bounds, BorderColor, 2); RectangleF rectTextSize = CoreGraphicsHelper.MeasureString(Bounds.Size, Title, "Roboto", 11); RectangleF rectText; if (Image != null) { float xImage = ((Bounds.Width - rectTextSize.Width - (padding * 2) - Image.Size.Width) / 2); RectangleF rectImage = new RectangleF(xImage, (Bounds.Height - Image.Size.Height) / 2, Image.Size.Width, Image.Size.Height); Image.DrawInRect(rectImage, new RectangleF(0, 0, Image.Size.Width, Image.Size.Height), NSCompositingOperation.SourceOver, 1.0f); float xText = xImage + padding + Image.Size.Width + padding; rectText = new RectangleF(xText, (Bounds.Height - rectTextSize.Height) / 2, rectTextSize.Width, rectTextSize.Height); } else { rectText = new RectangleF(padding * 2, ((Bounds.Height - rectTextSize.Height) / 2) - 2, rectTextSize.Width, rectTextSize.Height); } CoreGraphicsHelper.DrawText(rectText, 0, 0, Title, "Roboto", 11, NSColor.White); var triangleColor = new CGColor(0.8f, 0.8f, 0.8f); float trianglePadding = 8; float triangleWidth = 8; var path = new CGPath(); path.MoveToPoint(new PointF(Bounds.Width - trianglePadding, trianglePadding)); path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding - (triangleWidth / 2), Bounds.Height - trianglePadding)); path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding - triangleWidth, trianglePadding)); path.AddLineToPoint(new PointF(Bounds.Width - trianglePadding, trianglePadding)); CoreGraphicsHelper.StrokePath(context, path, 1, triangleColor); if(_isMouseOver) CoreGraphicsHelper.FillPath(context, path, triangleColor); }