iTz_Mercury

C# Themebase 1.5.3 modified

May 18th, 2012
178
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 54.36 KB | None | 0 0
  1. //use this for carbon theme
  2. using System;
  3. using System.Collections.Generic;
  4. using System.IO;
  5. using System.Drawing;
  6. using System.Drawing.Drawing2D;
  7. using System.ComponentModel;
  8. using System.Windows.Forms;
  9. using System.Runtime.InteropServices;
  10. using System.Drawing.Imaging;
  11.  
  12. //------------------
  13. //Creator: aeonhack
  14. //Site: elitevs.net
  15. //Created: 08/02/2011
  16. //Changed: 10/9/2011
  17. //Version: 1.5.3
  18. //------------------
  19.  
  20. public abstract class ThemeContainer153 : ContainerControl
  21. {
  22.  
  23.     #region " Initialization "
  24.  
  25.     protected Graphics G;
  26.  
  27.     protected Bitmap B;
  28.     public ThemeContainer153()
  29.     {
  30.         SetStyle((ControlStyles)139270, true);
  31.  
  32.         _ImageSize = Size.Empty;
  33.         Font = new Font("Verdana", 8);
  34.  
  35.         MeasureBitmap = new Bitmap(1, 1);
  36.         MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  37.  
  38.         DrawRadialPath = new GraphicsPath();
  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.             //Parent.Text = value;
  412.             Invalidate();
  413.         }
  414.     }
  415.  
  416.     public override Font Font
  417.     {
  418.         get { return base.Font; }
  419.         set
  420.         {
  421.             base.Font = value;
  422.             Invalidate();
  423.         }
  424.     }
  425.  
  426.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  427.     public override Color ForeColor
  428.     {
  429.         get { return Color.Empty; }
  430.         set { }
  431.     }
  432.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  433.     public override Image BackgroundImage
  434.     {
  435.         get { return null; }
  436.         set { }
  437.     }
  438.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  439.     public override ImageLayout BackgroundImageLayout
  440.     {
  441.         get { return ImageLayout.None; }
  442.         set { }
  443.     }
  444.  
  445.     #endregion
  446.  
  447.     #region " Public Properties "
  448.  
  449.     private bool _SmartBounds = true;
  450.     public bool SmartBounds
  451.     {
  452.         get { return _SmartBounds; }
  453.         set { _SmartBounds = value; }
  454.     }
  455.  
  456.     private bool _Movable = true;
  457.     public bool Movable
  458.     {
  459.         get { return _Movable; }
  460.         set { _Movable = value; }
  461.     }
  462.  
  463.     private bool _Sizable = true;
  464.     public bool Sizable
  465.     {
  466.         get { return _Sizable; }
  467.         set { _Sizable = value; }
  468.     }
  469.  
  470.     private Color _TransparencyKey;
  471.     public Color TransparencyKey
  472.     {
  473.         get
  474.         {
  475.             if (_IsParentForm && !_ControlMode)
  476.                 return ParentForm.TransparencyKey;
  477.             else
  478.                 return _TransparencyKey;
  479.         }
  480.         set
  481.         {
  482.             if (value == _TransparencyKey)
  483.                 return;
  484.             _TransparencyKey = value;
  485.  
  486.             if (_IsParentForm && !_ControlMode)
  487.             {
  488.                 ParentForm.TransparencyKey = value;
  489.                 ColorHook();
  490.             }
  491.         }
  492.     }
  493.  
  494.     private FormBorderStyle _BorderStyle;
  495.     public FormBorderStyle BorderStyle
  496.     {
  497.         get
  498.         {
  499.             if (_IsParentForm && !_ControlMode)
  500.                 return ParentForm.FormBorderStyle;
  501.             else
  502.                 return _BorderStyle;
  503.         }
  504.         set
  505.         {
  506.             _BorderStyle = value;
  507.  
  508.             if (_IsParentForm && !_ControlMode)
  509.             {
  510.                 ParentForm.FormBorderStyle = value;
  511.  
  512.                 if (!(value == FormBorderStyle.None))
  513.                 {
  514.                     Movable = false;
  515.                     Sizable = false;
  516.                 }
  517.             }
  518.         }
  519.     }
  520.  
  521.     private bool _NoRounding;
  522.     public bool NoRounding
  523.     {
  524.         get { return _NoRounding; }
  525.         set
  526.         {
  527.             _NoRounding = value;
  528.             Invalidate();
  529.         }
  530.     }
  531.  
  532.     private Image _Image;
  533.     public Image Image
  534.     {
  535.         get { return _Image; }
  536.         set
  537.         {
  538.             if (value == null)
  539.                 _ImageSize = Size.Empty;
  540.             else
  541.                 _ImageSize = value.Size;
  542.  
  543.             _Image = value;
  544.             Invalidate();
  545.         }
  546.     }
  547.  
  548.     private Dictionary<string, Color> Items = new Dictionary<string, Color>();
  549.     public Bloom[] Colors
  550.     {
  551.         get
  552.         {
  553.             List<Bloom> T = new List<Bloom>();
  554.             Dictionary<string, Color>.Enumerator E = Items.GetEnumerator();
  555.  
  556.             while (E.MoveNext())
  557.             {
  558.                 T.Add(new Bloom(E.Current.Key, E.Current.Value));
  559.             }
  560.  
  561.             return T.ToArray();
  562.         }
  563.         set
  564.         {
  565.             foreach (Bloom B in value)
  566.             {
  567.                 if (Items.ContainsKey(B.Name))
  568.                     Items[B.Name] = B.Value;
  569.             }
  570.  
  571.             InvalidateCustimization();
  572.             ColorHook();
  573.             Invalidate();
  574.         }
  575.     }
  576.  
  577.     private string _Customization;
  578.     public string Customization
  579.     {
  580.         get { return _Customization; }
  581.         set
  582.         {
  583.             if (value == _Customization)
  584.                 return;
  585.  
  586.             byte[] Data = null;
  587.             Bloom[] Items = Colors;
  588.  
  589.             try
  590.             {
  591.                 Data = Convert.FromBase64String(value);
  592.                 for (int I = 0; I <= Items.Length - 1; I++)
  593.                 {
  594.                     Items[I].Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
  595.                 }
  596.             }
  597.             catch
  598.             {
  599.                 return;
  600.             }
  601.  
  602.             _Customization = value;
  603.  
  604.             Colors = Items;
  605.             ColorHook();
  606.             Invalidate();
  607.         }
  608.     }
  609.  
  610.     private bool _Transparent;
  611.     public bool Transparent
  612.     {
  613.         get { return _Transparent; }
  614.         set
  615.         {
  616.             _Transparent = value;
  617.             if (!(IsHandleCreated || _ControlMode))
  618.                 return;
  619.  
  620.             if (!value && !(BackColor.A == 255))
  621.             {
  622.                 throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
  623.             }
  624.  
  625.             SetStyle(ControlStyles.Opaque, !value);
  626.             SetStyle(ControlStyles.SupportsTransparentBackColor, value);
  627.  
  628.             InvalidateBitmap();
  629.             Invalidate();
  630.         }
  631.     }
  632.  
  633.     #endregion
  634.  
  635.     #region " Private Properties "
  636.  
  637.     private Size _ImageSize;
  638.     protected Size ImageSize
  639.     {
  640.         get { return _ImageSize; }
  641.     }
  642.  
  643.     private bool _IsParentForm;
  644.     protected bool IsParentForm
  645.     {
  646.         get { return _IsParentForm; }
  647.     }
  648.  
  649.     protected bool IsParentMdi
  650.     {
  651.         get
  652.         {
  653.             if (Parent == null)
  654.                 return false;
  655.             return Parent.Parent != null;
  656.         }
  657.     }
  658.  
  659.     private int _LockWidth;
  660.     protected int LockWidth
  661.     {
  662.         get { return _LockWidth; }
  663.         set
  664.         {
  665.             _LockWidth = value;
  666.             if (!(LockWidth == 0) && IsHandleCreated)
  667.                 Width = LockWidth;
  668.         }
  669.     }
  670.  
  671.     private int _LockHeight;
  672.     protected int LockHeight
  673.     {
  674.         get { return _LockHeight; }
  675.         set
  676.         {
  677.             _LockHeight = value;
  678.             if (!(LockHeight == 0) && IsHandleCreated)
  679.                 Height = LockHeight;
  680.         }
  681.     }
  682.  
  683.     private int _Header = 24;
  684.     protected int Header
  685.     {
  686.         get { return _Header; }
  687.         set
  688.         {
  689.             _Header = value;
  690.  
  691.             if (!_ControlMode)
  692.             {
  693.                 Frame = new Rectangle(7, 7, Width - 14, value - 7);
  694.                 Invalidate();
  695.             }
  696.         }
  697.     }
  698.  
  699.     private bool _ControlMode;
  700.     protected bool ControlMode
  701.     {
  702.         get { return _ControlMode; }
  703.         set
  704.         {
  705.             _ControlMode = value;
  706.  
  707.             Transparent = _Transparent;
  708.             if (_Transparent && _BackColor)
  709.                 BackColor = Color.Transparent;
  710.  
  711.             InvalidateBitmap();
  712.             Invalidate();
  713.         }
  714.     }
  715.  
  716.     #endregion
  717.  
  718.  
  719.     #region " Property Helpers "
  720.  
  721.     protected Pen GetPen(string name)
  722.     {
  723.         return new Pen(Items[name]);
  724.     }
  725.     protected Pen GetPen(string name, float width)
  726.     {
  727.         return new Pen(Items[name], width);
  728.     }
  729.  
  730.     protected SolidBrush GetBrush(string name)
  731.     {
  732.         return new SolidBrush(Items[name]);
  733.     }
  734.  
  735.     protected Color GetColor(string name)
  736.     {
  737.         return Items[name];
  738.     }
  739.  
  740.     protected void SetColor(string name, Color value)
  741.     {
  742.         if (Items.ContainsKey(name))
  743.             Items[name] = value;
  744.         else
  745.             Items.Add(name, value);
  746.     }
  747.     protected void SetColor(string name, byte r, byte g, byte b)
  748.     {
  749.         SetColor(name, Color.FromArgb(r, g, b));
  750.     }
  751.     protected void SetColor(string name, byte a, byte r, byte g, byte b)
  752.     {
  753.         SetColor(name, Color.FromArgb(a, r, g, b));
  754.     }
  755.     protected void SetColor(string name, byte a, Color value)
  756.     {
  757.         SetColor(name, Color.FromArgb(a, value));
  758.     }
  759.  
  760.     private void InvalidateBitmap()
  761.     {
  762.         if (_Transparent && _ControlMode)
  763.         {
  764.             if (Width == 0 || Height == 0)
  765.                 return;
  766.             B = new Bitmap(Width, Height, PixelFormat.Format32bppPArgb);
  767.             G = Graphics.FromImage(B);
  768.         }
  769.         else
  770.         {
  771.             G = null;
  772.             B = null;
  773.         }
  774.     }
  775.  
  776.     private void InvalidateCustimization()
  777.     {
  778.         MemoryStream M = new MemoryStream(Items.Count * 4);
  779.  
  780.         foreach (Bloom B in Colors)
  781.         {
  782.             M.Write(BitConverter.GetBytes(B.Value.ToArgb()), 0, 4);
  783.         }
  784.  
  785.         M.Close();
  786.         _Customization = Convert.ToBase64String(M.ToArray());
  787.     }
  788.  
  789.     #endregion
  790.  
  791.  
  792.     #region " User Hooks "
  793.  
  794.     protected abstract void ColorHook();
  795.     protected abstract void PaintHook();
  796.  
  797.     protected virtual void OnCreation()
  798.     {
  799.     }
  800.  
  801.     #endregion
  802.  
  803.  
  804.     #region " Offset "
  805.  
  806.     private Rectangle OffsetReturnRectangle;
  807.     protected Rectangle Offset(Rectangle r, int amount)
  808.     {
  809.         OffsetReturnRectangle = new Rectangle(r.X + amount, r.Y + amount, r.Width - (amount * 2), r.Height - (amount * 2));
  810.         return OffsetReturnRectangle;
  811.     }
  812.  
  813.     private Size OffsetReturnSize;
  814.     protected Size Offset(Size s, int amount)
  815.     {
  816.         OffsetReturnSize = new Size(s.Width + amount, s.Height + amount);
  817.         return OffsetReturnSize;
  818.     }
  819.  
  820.     private Point OffsetReturnPoint;
  821.     protected Point Offset(Point p, int amount)
  822.     {
  823.         OffsetReturnPoint = new Point(p.X + amount, p.Y + amount);
  824.         return OffsetReturnPoint;
  825.     }
  826.  
  827.     #endregion
  828.  
  829.     #region " Center "
  830.  
  831.  
  832.     private Point CenterReturn;
  833.     protected Point Center(Rectangle p, Rectangle c)
  834.     {
  835.         CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X + c.X, (p.Height / 2 - c.Height / 2) + p.Y + c.Y);
  836.         return CenterReturn;
  837.     }
  838.     protected Point Center(Rectangle p, Size c)
  839.     {
  840.         CenterReturn = new Point((p.Width / 2 - c.Width / 2) + p.X, (p.Height / 2 - c.Height / 2) + p.Y);
  841.         return CenterReturn;
  842.     }
  843.  
  844.     protected Point Center(Rectangle child)
  845.     {
  846.         return Center(Width, Height, child.Width, child.Height);
  847.     }
  848.     protected Point Center(Size child)
  849.     {
  850.         return Center(Width, Height, child.Width, child.Height);
  851.     }
  852.     protected Point Center(int childWidth, int childHeight)
  853.     {
  854.         return Center(Width, Height, childWidth, childHeight);
  855.     }
  856.  
  857.     protected Point Center(Size p, Size c)
  858.     {
  859.         return Center(p.Width, p.Height, c.Width, c.Height);
  860.     }
  861.  
  862.     protected Point Center(int pWidth, int pHeight, int cWidth, int cHeight)
  863.     {
  864.         CenterReturn = new Point(pWidth / 2 - cWidth / 2, pHeight / 2 - cHeight / 2);
  865.         return CenterReturn;
  866.     }
  867.  
  868.     #endregion
  869.  
  870.     #region " Measure "
  871.  
  872.     private Bitmap MeasureBitmap;
  873.     //TODO: Potential issues during multi-threading.
  874.     private Graphics MeasureGraphics;
  875.  
  876.     protected Size Measure()
  877.     {
  878.         return MeasureGraphics.MeasureString(Text, Font, Width).ToSize();
  879.     }
  880.     protected Size Measure(string text)
  881.     {
  882.         return MeasureGraphics.MeasureString(text, Font, Width).ToSize();
  883.     }
  884.  
  885.     #endregion
  886.  
  887.  
  888.     #region " DrawPixel "
  889.  
  890.  
  891.     private SolidBrush DrawPixelBrush;
  892.     protected void DrawPixel(Color c1, int x, int y)
  893.     {
  894.         if (_Transparent)
  895.         {
  896.             B.SetPixel(x, y, c1);
  897.         }
  898.         else
  899.         {
  900.             DrawPixelBrush = new SolidBrush(c1);
  901.             G.FillRectangle(DrawPixelBrush, x, y, 1, 1);
  902.         }
  903.     }
  904.  
  905.     #endregion
  906.  
  907.     #region " DrawCorners "
  908.  
  909.  
  910.     private SolidBrush DrawCornersBrush;
  911.     protected void DrawCorners(Color c1, int offset)
  912.     {
  913.         DrawCorners(c1, 0, 0, Width, Height, offset);
  914.     }
  915.     protected void DrawCorners(Color c1, Rectangle r1, int offset)
  916.     {
  917.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height, offset);
  918.     }
  919.     protected void DrawCorners(Color c1, int x, int y, int width, int height, int offset)
  920.     {
  921.         DrawCorners(c1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  922.     }
  923.  
  924.     protected void DrawCorners(Color c1)
  925.     {
  926.         DrawCorners(c1, 0, 0, Width, Height);
  927.     }
  928.     protected void DrawCorners(Color c1, Rectangle r1)
  929.     {
  930.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
  931.     }
  932.     protected void DrawCorners(Color c1, int x, int y, int width, int height)
  933.     {
  934.         if (_NoRounding)
  935.             return;
  936.  
  937.         if (_Transparent)
  938.         {
  939.             B.SetPixel(x, y, c1);
  940.             B.SetPixel(x + (width - 1), y, c1);
  941.             B.SetPixel(x, y + (height - 1), c1);
  942.             B.SetPixel(x + (width - 1), y + (height - 1), c1);
  943.         }
  944.         else
  945.         {
  946.             DrawCornersBrush = new SolidBrush(c1);
  947.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
  948.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
  949.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
  950.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
  951.         }
  952.     }
  953.  
  954.     #endregion
  955.  
  956.     #region " DrawBorders "
  957.  
  958.     protected void DrawBorders(Pen p1, int offset)
  959.     {
  960.         DrawBorders(p1, 0, 0, Width, Height, offset);
  961.     }
  962.     protected void DrawBorders(Pen p1, Rectangle r, int offset)
  963.     {
  964.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
  965.     }
  966.     protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
  967.     {
  968.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  969.     }
  970.  
  971.     protected void DrawBorders(Pen p1)
  972.     {
  973.         DrawBorders(p1, 0, 0, Width, Height);
  974.     }
  975.     protected void DrawBorders(Pen p1, Rectangle r)
  976.     {
  977.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
  978.     }
  979.     protected void DrawBorders(Pen p1, int x, int y, int width, int height)
  980.     {
  981.         G.DrawRectangle(p1, x, y, width - 1, height - 1);
  982.     }
  983.  
  984.     #endregion
  985.  
  986.     #region " DrawText "
  987.  
  988.     private Point DrawTextPoint;
  989.  
  990.     private Size DrawTextSize;
  991.     protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
  992.     {
  993.         DrawText(b1, Text, a, x, y);
  994.     }
  995.     protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
  996.     {
  997.         if (text.Length == 0)
  998.             return;
  999.  
  1000.         DrawTextSize = Measure(text);
  1001.         DrawTextPoint = new Point(Width / 2 - DrawTextSize.Width / 2, Header / 2 - DrawTextSize.Height / 2);
  1002.  
  1003.         switch (a)
  1004.         {
  1005.             case HorizontalAlignment.Left:
  1006.                 G.DrawString(text, Font, b1, x, DrawTextPoint.Y + y);
  1007.                 break;
  1008.             case HorizontalAlignment.Center:
  1009.                 G.DrawString(text, Font, b1, DrawTextPoint.X + x, DrawTextPoint.Y + y);
  1010.                 break;
  1011.             case HorizontalAlignment.Right:
  1012.                 G.DrawString(text, Font, b1, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
  1013.                 break;
  1014.         }
  1015.     }
  1016.  
  1017.     protected void DrawText(Brush b1, Point p1)
  1018.     {
  1019.         if (Text.Length == 0)
  1020.             return;
  1021.         G.DrawString(Text, Font, b1, p1);
  1022.     }
  1023.     protected void DrawText(Brush b1, int x, int y)
  1024.     {
  1025.         if (Text.Length == 0)
  1026.             return;
  1027.         G.DrawString(Text, Font, b1, x, y);
  1028.     }
  1029.  
  1030.     #endregion
  1031.  
  1032.     #region " DrawImage "
  1033.  
  1034.  
  1035.     private Point DrawImagePoint;
  1036.     protected void DrawImage(HorizontalAlignment a, int x, int y)
  1037.     {
  1038.         DrawImage(_Image, a, x, y);
  1039.     }
  1040.     protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
  1041.     {
  1042.         if (image == null)
  1043.             return;
  1044.         DrawImagePoint = new Point(Width / 2 - image.Width / 2, Header / 2 - image.Height / 2);
  1045.  
  1046.         switch (a)
  1047.         {
  1048.             case HorizontalAlignment.Left:
  1049.                 G.DrawImage(image, x, DrawImagePoint.Y + y, image.Width, image.Height);
  1050.                 break;
  1051.             case HorizontalAlignment.Center:
  1052.                 G.DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y, image.Width, image.Height);
  1053.                 break;
  1054.             case HorizontalAlignment.Right:
  1055.                 G.DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y, image.Width, image.Height);
  1056.                 break;
  1057.         }
  1058.     }
  1059.  
  1060.     protected void DrawImage(Point p1)
  1061.     {
  1062.         DrawImage(_Image, p1.X, p1.Y);
  1063.     }
  1064.     protected void DrawImage(int x, int y)
  1065.     {
  1066.         DrawImage(_Image, x, y);
  1067.     }
  1068.  
  1069.     protected void DrawImage(Image image, Point p1)
  1070.     {
  1071.         DrawImage(image, p1.X, p1.Y);
  1072.     }
  1073.     protected void DrawImage(Image image, int x, int y)
  1074.     {
  1075.         if (image == null)
  1076.             return;
  1077.         G.DrawImage(image, x, y, image.Width, image.Height);
  1078.     }
  1079.  
  1080.     #endregion
  1081.  
  1082.     #region " DrawGradient "
  1083.  
  1084.     private LinearGradientBrush DrawGradientBrush;
  1085.  
  1086.     private Rectangle DrawGradientRectangle;
  1087.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
  1088.     {
  1089.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  1090.         DrawGradient(blend, DrawGradientRectangle);
  1091.     }
  1092.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
  1093.     {
  1094.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  1095.         DrawGradient(blend, DrawGradientRectangle, angle);
  1096.     }
  1097.  
  1098.     protected void DrawGradient(ColorBlend blend, Rectangle r)
  1099.     {
  1100.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, 90f);
  1101.         DrawGradientBrush.InterpolationColors = blend;
  1102.         G.FillRectangle(DrawGradientBrush, r);
  1103.     }
  1104.     protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
  1105.     {
  1106.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
  1107.         DrawGradientBrush.InterpolationColors = blend;
  1108.         G.FillRectangle(DrawGradientBrush, r);
  1109.     }
  1110.  
  1111.  
  1112.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
  1113.     {
  1114.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  1115.         DrawGradient(c1, c2, DrawGradientRectangle);
  1116.     }
  1117.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
  1118.     {
  1119.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  1120.         DrawGradient(c1, c2, DrawGradientRectangle, angle);
  1121.     }
  1122.  
  1123.     protected void DrawGradient(Color c1, Color c2, Rectangle r)
  1124.     {
  1125.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, 90f);
  1126.         G.FillRectangle(DrawGradientBrush, r);
  1127.     }
  1128.     protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
  1129.     {
  1130.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
  1131.         G.FillRectangle(DrawGradientBrush, r);
  1132.     }
  1133.  
  1134.     #endregion
  1135.  
  1136.     #region " DrawRadial "
  1137.  
  1138.     private GraphicsPath DrawRadialPath;
  1139.     private PathGradientBrush DrawRadialBrush1;
  1140.     private LinearGradientBrush DrawRadialBrush2;
  1141.  
  1142.     private Rectangle DrawRadialRectangle;
  1143.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height)
  1144.     {
  1145.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  1146.         DrawRadial(blend, DrawRadialRectangle, width / 2, height / 2);
  1147.     }
  1148.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, Point center)
  1149.     {
  1150.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  1151.         DrawRadial(blend, DrawRadialRectangle, center.X, center.Y);
  1152.     }
  1153.     public void DrawRadial(ColorBlend blend, int x, int y, int width, int height, int cx, int cy)
  1154.     {
  1155.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  1156.         DrawRadial(blend, DrawRadialRectangle, cx, cy);
  1157.     }
  1158.  
  1159.     public void DrawRadial(ColorBlend blend, Rectangle r)
  1160.     {
  1161.         DrawRadial(blend, r, r.Width / 2, r.Height / 2);
  1162.     }
  1163.     public void DrawRadial(ColorBlend blend, Rectangle r, Point center)
  1164.     {
  1165.         DrawRadial(blend, r, center.X, center.Y);
  1166.     }
  1167.     public void DrawRadial(ColorBlend blend, Rectangle r, int cx, int cy)
  1168.     {
  1169.         DrawRadialPath.Reset();
  1170.         DrawRadialPath.AddEllipse(r.X, r.Y, r.Width - 1, r.Height - 1);
  1171.  
  1172.         DrawRadialBrush1 = new PathGradientBrush(DrawRadialPath);
  1173.         DrawRadialBrush1.CenterPoint = new Point(r.X + cx, r.Y + cy);
  1174.         DrawRadialBrush1.InterpolationColors = blend;
  1175.  
  1176.         if (G.SmoothingMode == SmoothingMode.AntiAlias)
  1177.         {
  1178.             G.FillEllipse(DrawRadialBrush1, r.X + 1, r.Y + 1, r.Width - 3, r.Height - 3);
  1179.         }
  1180.         else
  1181.         {
  1182.             G.FillEllipse(DrawRadialBrush1, r);
  1183.         }
  1184.     }
  1185.  
  1186.  
  1187.     protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height)
  1188.     {
  1189.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  1190.         DrawRadial(c1, c2, DrawGradientRectangle);
  1191.     }
  1192.     protected void DrawRadial(Color c1, Color c2, int x, int y, int width, int height, float angle)
  1193.     {
  1194.         DrawRadialRectangle = new Rectangle(x, y, width, height);
  1195.         DrawRadial(c1, c2, DrawGradientRectangle, angle);
  1196.     }
  1197.  
  1198.     protected void DrawRadial(Color c1, Color c2, Rectangle r)
  1199.     {
  1200.         DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, 90f);
  1201.         G.FillRectangle(DrawGradientBrush, r);
  1202.     }
  1203.     protected void DrawRadial(Color c1, Color c2, Rectangle r, float angle)
  1204.     {
  1205.         DrawRadialBrush2 = new LinearGradientBrush(r, c1, c2, angle);
  1206.         G.FillEllipse(DrawGradientBrush, r);
  1207.     }
  1208.  
  1209.     #endregion
  1210.  
  1211. }
  1212.  
  1213. public abstract class ThemeControl153 : Control
  1214. {
  1215.  
  1216.  
  1217.     #region " Initialization "
  1218.  
  1219.     protected Graphics G;
  1220.  
  1221.     protected Bitmap B;
  1222.     public ThemeControl153()
  1223.     {
  1224.         SetStyle((ControlStyles)139270, true);
  1225.  
  1226.         _ImageSize = Size.Empty;
  1227.         Font = new Font("Verdana", 8);
  1228.  
  1229.         MeasureBitmap = new Bitmap(1, 1);
  1230.         MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  1231.  
  1232.         DrawRadialPath = new GraphicsPath();
  1233.  
  1234.         InvalidateCustimization();
  1235.         //Remove?
  1236.     }
  1237.  
  1238.     protected override sealed void OnHandleCreated(EventArgs e)
  1239.     {
  1240.         InvalidateCustimization();
  1241.         ColorHook();
  1242.  
  1243.         if (!(_LockWidth == 0))
  1244.             Width = _LockWidth;
  1245.         if (!(_LockHeight == 0))
  1246.             Height = _LockHeight;
  1247.  
  1248.         Transparent = _Transparent;
  1249.         if (_Transparent && _BackColor)
  1250.             BackColor = Color.Transparent;
  1251.  
  1252.         base.OnHandleCreated(e);
  1253.     }
  1254.  
  1255.     protected override sealed void OnParentChanged(EventArgs e)
  1256.     {
  1257.         if (Parent != null)
  1258.             OnCreation();
  1259.         base.OnParentChanged(e);
  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. public enum MouseState : byte
  2062. {
  2063.     None = 0,
  2064.     Over = 1,
  2065.     Down = 2,
  2066.     Block = 3
  2067. }
  2068.  
  2069. public 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