/// <summary> /// Draw method /// </summary> protected override void OnPaint(PaintEventArgs e) { // Base painting base.OnPaint(e); // Graphics Graphics g = e.Graphics; // Clear control g.Clear(Parent.BackColor); // Client rectangle Rectangle r = ClientRectangle; // Draw raised button if (_buttonType == ButtonType.Raised) { // Fill color Color fill = new Color(); // Button is filled with his Accent color if (_customColor) { // If control is enabled if (Enabled) { // Control enabled fill = ColorExtensions.AddRGB((Component.SourceTheme.DARK_BASED) ? +(_hoverAlpha / 15) : -(_hoverAlpha / 15), Component.Accent); } else { // Control disabled fill = Component.SourceTheme.COMPONENT_FILL.Disabled; } // Fill client rectangle with correct color (background layer) using (SolidBrush brush = new SolidBrush(fill)) g.FillRectangle(brush, ClientRectangle); // Turn on anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Mouse position relative to parent form Point mouse = PointToClient(Cursor.Position); // Draw reveal effect // Reveal effect ellipse GraphicsPath ellipse = Draw.GetEllipsePath(mouse, _revealDistance); // Path gradient brush PathGradientBrush pgb = new PathGradientBrush(ellipse); pgb.CenterPoint = mouse; pgb.CenterColor = ColorExtensions.AddRGB(Component.SourceTheme.DARK_BASED ? 70 : -70, Accent); pgb.SurroundColors = new Color[] { ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, fill), fill) }; // Draw reveal effect if mouse is hovering over an item if (!DesignMode) { g.FillPath(pgb, ellipse); } // Turn off anti-aliasing g.SmoothingMode = SmoothingMode.Default; // Shortcut variable for client rectangle Rectangle cr = ClientRectangle; // Fill client rectangle with correct color (foreground layer) using (SolidBrush brush = new SolidBrush(fill)) g.FillRectangle(brush, new Rectangle(cr.X + 2, cr.Y + 2, cr.Width - 4, cr.Height - 4)); } else { // Regular raised button fill = ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, Component.SourceTheme.COMPONENT_FILL.Hover), Component.SourceTheme.COMPONENT_FILL.Normal.ToColor()); // Control is disabled if (!Enabled) { // Change fill color fill = Component.SourceTheme.COMPONENT_FILL.Disabled; } // Fill client rectangle with correct color (background layer) using (SolidBrush brush = new SolidBrush(fill)) g.FillRectangle(brush, ClientRectangle); // Turn on anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Mouse position relative to parent form Point mouse = PointToClient(Cursor.Position); // Draw reveal effect // Reveal effect ellipse GraphicsPath ellipse = Draw.GetEllipsePath(mouse, _revealDistance); // Path gradient brush PathGradientBrush pgb = new PathGradientBrush(ellipse); pgb.CenterPoint = mouse; pgb.CenterColor = Component.SourceTheme.COMPONENT_HIGHLIGHT.Normal.ToColor(); pgb.SurroundColors = new Color[] { ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, fill), fill) }; // Draw reveal effect if mouse is hovering over an item if (!DesignMode) { g.FillPath(pgb, ellipse); } // Turn off anti-aliasing g.SmoothingMode = SmoothingMode.Default; // Shortcut variable for client rectangle Rectangle cr = ClientRectangle; // Fill client rectangle with correct color (foreground layer) using (SolidBrush brush = new SolidBrush(fill)) g.FillRectangle(brush, new Rectangle(cr.X + 2, cr.Y + 2, cr.Width - 4, cr.Height - 4)); } // Draw click-effect DrawClick(e); // Draws text DrawText(e); } // Draws outlined button if (_buttonType == ButtonType.Outline) { // Fill color Color fill = new Color(); // Border color Color border = new Color(); // Button is filled with his Accent color if (_customColor) { // Full-colored outlined button fill = ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, ColorExtensions.Fade(220, Component.Accent, Parent.BackColor)), Parent.BackColor); border = (Enabled) ? Component.Accent : Component.SourceTheme.COMPONENT_FILL.Disabled.ToColor(); // Control is not enabled if (!Enabled) { fill = Parent.BackColor; } } else { // Full colored outlined button fill = ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, ColorExtensions.Fade(220, Component.SourceTheme.COMPONENT_BORDER.Normal, Parent.BackColor)), Parent.BackColor); border = (Enabled) ? Component.SourceTheme.COMPONENT_FILL.Normal.ToColor() : Component.SourceTheme.COMPONENT_FILL.Disabled.ToColor(); // Control is not enabled if (!Enabled) { fill = Parent.BackColor; } } // Fills client rectangle using (SolidBrush brush = new SolidBrush(border)) g.FillRectangle(brush, r); // Turn on anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Mouse position relative to parent form Point mouse = PointToClient(Cursor.Position); // Draw reveal effect // Reveal effect ellipse GraphicsPath ellipse = Draw.GetEllipsePath(mouse, _revealDistance); // Path gradient brush PathGradientBrush pgb = new PathGradientBrush(ellipse); pgb.CenterPoint = mouse; pgb.CenterColor = (CustomColor) ? ColorExtensions.AddRGB(Component.SourceTheme.DARK_BASED ? 70 : -70, Accent) : Component.SourceTheme.COMPONENT_HIGHLIGHT.Normal.ToColor(); pgb.SurroundColors = new Color[] { ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, border), border) }; // Draw reveal effect if mouse is hovering over an item if (!DesignMode) { g.FillPath(pgb, ellipse); } // Turn off anti-aliasing g.SmoothingMode = SmoothingMode.Default; // Fills border (frame) using (SolidBrush pen = new SolidBrush(fill)) g.FillRectangle(pen, new Rectangle(r.X + 2, r.Y + 2, r.Width - 4, r.Height - 4)); // Draws click effect DrawClick(e); // Text DrawText(e); } // Flat button if (_buttonType == ButtonType.Flat) { // Fill color Color fill = new Color(); // Button is filled with his Accent color if (_customColor) { // Full colored outlined button fill = ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, ColorExtensions.Fade(220, Component.Accent, Parent.BackColor)), Parent.BackColor); // Control is not enabled if (!Enabled) { fill = Parent.BackColor; } } else { // Full colored outlined button fill = ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, ColorExtensions.Fade(160, Component.SourceTheme.COMPONENT_BORDER.Normal, Parent.BackColor)), Parent.BackColor); // Control is not enabled if (!Enabled) { fill = Parent.BackColor; } } // Fills rectangle (background layer) using (SolidBrush brush = new SolidBrush(fill)) g.FillRectangle(brush, r); // Turn on anti-aliasing g.SmoothingMode = SmoothingMode.AntiAlias; // Mouse position relative to parent form Point mouse = PointToClient(Cursor.Position); // Draw reveal effect // Reveal effect ellipse GraphicsPath ellipse = Draw.GetEllipsePath(mouse, _revealDistance); // Path gradient brush PathGradientBrush pgb = new PathGradientBrush(ellipse); pgb.CenterPoint = mouse; pgb.CenterColor = (CustomColor) ? Color.FromArgb(255, Accent) : Component.SourceTheme.COMPONENT_HIGHLIGHT.Normal.ToColor(); pgb.SurroundColors = new Color[] { ColorExtensions.Mix(Color.FromArgb(_hoverAlpha, fill), fill) }; // Draw reveal effect if mouse is hovering over an item if (!DesignMode) { g.FillPath(pgb, ellipse); } // Turn off anti-aliasing g.SmoothingMode = SmoothingMode.Default; // Shortcut variable for client rectangle Rectangle cr = ClientRectangle; // Fills rectangle (foreground layer) using (SolidBrush brush = new SolidBrush(fill)) g.FillRectangle(brush, new Rectangle(cr.X + 2, cr.Y + 2, cr.Width - 4, cr.Height - 4)); // Draws click-effect DrawClick(e); // Draws text DrawText(e); } }