/// <summary> /// Called by default to paint the row if no OnRowPaint is defined /// </summary> protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { // background var backColor = item.IsSeparator ? YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); e.Graphics.Clear(backColor); var curItem = item as FilteredTypeListItem; if (curItem != null) { var drawRect = row.ClientRectangle; drawRect.Height = RowHeight; // case of a separator if (item.IsSeparator) { RowPaintSeparator(e.Graphics, drawRect); } else { DrawFilteredTypeRow(e.Graphics, curItem, drawRect, row); } } }
/// <summary> /// Called by default to paint the row if no OnRowPaint is defined /// </summary> protected virtual void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { var backColor = item.IsSeparator ? YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); var foreColor = YamuiThemeManager.Current.MenuFg(row.IsSelected, row.IsHovered, !item.IsDisabled); // background e.Graphics.Clear(backColor); // case of a separator if (item.IsSeparator) { var rect = row.ClientRectangle; rect.Height = RowHeight; RowPaintSeparator(e.Graphics, rect); return; } // foreground // left line if (row.IsSelected) { using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.AccentColor)) { e.Graphics.FillRectangle(b, new Rectangle(0, 0, 3, row.ClientRectangle.Height)); } } // text TextRenderer.DrawText(e.Graphics, item.DisplayText, FontManager.GetStandardFont(), new Rectangle(5, 0, row.ClientRectangle.Width - 5, RowHeight), foreColor, TextFormatFlags.VerticalCenter | TextFormatFlags.Left | TextFormatFlags.NoPadding); }
/// <summary> /// Called by default to paint the row if no OnRowPaint is defined /// </summary> protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { // background var backColor = item.IsSeparator ? YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); e.Graphics.Clear(backColor); // foreground // left line if (row.IsSelected && !item.IsDisabled) { using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.AccentColor)) { e.Graphics.FillRectangle(b, new Rectangle(0, 0, 3, ClientRectangle.Height)); } } var curItem = item as FilteredTypeTreeListItem; if (curItem != null) { var drawRect = row.ClientRectangle; drawRect.X += 8; drawRect.Width -= 8; drawRect.Height = RowHeight; var shiftedDrawRect = drawRect; // draw the tree structure if (!_isSearching && !NoCanExpandItem) { shiftedDrawRect = RowPaintTree(e.Graphics, curItem, drawRect, row); } // case of a separator if (item.IsSeparator) { RowPaintSeparator(e.Graphics, curItem.Level == 0 ? drawRect : shiftedDrawRect); } else { DrawFilteredTypeRow(e.Graphics, curItem, NoCanExpandItem ? drawRect : shiftedDrawRect, row); } } }
/// <summary> /// Called by default to paint the row if no OnRowPaint is defined /// </summary> protected override void RowPaint(ListItem item, YamuiListRow row, PaintEventArgs e) { var backColor = item.IsSeparator ? YamuiThemeManager.Current.MenuBg(false, false, !item.IsDisabled) : YamuiThemeManager.Current.MenuBg(row.IsSelected, row.IsHovered, !item.IsDisabled); var foreColor = YamuiThemeManager.Current.MenuFg(row.IsSelected, row.IsHovered, !item.IsDisabled); // background e.Graphics.Clear(backColor); // case of a separator if (item.IsSeparator) { var rect = row.ClientRectangle; rect.Height = RowHeight; RowPaintSeparator(e.Graphics, rect); return; } // foreground // left line if (row.IsSelected) { using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.AccentColor)) { e.Graphics.FillRectangle(b, new Rectangle(0, 0, 3, row.ClientRectangle.Height)); } } var textRectangle = new Rectangle(5, 0, row.ClientRectangle.Width - 5, RowHeight); // letter highlight if (!(item.IsDisabled || item.IsSeparator)) { DrawTextHighlighting(e.Graphics, ((FilteredListItem)item).InternalFilterMatchedRanges, textRectangle, item.DisplayText, TextFlags); } // text TextRenderer.DrawText(e.Graphics, item.DisplayText, FontManager.GetStandardFont(), textRectangle, foreColor, TextFlags); }
protected virtual void DrawFilteredTypeRow(Graphics g, FilteredTypeListItem item, Rectangle drawRect, YamuiListRow row) { var foreColor = YamuiThemeManager.Current.MenuFg(row.IsSelected, row.IsHovered, !item.IsDisabled); // Highlighted row if (item.IsRowHighlighted) { using (SolidBrush b = new SolidBrush(YamuiThemeManager.Current.ButtonImageFocusedIndicator)) { GraphicsPath path = new GraphicsPath(); path.AddLines(new[] { new Point(drawRect.X, drawRect.Y), new Point(drawRect.X + drawRect.Height / 2, drawRect.Y), new Point(drawRect.X, drawRect.Y + drawRect.Height / 2), new Point(drawRect.X, drawRect.Y) }); g.FillPath(b, path); } } // Image icon Image img = item.ItemImage; if (img == null && item.ItemTypeImage != null) { img = item.ItemTypeImage; } if (img != null) { var recImg = new Rectangle(new Point(drawRect.X + 1, drawRect.Y + (drawRect.Height - img.Height) / 2), new Size(img.Width, img.Height)); g.DrawImage(img, recImg); } // tag images var xPos = 1; var listImg = item.TagImages; if (listImg != null) { listImg.Reverse(); // draw the image with a given opacity ColorMatrix imgColor = new ColorMatrix(); imgColor.Matrix33 = FlagImagesOpacity; using (ImageAttributes imgAttrib = new ImageAttributes()) { imgAttrib.SetColorMatrix(imgColor); foreach (var image in listImg) { xPos += image.Width; g.DrawImage(image, new Rectangle(new Point(drawRect.X + drawRect.Width - xPos, (drawRect.Height - image.Height) / 2), new Size(image.Width, image.Height)), 0, 0, image.Width, image.Height, GraphicsUnit.Pixel, imgAttrib); } } } // sub text var subText = item.SubText; if (!string.IsNullOrEmpty(subText)) { var textFont = FontManager.GetFont(FontStyle.Bold, 10); var textSize = TextRenderer.MeasureText(subText, textFont); var subColor = !item.IsDisabled ? YamuiThemeManager.Current.SubTextFore : foreColor; var drawPoint = new PointF(drawRect.X + drawRect.Width - xPos - textSize.Width - 3, (drawRect.Height / 2) - (textSize.Height / 2) - 1); // using Drawstring here because TextRender (GDI) can't draw semi transparent text g.DrawString(subText, textFont, new SolidBrush(Color.FromArgb((int)(SubTextOpacity * 255), subColor)), drawPoint); using (var pen = new Pen(Color.FromArgb((int)(SubTextOpacity * 0.8 * 255), subColor), 1) { Alignment = PenAlignment.Left }) { g.DrawPath(pen, Utilities.GetRoundedRect(drawPoint.X - 2, drawPoint.Y - 1, textSize.Width + 2, textSize.Height + 3, 3f)); } } var textRectangle = new Rectangle(drawRect.X + 3 + (img != null ? img.Width : 0), 0, drawRect.Width - 3 - (img != null ? img.Width : 0), drawRect.Height); // letter highlight if (!(item.IsDisabled || item.IsSeparator)) { DrawTextHighlighting(g, item.InternalFilterMatchedRanges, textRectangle, item.DisplayText, TextFlags); } // text TextRenderer.DrawText(g, item.DisplayText, FontManager.GetStandardFont(), textRectangle, foreColor, TextFlags); }
protected virtual Rectangle RowPaintTree(Graphics g, FilteredTypeTreeListItem curItem, Rectangle drawRect, YamuiListRow row) { var foreColor = YamuiThemeManager.Current.MenuFg(row.IsSelected, row.IsHovered, !curItem.IsDisabled); var shiftedDrawRect = drawRect; // draw the branches of the tree if (ShowTreeBranches) { using (var linePen = new Pen(!(curItem.IsDisabled || curItem.IsSeparator) ? YamuiThemeManager.Current.SubTextFore : foreColor, 1.5f) { DashStyle = DashStyle.Solid }) { var pos = drawRect.X + TreeWidth / 2; if (curItem.Level >= 1) { pos += (curItem.Level - 1) * TreeWidth; } // Draw the horizontal line that goes to the arrow if (curItem.Level > 0 && !curItem.IsSeparator) { g.DrawLine(linePen, pos, drawRect.Y + drawRect.Height / 2 - 1, pos + (curItem.CanExpand ? TreeWidth / 2 : TreeWidth), drawRect.Y + drawRect.Height / 2 - 1); } // draw the vertical lines var familyNode = curItem; while (familyNode != null && familyNode.Level > 0) { // the current item is the last item of its parent if (familyNode.Level == curItem.Level && familyNode.IsLastItem) { g.DrawLine(linePen, pos, drawRect.Y, pos, drawRect.Y + drawRect.Height / 2 - 1); } else if (!familyNode.IsLastItem) { g.DrawLine(linePen, pos, drawRect.Y, pos, drawRect.Y + drawRect.Height); } familyNode = familyNode.ParentNode; pos -= TreeWidth; } } } for (int i = 0; i <= curItem.Level; i++) { shiftedDrawRect.X += TreeWidth; shiftedDrawRect.Width -= TreeWidth; } // Draw the arrow icon indicating if the node is expanded or not if (curItem.CanExpand) { Color arrowColor; if (row.IsHovered && new Rectangle(new Point(0, 0), new Size(shiftedDrawRect.X + NodeExpandClickMargin, drawRect.Height)).Contains(row.PointToClient(MousePosition))) { arrowColor = YamuiThemeManager.Current.AccentColor; } else { arrowColor = curItem.IsExpanded ? YamuiThemeManager.Current.MenuNormalFore : YamuiThemeManager.Current.MenuDisabledFore; } var rect = new Rectangle(shiftedDrawRect.X - TreeWidth + 1, shiftedDrawRect.Y, TreeWidth - 2, shiftedDrawRect.Height); rect.Y = rect.Y + (rect.Height - rect.Width) / 2; rect.Height = rect.Width; g.PixelOffsetMode = PixelOffsetMode.Half; using (SolidBrush brush = new SolidBrush(arrowColor)) { if (!curItem.IsExpanded) { g.FillPolygon(brush, new[] { new Point(rect.X, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height / 2), new Point(rect.X, rect.Y + rect.Height) }); } else { g.FillPolygon(brush, new[] { new Point(rect.X, rect.Y + rect.Height), new Point(rect.X + rect.Width, rect.Y), new Point(rect.X + rect.Width, rect.Y + rect.Height) }); } } } return(shiftedDrawRect); }