using System;
using System.Text;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Windows.Forms;
using System.Collections.Generic;

namespace USB_interface
{
    public class DrawPoint : Button
    {
        protected override void OnPaint(System.Windows.Forms.PaintEventArgs e)
        {
            e.Graphics.FillEllipse(Brushes.Red, 0, 0, ClientSize.Width, ClientSize.Height);
            GraphicsPath grPath = new GraphicsPath();
            grPath.AddEllipse(0, 0, ClientSize.Width, ClientSize.Height);
            this.Region = new System.Drawing.Region(grPath);
            //base.OnPaint(e);
        }

        protected override void OnClick(EventArgs e)
        {
            Actual = this;
            Down = true;
        }

        protected override void OnMouseDown(MouseEventArgs mevent)
        {
            if (mevent.Button == System.Windows.Forms.MouseButtons.Left)
            {
                Actual = this;
                Down = true;
                MouseDownLocation = mevent.Location;
                this.Parent.Refresh();
            }
        }

        protected override void OnMouseUp(MouseEventArgs mevent)
        {
            if (mevent.Button == System.Windows.Forms.MouseButtons.Left)
            {
                Down = false;

                if (this.Top < 0)
                    this.Top = 0;
                else if (this.Top > MyForm.Max)
                    this.Top = MyForm.Max;

                MyForm.PointPosChanged(this);
                this.Parent.Refresh();
            }
        }

        protected override void OnMouseMove(MouseEventArgs mevent)
        {
            if(Actual != null && Down)
            {
                this.Top = mevent.Y + this.Top - MouseDownLocation.Y;
                this.Parent.Refresh();
            }
        }

        public MyGenForm MyForm;
        public static DrawPoint Actual;
        public static bool Down;
        public static Size PointSize = new Size(8, 8);

        private Point MouseDownLocation;
    }
}
