Advertisement
Guest User

ThemeBase154 - C#

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