123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268 |
- 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.Startup;
- using PaintDotNet.Base.CommTool;
- using System.IO;
- using static PaintDotNet.Base.SettingModel.LabelStyleModel;
- using PaintDotNet.Annotation.Enum;
- using System.Collections.Generic;
- using PaintDotNet.Base.Enum;
- namespace PaintDotNet.Annotation.Label
- {
- /// <summary>
- /// 标注->标记->日期
- /// </summary>
- public class DrawDateMark : DrawObject
- {
- private static Cursor handleCursor = new Cursor(PdnResources.GetResourceStream("Cursors.AnnotationPolyHandle.cur"));
- /// <summary>
- /// 标注样式信息model
- /// </summary>
- public DateMark labelDateMarkStyleModel;
- /// <summary>
- /// 日期信息
- /// </summary>
- private string dateStr = "";
- /// <summary>
- /// 辅助为第一次创建日期对象赋值
- /// </summary>
- public bool isFirstClick = true;
- public DrawDateMark(ISurfaceBox surfaceBox) : base()
- {
- this.objectType = DrawClass.Label;
- this.drawToolType = DrawToolType.DrawDateMark;
- Initialize();
- }
- public DrawDateMark(ISurfaceBox surfaceBox, string nowDate) : base()
- {
- this.objectType = DrawClass.Label;
- this.drawToolType = DrawToolType.DrawDateMark;
- dateStr = nowDate;
- labelDateMarkStyleModel = surfaceBox.GetLabelStyleModel().dateMark;
- startPoint = new PointF(0, 0);
- Initialize();
- }
- public DrawDateMark(ISurfaceBox surfaceBox, List<PointF> points, ParentStyleModel parentStyleModel, Object content) : base()
- {
- this.objectType = DrawClass.Label;
- this.drawToolType = DrawToolType.DrawDateMark;
- this.ISurfaceBox = surfaceBox;
- labelDateMarkStyleModel = (LabelStyleModel.DateMark)parentStyleModel;
- startPoint = points[0];
- dateStr = content.ToString();
- isFirstClick = false;
- }
- /// <summary>
- /// Clone this instance
- /// </summary>
- public override DrawObject Clone()
- {
- DrawDateMark dateMark = new DrawDateMark(ISurfaceBox);
- dateMark.objectType = DrawClass.Label;
- dateMark.drawToolType = DrawToolType.DrawDateMark;
- dateMark.ISurfaceBox = ISurfaceBox;
- dateMark.startPoint = this.startPoint;
- dateMark.dateStr = this.dateStr;
- dateMark.isFirstClick = false;
- dateMark.labelDateMarkStyleModel = this.labelDateMarkStyleModel;
- FillDrawObjectFields(dateMark);
- return dateMark;
- }
- public override DrawObject Clone(ISurfaceBox surfaceBox)
- {
- DrawDateMark dateMark = new DrawDateMark(surfaceBox);
- dateMark.objectType = DrawClass.Label;
- dateMark.drawToolType = DrawToolType.DrawDateMark;
- dateMark.ISurfaceBox = surfaceBox;
- dateMark.startPoint = this.startPoint;
- dateMark.dateStr = this.dateStr;
- dateMark.isFirstClick = false;
- dateMark.labelDateMarkStyleModel = this.labelDateMarkStyleModel;
- FillDrawObjectFields(dateMark);
- return dateMark;
- }
- public override void Draw(Graphics g)
- {
- g.SmoothingMode = SmoothingMode.AntiAlias;
- Font textfont = new Font(this.labelDateMarkStyleModel.font, this.labelDateMarkStyleModel.fontSize);
- Brush textbrush = new SolidBrush(Color.FromArgb(this.labelDateMarkStyleModel.textColor));
- Color color = Color.FromArgb(this.labelDateMarkStyleModel.backgroundBoxColor);
- Pen pen = new Pen(color, this.labelDateMarkStyleModel.lineWidth);
- Color fillColor = Color.FromArgb(this.labelDateMarkStyleModel.backgroundColor);
- SolidBrush fillBrush = new SolidBrush(fillColor);
-
- Size fontSize = g.MeasureString(dateStr, textfont).ToSize();
- float positionSize = 0;//位置大小
- float backgroundSize = 0;//背景大小
- if(fontSize.Width > fontSize.Height)
- {
- positionSize = fontSize.Width * (this.labelDateMarkStyleModel.positionSize / 100f);
- backgroundSize = fontSize.Width * (this.labelDateMarkStyleModel.backgroundSize / 100f);
- }
- else
- {
- positionSize = fontSize.Height * (this.labelDateMarkStyleModel.positionSize / 100f);
- backgroundSize = fontSize.Height * (this.labelDateMarkStyleModel.backgroundSize / 100f);
- }
- if (isFirstClick)
- {
- string gainPosition = this.labelDateMarkStyleModel.position;
- SizeF windowSize = this.ISurfaceBox.GetDocumentSize();
- switch ((TagLocation)System.Enum.ToObject(typeof(TagLocation), int.Parse(gainPosition)))
- {
- case TagLocation.UpLeft:
- startPoint.X = 0 + positionSize;
- startPoint.Y = 0 + positionSize;
- break;
- case TagLocation.UpRight:
- startPoint.X = Convert.ToInt32(windowSize.Width) - fontSize.Width - 2 * backgroundSize - positionSize;
- startPoint.Y = 0 + positionSize;
- break;
- case TagLocation.DownLeft:
- startPoint.X = 0 + positionSize;
- startPoint.Y = Convert.ToInt32(windowSize.Height) - fontSize.Height - 2 * backgroundSize - positionSize;
- break;
- case TagLocation.DownRight:
- startPoint.X = Convert.ToInt32(windowSize.Width) - fontSize.Width - 2 * backgroundSize - positionSize;
- startPoint.Y = Convert.ToInt32(windowSize.Height) - fontSize.Height - 2 * backgroundSize - positionSize;
- break;
- }
- isFirstClick = false;
- }
- g.FillRectangle(fillBrush, startPoint.X, startPoint.Y, fontSize.Width + 2 * backgroundSize, fontSize.Height + 2 * backgroundSize);
- g.DrawRectangle(pen, startPoint.X, startPoint.Y, fontSize.Width + 2 * backgroundSize, fontSize.Height + 2 * backgroundSize);
- g.DrawString(dateStr, textfont, textbrush, startPoint.X + backgroundSize, startPoint.Y + backgroundSize);
- rectangle.X = startPoint.X;
- rectangle.Y = startPoint.Y;
- rectangle.Width = fontSize.Width + 2 * backgroundSize;
- rectangle.Height = fontSize.Height + 2 * backgroundSize;
- fillBrush.Dispose();
- pen.Dispose();
- }
- public override int HandleCount
- {
- get
- {
- return 1;
- }
- }
- /// <summary>
- /// Get handle pointscroll by 1-based number
- /// </summary>
- /// <param name="handleNumber"></param>
- /// <returns></returns>
- public override PointF GetHandle(int handleNumber)
- {
- return startPoint;
- }
- /// <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);
- }
- 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<PointF> GetPoints()
- {
- List<PointF> points = new List<PointF>();
- points.Add(startPoint);
- return points;
- }
- public override ParentStyleModel GetStyle()
- {
- return labelDateMarkStyleModel;
- }
- public override string GetContent()
- {
- return dateStr;
- }
- }
- }
|