ImaFoSho

[VB] Simpl Theme

Nov 17th, 2012
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 43.83 KB | None | 0 0
  1. Imports System, System.IO, System.Collections.Generic, System.ComponentModel, System.Windows.Forms, System.Drawing, System.Drawing.Drawing2D
  2.  
  3. 'Simpl Theme
  4. 'By: FoSho
  5. 'ThemeBase: Aeonhack
  6.  
  7. MustInherit Class ThemeContainer151
  8.     Inherits ContainerControl
  9.  
  10.     Protected G As Graphics
  11.  
  12.     Sub New()
  13.         SetStyle(DirectCast(139270, ControlStyles), True)
  14.         _ImageSize = Size.Empty
  15.  
  16.         MeasureBitmap = New Bitmap(1, 1)
  17.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  18.  
  19.         Font = New Font("Verdana", 8S)
  20.  
  21.         InvalidateCustimization()
  22.     End Sub
  23.  
  24.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  25.         If Not _LockWidth = 0 Then width = _LockWidth
  26.         If Not _LockHeight = 0 Then height = _LockHeight
  27.         MyBase.SetBoundsCore(x, y, width, height, specified)
  28.     End Sub
  29.  
  30.     Private Header As Rectangle
  31.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  32.         MyBase.OnSizeChanged(e)
  33.         If _Movable AndAlso Not _ControlMode Then Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  34.         Invalidate()
  35.     End Sub
  36.  
  37.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  38.         If Width = 0 OrElse Height = 0 Then Return
  39.         G = e.Graphics
  40.         PaintHook()
  41.     End Sub
  42.  
  43.     Protected NotOverridable Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  44.         InitializeMessages()
  45.         InvalidateCustimization()
  46.         ColorHook()
  47.  
  48.         _IsParentForm = TypeOf Parent Is Form
  49.         If Not _ControlMode Then Dock = DockStyle.Fill
  50.  
  51.         If Not _LockWidth = 0 Then Width = _LockWidth
  52.         If Not _LockHeight = 0 Then Height = _LockHeight
  53.         If Not BackColorWait = Nothing Then BackColor = BackColorWait
  54.  
  55.         If _IsParentForm AndAlso Not _ControlMode Then
  56.             ParentForm.FormBorderStyle = _BorderStyle
  57.             ParentForm.TransparencyKey = _TransparencyKey
  58.         End If
  59.  
  60.         OnCreation()
  61.         MyBase.OnHandleCreated(e)
  62.     End Sub
  63.  
  64.     Protected Overridable Sub OnCreation()
  65.     End Sub
  66.  
  67. #Region " Sizing and Movement "
  68.  
  69.     Protected State As MouseState
  70.     Private Sub SetState(ByVal current As MouseState)
  71.         State = current
  72.         Invalidate()
  73.     End Sub
  74.  
  75.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  76.         If _Sizable AndAlso Not _ControlMode Then InvalidateMouse()
  77.         MyBase.OnMouseMove(e)
  78.     End Sub
  79.  
  80.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  81.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  82.         MyBase.OnEnabledChanged(e)
  83.     End Sub
  84.  
  85.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  86.         SetState(MouseState.Over)
  87.         MyBase.OnMouseEnter(e)
  88.     End Sub
  89.  
  90.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  91.         SetState(MouseState.Over)
  92.         MyBase.OnMouseUp(e)
  93.     End Sub
  94.  
  95.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  96.         SetState(MouseState.None)
  97.  
  98.         If _Sizable AndAlso Not _ControlMode AndAlso GetChildAtPoint(PointToClient(MousePosition)) IsNot Nothing Then
  99.             Cursor = Cursors.Default
  100.             Previous = 0
  101.         End If
  102.  
  103.         MyBase.OnMouseLeave(e)
  104.     End Sub
  105.  
  106.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  107.         MyBase.OnMouseDown(e)
  108.  
  109.         If Not e.Button = Windows.Forms.MouseButtons.Left Then Return
  110.         SetState(MouseState.Down)
  111.  
  112.         If _IsParentForm AndAlso ParentForm.WindowState = FormWindowState.Maximized OrElse _ControlMode Then Return
  113.  
  114.         If _Movable AndAlso Header.Contains(e.Location) Then
  115.             Capture = False
  116.             DefWndProc(Messages(0))
  117.         ElseIf _Sizable AndAlso Not Previous = 0 Then
  118.             Capture = False
  119.             DefWndProc(Messages(Previous))
  120.         End If
  121.     End Sub
  122.  
  123.     Private GetIndexPoint As Point
  124.     Private B1, B2, B3, B4 As Boolean
  125.     Private Function GetIndex() As Integer
  126.         GetIndexPoint = PointToClient(MousePosition)
  127.         B1 = GetIndexPoint.X < 7
  128.         B2 = GetIndexPoint.X > Width - 7
  129.         B3 = GetIndexPoint.Y < 7
  130.         B4 = GetIndexPoint.Y > Height - 7
  131.  
  132.         If B1 AndAlso B3 Then Return 4
  133.         If B1 AndAlso B4 Then Return 7
  134.         If B2 AndAlso B3 Then Return 5
  135.         If B2 AndAlso B4 Then Return 8
  136.         If B1 Then Return 1
  137.         If B2 Then Return 2
  138.         If B3 Then Return 3
  139.         If B4 Then Return 6
  140.         Return 0
  141.     End Function
  142.  
  143.     Private Current, Previous As Integer
  144.     Private Sub InvalidateMouse()
  145.         Current = GetIndex()
  146.         If Current = Previous Then Return
  147.  
  148.         Previous = Current
  149.         Select Case Previous
  150.             Case 0
  151.                 Cursor = Cursors.Default
  152.             Case 1, 2
  153.                 Cursor = Cursors.SizeWE
  154.             Case 3, 6
  155.                 Cursor = Cursors.SizeNS
  156.             Case 4, 8
  157.                 Cursor = Cursors.SizeNWSE
  158.             Case 5, 7
  159.                 Cursor = Cursors.SizeNESW
  160.         End Select
  161.     End Sub
  162.  
  163.     Private Messages(8) As Message
  164.     Private Sub InitializeMessages()
  165.         Messages(0) = Message.Create(Parent.Handle, 161, New IntPtr(2), IntPtr.Zero)
  166.         For I As Integer = 1 To 8
  167.             Messages(I) = Message.Create(Parent.Handle, 161, New IntPtr(I + 9), IntPtr.Zero)
  168.         Next
  169.     End Sub
  170.  
  171. #End Region
  172.  
  173.  
  174. #Region " Property Overrides "
  175.  
  176.     Private BackColorWait As Color
  177.     Overrides Property BackColor() As Color
  178.         Get
  179.             Return MyBase.BackColor
  180.         End Get
  181.         Set(ByVal value As Color)
  182.             If IsHandleCreated Then
  183.                 If Not _ControlMode Then Parent.BackColor = value
  184.                 MyBase.BackColor = value
  185.             Else
  186.                 BackColorWait = value
  187.             End If
  188.         End Set
  189.     End Property
  190.  
  191.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  192.     Overrides Property ForeColor() As Color
  193.         Get
  194.             Return Color.Empty
  195.         End Get
  196.         Set(ByVal value As Color)
  197.         End Set
  198.     End Property
  199.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  200.     Overrides Property BackgroundImage() As Image
  201.         Get
  202.             Return Nothing
  203.         End Get
  204.         Set(ByVal value As Image)
  205.         End Set
  206.     End Property
  207.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  208.     Overrides Property BackgroundImageLayout() As ImageLayout
  209.         Get
  210.             Return ImageLayout.None
  211.         End Get
  212.         Set(ByVal value As ImageLayout)
  213.         End Set
  214.     End Property
  215.  
  216.     Overrides Property Text() As String
  217.         Get
  218.             Return MyBase.Text
  219.         End Get
  220.         Set(ByVal value As String)
  221.             MyBase.Text = value
  222.             Invalidate()
  223.         End Set
  224.     End Property
  225.  
  226.     Overrides Property Font() As Font
  227.         Get
  228.             Return MyBase.Font
  229.         End Get
  230.         Set(ByVal value As Font)
  231.             MyBase.Font = value
  232.             Invalidate()
  233.         End Set
  234.     End Property
  235.  
  236. #End Region
  237.  
  238. #Region " Properties "
  239.  
  240.     Private _Movable As Boolean = True
  241.     Property Movable() As Boolean
  242.         Get
  243.             Return _Movable
  244.         End Get
  245.         Set(ByVal value As Boolean)
  246.             _Movable = value
  247.         End Set
  248.     End Property
  249.  
  250.     Private _Sizable As Boolean = True
  251.     Property Sizable() As Boolean
  252.         Get
  253.             Return _Sizable
  254.         End Get
  255.         Set(ByVal value As Boolean)
  256.             _Sizable = value
  257.         End Set
  258.     End Property
  259.  
  260.     Private _MoveHeight As Integer = 24
  261.     Protected Property MoveHeight() As Integer
  262.         Get
  263.             Return _MoveHeight
  264.         End Get
  265.         Set(ByVal v As Integer)
  266.             If v < 8 Then Return
  267.             Header = New Rectangle(7, 7, Width - 14, v - 7)
  268.             _MoveHeight = v
  269.             Invalidate()
  270.         End Set
  271.     End Property
  272.  
  273.     Private _ControlMode As Boolean
  274.     Protected Property ControlMode() As Boolean
  275.         Get
  276.             Return _ControlMode
  277.         End Get
  278.         Set(ByVal v As Boolean)
  279.             _ControlMode = v
  280.         End Set
  281.     End Property
  282.  
  283.     Private _TransparencyKey As Color
  284.     Property TransparencyKey() As Color
  285.         Get
  286.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.TransparencyKey Else Return _TransparencyKey
  287.         End Get
  288.         Set(ByVal value As Color)
  289.             If _IsParentForm AndAlso Not _ControlMode Then ParentForm.TransparencyKey = value
  290.             _TransparencyKey = value
  291.         End Set
  292.     End Property
  293.  
  294.     Private _BorderStyle As FormBorderStyle
  295.     Property BorderStyle() As FormBorderStyle
  296.         Get
  297.             If _IsParentForm AndAlso Not _ControlMode Then Return ParentForm.FormBorderStyle Else Return _BorderStyle
  298.         End Get
  299.         Set(ByVal value As FormBorderStyle)
  300.             If _IsParentForm AndAlso Not _ControlMode Then ParentForm.FormBorderStyle = value
  301.             _BorderStyle = value
  302.         End Set
  303.     End Property
  304.  
  305.     Private _NoRounding As Boolean
  306.     Property NoRounding() As Boolean
  307.         Get
  308.             Return _NoRounding
  309.         End Get
  310.         Set(ByVal v As Boolean)
  311.             _NoRounding = v
  312.             Invalidate()
  313.         End Set
  314.     End Property
  315.  
  316.     Private _Image As Image
  317.     Property Image() As Image
  318.         Get
  319.             Return _Image
  320.         End Get
  321.         Set(ByVal value As Image)
  322.             If value Is Nothing Then
  323.                 _ImageSize = Size.Empty
  324.             Else
  325.                 _ImageSize = value.Size
  326.             End If
  327.  
  328.             _Image = value
  329.             Invalidate()
  330.         End Set
  331.     End Property
  332.  
  333.     Private _ImageSize As Size
  334.     Protected ReadOnly Property ImageSize() As Size
  335.         Get
  336.             Return _ImageSize
  337.         End Get
  338.     End Property
  339.  
  340.     Private _IsParentForm As Boolean
  341.     Protected ReadOnly Property IsParentForm As Boolean
  342.         Get
  343.             Return _IsParentForm
  344.         End Get
  345.     End Property
  346.  
  347.     Private _LockWidth As Integer
  348.     Protected Property LockWidth() As Integer
  349.         Get
  350.             Return _LockWidth
  351.         End Get
  352.         Set(ByVal value As Integer)
  353.             _LockWidth = value
  354.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  355.         End Set
  356.     End Property
  357.  
  358.     Private _LockHeight As Integer
  359.     Protected Property LockHeight() As Integer
  360.         Get
  361.             Return _LockHeight
  362.         End Get
  363.         Set(ByVal value As Integer)
  364.             _LockHeight = value
  365.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  366.         End Set
  367.     End Property
  368.  
  369.     Private Items As New Dictionary(Of String, Color)
  370.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  371.     Property Colors() As Bloom()
  372.         Get
  373.             Dim T As New List(Of Bloom)
  374.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  375.  
  376.             While E.MoveNext
  377.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  378.             End While
  379.  
  380.             Return T.ToArray
  381.         End Get
  382.         Set(ByVal value As Bloom())
  383.             For Each B As Bloom In value
  384.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  385.             Next
  386.  
  387.             InvalidateCustimization()
  388.             ColorHook()
  389.             Invalidate()
  390.         End Set
  391.     End Property
  392.  
  393.     Private _Customization As String
  394.     Property Customization() As String
  395.         Get
  396.             Return _Customization
  397.         End Get
  398.         Set(ByVal value As String)
  399.             If value = _Customization Then Return
  400.  
  401.             Dim Data As Byte()
  402.             Dim Items As Bloom() = Colors
  403.  
  404.             Try
  405.                 Data = Convert.FromBase64String(value)
  406.                 For I As Integer = 0 To Items.Length - 1
  407.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  408.                 Next
  409.             Catch
  410.                 Return
  411.             End Try
  412.  
  413.             _Customization = value
  414.  
  415.             Colors = Items
  416.             ColorHook()
  417.             Invalidate()
  418.         End Set
  419.     End Property
  420.  
  421. #End Region
  422.  
  423. #Region " Property Helpers "
  424.  
  425.     Protected Function GetColor(ByVal name As String) As Color
  426.         Return Items(name)
  427.     End Function
  428.  
  429.     Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  430.         If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  431.     End Sub
  432.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  433.         SetColor(name, Color.FromArgb(r, g, b))
  434.     End Sub
  435.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  436.         SetColor(name, Color.FromArgb(a, r, g, b))
  437.     End Sub
  438.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  439.         SetColor(name, color.FromArgb(a, color))
  440.     End Sub
  441.  
  442.     Private Sub InvalidateCustimization()
  443.         Dim M As New MemoryStream(Items.Count * 4)
  444.  
  445.         For Each B As Bloom In Colors
  446.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  447.         Next
  448.  
  449.         M.Close()
  450.         _Customization = Convert.ToBase64String(M.ToArray)
  451.     End Sub
  452.  
  453. #End Region
  454.  
  455.  
  456. #Region " User Hooks "
  457.  
  458.     Protected MustOverride Sub ColorHook()
  459.     Protected MustOverride Sub PaintHook()
  460.  
  461. #End Region
  462.  
  463.  
  464. #Region " Center Overloads "
  465.  
  466.     Private CenterReturn As Point
  467.  
  468.     Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  469.         CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  470.         Return CenterReturn
  471.     End Function
  472.     Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  473.         Return Center(r1, r2.Size)
  474.     End Function
  475.  
  476.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  477.         CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  478.         Return CenterReturn
  479.     End Function
  480.  
  481.     Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  482.         Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  483.     End Function
  484.  
  485.     Protected Function Center(ByVal r1 As Rectangle) As Point
  486.         Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  487.     End Function
  488.     Protected Function Center(ByVal s1 As Size) As Point
  489.         Return Center(Width, Height, s1.Width, s1.Height)
  490.     End Function
  491.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  492.         Return Center(Width, Height, w1, h1)
  493.     End Function
  494.  
  495. #End Region
  496.  
  497. #Region " Measure Overloads "
  498.  
  499.     Private MeasureBitmap As Bitmap
  500.     Private MeasureGraphics As Graphics
  501.  
  502.     Protected Function Measure(ByVal text As String) As Size
  503.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  504.     End Function
  505.     Protected Function Measure() As Size
  506.         Return MeasureGraphics.MeasureString(Text, Font).ToSize
  507.     End Function
  508.  
  509. #End Region
  510.  
  511. #Region " DrawCorners Overloads "
  512.  
  513.     'TODO: Optimize by checking brush color
  514.  
  515.     Private DrawCornersBrush As SolidBrush
  516.  
  517.     Protected Sub DrawCorners(ByVal c1 As Color)
  518.         DrawCorners(c1, 0, 0, Width, Height)
  519.     End Sub
  520.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  521.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  522.     End Sub
  523.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  524.         If _NoRounding Then Return
  525.  
  526.         DrawCornersBrush = New SolidBrush(c1)
  527.         G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  528.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  529.         G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  530.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  531.     End Sub
  532.  
  533. #End Region
  534.  
  535. #Region " DrawBorders Overloads "
  536.  
  537.     'TODO: Remove triple overload?
  538.  
  539.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  540.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  541.     End Sub
  542.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  543.         DrawBorders(p1, 0, 0, Width, Height, offset)
  544.     End Sub
  545.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  546.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  547.     End Sub
  548.  
  549.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  550.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  551.     End Sub
  552.     Protected Sub DrawBorders(ByVal p1 As Pen)
  553.         DrawBorders(p1, 0, 0, Width, Height)
  554.     End Sub
  555.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  556.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  557.     End Sub
  558.  
  559. #End Region
  560.  
  561. #Region " DrawText Overloads "
  562.  
  563.     'TODO: Remove triple overloads?
  564.  
  565.     Private DrawTextPoint As Point
  566.     Private DrawTextSize As Size
  567.  
  568.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  569.         DrawText(b1, Text, a, x, y)
  570.     End Sub
  571.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  572.         DrawText(b1, Text, p1.X, p1.Y)
  573.     End Sub
  574.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  575.         DrawText(b1, Text, x, y)
  576.     End Sub
  577.  
  578.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  579.         If text.Length = 0 Then Return
  580.         DrawTextSize = Measure(text)
  581.         DrawTextPoint = New Point(Width \ 2 - DrawTextSize.Width \ 2, MoveHeight \ 2 - DrawTextSize.Height \ 2)
  582.  
  583.         Select Case a
  584.             Case HorizontalAlignment.Left
  585.                 DrawText(b1, text, x, DrawTextPoint.Y + y)
  586.             Case HorizontalAlignment.Center
  587.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  588.             Case HorizontalAlignment.Right
  589.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  590.         End Select
  591.     End Sub
  592.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  593.         DrawText(b1, text, p1.X, p1.Y)
  594.     End Sub
  595.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  596.         If text.Length = 0 Then Return
  597.         G.DrawString(text, Font, b1, x, y)
  598.     End Sub
  599.  
  600. #End Region
  601.  
  602. #Region " DrawImage Overloads "
  603.  
  604.     'TODO: Remove triple overloads?
  605.  
  606.     Private DrawImagePoint As Point
  607.  
  608.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  609.         DrawImage(_Image, a, x, y)
  610.     End Sub
  611.     Protected Sub DrawImage(ByVal p1 As Point)
  612.         DrawImage(_Image, p1.X, p1.Y)
  613.     End Sub
  614.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  615.         DrawImage(_Image, x, y)
  616.     End Sub
  617.  
  618.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  619.         If image Is Nothing Then Return
  620.         DrawImagePoint = New Point(Width \ 2 - image.Width \ 2, MoveHeight \ 2 - image.Height \ 2)
  621.  
  622.         Select Case a
  623.             Case HorizontalAlignment.Left
  624.                 DrawImage(image, x, DrawImagePoint.Y + y)
  625.             Case HorizontalAlignment.Center
  626.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  627.             Case HorizontalAlignment.Right
  628.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  629.         End Select
  630.     End Sub
  631.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  632.         DrawImage(image, p1.X, p1.Y)
  633.     End Sub
  634.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  635.         If image Is Nothing Then Return
  636.         G.DrawImage(image, x, y, image.Width, image.Height)
  637.     End Sub
  638.  
  639. #End Region
  640.  
  641. #Region " DrawGradient Overloads "
  642.  
  643.     'TODO: Remove triple overload?
  644.  
  645.     Private DrawGradientBrush As LinearGradientBrush
  646.     Private DrawGradientRectangle As Rectangle
  647.  
  648.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  649.         DrawGradient(blend, x, y, width, height, 90S)
  650.     End Sub
  651.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  652.         DrawGradient(c1, c2, x, y, width, height, 90S)
  653.     End Sub
  654.  
  655.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  656.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  657.         DrawGradient(blend, DrawGradientRectangle, angle)
  658.     End Sub
  659.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  660.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  661.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  662.     End Sub
  663.  
  664.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  665.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  666.         DrawGradientBrush.InterpolationColors = blend
  667.         G.FillRectangle(DrawGradientBrush, r)
  668.     End Sub
  669.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  670.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  671.         G.FillRectangle(DrawGradientBrush, r)
  672.     End Sub
  673.  
  674. #End Region
  675.  
  676. End Class
  677.  
  678. MustInherit Class ThemeControl151
  679.     Inherits Control
  680.  
  681.     Protected G As Graphics, B As Bitmap
  682.  
  683.     Sub New()
  684.         SetStyle(DirectCast(139270, ControlStyles), True)
  685.  
  686.         _ImageSize = Size.Empty
  687.  
  688.         MeasureBitmap = New Bitmap(1, 1)
  689.         MeasureGraphics = Graphics.FromImage(MeasureBitmap)
  690.  
  691.         Font = New Font("Verdana", 8S)
  692.  
  693.         InvalidateCustimization()
  694.     End Sub
  695.  
  696.     Protected Overrides Sub SetBoundsCore(ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal specified As BoundsSpecified)
  697.         If Not _LockWidth = 0 Then width = _LockWidth
  698.         If Not _LockHeight = 0 Then height = _LockHeight
  699.         MyBase.SetBoundsCore(x, y, width, height, specified)
  700.     End Sub
  701.  
  702.     Protected NotOverridable Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  703.         If _Transparent AndAlso Not (Width = 0 OrElse Height = 0) Then
  704.             B = New Bitmap(Width, Height)
  705.             G = Graphics.FromImage(B)
  706.         End If
  707.  
  708.         Invalidate()
  709.         MyBase.OnSizeChanged(e)
  710.     End Sub
  711.  
  712.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  713.         If Width = 0 OrElse Height = 0 Then Return
  714.  
  715.         If _Transparent Then
  716.             PaintHook()
  717.             e.Graphics.DrawImage(B, 0, 0)
  718.         Else
  719.             G = e.Graphics
  720.             PaintHook()
  721.         End If
  722.     End Sub
  723.  
  724.     Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  725.         InvalidateCustimization()
  726.         ColorHook()
  727.  
  728.         If Not _LockWidth = 0 Then Width = _LockWidth
  729.         If Not _LockHeight = 0 Then Height = _LockHeight
  730.         If Not BackColorWait = Nothing Then BackColor = BackColorWait
  731.  
  732.         OnCreation()
  733.         MyBase.OnHandleCreated(e)
  734.     End Sub
  735.  
  736.     Protected Overridable Sub OnCreation()
  737.     End Sub
  738.  
  739. #Region " State Handling "
  740.  
  741.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  742.         SetState(MouseState.Over)
  743.         MyBase.OnMouseEnter(e)
  744.     End Sub
  745.  
  746.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  747.         SetState(MouseState.Over)
  748.         MyBase.OnMouseUp(e)
  749.     End Sub
  750.  
  751.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  752.         If e.Button = Windows.Forms.MouseButtons.Left Then SetState(MouseState.Down)
  753.         MyBase.OnMouseDown(e)
  754.     End Sub
  755.  
  756.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  757.         SetState(MouseState.None)
  758.         MyBase.OnMouseLeave(e)
  759.     End Sub
  760.  
  761.     Protected Overrides Sub OnEnabledChanged(ByVal e As EventArgs)
  762.         If Enabled Then SetState(MouseState.None) Else SetState(MouseState.Block)
  763.         MyBase.OnEnabledChanged(e)
  764.     End Sub
  765.  
  766.     Protected State As MouseState
  767.     Private Sub SetState(ByVal current As MouseState)
  768.         State = current
  769.         Invalidate()
  770.     End Sub
  771.  
  772. #End Region
  773.  
  774.  
  775. #Region " Property Overrides "
  776.  
  777.     Private BackColorWait As Color
  778.     Overrides Property BackColor() As Color
  779.         Get
  780.             Return MyBase.BackColor
  781.         End Get
  782.         Set(ByVal value As Color)
  783.             If IsHandleCreated Then
  784.                 MyBase.BackColor = value
  785.             Else
  786.                 BackColorWait = value
  787.             End If
  788.         End Set
  789.     End Property
  790.  
  791.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  792.     Overrides Property ForeColor() As Color
  793.         Get
  794.             Return Color.Empty
  795.         End Get
  796.         Set(ByVal value As Color)
  797.         End Set
  798.     End Property
  799.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  800.     Overrides Property BackgroundImage() As Image
  801.         Get
  802.             Return Nothing
  803.         End Get
  804.         Set(ByVal value As Image)
  805.         End Set
  806.     End Property
  807.     <Browsable(False), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)> _
  808.     Overrides Property BackgroundImageLayout() As ImageLayout
  809.         Get
  810.             Return ImageLayout.None
  811.         End Get
  812.         Set(ByVal value As ImageLayout)
  813.         End Set
  814.     End Property
  815.  
  816.     Overrides Property Text() As String
  817.         Get
  818.             Return MyBase.Text
  819.         End Get
  820.         Set(ByVal value As String)
  821.             MyBase.Text = value
  822.             Invalidate()
  823.         End Set
  824.     End Property
  825.  
  826.     Overrides Property Font() As Font
  827.         Get
  828.             Return MyBase.Font
  829.         End Get
  830.         Set(ByVal value As Font)
  831.             MyBase.Font = value
  832.             Invalidate()
  833.         End Set
  834.     End Property
  835.  
  836. #End Region
  837.  
  838. #Region " Properties "
  839.  
  840.     Private _NoRounding As Boolean
  841.     Property NoRounding() As Boolean
  842.         Get
  843.             Return _NoRounding
  844.         End Get
  845.         Set(ByVal v As Boolean)
  846.             _NoRounding = v
  847.             Invalidate()
  848.         End Set
  849.     End Property
  850.  
  851.     Private _Image As Image
  852.     Property Image() As Image
  853.         Get
  854.             Return _Image
  855.         End Get
  856.         Set(ByVal value As Image)
  857.             If value Is Nothing Then
  858.                 _ImageSize = Size.Empty
  859.             Else
  860.                 _ImageSize = value.Size
  861.             End If
  862.  
  863.             _Image = value
  864.             Invalidate()
  865.         End Set
  866.     End Property
  867.  
  868.     Private _ImageSize As Size
  869.     Protected ReadOnly Property ImageSize() As Size
  870.         Get
  871.             Return _ImageSize
  872.         End Get
  873.     End Property
  874.  
  875.     Private _LockWidth As Integer
  876.     Protected Property LockWidth() As Integer
  877.         Get
  878.             Return _LockWidth
  879.         End Get
  880.         Set(ByVal value As Integer)
  881.             _LockWidth = value
  882.             If Not LockWidth = 0 AndAlso IsHandleCreated Then Width = LockWidth
  883.         End Set
  884.     End Property
  885.  
  886.     Private _LockHeight As Integer
  887.     Protected Property LockHeight() As Integer
  888.         Get
  889.             Return _LockHeight
  890.         End Get
  891.         Set(ByVal value As Integer)
  892.             _LockHeight = value
  893.             If Not LockHeight = 0 AndAlso IsHandleCreated Then Height = LockHeight
  894.         End Set
  895.     End Property
  896.  
  897.     Private _Transparent As Boolean
  898.     Property Transparent() As Boolean
  899.         Get
  900.             Return _Transparent
  901.         End Get
  902.         Set(ByVal value As Boolean)
  903.             If Not value AndAlso Not BackColor.A = 255 Then
  904.                 Throw New Exception("Unable to change value to false while a transparent BackColor is in use.")
  905.             End If
  906.  
  907.             SetStyle(ControlStyles.Opaque, Not value)
  908.             SetStyle(ControlStyles.SupportsTransparentBackColor, value)
  909.  
  910.             If value Then InvalidateBitmap() Else B = Nothing
  911.  
  912.             _Transparent = value
  913.             Invalidate()
  914.         End Set
  915.     End Property
  916.  
  917.     Private Items As New Dictionary(Of String, Color)
  918.     <DesignerSerializationVisibility(DesignerSerializationVisibility.Content)> _
  919.     Property Colors() As Bloom()
  920.         Get
  921.             Dim T As New List(Of Bloom)
  922.             Dim E As Dictionary(Of String, Color).Enumerator = Items.GetEnumerator
  923.  
  924.             While E.MoveNext
  925.                 T.Add(New Bloom(E.Current.Key, E.Current.Value))
  926.             End While
  927.  
  928.             Return T.ToArray
  929.         End Get
  930.         Set(ByVal value As Bloom())
  931.             For Each B As Bloom In value
  932.                 If Items.ContainsKey(B.Name) Then Items(B.Name) = B.Value
  933.             Next
  934.  
  935.             InvalidateCustimization()
  936.             ColorHook()
  937.             Invalidate()
  938.         End Set
  939.     End Property
  940.  
  941.     Private _Customization As String
  942.     Property Customization() As String
  943.         Get
  944.             Return _Customization
  945.         End Get
  946.         Set(ByVal value As String)
  947.             If value = _Customization Then Return
  948.  
  949.             Dim Data As Byte()
  950.             Dim Items As Bloom() = Colors
  951.  
  952.             Try
  953.                 Data = Convert.FromBase64String(value)
  954.                 For I As Integer = 0 To Items.Length - 1
  955.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4))
  956.                 Next
  957.             Catch
  958.                 Return
  959.             End Try
  960.  
  961.             _Customization = value
  962.  
  963.             Colors = Items
  964.             ColorHook()
  965.             Invalidate()
  966.         End Set
  967.     End Property
  968.  
  969. #End Region
  970.  
  971. #Region " Property Helpers "
  972.  
  973.     Private Sub InvalidateBitmap()
  974.         If Width = 0 OrElse Height = 0 Then Return
  975.         B = New Bitmap(Width, Height)
  976.         G = Graphics.FromImage(B)
  977.     End Sub
  978.  
  979.     Protected Function GetColor(ByVal name As String) As Color
  980.         Return Items(name)
  981.     End Function
  982.  
  983.     Protected Sub SetColor(ByVal name As String, ByVal color As Color)
  984.         If Items.ContainsKey(name) Then Items(name) = color Else Items.Add(name, color)
  985.     End Sub
  986.     Protected Sub SetColor(ByVal name As String, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  987.         SetColor(name, Color.FromArgb(r, g, b))
  988.     End Sub
  989.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal r As Byte, ByVal g As Byte, ByVal b As Byte)
  990.         SetColor(name, Color.FromArgb(a, r, g, b))
  991.     End Sub
  992.     Protected Sub SetColor(ByVal name As String, ByVal a As Byte, ByVal color As Color)
  993.         SetColor(name, color.FromArgb(a, color))
  994.     End Sub
  995.  
  996.     Private Sub InvalidateCustimization()
  997.         Dim M As New MemoryStream(Items.Count * 4)
  998.  
  999.         For Each B As Bloom In Colors
  1000.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4)
  1001.         Next
  1002.  
  1003.         M.Close()
  1004.         _Customization = Convert.ToBase64String(M.ToArray)
  1005.     End Sub
  1006.  
  1007. #End Region
  1008.  
  1009.  
  1010. #Region " User Hooks "
  1011.  
  1012.     Protected MustOverride Sub ColorHook()
  1013.     Protected MustOverride Sub PaintHook()
  1014.  
  1015. #End Region
  1016.  
  1017.  
  1018. #Region " Center Overloads "
  1019.  
  1020.     Private CenterReturn As Point
  1021.  
  1022.     Protected Function Center(ByVal r1 As Rectangle, ByVal s1 As Size) As Point
  1023.         CenterReturn = New Point((r1.Width \ 2 - s1.Width \ 2) + r1.X, (r1.Height \ 2 - s1.Height \ 2) + r1.Y)
  1024.         Return CenterReturn
  1025.     End Function
  1026.     Protected Function Center(ByVal r1 As Rectangle, ByVal r2 As Rectangle) As Point
  1027.         Return Center(r1, r2.Size)
  1028.     End Function
  1029.  
  1030.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer, ByVal w2 As Integer, ByVal h2 As Integer) As Point
  1031.         CenterReturn = New Point(w1 \ 2 - w2 \ 2, h1 \ 2 - h2 \ 2)
  1032.         Return CenterReturn
  1033.     End Function
  1034.  
  1035.     Protected Function Center(ByVal s1 As Size, ByVal s2 As Size) As Point
  1036.         Return Center(s1.Width, s1.Height, s2.Width, s2.Height)
  1037.     End Function
  1038.  
  1039.     Protected Function Center(ByVal r1 As Rectangle) As Point
  1040.         Return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height)
  1041.     End Function
  1042.     Protected Function Center(ByVal s1 As Size) As Point
  1043.         Return Center(Width, Height, s1.Width, s1.Height)
  1044.     End Function
  1045.     Protected Function Center(ByVal w1 As Integer, ByVal h1 As Integer) As Point
  1046.         Return Center(Width, Height, w1, h1)
  1047.     End Function
  1048.  
  1049. #End Region
  1050.  
  1051. #Region " Measure Overloads "
  1052.  
  1053.     Private MeasureBitmap As Bitmap
  1054.     Private MeasureGraphics As Graphics
  1055.  
  1056.     Protected Function Measure(ByVal text As String) As Size
  1057.         Return MeasureGraphics.MeasureString(text, Font, Width).ToSize
  1058.     End Function
  1059.     Protected Function Measure() As Size
  1060.         Return MeasureGraphics.MeasureString(Text, Font, Width).ToSize
  1061.     End Function
  1062.  
  1063. #End Region
  1064.  
  1065. #Region " DrawCorners Overloads "
  1066.  
  1067.     'TODO: Optimize by checking brush color
  1068.  
  1069.     Private DrawCornersBrush As SolidBrush
  1070.  
  1071.     Protected Sub DrawCorners(ByVal c1 As Color)
  1072.         DrawCorners(c1, 0, 0, Width, Height)
  1073.     End Sub
  1074.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal r1 As Rectangle)
  1075.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height)
  1076.     End Sub
  1077.     Protected Sub DrawCorners(ByVal c1 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1078.         If _NoRounding Then Return
  1079.  
  1080.         If _Transparent Then
  1081.             B.SetPixel(x, y, c1)
  1082.             B.SetPixel(x + (width - 1), y, c1)
  1083.             B.SetPixel(x, y + (height - 1), c1)
  1084.             B.SetPixel(x + (width - 1), y + (height - 1), c1)
  1085.         Else
  1086.             DrawCornersBrush = New SolidBrush(c1)
  1087.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1)
  1088.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1)
  1089.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1)
  1090.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1)
  1091.         End If
  1092.     End Sub
  1093.  
  1094. #End Region
  1095.  
  1096. #Region " DrawBorders Overloads "
  1097.  
  1098.     'TODO: Remove triple overload?
  1099.  
  1100.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal offset As Integer)
  1101.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2))
  1102.     End Sub
  1103.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal offset As Integer)
  1104.         DrawBorders(p1, 0, 0, Width, Height, offset)
  1105.     End Sub
  1106.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle, ByVal offset As Integer)
  1107.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset)
  1108.     End Sub
  1109.  
  1110.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1111.         G.DrawRectangle(p1, x, y, width - 1, height - 1)
  1112.     End Sub
  1113.     Protected Sub DrawBorders(ByVal p1 As Pen)
  1114.         DrawBorders(p1, 0, 0, Width, Height)
  1115.     End Sub
  1116.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal r As Rectangle)
  1117.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height)
  1118.     End Sub
  1119.  
  1120. #End Region
  1121.  
  1122. #Region " DrawText Overloads "
  1123.  
  1124.     'TODO: Remove triple overloads?
  1125.  
  1126.     Private DrawTextPoint As Point
  1127.     Private DrawTextSize As Size
  1128.  
  1129.     Protected Sub DrawText(ByVal b1 As Brush, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1130.         DrawText(b1, Text, a, x, y)
  1131.     End Sub
  1132.     Protected Sub DrawText(ByVal b1 As Brush, ByVal p1 As Point)
  1133.         DrawText(b1, Text, p1.X, p1.Y)
  1134.     End Sub
  1135.     Protected Sub DrawText(ByVal b1 As Brush, ByVal x As Integer, ByVal y As Integer)
  1136.         DrawText(b1, Text, x, y)
  1137.     End Sub
  1138.  
  1139.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1140.         If text.Length = 0 Then Return
  1141.         DrawTextSize = Measure(text)
  1142.         DrawTextPoint = Center(DrawTextSize)
  1143.  
  1144.         Select Case a
  1145.             Case HorizontalAlignment.Left
  1146.                 DrawText(b1, text, x, DrawTextPoint.Y + y)
  1147.             Case HorizontalAlignment.Center
  1148.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y)
  1149.             Case HorizontalAlignment.Right
  1150.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y)
  1151.         End Select
  1152.     End Sub
  1153.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal p1 As Point)
  1154.         DrawText(b1, text, p1.X, p1.Y)
  1155.     End Sub
  1156.     Protected Sub DrawText(ByVal b1 As Brush, ByVal text As String, ByVal x As Integer, ByVal y As Integer)
  1157.         If text.Length = 0 Then Return
  1158.         G.DrawString(text, Font, b1, x, y)
  1159.     End Sub
  1160.  
  1161. #End Region
  1162.  
  1163. #Region " DrawImage Overloads "
  1164.  
  1165.     'TODO: Remove triple overloads?
  1166.  
  1167.     Private DrawImagePoint As Point
  1168.  
  1169.     Protected Sub DrawImage(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1170.         DrawImage(_Image, a, x, y)
  1171.     End Sub
  1172.     Protected Sub DrawImage(ByVal p1 As Point)
  1173.         DrawImage(_Image, p1.X, p1.Y)
  1174.     End Sub
  1175.     Protected Sub DrawImage(ByVal x As Integer, ByVal y As Integer)
  1176.         DrawImage(_Image, x, y)
  1177.     End Sub
  1178.  
  1179.     Protected Sub DrawImage(ByVal image As Image, ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  1180.         If image Is Nothing Then Return
  1181.         DrawImagePoint = Center(image.Size)
  1182.  
  1183.         Select Case a
  1184.             Case HorizontalAlignment.Left
  1185.                 DrawImage(image, x, DrawImagePoint.Y + y)
  1186.             Case HorizontalAlignment.Center
  1187.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y)
  1188.             Case HorizontalAlignment.Right
  1189.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y)
  1190.         End Select
  1191.     End Sub
  1192.     Protected Sub DrawImage(ByVal image As Image, ByVal p1 As Point)
  1193.         DrawImage(image, p1.X, p1.Y)
  1194.     End Sub
  1195.     Protected Sub DrawImage(ByVal image As Image, ByVal x As Integer, ByVal y As Integer)
  1196.         If image Is Nothing Then Return
  1197.         G.DrawImage(image, x, y, image.Width, image.Height)
  1198.     End Sub
  1199.  
  1200. #End Region
  1201.  
  1202. #Region " DrawGradient Overloads "
  1203.  
  1204.     'TODO: Remove triple overload?
  1205.  
  1206.     Private DrawGradientBrush As LinearGradientBrush
  1207.     Private DrawGradientRectangle As Rectangle
  1208.  
  1209.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1210.         DrawGradient(blend, x, y, width, height, 90S)
  1211.     End Sub
  1212.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer)
  1213.         DrawGradient(c1, c2, x, y, width, height, 90S)
  1214.     End Sub
  1215.  
  1216.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1217.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1218.         DrawGradient(blend, DrawGradientRectangle, angle)
  1219.     End Sub
  1220.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal x As Integer, ByVal y As Integer, ByVal width As Integer, ByVal height As Integer, ByVal angle As Single)
  1221.         DrawGradientRectangle = New Rectangle(x, y, width, height)
  1222.         DrawGradient(c1, c2, DrawGradientRectangle, angle)
  1223.     End Sub
  1224.  
  1225.     Protected Sub DrawGradient(ByVal blend As ColorBlend, ByVal r As Rectangle, ByVal angle As Single)
  1226.         DrawGradientBrush = New LinearGradientBrush(r, Color.Empty, Color.Empty, angle)
  1227.         DrawGradientBrush.InterpolationColors = blend
  1228.         G.FillRectangle(DrawGradientBrush, r)
  1229.     End Sub
  1230.     Protected Sub DrawGradient(ByVal c1 As Color, ByVal c2 As Color, ByVal r As Rectangle, ByVal angle As Single)
  1231.         DrawGradientBrush = New LinearGradientBrush(r, c1, c2, angle)
  1232.         G.FillRectangle(DrawGradientBrush, r)
  1233.     End Sub
  1234.  
  1235. #End Region
  1236.  
  1237. End Class
  1238.  
  1239. Enum MouseState As Byte
  1240.     None = 0
  1241.     Over = 1
  1242.     Down = 2
  1243.     Block = 3
  1244. End Enum
  1245.  
  1246. Class Bloom
  1247.  
  1248.     Private _Name As String
  1249.     Property Name() As String
  1250.         Get
  1251.             Return _Name
  1252.         End Get
  1253.         Set(ByVal value As String)
  1254.             _Name = value
  1255.         End Set
  1256.     End Property
  1257.  
  1258.     Private _Value As Color
  1259.     Property Value() As Color
  1260.         Get
  1261.             Return _Value
  1262.         End Get
  1263.         Set(ByVal value As Color)
  1264.             _Value = value
  1265.         End Set
  1266.     End Property
  1267.  
  1268.     Sub New()
  1269.     End Sub
  1270.  
  1271.     Sub New(ByVal name As String, ByVal value As Color)
  1272.         _Name = name
  1273.         _Value = value
  1274.     End Sub
  1275. End Class
  1276.  
  1277. Class SimplThemeBottom
  1278.     Inherits ThemeContainer151
  1279.  
  1280.     Sub New()
  1281.         TransparencyKey = Color.Fuchsia
  1282.     End Sub
  1283.     Protected Overrides Sub ColorHook()
  1284.  
  1285.     End Sub
  1286.  
  1287.     Protected Overrides Sub PaintHook()
  1288.         G.Clear(Color.FromArgb(35, 35, 35))
  1289.         DrawGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(211, 211, 211), ClientRectangle, 90S)
  1290.         DrawGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(211, 211, 211), 0, 0, Width, 35, 90S)
  1291.  
  1292.         DrawGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(211, 211, 211), 0, Height - 35, Width, 35, 90S)
  1293.         G.DrawLine(Pens.DarkGray, 0, Height - 35, Width, Height - 35)
  1294.  
  1295.         G.DrawLine(Pens.DarkGray, 0, 35, Width, 35)
  1296.         DrawText(Brushes.Black, 12, 12)
  1297.         DrawBorders(Pens.DarkGray)
  1298.         DrawCorners(TransparencyKey)
  1299.  
  1300.     End Sub
  1301. End Class
  1302. Class SimplTheme
  1303.     Inherits ThemeContainer151
  1304.  
  1305.     Sub New()
  1306.         TransparencyKey = Color.Fuchsia
  1307.     End Sub
  1308.     Protected Overrides Sub ColorHook()
  1309.  
  1310.     End Sub
  1311.  
  1312.     Protected Overrides Sub PaintHook()
  1313.         G.Clear(Color.FromArgb(35, 35, 35))
  1314.         DrawGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(211, 211, 211), ClientRectangle, 90S)
  1315.         DrawGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(211, 211, 211), 0, 0, Width, 35, 90S)
  1316.  
  1317.         G.DrawLine(Pens.DarkGray, 0, 35, Width, 35)
  1318.         DrawText(Brushes.Black, 12, 12)
  1319.         DrawBorders(Pens.DarkGray)
  1320.         DrawCorners(TransparencyKey)
  1321.     End Sub
  1322. End Class
  1323. Class SimplButton
  1324.     Inherits ThemeControl151
  1325.  
  1326.     Protected Overrides Sub ColorHook()
  1327.  
  1328.     End Sub
  1329.  
  1330.     Protected Overrides Sub PaintHook()
  1331.         G.Clear(Color.FromArgb(35, 35, 35))
  1332.         Select Case State
  1333.             Case 0
  1334.                 DrawGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(211, 211, 211), 0, 0, Width, Height)
  1335.             Case 1
  1336.                 DrawGradient(Color.FromArgb(255, 255, 255), Color.FromArgb(105, 105, 105), 0, 0, Width, Height)
  1337.             Case 2
  1338.                 DrawGradient(Color.FromArgb(211, 211, 211), Color.FromArgb(255, 255, 255), 0, 0, Width, Height)
  1339.  
  1340.         End Select
  1341.         DrawText(Brushes.Black, HorizontalAlignment.Center, 0, 0)
  1342.         DrawBorders(Pens.DarkGray)
  1343.         DrawCorners(Color.FromArgb(211, 211, 211))
  1344.  
  1345.     End Sub
  1346. End Class
Advertisement
Add Comment
Please, Sign In to add comment