0Hawk0

Endeavour Theme

Jan 20th, 2016
503
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 45.49 KB | None | 0 0
  1. Option Strict On
  2.  
  3. Imports System.Drawing.Drawing2D
  4. Imports System.Drawing.Text
  5. Imports System.ComponentModel
  6.  
  7. Module AnimationManager
  8.  
  9.     Interface IAnimatable
  10.         Property IsAnimating As Boolean
  11.         Sub Animate()
  12.     End Interface
  13.  
  14.     Private WithEvents animTimer As New Timer
  15.     Private animControls As New List(Of Control)
  16.     Private childControls As New List(Of Control)
  17.  
  18.     Public Property Interval As Integer
  19.         Get
  20.             Return animTimer.Interval
  21.         End Get
  22.         Set(value As Integer)
  23.             animTimer.Interval = If(value >= 10, value, 10)
  24.         End Set
  25.     End Property
  26.  
  27.     Sub New()
  28.         Interval = 20
  29.         animTimer.Enabled = True
  30.     End Sub
  31.  
  32.     Private Sub animTimer_Tick(sender As Object, e As EventArgs) Handles animTimer.Tick
  33.         For Each animCtrl As IAnimatable In animControls
  34.             If animCtrl.IsAnimating Then animCtrl.Animate()
  35.         Next
  36.     End Sub
  37.  
  38.     Public Sub Add(ByVal animCtrl As Control)
  39.         If TypeOf animCtrl Is IAnimatable AndAlso Not animControls.Contains(animCtrl) Then
  40.             animControls.Add(animCtrl)
  41.         End If
  42.     End Sub
  43.  
  44.     Public Sub AddAllFromContainer(ByVal container As ContainerControl)
  45.         childControls.Clear()
  46.         For Each animCtrl As Control In GetAllChildren(container)
  47.             Add(animCtrl)
  48.         Next
  49.     End Sub
  50.  
  51.     Public Sub AddRange(ByVal animCtrls As Control())
  52.         For Each animCtrl As Control In animCtrls
  53.             Add(animCtrl)
  54.         Next
  55.     End Sub
  56.  
  57.     Public Sub Clear()
  58.         animControls.Clear()
  59.     End Sub
  60.  
  61.     Public Sub Remove(ByVal animCtrl As Control)
  62.         If animControls.Contains(animCtrl) Then animControls.Remove(animCtrl)
  63.     End Sub
  64.  
  65.     Public Sub RemoveAllFromContainer(container As ContainerControl)
  66.         childControls.Clear()
  67.         For Each animCtrl As Control In GetAllChildren(container)
  68.             Remove(animCtrl)
  69.         Next
  70.     End Sub
  71.  
  72.     Public Sub RemoveRange(ByVal animates As IAnimatable())
  73.         For Each animCtrl As Control In animates
  74.             Remove(animCtrl)
  75.         Next
  76.     End Sub
  77.  
  78.     Private Function GetAllChildren(control As Control) As Control()
  79.         For Each ctrl As Control In control.Controls
  80.             GetAllChildren(ctrl)
  81.             childControls.Add(ctrl)
  82.         Next
  83.         Return childControls.ToArray()
  84.     End Function
  85.  
  86. End Module
  87.  
  88. Module EndeavourHelper
  89.  
  90.     Enum MouseState
  91.         None
  92.         Over
  93.         Down
  94.     End Enum
  95.  
  96.     Public Function AlterColor(originalColor As Color, difference As Integer, Optional keepAlpha As Boolean = True) As Color
  97.  
  98.         With originalColor
  99.  
  100.             Dim a, r, g, b As Integer
  101.  
  102.             a = If(keepAlpha, .A, 255)
  103.             r = SetInteger(.R + difference)
  104.             g = SetInteger(.G + difference)
  105.             b = SetInteger(.B + difference)
  106.  
  107.             Return Color.FromArgb(a, r, g, b)
  108.  
  109.         End With
  110.  
  111.     End Function
  112.  
  113.     Public Function SetInteger(intendedValue As Integer, Optional minimum As Integer = 0, Optional maximum As Integer = 255) As Integer
  114.  
  115.         If intendedValue < minimum Then
  116.             Return minimum
  117.         ElseIf intendedValue > maximum Then
  118.             Return maximum
  119.         Else
  120.             Return intendedValue
  121.         End If
  122.  
  123.     End Function
  124.  
  125.     Public Function CreateRound(rect As Rectangle, slope As Integer, topLeft As Boolean, topRight As Boolean, bottomRight As Boolean, bottomLeft As Boolean) As GraphicsPath
  126.  
  127.         Dim gp As New GraphicsPath()
  128.  
  129.         gp.StartFigure()
  130.  
  131.         If slope <= 0 Then
  132.             gp.AddRectangle(rect)
  133.             gp.CloseFigure()
  134.             Return gp
  135.         End If
  136.  
  137.         Dim arcWidth As Integer = slope * 2
  138.  
  139.         If topLeft Then
  140.             gp.AddArc(New Rectangle(rect.X, rect.Y, arcWidth, arcWidth), -180, 90)
  141.         Else
  142.             gp.AddLine(rect.X, rect.Y, rect.X + 1, rect.Y)
  143.         End If
  144.  
  145.         If topRight Then
  146.             gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Y, arcWidth, arcWidth), -90, 90)
  147.         Else
  148.             gp.AddLine(rect.X + rect.Width, rect.Y, rect.X + rect.Width, rect.Y + 1)
  149.         End If
  150.  
  151.         If bottomRight Then
  152.             gp.AddArc(New Rectangle(rect.Width - arcWidth + rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 0, 90)
  153.         Else
  154.             gp.AddLine(rect.X + rect.Width, rect.Y + rect.Height, rect.X + rect.Width - 1, rect.Y + rect.Height)
  155.         End If
  156.  
  157.         If bottomLeft Then
  158.             gp.AddArc(New Rectangle(rect.X, rect.Height - arcWidth + rect.Y, arcWidth, arcWidth), 90, 90)
  159.         Else
  160.             gp.AddLine(rect.X, rect.Y + rect.Height, rect.X, rect.Y + rect.Height - 1)
  161.         End If
  162.  
  163.         gp.CloseFigure()
  164.  
  165.         Return gp
  166.  
  167.     End Function
  168.  
  169.     Public Function CreateRound(rect As Rectangle, slope As Integer) As GraphicsPath
  170.         Return CreateRound(rect, slope, True, True, True, True)
  171.     End Function
  172.  
  173.     Class RelationalColorSwitcher
  174.  
  175.         Private _currentColor As Color
  176.  
  177.         Private _transitions As Integer
  178.         Private _transitionsLapsed As Integer
  179.  
  180.         Private currentValues(3) As Double
  181.         Private increments(3) As Double
  182.  
  183.         Public Property OriginalColor As Color
  184.         Public Property NewColor As Color
  185.  
  186.         Public ReadOnly Property CurrentColor As Color
  187.             Get
  188.                 Return _currentColor
  189.             End Get
  190.         End Property
  191.  
  192.         Public ReadOnly Property Transitions As Integer
  193.             Get
  194.                 Return _transitions
  195.             End Get
  196.         End Property
  197.  
  198.         Public ReadOnly Property TransitionsLapsed As Integer
  199.             Get
  200.                 Return _transitionsLapsed
  201.             End Get
  202.         End Property
  203.  
  204.         Sub New(originalColor As Color, newColor As Color, Optional transitions As Integer = 10)
  205.  
  206.             Me.OriginalColor = originalColor
  207.             Me.NewColor = newColor
  208.             _transitions = transitions
  209.  
  210.             _transitionsLapsed = 0
  211.  
  212.             currentValues = GetValues(originalColor)
  213.  
  214.             GetIncrements(GetValues(originalColor), GetValues(newColor))
  215.  
  216.         End Sub
  217.  
  218.         Public Sub Transition()
  219.  
  220.             For i As Integer = 0 To 3
  221.                 currentValues(i) += increments(i)
  222.             Next
  223.  
  224.             _currentColor = Color.FromArgb(
  225.                 SetInteger(CInt(currentValues(0))), _
  226.                 SetInteger(CInt(currentValues(1))), _
  227.                 SetInteger(CInt(currentValues(2))), _
  228.                 SetInteger(CInt(currentValues(3))))
  229.  
  230.             _transitionsLapsed += 1
  231.  
  232.         End Sub
  233.  
  234.         Private Sub GetIncrements(originalValues As Double(), newValues As Double())
  235.  
  236.             For i As Integer = 0 To 3
  237.                 increments(i) = (newValues(i) - originalValues(i)) / _transitions
  238.             Next
  239.  
  240.         End Sub
  241.  
  242.         Private Function GetValues(color As Color) As Double()
  243.             Return New Double() {CDbl(color.A), CDbl(color.R), CDbl(color.G), CDbl(color.B)}
  244.         End Function
  245.  
  246.     End Class
  247.  
  248. End Module
  249.  
  250. MustInherit Class EndeavourControl
  251.     Inherits Control
  252.  
  253.     Private _borderRectangle As Rectangle
  254.  
  255.     Protected g As Graphics
  256.  
  257.     Public Shadows Property BackColor As Color
  258.         Get
  259.             Return Color.Transparent
  260.         End Get
  261.         Set(value As Color)
  262.             If Not value = Color.Transparent Then
  263.                 Throw New Exception("BackColor must be transparent.")
  264.             End If
  265.         End Set
  266.     End Property
  267.  
  268.     Protected ReadOnly Property BorderRectangle As Rectangle
  269.         Get
  270.             Return _borderRectangle
  271.         End Get
  272.     End Property
  273.  
  274.     Sub New()
  275.  
  276.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  277.                  ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor Or _
  278.                  ControlStyles.UserPaint, True)
  279.  
  280.         BackColor = Color.Transparent
  281.  
  282.     End Sub
  283.  
  284.     Protected MustOverride Overrides Sub OnPaint(e As PaintEventArgs)
  285.  
  286.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  287.         _borderRectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  288.     End Sub
  289.  
  290.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  291.         Invalidate()
  292.     End Sub
  293.  
  294. End Class
  295.  
  296. MustInherit Class EndeavourContainer
  297.     Inherits ContainerControl
  298.  
  299.     Private _borderRectangle As Rectangle
  300.  
  301.     Protected g As Graphics
  302.  
  303.     Public Shadows Property BackColor As Color
  304.         Get
  305.             Return Color.Transparent
  306.         End Get
  307.         Set(value As Color)
  308.             If Not value = Color.Transparent Then
  309.                 Throw New Exception("BackColor must be transparent.")
  310.             End If
  311.         End Set
  312.     End Property
  313.  
  314.     Protected ReadOnly Property BorderRectangle As Rectangle
  315.         Get
  316.             Return _borderRectangle
  317.         End Get
  318.     End Property
  319.  
  320.     Sub New()
  321.  
  322.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  323.                  ControlStyles.ResizeRedraw Or ControlStyles.SupportsTransparentBackColor Or _
  324.                  ControlStyles.UserPaint, True)
  325.  
  326.         BackColor = Color.Transparent
  327.  
  328.     End Sub
  329.  
  330.     Protected MustOverride Overrides Sub OnPaint(e As PaintEventArgs)
  331.  
  332.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  333.         _borderRectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  334.     End Sub
  335.  
  336.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  337.         Invalidate()
  338.     End Sub
  339.  
  340. End Class
  341.  
  342. Class eFormSkin
  343.     Inherits ContainerControl
  344.  
  345.     Private Const HEADER_HEIGHT As Integer = 40
  346.     Private Const FOOTER_HEIGHT As Integer = 26
  347.  
  348.     Protected g As Graphics
  349.  
  350.     Private _headerFont As Font
  351.  
  352.     Public Property HeaderFont As Font
  353.         Get
  354.             Return _headerFont
  355.         End Get
  356.         Set(value As Font)
  357.             _headerFont = value
  358.             Invalidate()
  359.         End Set
  360.     End Property
  361.  
  362.     Public Overrides Property BackColor As Color
  363.         Get
  364.             Return MyBase.BackColor
  365.         End Get
  366.         Set(value As Color)
  367.             If value <> Color.FromArgb(220, 220, 220) Then
  368.                 Throw New Exception("The BackColor of this control may not be changed.")
  369.             End If
  370.             MyBase.BackColor = Color.FromArgb(220, 220, 220)
  371.         End Set
  372.     End Property
  373.  
  374.     Private formCanMove As Boolean
  375.     Private mouseX, mouseY As Integer
  376.  
  377.     Private borderRectangle As Rectangle
  378.     Private borderPath As GraphicsPath
  379.  
  380.     Private backBrush As SolidBrush
  381.  
  382.     Private headerRectangle As Rectangle
  383.     Private headerPath As GraphicsPath
  384.     Private headerGradientBrush As LinearGradientBrush
  385.  
  386.     Private footerRectangle As Rectangle
  387.     Private footerPath As GraphicsPath
  388.     Private footerGradientBrush As LinearGradientBrush
  389.  
  390.     Private borderPen As Pen
  391.     Private borderHighlightPen As Pen
  392.  
  393.     Private textSize As Size
  394.     Private textX, textY As Integer
  395.  
  396.     Sub New()
  397.  
  398.         SetStyle(ControlStyles.AllPaintingInWmPaint Or ControlStyles.OptimizedDoubleBuffer Or _
  399.             ControlStyles.ResizeRedraw Or ControlStyles.UserPaint, True)
  400.  
  401.         BackColor = Color.FromArgb(220, 220, 220)
  402.         Padding = New Padding(6, 46, 6, 32)
  403.  
  404.         HeaderFont = New Font("Segoe UI", 11)
  405.  
  406.         backBrush = New SolidBrush(Color.FromArgb(220, 220, 220))
  407.         borderPen = New Pen(Color.FromArgb(45, 45, 45))
  408.         borderHighlightPen = New Pen(Color.FromArgb(80, Color.White), 2)
  409.  
  410.     End Sub
  411.  
  412.     Protected Overrides Sub CreateHandle()
  413.  
  414.         MyBase.CreateHandle()
  415.  
  416.         FindForm().BackColor = Color.Fuchsia
  417.         FindForm().TransparencyKey = Color.Fuchsia
  418.         FindForm().FormBorderStyle = FormBorderStyle.None
  419.         Dock = DockStyle.Fill
  420.  
  421.     End Sub
  422.  
  423.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  424.  
  425.         g = e.Graphics
  426.         g.Clear(Color.Fuchsia)
  427.         g.SmoothingMode = SmoothingMode.HighQuality
  428.  
  429.         g.FillPath(backBrush, borderPath)
  430.  
  431.         g.FillPath(headerGradientBrush, headerPath)
  432.         g.DrawArc(borderHighlightPen, 0, 1, 12, 12, -180, 90)
  433.         g.DrawLine(borderHighlightPen, 6, 1, Width - 7, 1)
  434.         g.DrawArc(borderHighlightPen, Width - 1 - 12, 1, 12, 12, -90, 90)
  435.  
  436.         g.FillPath(footerGradientBrush, footerPath)
  437.         g.DrawLine(borderHighlightPen, 0, footerRectangle.Y + 1, Width - 1, footerRectangle.Y)
  438.  
  439.         g.DrawLine(borderPen, 0, HEADER_HEIGHT, Width - 1, HEADER_HEIGHT)
  440.         g.DrawLine(borderPen, 0, Height - 1 - FOOTER_HEIGHT, Width - 1, Height - 1 - FOOTER_HEIGHT)
  441.  
  442.         g.SmoothingMode = SmoothingMode.None
  443.         For i As Integer = 10 To 12
  444.             g.DrawArc(Pens.Fuchsia, 0, 0, i, i, -180, 90)
  445.             g.DrawArc(Pens.Fuchsia, Width - 1 - i, 0, i, i, -90, 90)
  446.             g.DrawArc(Pens.Fuchsia, Width - 1 - i, Height - 1 - i, i, i, 0, 90)
  447.             g.DrawArc(Pens.Fuchsia, 0, Height - 1 - i, i, i, 90, 90)
  448.         Next
  449.         g.DrawPath(borderPen, borderPath)
  450.  
  451.         textSize = g.MeasureString(Text, HeaderFont).ToSize()
  452.         textX = CInt((Width / 2) - (textSize.Width / 2) + 1)
  453.         textY = CInt((headerRectangle.Height / 2) - (textSize.Height / 2))
  454.         g.DrawString(Text, HeaderFont, Brushes.White, textX, textY)
  455.  
  456.     End Sub
  457.  
  458.     Protected Overrides Sub OnMouseDown(ByVal e As System.Windows.Forms.MouseEventArgs)
  459.  
  460.         mouseX = e.X
  461.         mouseY = e.Y
  462.  
  463.         formCanMove = e.Y <= HEADER_HEIGHT
  464.  
  465.     End Sub
  466.  
  467.     Protected Overrides Sub OnMouseMove(ByVal e As System.Windows.Forms.MouseEventArgs)
  468.  
  469.         If e.Y <= HEADER_HEIGHT Then
  470.             If formCanMove = True Then
  471.                 FindForm().Location = New Point(MousePosition.X - mouseX, MousePosition.Y - mouseY)
  472.             End If
  473.         End If
  474.  
  475.     End Sub
  476.  
  477.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  478.  
  479.         formCanMove = False
  480.  
  481.     End Sub
  482.  
  483.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  484.  
  485.         borderRectangle = New Rectangle(0, 0, Width - 1, Height - 1)
  486.         borderPath = CreateRound(borderRectangle, 8)
  487.  
  488.         headerRectangle = New Rectangle(0, 0, Width - 1, HEADER_HEIGHT)
  489.         headerPath = CreateRound(headerRectangle, 8, True, True, False, False)
  490.         headerGradientBrush = New LinearGradientBrush(headerRectangle, Color.FromArgb(65, 65, 65), Color.FromArgb(30, 30, 30), 90.0F)
  491.  
  492.         footerRectangle = New Rectangle(0, Height - 1 - FOOTER_HEIGHT, Width - 1, FOOTER_HEIGHT)
  493.         footerPath = CreateRound(footerRectangle, 8, False, False, True, True)
  494.         footerGradientBrush = New LinearGradientBrush(footerRectangle, Color.FromArgb(65, 65, 65), Color.FromArgb(30, 30, 30), 90.0F)
  495.  
  496.     End Sub
  497.  
  498.     Protected Overrides Sub OnTextChanged(e As EventArgs)
  499.         Invalidate()
  500.     End Sub
  501.  
  502. End Class
  503.  
  504. Class eControlButton
  505.     Inherits EndeavourControl
  506.     Implements IAnimatable
  507.  
  508.     Public Enum ControlAction
  509.         Minimize
  510.         None
  511.         Close
  512.     End Enum
  513.  
  514.     Private _mouseState As MouseState
  515.  
  516.     Public Property Action As ControlAction
  517.  
  518.     Public Property IsAnimating As Boolean Implements IAnimatable.IsAnimating
  519.  
  520.     Protected Property MouseState As MouseState
  521.         Private Set(value As MouseState)
  522.             If _mouseState <> value Then
  523.                 _mouseState = value
  524.                 SetSwitchers()
  525.                 IsAnimating = True
  526.             End If
  527.         End Set
  528.         Get
  529.             Return _mouseState
  530.         End Get
  531.     End Property
  532.  
  533.     Private borderPath As GraphicsPath
  534.  
  535.     Private defaultColors(1), overColors(1) As Color
  536.  
  537.     Private topSwitcher, bottomSwitcher As RelationalColorSwitcher
  538.     Private topColor, bottomColor As Color
  539.  
  540.     Private backGradientBrush As LinearGradientBrush
  541.  
  542.     Private borderPen As Pen
  543.  
  544.     Sub New()
  545.  
  546.         Size = New Size(10, 10)
  547.  
  548.         Action = ControlAction.None
  549.  
  550.         defaultColors = New Color() {Color.FromArgb(240, 235, 230), Color.FromArgb(185, 180, 170)}
  551.         overColors = New Color() {Color.FromArgb(125, 200, 230), Color.FromArgb(45, 130, 195)}
  552.  
  553.         topColor = defaultColors(0)
  554.         bottomColor = defaultColors(1)
  555.  
  556.         borderPen = New Pen(Color.FromArgb(25, 25, 25))
  557.  
  558.     End Sub
  559.  
  560.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  561.  
  562.         g = e.Graphics
  563.         g.Clear(Color.FromArgb(46, 46, 46))
  564.         g.SmoothingMode = SmoothingMode.HighQuality
  565.  
  566.         backGradientBrush = New LinearGradientBrush(BorderRectangle, topColor, bottomColor, 90.0F)
  567.         g.FillPath(backGradientBrush, borderPath)
  568.  
  569.         g.DrawPath(borderPen, borderPath)
  570.  
  571.     End Sub
  572.  
  573.     Public Sub Animate() Implements IAnimatable.Animate
  574.  
  575.         topSwitcher.Transition()
  576.         topColor = topSwitcher.CurrentColor
  577.  
  578.         bottomSwitcher.Transition()
  579.         bottomColor = bottomSwitcher.CurrentColor
  580.  
  581.         If topSwitcher.TransitionsLapsed = topSwitcher.Transitions Then IsAnimating = False
  582.  
  583.         Invalidate()
  584.  
  585.     End Sub
  586.  
  587.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  588.  
  589.         With FindForm()
  590.             Select Case Action
  591.                 Case ControlAction.Close
  592.                     .Close()
  593.                 Case ControlAction.Minimize
  594.                     .WindowState = FormWindowState.Minimized
  595.                     topColor = defaultColors(0)
  596.                     bottomColor = defaultColors(1)
  597.                     Invalidate()
  598.             End Select
  599.         End With
  600.  
  601.     End Sub
  602.  
  603.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  604.         MouseState = EndeavourHelper.MouseState.Over
  605.     End Sub
  606.  
  607.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  608.         MouseState = EndeavourHelper.MouseState.None
  609.     End Sub
  610.  
  611.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  612.         MyBase.OnSizeChanged(e)
  613.         borderPath = CreateRound(BorderRectangle, 2)
  614.     End Sub
  615.  
  616.     Private Sub SetSwitchers()
  617.  
  618.         Dim newColors() As Color = GetNewColors()
  619.         Dim newTopColor, newBottomColor As Color
  620.  
  621.         newTopColor = newColors(0)
  622.         newBottomColor = newColors(1)
  623.  
  624.         topSwitcher = New RelationalColorSwitcher(topColor, newTopColor)
  625.         bottomSwitcher = New RelationalColorSwitcher(bottomColor, newBottomColor)
  626.  
  627.     End Sub
  628.  
  629.     Private Function GetNewColors() As Color()
  630.  
  631.         Select Case MouseState
  632.             Case EndeavourHelper.MouseState.Over
  633.                 Return New Color() {overColors(0), overColors(1)}
  634.             Case Else
  635.                 Return New Color() {defaultColors(0), defaultColors(1)}
  636.         End Select
  637.  
  638.     End Function
  639.  
  640. End Class
  641.  
  642. Class eButton
  643.     Inherits EndeavourControl
  644.     Implements IAnimatable
  645.  
  646.     Private topSwitcher, bottomSwitcher As RelationalColorSwitcher
  647.     Private borderSwitcher As RelationalColorSwitcher
  648.  
  649.     Private _mouseState As MouseState
  650.  
  651.     Public Property IsAnimating As Boolean Implements IAnimatable.IsAnimating
  652.  
  653.     Protected Property MouseState As MouseState
  654.         Private Set(value As MouseState)
  655.             If _mouseState <> value Then
  656.                 _mouseState = value
  657.                 SetSwitchers()
  658.                 IsAnimating = True
  659.             End If
  660.         End Set
  661.         Get
  662.             Return _mouseState
  663.         End Get
  664.     End Property
  665.  
  666.     Private topColor, bottomColor As Color
  667.     Private borderColor As Color
  668.  
  669.     Private defaultColors(2), overColors(2), downColors(2) As Color
  670.  
  671.     Private borderPath As GraphicsPath
  672.     Private borderPen As Pen
  673.     Private borderHighlightPen As Pen
  674.  
  675.     Private backGradientBrush As LinearGradientBrush
  676.  
  677.     Private textSize As Size
  678.     Private textX, textY As Integer
  679.  
  680.     Sub New()
  681.  
  682.         Cursor = Cursors.Hand
  683.         Font = New Font("Segoe UI", 10)
  684.         Size = New Size(86, 36)
  685.  
  686.         _mouseState = EndeavourHelper.MouseState.None
  687.  
  688.         defaultColors = New Color() {Color.FromArgb(75, 75, 75), Color.FromArgb(45, 45, 45), Color.FromArgb(25, 25, 25)}
  689.         overColors = New Color() {Color.FromArgb(85, 165, 215), Color.FromArgb(45, 125, 185), Color.FromArgb(80, 80, 80)}
  690.         downColors = New Color() {Color.FromArgb(40, 105, 160), Color.FromArgb(75, 150, 195), Color.FromArgb(80, 80, 80)}
  691.  
  692.         borderPath = CreateRound(New Rectangle(0, 0, Width - 1, Height - 1), 6)
  693.  
  694.         borderHighlightPen = New Pen(Color.FromArgb(80, Color.White), 2)
  695.  
  696.         topColor = defaultColors(0)
  697.         bottomColor = defaultColors(1)
  698.         borderColor = defaultColors(2)
  699.  
  700.     End Sub
  701.  
  702.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  703.  
  704.         g = e.Graphics
  705.         g.SmoothingMode = SmoothingMode.HighQuality
  706.         g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  707.  
  708.         backGradientBrush = New LinearGradientBrush(BorderRectangle, topColor, bottomColor, 90.0F)
  709.  
  710.         g.FillPath(backGradientBrush, borderPath)
  711.         g.DrawArc(borderHighlightPen, 0, 1, 12, 12, -180, 90)
  712.         g.DrawLine(borderHighlightPen, 6, 1, Width - 7, 1)
  713.         g.DrawArc(borderHighlightPen, Width - 1 - 12, 1, 12, 12, -90, 90)
  714.  
  715.         borderPen = New Pen(borderColor)
  716.         g.DrawPath(borderPen, borderPath)
  717.  
  718.         textSize = g.MeasureString(Text, Font).ToSize
  719.         textX = CInt((Width / 2) - (textSize.Width / 2) + 1)
  720.         textY = CInt((Height / 2) - (textSize.Height / 2))
  721.         g.DrawString(Text, Font, Brushes.White, textX, textY)
  722.  
  723.     End Sub
  724.  
  725.     Protected Sub Animate() Implements IAnimatable.Animate
  726.  
  727.         topSwitcher.Transition()
  728.         topColor = topSwitcher.CurrentColor
  729.  
  730.         bottomSwitcher.Transition()
  731.         bottomColor = bottomSwitcher.CurrentColor
  732.  
  733.         borderSwitcher.Transition()
  734.         borderColor = borderSwitcher.CurrentColor
  735.  
  736.         If topSwitcher.TransitionsLapsed = topSwitcher.Transitions Then IsAnimating = False
  737.  
  738.         Invalidate()
  739.  
  740.     End Sub
  741.  
  742.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  743.         MouseState = EndeavourHelper.MouseState.Down
  744.     End Sub
  745.  
  746.     Protected Overrides Sub OnMouseEnter(e As EventArgs)
  747.         MouseState = EndeavourHelper.MouseState.Over
  748.     End Sub
  749.  
  750.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  751.         MouseState = EndeavourHelper.MouseState.None
  752.     End Sub
  753.  
  754.     Protected Overrides Sub OnMouseUp(e As MouseEventArgs)
  755.         MouseState = EndeavourHelper.MouseState.Over
  756.     End Sub
  757.  
  758.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  759.         MyBase.OnSizeChanged(e)
  760.         borderPath = CreateRound(BorderRectangle, 6)
  761.     End Sub
  762.  
  763.     Private Sub SetSwitchers()
  764.  
  765.         Dim newColors() As Color = GetNewColors()
  766.  
  767.         Dim newTopColor, newBottomColor As Color
  768.         Dim newBorderColor As Color
  769.  
  770.         Dim transitions As Integer
  771.  
  772.         newTopColor = newColors(0)
  773.         newBottomColor = newColors(1)
  774.         newBorderColor = newColors(2)
  775.  
  776.         transitions = If(MouseState <> EndeavourHelper.MouseState.Down, 10, 2)
  777.  
  778.         topSwitcher = New RelationalColorSwitcher(topColor, newTopColor, transitions)
  779.         bottomSwitcher = New RelationalColorSwitcher(bottomColor, newBottomColor, transitions)
  780.         borderSwitcher = New RelationalColorSwitcher(borderColor, newBorderColor, transitions)
  781.  
  782.     End Sub
  783.  
  784.     Private Function GetNewColors() As Color()
  785.  
  786.         Select Case MouseState
  787.             Case EndeavourHelper.MouseState.Over
  788.                 Return overColors
  789.             Case EndeavourHelper.MouseState.Down
  790.                 Return downColors
  791.             Case Else
  792.                 Return defaultColors
  793.         End Select
  794.  
  795.     End Function
  796.  
  797. End Class
  798.  
  799. <DefaultEvent("ValueChanged")> Class eProgressBar
  800.     Inherits EndeavourControl
  801.  
  802.     Event ValueChanged(sender As Object)
  803.  
  804.     Private _maximum As Integer
  805.     Private _value As Integer
  806.  
  807.     Public Property Maximum As Integer
  808.         Get
  809.             Return _maximum
  810.         End Get
  811.         Set(value As Integer)
  812.             If value > 0 Then
  813.                 _maximum = value
  814.                 If _value > _maximum Then _value = _maximum
  815.                 Invalidate()
  816.             Else
  817.                 Throw New Exception("Maximum must be great than 0.")
  818.             End If
  819.         End Set
  820.     End Property
  821.  
  822.     Public Property Value As Integer
  823.         Get
  824.             Return _value
  825.         End Get
  826.         Set(value As Integer)
  827.             If value <> _value Then
  828.                 If value >= 0 Then
  829.                     _value = value
  830.                     If _value > _maximum Then _value = _maximum
  831.                     Invalidate()
  832.                 Else
  833.                     Throw New Exception("Value must be greater than or equal to 0.")
  834.                 End If
  835.                 RaiseEvent ValueChanged(Me)
  836.             End If
  837.         End Set
  838.     End Property
  839.  
  840.     Private borderPath As GraphicsPath
  841.     Private backGradientBrush As LinearGradientBrush
  842.     Private borderPen As Pen
  843.  
  844.     Private barWidth As Integer
  845.     Private barPath, innerBarPath As GraphicsPath
  846.     Private barGradientBrush As LinearGradientBrush
  847.     Private barBorderPen As Pen
  848.  
  849.     Sub New()
  850.  
  851.         MyBase.New()
  852.  
  853.         Size = New Size(300, 14)
  854.  
  855.         _maximum = 100
  856.  
  857.         backGradientBrush = New LinearGradientBrush(BorderRectangle, Color.FromArgb(220, 225, 240), Color.FromArgb(160, 165, 175), 90.0F)
  858.         borderPen = New Pen(Color.FromArgb(115, 115, 115))
  859.  
  860.         barGradientBrush = New LinearGradientBrush(BorderRectangle, Color.FromArgb(85, 165, 215), Color.FromArgb(35, 100, 150), 90.0F)
  861.         barBorderPen = New Pen(Color.FromArgb(50, Color.White))
  862.  
  863.     End Sub
  864.  
  865.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  866.  
  867.         g = e.Graphics
  868.         g.SmoothingMode = SmoothingMode.HighQuality
  869.  
  870.         g.FillPath(backGradientBrush, borderPath)
  871.  
  872.         If _value > 0 Then
  873.  
  874.             barWidth = CInt((Width / _maximum) * _value)
  875.  
  876.             If barWidth <= 12 Then
  877.                 barPath = CreateRound(New Rectangle(0, 0, 10, Height - 1), 6)
  878.                 innerBarPath = CreateRound(New Rectangle(1, 1, 8, Height - 3), 6)
  879.             Else
  880.                 barPath = CreateRound(New Rectangle(0, 0, barWidth - 1, Height - 1), 6)
  881.                 innerBarPath = CreateRound(New Rectangle(1, 1, barWidth - 3, Height - 3), 6)
  882.             End If
  883.  
  884.             g.FillPath(barGradientBrush, barPath)
  885.             g.DrawPath(barBorderPen, innerBarPath)
  886.             g.DrawPath(borderPen, barPath)
  887.  
  888.         End If
  889.  
  890.         g.DrawPath(borderPen, borderPath)
  891.  
  892.     End Sub
  893.  
  894.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  895.         MyBase.OnSizeChanged(e)
  896.         borderPath = CreateRound(BorderRectangle, 6)
  897.     End Sub
  898.  
  899. End Class
  900.  
  901. Class eSpinner
  902.     Inherits EndeavourControl
  903.     Implements IAnimatable
  904.  
  905.     Class Spinner
  906.  
  907.         Public Property Rectangle As Rectangle
  908.         Public Property Angle As Integer
  909.  
  910.         Sub New()
  911.  
  912.             Angle = 180
  913.  
  914.         End Sub
  915.  
  916.     End Class
  917.  
  918.     Public Property IsAnimating As Boolean Implements IAnimatable.IsAnimating
  919.  
  920.     Private spinners(3) As Spinner
  921.  
  922.     Private spinnerPen As Pen
  923.  
  924.     Sub New()
  925.  
  926.         For i As Integer = 0 To spinners.Count - 1
  927.             spinners(i) = New Spinner
  928.             Dim m As Integer = i Mod 4
  929.             With spinners(i)
  930.                 Select Case m
  931.                     Case 0
  932.                         .Angle = 0
  933.                     Case 1
  934.                         .Angle = 90
  935.                     Case 2
  936.                         .Angle = 180
  937.                     Case 3
  938.                         .Angle = 270
  939.                 End Select
  940.             End With
  941.             spinners(i).Angle = If(i Mod 2 = 0, 90, 270)
  942.         Next
  943.  
  944.         PlaceSpinners()
  945.  
  946.         Size = New Size(40, 40)
  947.  
  948.         spinnerPen = New Pen(Color.FromArgb(65, 145, 200), 2)
  949.  
  950.         IsAnimating = False
  951.  
  952.     End Sub
  953.  
  954.     Public Sub Animate() Implements IAnimatable.Animate
  955.  
  956.         For i As Integer = 0 To spinners.Count - 1
  957.             Dim m As Integer = i Mod 4
  958.             With spinners(i)
  959.                 Select Case m
  960.                     Case 0
  961.                         .Angle = If(.Angle <> 360, .Angle + 4, 4)
  962.                     Case 1
  963.                         .Angle = If(.Angle <> 360, .Angle - 5, 5)
  964.                     Case 2
  965.                         .Angle = If(.Angle <> 0, .Angle + 6, 354)
  966.                     Case 3
  967.                         .Angle = If(.Angle <> 0, .Angle - 8, 352)
  968.                 End Select
  969.             End With
  970.         Next
  971.  
  972.         Invalidate()
  973.  
  974.     End Sub
  975.  
  976.     Protected Overrides Sub OnCreateControl()
  977.  
  978.         IsAnimating = True
  979.  
  980.     End Sub
  981.  
  982.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  983.  
  984.         e.Graphics.Clear(Parent.BackColor)
  985.         e.Graphics.SmoothingMode = Drawing2D.SmoothingMode.HighQuality
  986.  
  987.         For Each s As Spinner In spinners
  988.             e.Graphics.DrawArc(spinnerPen, s.Rectangle, s.Angle, 180)
  989.         Next
  990.  
  991.     End Sub
  992.  
  993.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  994.  
  995.         PlaceSpinners()
  996.  
  997.     End Sub
  998.  
  999.     Private Sub PlaceSpinners()
  1000.  
  1001.         Dim padding As Integer = 3
  1002.         For Each s As Spinner In spinners
  1003.             s.Rectangle = New Rectangle(padding, padding, Width - (padding * 2) - 1, Height - (padding * 2) - 1)
  1004.             padding += 4
  1005.         Next
  1006.  
  1007.     End Sub
  1008.  
  1009. End Class
  1010.  
  1011. <DefaultEvent("CheckedChanged")> Class eCheckBox
  1012.     Inherits EndeavourControl
  1013.     Implements IAnimatable
  1014.  
  1015.     Event CheckedChanged(sender As Object)
  1016.  
  1017.     Private _checked As Boolean
  1018.     Private _overBox As Boolean
  1019.  
  1020.     Public Property IsAnimating As Boolean Implements IAnimatable.IsAnimating
  1021.  
  1022.     Public Property Checked As Boolean
  1023.         Get
  1024.             Return _checked
  1025.         End Get
  1026.         Set(value As Boolean)
  1027.             If _checked <> value Then
  1028.                 _checked = value
  1029.                 SetSwitchers()
  1030.                 IsAnimating = True
  1031.                 RaiseEvent CheckedChanged(Me)
  1032.             End If
  1033.         End Set
  1034.     End Property
  1035.  
  1036.     Private Property OverBox As Boolean
  1037.         Get
  1038.             Return _overBox
  1039.         End Get
  1040.         Set(value As Boolean)
  1041.             If _overBox <> value Then
  1042.                 _overBox = value
  1043.                 SetSwitchers()
  1044.                 IsAnimating = True
  1045.                 Cursor = If(_overBox, Cursors.Hand, Cursors.Default)
  1046.             End If
  1047.         End Set
  1048.     End Property
  1049.  
  1050.     Private boxBorderRect As Rectangle
  1051.     Private checkBorderRect As Rectangle
  1052.     Private boxBorderPath As GraphicsPath
  1053.     Private checkBorderPath As GraphicsPath
  1054.  
  1055.     Private boxBorderPen As Pen
  1056.     Private checkBorderPen As Pen
  1057.  
  1058.     Private boxDefaultColors(1), boxOverColors(1) As Color
  1059.     Private uncheckedColors(2), checkedColors(2) As Color
  1060.  
  1061.     Private boxTopSwitcher, boxBottomSwitcher As RelationalColorSwitcher
  1062.     Private checkTopSwitcher, checkBottomSwitcher As RelationalColorSwitcher
  1063.     Private checkBorderSwitcher As RelationalColorSwitcher
  1064.  
  1065.     Private boxTopColor, boxBottomColor As Color
  1066.     Private checkTopColor, checkBottomColor As Color
  1067.     Private checkBorderColor As Color
  1068.  
  1069.     Private boxGradientBrush As LinearGradientBrush
  1070.     Private checkGradientBrush As LinearGradientBrush
  1071.  
  1072.     Private textY As Integer
  1073.     Private textBrush As SolidBrush
  1074.  
  1075.     Sub New()
  1076.  
  1077.         Font = New Font("Segoe UI", 10)
  1078.         Size = New Size(120, 24)
  1079.  
  1080.         boxDefaultColors = New Color() {Color.FromArgb(235, 230, 220), Color.FromArgb(185, 180, 170)}
  1081.         boxOverColors = New Color() {Color.FromArgb(125, 200, 235), Color.FromArgb(50, 130, 195)}
  1082.         uncheckedColors = New Color() {Color.Transparent, Color.Transparent, Color.Transparent}
  1083.         checkedColors = New Color() {Color.FromArgb(180, Color.White), Color.FromArgb(150, Color.White), Color.FromArgb(80, Color.Black)}
  1084.  
  1085.         boxTopColor = boxDefaultColors(0)
  1086.         boxBottomColor = boxDefaultColors(1)
  1087.         checkTopColor = uncheckedColors(0)
  1088.         checkBottomColor = uncheckedColors(1)
  1089.         checkBorderColor = uncheckedColors(2)
  1090.  
  1091.         boxBorderPen = New Pen(Color.FromArgb(120, 120, 120))
  1092.  
  1093.         textBrush = New SolidBrush(Color.FromArgb(25, 25, 25))
  1094.  
  1095.     End Sub
  1096.  
  1097.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  1098.  
  1099.         g = e.Graphics
  1100.         g.SmoothingMode = SmoothingMode.HighQuality
  1101.         g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  1102.  
  1103.         boxGradientBrush = New LinearGradientBrush(boxBorderRect, boxTopColor, boxBottomColor, 90.0F)
  1104.         g.FillPath(boxGradientBrush, boxBorderPath)
  1105.  
  1106.         checkGradientBrush = New LinearGradientBrush(checkBorderRect, checkTopColor, checkBottomColor, 90.0F)
  1107.         g.FillPath(checkGradientBrush, checkBorderPath)
  1108.  
  1109.         checkBorderPen = New Pen(checkBorderColor)
  1110.         g.DrawPath(checkBorderPen, checkBorderPath)
  1111.  
  1112.         g.DrawPath(boxBorderPen, boxBorderPath)
  1113.  
  1114.         textY = CInt((Height / 2) - (g.MeasureString(Text, Font).Height / 2))
  1115.         g.DrawString(Text, Font, textBrush, 23, textY)
  1116.  
  1117.     End Sub
  1118.  
  1119.     Public Sub Animate() Implements IAnimatable.Animate
  1120.  
  1121.         Dim boxAnimating, checkAnimating As Boolean
  1122.  
  1123.         If boxTopSwitcher.TransitionsLapsed <> boxTopSwitcher.Transitions Then
  1124.  
  1125.             boxAnimating = True
  1126.  
  1127.             boxTopSwitcher.Transition()
  1128.             boxTopColor = boxTopSwitcher.CurrentColor
  1129.  
  1130.             boxBottomSwitcher.Transition()
  1131.             boxBottomColor = boxBottomSwitcher.CurrentColor
  1132.  
  1133.         Else
  1134.  
  1135.             boxAnimating = False
  1136.  
  1137.         End If
  1138.  
  1139.         If checkTopSwitcher.TransitionsLapsed <> checkTopSwitcher.Transitions Then
  1140.  
  1141.             checkAnimating = True
  1142.  
  1143.             checkTopSwitcher.Transition()
  1144.             checkTopColor = checkTopSwitcher.CurrentColor
  1145.  
  1146.             checkBottomSwitcher.Transition()
  1147.             checkBottomColor = checkBottomSwitcher.CurrentColor
  1148.  
  1149.             checkBorderSwitcher.Transition()
  1150.             checkBorderColor = checkBorderSwitcher.CurrentColor
  1151.  
  1152.         Else
  1153.  
  1154.             checkAnimating = False
  1155.  
  1156.         End If
  1157.  
  1158.         If Not boxAnimating AndAlso Not checkAnimating Then
  1159.             IsAnimating = False
  1160.         Else
  1161.             Invalidate()
  1162.         End If
  1163.  
  1164.     End Sub
  1165.  
  1166.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  1167.         If OverBox Then Checked = Not Checked
  1168.     End Sub
  1169.  
  1170.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  1171.         OverBox = boxBorderRect.Contains(e.Location)
  1172.     End Sub
  1173.  
  1174.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  1175.         OverBox = False
  1176.     End Sub
  1177.  
  1178.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  1179.  
  1180.         MyBase.OnSizeChanged(e)
  1181.  
  1182.         boxBorderRect = New Rectangle(0, CInt((Height / 2) - 9), 20, 20)
  1183.         boxBorderPath = CreateRound(boxBorderRect, 6)
  1184.  
  1185.         checkBorderRect = New Rectangle(boxBorderRect.X + 5, boxBorderRect.Y + 5, 10, 10)
  1186.         checkBorderPath = CreateRound(checkBorderRect, 4)
  1187.  
  1188.     End Sub
  1189.  
  1190.     Private Sub SetSwitchers()
  1191.  
  1192.         Dim newBackColors() As Color = GetNewBackColors()
  1193.         Dim backTransitions As Integer = If(boxTopColor <> newBackColors(0), 10, 0)
  1194.  
  1195.         boxTopSwitcher = New RelationalColorSwitcher(boxTopColor, newBackColors(0), backTransitions)
  1196.         boxBottomSwitcher = New RelationalColorSwitcher(boxBottomColor, newBackColors(1), backTransitions)
  1197.  
  1198.         Dim newCheckColors() As Color = GetNewCheckColors()
  1199.         Dim checkTransitions As Integer = If(checkTopColor <> newCheckColors(0), 6, 0)
  1200.  
  1201.         checkTopSwitcher = New RelationalColorSwitcher(checkTopColor, newCheckColors(0), checkTransitions)
  1202.         checkBottomSwitcher = New RelationalColorSwitcher(checkBottomColor, newCheckColors(1), checkTransitions)
  1203.         checkBorderSwitcher = New RelationalColorSwitcher(checkBorderColor, newCheckColors(2), checkTransitions)
  1204.  
  1205.     End Sub
  1206.  
  1207.     Private Function GetNewBackColors() As Color()
  1208.         Return If(OverBox OrElse Checked, boxOverColors, boxDefaultColors)
  1209.     End Function
  1210.  
  1211.     Private Function GetNewCheckColors() As Color()
  1212.         Return If(Checked, checkedColors, uncheckedColors)
  1213.     End Function
  1214.  
  1215. End Class
  1216.  
  1217. <DefaultEvent("CheckedChanged")> Class eRadioButton
  1218.     Inherits EndeavourControl
  1219.     Implements IAnimatable
  1220.  
  1221.     Event CheckedChanged(sender As Object)
  1222.  
  1223.     Private _checked As Boolean
  1224.     Private _overBox As Boolean
  1225.  
  1226.     Public Property IsAnimating As Boolean Implements IAnimatable.IsAnimating
  1227.  
  1228.     Public Property Checked As Boolean
  1229.         Get
  1230.             Return _checked
  1231.         End Get
  1232.         Set(value As Boolean)
  1233.             If _checked <> value Then
  1234.                 _checked = value
  1235.                 SetSwitchers()
  1236.                 IsAnimating = True
  1237.                 RaiseEvent CheckedChanged(Me)
  1238.             End If
  1239.         End Set
  1240.     End Property
  1241.  
  1242.     Private Property OverBox As Boolean
  1243.         Get
  1244.             Return _overBox
  1245.         End Get
  1246.         Set(value As Boolean)
  1247.             If _overBox <> value Then
  1248.                 _overBox = value
  1249.                 SetSwitchers()
  1250.                 IsAnimating = True
  1251.                 Cursor = If(_overBox, Cursors.Hand, Cursors.Default)
  1252.             End If
  1253.         End Set
  1254.     End Property
  1255.  
  1256.     Private boxBorderRect As Rectangle
  1257.     Private checkBorderRect As Rectangle
  1258.  
  1259.     Private boxBorderPen As Pen
  1260.     Private checkBorderPen As Pen
  1261.  
  1262.     Private boxDefaultColors(1), boxOverColors(1) As Color
  1263.     Private uncheckedColors(2), checkedColors(2) As Color
  1264.  
  1265.     Private boxTopSwitcher, boxBottomSwitcher As RelationalColorSwitcher
  1266.     Private checkTopSwitcher, checkBottomSwitcher As RelationalColorSwitcher
  1267.     Private checkBorderSwitcher As RelationalColorSwitcher
  1268.  
  1269.     Private boxTopColor, boxBottomColor As Color
  1270.     Private checkTopColor, checkBottomColor As Color
  1271.     Private checkBorderColor As Color
  1272.  
  1273.     Private boxGradientBrush As LinearGradientBrush
  1274.     Private checkGradientBrush As LinearGradientBrush
  1275.  
  1276.     Private textY As Integer
  1277.     Private textBrush As SolidBrush
  1278.  
  1279.     Sub New()
  1280.  
  1281.         Font = New Font("Segoe UI", 10)
  1282.         Size = New Size(120, 24)
  1283.  
  1284.         boxDefaultColors = New Color() {Color.FromArgb(235, 230, 220), Color.FromArgb(185, 180, 170)}
  1285.         boxOverColors = New Color() {Color.FromArgb(125, 200, 235), Color.FromArgb(50, 130, 195)}
  1286.         uncheckedColors = New Color() {Color.Transparent, Color.Transparent, Color.Transparent}
  1287.         checkedColors = New Color() {Color.FromArgb(180, Color.White), Color.FromArgb(150, Color.White), Color.FromArgb(80, Color.Black)}
  1288.  
  1289.         boxTopColor = boxDefaultColors(0)
  1290.         boxBottomColor = boxDefaultColors(1)
  1291.         checkTopColor = uncheckedColors(0)
  1292.         checkBottomColor = uncheckedColors(1)
  1293.         checkBorderColor = uncheckedColors(2)
  1294.  
  1295.         boxBorderPen = New Pen(Color.FromArgb(120, 120, 120))
  1296.  
  1297.         textBrush = New SolidBrush(Color.FromArgb(25, 25, 25))
  1298.  
  1299.     End Sub
  1300.  
  1301.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  1302.  
  1303.         g = e.Graphics
  1304.         g.SmoothingMode = SmoothingMode.HighQuality
  1305.         g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit
  1306.  
  1307.         boxGradientBrush = New LinearGradientBrush(boxBorderRect, boxTopColor, boxBottomColor, 90.0F)
  1308.         g.FillEllipse(boxGradientBrush, boxBorderRect)
  1309.  
  1310.         checkGradientBrush = New LinearGradientBrush(checkBorderRect, checkTopColor, checkBottomColor, 90.0F)
  1311.         g.FillEllipse(checkGradientBrush, checkBorderRect)
  1312.  
  1313.         checkBorderPen = New Pen(checkBorderColor)
  1314.         g.DrawEllipse(checkBorderPen, checkBorderRect)
  1315.  
  1316.         g.DrawEllipse(boxBorderPen, boxBorderRect)
  1317.  
  1318.         textY = CInt((Height / 2) - (g.MeasureString(Text, Font).Height / 2) + 2)
  1319.         g.DrawString(Text, Font, textBrush, 23, textY)
  1320.  
  1321.     End Sub
  1322.  
  1323.     Public Sub Animate() Implements IAnimatable.Animate
  1324.  
  1325.         Dim boxAnimating, checkAnimating As Boolean
  1326.  
  1327.         If boxTopSwitcher.TransitionsLapsed <> boxTopSwitcher.Transitions Then
  1328.  
  1329.             boxAnimating = True
  1330.  
  1331.             boxTopSwitcher.Transition()
  1332.             boxTopColor = boxTopSwitcher.CurrentColor
  1333.  
  1334.             boxBottomSwitcher.Transition()
  1335.             boxBottomColor = boxBottomSwitcher.CurrentColor
  1336.  
  1337.         Else
  1338.  
  1339.             boxAnimating = False
  1340.  
  1341.         End If
  1342.  
  1343.         If checkTopSwitcher.TransitionsLapsed <> checkTopSwitcher.Transitions Then
  1344.  
  1345.             checkAnimating = True
  1346.  
  1347.             checkTopSwitcher.Transition()
  1348.             checkTopColor = checkTopSwitcher.CurrentColor
  1349.  
  1350.             checkBottomSwitcher.Transition()
  1351.             checkBottomColor = checkBottomSwitcher.CurrentColor
  1352.  
  1353.             checkBorderSwitcher.Transition()
  1354.             checkBorderColor = checkBorderSwitcher.CurrentColor
  1355.  
  1356.         Else
  1357.  
  1358.             checkAnimating = False
  1359.  
  1360.         End If
  1361.  
  1362.         If Not boxAnimating AndAlso Not checkAnimating Then
  1363.             IsAnimating = False
  1364.         Else
  1365.             Invalidate()
  1366.         End If
  1367.  
  1368.     End Sub
  1369.  
  1370.     Protected Overrides Sub OnMouseDown(e As MouseEventArgs)
  1371.  
  1372.         If OverBox And Not Checked Then
  1373.             For Each c As Control In Parent.Controls
  1374.                 If TypeOf c Is eRadioButton Then DirectCast(c, eRadioButton).Checked = False
  1375.             Next
  1376.             Checked = True
  1377.         End If
  1378.  
  1379.     End Sub
  1380.  
  1381.     Protected Overrides Sub OnMouseMove(e As MouseEventArgs)
  1382.         OverBox = boxBorderRect.Contains(e.Location)
  1383.     End Sub
  1384.  
  1385.     Protected Overrides Sub OnMouseLeave(e As EventArgs)
  1386.         OverBox = False
  1387.     End Sub
  1388.  
  1389.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  1390.  
  1391.         MyBase.OnSizeChanged(e)
  1392.         boxBorderRect = New Rectangle(0, CInt((Height / 2) - 9), 20, 20)
  1393.         checkBorderRect = New Rectangle(boxBorderRect.X + 6, boxBorderRect.Y + 6, 8, 8)
  1394.  
  1395.     End Sub
  1396.  
  1397.     Private Sub SetSwitchers()
  1398.  
  1399.         Dim newBackColors() As Color = GetNewBackColors()
  1400.         Dim backTransitions As Integer = If(boxTopColor <> newBackColors(0), 10, 0)
  1401.  
  1402.         boxTopSwitcher = New RelationalColorSwitcher(boxTopColor, newBackColors(0), backTransitions)
  1403.         boxBottomSwitcher = New RelationalColorSwitcher(boxBottomColor, newBackColors(1), backTransitions)
  1404.  
  1405.         Dim newCheckColors() As Color = GetNewCheckColors()
  1406.         Dim checkTransitions As Integer = If(checkTopColor <> newCheckColors(0), 6, 0)
  1407.  
  1408.         checkTopSwitcher = New RelationalColorSwitcher(checkTopColor, newCheckColors(0), checkTransitions)
  1409.         checkBottomSwitcher = New RelationalColorSwitcher(checkBottomColor, newCheckColors(1), checkTransitions)
  1410.         checkBorderSwitcher = New RelationalColorSwitcher(checkBorderColor, newCheckColors(2), checkTransitions)
  1411.  
  1412.     End Sub
  1413.  
  1414.     Private Function GetNewBackColors() As Color()
  1415.         Return If(OverBox OrElse Checked, boxOverColors, boxDefaultColors)
  1416.     End Function
  1417.  
  1418.     Private Function GetNewCheckColors() As Color()
  1419.         Return If(Checked, checkedColors, uncheckedColors)
  1420.     End Function
  1421.  
  1422. End Class
  1423.  
  1424. Class eSplitter
  1425.     Inherits EndeavourControl
  1426.     Implements IAnimatable
  1427.  
  1428.     Private animX As Integer
  1429.     Private animWidth As Integer
  1430.  
  1431.     Public Property IsAnimating As Boolean Implements IAnimatable.IsAnimating
  1432.  
  1433.     Private baseLineColors(2), animLineColors(4) As Color
  1434.  
  1435.     Private baseLineGradientBrush As LinearGradientBrush
  1436.     Private baseLineBlend As ColorBlend
  1437.     Private baseLinePen As Pen
  1438.  
  1439.     Private animLineGradientBrush As LinearGradientBrush
  1440.     Private animLineBlend As ColorBlend
  1441.     Private animLinePen As Pen
  1442.  
  1443.     Sub New()
  1444.  
  1445.         baseLineColors = New Color() {Color.FromArgb(45, 45, 45), Color.FromArgb(75, 75, 75), Color.FromArgb(45, 45, 45)}
  1446.         animLineColors = New Color() {Color.Transparent, Color.FromArgb(45, 125, 185), Color.FromArgb(85, 165, 215), _
  1447.                                       Color.FromArgb(45, 125, 185), Color.Transparent}
  1448.  
  1449.         baseLineBlend = New ColorBlend(3)
  1450.         baseLineBlend.Colors = baseLineColors
  1451.         baseLineBlend.Positions = New Single() {0.0F, 0.5F, 1.0F}
  1452.  
  1453.         animLineBlend = New ColorBlend(5)
  1454.         animLineBlend.Colors = animLineColors
  1455.         animLineBlend.Positions = New Single() {0.0F, 0.2F, 0.5F, 0.8F, 1.0F}
  1456.  
  1457.         Size = New Size(300, 14)
  1458.  
  1459.         IsAnimating = True
  1460.  
  1461.     End Sub
  1462.  
  1463.     Protected Overrides Sub OnPaint(e As PaintEventArgs)
  1464.  
  1465.         g = e.Graphics
  1466.         g.SmoothingMode = SmoothingMode.HighQuality
  1467.  
  1468.         Dim halfHeight As Integer = CInt(Height / 2)
  1469.  
  1470.         g.DrawLine(baseLinePen, 0, halfHeight, Width, halfHeight)
  1471.         g.DrawLine(animLinePen, animX, halfHeight, animX + animWidth, halfHeight)
  1472.  
  1473.     End Sub
  1474.  
  1475.     Public Sub Animate() Implements IAnimatable.Animate
  1476.  
  1477.         animX = If(animX < Width + animWidth, animX + 2, animWidth * -1)
  1478.  
  1479.         animLineGradientBrush = New LinearGradientBrush(New Rectangle(animX, Height, animWidth, Height), Color.Transparent, Color.Transparent, 0.0F)
  1480.         animLineGradientBrush.InterpolationColors = animLineBlend
  1481.         animLinePen = New Pen(animLineGradientBrush)
  1482.  
  1483.         Invalidate()
  1484.  
  1485.     End Sub
  1486.  
  1487.     Protected Overrides Sub OnSizeChanged(e As EventArgs)
  1488.  
  1489.         MyBase.OnSizeChanged(e)
  1490.  
  1491.         baseLineGradientBrush = New LinearGradientBrush(BorderRectangle, Color.Transparent, Color.Transparent, 0.0F)
  1492.         baseLineGradientBrush.InterpolationColors = baseLineBlend
  1493.         baseLinePen = New Pen(baseLineGradientBrush)
  1494.  
  1495.         animX = animWidth * -1
  1496.         animWidth = CInt(Width / 3)
  1497.  
  1498.         animLineGradientBrush = New LinearGradientBrush(New Rectangle(animX, Height, animWidth, Height), Color.Transparent, Color.Transparent, 0.0F)
  1499.         animLineGradientBrush.InterpolationColors = animLineBlend
  1500.         animLinePen = New Pen(animLineGradientBrush)
  1501.  
  1502.     End Sub
  1503.  
  1504. End Class
  1505.  
  1506. Class eLabel
  1507.     Inherits Label
  1508.  
  1509.     Sub New()
  1510.  
  1511.         ForeColor = Color.FromArgb(25, 25, 25)
  1512.         Font = New Font("Segoe UI", 9)
  1513.  
  1514.     End Sub
  1515.  
  1516. End Class
Advertisement
Add Comment
Please, Sign In to add comment