﻿Imports System.Drawing.Drawing2D


Public Class clsVistaToolStripRenderer
    Inherits System.Windows.Forms.ToolStripSystemRenderer


    '// List of all colors

    'Main background
    Public clrBGTop1 As Color = Color.FromArgb(255, 127, 166, 191)
    Public clrBGTop2 As Color = Color.FromArgb(255, 4, 72, 117)
    Public clrBGBottom1 As Color = Color.FromArgb(255, 57, 117, 156)
    Public clrBGBottom2 As Color = Color.FromArgb(150, 255, 255, 255)
    Public clrBGBorder As Color = Color.FromArgb(200, 176, 200, 216)
    Public clrBGGreen As Color = Color.FromArgb(100, 57, 161, 133)

    'Buttons
    Public clrBtnDarkBorder As Color = Color.FromArgb(200, 3, 50, 81)
    Public clrBtnLightBorder As Color = Color.FromArgb(200, 216, 228, 236)


    Public Sub DrawRoundedRectangle(ByVal objGraphics As Graphics, _
                                ByVal m_intxAxis As Integer, _
                                ByVal m_intyAxis As Integer, _
                                ByVal m_intWidth As Integer, _
                                ByVal m_intHeight As Integer, _
                                ByVal m_diameter As Integer, ByVal color As Color)

        Dim pen As New Pen(color)

        'Dim g As Graphics
        Dim BaseRect As New RectangleF(m_intxAxis, m_intyAxis, m_intWidth, m_intHeight)
        Dim ArcRect As New RectangleF(BaseRect.Location, New SizeF(m_diameter, m_diameter))
        'top left Arc
        objGraphics.DrawArc(pen, ArcRect, 180, 90)
        objGraphics.DrawLine(pen, m_intxAxis + CInt(m_diameter / 2), m_intyAxis, m_intxAxis + m_intWidth - CInt(m_diameter / 2), m_intyAxis)

        ' top right arc
        ArcRect.X = BaseRect.Right - m_diameter
        objGraphics.DrawArc(pen, ArcRect, 270, 90)
        objGraphics.DrawLine(pen, m_intxAxis + m_intWidth, m_intyAxis + CInt(m_diameter / 2), m_intxAxis + m_intWidth, m_intyAxis + m_intHeight - CInt(m_diameter / 2))

        ' bottom right arc
        ArcRect.Y = BaseRect.Bottom - m_diameter
        objGraphics.DrawArc(pen, ArcRect, 0, 90)
        objGraphics.DrawLine(pen, m_intxAxis + CInt(m_diameter / 2), m_intyAxis + m_intHeight, m_intxAxis + m_intWidth - CInt(m_diameter / 2), m_intyAxis + m_intHeight)

        ' bottom left arc
        ArcRect.X = BaseRect.Left
        objGraphics.DrawArc(pen, ArcRect, 90, 90)
        objGraphics.DrawLine(pen, m_intxAxis, m_intyAxis + CInt(m_diameter / 2), m_intxAxis, m_intyAxis + m_intHeight - CInt(m_diameter / 2))

    End Sub

    Protected Overrides Sub Initialize(ByVal toolStrip As System.Windows.Forms.ToolStrip)
        MyBase.Initialize(toolStrip)
        'toolStrip.AutoSize = False
        'toolStrip.Height = 32
        toolStrip.ForeColor = Color.White
        toolStrip.Padding = New Padding(5, 2, 5, 2)
    End Sub

    Protected Overrides Sub OnRenderToolStripBorder(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
        MyBase.OnRenderToolStripBorder(e)
        ' e.Graphics.DrawRectangle(New Pen(clrBGBorder, 1), e.AffectedBounds)
    End Sub

    Protected Overrides Sub OnRenderItemText(ByVal e As System.Windows.Forms.ToolStripItemTextRenderEventArgs)
        MyBase.OnRenderItemText(e)
        'e.Graphics.DrawString(e.Text, e.Item.Font, Brushes.Gray, 20, 6)
    End Sub

    Protected Overrides Sub OnRenderItemBackground(ByVal e As System.Windows.Forms.ToolStripItemRenderEventArgs)
        MyBase.OnRenderItemBackground(e)
        'e.Item.

    End Sub

    Protected Overrides Sub OnRenderToolStripBackground(ByVal e As System.Windows.Forms.ToolStripRenderEventArgs)
        MyBase.OnRenderToolStripBackground(e)
        Dim topRect As New Rectangle(0, 0, e.ToolStrip.Width + 2, e.ToolStrip.Height / 2) '16
        Dim bottomRect As New Rectangle(0, e.ToolStrip.Height / 2, e.ToolStrip.Width + 2, e.ToolStrip.Height / 2) '16
        'Dim bottomGradRect As New Rectangle(0, 23, e.ToolStrip.Width + 2, 7)

        Dim topBrush As New LinearGradientBrush(topRect, clrBGTop1, clrBGBottom1, LinearGradientMode.Vertical)
        Dim bottomBrush As New LinearGradientBrush(bottomRect, clrBGTop2, clrBGBottom2, LinearGradientMode.Vertical)
        'Dim bottomBrush As New SolidBrush(clrBGTop2)
        'Dim bottomGradBrush As New LinearGradientBrush(bottomGradRect, clrBGTop2, clrBGBottom2, LinearGradientMode.Vertical)
        Dim horGradBrush As New LinearGradientBrush(e.AffectedBounds, Color.Transparent, clrBGGreen, LinearGradientMode.Horizontal)

        e.Graphics.FillRectangle(New SolidBrush(clrBGTop2), e.AffectedBounds)
        e.Graphics.FillRectangle(topBrush, topRect)
        e.Graphics.FillRectangle(bottomBrush, bottomRect)
        'e.Graphics.FillRectangle(bottomGradBrush, bottomGradRect)
        e.Graphics.FillRectangle(horGradBrush, e.AffectedBounds)
        e.Graphics.DrawRectangle(New Pen(clrBGBorder, 1), New Rectangle(0, 1, e.ToolStrip.Width - 1, e.ToolStrip.Height - 1))
    End Sub

    Protected Overrides Sub OnRenderToolStripPanelBackground(ByVal e As System.Windows.Forms.ToolStripPanelRenderEventArgs)
        MyBase.OnRenderToolStripPanelBackground(e)
        Dim topRect As New Rectangle(0, 0, e.ToolStripPanel.Width, 15)
        Dim bottomRect As New Rectangle(0, 15, e.ToolStripPanel.Width, 15)

        Dim topBrush As New LinearGradientBrush(topRect, clrBGTop1, clrBGBottom1, LinearGradientMode.Vertical)
        Dim bottomBrush As New LinearGradientBrush(bottomRect, clrBGTop2, clrBGBottom2, LinearGradientMode.Vertical)

        e.Graphics.FillRectangle(topBrush, topRect)
        e.Graphics.FillRectangle(bottomBrush, bottomRect)
    End Sub
End Class

