Astekk

C# Theme Base 1.5.4

Dec 3rd, 2014
342
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 63.02 KB | None | 0 0
  1. using System;
  2. using System.Collections.Generic;
  3. using System.IO;
  4. using System.Drawing;
  5. using System.Drawing.Drawing2D;
  6. using System.ComponentModel;
  7. using System.Windows.Forms;
  8. using System.Runtime.InteropServices;
  9. using System.Drawing.Imaging;
  10.  
  11. //------------------
  12. //Creator: aeonhack
  13. //Site: elitevs.net
  14. //Created: 08/02/2011
  15. //Changed: 12/06/2011
  16. //Version: 1.5.4
  17. //------------------
  18.  
  19. abstract class ThemeContainer154 : ContainerControl
  20. {
  21.  
  22. #region " Initialization "
  23.  
  24. protected Graphics G;
  25.  
  26. protected Bitmap B;
  27. public ThemeContainer154()
  28. {
  29. SetStyle((ControlStyles)139270, true);
  30.  
  31. _ImageSize = Size.Empty;
  32. Font = new Font("Verdana", 8);
  33.  
  34. MeasureBitmap = new Bitmap(1, 1);
  35. MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  36.  
  37. DrawRadialPath = new GraphicsPath();
  38.  
  39. InvalidateCustimization();
  40. }
  41.  
  42. protected override sealed void OnHandleCreated(EventArgs e)
  43. {
  44. if (DoneCreation)
  45. InitializeMessages();
  46.  
  47. InvalidateCustimization();
  48. ColorHook();
  49.  
  50. if (!(_LockWidth == 0))
  51. Width = _LockWidth;
  52. if (!(_LockHeight == 0))
  53. Height = _LockHeight;
  54. if (!_ControlMode)
  55. base.Dock = DockStyle.Fill;
  56.  
  57. Transparent = _Transparent;
  58. if (_Transparent && _BackColor)
  59. BackColor = Color.Transparent;
  60.  
  61. base.OnHandleCreated(e);
  62. }
  63.  
  64. private bool DoneCreation;
  65. protected override sealed void OnParentChanged(EventArgs e)
  66. {
  67. base.OnParentChanged(e);
  68.  
  69. if (Parent == null)
  70. return;
  71. _IsParentForm = Parent is Form;
  72.  
  73. if (!_ControlMode)
  74. {
  75. InitializeMessages();
  76.  
  77. if (_IsParentForm)
  78. {
  79. ParentForm.FormBorderStyle = _BorderStyle;
  80. ParentForm.TransparencyKey = _TransparencyKey;
  81.  
  82. if (!DesignMode)
  83. {
  84. ParentForm.Shown += FormShown;
  85. }
  86. }
  87.  
  88. Parent.BackColor = BackColor;
  89. }
  90.  
  91. OnCreation();
  92. DoneCreation = true;
  93. InvalidateTimer();
  94. }
  95.  
  96. #endregion
  97.  
  98. private void DoAnimation(bool i)
  99. {
  100. OnAnimation();
  101. if (i)
  102. Invalidate();
  103. }
  104.  
  105. protected override sealed void OnPaint(PaintEventArgs e)
  106. {
  107. if (Width == 0 || Height == 0)
  108. return;
  109.  
  110. if (_Transparent && _ControlMode)
  111. {
  112. PaintHook();
  113. e.Graphics.DrawImage(B, 0, 0);
  114. }
  115. else
  116. {
  117. G = e.Graphics;
  118. PaintHook();
  119. }
  120. }
  121.  
  122. protected override void OnHandleDestroyed(EventArgs e)
  123. {
  124. ThemeShare.RemoveAnimationCallback(DoAnimation);
  125. base.OnHandleDestroyed(e);
  126. }
  127.  
  128. private bool HasShown;
  129. private void FormShown(object sender, EventArgs e)
  130. {
  131. if (_ControlMode || HasShown)
  132. return;
  133.  
  134. if (_StartPosition == FormStartPosition.CenterParent || _StartPosition == FormStartPosition.CenterScreen)
  135. {
  136. Rectangle SB = Screen.PrimaryScreen.Bounds;
  137. Rectangle CB = ParentForm.Bounds;
  138. ParentForm.Location = new Point(SB.Width / 2 - CB.Width / 2, SB.Height / 2 - CB.Width / 2);
  139. }
  140.  
  141. HasShown = true;
  142. }
  143.  
  144.  
  145. #region " Size Handling "
  146.  
  147. private Rectangle Frame;
  148. protected override sealed void OnSizeChanged(EventArgs e)
  149. {
  150. if (_Movable && !_ControlMode)
  151. {
  152. Frame = new Rectangle(7, 7, Width - 14, _Header - 7);
  153. }
  154.  
  155. InvalidateBitmap();
  156. Invalidate();
  157.  
  158. base.OnSizeChanged(e);
  159. }
  160.  
  161. protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  162. {
  163. if (!(_LockWidth == 0))
  164. width = _LockWidth;
  165. if (!(_LockHeight == 0))
  166. height = _LockHeight;
  167. base.SetBoundsCore(x, y, width, height, specified);
  168. }
  169.  
  170. #endregion
  171.  
  172. #region " State Handling "
  173.  
  174. protected MouseState State;
  175. private void SetState(MouseState current)
  176. {
  177. State = current;
  178. Invalidate();
  179. }
  180.  
  181. protected override void OnMouseMove(MouseEventArgs e)
  182. {
  183. if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized))
  184. {
  185. if (_Sizable && !_ControlMode)
  186. InvalidateMouse();
  187. }
  188.  
  189. base.OnMouseMove(e);
  190. }
  191.  
  192. protected override void OnEnabledChanged(EventArgs e)
  193. {
  194. if (Enabled)
  195. SetState(MouseState.None);
  196. else
  197. SetState(MouseState.Block);
  198. base.OnEnabledChanged(e);
  199. }
  200.  
  201. protected override void OnMouseEnter(EventArgs e)
  202. {
  203. SetState(MouseState.Over);
  204. base.OnMouseEnter(e);
  205. }
  206.  
  207. protected override void OnMouseUp(MouseEventArgs e)
  208. {
  209. SetState(MouseState.Over);
  210. base.OnMouseUp(e);
  211. }
  212.  
  213. protected override void OnMouseLeave(EventArgs e)
  214. {
  215. SetState(MouseState.None);
  216.  
  217. if (GetChildAtPoint(PointToClient(MousePosition)) != null)
  218. {
  219. if (_Sizable && !_ControlMode)
  220. {
  221. Cursor = Cursors.Default;
  222. Previous = 0;
  223. }
  224. }
  225.  
  226. base.OnMouseLeave(e);
  227. }
  228.  
  229. protected override void OnMouseDown(MouseEventArgs e)
  230. {
  231. if (e.Button == System.Windows.Forms.MouseButtons.Left)
  232. SetState(MouseState.Down);
  233.  
  234. if (!(_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized || _ControlMode))
  235. {
  236. if (_Movable && Frame.Contains(e.Location))
  237. {
  238. Capture = false;
  239. WM_LMBUTTONDOWN = true;
  240. DefWndProc(ref Messages[0]);
  241. }
  242. else if (_Sizable && !(Previous == 0))
  243. {
  244. Capture = false;
  245. WM_LMBUTTONDOWN = true;
  246. DefWndProc(ref Messages[Previous]);
  247. }
  248. }
  249.  
  250. base.OnMouseDown(e);
  251. }
  252.  
  253. private bool WM_LMBUTTONDOWN;
  254. protected override void WndProc(ref Message m)
  255. {
  256. base.WndProc(ref m);
  257.  
  258. if (WM_LMBUTTONDOWN && m.Msg == 513)
  259. {
  260. WM_LMBUTTONDOWN = false;
  261.  
  262. SetState(MouseState.Over);
  263. if (!_SmartBounds)
  264. return;
  265.  
  266. if (IsParentMdi)
  267. {
  268. CorrectBounds(new Rectangle(Point.Empty, Parent.Parent.Size));
  269. }
  270. else
  271. {
  272. CorrectBounds(Screen.FromControl(Parent).WorkingArea);
  273. }
  274. }
  275. }
  276.  
  277. private Point GetIndexPoint;
  278. private bool B1;
  279. private bool B2;
  280. private bool B3;
  281. private bool B4;
  282. private int GetIndex()
  283. {
  284. GetIndexPoint = PointToClient(MousePosition);
  285. B1 = GetIndexPoint.X < 7;
  286. B2 = GetIndexPoint.X > Width - 7;
  287. B3 = GetIndexPoint.Y < 7;
  288. B4 = GetIndexPoint.Y > Height - 7;
  289.  
  290. if (B1 && B3)
  291. return 4;
  292. if (B1 && B4)
  293. return 7;
  294. if (B2 && B3)
  295. return 5;
  296. if (B2 && B4)
  297. return 8;
  298. if (B1)
  299. return 1;
  300. if (B2)
  301. return 2;
  302. if (B3)
  303. return 3;
  304. if (B4)
  305. return 6;
  306. return 0;
  307. }
  308.  
  309. private int Current;
  310. private int Previous;
  311. private void InvalidateMouse()
  312. {
  313. Current = GetIndex();
  314. if (Current == Previous)
  315. return;
  316.  
  317. Previous = Current;
  318. switch (Previous)
  319. {
  320. case 0:
  321. Cursor = Cursors.Default;
  322. break;
  323. case 1:
  324. case 2:
  325. Cursor = Cursors.SizeWE;
  326. break;
  327. case 3:
  328. case 6:
  329. Cursor = Cursors.SizeNS;
  330. break;
  331. case 4:
  332. case 8:
  333. Cursor = Cursors.SizeNWSE;
  334. break;
  335. case 5:
  336. case 7:
  337. Cursor = Cursors.SizeNESW;
  338. break;
  339. }
  340. }
  341.  
  342. private Message[] Messages = new Message[9];
  343. private void InitializeMessages()
  344. {
  345. Messages[0] = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero);
  346. for (int I = 1; I <= 8; I++)
  347. {
  348. Messages[I] = Message.Create(Parent.Handle, 161, new IntPtr(I + 9), IntPtr.Zero);
  349. }
  350. }
  351.  
  352. private void CorrectBounds(Rectangle bounds)
  353. {
  354. if (Parent.Width > bounds.Width)
  355. Parent.Width = bounds.Width;
  356. if (Parent.Height > bounds.Height)
  357. Parent.Height = bounds.Height;
  358.  
  359. int X = Parent.Location.X;
  360. int Y = Parent.Location.Y;
  361.  
  362. if (X < bounds.X)
  363. X = bounds.X;
  364. if (Y < bounds.Y)
  365. Y = bounds.Y;
  366.  
  367. int Width = bounds.X + bounds.Width;
  368. int Height = bounds.Y + bounds.Height;
  369.  
  370. if (X + Parent.Width > Width)
  371. X = Width - Parent.Width;
  372. if (Y + Parent.Height > Height)
  373. Y = Height - Parent.Height;
  374.  
  375. Parent.Location = new Point(X, Y);
  376. }
  377.  
  378. #endregion
  379.  
  380.  
  381. #region " Base Properties "
  382.  
  383. public override DockStyle Dock
  384. {
  385. get { return base.Dock; }
  386. set
  387. {
  388. if (!_ControlMode)
  389. return;
  390. base.Dock = value;
  391. }
  392. }
  393.  
  394. private bool _BackColor;
  395. [Category("Misc")]
  396. public override Color BackColor
  397. {
  398. get { return base.BackColor; }
  399. set
  400. {
  401. if (value == base.BackColor)
  402. return;
  403.  
  404. if (!IsHandleCreated && _ControlMode && value == Color.Transparent)
  405. {
  406. _BackColor = true;
  407. return;
  408. }
  409.  
  410. base.BackColor = value;
  411. if (Parent != null)
  412. {
  413. if (!_ControlMode)
  414. Parent.BackColor = value;
  415. ColorHook();
  416. }
  417. }
  418. }
  419.  
  420. public override Size MinimumSize
  421. {
  422. get { return base.MinimumSize; }
  423. set
  424. {
  425. base.MinimumSize = value;
  426. if (Parent != null)
  427. Parent.MinimumSize = value;
  428. }
  429. }
  430.  
  431. public override Size MaximumSize
  432. {
  433. get { return base.MaximumSize; }
  434. set
  435. {
  436. base.MaximumSize = value;
  437. if (Parent != null)
  438. Parent.MaximumSize = value;
  439. }
  440. }
  441.  
  442. public override string Text
  443. {
  444. get { return base.Text; }
  445. set
  446. {
  447. base.Text = value;
  448. Invalidate();
  449. }
  450. }
  451.  
  452. public override Font Font
  453. {
  454. get { return base.Font; }
  455. set
  456. {
  457. base.Font = value;
  458. Invalidate();
  459. }
  460. }
  461.  
  462. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  463. public override Color ForeColor
  464. {
  465. get { return Color.Empty; }
  466. set { }
  467. }
  468. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  469. public override Image BackgroundImage
  470. {
  471. get { return null; }
  472. set { }
  473. }
  474. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  475. public override ImageLayout BackgroundImageLayout
  476. {
  477. get { return ImageLayout.None; }
  478. set { }
  479. }
  480.  
  481. #endregion
  482.  
  483. #region " Public Properties "
  484.  
  485. private bool _SmartBounds = true;
  486. public bool SmartBounds
  487. {
  488. get { return _SmartBounds; }
  489. set { _SmartBounds = value; }
  490. }
  491.  
  492. private bool _Movable = true;
  493. public bool Movable
  494. {
  495. get { return _Movable; }
  496. set { _Movable = value; }
  497. }
  498.  
  499. private bool _Sizable = true;
  500. public bool Sizable
  501. {
  502. get { return _Sizable; }
  503. set { _Sizable = value; }
  504. }
  505.  
  506. private Color _TransparencyKey;
  507. public Color TransparencyKey
  508. {
  509. get
  510. {
  511. if (_IsParentForm && !_ControlMode)
  512. return ParentForm.TransparencyKey;
  513. else
  514. return _TransparencyKey;
  515. }
  516. set
  517. {
  518. if (value == _TransparencyKey)
  519. return;
  520. _TransparencyKey = value;
  521.  
  522. if (_IsParentForm && !_ControlMode)
  523. {
  524. ParentForm.TransparencyKey = value;
  525. ColorHook();
  526. }
  527. }
  528. }
  529.  
  530. private FormBorderStyle _BorderStyle;
  531. public FormBorderStyle BorderStyle
  532. {
  533. get
  534. {
  535. if (_IsParentForm && !_ControlMode)
  536. return ParentForm.FormBorderStyle;
  537. else
  538. return _BorderStyle;
  539. }
  540. set
  541. {
  542. _BorderStyle = value;
  543.  
  544. if (_IsParentForm && !_ControlMode)
  545. {
  546. ParentForm.FormBorderStyle = value;
  547.  
  548. if (!(value == FormBorderStyle.None))
  549. {
  550. Movable = false;
  551. Sizable = false;
  552. }
  553. }
  554. }
  555. }
  556.  
  557. private FormStartPosition _StartPosition;
  558. public FormStartPosition StartPosition
  559. {
  560. get
  561. {
  562. if (_IsParentForm && !_ControlMode)
  563. return ParentForm.StartPosition;
  564. else
  565. return _StartPosition;
  566. }
  567. set
  568. {
  569. _StartPosition = value;
  570.  
  571. if (_IsParentForm && !_ControlMode)
  572. {
  573. ParentForm.StartPosition = value;
  574. }
  575. }
  576. }
  577.  
  578. private bool _NoRounding;
  579. public bool NoRounding
  580. {
  581. get { return _NoRounding; }
  582. set
  583. {
  584. _NoRounding = value;
  585. Invalidate();
  586. }
  587. }
  588.  
  589. private Image _Image;
  590. public Image Image
  591. {
  592. get { return _Image; }
  593. set
  594. {
  595. if (value == null)
  596. _ImageSize = Size.Empty;
  597. else
  598. _ImageSize = value.Size;
  599.  
  600. _Image = value;
  601. Invalidate();
  602. }
  603. }
  604.  
  605. private Dictionary<string, Color> Items = new Dictionary<string, Color>();
  606. public Bloom[] Colors
  607. {
  608. get
  609. {
  610. List<Bloom> T = new List<Bloom>();
  611. Dictionary<string, Color>.Enumerator E = Items.GetEnumerator();
  612.  
  613. while (E.MoveNext())
  614. {
  615. T.Add(new Bloom(E.Current.Key, E.Current.Value));
  616. }
  617.  
  618. return T.ToArray();
  619. }
  620. set
  621. {
  622. foreach (Bloom B in value)
  623. {
  624. if (Items.ContainsKey(B.Name))
  625. Items[B.Name] = B.Value;
  626. }
  627.  
  628. InvalidateCustimization();
  629. ColorHook();
  630. Invalidate();
  631. }
  632. }
  633.  
  634. private string _Customization;
  635. public string Customization
  636. {
  637. get { return _Customization; }
  638. set
  639. {
  640. if (value == _Customization)
  641. return;
  642.  
  643. byte[] Data = null;
  644. Bloom[] Items = Colors;
  645.  
  646. try
  647. {
  648. Data = Convert.FromBase64String(value);
  649. for (int I = 0; I <= Items.Length - 1; I++)
  650. {
  651. Items[I].Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
  652. }
  653. }
  654. catch
  655. {
  656. return;
  657. }
  658.  
  659. _Customization = value;
  660.  
  661. Colors = Items;
  662. ColorHook();
  663. Invalidate();
  664. }
  665. }
  666.  
  667. private bool _Transparent;
  668. public bool Transparent
  669. {
  670. get { return _Transparent; }
  671. set
  672. {
  673. _Transparent = value;
  674. if (!(IsHandleCreated || _ControlMode))
  675. return;
  676.  
  677. if (!value && !(BackColor.A == 255))
  678. {
  679. throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
  680. }
  681.  
  682. SetStyle(ControlStyles.Opaque, !value);
  683. SetStyle(ControlStyles.SupportsTransparentBackColor, value);
  684.  
  685. InvalidateBitmap();
  686. Invalidate();
  687. }
  688. }
  689.  
  690. #endregion
  691.  
  692. #region " Private Properties "
  693.  
  694. private Size _ImageSize;
  695. protected Size ImageSize
  696. {
  697. get { return _ImageSize; }
  698. }
  699.  
  700. private bool _IsParentForm;
  701. protected bool IsParentForm
  702. {
  703. get { return _IsParentForm; }
  704. }
  705.  
  706. protected bool IsParentMdi
  707. {
  708. get
  709. {
  710. if (Parent == null)
  711. return false;
  712. return Parent.Parent != null;
  713. }
  714. }
  715.  
  716. private int _LockWidth;
  717. protected int LockWidth
  718. {
  719. get { return _LockWidth; }
  720. set
  721. {
  722. _LockWidth = value;
  723. if (!(LockWidth == 0) && IsHandleCreated)
  724. Width = LockWidth;
  725. }
  726. }
  727.  
  728. private int _LockHeight;
  729. protected int LockHeight
  730. {
  731. get { return _LockHeight; }
  732. set
  733. {
  734. _LockHeight = value;
  735. if (!(LockHeight == 0) && IsHandleCreated)
  736. Height = LockHeight;
  737. }
  738. }
  739.  
  740. private int _Header = 24;
  741. protected int Header
  742. {
  743. get { return _Header; }
  744. set
  745. {
  746. _Header = value;
  747.  
  748. if (!_ControlMode)
  749. {
  750. Frame = new Rectangle(7, 7, Width - 14, value - 7);
  751. Invalidate();
  752. }
  753. }
  754. }
  755.  
  756. private bool _ControlMode;
  757. protected bool ControlMode
  758. {
  759. get { return _ControlMode; }
  760. set
  761. {
  762. _ControlMode = value;
  763.  
  764. Transparent = _Transparent;
  765. if (_Transparent && _BackColor)
  766. BackColor = Color.Transparent;
  767.  
  768. InvalidateBitmap();
  769. Invalidate();
  770. }
  771. }
  772.  
  773. private bool _IsAnimated;
  774. protected bool IsAnimated
  775. {
  776. get { return _IsAnimated; }
  777. set
  778. {
  779. _IsAnimated = value;
  780. InvalidateTimer();
  781. }
  782. }
  783.  
  784. #endregion
  785.  
  786.  
  787. #region " Property Helpers "
  788.  
  789. protected Pen GetPen(string name)
  790. {
  791. return new Pen(Items[name]);
  792. }
  793. protected Pen GetPen(string name, float width)
  794. {
  795. return new Pen(Items[name], width);
  796. }
  797.  
  798. protected SolidBrush GetBrush(string name)
  799. {
  800. return new SolidBrush(Items[name]);
  801. }
  802.  
  803. protected Color GetColor(string name)
  804. {
  805. return Items[name];
  806. }
  807.  
  808. protected void SetColor(string name, Color value)
  809. {
  810. if (Items.ContainsKey(name))
  811. Items[name] = value;
  812. else
  813. Items.Add(name, value);
  814. }
  815. protected void SetColor(string name, byte r, byte g, byte b)
  816. {
  817. SetColor(name, Color.FromArgb(r, g, b));
  818. }
  819. protected void SetColor(string name, byte a, byte r, byte g, byte b)
  820. {
  821. SetColor(name, Color.FromArgb(a, r, g, b));
  822. }
  823. protected void SetColor(string name, byte a, Color value)
  824. {
  825. SetColor(name, Color.FromArgb(a, value));
  826. }
  827.  
  828. private void InvalidateBitmap()
  829. {
  830. if (_Transparent && _ControlMode)
  831. {
  832. if (Width == 0 || Height == 0)
  833. return;
  834. B = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
  835. G = Graphics.FromImage(B);
  836. }
  837. else
  838. {
  839. G = null;
  840. B = null;
  841. }
  842. }
  843.  
  844. private void InvalidateCustimization()
  845. {
  846. MemoryStream M = new MemoryStream(Items.Count * 4);
  847.  
  848. foreach (Bloom B in Colors)
  849. {
  850. M.Write(BitConverter.GetBytes(B.Value.ToArgb()), 0, 4);
  851. }
  852.  
  853. M.Close();
  854. _Customization = Convert.ToBase64String(M.ToArray());
  855. }
  856.  
  857. private void InvalidateTimer()
  858. {
  859. if (DesignMode || !DoneCreation)
  860. return;
  861.  
  862. if (_IsAnimated)
  863. {
  864. ThemeShare.AddAnimationCallback(DoAnimation);
  865. }
  866. else
  867. {
  868. ThemeShare.RemoveAnimationCallback(DoAnimation);
  869. }
  870. }
  871.  
  872. #endregion
  873.  
  874.  
  875. #region " User Hooks "
  876.  
  877. protected abstract void ColorHook();
  878. protected abstract void PaintHook();
  879.  
  880. protected virtual void OnCreation()
  881. {
  882. }
  883.  
  884. protected virtual void OnAnimation()
  885. {
  886. }
  887.  
  888. #endregion
  889.  
  890.  
  891. #region " Offset "
  892.  
  893. private Rectangle OffsetReturnRectangle;
  894. protected Rectangle Offset(Rectangle r, int amount)
  895. {
  896. OffsetReturnRectangle = new Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2));
  897. return OffsetReturnRectangle;
  898. }
  899.  
  900. private Size OffsetReturnSize;
  901. protected Size Offset(Size s, int amount)
  902. {
  903. OffsetReturnSize = new Size(s.Width + amount, s.Height + amount);
  904. return OffsetReturnSize;
  905. }
  906.  
  907. private Point OffsetReturnPoint;
  908. protected Point Offset(Point p, int amount)
  909. {
  910. OffsetReturnPoint = new Point(p.X + amount, p.Y + amount);
  911. return OffsetReturnPoint;
  912. }
  913.  
  914. #endregion
  915.  
  916. #region " Center "
  917.  
  918.  
  919. private Point CenterReturn;
  920. protected Point Center(Rectangle p, Rectangle c)
  921. {
  922. CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X + c.X, (p.Height / 2 - c.Height / 2) + p.Y + c.Y);
  923. return CenterReturn;
  924. }
  925. protected Point Center(Rectangle p, Size c)
  926. {
  927. CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X, (p.Height / 2 - c.Height / 2) + p.Y);
  928. return CenterReturn;
  929. }
  930.  
  931. protected Point Center(Rectangle child)
  932. {
  933. return Center(Width, Height, child.Width, child.Height);
  934. }
  935. protected Point Center(Size child)
  936. {
  937. return Center(Width, Height, child.Width, child.Height);
  938. }
  939. protected Point Center(int childWidth, int childHeight)
  940. {
  941. return Center(Width, Height, childWidth, childHeight);
  942. }
  943.  
  944. protected Point Center(Size p, Size c)
  945. {
  946. return Center(p.Width, p.Height, c.Width, c.Height);
  947. }
  948.  
  949. protected Point Center(int pWidth, int pHeight, int cWidth, int cHeight)
  950. {
  951. CenterReturn = new Point(pWidth / 2 - cWidth / 2, pHeight / 2 - cHeight / 2);
  952. return CenterReturn;
  953. }
  954.  
  955. #endregion
  956.  
  957. #region " Measure "
  958.  
  959. private Bitmap MeasureBitmap;
  960.  
  961. private Graphics MeasureGraphics;
  962. protected Size Measure()
  963. {
  964. lock (MeasureGraphics)
  965. {
  966. return MeasureGraphics.MeasureString(Text, Font, Width).ToSize();
  967. }
  968. }
  969. protected Size Measure(string text)
  970. {
  971. lock (MeasureGraphics)
  972. {
  973. return MeasureGraphics.MeasureString(text, Font, Width).ToSize();
  974. }
  975. }
  976.  
  977. #endregion
  978.  
  979.  
  980. #region " DrawPixel "
  981.  
  982.  
  983. private SolidBrush DrawPixelBrush;
  984. protected void DrawPixel(Color c1, int x, int y)
  985. {
  986. if (_Transparent)
  987. {
  988. B.SetPixel(x, y, c1);
  989. }
  990. else
  991. {
  992. DrawPixelBrush = new SolidBrush(c1);
  993. G.FillRectangle(DrawPixelBrush, x, y, 1, 1);
  994. }
  995. }
  996.  
  997. #endregion
  998.  
  999. #region " DrawCorners "
  1000.  
  1001.  
  1002. private SolidBrush DrawCornersBrush;
  1003. protected void DrawCorners(Color c1, int offset)
  1004. {
  1005. DrawCorners(c1, 0, 0, Width, Height, offset);
  1006. }
  1007. protected void DrawCorners(Color c1, Rectangle r1, int offset)
  1008. {
  1009. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset);
  1010. }
  1011. protected void DrawCorners(Color c1, int x, int y, int width, int height, int offset)
  1012. {
  1013. DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  1014. }
  1015.  
  1016. protected void DrawCorners(Color c1)
  1017. {
  1018. DrawCorners(c1, 0, 0, Width, Height);
  1019. }
  1020. protected void DrawCorners(Color c1, Rectangle r1)
  1021. {
  1022. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
  1023. }
  1024. protected void DrawCorners(Color c1, int x, int y, int width, int height)
  1025. {
  1026. if (_NoRounding)
  1027. return;
  1028.  
  1029. if (_Transparent)
  1030. {
  1031. B.SetPixel(x, y, c1);
  1032. B.SetPixel(x + (width - 1), y, c1);
  1033. B.SetPixel(x, y + (height - 1), c1);
  1034. B.SetPixel(x + (width - 1), y + (height - 1), c1);
  1035. }
  1036. else
  1037. {
  1038. DrawCornersBrush = new SolidBrush(c1);
  1039. G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
  1040. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
  1041. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
  1042. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
  1043. }
  1044. }
  1045.  
  1046. #endregion
  1047.  
  1048. #region " DrawBorders "
  1049.  
  1050. protected void DrawBorders(Pen p1, int offset)
  1051. {
  1052. DrawBorders(p1, 0, 0, Width, Height, offset);
  1053. }
  1054. protected void DrawBorders(Pen p1, Rectangle r, int offset)
  1055. {
  1056. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
  1057. }
  1058. protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
  1059. {
  1060. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  1061. }
  1062.  
  1063. protected void DrawBorders(Pen p1)
  1064. {
  1065. DrawBorders(p1, 0, 0, Width, Height);
  1066. }
  1067. protected void DrawBorders(Pen p1, Rectangle r)
  1068. {
  1069. DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
  1070. }
  1071. protected void DrawBorders(Pen p1, int x, int y, int width, int height)
  1072. {
  1073. G.DrawRectangle(p1, x, y, width - 1, height - 1);
  1074. }
  1075.  
  1076. #endregion
  1077.  
  1078. #region " DrawText "
  1079.  
  1080. private Point DrawTextPoint;
  1081.  
  1082. private Size DrawTextSize;
  1083. protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
  1084. {
  1085. DrawText(b1, Text, a, x, y);
  1086. }
  1087. protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
  1088. {
  1089. if (text.Length == 0)
  1090. return;
  1091.  
  1092. DrawTextSize = Measure(text);
  1093. DrawTextPoint = new Point(Width / 2 - DrawTextSize.Width / 2, Header / 2 - DrawTextSize.Height / 2);
  1094.  
  1095. switch (a)
  1096. {
  1097. case HorizontalAlignment.Left:
  1098. G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y);
  1099. break;
  1100. case HorizontalAlignment.Center:
  1101. G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y);
  1102. break;
  1103. case HorizontalAlignment.Right:
  1104. G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
  1105. break;
  1106. }
  1107. }
  1108.  
  1109. protected void DrawText(Brush b1, Point p1)
  1110. {
  1111. if (Text.Length == 0)
  1112. return;
  1113. G.DrawString(Text, Font, b1, p1);
  1114. }
  1115. protected void DrawText(Brush b1, int x, int y)
  1116. {
  1117. if (Text.Length == 0)
  1118. return;
  1119. G.DrawString(Text, Font, b1, x, y);
  1120. }
  1121.  
  1122. #endregion
  1123.  
  1124. #region " DrawImage "
  1125.  
  1126.  
  1127. private Point DrawImagePoint;
  1128. protected void DrawImage(HorizontalAlignment a, int x, int y)
  1129. {
  1130. DrawImage(_Image, a, x, y);
  1131. }
  1132. protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
  1133. {
  1134. if (image == null)
  1135. return;
  1136. DrawImagePoint = new Point(Width / 2 - image.Width / 2, Header / 2 - image.Height / 2);
  1137.  
  1138. switch (a)
  1139. {
  1140. case HorizontalAlignment.Left:
  1141. G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height);
  1142. break;
  1143. case HorizontalAlignment.Center:
  1144. G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height);
  1145. break;
  1146. case HorizontalAlignment.Right:
  1147. G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height);
  1148. break;
  1149. }
  1150. }
  1151.  
  1152. protected void DrawImage(Point p1)
  1153. {
  1154. DrawImage(_Image, p1.X, p1.Y);
  1155. }
  1156. protected void DrawImage(int x, int y)
  1157. {
  1158. DrawImage(_Image, x, y);
  1159. }
  1160.  
  1161. protected void DrawImage(Image image, Point p1)
  1162. {
  1163. DrawImage(image, p1.X, p1.Y);
  1164. }
  1165. protected void DrawImage(Image image, int x, int y)
  1166. {
  1167. if (image == null)
  1168. return;
  1169. G.DrawImage(image, x, y, image.Width, image.Height);
  1170. }
  1171.  
  1172. #endregion
  1173.  
  1174. #region " DrawGradient "
  1175.  
  1176. private LinearGradientBrush DrawGradientBrush;
  1177.  
  1178. private Rectangle DrawGradientRectangle;
  1179. protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
  1180. {
  1181. DrawGradientRectangle = new Rectangle(x, y, width, height);
  1182. DrawGradient(blend, DrawGradientRectangle);
  1183. }
  1184. protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
  1185. {
  1186. DrawGradientRectangle = new Rectangle(x, y, width, height);
  1187. DrawGradient(blend, DrawGradientRectangle, angle);
  1188. }
  1189.  
  1190. protected void DrawGradient(ColorBlend blend, Rectangle r)
  1191. {
  1192. DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, 90f);
  1193. DrawGradientBrush.InterpolationColors = blend;
  1194. G.FillRectangle(DrawGradientBrush, r);
  1195. }
  1196. protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
  1197. {
  1198. DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
  1199. DrawGradientBrush.InterpolationColors = blend;
  1200. G.FillRectangle(DrawGradientBrush, r);
  1201. }
  1202.  
  1203.  
  1204. protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
  1205. {
  1206. DrawGradientRectangle = new Rectangle(x, y, width, height);
  1207. DrawGradient(c1, c2, DrawGradientRectangle);
  1208. }
  1209. protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
  1210. {
  1211. DrawGradientRectangle = new Rectangle(x, y, width, height);
  1212. DrawGradient(c1, c2, DrawGradientRectangle, angle);
  1213. }
  1214.  
  1215. protected void DrawGradient(Color c1, Color c2, Rectangle r)
  1216. {
  1217. DrawGradientBrush = new LinearGradientBrush(r, c1, c2, 90f);
  1218. G.FillRectangle(DrawGradientBrush, r);
  1219. }
  1220. protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
  1221. {
  1222. DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
  1223. G.FillRectangle(DrawGradientBrush, r);
  1224. }
  1225.  
  1226. #endregion
  1227.  
  1228. #region " DrawRadial "
  1229.  
  1230. private GraphicsPath DrawRadialPath;
  1231. private PathGradientBrush DrawRadialBrush1;
  1232. private LinearGradientBrush DrawRadialBrush2;
  1233.  
  1234. private Rectangle DrawRadialRectangle;
  1235. public void DrawRadial(ColorBlend blend, int x, int y, int width, int height)
  1236. {
  1237. DrawRadialRectangle = new Rectangle(x, y, width, height);
  1238. DrawRadial(blend, DrawRadialRectangle, width / 2, height / 2);
  1239. }
  1240. public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, Point center)
  1241. {
  1242. DrawRadialRectangle = new Rectangle(x, y, width, height);
  1243. DrawRadial(blend, DrawRadialRectangle, center.X, center.Y);
  1244. }
  1245. public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, int cx, int cy)
  1246. {
  1247. DrawRadialRectangle = new Rectangle(x, y, width, height);
  1248. DrawRadial(blend, DrawRadialRectangle, cx, cy);
  1249. }
  1250.  
  1251. public void DrawRadial(ColorBlend blend, Rectangle r)
  1252. {
  1253. DrawRadial(blend, r, r.Width / 2, r.Height / 2);
  1254. }
  1255. public void DrawRadial(ColorBlend blend, Rectangle r, Point center)
  1256. {
  1257. DrawRadial(blend, r, center.X, center.Y);
  1258. }
  1259. public void DrawRadial(ColorBlend blend, Rectangle r, int cx, int cy)
  1260. {
  1261. DrawRadialPath.Reset();
  1262. DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1);
  1263.  
  1264. DrawRadialBrush1 = new PathGradientBrush(DrawRadialPath);
  1265. DrawRadialBrush1.CenterPoint = new Point(r.X + cx, r.Y + cy);
  1266. DrawRadialBrush1.InterpolationColors = blend;
  1267.  
  1268. if (G.SmoothingMode == SmoothingMode.AntiAlias)
  1269. {
  1270. G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3);
  1271. }
  1272. else
  1273. {
  1274. G.FillEllipse(DrawRadialBrush1, r);
  1275. }
  1276. }
  1277.  
  1278.  
  1279. protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height)
  1280. {
  1281. DrawRadialRectangle = new Rectangle(x, y, width, height);
  1282. DrawRadial(c1, c2, DrawGradientRectangle);
  1283. }
  1284. protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height, float angle)
  1285. {
  1286. DrawRadialRectangle = new Rectangle(x, y, width, height);
  1287. DrawRadial(c1, c2, DrawGradientRectangle, angle);
  1288. }
  1289.  
  1290. protected void DrawRadial(Color c1, Color c2, Rectangle r)
  1291. {
  1292. DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, 90f);
  1293. G.FillRectangle(DrawGradientBrush, r);
  1294. }
  1295. protected void DrawRadial(Color c1, Color c2, Rectangle r, float angle)
  1296. {
  1297. DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, angle);
  1298. G.FillEllipse(DrawGradientBrush, r);
  1299. }
  1300.  
  1301. #endregion
  1302.  
  1303. #region " CreateRound "
  1304.  
  1305. private GraphicsPath CreateRoundPath;
  1306.  
  1307. private Rectangle CreateRoundRectangle;
  1308. public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
  1309. {
  1310. CreateRoundRectangle = new Rectangle(x, y, width, height);
  1311. return CreateRound(CreateRoundRectangle, slope);
  1312. }
  1313.  
  1314. public GraphicsPath CreateRound(Rectangle r, int slope)
  1315. {
  1316. CreateRoundPath = new GraphicsPath(FillMode.Winding);
  1317. CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
  1318. CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
  1319. CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
  1320. CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
  1321. CreateRoundPath.CloseFigure();
  1322. return CreateRoundPath;
  1323. }
  1324.  
  1325. #endregion
  1326.  
  1327. }
  1328.  
  1329. abstract class ThemeControl154 : Control
  1330. {
  1331.  
  1332.  
  1333. #region " Initialization "
  1334.  
  1335. protected Graphics G;
  1336.  
  1337. protected Bitmap B;
  1338. public ThemeControl154()
  1339. {
  1340. SetStyle((ControlStyles)139270, true);
  1341.  
  1342. _ImageSize = Size.Empty;
  1343. Font = new Font("Verdana", 8);
  1344.  
  1345. MeasureBitmap = new Bitmap(1, 1);
  1346. MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  1347.  
  1348. DrawRadialPath = new GraphicsPath();
  1349.  
  1350. InvalidateCustimization();
  1351. //Remove?
  1352. }
  1353.  
  1354. protected override sealed void OnHandleCreated(EventArgs e)
  1355. {
  1356. InvalidateCustimization();
  1357. ColorHook();
  1358.  
  1359. if (!(_LockWidth == 0))
  1360. Width = _LockWidth;
  1361. if (!(_LockHeight == 0))
  1362. Height = _LockHeight;
  1363.  
  1364. Transparent = _Transparent;
  1365. if (_Transparent && _BackColor)
  1366. BackColor = Color.Transparent;
  1367.  
  1368. base.OnHandleCreated(e);
  1369. }
  1370.  
  1371. private bool DoneCreation;
  1372. protected override sealed void OnParentChanged(EventArgs e)
  1373. {
  1374. if (Parent != null)
  1375. {
  1376. OnCreation();
  1377. DoneCreation = true;
  1378. InvalidateTimer();
  1379. }
  1380.  
  1381. base.OnParentChanged(e);
  1382. }
  1383.  
  1384. #endregion
  1385.  
  1386. private void DoAnimation(bool i)
  1387. {
  1388. OnAnimation();
  1389. if (i)
  1390. Invalidate();
  1391. }
  1392.  
  1393. protected override sealed void OnPaint(PaintEventArgs e)
  1394. {
  1395. if (Width == 0 || Height == 0)
  1396. return;
  1397.  
  1398. if (_Transparent)
  1399. {
  1400. PaintHook();
  1401. e.Graphics.DrawImage(B, 0, 0);
  1402. }
  1403. else
  1404. {
  1405. G = e.Graphics;
  1406. PaintHook();
  1407. }
  1408. }
  1409.  
  1410. protected override void OnHandleDestroyed(EventArgs e)
  1411. {
  1412. ThemeShare.RemoveAnimationCallback(DoAnimation);
  1413. base.OnHandleDestroyed(e);
  1414. }
  1415.  
  1416. #region " Size Handling "
  1417.  
  1418. protected override sealed void OnSizeChanged(EventArgs e)
  1419. {
  1420. if (_Transparent)
  1421. {
  1422. InvalidateBitmap();
  1423. }
  1424.  
  1425. Invalidate();
  1426. base.OnSizeChanged(e);
  1427. }
  1428.  
  1429. protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  1430. {
  1431. if (!(_LockWidth == 0))
  1432. width = _LockWidth;
  1433. if (!(_LockHeight == 0))
  1434. height = _LockHeight;
  1435. base.SetBoundsCore(x, y, width, height, specified);
  1436. }
  1437.  
  1438. #endregion
  1439.  
  1440. #region " State Handling "
  1441.  
  1442. private bool InPosition;
  1443. protected override void OnMouseEnter(EventArgs e)
  1444. {
  1445. InPosition = true;
  1446. SetState(MouseState.Over);
  1447. base.OnMouseEnter(e);
  1448. }
  1449.  
  1450. protected override void OnMouseUp(MouseEventArgs e)
  1451. {
  1452. if (InPosition)
  1453. SetState(MouseState.Over);
  1454. base.OnMouseUp(e);
  1455. }
  1456.  
  1457. protected override void OnMouseDown(MouseEventArgs e)
  1458. {
  1459. if (e.Button == System.Windows.Forms.MouseButtons.Left)
  1460. SetState(MouseState.Down);
  1461. base.OnMouseDown(e);
  1462. }
  1463.  
  1464. protected override void OnMouseLeave(EventArgs e)
  1465. {
  1466. InPosition = false;
  1467. SetState(MouseState.None);
  1468. base.OnMouseLeave(e);
  1469. }
  1470.  
  1471. protected override void OnEnabledChanged(EventArgs e)
  1472. {
  1473. if (Enabled)
  1474. SetState(MouseState.None);
  1475. else
  1476. SetState(MouseState.Block);
  1477. base.OnEnabledChanged(e);
  1478. }
  1479.  
  1480. protected MouseState State;
  1481. private void SetState(MouseState current)
  1482. {
  1483. State = current;
  1484. Invalidate();
  1485. }
  1486.  
  1487. #endregion
  1488.  
  1489.  
  1490. #region " Base Properties "
  1491.  
  1492. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1493. public override Color ForeColor
  1494. {
  1495. get { return Color.Empty; }
  1496. set { }
  1497. }
  1498. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1499. public override Image BackgroundImage
  1500. {
  1501. get { return null; }
  1502. set { }
  1503. }
  1504. [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  1505. public override ImageLayout BackgroundImageLayout
  1506. {
  1507. get { return ImageLayout.None; }
  1508. set { }
  1509. }
  1510.  
  1511. public override string Text
  1512. {
  1513. get { return base.Text; }
  1514. set
  1515. {
  1516. base.Text = value;
  1517. Invalidate();
  1518. }
  1519. }
  1520. public override Font Font
  1521. {
  1522. get { return base.Font; }
  1523. set
  1524. {
  1525. base.Font = value;
  1526. Invalidate();
  1527. }
  1528. }
  1529.  
  1530. private bool _BackColor;
  1531. [Category("Misc")]
  1532. public override Color BackColor
  1533. {
  1534. get { return base.BackColor; }
  1535. set
  1536. {
  1537. if (!IsHandleCreated && value == Color.Transparent)
  1538. {
  1539. _BackColor = true;
  1540. return;
  1541. }
  1542.  
  1543. base.BackColor = value;
  1544. if (Parent != null)
  1545. ColorHook();
  1546. }
  1547. }
  1548.  
  1549. #endregion
  1550.  
  1551. #region " Public Properties "
  1552.  
  1553. private bool _NoRounding;
  1554. public bool NoRounding
  1555. {
  1556. get { return _NoRounding; }
  1557. set
  1558. {
  1559. _NoRounding = value;
  1560. Invalidate();
  1561. }
  1562. }
  1563.  
  1564. private Image _Image;
  1565. public Image Image
  1566. {
  1567. get { return _Image; }
  1568. set
  1569. {
  1570. if (value == null)
  1571. {
  1572. _ImageSize = Size.Empty;
  1573. }
  1574. else
  1575. {
  1576. _ImageSize = value.Size;
  1577. }
  1578.  
  1579. _Image = value;
  1580. Invalidate();
  1581. }
  1582. }
  1583.  
  1584. private bool _Transparent;
  1585. public bool Transparent
  1586. {
  1587. get { return _Transparent; }
  1588. set
  1589. {
  1590. _Transparent = value;
  1591. if (!IsHandleCreated)
  1592. return;
  1593.  
  1594. if (!value && !(BackColor.A == 255))
  1595. {
  1596. throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
  1597. }
  1598.  
  1599. SetStyle(ControlStyles.Opaque, !value);
  1600. SetStyle(ControlStyles.SupportsTransparentBackColor, value);
  1601.  
  1602. if (value)
  1603. InvalidateBitmap();
  1604. else
  1605. B = null;
  1606. Invalidate();
  1607. }
  1608. }
  1609.  
  1610. private Dictionary<string, Color> Items = new Dictionary<string, Color>();
  1611. public Bloom[] Colors
  1612. {
  1613. get
  1614. {
  1615. List<Bloom> T = new List<Bloom>();
  1616. Dictionary<string, Color>.Enumerator E = Items.GetEnumerator();
  1617.  
  1618. while (E.MoveNext())
  1619. {
  1620. T.Add(new Bloom(E.Current.Key, E.Current.Value));
  1621. }
  1622.  
  1623. return T.ToArray();
  1624. }
  1625. set
  1626. {
  1627. foreach (Bloom B in value)
  1628. {
  1629. if (Items.ContainsKey(B.Name))
  1630. Items[B.Name] = B.Value;
  1631. }
  1632.  
  1633. InvalidateCustimization();
  1634. ColorHook();
  1635. Invalidate();
  1636. }
  1637. }
  1638.  
  1639. private string _Customization;
  1640. public string Customization
  1641. {
  1642. get { return _Customization; }
  1643. set
  1644. {
  1645. if (value == _Customization)
  1646. return;
  1647.  
  1648. byte[] Data = null;
  1649. Bloom[] Items = Colors;
  1650.  
  1651. try
  1652. {
  1653. Data = Convert.FromBase64String(value);
  1654. for (int I = 0; I <= Items.Length - 1; I++)
  1655. {
  1656. Items[I].Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
  1657. }
  1658. }
  1659. catch
  1660. {
  1661. return;
  1662. }
  1663.  
  1664. _Customization = value;
  1665.  
  1666. Colors = Items;
  1667. ColorHook();
  1668. Invalidate();
  1669. }
  1670. }
  1671.  
  1672. #endregion
  1673.  
  1674. #region " Private Properties "
  1675.  
  1676. private Size _ImageSize;
  1677. protected Size ImageSize
  1678. {
  1679. get { return _ImageSize; }
  1680. }
  1681.  
  1682. private int _LockWidth;
  1683. protected int LockWidth
  1684. {
  1685. get { return _LockWidth; }
  1686. set
  1687. {
  1688. _LockWidth = value;
  1689. if (!(LockWidth == 0) && IsHandleCreated)
  1690. Width = LockWidth;
  1691. }
  1692. }
  1693.  
  1694. private int _LockHeight;
  1695. protected int LockHeight
  1696. {
  1697. get { return _LockHeight; }
  1698. set
  1699. {
  1700. _LockHeight = value;
  1701. if (!(LockHeight == 0) && IsHandleCreated)
  1702. Height = LockHeight;
  1703. }
  1704. }
  1705.  
  1706. private bool _IsAnimated;
  1707. protected bool IsAnimated
  1708. {
  1709. get { return _IsAnimated; }
  1710. set
  1711. {
  1712. _IsAnimated = value;
  1713. InvalidateTimer();
  1714. }
  1715. }
  1716.  
  1717. #endregion
  1718.  
  1719.  
  1720. #region " Property Helpers "
  1721.  
  1722. protected Pen GetPen(string name)
  1723. {
  1724. return new Pen(Items[name]);
  1725. }
  1726. protected Pen GetPen(string name, float width)
  1727. {
  1728. return new Pen(Items[name], width);
  1729. }
  1730.  
  1731. protected SolidBrush GetBrush(string name)
  1732. {
  1733. return new SolidBrush(Items[name]);
  1734. }
  1735.  
  1736. protected Color GetColor(string name)
  1737. {
  1738. return Items[name];
  1739. }
  1740.  
  1741. protected void SetColor(string name, Color value)
  1742. {
  1743. if (Items.ContainsKey(name))
  1744. Items[name] = value;
  1745. else
  1746. Items.Add(name, value);
  1747. }
  1748. protected void SetColor(string name, byte r, byte g, byte b)
  1749. {
  1750. SetColor(name, Color.FromArgb(r, g, b));
  1751. }
  1752. protected void SetColor(string name, byte a, byte r, byte g, byte b)
  1753. {
  1754. SetColor(name, Color.FromArgb(a, r, g, b));
  1755. }
  1756. protected void SetColor(string name, byte a, Color value)
  1757. {
  1758. SetColor(name, Color.FromArgb(a, value));
  1759. }
  1760.  
  1761. private void InvalidateBitmap()
  1762. {
  1763. if (Width == 0 || Height == 0)
  1764. return;
  1765. B = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
  1766. G = Graphics.FromImage(B);
  1767. }
  1768.  
  1769. private void InvalidateCustimization()
  1770. {
  1771. MemoryStream M = new MemoryStream(Items.Count * 4);
  1772.  
  1773. foreach (Bloom B in Colors)
  1774. {
  1775. M.Write(BitConverter.GetBytes(B.Value.ToArgb()), 0, 4);
  1776. }
  1777.  
  1778. M.Close();
  1779. _Customization = Convert.ToBase64String(M.ToArray());
  1780. }
  1781.  
  1782. private void InvalidateTimer()
  1783. {
  1784. if (DesignMode || !DoneCreation)
  1785. return;
  1786.  
  1787. if (_IsAnimated)
  1788. {
  1789. ThemeShare.AddAnimationCallback(DoAnimation);
  1790. }
  1791. else
  1792. {
  1793. ThemeShare.RemoveAnimationCallback(DoAnimation);
  1794. }
  1795. }
  1796. #endregion
  1797.  
  1798.  
  1799. #region " User Hooks "
  1800.  
  1801. protected abstract void ColorHook();
  1802. protected abstract void PaintHook();
  1803.  
  1804. protected virtual void OnCreation()
  1805. {
  1806. }
  1807.  
  1808. protected virtual void OnAnimation()
  1809. {
  1810. }
  1811.  
  1812. #endregion
  1813.  
  1814.  
  1815. #region " Offset "
  1816.  
  1817. private Rectangle OffsetReturnRectangle;
  1818. protected Rectangle Offset(Rectangle r, int amount)
  1819. {
  1820. OffsetReturnRectangle = new Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2));
  1821. return OffsetReturnRectangle;
  1822. }
  1823.  
  1824. private Size OffsetReturnSize;
  1825. protected Size Offset(Size s, int amount)
  1826. {
  1827. OffsetReturnSize = new Size(s.Width + amount, s.Height + amount);
  1828. return OffsetReturnSize;
  1829. }
  1830.  
  1831. private Point OffsetReturnPoint;
  1832. protected Point Offset(Point p, int amount)
  1833. {
  1834. OffsetReturnPoint = new Point(p.X + amount, p.Y + amount);
  1835. return OffsetReturnPoint;
  1836. }
  1837.  
  1838. #endregion
  1839.  
  1840. #region " Center "
  1841.  
  1842.  
  1843. private Point CenterReturn;
  1844. protected Point Center(Rectangle p, Rectangle c)
  1845. {
  1846. CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X + c.X, (p.Height / 2 - c.Height / 2) + p.Y + c.Y);
  1847. return CenterReturn;
  1848. }
  1849. protected Point Center(Rectangle p, Size c)
  1850. {
  1851. CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X, (p.Height / 2 - c.Height / 2) + p.Y);
  1852. return CenterReturn;
  1853. }
  1854.  
  1855. protected Point Center(Rectangle child)
  1856. {
  1857. return Center(Width, Height, child.Width, child.Height);
  1858. }
  1859. protected Point Center(Size child)
  1860. {
  1861. return Center(Width, Height, child.Width, child.Height);
  1862. }
  1863. protected Point Center(int childWidth, int childHeight)
  1864. {
  1865. return Center(Width, Height, childWidth, childHeight);
  1866. }
  1867.  
  1868. protected Point Center(Size p, Size c)
  1869. {
  1870. return Center(p.Width, p.Height, c.Width, c.Height);
  1871. }
  1872.  
  1873. protected Point Center(int pWidth, int pHeight, int cWidth, int cHeight)
  1874. {
  1875. CenterReturn = new Point(pWidth / 2 - cWidth / 2, pHeight / 2 - cHeight / 2);
  1876. return CenterReturn;
  1877. }
  1878.  
  1879. #endregion
  1880.  
  1881. #region " Measure "
  1882.  
  1883. private Bitmap MeasureBitmap;
  1884. //TODO: Potential issues during multi-threading.
  1885. private Graphics MeasureGraphics;
  1886.  
  1887. protected Size Measure()
  1888. {
  1889. return MeasureGraphics.MeasureString(Text, Font, Width).ToSize();
  1890. }
  1891. protected Size Measure(string text)
  1892. {
  1893. return MeasureGraphics.MeasureString(text, Font, Width).ToSize();
  1894. }
  1895.  
  1896. #endregion
  1897.  
  1898.  
  1899. #region " DrawPixel "
  1900.  
  1901.  
  1902. private SolidBrush DrawPixelBrush;
  1903. protected void DrawPixel(Color c1, int x, int y)
  1904. {
  1905. if (_Transparent)
  1906. {
  1907. B.SetPixel(x, y, c1);
  1908. }
  1909. else
  1910. {
  1911. DrawPixelBrush = new SolidBrush(c1);
  1912. G.FillRectangle(DrawPixelBrush, x, y, 1, 1);
  1913. }
  1914. }
  1915.  
  1916. #endregion
  1917.  
  1918. #region " DrawCorners "
  1919.  
  1920.  
  1921. private SolidBrush DrawCornersBrush;
  1922. protected void DrawCorners(Color c1, int offset)
  1923. {
  1924. DrawCorners(c1, 0, 0, Width, Height, offset);
  1925. }
  1926. protected void DrawCorners(Color c1, Rectangle r1, int offset)
  1927. {
  1928. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset);
  1929. }
  1930. protected void DrawCorners(Color c1, int x, int y, int width, int height, int offset)
  1931. {
  1932. DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  1933. }
  1934.  
  1935. protected void DrawCorners(Color c1)
  1936. {
  1937. DrawCorners(c1, 0, 0, Width, Height);
  1938. }
  1939. protected void DrawCorners(Color c1, Rectangle r1)
  1940. {
  1941. DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
  1942. }
  1943. protected void DrawCorners(Color c1, int x, int y, int width, int height)
  1944. {
  1945. if (_NoRounding)
  1946. return;
  1947.  
  1948. if (_Transparent)
  1949. {
  1950. B.SetPixel(x, y, c1);
  1951. B.SetPixel(x + (width - 1), y, c1);
  1952. B.SetPixel(x, y + (height - 1), c1);
  1953. B.SetPixel(x + (width - 1), y + (height - 1), c1);
  1954. }
  1955. else
  1956. {
  1957. DrawCornersBrush = new SolidBrush(c1);
  1958. G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
  1959. G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
  1960. G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
  1961. G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
  1962. }
  1963. }
  1964.  
  1965. #endregion
  1966.  
  1967. #region " DrawBorders "
  1968.  
  1969. protected void DrawBorders(Pen p1, int offset)
  1970. {
  1971. DrawBorders(p1, 0, 0, Width, Height, offset);
  1972. }
  1973. protected void DrawBorders(Pen p1, Rectangle r, int offset)
  1974. {
  1975. DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
  1976. }
  1977. protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
  1978. {
  1979. DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  1980. }
  1981.  
  1982. protected void DrawBorders(Pen p1)
  1983. {
  1984. DrawBorders(p1, 0, 0, Width, Height);
  1985. }
  1986. protected void DrawBorders(Pen p1, Rectangle r)
  1987. {
  1988. DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
  1989. }
  1990. protected void DrawBorders(Pen p1, int x, int y, int width, int height)
  1991. {
  1992. G.DrawRectangle(p1, x, y, width - 1, height - 1);
  1993. }
  1994.  
  1995. #endregion
  1996.  
  1997. #region " DrawText "
  1998.  
  1999. private Point DrawTextPoint;
  2000.  
  2001. private Size DrawTextSize;
  2002. protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
  2003. {
  2004. DrawText(b1, Text, a, x, y);
  2005. }
  2006. protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
  2007. {
  2008. if (text.Length == 0)
  2009. return;
  2010.  
  2011. DrawTextSize = Measure(text);
  2012. DrawTextPoint = Center(DrawTextSize);
  2013.  
  2014. switch (a)
  2015. {
  2016. case HorizontalAlignment.Left:
  2017. G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y);
  2018. break;
  2019. case HorizontalAlignment.Center:
  2020. G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y);
  2021. break;
  2022. case HorizontalAlignment.Right:
  2023. G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
  2024. break;
  2025. }
  2026. }
  2027.  
  2028. protected void DrawText(Brush b1, Point p1)
  2029. {
  2030. if (Text.Length == 0)
  2031. return;
  2032. G.DrawString(Text, Font, b1, p1);
  2033. }
  2034. protected void DrawText(Brush b1, int x, int y)
  2035. {
  2036. if (Text.Length == 0)
  2037. return;
  2038. G.DrawString(Text, Font, b1, x, y);
  2039. }
  2040.  
  2041. #endregion
  2042.  
  2043. #region " DrawImage "
  2044.  
  2045.  
  2046. private Point DrawImagePoint;
  2047. protected void DrawImage(HorizontalAlignment a, int x, int y)
  2048. {
  2049. DrawImage(_Image, a, x, y);
  2050. }
  2051. protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
  2052. {
  2053. if (image == null)
  2054. return;
  2055. DrawImagePoint = Center(image.Size);
  2056.  
  2057. switch (a)
  2058. {
  2059. case HorizontalAlignment.Left:
  2060. G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height);
  2061. break;
  2062. case HorizontalAlignment.Center:
  2063. G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height);
  2064. break;
  2065. case HorizontalAlignment.Right:
  2066. G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height);
  2067. break;
  2068. }
  2069. }
  2070.  
  2071. protected void DrawImage(Point p1)
  2072. {
  2073. DrawImage(_Image, p1.X, p1.Y);
  2074. }
  2075. protected void DrawImage(int x, int y)
  2076. {
  2077. DrawImage(_Image, x, y);
  2078. }
  2079.  
  2080. protected void DrawImage(Image image, Point p1)
  2081. {
  2082. DrawImage(image, p1.X, p1.Y);
  2083. }
  2084. protected void DrawImage(Image image, int x, int y)
  2085. {
  2086. if (image == null)
  2087. return;
  2088. G.DrawImage(image, x, y, image.Width, image.Height);
  2089. }
  2090.  
  2091. #endregion
  2092.  
  2093. #region " DrawGradient "
  2094.  
  2095. private LinearGradientBrush DrawGradientBrush;
  2096.  
  2097. private Rectangle DrawGradientRectangle;
  2098. protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
  2099. {
  2100. DrawGradientRectangle = new Rectangle(x, y, width, height);
  2101. DrawGradient(blend, DrawGradientRectangle);
  2102. }
  2103. protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
  2104. {
  2105. DrawGradientRectangle = new Rectangle(x, y, width, height);
  2106. DrawGradient(blend, DrawGradientRectangle, angle);
  2107. }
  2108.  
  2109. protected void DrawGradient(ColorBlend blend, Rectangle r)
  2110. {
  2111. DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, 90f);
  2112. DrawGradientBrush.InterpolationColors = blend;
  2113. G.FillRectangle(DrawGradientBrush, r);
  2114. }
  2115. protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
  2116. {
  2117. DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
  2118. DrawGradientBrush.InterpolationColors = blend;
  2119. G.FillRectangle(DrawGradientBrush, r);
  2120. }
  2121.  
  2122.  
  2123. protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
  2124. {
  2125. DrawGradientRectangle = new Rectangle(x, y, width, height);
  2126. DrawGradient(c1, c2, DrawGradientRectangle);
  2127. }
  2128. protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
  2129. {
  2130. DrawGradientRectangle = new Rectangle(x, y, width, height);
  2131. DrawGradient(c1, c2, DrawGradientRectangle, angle);
  2132. }
  2133.  
  2134. protected void DrawGradient(Color c1, Color c2, Rectangle r)
  2135. {
  2136. DrawGradientBrush = new LinearGradientBrush(r, c1, c2, 90f);
  2137. G.FillRectangle(DrawGradientBrush, r);
  2138. }
  2139. protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
  2140. {
  2141. DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
  2142. G.FillRectangle(DrawGradientBrush, r);
  2143. }
  2144.  
  2145. #endregion
  2146.  
  2147. #region " DrawRadial "
  2148.  
  2149. private GraphicsPath DrawRadialPath;
  2150. private PathGradientBrush DrawRadialBrush1;
  2151. private LinearGradientBrush DrawRadialBrush2;
  2152.  
  2153. private Rectangle DrawRadialRectangle;
  2154. public void DrawRadial(ColorBlend blend, int x, int y, int width, int height)
  2155. {
  2156. DrawRadialRectangle = new Rectangle(x, y, width, height);
  2157. DrawRadial(blend, DrawRadialRectangle, width / 2, height / 2);
  2158. }
  2159. public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, Point center)
  2160. {
  2161. DrawRadialRectangle = new Rectangle(x, y, width, height);
  2162. DrawRadial(blend, DrawRadialRectangle, center.X, center.Y);
  2163. }
  2164. public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, int cx, int cy)
  2165. {
  2166. DrawRadialRectangle = new Rectangle(x, y, width, height);
  2167. DrawRadial(blend, DrawRadialRectangle, cx, cy);
  2168. }
  2169.  
  2170. public void DrawRadial(ColorBlend blend, Rectangle r)
  2171. {
  2172. DrawRadial(blend, r, r.Width / 2, r.Height / 2);
  2173. }
  2174. public void DrawRadial(ColorBlend blend, Rectangle r, Point center)
  2175. {
  2176. DrawRadial(blend, r, center.X, center.Y);
  2177. }
  2178. public void DrawRadial(ColorBlend blend, Rectangle r, int cx, int cy)
  2179. {
  2180. DrawRadialPath.Reset();
  2181. DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1);
  2182.  
  2183. DrawRadialBrush1 = new PathGradientBrush(DrawRadialPath);
  2184. DrawRadialBrush1.CenterPoint = new Point(r.X + cx, r.Y + cy);
  2185. DrawRadialBrush1.InterpolationColors = blend;
  2186.  
  2187. if (G.SmoothingMode == SmoothingMode.AntiAlias)
  2188. {
  2189. G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3);
  2190. }
  2191. else
  2192. {
  2193. G.FillEllipse(DrawRadialBrush1, r);
  2194. }
  2195. }
  2196.  
  2197.  
  2198. protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height)
  2199. {
  2200. DrawRadialRectangle = new Rectangle(x, y, width, height);
  2201. DrawRadial(c1, c2, DrawRadialRectangle);
  2202. }
  2203. protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height, float angle)
  2204. {
  2205. DrawRadialRectangle = new Rectangle(x, y, width, height);
  2206. DrawRadial(c1, c2, DrawRadialRectangle, angle);
  2207. }
  2208.  
  2209. protected void DrawRadial(Color c1, Color c2, Rectangle r)
  2210. {
  2211. DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, 90f);
  2212. G.FillEllipse(DrawRadialBrush2, r);
  2213. }
  2214. protected void DrawRadial(Color c1, Color c2, Rectangle r, float angle)
  2215. {
  2216. DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, angle);
  2217. G.FillEllipse(DrawRadialBrush2, r);
  2218. }
  2219.  
  2220. #endregion
  2221.  
  2222. #region " CreateRound "
  2223.  
  2224. private GraphicsPath CreateRoundPath;
  2225.  
  2226. private Rectangle CreateRoundRectangle;
  2227. public GraphicsPath CreateRound(int x, int y, int width, int height, int slope)
  2228. {
  2229. CreateRoundRectangle = new Rectangle(x, y, width, height);
  2230. return CreateRound(CreateRoundRectangle, slope);
  2231. }
  2232.  
  2233. public GraphicsPath CreateRound(Rectangle r, int slope)
  2234. {
  2235. CreateRoundPath = new GraphicsPath(FillMode.Winding);
  2236. CreateRoundPath.AddArc(r.X, r.Y, slope, slope, 180f, 90f);
  2237. CreateRoundPath.AddArc(r.Right - slope, r.Y, slope, slope, 270f, 90f);
  2238. CreateRoundPath.AddArc(r.Right - slope, r.Bottom - slope, slope, slope, 0f, 90f);
  2239. CreateRoundPath.AddArc(r.X, r.Bottom - slope, slope, slope, 90f, 90f);
  2240. CreateRoundPath.CloseFigure();
  2241. return CreateRoundPath;
  2242. }
  2243.  
  2244. #endregion
  2245.  
  2246. }
  2247.  
  2248. static class ThemeShare
  2249. {
  2250.  
  2251. #region " Animation "
  2252.  
  2253. private static int Frames;
  2254. private static bool Invalidate;
  2255.  
  2256. public static PrecisionTimer ThemeTimer = new PrecisionTimer();
  2257. //1000 / 50 = 20 FPS
  2258. private const int FPS = 50;
  2259.  
  2260. private const int Rate = 10;
  2261. public delegate void AnimationDelegate(bool invalidate);
  2262.  
  2263.  
  2264. private static List<AnimationDelegate> Callbacks = new List<AnimationDelegate>();
  2265. private static void HandleCallbacks(IntPtr state, bool reserve)
  2266. {
  2267. Invalidate = (Frames >= FPS);
  2268. if (Invalidate)
  2269. Frames = 0;
  2270.  
  2271. lock (Callbacks)
  2272. {
  2273. for (int I = 0; I <= Callbacks.Count - 1; I++)
  2274. {
  2275. Callbacks[I].Invoke(Invalidate);
  2276. }
  2277. }
  2278.  
  2279. Frames += Rate;
  2280. }
  2281.  
  2282. private static void InvalidateThemeTimer()
  2283. {
  2284. if (Callbacks.Count == 0)
  2285. {
  2286. ThemeTimer.Delete();
  2287. }
  2288. else
  2289. {
  2290. ThemeTimer.Create(0, Rate, HandleCallbacks);
  2291. }
  2292. }
  2293.  
  2294. public static void AddAnimationCallback(AnimationDelegate callback)
  2295. {
  2296. lock (Callbacks)
  2297. {
  2298. if (Callbacks.Contains(callback))
  2299. return;
  2300.  
  2301. Callbacks.Add(callback);
  2302. InvalidateThemeTimer();
  2303. }
  2304. }
  2305.  
  2306. public static void RemoveAnimationCallback(AnimationDelegate callback)
  2307. {
  2308. lock (Callbacks)
  2309. {
  2310. if (!Callbacks.Contains(callback))
  2311. return;
  2312.  
  2313. Callbacks.Remove(callback);
  2314. InvalidateThemeTimer();
  2315. }
  2316. }
  2317.  
  2318. #endregion
  2319.  
  2320. }
  2321.  
  2322. enum MouseState : byte
  2323. {
  2324. None = 0,
  2325. Over = 1,
  2326. Down = 2,
  2327. Block = 3
  2328. }
  2329.  
  2330. struct Bloom
  2331. {
  2332.  
  2333. public string _Name;
  2334. public string Name
  2335. {
  2336. get { return _Name; }
  2337. }
  2338.  
  2339. private Color _Value;
  2340. public Color Value
  2341. {
  2342. get { return _Value; }
  2343. set { _Value = value; }
  2344. }
  2345.  
  2346. public string ValueHex
  2347. {
  2348. get { return string.Concat("#", _Value.R.ToString("X2", null), _Value.G.ToString("X2", null), _Value.B.ToString("X2", null)); }
  2349. set
  2350. {
  2351. try
  2352. {
  2353. _Value = ColorTranslator.FromHtml(value);
  2354. }
  2355. catch
  2356. {
  2357. return;
  2358. }
  2359. }
  2360. }
  2361.  
  2362.  
  2363. public Bloom(string name, Color value)
  2364. {
  2365. _Name = name;
  2366. _Value = value;
  2367. }
  2368. }
  2369.  
  2370. //------------------
  2371. //Creator: aeonhack
  2372. //Site: elitevs.net
  2373. //Created: 11/30/2011
  2374. //Changed: 11/30/2011
  2375. //Version: 1.0.0
  2376. //------------------
  2377. class PrecisionTimer : IDisposable
  2378. {
  2379.  
  2380. private bool _Enabled;
  2381. public bool Enabled
  2382. {
  2383. get { return _Enabled; }
  2384. }
  2385.  
  2386. private IntPtr Handle;
  2387.  
  2388. private TimerDelegate TimerCallback;
  2389. [DllImport("kernel32.dll", EntryPoint = "CreateTimerQueueTimer")]
  2390. private static extern bool CreateTimerQueueTimer(ref IntPtr handle, IntPtr queue, TimerDelegate callback, IntPtr state, uint dueTime, uint period, uint flags);
  2391.  
  2392. [DllImport("kernel32.dll", EntryPoint = "DeleteTimerQueueTimer")]
  2393. private static extern bool DeleteTimerQueueTimer(IntPtr queue, IntPtr handle, IntPtr callback);
  2394.  
  2395. public delegate void TimerDelegate(IntPtr r1, bool r2);
  2396.  
  2397. public void Create(uint dueTime, uint period, TimerDelegate callback)
  2398. {
  2399. if (_Enabled)
  2400. return;
  2401.  
  2402. TimerCallback = callback;
  2403. bool Success = CreateTimerQueueTimer(ref Handle, IntPtr.Zero, TimerCallback, IntPtr.Zero, dueTime, period, 0);
  2404.  
  2405. if (!Success)
  2406. ThrowNewException("CreateTimerQueueTimer");
  2407. _Enabled = Success;
  2408. }
  2409.  
  2410. public void Delete()
  2411. {
  2412. if (!_Enabled)
  2413. return;
  2414. bool Success = DeleteTimerQueueTimer(IntPtr.Zero, Handle, IntPtr.Zero);
  2415.  
  2416. if (!Success && !(Marshal.GetLastWin32Error() == 997))
  2417. {
  2418. ThrowNewException("DeleteTimerQueueTimer");
  2419. }
  2420.  
  2421. _Enabled = !Success;
  2422. }
  2423.  
  2424. private void ThrowNewException(string name)
  2425. {
  2426. throw new Exception(string.Format("{0} failed. Win32Error: {1}", name, Marshal.GetLastWin32Error()));
  2427. }
  2428.  
  2429. public void Dispose()
  2430. {
  2431. Delete();
  2432. }
  2433. }
Add Comment
Please, Sign In to add comment