/// <summary> /// Renders a MenuItem. /// </summary> protected virtual void RenderItem(MenuDropDown control, MenuItem item, PaintEventArgs e) { // Background var background_color = item.Hovered || item.IsDropDownOpened ? Theme.ItemHighlightColor : Theme.LightTextColor; e.Canvas.FillRectangle(item.Bounds, background_color); // Image if (item.Image != null) { var image_size = e.LogicalToDeviceUnits(16); var image_bounds = DrawingExtensions.CenterSquare(item.Bounds, image_size); var image_rect = new Rectangle(item.Bounds.Left + e.LogicalToDeviceUnits(6), image_bounds.Top, image_size, image_size); e.Canvas.DrawBitmap(item.Image, image_rect, !item.Enabled); } // Text var font_color = item.Enabled ? Theme.PrimaryTextColor : Theme.DisabledTextColor; var font_size = e.LogicalToDeviceUnits(Theme.FontSize); var bounds = item.Bounds; bounds.X += e.LogicalToDeviceUnits(28); e.Canvas.DrawText(item.Text, Theme.UIFont, font_size, bounds, font_color, ContentAlignment.MiddleLeft); // Dropdown Arrow if (item.HasItems) { var arrow_bounds = DrawingExtensions.CenterSquare(item.Bounds, 16); var arrow_area = new Rectangle(item.Bounds.Right - e.LogicalToDeviceUnits(16) - 4, arrow_bounds.Top, 16, 16); ControlPaint.DrawArrowGlyph(e, arrow_area, font_color, ArrowDirection.Right); } }
/// <summary> /// Renders a MenuItem. /// </summary> protected virtual void RenderItem(Ribbon control, RibbonTabPage tabPage, RibbonItemGroup group, MenuItem item, PaintEventArgs e) { var canvas = e.Canvas; var padding = e.LogicalToDeviceUnits(item.Padding); var background_color = item.Selected ? Theme.ItemSelectedColor : item.Hovered ? Theme.ItemHighlightColor : Theme.NeutralGray; canvas.FillRectangle(item.Bounds, background_color); var image_area_bounds = new Rectangle(item.Bounds.Left + padding.Left, item.Bounds.Top + padding.Top, item.Bounds.Width - padding.Horizontal, e.LogicalToDeviceUnits(MINIMUM_ITEM_SIZE)); var final_image_bounds = DrawingExtensions.CenterSquare(image_area_bounds, e.LogicalToDeviceUnits(IMAGE_SIZE)); if (item.Image != null) { canvas.DrawBitmap(item.Image, final_image_bounds, !item.Enabled); } if (!string.IsNullOrWhiteSpace(item.Text)) { var font_size = e.LogicalToDeviceUnits(Theme.ItemFontSize); canvas.Save(); canvas.Clip(item.Bounds); var text_bounds = new Rectangle(item.Bounds.Left, image_area_bounds.Bottom, item.Bounds.Width, item.Bounds.Bottom - image_area_bounds.Bottom); canvas.DrawText(item.Text, Theme.UIFont, font_size, text_bounds, item.Enabled ? Theme.PrimaryTextColor : Theme.DisabledTextColor, ContentAlignment.MiddleCenter); canvas.Restore(); } }
/// <inheritdoc/> protected override void Render(CheckBox control, PaintEventArgs e) { var box_size = e.LogicalToDeviceUnits(GLYPH_SIZE); var glyph_padding = e.LogicalToDeviceUnits(GLYPH_TEXT_PADDING); // Draw the checkbox glyph var y = (control.ScaledHeight - box_size) / 2; var box_bounds = new Rectangle(e.LogicalToDeviceUnits(3), y, box_size, box_size); ControlPaint.DrawCheckBox(e, box_bounds, control.CheckState, !control.Enabled); var text_bounds = new Rectangle(box_bounds.Right + glyph_padding, 0, control.ScaledWidth - box_bounds.Right - glyph_padding, control.ScaledHeight); // Draw the focus rectangle if (control.Selected && control.ShowFocusCues) { var focus_bounds = new Rectangle(box_bounds.Right, 0, text_bounds.Width + glyph_padding, text_bounds.Height); e.Canvas.DrawFocusRectangle(focus_bounds, e.LogicalToDeviceUnits(3)); } // Draw the text if (control.Text.HasValue()) { e.Canvas.DrawText(control.Text, text_bounds, control, ContentAlignment.MiddleLeft); } }
/// <summary> /// Renders a TabStripItem. /// </summary> protected virtual void RenderItem(TabStrip control, TabStripItem item, PaintEventArgs e) { if (item.Selected) { e.Canvas.FillRectangle(item.Bounds, Theme.NeutralGray); } else if (item.Hovered && item.Enabled) { e.Canvas.FillRectangle(item.Bounds, Theme.HighlightColor); } // Draw focus rectangle if (control.Selected && control.ShowFocusCues && control.Tabs.FocusedIndex == control.Tabs.IndexOf(item)) { e.Canvas.DrawFocusRectangle(item.Bounds, e.LogicalToDeviceUnits(1)); } var font_color = !item.Enabled ? Theme.DisabledTextColor: item.Selected ? Theme.PrimaryColor : Theme.LightTextColor; var font_size = e.LogicalToDeviceUnits(Theme.FontSize); e.Canvas.DrawText(item.Text, Theme.UIFont, font_size, item.Bounds, font_color, ContentAlignment.MiddleCenter); }
/// <summary> /// Renders a ListViewItem. /// </summary> protected virtual void RenderItem(ListView control, ListViewItem item, PaintEventArgs e) { if (item.Selected) { e.Canvas.FillRectangle(item.Bounds, Theme.ItemHighlightColor); } var image_size = e.LogicalToDeviceUnits(32); var image_area = new Rectangle(item.Bounds.Left, item.Bounds.Top, item.Bounds.Width, item.Bounds.Width); var image_bounds = DrawingExtensions.CenterSquare(image_area, image_size); image_bounds.Y = item.Bounds.Top + e.LogicalToDeviceUnits(3); if (item.Image != null) { e.Canvas.DrawBitmap(item.Image, image_bounds); } if (!string.IsNullOrWhiteSpace(item.Text)) { var font_size = e.LogicalToDeviceUnits(Theme.ItemFontSize); e.Canvas.Save(); e.Canvas.Clip(item.Bounds); var text_bounds = new Rectangle(item.Bounds.Left, image_bounds.Bottom + e.LogicalToDeviceUnits(3), item.Bounds.Width, item.Bounds.Bottom - image_bounds.Bottom - e.LogicalToDeviceUnits(3)); e.Canvas.DrawText(item.Text, Theme.UIFont, font_size, text_bounds, Theme.PrimaryTextColor, ContentAlignment.MiddleCenter); e.Canvas.Restore(); } }
/// <summary> /// Renders a MenuSeparatorItem. /// </summary> protected virtual void RenderMenuSeparatorItem(Ribbon control, RibbonTabPage tabPage, RibbonItemGroup group, MenuSeparatorItem item, PaintEventArgs e) { // Background e.Canvas.FillRectangle(item.Bounds, Theme.NeutralGray); var center = item.Bounds.GetCenter(); var thickness = e.LogicalToDeviceUnits(1); var padding = e.LogicalToDeviceUnits(item.Padding); e.Canvas.DrawLine(center.X, item.Bounds.Y + padding.Top, center.X, item.Bounds.Bottom - padding.Bottom, item.Enabled ? Theme.ItemHighlightColor : Theme.DisabledTextColor, thickness); }
/// <summary> /// Renders a MenuSeparatorItem. /// </summary> protected virtual void RenderMenuSeparatorItem(MenuDropDown control, MenuSeparatorItem item, PaintEventArgs e) { // Background e.Canvas.FillRectangle(item.Bounds, Theme.LightTextColor); var center = item.Bounds.GetCenter(); var thickness = e.LogicalToDeviceUnits(1); var padding = e.LogicalToDeviceUnits(item.Padding); e.Canvas.DrawLine(item.Bounds.X + padding.Top, center.Y, item.Bounds.Right - padding.Right, center.Y, item.Enabled ? Theme.ItemHighlightColor : Theme.DisabledTextColor, thickness); }
protected override void OnPaint(PaintEventArgs e) { base.OnPaint(e); if (IsHovering) { e.Canvas.Clear(glyph == TitleBarButtonGlyph.Close ? Theme.FormCloseHighlightColor : Theme.HighlightColor); } var glyph_bounds = glyph == TitleBarButtonGlyph.Minimize ? DrawingExtensions.CenterRectangle(DisplayRectangle, e.LogicalToDeviceUnits(new Size(BUTTON_PADDING, 1))) : DrawingExtensions.CenterSquare(DisplayRectangle, e.LogicalToDeviceUnits(BUTTON_PADDING)); switch (glyph) { case TitleBarButtonGlyph.Close: ControlPaint.DrawCloseGlyph(e, glyph_bounds); break; case TitleBarButtonGlyph.Minimize: ControlPaint.DrawMinimizeGlyph(e, glyph_bounds); break; case TitleBarButtonGlyph.Maximize: ControlPaint.DrawMaximizeGlyph(e, glyph_bounds); break; } }
/// <summary> /// Gets the bounding box of the area to draw the ComboBox text. /// </summary> protected Rectangle GetTextArea(ComboBox control, PaintEventArgs e) { var area = control.PaddedClientRectangle; area.Width -= e.LogicalToDeviceUnits(GLYPH_SIZE); return(area); }
/// <inheritdoc/> protected override void Render(Button control, PaintEventArgs e) { if (control.Selected && control.ShowFocusCues) { e.Canvas.DrawFocusRectangle(control.ClientRectangle, e.LogicalToDeviceUnits(3)); } e.Canvas.DrawText(control.Text, control.PaddedClientRectangle, control, control.TextAlign); }
/// <inheritdoc/> protected override void Render(FormTitleBar control, PaintEventArgs e) { // Form icon if (control.Image != null) { var icon_glyph_bounds = DrawingExtensions.CenterSquare(GetIconBounds(control), e.LogicalToDeviceUnits(FORM_ICON_SIZE)); e.Canvas.DrawBitmap(control.Image, icon_glyph_bounds); } // Form text e.Canvas.DrawText(control.Text.Trim(), Theme.UIFont, e.LogicalToDeviceUnits(Theme.FontSize), GetTitleBounds(control), Theme.LightTextColor, ContentAlignment.MiddleCenter); // Minimize button if (control.AllowMinimize) { var minimize_button_bounds = GetMinimizeButtonBounds(control); if (control.HoverElement == FormTitleBar.FormTitleBarElement.Minimize) { e.Canvas.FillRectangle(minimize_button_bounds, Theme.HighlightColor); } var min_glyph_bounds = DrawingExtensions.CenterRectangle(minimize_button_bounds, e.LogicalToDeviceUnits(new Size(BUTTON_PADDING, 1))); ControlPaint.DrawMinimizeGlyph(e, min_glyph_bounds); } // Maximize button if (control.AllowMaximize) { var maximize_button_bounds = GetMaximizeButtonBounds(control); if (control.HoverElement == FormTitleBar.FormTitleBarElement.Maximize) { e.Canvas.FillRectangle(maximize_button_bounds, Theme.HighlightColor); } var max_glyph_bounds = DrawingExtensions.CenterSquare(maximize_button_bounds, e.LogicalToDeviceUnits(BUTTON_PADDING)); ControlPaint.DrawMaximizeGlyph(e, max_glyph_bounds); } // Close button var close_button_bounds = GetCloseButtonBounds(control); if (control.HoverElement == FormTitleBar.FormTitleBarElement.Close) { e.Canvas.FillRectangle(close_button_bounds, Theme.FormCloseHighlightColor); } var close_glyph_bounds = DrawingExtensions.CenterSquare(close_button_bounds, e.LogicalToDeviceUnits(BUTTON_PADDING)); ControlPaint.DrawCloseGlyph(e, close_glyph_bounds); }
/// <summary> /// Gets the bounds of the item image. /// </summary> protected virtual Rectangle GetImageBounds(TreeView control, TreeViewItem item, PaintEventArgs e) { if (!control.ShowItemImages || item.Image is null) { return(Rectangle.Empty); } var left_index = control.ShowDropdownGlyph ? GetGlyphBounds(control, item).Right : GetIndentStart(control, item); var image_area = new Rectangle(left_index, item.Bounds.Top, item.Bounds.Height, item.Bounds.Height); return(DrawingExtensions.CenterSquare(image_area, e.LogicalToDeviceUnits(IMAGE_SIZE))); }
/// <inheritdoc/> protected override void Render(RadioButton control, PaintEventArgs e) { var x = e.LogicalToDeviceUnits(11); var y = control.ScaledHeight / 2; ControlPaint.DrawRadioButton(e, new Point(x, y), control.Checked ? CheckState.Checked : CheckState.Unchecked, !control.Enabled); var text_bounds = control.ClientRectangle; var unit_24 = e.LogicalToDeviceUnits(24); var unit_5 = e.LogicalToDeviceUnits(5); text_bounds.X += unit_24; text_bounds.Width -= unit_24; if (control.Selected && control.ShowFocusCues) { var focus_bounds = new Rectangle(text_bounds.X - unit_5, 0, text_bounds.Width + unit_5, text_bounds.Height); e.Canvas.DrawFocusRectangle(focus_bounds, e.LogicalToDeviceUnits(3)); } e.Canvas.DrawText(control.Text, text_bounds, control, ContentAlignment.MiddleLeft); }
/// <summary> /// Renders a MenuItem. /// </summary> protected virtual void RenderItem(Menu control, MenuItem item, PaintEventArgs e) { // Background var background_color = item.Hovered || item.IsDropDownOpened ? Theme.ItemHighlightColor : Theme.NeutralGray; e.Canvas.FillRectangle(item.Bounds, background_color); // Text var font_color = item.Enabled ? Theme.PrimaryTextColor : Theme.DisabledTextColor; var font_size = e.LogicalToDeviceUnits(Theme.FontSize); e.Canvas.DrawText(item.Text, Theme.UIFont, font_size, item.Bounds, font_color, ContentAlignment.MiddleCenter); }
/// <summary> /// Renders a TreeViewItem. /// </summary> protected virtual void RenderItem(TreeView control, TreeViewItem item, PaintEventArgs e) { var is_selected = item == control.SelectedItem; var background_color = is_selected ? Theme.ItemHighlightColor : Theme.LightNeutralGray; var foreground_color = control.Enabled ? Theme.PrimaryTextColor : Theme.DisabledTextColor; e.Canvas.FillRectangle(item.Bounds, background_color); if (is_selected && control.Focused && control.ShowFocusCues) { e.Canvas.DrawFocusRectangle(item.Bounds, e.LogicalToDeviceUnits(1)); } if (control.ShowDropdownGlyph == true) { var glyph_bounds = GetGlyphBounds(control, item); if (GetShouldDrawDropdownGlyph(control, item)) { ControlPaint.DrawArrowGlyph(e, glyph_bounds, foreground_color, item.Expanded ? ArrowDirection.Down : ArrowDirection.Right); } } if (control.ShowItemImages == true && item.Image != null) { var image_bounds = GetImageBounds(control, item, e); e.Canvas.DrawBitmap(item.Image !, image_bounds, !control.Enabled); } if (string.IsNullOrWhiteSpace(item.Text)) { return; } var text_bounds = GetTextBounds(control, item, e); e.Canvas.DrawText(item.Text.Trim(), Theme.UIFont, e.LogicalToDeviceUnits(Theme.FontSize), text_bounds, foreground_color, ContentAlignment.MiddleLeft, maxLines: 1); }
/// <summary> /// Gets the bounds of the item text. /// </summary> protected virtual Rectangle GetTextBounds(TreeView control, TreeViewItem item, PaintEventArgs e) { var show_glyph = control.ShowDropdownGlyph; var show_image = control.ShowItemImages; if (!show_glyph && !show_image) { return(new Rectangle(GetIndentStart(control, item), item.Bounds.Top, item.Bounds.Width - GetIndentStart(control, item), item.Bounds.Height)); } // One of these will be valid because we handled the other case above var padding = e.LogicalToDeviceUnits(6); var used_bounds = show_image ? GetImageBounds(control, item, e) : GetGlyphBounds(control, item); return(new Rectangle(used_bounds.Right + padding, item.Bounds.Top, item.Bounds.Right - used_bounds.Right - padding, item.Bounds.Height)); }
/// <inheritdoc/> protected override void Render(ComboBox control, PaintEventArgs e) { var text_area = GetTextArea(control, e); var unit_3 = e.LogicalToDeviceUnits(3); if (control.Selected && control.ShowFocusCues) { var focus_bounds = new Rectangle(text_area.Left - unit_3, text_area.Top, text_area.Width + unit_3, text_area.Height); e.Canvas.DrawFocusRectangle(focus_bounds, unit_3); } // Draw the text of the selected item if (control.Items.SelectedItem != null) { e.Canvas.DrawText(control.Items.SelectedItem.ToString() !, text_area, control, ContentAlignment.MiddleLeft, maxLines: 1); } // Draw the drop down glyph var button_bounds = GetDropDownButtonArea(control, e); ControlPaint.DrawArrowGlyph(e, button_bounds, control.Enabled ? Theme.PrimaryTextColor : Theme.DisabledTextColor, ArrowDirection.Down); }
protected override void Render(MyCustomRenderedButton control, PaintEventArgs e) { e.Canvas.FillCircle(control.ScaledWidth / 2, control.ScaledHeight / 2, e.LogicalToDeviceUnits(10), SKColors.Red); }
/// <inheritdoc/> protected override void Render(FormTitleBar control, PaintEventArgs e) { // Form text e.Canvas.DrawText(control.Text.Trim(), Theme.UIFont, e.LogicalToDeviceUnits(Theme.FontSize), control.Bounds, Theme.LightTextColor, ContentAlignment.MiddleCenter); }
/// <summary> /// Gets the bounding box of the area to draw the drop down glyph. /// </summary> protected Rectangle GetDropDownButtonArea(ComboBox control, PaintEventArgs e) { var glyph_size = e.LogicalToDeviceUnits(GLYPH_SIZE); return(new Rectangle(control.ScaledWidth - glyph_size, 0, glyph_size - e.LogicalToDeviceUnits(control.Padding.Right), control.ScaledHeight)); }