コード例 #1
0
        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);
            }
        }
コード例 #2
0
        public void DrawText(NSRect aRect)
        {
            if (iText == null)
            {
                return;
            }

            // assume images for the background are the same for the no-hover, hover and down states
            NSImage left       = iLeft;
            NSImage right      = iRight;
            NSRect  fillerRect = new NSRect(aRect.MinX + left.Size.width, aRect.MinY, aRect.Width - left.Size.width - right.Size.width, aRect.Height);

            // calculate the text rect
            NSSize textSz   = TextSize;
            NSSize imgSz    = ImageSize;
            NSRect textRect = new NSRect(iTextLeft ? fillerRect.MinX + iTextPadding: fillerRect.MinX + imgSz.width + iTextPadding,
                                         aRect.MidY - textSz.height * 0.5f,
                                         fillerRect.Width - imgSz.width - 2.0f * iTextPadding,
                                         textSz.height);

            // draw
            iText.DrawInRectWithAttributes(textRect.IntegralRect(), TextAttributes);
        }