namespace VaioxOnline { using System; using System.Collections; using System.ComponentModel; using System.Drawing; using System.Drawing.Drawing2D; using System.Drawing.Text; using System.Windows.Forms; internal class FlatStickyButton : Control { private Color _BaseColor = Helpers._FlatColor; private bool _Rounded = false; private Color _TextColor = Color.FromArgb(0xf3, 0xf3, 0xf3); private int H; private MouseState State = MouseState.None; private int W; public FlatStickyButton() { base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.SupportsTransparentBackColor | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true); this.DoubleBuffered = true; base.Size = new Size(0x6a, 0x20); this.BackColor = Color.Transparent; this.Font = new Font("Segoe UI", 12f); this.Cursor = Cursors.Hand; } private bool[] GetConnectedSides() { IEnumerator enumerator; bool[] flagArray2 = new bool[4]; try { enumerator = base.Parent.Controls.GetEnumerator(); while (enumerator.MoveNext()) { Control current = (Control) enumerator.Current; if ((current is FlatStickyButton) && !((current == this) | !this.Rect.IntersectsWith(this.Rect))) { double a = (Math.Atan2((double) (base.Left - current.Left), (double) (base.Top - current.Top)) * 2.0) / 3.1415926535897931; if ((((long) Math.Round(a)) / 1L) == a) { flagArray2[(int) Math.Round((double) (a + 1.0))] = true; } } } } finally { if (enumerator is IDisposable) { (enumerator as IDisposable).Dispose(); } } return flagArray2; } protected override void OnCreateControl() { base.OnCreateControl(); } protected override void OnMouseDown(MouseEventArgs e) { base.OnMouseDown(e); this.State = MouseState.Down; base.Invalidate(); } protected override void OnMouseEnter(EventArgs e) { base.OnMouseEnter(e); this.State = MouseState.Over; base.Invalidate(); } protected override void OnMouseLeave(EventArgs e) { base.OnMouseLeave(e); this.State = MouseState.None; base.Invalidate(); } protected override void OnMouseUp(MouseEventArgs e) { base.OnMouseUp(e); this.State = MouseState.Over; base.Invalidate(); } protected override void OnPaint(PaintEventArgs e) { Helpers.B = new Bitmap(base.Width, base.Height); Helpers.G = Graphics.FromImage(Helpers.B); this.W = base.Width; this.H = base.Height; GraphicsPath path = new GraphicsPath(); bool[] connectedSides = this.GetConnectedSides(); GraphicsPath path2 = Helpers.RoundRect(0f, 0f, (float) this.W, (float) this.H, 0.3f, !(connectedSides[2] | connectedSides[1]), !(connectedSides[1] | connectedSides[0]), !(connectedSides[3] | connectedSides[0]), !(connectedSides[3] | connectedSides[2])); Rectangle rect = new Rectangle(0, 0, this.W, this.H); Graphics g = Helpers.G; g.SmoothingMode = SmoothingMode.HighQuality; g.PixelOffsetMode = PixelOffsetMode.HighQuality; g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit; g.Clear(this.BackColor); switch (this.State) { case MouseState.None: if (!this.Rounded) { g.FillRectangle(new SolidBrush(this._BaseColor), rect); g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF); break; } path = path2; g.FillPath(new SolidBrush(this._BaseColor), path); g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF); break; case MouseState.Over: if (!this.Rounded) { g.FillRectangle(new SolidBrush(this._BaseColor), rect); g.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.White)), rect); g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF); break; } path = path2; g.FillPath(new SolidBrush(this._BaseColor), path); g.FillPath(new SolidBrush(Color.FromArgb(20, Color.White)), path); g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF); break; case MouseState.Down: if (!this.Rounded) { g.FillRectangle(new SolidBrush(this._BaseColor), rect); g.FillRectangle(new SolidBrush(Color.FromArgb(20, Color.Black)), rect); g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF); break; } path = path2; g.FillPath(new SolidBrush(this._BaseColor), path); g.FillPath(new SolidBrush(Color.FromArgb(20, Color.Black)), path); g.DrawString(this.Text, this.Font, new SolidBrush(this._TextColor), rect, Helpers.CenterSF); break; } g = null; base.OnPaint(e); Helpers.G.Dispose(); e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic; e.Graphics.DrawImageUnscaled(Helpers.B, 0, 0); Helpers.B.Dispose(); } protected override void OnResize(EventArgs e) { base.OnResize(e); } [Category("Colors")] public Color BaseColor { get => this._BaseColor set { this._BaseColor = value; } } private Rectangle Rect => new Rectangle(base.Left, base.Top, base.Width, base.Height) [Category("Options")] public bool Rounded { get => this._Rounded set { this._Rounded = value; } } [Category("Colors")] public Color TextColor { get => this._TextColor set { this._TextColor = value; } } } }