123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259 |
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
- using PaintDotNet.Annotation.Enum;
- namespace PaintDotNet.Annotation.ImageCollect
- {
- public class DrawLocationCross : DrawObject
- {
- private int m_width;
- private int m_height;
- private int m_z;
- private Dictionary<int, object> points;
- public DrawLocationCross(ISurfaceBox surfaceBox, int x, int y, int width, int height, int z) : base()
- {
- this.objectType = DrawClass.Stitch;
- this.drawToolType = DrawToolType.DrawLocationCross;
- this.points = new Dictionary<int, object>();
- m_z = z;
- m_width = width;
- m_height = height;
- rectangle.X = x;
- rectangle.Y = y;
- rectangle.Width = width;
- rectangle.Height = height;
- Initialize();
- }
- public override DrawObject Clone()
- {
- DrawLocationCross drawRectangle = new DrawLocationCross(ISurfaceBox, 0, 0, 1, 0, 0);
- drawRectangle.objectType = DrawClass.Stitch;
- drawRectangle.drawToolType = DrawToolType.DrawLocationCross;
- drawRectangle.ISurfaceBox = this.ISurfaceBox;
- drawRectangle.rectangle = this.rectangle;
- FillDrawObjectFields(drawRectangle);
- return drawRectangle;
- }
- public override RectangleF GetBoundingBox()
- {
- return rectangle;
- }
- public override void Draw(Graphics g)
- {
- //样式暂时写死,没有对应样式设置
- int dashStyle = 0; //线形
- int thickness = 5; //粗细
- int color = -59111; //颜色
- Pen pen = new Pen(new SolidBrush(Color.FromArgb(color)), thickness);
- pen.DashStyle = (DashStyle)dashStyle;
- float lineLength = m_width < m_height ? m_width * 0.3f : m_height * 0.3f;//线长
- float x = rectangle.X + (m_width - lineLength) / 2;
- float y = rectangle.Y + (m_height - lineLength) / 2;
- g.DrawLine(pen, x, rectangle.Y + m_height / 2, x + lineLength, rectangle.Y + m_height / 2);
- g.DrawLine(pen, rectangle.X + m_width / 2, y, rectangle.X + m_width / 2, y + lineLength);
- if(this.points.Count > 0)
- {
- this.points[0] = this.ISurfaceBox.ScalePointToRulerPoint(new PointF(rectangle.X + m_width / 2, rectangle.Y + m_height / 2));
- }
- else
- {
- this.points.Add(0, this.ISurfaceBox.ScalePointToRulerPoint(new PointF(rectangle.X + m_width / 2, rectangle.Y + m_height / 2)));
- this.points.Add(1, m_z);
- }
- }
- 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;
- }
- /// <summary>
- /// Get number of handles
- /// </summary>
- public override int HandleCount
- {
- get
- {
- return 8;
- }
- }
- /// <summary>
- /// Get handle pointscroll by 1-based number
- /// </summary>
- /// <param name="handleNumber"></param>
- /// <returns></returns>
- public override PointF GetHandle(int handleNumber)
- {
- float x, y, xCenter, yCenter;
- xCenter = this.rectangle.X + this.rectangle.Width / 2;
- yCenter = this.rectangle.Y + this.rectangle.Height / 2;
- x = this.rectangle.X;
- y = this.rectangle.Y;
- switch (handleNumber)
- {
- case 1:
- x = this.rectangle.X;
- y = this.rectangle.Y;
- break;
- case 2:
- x = xCenter;
- y = this.rectangle.Y;
- break;
- case 3:
- x = this.rectangle.Right;
- y = this.rectangle.Y;
- break;
- case 4:
- x = this.rectangle.Right;
- y = yCenter;
- break;
- case 5:
- x = this.rectangle.Right;
- y = this.rectangle.Bottom;
- break;
- case 6:
- x = xCenter;
- y = this.rectangle.Bottom;
- break;
- case 7:
- x = this.rectangle.X;
- y = this.rectangle.Bottom;
- break;
- case 8:
- x = this.rectangle.X;
- y = yCenter;
- break;
- }
- return new PointF(x, y);
- }
- public override Rectangle GetHandleRectangle(int handleNumber)
- {
- PointF point = GetHandle(handleNumber);
- return new Rectangle((int)(point.X - 100), (int)(point.Y - 100), 201, 201);
- }
- /// <summary>
- /// Hit test.
- /// Return value: -1 - no hit
- /// 0 - hit anywhere
- /// > 1 - handle number
- /// </summary>
- /// <param name="pointscroll"></param>
- /// <returns></returns>
- 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);
- }
- /// <summary>
- /// Get cursor for the handle
- /// </summary>
- /// <param name="handleNumber"></param>
- /// <returns></returns>
- public override Cursor GetHandleCursor(int handleNumber)
- {
- return null;
- }
- /// <summary>
- /// Move handle to new pointscroll (resizing)
- /// </summary>
- /// <param name="pointscroll"></param>
- /// <param name="handleNumber"></param>
- public override void MoveHandleTo(Point point, int handleNumber)
- {
- return;
- }
- public override bool IntersectsWith(Rectangle rectangle)
- {
- return Rectangle.IntersectsWith(rectangle);
- }
- /// <summary>
- /// Move object
- /// </summary>
- /// <param name="deltaX"></param>
- /// <param name="deltaY"></param>
- public override void Move(int deltaX, int deltaY)
- {
- int x = ISurfaceBox.UnscaleScalar(deltaX);
- int y = ISurfaceBox.UnscaleScalar(deltaY);
- rectangle.X += x;
- rectangle.Y += y;
- }
- public override List<PointF> GetPoints()
- {
- List<PointF> points = new List<PointF>();
- points.Add(new PointF(rectangle.X, rectangle.Y));
- points.Add(new PointF(rectangle.Right, rectangle.Bottom));
- return points;
- }
- public List<PointF> GetRulerPoints()
- {
- List<PointF> points = new List<PointF>();
- points.Add(this.ISurfaceBox.ScalePointToRulerPoint(new PointF(rectangle.X, rectangle.Y)));
- points.Add(this.ISurfaceBox.ScalePointToRulerPoint(new PointF(rectangle.Right, rectangle.Bottom)));
- return points;
- }
- public Dictionary<int, object> GetViewPoints()
- {
- return this.points;
- }
- public void SetZPostion(Dictionary<int, object> point)
- {
- this.points = point;
- }
- }
- }
|