private void Draw(NSRect aRect, NSImage aLeft, NSImage aRight, NSImage aFiller) { // draw the background NSRect leftRect = new NSRect(aRect.MinX, aRect.MinY, aLeft.Size.width, aRect.Height); aLeft.DrawInRectFromRectOperationFraction(leftRect, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); NSRect rightRect = new NSRect(aRect.MaxX - aRight.Size.width, aRect.MinY, aRight.Size.width, aRect.Height); aRight.DrawInRectFromRectOperationFraction(rightRect, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); NSRect fillerRect = new NSRect(aRect.MinX + aLeft.Size.width, aRect.MinY, aRect.Width - aLeft.Size.width - aRight.Size.width, aRect.Height); aFiller.DrawInRectFromRectOperationFraction(fillerRect, NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); // draw image if (iText != null && iImage != null) { // button has text and an image NSSize imgSz = ImageSize; NSRect imgRect = new NSRect(iTextLeft ? fillerRect.MaxX - imgSz.width : fillerRect.MinX, aRect.MidY - imgSz.height * 0.5f, imgSz.width, imgSz.height); // fit the image to the available rect imgRect = NSImageHelper.CentreImageInRect(iImage, imgRect); iImage.DrawInRectFromRectOperationFraction(imgRect.IntegralRect(), NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); } else if (iImage != null) { // image only - draw centred NSSize imgSz = ImageSize; NSRect dstRect = new NSRect(aRect.MidX - imgSz.width * 0.5f, aRect.MidY - imgSz.height * 0.5f, imgSz.width, imgSz.height); // fit the image to the available rect dstRect = NSImageHelper.CentreImageInRect(iImage, dstRect); iImage.DrawInRectFromRectOperationFraction(dstRect.IntegralRect(), NSRect.NSZeroRect, NSCompositingOperation.NSCompositeSourceOver, 1.0f); } }