using System; using System.Collections.Generic; using System.Text; using System.Windows.Forms; using System.Drawing; using System.Drawing.Drawing2D; using Nevron.UI; using Nevron.UI.WinForm.Controls; using Nevron.UI.ToolStrips; using Nevron.GraphicsCore; namespace WindowsApplication16 { public class MyNNavigationPaneRenderer : NNavigationPaneRenderer { #region Constructors public MyNNavigationPaneRenderer(NNavigationPane pane) : base(pane) { m_Radius = 10; } #endregion #region Overrides protected override void DrawCommandBackground(Graphics g, Nevron.UI.WinForm.Controls.NCommand comm) { if (((NNavigationPaneToolbar)comm.Parent).Commands.IndexOf(comm) != 0) { base.DrawCommandBackground(g, comm); } if (m_Palette.Scheme == ColorScheme.WindowsDefault) { DrawCommandBackgroundWinDef(g, comm); return; } if (m_Palette.Scheme == ColorScheme.Standard) { DrawCommandBackgroundStandard(g, comm); return; } Rectangle r = comm.VisualState.Bounds; Color c1 = Color.Empty; Color c2 = Color.Empty; switch (comm.VisualState.State) { case CommandState.Default: if (!comm.Checked) return; c1 = m_Palette.CheckedLight; c2 = m_Palette.CheckedDark; break; case CommandState.Hovered: if (comm.Checked) { c1 = m_Palette.PressedLight; c2 = m_Palette.PressedDark; } else { c1 = m_Palette.HighlightLight; c2 = m_Palette.HighlightDark; } break; case CommandState.Pushed: c1 = m_Palette.PressedLight; c2 = m_Palette.PressedDark; break; } using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush = new LinearGradientBrush(r, c1, c2, 90f)) { NBrushHelper.ApplyBlend(linearGradientBrush, m_Palette.BlendStyle); FillRoundRect(g, linearGradientBrush, r, m_Radius, RoundedLocation.BottomRight); } } public override void DrawToolbarBackground(Graphics g, Rectangle r) { NNavigationPane parent = (NNavigationPane)Parent; NUIRenderer.DrawTransparentBackground(g, parent.Parent, parent.Controls[0], r); switch (m_Palette.Scheme) { case ColorScheme.Standard: g.Clear(m_Palette.Control); break; case ColorScheme.WindowsDefault: if (m_Palette.ThemeEnabled) g.Clear(m_Palette.Control); else g.Clear(NColorHelper.Dark(m_Palette.Control)); break; default: Color c1 = m_Palette.ControlLight; Color c2 = m_Palette.ControlDark; using (System.Drawing.Drawing2D.LinearGradientBrush linearGradientBrush = new LinearGradientBrush(r, c1, c2, 90f)) { NBrushHelper.ApplyBlend(linearGradientBrush, m_Palette.BlendStyle); FillRoundRect(g, linearGradientBrush, r, m_Radius, RoundedLocation.Bottom); } break; } } public override void DrawCaption(Graphics g, NButtonItem item) { NRectangle r = item.DeviceBounds; if (r.Width <= 0 || r.Height <= 0) return; r.Width += 1; r.Height += 1; r.X -= 1; r.Y -= 1; Color c1, c2; c1 = c2 = Color.Empty; g.SmoothingMode = SmoothingMode.AntiAlias; Rectangle gdiRect = r.ToRectangle(); switch (m_Palette.Scheme) { case ColorScheme.WindowsDefault: Brush.Color = NColorHelper.Dark(m_Palette.Control); FillRoundRect(g, Brush, gdiRect, m_Radius, RoundedLocation.Top); break; case ColorScheme.Standard: Brush.Color = m_Palette.ControlDark; FillRoundRect(g, Brush, gdiRect, m_Radius, RoundedLocation.Top); break; default: c1 = ControlPaint.Light(m_Palette.Caption); c2 = ControlPaint.Dark(m_Palette.Caption); using (LinearGradientBrush br = new LinearGradientBrush(gdiRect, c1, c2, 90.0f)) { FillRoundRect(g, br, gdiRect, m_Radius, RoundedLocation.Top); } break; } if (((NNavigationPane)Parent).State == NNavigationPane.PaneState.Collapsed) { return; } DrawItemImage(g, item); string text = (string)item.GetRenderCacheEntry(UIRenderCacheEntries.Text); if (text == null) return; object obj = item.GetRenderCacheEntry(UIRenderCacheEntries.TextBounds); if (!(obj is NRectangle)) return; NRectangle txtBounds = (NRectangle)obj; if (r.Width == 0 || r.Height == 0) return; NThemeStyle style = item.CurrentStyle; if (style == null) return; Font f = style.FontInfo.ToFont(); Color c; if (!item.Enabled) { c = SystemColors.GrayText; } else { c = Color.White; } int mask = item.CurrentStyle.GdiTextFormat.FormatMask; NTextRenderer.DrawText(g, f, txtBounds, text, c, mask, TextOrientation.Horizontal); } protected override void DrawParentBorder(Graphics g) { Rectangle r = Parent.ClientRectangle; r.Width -= 1; r.Height -= 1; DrawRoundRect(g, new Pen(m_Palette.ControlBorder), r, m_Radius, RoundedLocation.All); } #endregion #region Implementation protected virtual GraphicsPath GetGraphicsPath(Rectangle r, float radius, RoundedLocation roundedLocation) { GraphicsPath gp = new GraphicsPath(); switch (roundedLocation) { case RoundedLocation.All: { gp.AddLine(r.X + radius, r.Y, r.X + r.Width - (radius * 2), r.Y); // Line gp.AddArc(r.X + r.Width - (radius * 2), r.Y, radius * 2, radius * 2, 270, 90); // Corner gp.AddLine(r.X + r.Width, r.Y + radius, r.X + r.Width, r.Y + r.Height - (radius * 2)); // Line gp.AddArc(r.X + r.Width - (radius * 2), r.Y + r.Height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner gp.AddLine(r.X + r.Width - (radius * 2), r.Y + r.Height, r.X + radius, r.Y + r.Height); // Line gp.AddArc(r.X, r.Y + r.Height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner gp.AddLine(r.X, r.Y + r.Height - (radius * 2), r.X, r.Y + radius); // Line gp.AddArc(r.X, r.Y, radius * 2, radius * 2, 180, 90); // Corner gp.CloseFigure(); break; } case RoundedLocation.Top: { gp.AddLine(r.X + radius, r.Y, r.X + r.Width - (radius * 2), r.Y); // Line gp.AddArc(r.X + r.Width - (radius * 2), r.Y, radius * 2, radius * 2, 270, 90); // Corner gp.AddLine(r.X + r.Width, r.Y + radius, r.X + r.Width, r.Y + r.Height); // Line gp.AddLine(r.X + r.Width, r.Y + r.Height, r.X, r.Y + r.Height); // Line gp.AddLine(r.X, r.Y + r.Height, r.X, r.Y + radius); // Line gp.AddArc(r.X, r.Y, radius * 2, radius * 2, 180, 90); // Corner gp.CloseFigure(); break; } case RoundedLocation.Bottom: { gp.AddLine(r.X, r.Y, r.X + r.Width, r.Y); // Line gp.AddLine(r.X + r.Width, r.Y, r.X + r.Width, r.Y + r.Height - radius); // Line gp.AddArc(r.X + r.Width - (radius * 2), r.Y + r.Height - (radius * 2), radius * 2, radius * 2, 0, 90); // Corner gp.AddLine(r.X + r.Width - (radius * 2), r.Y + r.Height, r.X + radius, r.Y + r.Height); // Line gp.AddArc(r.X, r.Y + r.Height - (radius * 2), radius * 2, radius * 2, 90, 90); // Corner gp.AddLine(r.X, r.Y + r.Height - radius, r.X, r.Y); // Line gp.CloseFigure(); break; } } return gp; } protected virtual void FillRoundRect(Graphics g, Brush brush, Rectangle r, float radius, RoundedLocation roundedLocation) { GraphicsPath gp = GetGraphicsPath(r, radius, roundedLocation); g.FillPath(brush, gp); gp.Dispose(); } protected virtual void DrawRoundRect(Graphics g, Pen p, Rectangle r, float radius, RoundedLocation roundedLocation) { GraphicsPath gp = GetGraphicsPath(r, radius, roundedLocation); g.DrawPath(p, gp); gp.Dispose(); } #endregion #region Fileds protected float m_Radius; #endregion } public enum RoundedLocation { Top, Bottom, All, BottomRight, } }