ImaFoSho

[C#] Simpl Theme

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