| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136 | using PaintDotNet.Annotation.Enum;using PaintDotNet.Annotation.Label;using System.Collections.Generic;using System.Drawing;using System.Drawing.Drawing2D;using System.Windows.Forms;namespace PaintDotNet.Annotation.Other{    /// <summary>    /// 二值提取-交互操作-删除-多边形    /// </summary>    public class DrawBinaryChoisePolygon : DrawObject    {        public List<PointF> pointArray = new List<PointF>();        public DrawBinaryChoisePolygon(ISurfaceBox surfaceBox, int x, int y) : base()        {            this.objectType = DrawClass.Interaction;            this.drawToolType = DrawToolType.BinaryChoisePolygon;            pointArray.Add(new Point(x, y));            startPoint.X = x;            startPoint.Y = y;            this.rectangle.X = x;            this.rectangle.Y = y;            Initialize();        }        public override DrawObject Clone()        {            return null;        }        public override void Draw(Graphics g)        {            if (HandleCount >= 3)            {                g.SmoothingMode = SmoothingMode.AntiAlias;                Color color = Color.Red;                Pen pen = new Pen(color, PenWidth);                int penWidth = 3;                pen.DashStyle = DashStyle.Dot;                pen.Width = penWidth;                Color fillColor = Color.Transparent;                SolidBrush fillBrush = new SolidBrush(fillColor);                g.FillPolygon(fillBrush, pointArray.ToArray());                g.DrawPolygon(pen, pointArray.ToArray());                pen.Dispose();                fillBrush.Dispose();            }        }        public override int HandleCount        {            get            {                return pointArray.Count;            }        }        public override RectangleF GetBoundingBox()        {            return rectangle;        }        /// <summary>        /// Move handle to new pointscroll (resizing)        /// </summary>        /// <param name="pointscroll"></param>        /// <param name="handleNumber"></param>        public override void MoveHandleTo(Point point, int handleNumber)        {            float left = Rectangle.Left;            float top = Rectangle.Top;            float right = Rectangle.Right;            float bottom = Rectangle.Bottom;            switch (handleNumber)            {                case 1:                    left = point.X;                    top = point.Y;                    break;                case 2:                    top = point.Y;                    break;                case 3:                    right = point.X;                    top = point.Y;                    break;                case 4:                    right = point.X;                    break;                case 5:                    right = point.X;                    bottom = point.Y;                    break;                case 6:                    bottom = point.Y;                    break;                case 7:                    left = point.X;                    bottom = point.Y;                    break;                case 8:                    left = point.X;                    break;            }            SetRectangle(left, top, right - left, bottom - top);        }        protected void SetRectangle(float x, float y, float width, float height)        {            this.rectangle.X = x;            this.rectangle.Y = y;            this.rectangle.Width = width;            this.rectangle.Height = height;        }        public void AddPoint(Point point)        {            pointArray.Add(point);        }        internal void setNextPoint(Point p)        {            AddPoint(p);            startPoint = endPoint;            endPoint = p;        }    }}
 |