123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318 |
- using PaintDotNet.Annotation.Enum;
- using PaintDotNet.Base.SettingModel;
- using System;
- using System.Collections.Generic;
- using System.Drawing;
- using System.Drawing.Drawing2D;
- using System.Windows.Forms;
- using static PaintDotNet.Base.SettingModel.LabelStyleModel;
- namespace PaintDotNet.Annotation.Label
- {
- /// <summary>
- /// 标注->圆->椭圆
- /// </summary>
- public class DrawEllipse : DrawObject
- {
- /// <summary>
- /// 标注样式信息model
- /// </summary>
- public Oval labelOvalStyleModel;
- public DrawEllipse(ISurfaceBox surfaceBox, int x, int y, int width, int height) : base()
- {
- this.objectType = DrawClass.Label;
- this.drawToolType = DrawToolType.DrawEllipse;
- labelOvalStyleModel = surfaceBox.GetLabelStyleModel().ovalModel;
- rectangle.X = x;
- rectangle.Y = y;
- rectangle.Width = width;
- rectangle.Height = height;
- Initialize();
- }
- public DrawEllipse(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
- {
- this.objectType = DrawClass.Label;
- this.drawToolType = DrawToolType.DrawEllipse;
- this.ISurfaceBox = surfaceBox;
- labelOvalStyleModel = (Oval)parentStyleModel;
- rectangle.X = points[0].X;
- rectangle.Y = points[0].Y;
- rectangle.Width = points[1].X - points[0].X;
- rectangle.Height = points[1].Y - points[0].Y;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone()
- {
- DrawEllipse drawRectangle = new DrawEllipse(ISurfaceBox, 0, 0, 1, 0);
- drawRectangle.objectType = DrawClass.Label;
- drawRectangle.drawToolType = DrawToolType.DrawEllipse;
- drawRectangle.ISurfaceBox = this.ISurfaceBox;
- drawRectangle.rectangle = this.rectangle;
- FillDrawObjectFields(drawRectangle);
- return drawRectangle;
- }
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- DrawEllipse drawRectangle = new DrawEllipse(surfaceBox, 0, 0, 1, 0);
- drawRectangle.objectType = DrawClass.Label;
- drawRectangle.drawToolType = DrawToolType.DrawEllipse;
- drawRectangle.ISurfaceBox = surfaceBox;
- drawRectangle.rectangle = this.rectangle;
- drawRectangle.labelOvalStyleModel = this.labelOvalStyleModel;
- FillDrawObjectFields(drawRectangle);
- return drawRectangle;
- }
- /// <summary>
- /// Draw rectangle
- /// </summary>
- /// <param name="g"></param>
- public override void Draw(Graphics g)
- {
- Color color = Color.FromArgb(this.labelOvalStyleModel.lineColor);
- int penWidth = this.labelOvalStyleModel.lineWidth;
- Pen pen = new Pen(color, penWidth);
- pen.DashStyle = (DashStyle)this.labelOvalStyleModel.lineStyle;
- Color fillColor = Color.FromArgb(this.labelOvalStyleModel.fillColor);
- SolidBrush fillBrush = new SolidBrush(fillColor);
-
- g.FillEllipse(fillBrush,DrawRectangle.GetNormalizedRectangle(Rectangle));
- g.DrawEllipse(pen, DrawRectangle.GetNormalizedRectangle(Rectangle));
- pen.Dispose();
- fillBrush.Dispose();
- }
- protected void SetRectangle(float x, float y, float width, float height)
- {
- rectangle.X = x;
- rectangle.Y = y;
- rectangle.Width = width;
- 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 = rectangle.X + rectangle.Width / 2;
- yCenter = rectangle.Y + rectangle.Height / 2;
- x = rectangle.X;
- y = rectangle.Y;
- switch (handleNumber)
- {
- case 1:
- x = rectangle.X;
- y = rectangle.Y;
- break;
- case 2:
- x = xCenter;
- y = rectangle.Y;
- break;
- case 3:
- x = rectangle.Right;
- y = rectangle.Y;
- break;
- case 4:
- x = rectangle.Right;
- y = yCenter;
- break;
- case 5:
- x = rectangle.Right;
- y = rectangle.Bottom;
- break;
- case 6:
- x = xCenter;
- y = rectangle.Bottom;
- break;
- case 7:
- x = rectangle.X;
- y = rectangle.Bottom;
- break;
- case 8:
- x = rectangle.X;
- y = yCenter;
- break;
- }
- return new PointF(x, y);
- }
- /// <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)
- {
- switch (handleNumber)
- {
- case 1:
- return Cursors.SizeNWSE;
- case 2:
- return Cursors.SizeNS;
- case 3:
- return Cursors.SizeNESW;
- case 4:
- return Cursors.SizeWE;
- case 5:
- return Cursors.SizeNWSE;
- case 6:
- return Cursors.SizeNS;
- case 7:
- return Cursors.SizeNESW;
- case 8:
- return Cursors.SizeWE;
- default:
- return Cursors.Default;
- }
- }
- /// <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);
- }
- 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 void Normalize()
- {
- rectangle = GetNormalizedRectangle(rectangle);
- }
- public override RectangleF GetBoundingBox()
- {
- return rectangle;
- }
- 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 override ParentStyleModel GetStyle()
- {
- return labelOvalStyleModel;
- }
- }
- }
|