Advertisement
Astekk

c# theme base 1.5.3

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