Nikey646

AeroRev9's Aevion Theme [C#]

Dec 31st, 2014
438
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 14.50 KB | None | 0 0
  1. using System;
  2. using System.Linq;
  3. using System.Drawing;
  4. using System.Windows.Forms;
  5. using System.Drawing.Drawing2D;
  6.  
  7. namespace Aevion_r2
  8. {
  9.  
  10.     public static class Helper
  11.     {
  12.         public struct Fonts
  13.         {
  14.             public static Font Primary = new Font("Segoe UI", 9);
  15.             public static Font PrimaryBold = new Font("Segoe UI", 9, FontStyle.Bold);
  16.         }
  17.  
  18.         public struct Colors
  19.         {
  20.             public static Color Foreground = Color.White;
  21.             public static Color Background = Color.FromArgb(48, 57, 65);
  22.         }
  23.  
  24.  
  25.         public enum MouseState : byte
  26.         {
  27.             None = 0,
  28.             Hover = 1,
  29.             Down = 2
  30.         }
  31.  
  32.         public enum Direction : byte
  33.         {
  34.             Up = 0,
  35.             Down = 1,
  36.             Left = 3,
  37.             Right = 4
  38.         }
  39.  
  40.         public static void RoundRect(Graphics g, Int32 x, Int32 y, Int32 Width, Int32 Height, Int32 Curve, Color c)
  41.         {
  42.             if (Curve <= 0) throw new ArgumentException("Curve must be Greater than 0.", "Curve");
  43.  
  44.             var p = new Pen(c);
  45.  
  46.             var BaseRect = new RectangleF(x, y, Width, Height);
  47.             var ArcRect = new RectangleF(BaseRect.Location, new SizeF(Curve, Curve));
  48.  
  49.             g.DrawArc(p, ArcRect, 180, 90);
  50.             g.DrawLine(p, x + (Curve / 2), y, y + Width - (Curve / 2), y);
  51.  
  52.             ArcRect.X = BaseRect.Right - Curve;
  53.             g.DrawArc(p, ArcRect, 270, 90);
  54.             g.DrawLine(p, x + Width, y + (Curve / 2), x + Width, y + Height - (Curve / 2));
  55.  
  56.             ArcRect.Y = BaseRect.Bottom - Curve;
  57.             g.DrawArc(p, ArcRect, 0, 90);
  58.             g.DrawLine(p, x + (Curve / 2), y + Height, x + Width - (Curve / 2), y + Height);
  59.  
  60.             ArcRect.X = BaseRect.Left;
  61.             g.DrawArc(p, ArcRect, 90, 30);
  62.             g.DrawLine(p, x, y + (Curve / 2), x, y + Height - (Curve / 2));
  63.  
  64.             p.Dispose();
  65.         }
  66.  
  67.         public static void DrawTriangle(Graphics g, Rectangle r, Direction d, Color c)
  68.         {
  69.             var w = r.Width/2;
  70.             var y = r.Height/2;
  71.  
  72.             Point p0 = Point.Empty, p1 = Point.Empty, p2 = Point.Empty;
  73.  
  74.             switch (d)
  75.             {
  76.                 case Direction.Up:
  77.                     p0 = new Point(r.Left + w, r.Top);
  78.                     p1 = new Point(r.Left, r.Bottom);
  79.                     p2 = new Point(r.Right, r.Bottom);
  80.                     break;
  81.  
  82.                 case Direction.Down:
  83.                     p0 = new Point(r.Left + w, r.Bottom);
  84.                     p1 = new Point(r.Left, r.Top);
  85.                     p2 = new Point(r.Right, r.Top);
  86.                     break;
  87.  
  88.                 case Direction.Left:
  89.                     p0 = new Point(r.Left, r.Top + y);
  90.                     p1 = new Point(r.Right, r.Top);
  91.                     p2 = new Point(r.Right, r.Bottom);
  92.                     break;
  93.  
  94.                 case Direction.Right:
  95.                     p0 = new Point(r.Right, r.Top + y);
  96.                     p1 = new Point(r.Left, r.Bottom);
  97.                     p2 = new Point(r.Left, r.Top);
  98.                     break;
  99.             }
  100.  
  101.             var s = new SolidBrush(c);
  102.             g.FillPolygon(s, new [] {p0, p1, p2});
  103.  
  104.             MultiDispose(s);
  105.         }
  106.  
  107.         public static void CenterString(Graphics g, String Text, Font Font, Color c, Rectangle rect, Boolean Shadow = false, Int32 yOffset = 1)
  108.         {
  109.             CenterString(g, Text, Font, new SolidBrush(c), rect, Shadow, yOffset);
  110.         }
  111.  
  112.         public static void CenterString(Graphics g, String Text, Font Font, Brush b, Rectangle rect, Boolean Shadow = false, Int32 yOffset = 1)
  113.         {
  114.             var TextSize = g.MeasureString(Text, Font);
  115.             var x = rect.X + (rect.Width / 2) - (TextSize.Width / 2);
  116.             var y = rect.Y + (rect.Height / 2) - (TextSize.Height / 2) + yOffset;
  117.  
  118.             if (Shadow)
  119.                 g.DrawString(Text, Font, Brushes.Black, x + 1, y + 1);
  120.             g.DrawString(Text, Font, b, x, y);
  121.  
  122.             b.Dispose();
  123.         }
  124.  
  125.         public static Single ValueToPercentage(Int32 Value, Int32 Maximum, Int32 Minimum)
  126.         {
  127.             return (Single)(Value - Minimum) / (Maximum - Minimum);
  128.         }
  129.  
  130.         public static void MultiDispose(params IDisposable[] Disposables)
  131.         {
  132.             foreach (var Disposable in Disposables.Where(Disposable => Disposable != null))
  133.             {
  134.                 Disposable.Dispose();
  135.             }
  136.         }
  137.     }
  138.  
  139.     sealed class AevionForm : Control
  140.     {
  141.         public AevionForm()
  142.         {
  143.             DoubleBuffered = true;
  144.             Font = Helper.Fonts.Primary;
  145.             ForeColor = Helper.Colors.Foreground;
  146.             BackColor = Helper.Colors.Background;
  147.             Dock = DockStyle.Fill;
  148.         }
  149.  
  150.         protected override void OnPaint(PaintEventArgs e)
  151.         {
  152.             base.OnPaint(e);
  153.             var g = e.Graphics;
  154.             g.SmoothingMode=SmoothingMode.HighQuality;
  155.             g.Clear(Helper.Colors.Background);
  156.         }
  157.  
  158.     }
  159.  
  160.     sealed class AevionButton : Button
  161.     {
  162.         private Helper.MouseState State = Helper.MouseState.None;
  163.         private LinearGradientBrush l1, l2, l3 = null;
  164.  
  165.         public enum Style
  166.         {
  167.             Default,
  168.             Green,
  169.             Red
  170.         }
  171.  
  172.         private Style _ButtonStyle = Style.Default;
  173.         private Image _Icon;
  174.         private Boolean _ShowIcon = false;
  175.  
  176.         public Style ButtonStyle
  177.         {
  178.             get { return _ButtonStyle; }
  179.             set { _ButtonStyle = value; Invalidate(); }
  180.         }
  181.  
  182.         public Image Icon
  183.         {
  184.             get { return _Icon; }
  185.             set { _Icon = value; Invalidate(); }
  186.         }
  187.  
  188.         public Boolean ShowIcon
  189.         {
  190.             get { return _ShowIcon; }
  191.             set { _ShowIcon = value; Invalidate(); }
  192.         }
  193.  
  194.         public override string Text
  195.         {
  196.             get { return base.Text; }
  197.             set { base.Text = value; Invalidate(); }
  198.         }
  199.  
  200.         public override Font Font
  201.         {
  202.             get { return base.Font; }
  203.             set { base.Font = value; Invalidate(); }
  204.         }
  205.  
  206.         public AevionButton()
  207.         {
  208.             DoubleBuffered = true;
  209.             Font = Helper.Fonts.PrimaryBold;
  210.             SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
  211.         }
  212.  
  213.         protected override void OnMouseDown(MouseEventArgs mevent)
  214.         {
  215.             base.OnMouseDown(mevent);
  216.             State = Helper.MouseState.Down;
  217.             Invalidate();
  218.         }
  219.  
  220.         protected override void OnMouseUp(MouseEventArgs mevent)
  221.         {
  222.             base.OnMouseUp(mevent);
  223.             State = Helper.MouseState.None;
  224.             Invalidate();
  225.         }
  226.  
  227.         protected override void OnMouseEnter(EventArgs e)
  228.         {
  229.             base.OnMouseEnter(e);
  230.             State = Helper.MouseState.Hover;
  231.             Invalidate();
  232.         }
  233.  
  234.         protected override void OnMouseLeave(EventArgs e)
  235.         {
  236.             base.OnMouseLeave(e);
  237.             State = Helper.MouseState.None;
  238.             Invalidate();
  239.         }
  240.  
  241.         protected override void OnPaint(PaintEventArgs e)
  242.         {
  243.             base.OnPaint(e);
  244.             var g = e.Graphics;
  245.             g.SmoothingMode = SmoothingMode.HighQuality;
  246.             g.Clear(Helper.Colors.Background);
  247.  
  248.             switch (ButtonStyle)
  249.             {
  250.                 case Style.Default:
  251.                     l1 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(88, 105, 123), Color.Black, LinearGradientMode.Vertical);
  252.                     l2 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(108, 125, 143), Color.Black, LinearGradientMode.Vertical);
  253.                     l3 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(98, 115, 133), Color.Black, LinearGradientMode.Vertical);
  254.                     break;
  255.                 case Style.Red:
  256.                     l1 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(173, 83, 74), Color.Black, LinearGradientMode.Vertical);
  257.                     l2 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(193, 103, 94), Color.Black, LinearGradientMode.Vertical);
  258.                     l3 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(183, 93, 84), Color.Black, LinearGradientMode.Vertical);
  259.                     break;
  260.                 case Style.Green:
  261.                     l1 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(127, 177, 80), Color.Black, LinearGradientMode.Vertical);
  262.                     l2 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(157, 197, 100), Color.Black, LinearGradientMode.Vertical);
  263.                     l3 = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(147, 187, 90), Color.Black, LinearGradientMode.Vertical);
  264.                     break;
  265.             }
  266.  
  267.             switch (State)
  268.             {
  269.                 case Helper.MouseState.Down:
  270.                     g.FillRectangle(l1, new Rectangle(1, 1, Width - 2, Height - 2));
  271.                     break;
  272.                 case Helper.MouseState.Hover:
  273.                     g.FillRectangle(l2, new Rectangle(1, 1, Width - 2, Height - 2));
  274.                     break;
  275.                 case Helper.MouseState.None:
  276.                     g.FillRectangle(l3, new Rectangle(1, 1, Width - 2, Height - 2));
  277.                     break;
  278.             }
  279.  
  280.             Helper.RoundRect(g, 0, 0, Width - 1, Height - 1, 3, Color.FromArgb(38, 38, 38));
  281.            
  282.             if (ShowIcon)
  283.                 g.DrawImage(Icon, new Point(Width / 8, Height / 2 - 8));
  284.  
  285.             Helper.CenterString(g, Text, Font, Helper.Colors.Foreground, new Rectangle(0, 0, Width, Height));
  286.            
  287.         }
  288.     }
  289.  
  290.     sealed class AevionRadioButton : Control
  291.     {
  292.         public event EventHandler CheckedChanged = delegate { };
  293.  
  294.         private Boolean _Checked;
  295.  
  296.         public Boolean Checked
  297.         {
  298.             get { return _Checked; }
  299.             set {
  300.                 _Checked = value;
  301.                 Invalidate();
  302.                 CheckedChanged(this, new EventArgs());
  303.             }
  304.         }
  305.  
  306.         public override string Text
  307.         {
  308.             get { return base.Text; }
  309.             set { base.Text = value; Invalidate(); }
  310.         }
  311.  
  312.         public override Font Font
  313.         {
  314.             get { return base.Font; }
  315.             set { base.Font = value; Invalidate(); }
  316.         }
  317.  
  318.         public AevionRadioButton()
  319.         {
  320.             DoubleBuffered = true;
  321.             Size = new Size(Width, 16);
  322.             Font = Helper.Fonts.Primary;
  323.             SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
  324.         }
  325.  
  326.         protected override void OnResize(EventArgs e)
  327.         {
  328.             base.OnResize(e);
  329.             Size = new Size(Width, 16);
  330.         }
  331.  
  332.         protected override void OnMouseUp(MouseEventArgs e)
  333.         {
  334.             base.OnMouseUp(e);
  335.             Checked = !Checked;
  336.         }
  337.  
  338.         protected override void OnPaint(PaintEventArgs e)
  339.         {
  340.             base.OnPaint(e);
  341.             var g = e.Graphics;
  342.             var p = new Pen(Color.FromArgb(35, 35, 40));
  343.             var s = new SolidBrush(Color.FromArgb(220, 220, 255));
  344.  
  345.             g.SmoothingMode = SmoothingMode.HighQuality;
  346.             g.Clear(Helper.Colors.Background);
  347.  
  348.             var l = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(98, 115, 133), Color.Black, LinearGradientMode.Vertical);
  349.  
  350.             g.FillEllipse(l, new Rectangle(1, 1, 14, 14));
  351.             g.DrawEllipse(p, new Rectangle(5, 5, 5, 5));
  352.  
  353.             if (Checked)
  354.                 g.FillEllipse(s, new Rectangle(5, 5, 5, 5));
  355.  
  356.             s.Color = Helper.Colors.Foreground;
  357.             g.DrawString(Text, Font, s, new PointF(20, 0));
  358.  
  359.             Helper.MultiDispose(s, p, l);
  360.  
  361.         }
  362.     }
  363.  
  364.     sealed class AevionCheckBox : Control
  365.     {
  366.         public event EventHandler CheckedChanged = delegate { };
  367.        
  368.         private Boolean _Checked;
  369.  
  370.         public Boolean Checked
  371.         {
  372.             get { return _Checked; }
  373.             set {
  374.                 _Checked = value;
  375.                 Invalidate();
  376.                 CheckedChanged(this, new EventArgs());
  377.             }
  378.         }
  379.        
  380.         public override string Text
  381.         {
  382.             get { return base.Text; }
  383.             set { base.Text = value; Invalidate(); }
  384.         }
  385.  
  386.         public override Font Font
  387.         {
  388.             get { return base.Font; }
  389.             set { base.Font = value; Invalidate(); }
  390.         }
  391.  
  392.         public AevionCheckBox()
  393.         {
  394.             DoubleBuffered = true;
  395.             Font = Helper.Fonts.Primary;
  396.             Size = new Size(Width, 16);
  397.         }
  398.  
  399.         protected override void OnResize(EventArgs e)
  400.         {
  401.             base.OnResize(e);
  402.             Size = new Size(Width, 16);
  403.         }
  404.  
  405.         protected override void OnMouseUp(MouseEventArgs e)
  406.         {
  407.             base.OnMouseUp(e);
  408.             Checked = !Checked;
  409.         }
  410.  
  411.         protected override void OnPaint(PaintEventArgs e)
  412.         {
  413.             base.OnPaint(e);
  414.             var g = e.Graphics;
  415.             var s = new SolidBrush(Helper.Colors.Foreground);
  416.             var l = new LinearGradientBrush(new Rectangle(0, 0, Width, Height + 35), Color.FromArgb(98, 115, 133), Color.Black, LinearGradientMode.Vertical);
  417.  
  418.             g.SmoothingMode = SmoothingMode.HighQuality;
  419.             g.Clear(Helper.Colors.Background);
  420.  
  421.             g.FillRectangle(l, new Rectangle(1, 1, 13, 13));
  422.             Helper.RoundRect(g, 0, 0, 14, 14, 3, Color.FromArgb(35, 35, 40));
  423.  
  424.             if (Checked)
  425.                 Helper.CenterString(g, "b", new Font("Marlett", 10), Helper.Colors.Foreground, new Rectangle(2, 1, 13, 13));
  426.  
  427.             g.DrawString(Text, Font, s, new Point(20, -1));
  428.            
  429.             Helper.MultiDispose(s, l);
  430.  
  431.         }
  432.     }
  433.  
  434.     sealed class AevionProgressBar : Control
  435.     {
  436.         private Int32 _Maximum = 100;
  437.         private Int32 _Minimum, _Value = 0;
  438.         private Boolean _ShowText = true;
  439.  
  440.         public Int32 Maximum
  441.         {
  442.             get { return _Maximum; }
  443.             set
  444.             {
  445.                 if (value > Int32.MaxValue)
  446.                     throw new OverflowException();
  447.                 if (value < _Minimum)
  448.                     _Minimum = value - 1;
  449.                 if (_Value > _Maximum)
  450.                     _Value = value;
  451.                 _Maximum = value;
  452.                 Invalidate();
  453.             }
  454.         }
  455.  
  456.         public Int32 Minimum
  457.         {
  458.             get { return _Minimum; }
  459.             set
  460.             {
  461.                 if (value < 0)
  462.                     throw new ArgumentOutOfRangeException("Minimum", "Value cannot go below 0.");
  463.                 if (value < _Minimum)
  464.                     _Value = value;
  465.                 if (value > _Maximum)
  466.                     _Maximum = value + 1;
  467.                 _Minimum = value;
  468.                 Invalidate();
  469.             }
  470.         }
  471.  
  472.         public Int32 Value
  473.         {
  474.             get { return _Value; }
  475.             set
  476.             {
  477.                 if (value > _Maximum)
  478.                     _Value = _Maximum;
  479.                 else if (value < _Minimum)
  480.                     _Value = _Minimum;
  481.                 else _Value = value;
  482.                 Invalidate();
  483.             }
  484.         }
  485.  
  486.         public Boolean ShowText
  487.         {
  488.             get { return _ShowText; }
  489.             set { _ShowText = value; Invalidate(); }
  490.         }
  491.  
  492.         public override string Text
  493.         {
  494.             get { return base.Text; }
  495.             set { base.Text = value; Invalidate(); }
  496.         }
  497.  
  498.         public override Font Font
  499.         {
  500.             get { return base.Font; }
  501.             set { base.Font = value; Invalidate(); }
  502.         }
  503.  
  504.         public AevionProgressBar()
  505.         {
  506.             DoubleBuffered = true;
  507.             Font = Helper.Fonts.Primary;
  508.         }
  509.  
  510.         protected override void OnPaint(PaintEventArgs e)
  511.         {
  512.             base.OnPaint(e);
  513.             var g = e.Graphics;
  514.             var l = new LinearGradientBrush(new Point(0, 0), new Point(Width + Value + 50, Height), Color.FromArgb(98, 115, 133), Color.Black);
  515.  
  516.             g.SmoothingMode = SmoothingMode.HighQuality;
  517.             g.Clear(Helper.Colors.Background);
  518.  
  519.             g.FillRectangle(l, new Rectangle(0, 0, (int)(Helper.ValueToPercentage(Value, Maximum, Minimum) * Width), Height));
  520.  
  521.             Helper.RoundRect(g, 0, 0, Width - 1, Height - 1, 3, Color.FromArgb(38, 38, 38));
  522.  
  523.             if (ShowText)
  524.                 Helper.CenterString(g, Text, Font, Helper.Colors.Foreground, new Rectangle(0, 0, Width, Height));
  525.  
  526.             Helper.MultiDispose(l);
  527.  
  528.         }
  529.  
  530.     }
  531.  
  532.     sealed class AevionNotice : TextBox
  533.     {
  534.  
  535.         public AevionNotice()
  536.         {
  537.             DoubleBuffered = true;
  538.             Font = Helper.Fonts.Primary;
  539.             Enabled = false;
  540.             Multiline = true;
  541.             BorderStyle = BorderStyle.None;
  542.             SetStyle(ControlStyles.UserPaint | ControlStyles.SupportsTransparentBackColor, true);
  543.         }
  544.  
  545.         protected override void OnPaint(PaintEventArgs e)
  546.         {
  547.             base.OnPaint(e);
  548.             var g = e.Graphics;
  549.             var s = new SolidBrush(Color.FromArgb(38, 38, 38));
  550.  
  551.             g.SmoothingMode = SmoothingMode.HighQuality;
  552.             g.Clear(Helper.Colors.Background);
  553.  
  554.             g.FillRectangle(s, new Rectangle(1, 1, Width - 2, Height - 2));
  555.             Helper.RoundRect(g, 0, 0, Width - 1, Height - 1, 3, Color.FromArgb(35, 35, 40));
  556.  
  557.             s.Color = Helper.Colors.Foreground;
  558.             g.DrawString(Text, Font, s, new Point(12, 8));
  559.  
  560.         }
  561.     }
  562.  
  563.     sealed class AevionLabel : Label
  564.     {
  565.         public AevionLabel()
  566.         {
  567.             DoubleBuffered = true;
  568.             Font = Helper.Fonts.Primary;
  569.             ForeColor = Helper.Colors.Foreground;
  570.             BackColor = Helper.Colors.Background;
  571.         }
  572.     }
  573.  
  574. }
Advertisement
Add Comment
Please, Sign In to add comment