Advertisement
Guest User

Genuine Theme by AeonHack, converted by Chuiby

a guest
Apr 25th, 2011
3,330
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.24 KB | None | 0 0
  1. abstract class Theme : ContainerControl
  2. {
  3.  
  4.     #region " Initialization "
  5.  
  6.     protected Bitmap B;
  7.     protected Graphics G;
  8.     public Theme()
  9.     {
  10.         SetStyle((ControlStyles)8198, true);
  11.         B = new Bitmap(1, 1);
  12.         G = Graphics.FromImage(B);
  13.     }
  14.  
  15.     private bool ParentIsForm;
  16.     protected override void OnHandleCreated(EventArgs e)
  17.     {
  18.         Dock = DockStyle.Fill;
  19.         ParentIsForm = Parent is Form;
  20.         if (ParentIsForm)
  21.             ParentForm.FormBorderStyle = FormBorderStyle.None;
  22.         base.OnHandleCreated(e);
  23.     }
  24.  
  25.     #endregion
  26.  
  27.     #region " Sizing and Movement "
  28.  
  29.     private bool _Resizable = true;
  30.     public bool Resizable
  31.     {
  32.         get { return _Resizable; }
  33.         set { _Resizable = value; }
  34.     }
  35.  
  36.     private int _MoveHeight = 24;
  37.     public int MoveHeight
  38.     {
  39.         get { return _MoveHeight; }
  40.         set
  41.         {
  42.             _MoveHeight = value;
  43.             Header = new Rectangle(7, 7, Width - 14, _MoveHeight);
  44.         }
  45.     }
  46.  
  47.     private IntPtr Flag;
  48.     protected override void OnMouseDown(MouseEventArgs e)
  49.     {
  50.         if (!(e.Button == MouseButtons.Left))
  51.             return;
  52.         if (ParentIsForm)
  53.             if (ParentForm.WindowState == FormWindowState.Maximized)
  54.                 return;
  55.  
  56.         if (Header.Contains(e.Location))
  57.         {
  58.             Flag = new IntPtr(2);
  59.         }
  60.         else if (Current.Position == 0 | !_Resizable)
  61.         {
  62.             return;
  63.         }
  64.         else
  65.         {
  66.             Flag = new IntPtr(Current.Position);
  67.         }
  68.  
  69.         Capture = false;
  70.         Message msg = Message.Create(Parent.Handle, 161, Flag, IntPtr.Zero);
  71.         DefWndProc(ref msg);
  72.  
  73.         base.OnMouseDown(e);
  74.     }
  75.  
  76.     private struct Pointer
  77.     {
  78.         public readonly Cursor Cursor;
  79.         public readonly byte Position;
  80.         public Pointer(Cursor c, byte p)
  81.         {
  82.             Cursor = c;
  83.             Position = p;
  84.         }
  85.     }
  86.  
  87.     private bool F1;
  88.     private bool F2;
  89.     private bool F3;
  90.     private bool F4;
  91.     private Point PTC;
  92.     private Pointer GetPointer()
  93.     {
  94.         PTC = PointToClient(MousePosition);
  95.         F1 = PTC.X < 7;
  96.         F2 = PTC.X > Width - 7;
  97.         F3 = PTC.Y < 7;
  98.         F4 = PTC.Y > Height - 7;
  99.  
  100.         if (F1 & F3)
  101.             return new Pointer(Cursors.SizeNWSE, 13);
  102.         if (F1 & F4)
  103.             return new Pointer(Cursors.SizeNESW, 16);
  104.         if (F2 & F3)
  105.             return new Pointer(Cursors.SizeNESW, 14);
  106.         if (F2 & F4)
  107.             return new Pointer(Cursors.SizeNWSE, 17);
  108.         if (F1)
  109.             return new Pointer(Cursors.SizeWE, 10);
  110.         if (F2)
  111.             return new Pointer(Cursors.SizeWE, 11);
  112.         if (F3)
  113.             return new Pointer(Cursors.SizeNS, 12);
  114.         if (F4)
  115.             return new Pointer(Cursors.SizeNS, 15);
  116.         return new Pointer(Cursors.Default, 0);
  117.     }
  118.  
  119.     private Pointer Current;
  120.     private Pointer Pending;
  121.     private void SetCurrent()
  122.     {
  123.         Pending = GetPointer();
  124.         if (Current.Position == Pending.Position)
  125.             return;
  126.         Current = GetPointer();
  127.         Cursor = Current.Cursor;
  128.     }
  129.  
  130.     protected override void OnMouseMove(MouseEventArgs e)
  131.     {
  132.         if (_Resizable)
  133.             SetCurrent();
  134.         base.OnMouseMove(e);
  135.     }
  136.  
  137.     protected Rectangle Header;
  138.     protected override void OnSizeChanged(EventArgs e)
  139.     {
  140.         Header = new Rectangle(7, 7, Width - 14, _MoveHeight);
  141.         G.Dispose();
  142.         B.Dispose();
  143.         B = new Bitmap(Width, Height);
  144.         G = Graphics.FromImage(B);
  145.         Invalidate();
  146.         base.OnSizeChanged(e);
  147.     }
  148.  
  149.     #endregion
  150.  
  151.     #region " Convienence "
  152.  
  153.     public void SetTransparent(Color c)
  154.     {
  155.         if (ParentIsForm)
  156.             ParentForm.TransparencyKey = c;
  157.     }
  158.  
  159.     protected override abstract void OnPaint(PaintEventArgs e);
  160.  
  161.     public void DrawCorners(Color c, Rectangle rect)
  162.     {
  163.         B.SetPixel(rect.X, rect.Y, c);
  164.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c);
  165.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c);
  166.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c);
  167.     }
  168.  
  169.     public void DrawBorders(Pen p1, Pen p2, Rectangle rect)
  170.     {
  171.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
  172.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3);
  173.     }
  174.  
  175.     private Size TextSize;
  176.     public void DrawText(HorizontalAlignment a, Brush b, int offset = 0)
  177.     {
  178.         if (string.IsNullOrEmpty(Text))
  179.             return;
  180.         TextSize = G.MeasureString(Text, Font).ToSize();
  181.  
  182.         switch (a)
  183.         {
  184.             case HorizontalAlignment.Left:
  185.                 G.DrawString(Text, Font, b, 5 + offset, _MoveHeight / 2 - TextSize.Height / 2 + 7);
  186.                 break;
  187.             case HorizontalAlignment.Right:
  188.                 G.DrawString(Text, Font, b, Width - 5 - TextSize.Width - offset, _MoveHeight / 2 - TextSize.Height / 2 + 7);
  189.                 break;
  190.             case HorizontalAlignment.Center:
  191.                 G.DrawString(Text, Font, b, Width / 2 - TextSize.Width / 2, _MoveHeight / 2 - TextSize.Height / 2 + 7);
  192.                 break;
  193.         }
  194.     }
  195.  
  196.     public int ImageWidth
  197.     {
  198.         get
  199.         {
  200.             if (_Image == null)
  201.                 return 0;
  202.             return _Image.Width;
  203.         }
  204.     }
  205.  
  206.     private Image _Image;
  207.     public Image Image
  208.     {
  209.         get { return _Image; }
  210.         set
  211.         {
  212.             _Image = value;
  213.             Invalidate();
  214.         }
  215.     }
  216.  
  217.     public void DrawIcon(HorizontalAlignment a, int offset = 0)
  218.     {
  219.         if (_Image == null)
  220.             return;
  221.         switch (a)
  222.         {
  223.             case HorizontalAlignment.Left:
  224.                 G.DrawImage(_Image, 5 + offset, _MoveHeight / 2 - _Image.Height / 2 + 7);
  225.                 break;
  226.             case HorizontalAlignment.Right:
  227.                 G.DrawImage(_Image, Width - 5 - TextSize.Width - offset, _MoveHeight / 2 - TextSize.Height / 2 + 7);
  228.                 break;
  229.             case HorizontalAlignment.Center:
  230.                 G.DrawImage(_Image, Width / 2 - TextSize.Width / 2, _MoveHeight / 2 - TextSize.Height / 2 + 7);
  231.                 break;
  232.         }
  233.     }
  234.     #endregion
  235.  
  236. }
  237. abstract class ThemeControl : Control
  238. {
  239.  
  240.     #region " Initialization "
  241.  
  242.     protected Bitmap B;
  243.     protected Graphics G;
  244.     public ThemeControl()
  245.     {
  246.         SetStyle((ControlStyles)8198, true);
  247.         B = new Bitmap(1, 1);
  248.         G = Graphics.FromImage(B);
  249.     }
  250.  
  251.     public void AllowTransparent()
  252.     {
  253.         SetStyle(ControlStyles.Opaque, false);
  254.         SetStyle((ControlStyles)141314, true);
  255.     }
  256.  
  257.     #endregion
  258.  
  259.     #region " Mouse Handling "
  260.  
  261.     public enum State : byte
  262.     {
  263.         MouseNone = 0,
  264.         MouseOver = 1,
  265.         MouseDown = 2
  266.     }
  267.  
  268.     protected State MouseState;
  269.     protected override void OnMouseLeave(EventArgs e)
  270.     {
  271.         ChangeMouseState(State.MouseNone);
  272.         base.OnMouseLeave(e);
  273.     }
  274.     protected override void OnMouseEnter(EventArgs e)
  275.     {
  276.         ChangeMouseState(State.MouseOver);
  277.         base.OnMouseEnter(e);
  278.     }
  279.     protected override void OnMouseUp(MouseEventArgs e)
  280.     {
  281.         ChangeMouseState(State.MouseOver);
  282.         base.OnMouseUp(e);
  283.     }
  284.     protected override void OnMouseDown(MouseEventArgs e)
  285.     {
  286.         if (e.Button == MouseButtons.Left)
  287.             ChangeMouseState(State.MouseDown);
  288.         base.OnMouseDown(e);
  289.     }
  290.  
  291.     private void ChangeMouseState(State e)
  292.     {
  293.         MouseState = e;
  294.         Invalidate();
  295.     }
  296.  
  297.     #endregion
  298.  
  299.     #region " Sizing "
  300.  
  301.     protected override void OnSizeChanged(EventArgs e)
  302.     {
  303.         G.Dispose();
  304.         B.Dispose();
  305.         B = new Bitmap(Width, Height);
  306.         G = Graphics.FromImage(B);
  307.         Invalidate();
  308.         base.OnSizeChanged(e);
  309.     }
  310.  
  311.     #endregion
  312.  
  313.     #region " Convienence "
  314.  
  315.     protected override abstract void OnPaint(PaintEventArgs e);
  316.  
  317.     public void DrawCorners(Color c, Rectangle rect)
  318.     {
  319.         B.SetPixel(rect.X, rect.Y, c);
  320.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c);
  321.         B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c);
  322.         B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c);
  323.     }
  324.  
  325.     public void DrawBorders(Pen p1, Pen p2, Rectangle rect)
  326.     {
  327.         G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
  328.         G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3);
  329.     }
  330.  
  331.     private Size TextSize;
  332.     public void DrawText(HorizontalAlignment a, Brush b, int offset = 0)
  333.     {
  334.         if (string.IsNullOrEmpty(Text))
  335.             return;
  336.         TextSize = G.MeasureString(Text, Font).ToSize();
  337.  
  338.         switch (a)
  339.         {
  340.             case HorizontalAlignment.Left:
  341.                 G.DrawString(Text, Font, b, 5 + offset, Height / 2 - TextSize.Height / 2);
  342.                 break;
  343.             case HorizontalAlignment.Right:
  344.                 G.DrawString(Text, Font, b, Width - 5 - TextSize.Width - offset, Height / 2 - TextSize.Height / 2);
  345.                 break;
  346.             case HorizontalAlignment.Center:
  347.                 G.DrawString(Text, Font, b, Width / 2 - TextSize.Width / 2, Height / 2 - TextSize.Height / 2);
  348.                 break;
  349.         }
  350.     }
  351.  
  352.     public int ImageWidth
  353.     {
  354.         get
  355.         {
  356.             if (_Image == null)
  357.                 return 0;
  358.             return _Image.Width;
  359.         }
  360.     }
  361.  
  362.     private Image _Image;
  363.     public Image Image
  364.     {
  365.         get { return _Image; }
  366.         set
  367.         {
  368.             _Image = value;
  369.             Invalidate();
  370.         }
  371.     }
  372.  
  373.     public void DrawIcon(HorizontalAlignment a, int offset = 0)
  374.     {
  375.         if (_Image == null)
  376.             return;
  377.         switch (a)
  378.         {
  379.             case HorizontalAlignment.Left:
  380.                 G.DrawImage(_Image, Width / 10 + offset, Height / 2 - _Image.Height / 2);
  381.                 break;
  382.             case HorizontalAlignment.Right:
  383.                 G.DrawImage(_Image, Width - (Width / 10) - TextSize.Width - offset, Height / 2 - TextSize.Height / 2);
  384.                 break;
  385.             case HorizontalAlignment.Center:
  386.                 G.DrawImage(_Image, Width / 2 - TextSize.Width / 2, Height / 2 - TextSize.Height / 2);
  387.                 break;
  388.         }
  389.     }
  390.  
  391.     #endregion
  392.  
  393. }
  394.  
  395. class GTheme : Theme
  396. {
  397.  
  398.     public GTheme()
  399.     {
  400.         MoveHeight = 28;
  401.         ForeColor = Color.FromArgb(100, 100, 100);
  402.         SetTransparent(Color.Fuchsia);
  403.  
  404.         C1 = Color.FromArgb(41, 41, 41);
  405.         C2 = Color.FromArgb(25, 25, 25);
  406.  
  407.         P1 = new Pen(Color.FromArgb(58, 58, 58));
  408.         P2 = new Pen(C2);
  409.     }
  410.  
  411.     private Color C1;
  412.     private Color C2;
  413.     private Pen P1;
  414.     private Pen P2;
  415.     private LinearGradientBrush B1;
  416.  
  417.     private Rectangle R1;
  418.     protected override void OnPaint(PaintEventArgs e)
  419.     {
  420.         G.Clear(C1);
  421.  
  422.         R1 = new Rectangle(0, 0, Width, 28);
  423.         B1 = new LinearGradientBrush(R1, C2, C1, LinearGradientMode.Vertical);
  424.         G.FillRectangle(B1, R1);
  425.  
  426.         G.DrawLine(P2, 0, 28, Width, 28);
  427.         G.DrawLine(P1, 0, 29, Width, 29);
  428.  
  429.         DrawText(HorizontalAlignment.Left, new SolidBrush(ForeColor), ImageWidth);
  430.         DrawIcon(HorizontalAlignment.Left);
  431.  
  432.         DrawBorders(Pens.Black, P1, ClientRectangle);
  433.         DrawCorners(Color.Fuchsia, ClientRectangle);
  434.  
  435.         e.Graphics.DrawImage(B, 0, 0);
  436.     }
  437. }
  438. class GButton : ThemeControl
  439. {
  440.  
  441.     private Pen P1;
  442.     private Pen P2;
  443.     private LinearGradientBrush B1;
  444.     private Color C1;
  445.     private Color C2;
  446.  
  447.     private Rectangle R1;
  448.     public GButton()
  449.     {
  450.         AllowTransparent();
  451.         BackColor = Color.FromArgb(41, 41, 41);
  452.         ForeColor = Color.FromArgb(100, 100, 100);
  453.  
  454.         P1 = new Pen(Color.FromArgb(25, 25, 25));
  455.         P2 = new Pen(Color.FromArgb(11, Color.White));
  456.  
  457.         C1 = Color.FromArgb(41, 41, 41);
  458.         C2 = Color.FromArgb(51, 51, 51);
  459.     }
  460.  
  461.     protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
  462.     {
  463.         if (MouseState == State.MouseDown)
  464.         {
  465.             B1 = new LinearGradientBrush(ClientRectangle, C1, C2, LinearGradientMode.Vertical);
  466.         }
  467.         else
  468.         {
  469.             B1 = new LinearGradientBrush(ClientRectangle, C2, C1, LinearGradientMode.Vertical);
  470.         }
  471.  
  472.         G.FillRectangle(B1, ClientRectangle);
  473.  
  474.         DrawText(HorizontalAlignment.Center, new SolidBrush(ForeColor));
  475.         DrawIcon(HorizontalAlignment.Left);
  476.  
  477.         DrawBorders(P1, P2, ClientRectangle);
  478.         DrawCorners(BackColor, ClientRectangle);
  479.  
  480.         e.Graphics.DrawImage(B, 0, 0);
  481.     }
  482. }
  483. class Seperator : ThemeControl
  484. {
  485.  
  486.     public Seperator()
  487.     {
  488.         AllowTransparent();
  489.         BackColor = Color.Transparent;
  490.     }
  491.  
  492.     private Orientation _Direction;
  493.     public Orientation Direction
  494.     {
  495.         get { return _Direction; }
  496.         set
  497.         {
  498.             _Direction = value;
  499.             Invalidate();
  500.         }
  501.     }
  502.  
  503.     private Color _Color1 = Color.FromArgb(90, Color.Black);
  504.     public Color Color1
  505.     {
  506.         get { return _Color1; }
  507.         set
  508.         {
  509.             _Color1 = value;
  510.             Invalidate();
  511.         }
  512.     }
  513.  
  514.     private Color _Color2 = Color.FromArgb(14, Color.White);
  515.     public Color Color2
  516.     {
  517.         get { return _Color2; }
  518.         set
  519.         {
  520.             _Color2 = value;
  521.             Invalidate();
  522.         }
  523.     }
  524.  
  525.     private Rectangle R1;
  526.     private LinearGradientBrush B1;
  527.  
  528.     private int Rotation;
  529.     protected override void OnPaint(PaintEventArgs e)
  530.     {
  531.         G.Clear(BackColor);
  532.  
  533.         if (_Direction == Orientation.Horizontal)
  534.         {
  535.             G.DrawLine(new Pen(_Color1), 0, Height / 2, Width, Height / 2);
  536.             G.DrawLine(new Pen(_Color2), 0, Height / 2 + 1, Width, Height / 2 + 1);
  537.         }
  538.         else
  539.         {
  540.             G.DrawLine(new Pen(_Color1), Width / 2, 0, Width / 2, Height);
  541.             G.DrawLine(new Pen(_Color2), Width / 2 + 1, 0, Width / 2 + 1, Height);
  542.         }
  543.  
  544.         e.Graphics.DrawImage(B, 0, 0);
  545.     }
  546. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement