Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Hero Theme
- //By: FoSho
- //Theme Base: AeonHack
- //Version: 1.0.0.0
- using System.Drawing.Drawing2D;
- using System.ComponentModel;
- using System.Runtime.InteropServices;
- abstract class Theme : ContainerControl
- {
- protected Graphics G;
- Theme()
- {
- SetStyle((ControlStyles)139270, true);
- }
- private bool ParentIsForm;
- protected override void OnHandleCreated(EventArgs e)
- {
- Dock = DockStyle.Fill;
- ParentIsForm = Parent is Form;
- if (ParentIsForm) {
- if (!_TransparencyKey == Color.Empty) ParentForm.TransparencyKey = _TransparencyKey;
- ParentForm.FormBorderStyle = FormBorderStyle.None;
- }
- base.OnHandleCreated(e);
- }
- override string Text {
- get { return base.Text; }
- set {
- base.Text = v;
- Invalidate();
- }
- }
- private bool _Resizable = true;
- bool Resizable {
- get { return _Resizable; }
- set { _Resizable = value; }
- }
- private int _MoveHeight = 24;
- int MoveHeight {
- get { return _MoveHeight; }
- set {
- _MoveHeight = v;
- Header = new Rectangle(7, 7, Width - 14, _MoveHeight - 7);
- }
- }
- private IntPtr Flag;
- protected override void OnMouseDown(MouseEventArgs e)
- {
- if (!e.Button == MouseButtons.Left) return;
- if (ParentIsForm) if (ParentForm.WindowState == FormWindowState.Maximized) return;
- if (Header.Contains(e.Location)) {
- Flag = new IntPtr(2);
- }
- else if (Current.Position == 0 | !_Resizable) {
- return;
- }
- else {
- Flag = new IntPtr(Current.Position);
- }
- Capture = false;
- DefWndProc(Message.Create(Parent.Handle, 161, Flag, null));
- base.OnMouseDown(e);
- }
- private struct Pointer
- {
- readonly Cursor Cursor;
- readonly byte Position;
- Pointer(Cursor c, byte p)
- {
- Cursor = c;
- Position = p;
- }
- }
- private bool F1;
- private bool F2;
- private bool F3;
- private bool F4;
- private Point PTC;
- private Pointer GetPointer()
- {
- PTC = PointToClient(MousePosition);
- F1 = PTC.X < 7;
- F2 = PTC.X > Width - 7;
- F3 = PTC.Y < 7;
- F4 = PTC.Y > Height - 7;
- if (F1 & F3) return new Pointer(Cursors.SizeNWSE, 13);
- if (F1 & F4) return new Pointer(Cursors.SizeNESW, 16);
- if (F2 & F3) return new Pointer(Cursors.SizeNESW, 14);
- if (F2 & F4) return new Pointer(Cursors.SizeNWSE, 17);
- if (F1) return new Pointer(Cursors.SizeWE, 10);
- if (F2) return new Pointer(Cursors.SizeWE, 11);
- if (F3) return new Pointer(Cursors.SizeNS, 12);
- if (F4) return new Pointer(Cursors.SizeNS, 15);
- return new Pointer(Cursors.Default, 0);
- }
- private Pointer Current;
- private Pointer Pending;
- private void SetCurrent()
- {
- Pending = GetPointer();
- if (Current.Position == Pending.Position) return;
- Current = GetPointer();
- Cursor = Current.Cursor;
- }
- protected override void OnMouseMove(MouseEventArgs e)
- {
- if (_Resizable) SetCurrent();
- base.OnMouseMove(e);
- }
- protected Rectangle Header;
- protected override void OnSizeChanged(EventArgs e)
- {
- if (Width == 0 || Height == 0) return;
- Header = new Rectangle(7, 7, Width - 14, _MoveHeight - 7);
- Invalidate();
- base.OnSizeChanged(e);
- }
- abstract void PaintHook();
- protected override sealed void OnPaint(PaintEventArgs e)
- {
- if (Width == 0 || Height == 0) return;
- G = e.Graphics;
- PaintHook();
- }
- private Color _TransparencyKey;
- Color TransparencyKey {
- get { return _TransparencyKey; }
- set {
- _TransparencyKey = v;
- Invalidate();
- }
- }
- private Image _Image;
- Image Image {
- get { return _Image; }
- set {
- _Image = value;
- Invalidate();
- }
- }
- int ImageWidth {
- get {
- if (_Image == null) return 0;
- return _Image.Width;
- }
- }
- private Size _Size;
- private Rectangle _Rectangle;
- private LinearGradientBrush _Gradient;
- private SolidBrush _Brush;
- protected void DrawCorners(Color c, Rectangle rect)
- {
- _Brush = new SolidBrush(c);
- G.FillRectangle(_Brush, rect.X, rect.Y, 1, 1);
- G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y, 1, 1);
- G.FillRectangle(_Brush, rect.X, rect.Y + (rect.Height - 1), 1, 1);
- G.FillRectangle(_Brush, rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), 1, 1);
- }
- protected void DrawBorders(Pen p1, Pen p2, Rectangle rect)
- {
- G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
- G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3);
- }
- protected void DrawText(HorizontalAlignment a, Color c, int x)
- {
- DrawText(a, c, x, 0);
- }
- protected void DrawText(HorizontalAlignment a, Color c, int x, int y)
- {
- if (string.IsNullOrEmpty(Text)) return;
- _Size = G.MeasureString(Text, Font).ToSize;
- _Brush = new SolidBrush(c);
- switch (a) {
- case HorizontalAlignment.Left:
- G.DrawString(Text, Font, _Brush, x, _MoveHeight / 2 - _Size.Height / 2 + y);
- case HorizontalAlignment.Right:
- G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, _MoveHeight / 2 - _Size.Height / 2 + y);
- case HorizontalAlignment.Center:
- G.DrawString(Text, Font, _Brush, Width / 2 - _Size.Width / 2 + x, _MoveHeight / 2 - _Size.Height / 2 + y);
- }
- }
- protected void DrawIcon(HorizontalAlignment a, int x)
- {
- DrawIcon(a, x, 0);
- }
- protected void DrawIcon(HorizontalAlignment a, int x, int y)
- {
- if (_Image == null) return;
- switch (a) {
- case HorizontalAlignment.Left:
- G.DrawImage(_Image, x, _MoveHeight / 2 - _Image.Height / 2 + y);
- case HorizontalAlignment.Right:
- G.DrawImage(_Image, Width - _Image.Width - x, _MoveHeight / 2 - _Image.Height / 2 + y);
- case HorizontalAlignment.Center:
- G.DrawImage(_Image, Width / 2 - _Image.Width / 2, _MoveHeight / 2 - _Image.Height / 2);
- }
- }
- protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
- {
- _Rectangle = new Rectangle(x, y, width, height);
- _Gradient = new LinearGradientBrush(_Rectangle, c1, c2, angle);
- G.FillRectangle(_Gradient, _Rectangle);
- }
- }
- abstract class ThemeControl : Control
- {
- protected Graphics G;
- protected Bitmap B;
- ThemeControl()
- {
- SetStyle((ControlStyles)139270, true);
- B = new Bitmap(1, 1);
- G = Graphics.FromImage(B);
- }
- void AllowTransparent()
- {
- SetStyle(ControlStyles.Opaque, false);
- SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- }
- override string Text {
- get { return base.Text; }
- set {
- base.Text = v;
- Invalidate();
- }
- }
- protected enum State : byte
- {
- MouseNone = 0,
- MouseOver = 1,
- MouseDown = 2
- }
- protected State MouseState;
- protected override void OnMouseLeave(EventArgs e)
- {
- ChangeMouseState(State.MouseNone);
- base.OnMouseLeave(e);
- }
- protected override void OnMouseEnter(EventArgs e)
- {
- ChangeMouseState(State.MouseOver);
- base.OnMouseEnter(e);
- }
- protected override void OnMouseUp(MouseEventArgs e)
- {
- ChangeMouseState(State.MouseOver);
- base.OnMouseUp(e);
- }
- protected override void OnMouseDown(MouseEventArgs e)
- {
- if (e.Button == MouseButtons.Left) ChangeMouseState(State.MouseDown);
- base.OnMouseDown(e);
- }
- private void ChangeMouseState(State e)
- {
- MouseState = e;
- Invalidate();
- }
- abstract void PaintHook();
- protected override sealed void OnPaint(PaintEventArgs e)
- {
- if (Width == 0 || Height == 0) return;
- PaintHook();
- e.Graphics.DrawImage(B, 0, 0);
- }
- protected override void OnSizeChanged(EventArgs e)
- {
- if (!Width == 0 && !Height == 0) {
- B = new Bitmap(Width, Height);
- G = Graphics.FromImage(B);
- Invalidate();
- }
- base.OnSizeChanged(e);
- }
- private bool _NoRounding;
- bool NoRounding {
- get { return _NoRounding; }
- set {
- _NoRounding = v;
- Invalidate();
- }
- }
- private Image _Image;
- Image Image {
- get { return _Image; }
- set {
- _Image = value;
- Invalidate();
- }
- }
- int ImageWidth {
- get {
- if (_Image == null) return 0;
- return _Image.Width;
- }
- }
- int ImageTop {
- get {
- if (_Image == null) return 0;
- return Height / 2 - _Image.Height / 2;
- }
- }
- private Size _Size;
- private Rectangle _Rectangle;
- private LinearGradientBrush _Gradient;
- private SolidBrush _Brush;
- protected void DrawCorners(Color c, Rectangle rect)
- {
- if (_NoRounding) return;
- B.SetPixel(rect.X, rect.Y, c);
- B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c);
- B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c);
- B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c);
- }
- protected void DrawBorders(Pen p1, Pen p2, Rectangle rect)
- {
- G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
- G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3);
- }
- protected void DrawText(HorizontalAlignment a, Color c, int x)
- {
- DrawText(a, c, x, 0);
- }
- protected void DrawText(HorizontalAlignment a, Color c, int x, int y)
- {
- if (string.IsNullOrEmpty(Text)) return;
- _Size = G.MeasureString(Text, Font).ToSize;
- _Brush = new SolidBrush(c);
- switch (a) {
- case HorizontalAlignment.Left:
- G.DrawString(Text, Font, _Brush, x, Height / 2 - _Size.Height / 2 + y);
- case HorizontalAlignment.Right:
- G.DrawString(Text, Font, _Brush, Width - _Size.Width - x, Height / 2 - _Size.Height / 2 + y);
- case HorizontalAlignment.Center:
- G.DrawString(Text, Font, _Brush, Width / 2 - _Size.Width / 2 + x, Height / 2 - _Size.Height / 2 + y);
- }
- }
- protected void DrawIcon(HorizontalAlignment a, int x)
- {
- DrawIcon(a, x, 0);
- }
- protected void DrawIcon(HorizontalAlignment a, int x, int y)
- {
- if (_Image == null) return;
- switch (a) {
- case HorizontalAlignment.Left:
- G.DrawImage(_Image, x, Height / 2 - _Image.Height / 2 + y);
- case HorizontalAlignment.Right:
- G.DrawImage(_Image, Width - _Image.Width - x, Height / 2 - _Image.Height / 2 + y);
- case HorizontalAlignment.Center:
- G.DrawImage(_Image, Width / 2 - _Image.Width / 2, Height / 2 - _Image.Height / 2);
- }
- }
- protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
- {
- _Rectangle = new Rectangle(x, y, width, height);
- _Gradient = new LinearGradientBrush(_Rectangle, c1, c2, angle);
- G.FillRectangle(_Gradient, _Rectangle);
- }
- }
- abstract class ThemeContainerControl : ContainerControl
- {
- protected Graphics G;
- protected Bitmap B;
- ThemeContainerControl()
- {
- SetStyle((ControlStyles)139270, true);
- B = new Bitmap(1, 1);
- G = Graphics.FromImage(B);
- }
- void AllowTransparent()
- {
- SetStyle(ControlStyles.Opaque, false);
- SetStyle(ControlStyles.SupportsTransparentBackColor, true);
- }
- abstract void PaintHook();
- protected override sealed void OnPaint(PaintEventArgs e)
- {
- if (Width == 0 || Height == 0) return;
- PaintHook();
- e.Graphics.DrawImage(B, 0, 0);
- }
- protected override void OnSizeChanged(EventArgs e)
- {
- if (!Width == 0 && !Height == 0) {
- B = new Bitmap(Width, Height);
- G = Graphics.FromImage(B);
- Invalidate();
- }
- base.OnSizeChanged(e);
- }
- private bool _NoRounding;
- bool NoRounding {
- get { return _NoRounding; }
- set {
- _NoRounding = v;
- Invalidate();
- }
- }
- private Rectangle _Rectangle;
- private LinearGradientBrush _Gradient;
- protected void DrawCorners(Color c, Rectangle rect)
- {
- if (_NoRounding) return;
- B.SetPixel(rect.X, rect.Y, c);
- B.SetPixel(rect.X + (rect.Width - 1), rect.Y, c);
- B.SetPixel(rect.X, rect.Y + (rect.Height - 1), c);
- B.SetPixel(rect.X + (rect.Width - 1), rect.Y + (rect.Height - 1), c);
- }
- protected void DrawBorders(Pen p1, Pen p2, Rectangle rect)
- {
- G.DrawRectangle(p1, rect.X, rect.Y, rect.Width - 1, rect.Height - 1);
- G.DrawRectangle(p2, rect.X + 1, rect.Y + 1, rect.Width - 3, rect.Height - 3);
- }
- protected void DrawGradient(Color c1, Color c2, int x, int y, int width, int height, float angle)
- {
- _Rectangle = new Rectangle(x, y, width, height);
- _Gradient = new LinearGradientBrush(_Rectangle, c1, c2, angle);
- G.FillRectangle(_Gradient, _Rectangle);
- }
- }
- class HeroTheme : Theme
- {
- HeroTheme()
- {
- Resizable = false;
- BackColor = Color.FromArgb(211, 211, 211);
- MoveHeight = 25;
- TransparencyKey = Color.Fuchsia;
- }
- public override void PaintHook()
- {
- G.Clear(BackColor);
- G.Clear(Color.FromArgb(211, 211, 211));
- DrawGradient(Color.FromArgb(62, 62, 62), Color.FromArgb(40, 40, 40), 0, 0, Width, 25, 90);
- G.DrawLine(Pens.Black, 0, 25, Width, 25);
- DrawCorners(Color.Fuchsia, ClientRectangle);
- DrawBorders(Pens.Black, Pens.DimGray, ClientRectangle);
- DrawText(HorizontalAlignment.Left, Color.FromArgb(211, 211, 211), 7, 1);
- }
- }
- class HeroButton : ThemeControl
- {
- override void PaintHook()
- {
- switch (MouseState) {
- case State.MouseNone:
- G.Clear(Color.FromArgb(50, 50, 50));
- DrawGradient(Color.FromArgb(62, 62, 62), Color.FromArgb(40, 40, 40), 0, 0, Width, Height, 90);
- case State.MouseOver:
- G.Clear(Color.Gray);
- DrawGradient(Color.FromArgb(62, 62, 62), Color.FromArgb(40, 40, 40), 0, 0, Width, Height, 90);
- case State.MouseDown:
- G.Clear(Color.FromArgb(211, 211, 211));
- DrawGradient(Color.FromArgb(38, 38, 38), Color.FromArgb(40, 40, 40), 0, 0, Width, Height, 90);
- }
- DrawCorners(Color.Black, ClientRectangle);
- DrawText(HorizontalAlignment.Center, Color.FromArgb(211, 211, 211), 0);
- }
- }
- class HeroLabel : ThemeControl
- {
- override void PaintHook()
- {
- G.Clear(BackColor);
- DrawText(HorizontalAlignment.Center, Color.FromArgb(40, 40, 40), 0);
- }
- }
- class HeroSeperater : ThemeControl
- {
- override void PaintHook()
- {
- G.Clear(BackColor);
- G.DrawLine(Pens.Gray, 0, (int)ClientRectangle.Y / 2, Width, 0);
- }
- }
- class HeroGroupBox : ThemeContainerControl
- {
- HeroGroupBox()
- {
- AllowTransparent();
- }
- override void PaintHook()
- {
- G.Clear(BackColor);
- DrawBorders(Pens.Black, Pens.DimGray, ClientRectangle);
- DrawCorners(Color.Fuchsia, ClientRectangle);
- }
- }
- class HeroProgressBar : ThemeControl
- {
- private int _Maximum = 100;
- public int Maximum {
- get { return _Maximum; }
- set {
- if (value < 1) value = 1;
- if (value < _Value) _Value = value;
- _Maximum = value;
- Invalidate();
- }
- }
- private int _Value = 50;
- public int Value {
- get { return _Value; }
- set {
- if (value > _Maximum) value = _Maximum;
- if (value < 1) value = 1;
- _Value = value;
- Invalidate();
- }
- }
- override void PaintHook()
- {
- G.Clear(Color.FromArgb(50, 50, 50));
- if ((_Value > 0)) {
- DrawGradient(Color.FromArgb(62, 62, 62), Color.FromArgb(40, 40, 40), 0, 0, (int)(_Value / _Maximum) * Width, Height, 90);
- }
- G.DrawRectangle(Pens.LightGray, 0, 0, Width - 1, Height - 1);
- DrawBorders(Pens.Black, Pens.DimGray, ClientRectangle);
- }
- }
- class HeroCheckBox : ThemeControl
- {
- private bool _CheckedState;
- public bool CheckedState {
- get { return _CheckedState; }
- set {
- _CheckedState = v;
- Invalidate();
- }
- }
- HeroCheckBox()
- {
- Size = new Size(90, 15);
- MinimumSize = new Size(16, 16);
- MaximumSize = new Size(600, 16);
- CheckedState = false;
- }
- public override void PaintHook()
- {
- G.Clear(BackColor);
- switch (CheckedState) {
- case true:
- DrawGradient(Color.FromArgb(62, 62, 62), Color.FromArgb(38, 38, 38), 0, 0, 15, 15, 90);
- DrawGradient(Color.FromArgb(80, 80, 80), Color.FromArgb(60, 60, 60), 3, 3, 9, 9, 90);
- DrawGradient(Color.FromArgb(80, 80, 80), Color.FromArgb(60, 60, 60), 4, 4, 7, 7, 90);
- case false:
- DrawGradient(Color.FromArgb(211, 211, 211), Color.FromArgb(200, 200, 200), 0, 0, 15, 15, 90);
- }
- DrawBorders(Pens.Black, Pens.DimGray, new Rectangle(0, 0, 15, 15));
- DrawText(HorizontalAlignment.Left, Color.FromArgb(30, 30, 30), 17, 0);
- }
- void // ERROR: Handles clauses are not supported in C#
- changeCheck()
- {
- switch (CheckedState) {
- case true:
- CheckedState = false;
- case false:
- CheckedState = true;
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment