using Bro.Common.Helper; using Bro.Common.Model; using System; using System.ComponentModel; using System.Drawing; using System.Drawing.Design; using System.Windows.Forms; namespace Bro.Common.UI { public class CrossHair : ElementBase { #region 基类属性复写 [Browsable(false)] public override string ID { get => base.ID; set => base.ID = value; } [Browsable(false)] public override int Index { get => base.Index; set => base.Index = value; } [Browsable(false)] public override string Name { get => base.Name; set => base.Name = value; } [Browsable(false)] public override bool IsEnabled { get => base.IsEnabled; set => base.IsEnabled = value; } #endregion #region 属性 [Category("标定属性")] [Description("标定点坐标信息")] [TypeConverter(typeof(ComplexObjectConvert))] [Editor(typeof(PropertyObjectEditor), typeof(UITypeEditor))] public CalibrationPoint CenterPoint { get; set; } [Category("显示属性")] [Description("标记框大小")] [Browsable(false)] public int HalfRectangleSize { get; set; } = 10; [Category("显示属性")] [Description("标记线长度")] [Browsable(false)] public int HalfLength { get; set; } = 30; #endregion #region 构造方法 public CrossHair() { } public CrossHair(PointF centerPoint, int halfRectSiez = 10, int halfLength = 30) { CenterPoint = new CalibrationPoint(centerPoint); HalfRectangleSize = halfRectSiez; HalfLength = halfLength; CenterPoint.PropertyChanged -= CenterPoint_PropertyChanged; CenterPoint.PropertyChanged += CenterPoint_PropertyChanged; CalculateBaseRectangle(); } public CrossHair(CalibrationPoint centerPoint, int halfRectSiez = 10, int halfLength = 30) { CenterPoint = centerPoint; HalfRectangleSize = halfRectSiez; HalfLength = halfLength; CenterPoint.PropertyChanged -= CenterPoint_PropertyChanged; CenterPoint.PropertyChanged += CenterPoint_PropertyChanged; CalculateBaseRectangle(); } #endregion #region ElementBase private void CenterPoint_PropertyChanged(object sender, PropertyChangedEventArgs e) { SetNormalPen(); } protected override void SetNormalPen() { if (CenterPoint.IsBasePoint) { HalfRectangleSize = 20; HalfLength = 80; Pen = new Pen(Color.DarkGreen, 1); } else { HalfRectangleSize = 10; HalfLength = 30; base.SetNormalPen(); } } public override void Calculate(string imagePath) { //throw new NotImplementedException(); } public override void Calculate(Bitmap image) { //throw new NotImplementedException(); } public override void Calculate(IntPtr imagePtr, int ptrSize, int imageWidth, int imageHeight) { //throw new NotImplementedException(); } public override object Clone() { //throw new NotImplementedException(); return null; } public override void Draw(Graphics g) { g.DrawRectangle(Pen, CenterPoint.U - HalfRectangleSize, CenterPoint.V - HalfRectangleSize, HalfRectangleSize * 2, HalfRectangleSize * 2); g.DrawLine(Pen, CenterPoint.U, CenterPoint.V - HalfLength, CenterPoint.U, CenterPoint.V + HalfLength); g.DrawLine(Pen, CenterPoint.U - HalfLength, CenterPoint.V, CenterPoint.U + HalfLength, CenterPoint.V); if (IsShowRemark) { string info = Index.ToString() + ":(" + CenterPoint.X.ToString() + ";" + CenterPoint.Y.ToString() + ")"; g.DrawString(info, new Font("NewRoman", FontSize), new SolidBrush(Pen.Color), new PointF(CenterPoint.U + FontDistance, CenterPoint.V + FontDistance)); } } public override bool IsMouseHover(Point p) { //throw new NotImplementedException(); return false; } public override bool IsMouseInSide(Point p) { return (p.X >= BaseRectangle.Location.X && p.X <= BaseRectangle.Location.X + BaseRectangle.Width && p.Y >= BaseRectangle.Location.Y && p.Y <= BaseRectangle.Location.Y + BaseRectangle.Height); } public override bool IsIntersect(Rectangle rect) { return rect.IntersectsWith(BaseRectangle); } public override void CalculateBaseRectangle() { BaseRectangle = new Rectangle(new Point((int)CenterPoint.U - HalfLength, (int)CenterPoint.V - HalfLength), new Size(HalfLength * 2, HalfLength * 2)); } public override void OnKeyDown(object sender, KeyEventArgs e) { //throw new NotImplementedException(); } public override void OnKeyUp(object sender, KeyEventArgs e) { //throw new NotImplementedException(); } public override void OnMouseDownWhenNew(Point p) { //throw new NotImplementedException(); } public override void OnMouseMoveWhenNew(Point p) { //throw new NotImplementedException(); } public override void OnMouseUpWhenNew(Point p) { //throw new NotImplementedException(); } public override void Translate(int x, int y) { //CenterPoint.U -= x; //CenterPoint.V -= y; } protected override void DrawResult(Graphics g) { //throw new NotImplementedException(); } public override string GetDisplayText() { return ""; } #endregion } }