Advertisement
Guest User

Graywhite Theme - Friendly Ghost/Aeonhack

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