public void Draw(NSRect aCellFrame, NSView aControlView) { BookmarkData item = ObjectValue.CastAs <BookmarkData>(); // create attributes for the title and subtitle text NSMutableParagraphStyle style = new NSMutableParagraphStyle(); style.SetParagraphStyle(NSParagraphStyle.DefaultParagraphStyle); style.SetLineBreakMode(NSLineBreakMode.NSLineBreakByTruncatingTail); NSDictionary titleAttr = NSDictionary.DictionaryWithObjectsAndKeys(FontManager.FontMedium, NSAttributedString.NSFontAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, null); NSDictionary subtitleAttr = NSDictionary.DictionaryWithObjectsAndKeys(FontManager.FontSmall, NSAttributedString.NSFontAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, null); style.Release(); NSPoint pt = aCellFrame.origin; // draw title NSString title = NSString.StringWithUTF8String(item.Bookmark.Title); title.DrawAtPointWithAttributes(pt, titleAttr); NSSize size = title.SizeWithAttributes(titleAttr); pt.y += size.height; // draw breadcrumb List <string> titleTrail = new List <string>(); foreach (Breadcrumb bc in item.Bookmark.BreadcrumbTrail) { titleTrail.Add(bc.Title); } string breadcrumb = string.Join("/", titleTrail.ToArray()); NSString breadcrumb2 = NSString.StringWithUTF8String(breadcrumb); breadcrumb2.DrawAtPointWithAttributes(pt, subtitleAttr); }
public override void DrawRect(NSRect aRect) { // draw bars if (iMaxValue > 0) { // draw the current value bar NSColor colour = NSColor.ColorWithCalibratedRedGreenBlueAlpha(71.0f / 255.0f, 172.0f / 255.0f, 220.0f / 255.0f, 1.0f); colour.SetStroke(); DrawArc(0, iValue, true); // draw the preview bar if (iPreviewEnabled) { colour = NSColor.ColorWithCalibratedRedGreenBlueAlpha(187.0f / 255.0f, 187.0f / 255.0f, 0.0f / 255.0f, 1.0f); colour.SetStroke(); DrawArc(iValue, iPreviewValue, (iPreviewValue > iValue)); } } // draw text if (iText != null) { NSMutableParagraphStyle style = new NSMutableParagraphStyle(); style.SetParagraphStyle(NSParagraphStyle.DefaultParagraphStyle); style.SetAlignment(NSTextAlignment.NSCenterTextAlignment); NSDictionary dict = NSDictionary.DictionaryWithObjectsAndKeys(FontManager.FontMedium, NSAttributedString.NSFontAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, null); style.Release(); NSSize size = iText.SizeWithAttributes(dict); NSRect rect = new NSRect((Bounds.Width - size.width) * 0.5f, (Bounds.Height - size.height) * 0.5f, size.width, size.height); iText.DrawInRectWithAttributes(rect, dict); } }
public void Draw(NSRect aCellFrame, NSView aControlView) { WrappedDataTrackItem wrapped = ObjectValue.CastAs <WrappedDataTrackItem>(); IDataTrackItem item = wrapped.Item; // create attributes for the title and subtitle text NSMutableParagraphStyle style = new NSMutableParagraphStyle(); style.SetParagraphStyle(NSParagraphStyle.DefaultParagraphStyle); style.SetLineBreakMode(NSLineBreakMode.NSLineBreakByTruncatingTail); // set font sizes depending on whether this item is a group or track NSFont titleFont = item.IsGroup ? FontManager.FontLarge : FontManager.FontSemiLarge; NSFont subtitleFont = item.IsGroup ? FontManager.FontMedium : FontManager.FontSmall; NSDictionary titleAttr = NSDictionary.DictionaryWithObjectsAndKeys(titleFont, NSAttributedString.NSFontAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, null); NSDictionary subtitleAttr = NSDictionary.DictionaryWithObjectsAndKeys(subtitleFont, NSAttributedString.NSFontAttributeName, NSColor.WhiteColor, NSAttributedString.NSForegroundColorAttributeName, style, NSAttributedString.NSParagraphStyleAttributeName, null); style.Release(); float vertPos = aCellFrame.origin.y; float titleIndent = 0.0f; NSSize size; NSRect rect; // draw index for non-group items if (!item.IsGroup) { NSString index = NSString.StringWithUTF8String(string.Format("{0}. ", item.Index + 1)); size = index.SizeWithAttributes(titleAttr); rect = new NSRect(aCellFrame.MinX, vertPos, size.width, size.height); index.DrawInRectWithAttributes(rect, titleAttr); titleIndent = size.width; } // draw the title NSString title = NSString.StringWithUTF8String(item.Title); size = title.SizeWithAttributes(titleAttr); rect = new NSRect(aCellFrame.MinX + titleIndent, vertPos, aCellFrame.Width - titleIndent, size.height); title.DrawInRectWithAttributes(rect, titleAttr); vertPos += size.height; // draw subtitle 1 aligned with the left of the cell if (item.Subtitle1 != string.Empty) { NSString subtitle1 = NSString.StringWithUTF8String(item.Subtitle1); size = subtitle1.SizeWithAttributes(subtitleAttr); rect = new NSRect(aCellFrame.MinX, vertPos, aCellFrame.Width, size.height); subtitle1.DrawInRectWithAttributes(rect, subtitleAttr); vertPos += size.height; } // draw subtitle 2 aligned with the left of the cell if (item.Subtitle2 != string.Empty) { NSString subtitle2 = NSString.StringWithUTF8String(item.Subtitle2); size = subtitle2.SizeWithAttributes(subtitleAttr); rect = new NSRect(aCellFrame.MinX, vertPos, aCellFrame.Width, size.height); subtitle2.DrawInRectWithAttributes(rect, subtitleAttr); } }