private static void RenderSolutionNameIcon(string name) { if (!string.IsNullOrWhiteSpace(name)) { const float margin = 4; NSString text = (NSString)name; var paragraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy(); paragraphStyle.Alignment = NSTextAlignment.Center; var attributes = new NSStringAttributes() { Font = NSFont.SystemFontOfSize(19, NSFontWeight.Regular), ForegroundColor = NSColor.White, ParagraphStyle = paragraphStyle }; var textRect = new CGSize(_defaultImage.Size.Width - margin * 2, _defaultImage.Size.Height - 2 * margin); var rect = text.BoundingRectWithSize(textRect, NSStringDrawingOptions.UsesLineFragmentOrigin, attributes.Dictionary); var centerAdjustment = _defaultImage.Size.Width - rect.Width - 2 * margin; rect.Offset(margin + centerAdjustment / 2, margin); var brandedImage = NSImage.ImageWithSize(_defaultImage.Size, false, (dstRect) => { _defaultImage.Draw(dstRect); DrawBackgroundInRect(rect); text.DrawInRect(rect, attributes); return(true); }); NSApplication.SharedApplication.ApplicationIconImage = brandedImage; } else { NSApplication.SharedApplication.ApplicationIconImage = _defaultImage; } }
public void ImageWithSize() { Asserts.EnsureMountainLion(); var image = NSImage.ImageWithSize(new CGSize(50, 50), false, rect => { return(true); }); Assert.IsNotNull(image); }
public static NSImage CreateIconWithSolutionName(string name, NSImage baseImage) { if (string.IsNullOrWhiteSpace(name)) { return(baseImage); } const float margin = 4; var text = (NSString)name; // setup text styles var paragraphStyle = (NSParagraphStyle)NSParagraphStyle.DefaultParagraphStyle.MutableCopy(); paragraphStyle.Alignment = NSTextAlignment.Center; var attributes = new NSStringAttributes { Font = NSFont.SystemFontOfSize(19, NSFontWeight.Regular), ForegroundColor = NSColor.White, ParagraphStyle = paragraphStyle }; // setup rect var textRect = new CGSize(baseImage.Size.Width - margin * 2, baseImage.Size.Height - 2 * margin); var rect = text.BoundingRectWithSize(textRect, NSStringDrawingOptions.UsesLineFragmentOrigin, attributes.Dictionary); var centerAdjustment = baseImage.Size.Width - rect.Width - 2 * margin; rect.Offset(margin + centerAdjustment / 2, margin); // create image var brandedImage = NSImage.ImageWithSize(baseImage.Size, false, dstRect => { baseImage.Draw(dstRect); DrawBackgroundInRect(rect); text.DrawInRect(rect, attributes); return(true); }); return(brandedImage); }