namespace VaioxOnline
{
    using Microsoft.VisualBasic.CompilerServices;
    using System;
    using System.ComponentModel;
    using System.Drawing;
    using System.Drawing.Drawing2D;
    using System.Drawing.Text;
    using System.Runtime.CompilerServices;
    using System.Windows.Forms;

    internal class FlatComboBox : ComboBox
    {
        private Color _BaseColor;
        private Color _BGColor;
        private Color _HoverColor;
        private int _StartIndex;
        private int H;
        private MouseState State;
        private int W;
        private int x;
        private int y;

        public FlatComboBox()
        {
            base.DrawItem += new DrawItemEventHandler(this.DrawItem_);
            this._StartIndex = 0;
            this.State = MouseState.None;
            this._BaseColor = Color.FromArgb(0x19, 0x1b, 0x1d);
            this._BGColor = Color.FromArgb(0x2d, 0x2f, 0x31);
            this._HoverColor = Color.FromArgb(0x23, 0xa8, 0x6d);
            base.SetStyle(ControlStyles.OptimizedDoubleBuffer | ControlStyles.AllPaintingInWmPaint | ControlStyles.ResizeRedraw | ControlStyles.UserPaint, true);
            this.DoubleBuffered = true;
            base.DrawMode = DrawMode.OwnerDrawFixed;
            this.BackColor = Color.FromArgb(0x2d, 0x2d, 0x30);
            this.ForeColor = Color.White;
            base.DropDownStyle = ComboBoxStyle.DropDownList;
            this.Cursor = Cursors.Hand;
            this.StartIndex = 0;
            base.ItemHeight = 0x12;
            this.Font = new Font("Segoe UI", 8f, FontStyle.Regular);
        }

        public void DrawItem_(object sender, DrawItemEventArgs e)
        {
            if (e.Index >= 0)
            {
                e.DrawBackground();
                e.DrawFocusRectangle();
                e.Graphics.SmoothingMode = SmoothingMode.HighQuality;
                e.Graphics.PixelOffsetMode = PixelOffsetMode.HighQuality;
                e.Graphics.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
                e.Graphics.InterpolationMode = InterpolationMode.HighQualityBicubic;
                if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
                {
                    e.Graphics.FillRectangle(new SolidBrush(this._HoverColor), e.Bounds);
                }
                else
                {
                    e.Graphics.FillRectangle(new SolidBrush(this._BaseColor), e.Bounds);
                }
                e.Graphics.DrawString(base.GetItemText(RuntimeHelpers.GetObjectValue(base.Items[e.Index])), new Font("Segoe UI", 8f), Brushes.White, new Rectangle(e.Bounds.X + 2, e.Bounds.Y + 2, e.Bounds.Width, e.Bounds.Height));
                e.Graphics.Dispose();
            }
        }

        protected override void OnClick(EventArgs e)
        {
            base.OnClick(e);
            base.Invalidate();
        }

        protected override void OnDrawItem(DrawItemEventArgs e)
        {
            base.OnDrawItem(e);
            base.Invalidate();
            if ((e.State & DrawItemState.Selected) == DrawItemState.Selected)
            {
                base.Invalidate();
            }
        }

        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 OnMouseMove(MouseEventArgs e)
        {
            base.OnMouseMove(e);
            this.x = e.Location.X;
            this.y = e.Location.Y;
            base.Invalidate();
            if (e.X < (base.Width - 0x29))
            {
                this.Cursor = Cursors.IBeam;
            }
            else
            {
                this.Cursor = Cursors.Hand;
            }
        }

        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;
            Rectangle rect = new Rectangle(0, 0, this.W, this.H);
            Rectangle rectangle2 = new Rectangle(this.W - 40, 0, this.W, this.H);
            GraphicsPath path = new GraphicsPath();
            GraphicsPath path2 = new GraphicsPath();
            Graphics g = Helpers.G;
            g.Clear(Color.FromArgb(0x2d, 0x2d, 0x30));
            g.SmoothingMode = SmoothingMode.HighQuality;
            g.PixelOffsetMode = PixelOffsetMode.HighQuality;
            g.TextRenderingHint = TextRenderingHint.ClearTypeGridFit;
            g.FillRectangle(new SolidBrush(this._BGColor), rect);
            path.Reset();
            path.AddRectangle(rectangle2);
            g.SetClip(path);
            g.FillRectangle(new SolidBrush(this._BaseColor), rectangle2);
            g.ResetClip();
            g.DrawLine(Pens.White, this.W - 10, 6, this.W - 30, 6);
            g.DrawLine(Pens.White, this.W - 10, 12, this.W - 30, 12);
            g.DrawLine(Pens.White, this.W - 10, 0x12, this.W - 30, 0x12);
            g.DrawString(this.Text, this.Font, Brushes.White, (PointF) new Point(4, 6), Helpers.NearSF);
            g = null;
            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);
            base.Height = 0x12;
        }

        [Category("Colors")]
        public Color HoverColor
        {
            get => 
                this._HoverColor
            set
            {
                this._HoverColor = value;
            }
        }

        private int StartIndex
        {
            get => 
                this._StartIndex
            set
            {
                this._StartIndex = value;
                try
                {
                    base.SelectedIndex = value;
                }
                catch (Exception exception1)
                {
                    ProjectData.SetProjectError(exception1);
                    ProjectData.ClearProjectError();
                }
                base.Invalidate();
            }
        }
    }
}

