using System; using System.Collections.Generic; using System.Drawing; using System.Drawing.Drawing2D; namespace Make3UI { public class XLeftSideBar { private List m_LeftSideBarMix = new List(); private Color m_clrFillStart = Color.FromArgb(60, 60, 60); private Color m_clrFillEnd = Color.FromArgb(42, 42, 42); private Color m_clrUpperFillStart = Color.FromArgb(147, 147, 147); private Color m_clrUpperFillEnd = Color.FromArgb(93, 93, 93); private Color m_clrStart = Color.FromArgb(40, 40, 40); private Color m_clrEnd = Color.FromArgb(35, 35, 35); private Color m_clrBarSepLineUp = Color.FromArgb(27, 27, 27); private int m_lBarWidth = 22; public Rectangle rcSizeGrip = new Rectangle(); private bool m_bEllipticalGlow = true; private Color m_clrGlow = Color.FromArgb(80, 80, 80); public enum XButtonBoxFill { /// /// Rendered using color mix. /// ColorMix, /// /// Rendered using titlebar start / end rectangle colors. /// TitleBarRectangleRendering } public XButtonBoxFill m_eButtonBoxFill = XButtonBoxFill.ColorMix; public XButtonBoxFill ButtonBoxFill { get { return this.m_eButtonBoxFill; } set { this.m_eButtonBoxFill = value; } } public enum XLeftSideBarBackImageAlign { /// /// Top aligned image. /// Top, /// /// Middle aligned image. /// Center, /// /// Bottom aligned image. /// Bottom } public enum XLeftSideBarType { Rounded, Angular, Rectangular } private XLeftSideBarType m_eLeftSideBarType = XLeftSideBarType.Angular; private XLeftSideBarBackImageAlign m_eLeftSideBarImageAlign = XLeftSideBarBackImageAlign.Bottom; private bool m_bShouldRenderButtonBox = false; private Image m_LeftSideBarTexture; private Image m_LeftSideBarBackImage; private Color m_clrButtonBoxInner = Color.FromArgb(29, 8, 5); private Color m_clrButtonBoxOuter = Color.FromArgb(60, 65, 68); private List m_ButtonBoxColors = new List(); private List m_xlsButtons = new List(); private Color m_clrOuterLeftSideBarColor = Color.FromArgb(0, 0, 0); private Color m_clrInnerLeftSideBarColor = Color.FromArgb(52, 52, 52); public bool ShouldDrawButtonBox { get { return this.m_bShouldRenderButtonBox; } } public XLeftSideBarType LeftSideBarType { get { return this.m_eLeftSideBarType; } set { this.m_eLeftSideBarType = value; } } public List LeftSideBarButtons { get { return this.m_xlsButtons; } } public enum XLeftSideBarFill { /// /// Just renders titlebar shape, without fill. /// None, /// /// Titlebar is rendering using linear gradient. /// LinearRendering, /// /// Titlebar is rendered using gradient mix and glow. /// AdvancedRendering, /// /// Titlebar is rendered with upper glow. /// UpperGlow, /// /// Titlebar is filled using two gradient rectangles. /// RectangleRendering, /// /// Titlebar is rendered using custom texture. /// Texture } public XLeftSideBarFill m_eLeftSideBarFill = XLeftSideBarFill.AdvancedRendering; public XLeftSideBarFill LeftSideBarFill { get { return this.m_eLeftSideBarFill; } set { this.m_eLeftSideBarFill = value; } } public XLeftSideBar() { // initialize button box mix colors: m_ButtonBoxColors.Add(Color.FromArgb(112, 106, 108)); m_ButtonBoxColors.Add(Color.FromArgb(56, 52, 53)); m_ButtonBoxColors.Add(Color.FromArgb(53, 49, 50)); m_ButtonBoxColors.Add(Color.FromArgb(71, 71, 71)); m_ButtonBoxColors.Add(Color.FromArgb(112, 106, 108)); // initialize titlebar mix colors: m_LeftSideBarMix.Add(Color.FromArgb(245, 245, 245)); m_LeftSideBarMix.Add(Color.FromArgb(93, 93, 93)); m_LeftSideBarMix.Add(Color.FromArgb(45, 45, 45)); m_LeftSideBarMix.Add(Color.FromArgb(30, 30, 30)); m_LeftSideBarMix.Add(Color.FromArgb(52, 52, 52)); } public void RenderLeftSideBar( Graphics g, Rectangle rcLSb ) { FillLeftSideBar(g, rcLSb); //DrawTitleBarText(g, m_clrCaptionFont, m_sCaption, rcTb); } /// /// /// /// /// private GraphicsPath BuildLeftSideBarShape( Rectangle rc ) { GraphicsPath e = new GraphicsPath(); switch (m_eLeftSideBarType) { case XLeftSideBarType.Rounded: e.AddArc( rc.Left, rc.Top, rc.Height, rc.Height, 90, 180); e.AddLine( rc.Left + rc.Height / 2, rc.Top, rc.Right, rc.Top ); e.AddArc( rc.Right, rc.Top, rc.Height, rc.Height, -90, 180); e.AddLine( rc.Right, rc.Bottom, rc.Left + rc.Height / 2, rc.Bottom); break; case XLeftSideBarType.Angular: e.AddLine(rc.Left, rc.Top, rc.Right, rc.Top + 30); e.AddLine(rc.Right, rc.Top + 30, rc.Right, rc.Top + 60); e.AddLine(rc.Right, rc.Top + 60, rc.Left, rc.Top + 90); e.AddLine(rc.Left, rc.Top + 90, rc.Left, rc.Top + 120); e.AddLine(rc.Left, rc.Top + 120, rc.Right, rc.Top + 150); e.AddLine(rc.Right, rc.Top + 150, rc.Right, rc.Top + 180); e.AddLine(rc.Right, rc.Top + 180, rc.Left, rc.Top + 210); e.AddLine(rc.Left, rc.Top + 210, rc.Left, rc.Top + 240); e.AddLine(rc.Left, rc.Top + 240, rc.Right, rc.Top + 270); e.AddLine(rc.Right, rc.Top + 270, rc.Right, rc.Top + 300); e.AddLine(rc.Right, rc.Top + 300, rc.Left, rc.Top + 330); e.AddLine(rc.Left, rc.Top + 330, rc.Left, rc.Top + 360); e.AddLine(rc.Left, rc.Top + 360, rc.Right, rc.Top + 390); e.AddLine(rc.Right, rc.Top + 390, rc.Right, rc.Bottom); e.AddLine(rc.Right, rc.Bottom, rc.Left, rc.Bottom - 30); e.AddLine(rc.Left, rc.Bottom - 30, rc.Left, rc.Top); //e.AddLine(rc.Right, rc.Top + 60, rc.Right, rc.Bottom); break; case XLeftSideBarType.Rectangular: e.AddRectangle(rc); break; } return e; } private void DrawLeftSideBarBackImage( Graphics g, Rectangle rcTitlebar, GraphicsPath clip ) { if (m_LeftSideBarBackImage != null) { int lH = m_LeftSideBarBackImage.Height; int lW = m_LeftSideBarBackImage.Width; Rectangle rcIcon = new Rectangle( 0, 0, lW, lH ); switch (m_eLeftSideBarImageAlign) { case XLeftSideBarBackImageAlign.Bottom: rcIcon.X = rcTitlebar.Right - lW; rcIcon.Y = rcTitlebar.Bottom / 2 - lH / 2; break; case XLeftSideBarBackImageAlign.Center: rcIcon.X = rcTitlebar.Right / 2 - lW / 2 + rcTitlebar.Height / 2; rcIcon.Y = rcTitlebar.Bottom / 2 - lH / 2; break; case XLeftSideBarBackImageAlign.Top: rcIcon.X = rcTitlebar.Left - rcTitlebar.Height / 2; rcIcon.Y = rcTitlebar.Bottom / 2 - lH / 2; break; } // draw image: g.SetClip(clip); g.DrawImage( m_LeftSideBarBackImage, rcIcon ); g.ResetClip(); } } public void RenderLeftSideBarButtonsBox( Rectangle rcBox, Graphics g, int lSinglePosX, int lSinglePosY ) { using (XAntiAlias xaa = new XAntiAlias(g)) { int lBtnWidth = 0; int lBtnHeight = 0; XLeftSideBarButton btn1 = m_xlsButtons[0]; lBtnWidth = btn1.XButtonWidth; lBtnHeight = btn1.XButtonHeight; //foreach (XLeftSideBarButton btn in m_xlsButtons) //{ // if (btn.ButtonStyle == XLeftSideBarButton.XLeftSideBarButtonStyle.MacStyle) // m_bShouldRenderButtonBox = false; // lBtnWidth = btn.XButtonWidth; // lBtnHeight = btn.XButtonHeight; //} int lX = rcBox.Right - lBtnWidth; int lY = rcBox.Bottom - lBtnHeight; if (m_bShouldRenderButtonBox) { using (GraphicsPath XButtonBox = BuildLeftSideBarButtonsBox(rcBox)) { #region RenderButtonBox switch (m_eButtonBoxFill) { case XButtonBoxFill.ColorMix: using (LinearGradientBrush lgb = new LinearGradientBrush( rcBox, m_ButtonBoxColors[0], m_ButtonBoxColors[4], LinearGradientMode.Horizontal)) { lgb.InterpolationColors = XCoolFormHelper.ColorMix ( m_ButtonBoxColors, false ); g.FillPath( lgb, XButtonBox ); } break; case XButtonBoxFill.TitleBarRectangleRendering: RectangleF rcDownRect = XButtonBox.GetBounds(); RectangleF rcUpRect = XButtonBox.GetBounds(); g.SetClip(XButtonBox); rcUpRect.Height /= 2; using (LinearGradientBrush lgbUpperRect = new LinearGradientBrush( rcUpRect, m_clrUpperFillStart, m_clrUpperFillEnd, LinearGradientMode.Vertical )) { lgbUpperRect.WrapMode = WrapMode.TileFlipY; g.FillRectangle( lgbUpperRect, rcUpRect ); } rcDownRect.Height = rcDownRect.Height / 2; rcDownRect.Y = rcUpRect.Bottom; using (LinearGradientBrush lgbDwnRect = new LinearGradientBrush( rcDownRect, m_clrFillStart, m_clrFillEnd, LinearGradientMode.Vertical )) { g.FillRectangle( lgbDwnRect, rcDownRect ); } g.ResetClip(); break; } #endregion #region Draw button separators g.DrawLine( new Pen(m_clrButtonBoxOuter), rcBox.Right - lBtnWidth, rcBox.Bottom, rcBox.Right - lBtnWidth, rcBox.Top + 1); g.DrawLine( new Pen(m_clrButtonBoxInner), rcBox.Right - lBtnWidth - 1, rcBox.Bottom, rcBox.Right - lBtnWidth - 1, rcBox.Top + 1); g.DrawLine( new Pen(m_clrButtonBoxOuter), rcBox.Right - lBtnWidth * 2, rcBox.Bottom - 2, rcBox.Right - lBtnWidth * 2, rcBox.Top + 1); g.DrawLine( new Pen(m_clrButtonBoxInner), rcBox.Right - lBtnWidth * 2 - 1, rcBox.Bottom - 2, rcBox.Right - lBtnWidth * 2 - 1, rcBox.Top + 1); #endregion #region Render buttons g.SetClip(XButtonBox); int i = 0; foreach (XLeftSideBarButton btn in m_xlsButtons) { btn.XButtonLeft = lX; btn.XButtonTop = lY; btn.RenderLeftSideBarButton( i, btn.XButtonLeft, btn.XButtonTop, g, XButtonBox ); //lX -= btn.XButtonWidth + 1; lY += 60; i++; } g.ResetClip(); #endregion g.DrawPath( new Pen(m_clrButtonBoxOuter), XButtonBox ); DrawInnerLeftSideBarBoxBorder(g, rcBox, m_clrButtonBoxInner); } } else { #region render Buttons int lSPx = lSinglePosX; int lSPy = lSinglePosY; int i = 0; foreach (XLeftSideBarButton btn in m_xlsButtons) { btn.XButtonHeight = 13; btn.XButtonWidth = 13; btn.XButtonLeft = lSPx; btn.XButtonTop = lSPy; btn.RenderLeftSideBarButton( i, btn.XButtonLeft, btn.XButtonTop, g, null ); // lSP -= btn.XButtonWidth + 4; lSPy += 60; i++; } #endregion } } } public int HitLeftSideBarButton( int x, int y, Rectangle rcHolder ) { int lBtnIndex = -1; if (x >= rcHolder.Left && x <= rcHolder.Right) { XLeftSideBarButton btn = null; for (int i = 0; i < m_xlsButtons.Count; i++) { btn = m_xlsButtons[i]; if (y >= 4 && y <= btn.XButtonTop + btn.XButtonHeight) { if (x >= btn.XButtonLeft) { if (x < btn.XButtonLeft + btn.XButtonWidth) { lBtnIndex = i; break; } } } } } return lBtnIndex; } private void DrawInnerLeftSideBarBoxBorder( Graphics g, Rectangle rcBox, Color clrInnerBorder ) { rcBox.Inflate(-1, -1); using (GraphicsPath XLeftSideBarBox = BuildLeftSideBarButtonsBox(rcBox)) { using (Pen pInner = new Pen(clrInnerBorder)) { g.DrawPath( pInner, XLeftSideBarBox ); } } } public GraphicsPath BuildLeftSideBarButtonsBox(Rectangle r) { GraphicsPath XButtonBox = new GraphicsPath(); switch (m_eLeftSideBarType) { case XLeftSideBarType.Rounded: XButtonBox.AddBezier( new Point(r.Left - 5, r.Top + 1), new Point(r.Left + 20, r.Top + 5), new Point(r.Left - 5, r.Bottom + 2), new Point(r.Left + 45, r.Bottom)); XButtonBox.AddLine( r.Left + 45, r.Bottom, r.Right - 5, r.Bottom); XButtonBox.AddBezier( new Point(r.Right - 5, r.Bottom), new Point(r.Right - 2, r.Bottom - 1), new Point(r.Right - 2, r.Bottom - 1), new Point(r.Right, r.Bottom - 5)); XButtonBox.AddLine( r.Right, r.Bottom - 5, r.Right, r.Top + 1); break; case XLeftSideBarType.Angular: //XButtonBox.AddLine(r.Left + 18,r.Top,r.Left,r.Bottom); //XButtonBox.AddLine(r.Left + 18,r.Top,r.Right - r.Height,r.Top); //XButtonBox.AddArc(r.Right - r.Height,r.Top,r.Height,r.Height,-90,180); //XButtonBox.AddLine(r.Right - r.Height,r.Bottom,r.Left,r.Bottom); break; case XLeftSideBarType.Rectangular: XButtonBox.AddLine( r.Left, r.Top, r.Left, r.Bottom); XButtonBox.AddLine( r.Left, r.Top, r.Right - r.Height, r.Top); XButtonBox.AddArc( r.Right - r.Height, r.Top, r.Height, r.Height, -90, 180); XButtonBox.AddLine( r.Right - r.Height, r.Bottom, r.Left, r.Bottom); break; } return XButtonBox; } /// /// Draws outer border for titlebar area. /// /// /// /// private void DrawOuterLeftSideBarBorder( Graphics g, Rectangle rcLeftSideBar, Color clrOuterBorder ) { using (GraphicsPath XLeftSideBarPath = BuildLeftSideBarShape(rcLeftSideBar)) { using (Pen pOuter = new Pen(clrOuterBorder)) { g.DrawPath( pOuter, XLeftSideBarPath ); } } } /// /// Draws inner border for titlebar area. /// /// /// /// private void DrawInnerLeftSideBarBorder( Graphics g, Rectangle rcLeftSideBar, Color clrInnerBorder ) { if (m_eLeftSideBarType == XLeftSideBarType.Rectangular) rcLeftSideBar.Inflate(-1, -1); else { rcLeftSideBar.X += 1; rcLeftSideBar.Inflate(0, -1); } using (GraphicsPath XLeftSideBarPath = BuildLeftSideBarShape(rcLeftSideBar)) { using (Pen pInner = new Pen(clrInnerBorder)) { g.DrawPath( pInner, XLeftSideBarPath ); } } } private void FillLeftSideBar( Graphics g, Rectangle rcLeftSideBar ) { GraphicsPath XLeftSideBarPath = new GraphicsPath(); XLeftSideBarPath = BuildLeftSideBarShape(rcLeftSideBar); m_eLeftSideBarFill = XLeftSideBarFill.LinearRendering; using (XAntiAlias xaa = new XAntiAlias(g)) { #region Fill titlebar switch (m_eLeftSideBarFill) { case XLeftSideBarFill.AdvancedRendering: using (LinearGradientBrush lgb = new LinearGradientBrush( rcLeftSideBar, m_LeftSideBarMix[0], m_LeftSideBarMix[4], LinearGradientMode.Horizontal)) { lgb.InterpolationColors = XCoolFormHelper.ColorMix( m_LeftSideBarMix, true ); g.FillPath( lgb, XLeftSideBarPath ); } #region Draw titlebar glow using (GraphicsPath XGlow = new GraphicsPath()) { XGlow.AddEllipse( rcLeftSideBar.Left, rcLeftSideBar.Bottom / 2 + 4, rcLeftSideBar.Width, rcLeftSideBar.Height ); using (PathGradientBrush pgb = new PathGradientBrush(XGlow)) { pgb.CenterColor = Color.White; pgb.SurroundColors = new Color[] { Color.FromArgb(0, 229, 121, 13) }; g.SetClip(XLeftSideBarPath); g.FillPath( pgb, XGlow ); g.ResetClip(); } } #endregion break; case XLeftSideBarFill.Texture: if (m_LeftSideBarTexture != null) { using (TextureBrush tb = new TextureBrush(m_LeftSideBarTexture)) { g.FillPath( tb, XLeftSideBarPath ); } } break; case XLeftSideBarFill.LinearRendering: RectangleF rcLinearFill = XLeftSideBarPath.GetBounds(); g.SetClip(XLeftSideBarPath); using (LinearGradientBrush lgbLinearFill = new LinearGradientBrush( rcLinearFill, m_clrFillStart, m_clrFillEnd, LinearGradientMode.Horizontal )) { g.FillRectangle( lgbLinearFill, rcLinearFill ); } g.ResetClip(); break; case XLeftSideBarFill.UpperGlow: RectangleF rcGlow = XLeftSideBarPath.GetBounds(); g.SetClip(XLeftSideBarPath); rcGlow.Height /= 2; using (LinearGradientBrush lgbUpperGlow = new LinearGradientBrush( rcGlow, m_clrUpperFillStart, m_clrUpperFillEnd, LinearGradientMode.Vertical )) { g.FillRectangle( lgbUpperGlow, rcGlow ); } g.ResetClip(); break; case XLeftSideBarFill.RectangleRendering: RectangleF rcDownRect = XLeftSideBarPath.GetBounds(); RectangleF rcUpRect = XLeftSideBarPath.GetBounds(); g.SetClip(XLeftSideBarPath); rcUpRect.Height /= 2; using (LinearGradientBrush lgbUpperRect = new LinearGradientBrush( rcLeftSideBar, m_clrUpperFillStart, m_clrUpperFillEnd, LinearGradientMode.ForwardDiagonal )) { lgbUpperRect.WrapMode = WrapMode.TileFlipY; g.FillRectangle( lgbUpperRect, rcUpRect ); } rcDownRect.Height = rcDownRect.Height / 2; rcDownRect.Y = rcUpRect.Bottom; using (LinearGradientBrush lgbDwnRect = new LinearGradientBrush( rcDownRect, m_clrFillStart, m_clrFillEnd, LinearGradientMode.Vertical )) { g.FillRectangle( lgbDwnRect, rcDownRect ); } g.ResetClip(); break; } #endregion #region Draw back image DrawLeftSideBarBackImage(g, rcLeftSideBar, XLeftSideBarPath); #endregion DrawOuterLeftSideBarBorder(g, rcLeftSideBar, m_clrOuterLeftSideBarColor); DrawInnerLeftSideBarBorder(g, rcLeftSideBar, m_clrInnerLeftSideBarColor); } XLeftSideBarPath.Dispose(); } } }