using PaintDotNet.Annotation.Enum;
using System.Collections.Generic;
using System.Drawing;
namespace PaintDotNet.Annotation.PhysicalPhaseAction
{
///
/// 物相提取->定义物体->轮廓->椭圆
///
public class DrawPPhasePolygon : DrawObject
{
///
/// 点集合
///
public List pointArray = new List();
///
/// 画笔
///
private Pen pen = new Pen(Color.Blue, 2);
public DrawPPhasePolygon(ISurfaceBox surfaceBox, int x, int y) : base()
{
this.objectType = DrawClass.PhaseExtraction;
this.drawToolType = DrawToolType.PPhasePolygon;
pointArray.Add(new Point(x, y));
startPoint.X = x;
startPoint.Y = y;
this.rectangle.X = x;
this.rectangle.Y = y;
}
public override void Draw(Graphics g)
{
if (HandleCount >= 3)
{
g.DrawPolygon(pen, pointArray.ToArray());
}
}
///
/// Move handle to new pointscroll (resizing)
///
///
///
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;
}
public override int HandleCount
{
get
{
return pointArray.Count;
}
}
public override void DrawTracker(Graphics g)
{
}
public override DrawObject Clone()
{
return null;
}
public override RectangleF GetBoundingBox()
{
return rectangle;
}
}
}