using PaintDotNet.Base.SettingModel;
using System;
using System.Drawing;
using System.Drawing.Drawing2D;
using System.Globalization;
using System.Runtime.Serialization;
using System.Windows.Forms;
using PaintDotNet.Base.CommTool;
using System.IO;
using static PaintDotNet.Base.SettingModel.LabelStyleModel;
using PaintDotNet.Annotation.Enum;
using System.Collections;
using System.Collections.Generic;
using PaintDotNet.Base.Enum;
namespace PaintDotNet.Annotation.Label
{
///
/// 标注->标记->点标记
///
public class DrawPointMark : DrawObject
{
private static Cursor handleCursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationPolyHandle.cur"));
///
/// 标注样式信息model
///
public PointMark labelPointMarkStyleModel;
public DrawPointMark(ISurfaceBox surfaceBox) : base()
{
this.objectType = DrawClass.Label;
this.drawToolType = DrawToolType.DrawPointMark;
Initialize();
}
public DrawPointMark(ISurfaceBox surfaceBox, int x1, int y1) : base()
{
this.objectType = DrawClass.Label;
this.drawToolType = DrawToolType.DrawPointMark;
startPoint = new PointF(x1, y1);
labelPointMarkStyleModel = surfaceBox.GetLabelStyleModel().pointMark;
Initialize();
}
public DrawPointMark(ISurfaceBox surfaceBox, List points, ParentStyleModel parentStyleModel, Object content) : base()
{
this.objectType = DrawClass.Label;
this.drawToolType = DrawToolType.DrawPointMark;
this.ISurfaceBox = surfaceBox;
labelPointMarkStyleModel = (LabelStyleModel.PointMark)parentStyleModel;
startPoint = points[0];
}
///
/// Clone this instance
///
public override DrawObject Clone()
{
DrawPointMark pointMark = new DrawPointMark(ISurfaceBox);
pointMark.objectType = DrawClass.Label;
pointMark.drawToolType = DrawToolType.DrawPointMark;
pointMark.ISurfaceBox = this.ISurfaceBox;
pointMark.startPoint = this.startPoint;
pointMark.rectangle = this.rectangle;
pointMark.labelPointMarkStyleModel = this.labelPointMarkStyleModel;
FillDrawObjectFields(pointMark);
return pointMark;
}
public override DrawObject Clone(ISurfaceBox surfaceBox)
{
DrawPointMark pointMark = new DrawPointMark(surfaceBox);
pointMark.objectType = DrawClass.Label;
pointMark.drawToolType = DrawToolType.DrawPointMark;
pointMark.ISurfaceBox = surfaceBox;
pointMark.startPoint = this.startPoint;
pointMark.rectangle = this.rectangle;
pointMark.labelPointMarkStyleModel = this.labelPointMarkStyleModel;
FillDrawObjectFields(pointMark);
return pointMark;
}
public override void Draw(Graphics g)
{
SizeF windowSize = this.ISurfaceBox.GetDocumentSize();//窗体尺寸
int newHeight = Convert.ToInt32(windowSize.Height / 40);
string markStyle = this.labelPointMarkStyleModel.pointStyle;
Color color = Color.FromArgb(this.labelPointMarkStyleModel.pointColor);
Pen pen = new Pen(color);
pen.Width = newHeight / 5;
g.SmoothingMode = SmoothingMode.AntiAlias;
switch ((SomeStyle)System.Enum.ToObject(typeof(SomeStyle), int.Parse(markStyle)))
{
case SomeStyle.Arrow:
rectangle.X = startPoint.X - newHeight / 2;
rectangle.Y = startPoint.Y;
rectangle.Width = newHeight;
rectangle.Height = newHeight;
pen.EndCap = LineCap.ArrowAnchor;
g.DrawLine(pen, new PointF(startPoint.X, startPoint.Y), new PointF(startPoint.X, startPoint.Y + newHeight));
break;
case SomeStyle.Dot:
rectangle.X = startPoint.X - newHeight / 2;
rectangle.Y = startPoint.Y - newHeight / 2;
rectangle.Width = newHeight;
rectangle.Height = newHeight;
g.DrawEllipse(pen, rectangle);
break;
case SomeStyle.Triangle:
rectangle.X = startPoint.X - newHeight / 2;
rectangle.Y = startPoint.Y - newHeight / 2;
rectangle.Width = newHeight;
rectangle.Height = newHeight;
PointF p1 = new PointF(rectangle.X, rectangle.Y);
PointF p2 = new PointF(rectangle.Right, rectangle.Top);
PointF p3 = new PointF(rectangle.X + rectangle.Width / 2, rectangle.Bottom);
PointF[] pntArr = { p1, p2, p3 };
g.DrawPolygon(pen, pntArr);
break;
}
pen.Dispose();
}
public override int HandleCount
{
get
{
return 1;
}
}
///
/// Get handle pointscroll by 1-based number
///
///
///
public override PointF GetHandle(int handleNumber)
{
return startPoint;
}
///
/// Hit test.
/// Return value: -1 - no hit
/// 0 - hit anywhere
/// > 1 - handle number
///
///
///
public override int HitTest(Point point)
{
if (Selected)
{
for (int i = 1; i <= HandleCount; i++)
{
if (GetHandleRectangle(i).Contains(point))
return i;
}
}
if (PointInObject(point))
return 0;
return -1;
}
protected override bool PointInObject(Point point)
{
return rectangle.Contains(point);
}
public override bool IntersectsWith(Rectangle rectangle)
{
return Rectangle.IntersectsWith(rectangle);
}
public override Cursor GetHandleCursor(int handleNumber)
{
return Cursors.Default;
}
public override void MoveHandleTo(Point point, int handleNumber)
{
startPoint = point;
}
public override void Move(int deltaX, int deltaY)
{
int x = ISurfaceBox.UnscaleScalar(deltaX);
int y = ISurfaceBox.UnscaleScalar(deltaY);
startPoint.X += x;
startPoint.Y += y;
rectangle.X += x;
rectangle.Y += y;
}
public override RectangleF GetBoundingBox()
{
return rectangle;
}
public override List GetPoints()
{
List points = new List();
points.Add(startPoint);
return points;
}
public override ParentStyleModel GetStyle()
{
return labelPointMarkStyleModel;
}
}
}