Scourge

[C#] Complex Theme

Oct 19th, 2012
237
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 33.48 KB | None | 0 0
  1. using System;
  2. using System.IO;
  3. using System.Collections.Generic;
  4. using System.ComponentModel;
  5. using System.Windows.Forms;
  6. using System.Drawing;
  7. using System.Drawing.Drawing2D;
  8. abstract class ThemeContainer151 : ContainerControl
  9. {
  10.     protected Graphics G;
  11.     ThemeContainer151()
  12.     {
  13.         SetStyle((ControlStyles)139270, true);
  14.         _ImageSize = Size.Empty;
  15.         MeasureBitmap = new Bitmap(1, 1);
  16.         MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  17.         Font = new Font("Verdana", 8);
  18.         InvalidateCustimization();
  19.     }
  20.     protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  21.     {
  22.         if (!_LockWidth == 0) width = _LockWidth;
  23.         if (!_LockHeight == 0) height = _LockHeight;
  24.         base.SetBoundsCore(x, y, width, height, specified);
  25.     }
  26.     private Rectangle Header;
  27.     protected override sealed void OnSizeChanged(EventArgs e)
  28.     {
  29.         base.OnSizeChanged(e);
  30.         if (_Movable && !_ControlMode) Header = new Rectangle(7, 7, Width - 14, _MoveHeight - 7);
  31.         Invalidate();
  32.     }
  33.     protected override sealed void OnPaint(PaintEventArgs e)
  34.     {
  35.         if (Width == 0 || Height == 0) return;
  36.         G = e.Graphics;
  37.         PaintHook();
  38.     }
  39.     protected override sealed void OnHandleCreated(EventArgs e)
  40.     {
  41.         InitializeMessages();
  42.         InvalidateCustimization();
  43.         ColorHook();
  44.         _IsParentForm = Parent is Form;
  45.         if (!_ControlMode) Dock = DockStyle.Fill;
  46.         if (!_LockWidth == 0) Width = _LockWidth;
  47.         if (!_LockHeight == 0) Height = _LockHeight;
  48.         if (!BackColorWait == null) BackColor = BackColorWait;
  49.         if (_IsParentForm && !_ControlMode) {
  50.             ParentForm.FormBorderStyle = _BorderStyle;
  51.             ParentForm.TransparencyKey = _TransparencyKey;
  52.         }
  53.         OnCreation();
  54.         base.OnHandleCreated(e);
  55.     }
  56.     protected virtual void OnCreation()
  57.     {
  58.     }
  59.     protected MouseState State;
  60.     private void SetState(MouseState current)
  61.     {
  62.         State = current;
  63.         Invalidate();
  64.     }
  65.     protected override void OnMouseMove(MouseEventArgs e)
  66.     {
  67.         if (_Sizable && !_ControlMode) InvalidateMouse();
  68.         base.OnMouseMove(e);
  69.     }
  70.     protected override void OnEnabledChanged(EventArgs e)
  71.     {
  72.         if (Enabled) SetState(MouseState.None);         else SetState(MouseState.Block);
  73.         base.OnEnabledChanged(e);
  74.     }
  75.     protected override void OnMouseEnter(EventArgs e)
  76.     {
  77.         SetState(MouseState.Over);
  78.         base.OnMouseEnter(e);
  79.     }
  80.     protected override void OnMouseUp(MouseEventArgs e)
  81.     {
  82.         SetState(MouseState.Over);
  83.         base.OnMouseUp(e);
  84.     }
  85.     protected override void OnMouseLeave(EventArgs e)
  86.     {
  87.         SetState(MouseState.None);
  88.         if (_Sizable && !_ControlMode && GetChildAtPoint(PointToClient(MousePosition)) != null) {
  89.             Cursor = Cursors.Default;
  90.             Previous = 0;
  91.         }
  92.         base.OnMouseLeave(e);
  93.     }
  94.     protected override void OnMouseDown(MouseEventArgs e)
  95.     {
  96.         base.OnMouseDown(e);
  97.         if (!e.Button == Windows.Forms.MouseButtons.Left) return;
  98.         SetState(MouseState.Down);
  99.         if (_IsParentForm && ParentForm.WindowState == FormWindowState.Maximized || _ControlMode) return;
  100.         if (_Movable && Header.Contains(e.Location)) {
  101.             Capture = false;
  102.             DefWndProc(Messages(0));
  103.         }
  104.         else if (_Sizable && !Previous == 0) {
  105.             Capture = false;
  106.             DefWndProc(Messages(Previous));
  107.         }
  108.     }
  109.     private Point GetIndexPoint;
  110.     private bool B1;
  111.     private bool B2;
  112.     private bool B3;
  113.     private bool B4;
  114.     private int GetIndex()
  115.     {
  116.         GetIndexPoint = PointToClient(MousePosition);
  117.         B1 = GetIndexPoint.X < 7;
  118.         B2 = GetIndexPoint.X > Width - 7;
  119.         B3 = GetIndexPoint.Y < 7;
  120.         B4 = GetIndexPoint.Y > Height - 7;
  121.         if (B1 && B3) return 4;
  122.         if (B1 && B4) return 7;
  123.         if (B2 && B3) return 5;
  124.         if (B2 && B4) return 8;
  125.         if (B1) return 1;
  126.         if (B2) return 2;
  127.         if (B3) return 3;
  128.         if (B4) return 6;
  129.         return 0;
  130.     }
  131.     private int Current;
  132.     private int Previous;
  133.     private void InvalidateMouse()
  134.     {
  135.         Current = GetIndex();
  136.         if (Current == Previous) return;
  137.         Previous = Current;
  138.         switch (Previous) {
  139.             case 0:
  140.                 Cursor = Cursors.Default;
  141.             case 1:
  142.             case 2:
  143.                 Cursor = Cursors.SizeWE;
  144.             case 3:
  145.             case 6:
  146.                 Cursor = Cursors.SizeNS;
  147.             case 4:
  148.             case 8:
  149.                 Cursor = Cursors.SizeNWSE;
  150.             case 5:
  151.             case 7:
  152.                 Cursor = Cursors.SizeNESW;
  153.         }
  154.     }
  155.     private Message[] Messages = new Message[8];
  156.     private void InitializeMessages()
  157.     {
  158.         Messages(0) = Message.Create(Parent.Handle, 161, new IntPtr(2), IntPtr.Zero);
  159.         for (int I = 1; I <= 8; I++) {
  160.             Messages(I) = Message.Create(Parent.Handle, 161, new IntPtr(I + 9), IntPtr.Zero);
  161.         }
  162.     }
  163.     private Color BackColorWait;
  164.     override Color BackColor {
  165.         get { return base.BackColor; }
  166.         set {
  167.             if (IsHandleCreated) {
  168.                 if (!_ControlMode) Parent.BackColor = value;
  169.                 base.BackColor = value;
  170.             }
  171.             else {
  172.                 BackColorWait = value;
  173.             }
  174.         }
  175.     }
  176.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  177.     override Color ForeColor {
  178.         get { return Color.Empty; }
  179.         set { }
  180.     }
  181.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  182.     override Image BackgroundImage {
  183.         get { return null; }
  184.         set { }
  185.     }
  186.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  187.     override ImageLayout BackgroundImageLayout {
  188.         get { return ImageLayout.None; }
  189.         set { }
  190.     }
  191.     override string Text {
  192.         get { return base.Text; }
  193.         set {
  194.             base.Text = value;
  195.             Invalidate();
  196.         }
  197.     }
  198.     override Font Font {
  199.         get { return base.Font; }
  200.         set {
  201.             base.Font = value;
  202.             Invalidate();
  203.         }
  204.     }
  205.     private bool _Movable = true;
  206.     bool Movable {
  207.         get { return _Movable; }
  208.         set { _Movable = value; }
  209.     }
  210.     private bool _Sizable = true;
  211.     bool Sizable {
  212.         get { return _Sizable; }
  213.         set { _Sizable = value; }
  214.     }
  215.     private int _MoveHeight = 24;
  216.     protected int MoveHeight {
  217.         get { return _MoveHeight; }
  218.         set {
  219.             if (v < 8) return;
  220.             Header = new Rectangle(7, 7, Width - 14, v - 7);
  221.             _MoveHeight = v;
  222.             Invalidate();
  223.         }
  224.     }
  225.     private bool _ControlMode;
  226.     protected bool ControlMode {
  227.         get { return _ControlMode; }
  228.         set { _ControlMode = v; }
  229.     }
  230.     private Color _TransparencyKey;
  231.     Color TransparencyKey {
  232.         get {
  233.             if (_IsParentForm && !_ControlMode) return ParentForm.TransparencyKey;          else return _TransparencyKey;
  234.         }
  235.         set {
  236.             if (_IsParentForm && !_ControlMode) ParentForm.TransparencyKey = value;
  237.             _TransparencyKey = value;
  238.         }
  239.     }
  240.     private FormBorderStyle _BorderStyle;
  241.     FormBorderStyle BorderStyle {
  242.         get {
  243.             if (_IsParentForm && !_ControlMode) return ParentForm.FormBorderStyle;          else return _BorderStyle;
  244.         }
  245.         set {
  246.             if (_IsParentForm && !_ControlMode) ParentForm.FormBorderStyle = value;
  247.             _BorderStyle = value;
  248.         }
  249.     }
  250.     private bool _NoRounding;
  251.     bool NoRounding {
  252.         get { return _NoRounding; }
  253.         set {
  254.             _NoRounding = v;
  255.             Invalidate();
  256.         }
  257.     }
  258.     private Image _Image;
  259.     Image Image {
  260.         get { return _Image; }
  261.         set {
  262.             if (value == null) {
  263.                 _ImageSize = Size.Empty;
  264.             }
  265.             else {
  266.                 _ImageSize = value.Size;
  267.             }
  268.             _Image = value;
  269.             Invalidate();
  270.         }
  271.     }
  272.     private Size _ImageSize;
  273.     protected Size ImageSize {
  274.         get { return _ImageSize; }
  275.     }
  276.     private bool _IsParentForm;
  277.     protected bool IsParentForm {
  278.         get { return _IsParentForm; }
  279.     }
  280.     private int _LockWidth;
  281.     protected int LockWidth {
  282.         get { return _LockWidth; }
  283.         set {
  284.             _LockWidth = value;
  285.             if (!LockWidth == 0 && IsHandleCreated) Width = LockWidth;
  286.         }
  287.     }
  288.     private int _LockHeight;
  289.     protected int LockHeight {
  290.         get { return _LockHeight; }
  291.         set {
  292.             _LockHeight = value;
  293.             if (!LockHeight == 0 && IsHandleCreated) Height = LockHeight;
  294.         }
  295.     }
  296.     private Dictionary<string, Color> Items = new Dictionary<string, Color>();
  297.     [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  298.     Bloom[] Colors {
  299.         get {
  300.             List<Bloom> T = new List<Bloom>();
  301.             Dictionary<string, Color>.Enumerator E = Items.GetEnumerator;
  302.             while (E.MoveNext) {
  303.                 T.Add(new Bloom(E.Current.Key, E.Current.Value));
  304.             }
  305.             return T.ToArray;
  306.         }
  307.         set {
  308.             foreach (Bloom B in value) {
  309.                 if (Items.ContainsKey(B.Name)) Items(B.Name) = B.Value;
  310.             }
  311.             InvalidateCustimization();
  312.             ColorHook();
  313.             Invalidate();
  314.         }
  315.     }
  316.     private string _Customization;
  317.     string Customization {
  318.         get { return _Customization; }
  319.         set {
  320.             if (value == _Customization) return;
  321.             byte[] Data;
  322.             Bloom[] Items = Colors;
  323.             try {
  324.                 Data = Convert.FromBase64String(value);
  325.                 for (int I = 0; I <= Items.Length - 1; I++) {
  326.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
  327.                 }
  328.             }
  329.             catch {
  330.                 return;
  331.             }
  332.             _Customization = value;
  333.             Colors = Items;
  334.             ColorHook();
  335.             Invalidate();
  336.         }
  337.     }
  338.     protected Color GetColor(string name)
  339.     {
  340.         return Items(name);
  341.     }
  342.     protected void SetColor(string name, Color color)
  343.     {
  344.         if (Items.ContainsKey(name)) Items(name) = color;       else Items.Add(name, color);
  345.     }
  346.     protected void SetColor(string name, byte r, byte g, byte b)
  347.     {
  348.         SetColor(name, Color.FromArgb(r, g, b));
  349.     }
  350.     protected void SetColor(string name, byte a, byte r, byte g, byte b)
  351.     {
  352.         SetColor(name, Color.FromArgb(a, r, g, b));
  353.     }
  354.     protected void SetColor(string name, byte a, Color color)
  355.     {
  356.         SetColor(name, color.FromArgb(a, color));
  357.     }
  358.     private void InvalidateCustimization()
  359.     {
  360.         MemoryStream M = new MemoryStream(Items.Count * 4);
  361.         foreach (Bloom B in Colors) {
  362.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4);
  363.         }
  364.         M.Close();
  365.         _Customization = Convert.ToBase64String(M.ToArray);
  366.     }
  367.     protected abstract void ColorHook();
  368.     protected abstract void PaintHook();
  369.     private Point CenterReturn;
  370.     protected Point Center(Rectangle r1, Size s1)
  371.     {
  372.         CenterReturn = new Point((r1.Width / 2 - s1.Width / 2) + r1.X, (r1.Height / 2 - s1.Height / 2) + r1.Y);
  373.         return CenterReturn;
  374.     }
  375.     protected Point Center(Rectangle r1, Rectangle r2)
  376.     {
  377.         return Center(r1, r2.Size);
  378.     }
  379.     protected Point Center(int w1, int h1, int w2, int h2)
  380.     {
  381.         CenterReturn = new Point(w1 / 2 - w2 / 2, h1 / 2 - h2 / 2);
  382.         return CenterReturn;
  383.     }
  384.     protected Point Center(Size s1, Size s2)
  385.     {
  386.         return Center(s1.Width, s1.Height, s2.Width, s2.Height);
  387.     }
  388.     protected Point Center(Rectangle r1)
  389.     {
  390.         return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height);
  391.     }
  392.     protected Point Center(Size s1)
  393.     {
  394.         return Center(Width, Height, s1.Width, s1.Height);
  395.     }
  396.     protected Point Center(int w1, int h1)
  397.     {
  398.         return Center(Width, Height, w1, h1);
  399.     }
  400.     private Bitmap MeasureBitmap;
  401.     private Graphics MeasureGraphics;
  402.     protected Size Measure(string text)
  403.     {
  404.         return MeasureGraphics.MeasureString(text, Font, Width).ToSize;
  405.     }
  406.     protected Size Measure()
  407.     {
  408.         return MeasureGraphics.MeasureString(Text, Font).ToSize;
  409.     }
  410.     private SolidBrush DrawCornersBrush;
  411.     protected void DrawCorners(Color c1)
  412.     {
  413.         DrawCorners(c1, 0, 0, Width, Height);
  414.     }
  415.     protected void DrawCorners(Color c1, Rectangle r1)
  416.     {
  417.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
  418.     }
  419.     protected void DrawCorners(Color c1, int x, int y, int width, int height)
  420.     {
  421.         if (_NoRounding) return;
  422.         DrawCornersBrush = new SolidBrush(c1);
  423.         G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
  424.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
  425.         G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
  426.         G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
  427.     }
  428.     protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
  429.     {
  430.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  431.     }
  432.     protected void DrawBorders(Pen p1, int offset)
  433.     {
  434.         DrawBorders(p1, 0, 0, Width, Height, offset);
  435.     }
  436.     protected void DrawBorders(Pen p1, Rectangle r, int offset)
  437.     {
  438.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
  439.     }
  440.     protected void DrawBorders(Pen p1, int x, int y, int width, int height)
  441.     {
  442.         G.DrawRectangle(p1, x, y, width - 1, height - 1);
  443.     }
  444.     protected void DrawBorders(Pen p1)
  445.     {
  446.         DrawBorders(p1, 0, 0, Width, Height);
  447.     }
  448.     protected void DrawBorders(Pen p1, Rectangle r)
  449.     {
  450.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
  451.     }
  452.     private Point DrawTextPoint;
  453.     private Size DrawTextSize;
  454.     protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
  455.     {
  456.         DrawText(b1, Text, a, x, y);
  457.     }
  458.     protected void DrawText(Brush b1, Point p1)
  459.     {
  460.         DrawText(b1, Text, p1.X, p1.Y);
  461.     }
  462.     protected void DrawText(Brush b1, int x, int y)
  463.     {
  464.         DrawText(b1, Text, x, y);
  465.     }
  466.     protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
  467.     {
  468.         if (text.Length == 0) return;
  469.         DrawTextSize = Measure(text);
  470.         DrawTextPoint = new Point(Width / 2 - DrawTextSize.Width / 2, MoveHeight / 2 - DrawTextSize.Height / 2);
  471.         switch (a) {
  472.             case HorizontalAlignment.Left:
  473.                 DrawText(b1, text, x, DrawTextPoint.Y + y);
  474.             case HorizontalAlignment.Center:
  475.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y);
  476.             case HorizontalAlignment.Right:
  477.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
  478.         }
  479.     }
  480.     protected void DrawText(Brush b1, string text, Point p1)
  481.     {
  482.         DrawText(b1, text, p1.X, p1.Y);
  483.     }
  484.     protected void DrawText(Brush b1, string text, int x, int y)
  485.     {
  486.         if (text.Length == 0) return;
  487.         G.DrawString(text, Font, b1, x, y);
  488.     }
  489.     private Point DrawImagePoint;
  490.     protected void DrawImage(HorizontalAlignment a, int x, int y)
  491.     {
  492.         DrawImage(_Image, a, x, y);
  493.     }
  494.     protected void DrawImage(Point p1)
  495.     {
  496.         DrawImage(_Image, p1.X, p1.Y);
  497.     }
  498.     protected void DrawImage(int x, int y)
  499.     {
  500.         DrawImage(_Image, x, y);
  501.     }
  502.     protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
  503.     {
  504.         if (image == null) return;
  505.         DrawImagePoint = new Point(Width / 2 - image.Width / 2, MoveHeight / 2 - image.Height / 2);
  506.         switch (a) {
  507.             case HorizontalAlignment.Left:
  508.                 DrawImage(image, x, DrawImagePoint.Y + y);
  509.             case HorizontalAlignment.Center:
  510.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y);
  511.             case HorizontalAlignment.Right:
  512.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y);
  513.         }
  514.     }
  515.     protected void DrawImage(Image image, Point p1)
  516.     {
  517.         DrawImage(image, p1.X, p1.Y);
  518.     }
  519.     protected void DrawImage(Image image, int x, int y)
  520.     {
  521.         if (image == null) return;
  522.         G.DrawImage(image, x, y, image.Width, image.Height);
  523.     }
  524.     private LinearGradientBrush DrawGradientBrush;
  525.     private Rectangle DrawGradientRectangle;
  526.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
  527.     {
  528.         DrawGradient(blend, x, y, width, height, 90);
  529.     }
  530.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
  531.     {
  532.         DrawGradient(c1, c2, x, y, width, height, 90);
  533.     }
  534.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
  535.     {
  536.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  537.         DrawGradient(blend, DrawGradientRectangle, angle);
  538.     }
  539.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
  540.     {
  541.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  542.         DrawGradient(c1, c2, DrawGradientRectangle, angle);
  543.     }
  544.     protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
  545.     {
  546.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
  547.         DrawGradientBrush.InterpolationColors = blend;
  548.         G.FillRectangle(DrawGradientBrush, r);
  549.     }
  550.     protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
  551.     {
  552.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
  553.         G.FillRectangle(DrawGradientBrush, r);
  554.     }
  555. }
  556. abstract class ThemeControl151 : Control
  557. {
  558.     protected Graphics G;
  559.     protected Bitmap B;
  560.     ThemeControl151()
  561.     {
  562.         SetStyle((ControlStyles)139270, true);
  563.         _ImageSize = Size.Empty;
  564.         MeasureBitmap = new Bitmap(1, 1);
  565.         MeasureGraphics = Graphics.FromImage(MeasureBitmap);
  566.         Font = new Font("Verdana", 8);
  567.         InvalidateCustimization();
  568.     }
  569.     protected override void SetBoundsCore(int x, int y, int width, int height, BoundsSpecified specified)
  570.     {
  571.         if (!_LockWidth == 0) width = _LockWidth;
  572.         if (!_LockHeight == 0) height = _LockHeight;
  573.         base.SetBoundsCore(x, y, width, height, specified);
  574.     }
  575.     protected override sealed void OnSizeChanged(EventArgs e)
  576.     {
  577.         if (_Transparent && !(Width == 0 || Height == 0)) {
  578.             B = new Bitmap(Width, Height);
  579.             G = Graphics.FromImage(B);
  580.         }
  581.         Invalidate();
  582.         base.OnSizeChanged(e);
  583.     }
  584.     protected override sealed void OnPaint(PaintEventArgs e)
  585.     {
  586.         if (Width == 0 || Height == 0) return;
  587.         if (_Transparent) {
  588.             PaintHook();
  589.             e.Graphics.DrawImage(B, 0, 0);
  590.         }
  591.         else {
  592.             G = e.Graphics;
  593.             PaintHook();
  594.         }
  595.     }
  596.     protected override void OnHandleCreated(EventArgs e)
  597.     {
  598.         InvalidateCustimization();
  599.         ColorHook();
  600.         if (!_LockWidth == 0) Width = _LockWidth;
  601.         if (!_LockHeight == 0) Height = _LockHeight;
  602.         if (!BackColorWait == null) BackColor = BackColorWait;
  603.         OnCreation();
  604.         base.OnHandleCreated(e);
  605.     }
  606.     protected virtual void OnCreation()
  607.     {
  608.     }
  609.     protected override void OnMouseEnter(EventArgs e)
  610.     {
  611.         SetState(MouseState.Over);
  612.         base.OnMouseEnter(e);
  613.     }
  614.     protected override void OnMouseUp(MouseEventArgs e)
  615.     {
  616.         SetState(MouseState.Over);
  617.         base.OnMouseUp(e);
  618.     }
  619.     protected override void OnMouseDown(MouseEventArgs e)
  620.     {
  621.         if (e.Button == Windows.Forms.MouseButtons.Left) SetState(MouseState.Down);
  622.         base.OnMouseDown(e);
  623.     }
  624.     protected override void OnMouseLeave(EventArgs e)
  625.     {
  626.         SetState(MouseState.None);
  627.         base.OnMouseLeave(e);
  628.     }
  629.     protected override void OnEnabledChanged(EventArgs e)
  630.     {
  631.         if (Enabled) SetState(MouseState.None);         else SetState(MouseState.Block);
  632.         base.OnEnabledChanged(e);
  633.     }
  634.     protected MouseState State;
  635.     private void SetState(MouseState current)
  636.     {
  637.         State = current;
  638.         Invalidate();
  639.     }
  640.     private Color BackColorWait;
  641.     override Color BackColor {
  642.         get { return base.BackColor; }
  643.         set {
  644.             if (IsHandleCreated) {
  645.                 base.BackColor = value;
  646.             }
  647.             else {
  648.                 BackColorWait = value;
  649.             }
  650.         }
  651.     }
  652.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  653.     override Color ForeColor {
  654.         get { return Color.Empty; }
  655.         set { }
  656.     }
  657.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  658.     override Image BackgroundImage {
  659.         get { return null; }
  660.         set { }
  661.     }
  662.     [Browsable(false), EditorBrowsable(EditorBrowsableState.Never), DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
  663.     override ImageLayout BackgroundImageLayout {
  664.         get { return ImageLayout.None; }
  665.         set { }
  666.     }
  667.     override string Text {
  668.         get { return base.Text; }
  669.         set {
  670.             base.Text = value;
  671.             Invalidate();
  672.         }
  673.     }
  674.     override Font Font {
  675.         get { return base.Font; }
  676.         set {
  677.             base.Font = value;
  678.             Invalidate();
  679.         }
  680.     }
  681.     private bool _NoRounding;
  682.     bool NoRounding {
  683.         get { return _NoRounding; }
  684.         set {
  685.             _NoRounding = v;
  686.             Invalidate();
  687.         }
  688.     }
  689.     private Image _Image;
  690.     Image Image {
  691.         get { return _Image; }
  692.         set {
  693.             if (value == null) {
  694.                 _ImageSize = Size.Empty;
  695.             }
  696.             else {
  697.                 _ImageSize = value.Size;
  698.             }
  699.             _Image = value;
  700.             Invalidate();
  701.         }
  702.     }
  703.     private Size _ImageSize;
  704.     protected Size ImageSize {
  705.         get { return _ImageSize; }
  706.     }
  707.     private int _LockWidth;
  708.     protected int LockWidth {
  709.         get { return _LockWidth; }
  710.         set {
  711.             _LockWidth = value;
  712.             if (!LockWidth == 0 && IsHandleCreated) Width = LockWidth;
  713.         }
  714.     }
  715.     private int _LockHeight;
  716.     protected int LockHeight {
  717.         get { return _LockHeight; }
  718.         set {
  719.             _LockHeight = value;
  720.             if (!LockHeight == 0 && IsHandleCreated) Height = LockHeight;
  721.         }
  722.     }
  723.     private bool _Transparent;
  724.     bool Transparent {
  725.         get { return _Transparent; }
  726.         set {
  727.             if (!value && !BackColor.A == 255) {
  728.                 throw new Exception("Unable to change value to false while a transparent BackColor is in use.");
  729.             }
  730.             SetStyle(ControlStyles.Opaque, !value);
  731.             SetStyle(ControlStyles.SupportsTransparentBackColor, value);
  732.             if (value) InvalidateBitmap();          else B = null;
  733.             _Transparent = value;
  734.             Invalidate();
  735.         }
  736.     }
  737.     private Dictionary<string, Color> Items = new Dictionary<string, Color>();
  738.     [DesignerSerializationVisibility(DesignerSerializationVisibility.Content)]
  739.     Bloom[] Colors {
  740.         get {
  741.             List<Bloom> T = new List<Bloom>();
  742.             Dictionary<string, Color>.Enumerator E = Items.GetEnumerator;
  743.             while (E.MoveNext) {
  744.                 T.Add(new Bloom(E.Current.Key, E.Current.Value));
  745.             }
  746.             return T.ToArray;
  747.         }
  748.         set {
  749.             foreach (Bloom B in value) {
  750.                 if (Items.ContainsKey(B.Name)) Items(B.Name) = B.Value;
  751.             }
  752.             InvalidateCustimization();
  753.             ColorHook();
  754.             Invalidate();
  755.         }
  756.     }
  757.     private string _Customization;
  758.     string Customization {
  759.         get { return _Customization; }
  760.         set {
  761.             if (value == _Customization) return;
  762.             byte[] Data;
  763.             Bloom[] Items = Colors;
  764.             try {
  765.                 Data = Convert.FromBase64String(value);
  766.                 for (int I = 0; I <= Items.Length - 1; I++) {
  767.                     Items(I).Value = Color.FromArgb(BitConverter.ToInt32(Data, I * 4));
  768.                 }
  769.             }
  770.             catch {
  771.                 return;
  772.             }
  773.             _Customization = value;
  774.             Colors = Items;
  775.             ColorHook();
  776.             Invalidate();
  777.         }
  778.     }
  779.     private void InvalidateBitmap()
  780.     {
  781.         if (Width == 0 || Height == 0) return;
  782.         B = new Bitmap(Width, Height);
  783.         G = Graphics.FromImage(B);
  784.     }
  785.     protected Color GetColor(string name)
  786.     {
  787.         return Items(name);
  788.     }
  789.     protected void SetColor(string name, Color color)
  790.     {
  791.         if (Items.ContainsKey(name)) Items(name) = color;       else Items.Add(name, color);
  792.     }
  793.     protected void SetColor(string name, byte r, byte g, byte b)
  794.     {
  795.         SetColor(name, Color.FromArgb(r, g, b));
  796.     }
  797.     protected void SetColor(string name, byte a, byte r, byte g, byte b)
  798.     {
  799.         SetColor(name, Color.FromArgb(a, r, g, b));
  800.     }
  801.     protected void SetColor(string name, byte a, Color color)
  802.     {
  803.         SetColor(name, color.FromArgb(a, color));
  804.     }
  805.     private void InvalidateCustimization()
  806.     {
  807.         MemoryStream M = new MemoryStream(Items.Count * 4);
  808.         foreach (Bloom B in Colors) {
  809.             M.Write(BitConverter.GetBytes(B.Value.ToArgb), 0, 4);
  810.         }
  811.         M.Close();
  812.         _Customization = Convert.ToBase64String(M.ToArray);
  813.     }
  814.     protected abstract void ColorHook();
  815.     protected abstract void PaintHook();
  816.     private Point CenterReturn;
  817.     protected Point Center(Rectangle r1, Size s1)
  818.     {
  819.         CenterReturn = new Point((r1.Width / 2 - s1.Width / 2) + r1.X, (r1.Height / 2 - s1.Height / 2) + r1.Y);
  820.         return CenterReturn;
  821.     }
  822.     protected Point Center(Rectangle r1, Rectangle r2)
  823.     {
  824.         return Center(r1, r2.Size);
  825.     }
  826.     protected Point Center(int w1, int h1, int w2, int h2)
  827.     {
  828.         CenterReturn = new Point(w1 / 2 - w2 / 2, h1 / 2 - h2 / 2);
  829.         return CenterReturn;
  830.     }
  831.     protected Point Center(Size s1, Size s2)
  832.     {
  833.         return Center(s1.Width, s1.Height, s2.Width, s2.Height);
  834.     }
  835.     protected Point Center(Rectangle r1)
  836.     {
  837.         return Center(ClientRectangle.Width, ClientRectangle.Height, r1.Width, r1.Height);
  838.     }
  839.     protected Point Center(Size s1)
  840.     {
  841.         return Center(Width, Height, s1.Width, s1.Height);
  842.     }
  843.     protected Point Center(int w1, int h1)
  844.     {
  845.         return Center(Width, Height, w1, h1);
  846.     }
  847.     private Bitmap MeasureBitmap;
  848.     private Graphics MeasureGraphics;
  849.     protected Size Measure(string text)
  850.     {
  851.         return MeasureGraphics.MeasureString(text, Font, Width).ToSize;
  852.     }
  853.     protected Size Measure()
  854.     {
  855.         return MeasureGraphics.MeasureString(Text, Font, Width).ToSize;
  856.     }
  857.     private SolidBrush DrawCornersBrush;
  858.     protected void DrawCorners(Color c1)
  859.     {
  860.         DrawCorners(c1, 0, 0, Width, Height);
  861.     }
  862.     protected void DrawCorners(Color c1, Rectangle r1)
  863.     {
  864.         DrawCorners(c1, r1.X, r1.Y, r1.Width, r1.Height);
  865.     }
  866.     protected void DrawCorners(Color c1, int x, int y, int width, int height)
  867.     {
  868.         if (_NoRounding) return;
  869.         if (_Transparent) {
  870.             B.SetPixel(x, y, c1);
  871.             B.SetPixel(x + (width - 1), y, c1);
  872.             B.SetPixel(x, y + (height - 1), c1);
  873.             B.SetPixel(x + (width - 1), y + (height - 1), c1);
  874.         }
  875.         else {
  876.             DrawCornersBrush = new SolidBrush(c1);
  877.             G.FillRectangle(DrawCornersBrush, x, y, 1, 1);
  878.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y, 1, 1);
  879.             G.FillRectangle(DrawCornersBrush, x, y + (height - 1), 1, 1);
  880.             G.FillRectangle(DrawCornersBrush, x + (width - 1), y + (height - 1), 1, 1);
  881.         }
  882.     }
  883.     protected void DrawBorders(Pen p1, int x, int y, int width, int height, int offset)
  884.     {
  885.         DrawBorders(p1, x + offset, y + offset, width - (offset * 2), height - (offset * 2));
  886.     }
  887.     protected void DrawBorders(Pen p1, int offset)
  888.     {
  889.         DrawBorders(p1, 0, 0, Width, Height, offset);
  890.     }
  891.     protected void DrawBorders(Pen p1, Rectangle r, int offset)
  892.     {
  893.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height, offset);
  894.     }
  895.     protected void DrawBorders(Pen p1, int x, int y, int width, int height)
  896.     {
  897.         G.DrawRectangle(p1, x, y, width - 1, height - 1);
  898.     }
  899.     protected void DrawBorders(Pen p1)
  900.     {
  901.         DrawBorders(p1, 0, 0, Width, Height);
  902.     }
  903.     protected void DrawBorders(Pen p1, Rectangle r)
  904.     {
  905.         DrawBorders(p1, r.X, r.Y, r.Width, r.Height);
  906.     }
  907.     private Point DrawTextPoint;
  908.     private Size DrawTextSize;
  909.     protected void DrawText(Brush b1, HorizontalAlignment a, int x, int y)
  910.     {
  911.         DrawText(b1, Text, a, x, y);
  912.     }
  913.     protected void DrawText(Brush b1, Point p1)
  914.     {
  915.         DrawText(b1, Text, p1.X, p1.Y);
  916.     }
  917.     protected void DrawText(Brush b1, int x, int y)
  918.     {
  919.         DrawText(b1, Text, x, y);
  920.     }
  921.     protected void DrawText(Brush b1, string text, HorizontalAlignment a, int x, int y)
  922.     {
  923.         if (text.Length == 0) return;
  924.         DrawTextSize = Measure(text);
  925.         DrawTextPoint = Center(DrawTextSize);
  926.         switch (a) {
  927.             case HorizontalAlignment.Left:
  928.                 DrawText(b1, text, x, DrawTextPoint.Y + y);
  929.             case HorizontalAlignment.Center:
  930.                 DrawText(b1, text, DrawTextPoint.X + x, DrawTextPoint.Y + y);
  931.             case HorizontalAlignment.Right:
  932.                 DrawText(b1, text, Width - DrawTextSize.Width - x, DrawTextPoint.Y + y);
  933.         }
  934.     }
  935.     protected void DrawText(Brush b1, string text, Point p1)
  936.     {
  937.         DrawText(b1, text, p1.X, p1.Y);
  938.     }
  939.     protected void DrawText(Brush b1, string text, int x, int y)
  940.     {
  941.         if (text.Length == 0) return;
  942.         G.DrawString(text, Font, b1, x, y);
  943.     }
  944.     private Point DrawImagePoint;
  945.     protected void DrawImage(HorizontalAlignment a, int x, int y)
  946.     {
  947.         DrawImage(_Image, a, x, y);
  948.     }
  949.     protected void DrawImage(Point p1)
  950.     {
  951.         DrawImage(_Image, p1.X, p1.Y);
  952.     }
  953.     protected void DrawImage(int x, int y)
  954.     {
  955.         DrawImage(_Image, x, y);
  956.     }
  957.     protected void DrawImage(Image image, HorizontalAlignment a, int x, int y)
  958.     {
  959.         if (image == null) return;
  960.         DrawImagePoint = Center(image.Size);
  961.         switch (a) {
  962.             case HorizontalAlignment.Left:
  963.                 DrawImage(image, x, DrawImagePoint.Y + y);
  964.             case HorizontalAlignment.Center:
  965.                 DrawImage(image, DrawImagePoint.X + x, DrawImagePoint.Y + y);
  966.             case HorizontalAlignment.Right:
  967.                 DrawImage(image, Width - image.Width - x, DrawImagePoint.Y + y);
  968.         }
  969.     }
  970.     protected void DrawImage(Image image, Point p1)
  971.     {
  972.         DrawImage(image, p1.X, p1.Y);
  973.     }
  974.     protected void DrawImage(Image image, int x, int y)
  975.     {
  976.         if (image == null) return;
  977.         G.DrawImage(image, x, y, image.Width, image.Height);
  978.     }
  979.     private LinearGradientBrush DrawGradientBrush;
  980.     private Rectangle DrawGradientRectangle;
  981.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height)
  982.     {
  983.         DrawGradient(blend, x, y, width, height, 90);
  984.     }
  985.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height)
  986.     {
  987.         DrawGradient(c1, c2, x, y, width, height, 90);
  988.     }
  989.     protected void DrawGradient(ColorBlend blend, int x, int y, int width, int height, float angle)
  990.     {
  991.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  992.         DrawGradient(blend, DrawGradientRectangle, angle);
  993.     }
  994.     protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
  995.     {
  996.         DrawGradientRectangle = new Rectangle(x, y, width, height);
  997.         DrawGradient(c1, c2, DrawGradientRectangle, angle);
  998.     }
  999.     protected void DrawGradient(ColorBlend blend, Rectangle r, float angle)
  1000.     {
  1001.         DrawGradientBrush = new LinearGradientBrush(r, Color.Empty, Color.Empty, angle);
  1002.         DrawGradientBrush.InterpolationColors = blend;
  1003.         G.FillRectangle(DrawGradientBrush, r);
  1004.     }
  1005.     protected void DrawGradient(Color c1, Color c2, Rectangle r, float angle)
  1006.     {
  1007.         DrawGradientBrush = new LinearGradientBrush(r, c1, c2, angle);
  1008.         G.FillRectangle(DrawGradientBrush, r);
  1009.     }
  1010. }
  1011. class ComplexTheme : ThemeContainer151
  1012. {
  1013.     protected override void ColorHook()
  1014.     {
  1015.     }
  1016.     ComplexTheme()
  1017.     {
  1018.         MoveHeight = 28;
  1019.     }
  1020.     protected override void PaintHook()
  1021.     {
  1022.         Drawing2D.HatchBrush hb2 = new Drawing2D.HatchBrush(Drawing2D.HatchStyle.Trellis, Color.FromArgb(15, 15, 15));
  1023.         SolidBrush sb1 = new SolidBrush(Color.LightGray);
  1024.         SolidBrush sb3 = new SolidBrush(Color.White);
  1025.         SolidBrush sb2 = new SolidBrush(Color.FromArgb(35, 35, 35));
  1026.         G.Clear(Color.LightGray);
  1027.         G.DrawRectangle(new Pen(new SolidBrush(Color.LightGray)), new Rectangle(0, 0, Width, 28));
  1028.         G.FillRectangle(sb1, new Rectangle(0, 0, Width, 28));
  1029.         G.DrawString(Text, Font, Brushes.Black, new Point(5, 8));
  1030.         Font SubFont = new Font(DefaultFont.FontFamily, Font.Size - 1);
  1031.         G.DrawRectangle(Pens.LightGray, new Rectangle(0, 0, Width - 1, Height - 1));
  1032.         G.FillRectangle(sb3, new Rectangle(8, 28, Width - 16, Height - 35));
  1033.         DrawCorners(Color.White);
  1034.     }
  1035. }
  1036. class ComplexButton : ThemeControl151
  1037. {
  1038.     protected override void ColorHook()
  1039.     {
  1040.     }
  1041.     private Brush B1;
  1042.     private Brush B2;
  1043.     private Brush B3;
  1044.     protected override void PaintHook()
  1045.     {
  1046.         B1 = new SolidBrush(Color.FromArgb(50, Color.Gray));
  1047.         B2 = new SolidBrush(Color.FromArgb(50, Color.LightGray));
  1048.         B3 = new SolidBrush(Color.FromArgb(50, Color.DarkGray));
  1049.         G.Clear(BackColor);
  1050.         switch (State) {
  1051.             case MouseState.None:
  1052.                 G.FillRectangle(B1, ClientRectangle);
  1053.             case MouseState.Over:
  1054.                 G.FillRectangle(B2, ClientRectangle);
  1055.             case MouseState.Down:
  1056.                 G.FillRectangle(B3, ClientRectangle);
  1057.         }
  1058.         G.DrawString(Text, Font, Brushes.Black, new Point((int)(this.Width / 2) - (Measure(Text).Width / 2), (int)(this.Height / 2) - (Measure(Text).Height / 2)));
  1059.         G.DrawRectangle(Pens.LightGray, new Rectangle(0, 0, Width - 1, Height - 1));
  1060.         DrawCorners(Color.White);
  1061.     }
  1062. }
  1063. class ComplexTopButton : ThemeControl151
  1064. {
  1065.     protected override void ColorHook()
  1066.     {
  1067.     }
  1068.     private Brush B1;
  1069.     private Brush B2;
  1070.     private Brush B3;
  1071.     protected override void PaintHook()
  1072.     {
  1073.         B1 = new SolidBrush(Color.FromArgb(50, Color.Gray));
  1074.         B2 = new SolidBrush(Color.FromArgb(50, Color.LightGray));
  1075.         B3 = new SolidBrush(Color.FromArgb(50, Color.DarkGray));
  1076.         G.Clear(BackColor);
  1077.         switch (State) {
  1078.             case MouseState.None:
  1079.                 G.FillRectangle(B1, ClientRectangle);
  1080.             case MouseState.Over:
  1081.                 G.FillRectangle(B2, ClientRectangle);
  1082.             case MouseState.Down:
  1083.                 G.FillRectangle(B3, ClientRectangle);
  1084.         }
  1085.         G.DrawString(Text, Font, Brushes.Black, new Point((int)(this.Width / 2) - (Measure(Text).Width / 2), (int)(this.Height / 2) - (Measure(Text).Height / 2)));
  1086.         G.DrawRectangle(Pens.LightGray, new Rectangle(0, 0, Width - 1, Height - 1));
  1087.     }
  1088. }
  1089. class ComplexProgressBar : ThemeControl151
  1090. {
  1091.     private int _Maximum = 100;
  1092.     public int Maximum {
  1093.         get { return _Maximum; }
  1094.         set {
  1095.             if (value < 1) value = 1;
  1096.             if (value < _Value) _Value = value;
  1097.             _Maximum = value;
  1098.             Invalidate();
  1099.         }
  1100.     }
  1101.     private int _Value = 50;
  1102.     public int Value {
  1103.         get { return _Value; }
  1104.         set {
  1105.             if (value > _Maximum) value = _Maximum;
  1106.             _Value = value;
  1107.             Invalidate();
  1108.         }
  1109.     }
  1110.     private Color C2;
  1111.     private Pen P1;
  1112.     private Brush B1;
  1113.     private Brush B2;
  1114.     private Brush B3;
  1115.     ComplexProgressBar()
  1116.     {
  1117.         Size = new Size(75, 18);
  1118.     }
  1119.     protected override void ColorHook()
  1120.     {
  1121.         C2 = Color.LightGray;
  1122.         P1 = Pens.LightGray;
  1123.     }
  1124.     protected override void PaintHook()
  1125.     {
  1126.         B1 = new SolidBrush(Color.FromArgb(50, Color.Gray));
  1127.         B2 = new SolidBrush(Color.FromArgb(50, Color.LightGray));
  1128.         B3 = new SolidBrush(Color.FromArgb(50, Color.DarkGray));
  1129.         G.Clear(C2);
  1130.         if ((_Value > 0)) {
  1131.             G.FillRectangle(B3, 0, 0, (int)(_Value / _Maximum) * Width, Height);
  1132.         }
  1133.         DrawBorders(P1, 0, 0, Width, Height);
  1134.         DrawCorners(Color.White);
  1135.     }
  1136. }
  1137. class ComplexGroupBox : ThemeContainer151
  1138. {
  1139.     private Color C1;
  1140.     private Color C2;
  1141.     private Color C3;
  1142.     private Pen P1;
  1143.     private Brush B1;
  1144.     private Brush B2;
  1145.     private Brush B3;
  1146.     private Brush B0;
  1147.     private Brush B8;
  1148.     private Brush HB1;
  1149.     ComplexGroupBox()
  1150.     {
  1151.         ControlMode = true;
  1152.         Size = new Size(205, 95);
  1153.     }
  1154.     protected override void ColorHook()
  1155.     {
  1156.         C1 = Color.White;
  1157.         C2 = Color.FromArgb(50, 50, 50);
  1158.         C3 = Color.FromArgb(0, 0, 0);
  1159.         P1 = Pens.LightGray;
  1160.         B0 = new SolidBrush(Color.FromArgb(60, Color.White));
  1161.         B8 = new SolidBrush(Color.Black);
  1162.         B2 = new SolidBrush(Color.White);
  1163.     }
  1164.     protected override void PaintHook()
  1165.     {
  1166.         B1 = new SolidBrush(Color.FromArgb(50, Color.Gray));
  1167.         B2 = new SolidBrush(Color.FromArgb(50, Color.LightGray));
  1168.         B3 = new SolidBrush(Color.FromArgb(50, Color.DarkGray));
  1169.         G.Clear(C1);
  1170.         G.FillRectangle(B0, 0, 0, Width, Height);
  1171.         G.FillRectangle(B0, 0, 0, Width, 15);
  1172.         G.DrawRectangle(P1, 0, 15, Width - 1, (int)Height - 16);
  1173.         G.FillRectangle(B3, 0, 15, Width, 20);
  1174.         G.FillRectangle(B3, 0, 15, Width, 20);
  1175.         DrawText(B8, HorizontalAlignment.Left, 3, 13);
  1176.         DrawCorners(Color.White);
  1177.     }
  1178. }
  1179. enum MouseState : byte
  1180. {
  1181.     None = 0,
  1182.     Over = 1,
  1183.     Down = 2,
  1184.     Block = 3
  1185. }
  1186. class Bloom
  1187. {
  1188.     private string _Name;
  1189.     string Name {
  1190.         get { return _Name; }
  1191.         set { _Name = value; }
  1192.     }
  1193.     private Color _Value;
  1194.     Color Value {
  1195.         get { return _Value; }
  1196.         set { _Value = value; }
  1197.     }
  1198.     Bloom()
  1199.     {
  1200.     }
  1201.     Bloom(string name, Color value)
  1202.     {
  1203.         _Name = name;
  1204.         _Value = value;
  1205.     }
  1206. }
  1207.  
  1208.  
  1209. //Converted By: CodeConverter 2011 Conversion Utility!
Advertisement
Add Comment
Please, Sign In to add comment