Advertisement
Radar

AbyssTheme

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