Awaken

BTheme - Carbon

Aug 20th, 2011
666
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 15.69 KB | None | 0 0
  1. 'Creator: ¢aявøn ғιвєя
  2. 'Date: 8/20/2011
  3. 'Thanks Aeon for theme base.
  4.  
  5. Imports System.Drawing.Drawing2D
  6. Imports System.ComponentModel
  7. Imports System.Runtime.InteropServices
  8.  
  9. MustInherit Class Theme
  10.     Inherits ContainerControl
  11.  
  12. #Region " Initialization "
  13.  
  14.     Protected G As Graphics
  15.     Sub New()
  16.         SetStyle(DirectCast(139270, ControlStyles), True)
  17.     End Sub
  18.  
  19.     Private ParentIsForm As Boolean
  20.     Protected Overrides Sub OnHandleCreated(ByVal e As EventArgs)
  21.         Dock = DockStyle.Fill
  22.         ParentIsForm = TypeOf Parent Is Form
  23.         If ParentIsForm Then
  24.             If Not _TransparencyKey = Color.Empty Then ParentForm.TransparencyKey = _TransparencyKey
  25.             ParentForm.FormBorderStyle = FormBorderStyle.None
  26.         End If
  27.         MyBase.OnHandleCreated(e)
  28.     End Sub
  29.  
  30.     Overrides Property Text As String
  31.         Get
  32.             Return MyBase.Text
  33.         End Get
  34.         Set(ByVal v As String)
  35.             MyBase.Text = v
  36.             Invalidate()
  37.         End Set
  38.     End Property
  39. #End Region
  40.  
  41. #Region " Sizing and Movement "
  42.  
  43.     Private _Resizable As Boolean = True
  44.     Property Resizable() As Boolean
  45.         Get
  46.             Return _Resizable
  47.         End Get
  48.         Set(ByVal value As Boolean)
  49.             _Resizable = value
  50.         End Set
  51.     End Property
  52.  
  53.     Private _MoveHeight As Integer = 24
  54.     Property MoveHeight() As Integer
  55.         Get
  56.             Return _MoveHeight
  57.         End Get
  58.         Set(ByVal v As Integer)
  59.             _MoveHeight = v
  60.             Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  61.         End Set
  62.     End Property
  63.  
  64.     Private Flag As IntPtr
  65.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  66.         If Not e.Button = MouseButtons.Left Then Return
  67.         If ParentIsForm Then If ParentForm.WindowState = FormWindowState.Maximized Then Return
  68.  
  69.         If Header.Contains(e.Location) Then
  70.             Flag = New IntPtr(2)
  71.         ElseIf Current.Position = 0 Or Not _Resizable Then
  72.             Return
  73.         Else
  74.             Flag = New IntPtr(Current.Position)
  75.         End If
  76.  
  77.         Capture = False
  78.         DefWndProc(Message.Create(Parent.Handle, 161, Flag, Nothing))
  79.  
  80.         MyBase.OnMouseDown(e)
  81.     End Sub
  82.  
  83.     Private Structure Pointer
  84.         ReadOnly Cursor As Cursor, Position As Byte
  85.         Sub New(ByVal c As Cursor, ByVal p As Byte)
  86.             Cursor = c
  87.             Position = p
  88.         End Sub
  89.     End Structure
  90.  
  91.     Private F1, F2, F3, F4 As Boolean, PTC As Point
  92.     Private Function GetPointer() As Pointer
  93.         PTC = PointToClient(MousePosition)
  94.         F1 = PTC.X < 7
  95.         F2 = PTC.X > Width - 7
  96.         F3 = PTC.Y < 7
  97.         F4 = PTC.Y > Height - 7
  98.  
  99.         If F1 And F3 Then Return New Pointer(Cursors.SizeNWSE, 13)
  100.         If F1 And F4 Then Return New Pointer(Cursors.SizeNESW, 16)
  101.         If F2 And F3 Then Return New Pointer(Cursors.SizeNESW, 14)
  102.         If F2 And F4 Then Return New Pointer(Cursors.SizeNWSE, 17)
  103.         If F1 Then Return New Pointer(Cursors.SizeWE, 10)
  104.         If F2 Then Return New Pointer(Cursors.SizeWE, 11)
  105.         If F3 Then Return New Pointer(Cursors.SizeNS, 12)
  106.         If F4 Then Return New Pointer(Cursors.SizeNS, 15)
  107.         Return New Pointer(Cursors.Default, 0)
  108.     End Function
  109.  
  110.     Private Current, Pending As Pointer
  111.     Private Sub SetCurrent()
  112.         Pending = GetPointer()
  113.         If Current.Position = Pending.Position Then Return
  114.         Current = GetPointer()
  115.         Cursor = Current.Cursor
  116.     End Sub
  117.  
  118.     Protected Overrides Sub OnMouseMove(ByVal e As MouseEventArgs)
  119.         If _Resizable Then SetCurrent()
  120.         MyBase.OnMouseMove(e)
  121.     End Sub
  122.  
  123.     Protected Header As Rectangle
  124.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  125.         If Width = 0 OrElse Height = 0 Then Return
  126.         Header = New Rectangle(7, 7, Width - 14, _MoveHeight - 7)
  127.         Invalidate()
  128.         MyBase.OnSizeChanged(e)
  129.     End Sub
  130.  
  131. #End Region
  132.  
  133. #Region " Convienence "
  134.  
  135.     MustOverride Sub PaintHook()
  136.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  137.         If Width = 0 OrElse Height = 0 Then Return
  138.         G = e.Graphics
  139.         PaintHook()
  140.     End Sub
  141.  
  142.     Private _TransparencyKey As Color
  143.     Property TransparencyKey() As Color
  144.         Get
  145.             Return _TransparencyKey
  146.         End Get
  147.         Set(ByVal v As Color)
  148.             _TransparencyKey = v
  149.             Invalidate()
  150.         End Set
  151.     End Property
  152.  
  153.     Private _Image As Image
  154.     Property Image() As Image
  155.         Get
  156.             Return _Image
  157.         End Get
  158.         Set(ByVal value As Image)
  159.             _Image = value
  160.             Invalidate()
  161.         End Set
  162.     End Property
  163.     ReadOnly Property ImageWidth() As Integer
  164.         Get
  165.             If _Image Is Nothing Then Return 0
  166.             Return _Image.Width
  167.         End Get
  168.     End Property
  169.  
  170.     Private _Size As Size
  171.     Private _Rectangle As Rectangle
  172.     Private _Gradient As LinearGradientBrush
  173.     Private _Brush As SolidBrush
  174.  
  175.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  176.         _Brush = New SolidBrush(c)
  177.         G.FillRectangle(_Brush, rect.X, rect.Y, 1, 1)
  178.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y, 1, 1)
  179.         G.FillRectangle(_Brush, rect.X, rect.Y + (rect.Height - 1), 1, 1)
  180.         G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), 1, 1)
  181.     End Sub
  182.  
  183.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  184.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  185.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  186.     End Sub
  187.  
  188.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  189.         DrawText(a, c, x, 0)
  190.     End Sub
  191.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  192.         If String.IsNullOrEmpty(Text) Then Return
  193.         _Size = G.MeasureString(Text, Font).ToSize
  194.         _Brush = New SolidBrush(c)
  195.  
  196.         Select Case a
  197.             Case HorizontalAlignment.Left
  198.                 G.DrawString(Text, Font, _Brush, x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  199.             Case HorizontalAlignment.Right
  200.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  201.             Case HorizontalAlignment.Center
  202.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, _MoveHeight \ 2 - _Size.Height \ 2 + y)
  203.         End Select
  204.     End Sub
  205.  
  206.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  207.         DrawIcon(a, x, 0)
  208.     End Sub
  209.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  210.         If _Image Is Nothing Then Return
  211.         Select Case a
  212.             Case HorizontalAlignment.Left
  213.                 G.DrawImage(_Image, x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  214.             Case HorizontalAlignment.Right
  215.                 G.DrawImage(_Image, Width - _Image.Width - x, _MoveHeight \ 2 - _Image.Height \ 2 + y)
  216.             Case HorizontalAlignment.Center
  217.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, _MoveHeight \ 2 - _Image.Height \ 2)
  218.         End Select
  219.     End Sub
  220.  
  221.     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)
  222.         _Rectangle = New Rectangle(x, y, width, height)
  223.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  224.         G.FillRectangle(_Gradient, _Rectangle)
  225.     End Sub
  226.  
  227. #End Region
  228.  
  229. End Class
  230. MustInherit Class ThemeControl
  231.     Inherits Control
  232.  
  233. #Region " Initialization "
  234.  
  235.     Protected G As Graphics, B As Bitmap
  236.     Sub New()
  237.         SetStyle(DirectCast(139270, ControlStyles), True)
  238.         B = New Bitmap(1, 1)
  239.         G = Graphics.FromImage(B)
  240.     End Sub
  241.  
  242.     Sub AllowTransparent()
  243.         SetStyle(ControlStyles.Opaque, False)
  244.         SetStyle(ControlStyles.SupportsTransparentBackColor, True)
  245.     End Sub
  246.  
  247.     Overrides Property Text As String
  248.         Get
  249.             Return MyBase.Text
  250.         End Get
  251.         Set(ByVal v As String)
  252.             MyBase.Text = v
  253.             Invalidate()
  254.         End Set
  255.     End Property
  256. #End Region
  257.  
  258. #Region " Mouse Handling "
  259.  
  260.     Protected Enum State As Byte
  261.         MouseNone = 0
  262.         MouseOver = 1
  263.         MouseDown = 2
  264.     End Enum
  265.  
  266.     Protected MouseState As State
  267.     Protected Overrides Sub OnMouseLeave(ByVal e As EventArgs)
  268.         ChangeMouseState(State.MouseNone)
  269.         MyBase.OnMouseLeave(e)
  270.     End Sub
  271.     Protected Overrides Sub OnMouseEnter(ByVal e As EventArgs)
  272.         ChangeMouseState(State.MouseOver)
  273.         MyBase.OnMouseEnter(e)
  274.     End Sub
  275.     Protected Overrides Sub OnMouseUp(ByVal e As MouseEventArgs)
  276.         ChangeMouseState(State.MouseOver)
  277.         MyBase.OnMouseUp(e)
  278.     End Sub
  279.     Protected Overrides Sub OnMouseDown(ByVal e As MouseEventArgs)
  280.         If e.Button = MouseButtons.Left Then ChangeMouseState(State.MouseDown)
  281.         MyBase.OnMouseDown(e)
  282.     End Sub
  283.  
  284.     Private Sub ChangeMouseState(ByVal e As State)
  285.         MouseState = e
  286.         Invalidate()
  287.     End Sub
  288.  
  289. #End Region
  290.  
  291. #Region " Convienence "
  292.  
  293.     MustOverride Sub PaintHook()
  294.     Protected NotOverridable Overrides Sub OnPaint(ByVal e As PaintEventArgs)
  295.         If Width = 0 OrElse Height = 0 Then Return
  296.         PaintHook()
  297.         e.Graphics.DrawImage(B, 0, 0)
  298.     End Sub
  299.  
  300.     Protected Overrides Sub OnSizeChanged(ByVal e As EventArgs)
  301.         If Not Width = 0 AndAlso Not Height = 0 Then
  302.             B = New Bitmap(Width, Height)
  303.             G = Graphics.FromImage(B)
  304.             Invalidate()
  305.         End If
  306.         MyBase.OnSizeChanged(e)
  307.     End Sub
  308.  
  309.     Private _NoRounding As Boolean
  310.     Property NoRounding() As Boolean
  311.         Get
  312.             Return _NoRounding
  313.         End Get
  314.         Set(ByVal v As Boolean)
  315.             _NoRounding = v
  316.             Invalidate()
  317.         End Set
  318.     End Property
  319.  
  320.     Private _Image As Image
  321.     Property Image() As Image
  322.         Get
  323.             Return _Image
  324.         End Get
  325.         Set(ByVal value As Image)
  326.             _Image = value
  327.             Invalidate()
  328.         End Set
  329.     End Property
  330.     ReadOnly Property ImageWidth() As Integer
  331.         Get
  332.             If _Image Is Nothing Then Return 0
  333.             Return _Image.Width
  334.         End Get
  335.     End Property
  336.     ReadOnly Property ImageTop() As Integer
  337.         Get
  338.             If _Image Is Nothing Then Return 0
  339.             Return Height \ 2 - _Image.Height \ 2
  340.         End Get
  341.     End Property
  342.  
  343.     Private _Size As Size
  344.     Private _Rectangle As Rectangle
  345.     Private _Gradient As LinearGradientBrush
  346.     Private _Brush As SolidBrush
  347.  
  348.     Protected Sub DrawCorners(ByVal c As Color, ByVal rect As Rectangle)
  349.         If _NoRounding Then Return
  350.  
  351.         B.SetPixel(rect.X, rect.Y, c)
  352.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c)
  353.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c)
  354.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c)
  355.     End Sub
  356.  
  357.     Protected Sub DrawBorders(ByVal p1 As Pen, ByVal p2 As Pen, ByVal rect As Rectangle)
  358.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1)
  359.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3)
  360.     End Sub
  361.  
  362.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer)
  363.         DrawText(a, c, x, 0)
  364.     End Sub
  365.     Protected Sub DrawText(ByVal a As HorizontalAlignment, ByVal c As Color, ByVal x As Integer, ByVal y As Integer)
  366.         If String.IsNullOrEmpty(Text) Then Return
  367.         _Size = G.MeasureString(Text, Font).ToSize
  368.         _Brush = New SolidBrush(c)
  369.  
  370.         Select Case a
  371.             Case HorizontalAlignment.Left
  372.                 G.DrawString(Text, Font, _Brush, x, Height \ 2 - _Size.Height \ 2 + y)
  373.             Case HorizontalAlignment.Right
  374.                 G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, Height \ 2 - _Size.Height \ 2 + y)
  375.             Case HorizontalAlignment.Center
  376.                 G.DrawString(Text, Font, _Brush, Width \ 2 - _Size.Width \ 2 + x, Height \ 2 - _Size.Height \ 2 + y)
  377.         End Select
  378.     End Sub
  379.  
  380.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer)
  381.         DrawIcon(a, x, 0)
  382.     End Sub
  383.     Protected Sub DrawIcon(ByVal a As HorizontalAlignment, ByVal x As Integer, ByVal y As Integer)
  384.         If _Image Is Nothing Then Return
  385.         Select Case a
  386.             Case HorizontalAlignment.Left
  387.                 G.DrawImage(_Image, x, Height \ 2 - _Image.Height \ 2 + y)
  388.             Case HorizontalAlignment.Right
  389.                 G.DrawImage(_Image, Width - _Image.Width - x, Height \ 2 - _Image.Height \ 2 + y)
  390.             Case HorizontalAlignment.Center
  391.                 G.DrawImage(_Image, Width \ 2 - _Image.Width \ 2, Height \ 2 - _Image.Height \ 2)
  392.         End Select
  393.     End Sub
  394.  
  395.     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)
  396.         _Rectangle = New Rectangle(x, y, width, height)
  397.         _Gradient = New LinearGradientBrush(_Rectangle, c1, c2, angle)
  398.         G.FillRectangle(_Gradient, _Rectangle)
  399.     End Sub
  400. #End Region
  401.  
  402. End Class
  403.  
  404.  
  405. Class BTheme
  406.     Inherits Theme
  407.     Sub New()
  408.         TransparencyKey = Color.Fuchsia()
  409.  
  410.     End Sub
  411.     Public Overrides Sub PaintHook()
  412.         G.Clear(Color.DodgerBlue)
  413.  
  414.         DrawGradient(Color.MidnightBlue, Color.MidnightBlue, 0, 0, Width, 20, 90S)
  415.         G.DrawLine(Pens.White, 0, 20, Width, 20)
  416.         DrawText(HorizontalAlignment.Center, Color.White, 0)
  417.  
  418.  
  419.  
  420.         DrawBorders(Pens.DodgerBlue, Pens.White, ClientRectangle)
  421.         DrawCorners(Color.Fuchsia, ClientRectangle)
  422.  
  423.     End Sub
  424. End Class
  425.  
  426. Class BButton
  427.     Inherits ThemeControl
  428.     Public Overrides Sub PaintHook()
  429.         Select Case MouseState
  430.             Case State.MouseNone
  431.                 G.Clear(Color.MidnightBlue)
  432.             Case State.MouseOver
  433.                 G.Clear(Color.LightBlue)
  434.             Case State.MouseDown
  435.                 G.Clear(Color.DodgerBlue)
  436.         End Select
  437.  
  438.         DrawText(HorizontalAlignment.Center, Color.White, 0)
  439.  
  440.         DrawBorders(Pens.MidnightBlue, Pens.White, ClientRectangle)
  441.         DrawCorners(Color.Fuchsia, ClientRectangle)
  442.     End Sub
  443. End Class
  444.  
  445.  
  446.  
  447. Class BProgressBar
  448.     Inherits ThemeControl
  449.  
  450.     Private _Maximum As Integer = 100
  451.     Public Property Maximum() As Integer
  452.         Get
  453.             Return _Maximum
  454.         End Get
  455.         Set(ByVal value As Integer)
  456.             If value < 1 Then value = 1
  457.             If value < _Value Then _Value = value
  458.             _Maximum = value
  459.             Invalidate()
  460.         End Set
  461.     End Property
  462.  
  463.     Private _Value As Integer = 50
  464.     Public Property Value() As Integer
  465.         Get
  466.             Return _Value
  467.         End Get
  468.         Set(ByVal value As Integer)
  469.             If value > _Maximum Then value = _Maximum
  470.             If value < 1 Then value = 1
  471.             _Value = value
  472.             Invalidate()
  473.         End Set
  474.     End Property
  475.  
  476.     Overrides Sub PaintHook()
  477.  
  478.  
  479.  
  480.         G.Clear(Color.MidnightBlue)
  481.         If (_Value > 0) Then
  482.             DrawGradient(Color.LightBlue, Color.MidnightBlue, 0, 0, CInt((_Value / _Maximum) * Width), Height, 90S)
  483.         End If
  484.         G.DrawRectangle(Pens.White, 0, 0, Width - 1, Height - 1)
  485.         DrawBorders(Pens.MidnightBlue, Pens.White, ClientRectangle)
  486.     End Sub
  487. End Class
Advertisement
Add Comment
Please, Sign In to add comment