public static TagRendererResources GetTagResources(Tag tag, Graphics graphics, bool ShowFullNames) { string Key = tag == null ? "{Unknown Tag}" : tag.Id.ToString(); if (ShowFullNames) { Key = Key + "_FullName"; } if (Resources.ContainsKey(Key)) { return(Resources[Key]); } string tagName = tag == null ? "{Unknown Tag}" : tag.Name; if (!ShowFullNames) { int splitIndex = tagName.LastIndexOf('/'); if (splitIndex > 0) { tagName = tagName.Substring(splitIndex + 1); } } Color TagColor = tag == null ? Color.Cornsilk : tag.Color; Color DesaturatedColor = Drawing.Saturate(TagColor, 0.5f); Color VerDesaturatedColor = Drawing.Saturate(TagColor, 0.25f); TagRendererResources Res = new TagRendererResources(); Res.BackgroundBrush = new SolidBrush(TagColor);// SystemBrushes.Control; Res.BorderPen = new Pen(DesaturatedColor); Res.TextBrush = new SolidBrush(VerDesaturatedColor); Res.TagName = tagName; Res.TextSize = graphics.MeasureString(tagName, SystemFonts.DefaultFont); Resources.Add(Key, Res); return(Res); }
public float DrawTag(Tag tag, RectangleF bounds, Graphics graphics) { float padding = 2; float tagPadding = 10; TagRendererResources resources = GetTagResources(tag, graphics, ShowFullName); float tagHeight = bounds.Height; float tagPipWidth = tagHeight * 0.5f; float tagWidth = resources.TextSize.Width + (padding * 2); float tagX = bounds.X + tagPipWidth; float tagY = bounds.Y; graphics.FillEllipse(resources.BackgroundBrush, tagX - tagPipWidth, tagY, tagPipWidth * 2, tagHeight); graphics.DrawEllipse(resources.BorderPen, tagX - tagPipWidth, tagY, tagPipWidth * 2, tagHeight); graphics.FillRectangle(resources.BackgroundBrush, tagX, tagY, tagWidth, tagHeight); graphics.DrawRectangle(resources.BorderPen, tagX, tagY, tagWidth, tagHeight); graphics.FillRectangle(resources.BackgroundBrush, tagX - 1, tagY + 1, 2, tagHeight - 1); graphics.DrawString(resources.TagName, SystemFonts.DefaultFont, resources.TextBrush, tagX + padding, tagY + (tagHeight * 0.5f) - (resources.TextSize.Height * 0.5f)); return(tagPipWidth + tagWidth + tagPadding); }