using Bro.Common.Model; using System; using System.Drawing; using System.Windows; using System.Windows.Media; namespace Bro.Common.ImageCanvas.Shapes { public class ComplexPointIndicator : ShapeElementBase { public ComplexPoint PointInfo { get; set; } public float Angle { get; set; } readonly int halfRectSize = 20; readonly int halfLength = 100; public override void SetNormalPen() { if (PointInfo.PlatPoint.IsAvailable) { Pen = new System.Windows.Media.Pen(new SolidColorBrush(Colors.Green), 3); } else { Pen = new System.Windows.Media.Pen(new SolidColorBrush(Colors.Red), 3); } } protected override void DrawShape(DrawingContext dc) { Text = $"{Index} 图像坐标:{PointInfo.ImagePoint.X},{PointInfo.ImagePoint.Y}\r\n机台坐标:{PointInfo.PlatPoint.X},{PointInfo.PlatPoint.Y}\r\n角度:{Angle}"; dc.DrawText(new FormattedText(Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Typeface, FontSize, Pen.Brush), new System.Windows.Point(PointInfo.ImagePoint.X + FontDistance, PointInfo.ImagePoint.Y - FontDistance)); dc.PushTransform(new RotateTransform(0 - Angle, PointInfo.ImagePoint.X, PointInfo.ImagePoint.Y)); dc.DrawRectangle(null, Pen, new Rect(PointInfo.ImagePoint.X - halfRectSize, PointInfo.ImagePoint.Y - halfRectSize, halfRectSize * 2, halfRectSize * 2)); dc.DrawLine(Pen, new System.Windows.Point(PointInfo.ImagePoint.X, PointInfo.ImagePoint.Y - halfLength), new System.Windows.Point(PointInfo.ImagePoint.X, PointInfo.ImagePoint.Y + halfLength)); dc.DrawLine(Pen, new System.Windows.Point(PointInfo.ImagePoint.X - halfLength, PointInfo.ImagePoint.Y), new System.Windows.Point(PointInfo.ImagePoint.X + halfLength, PointInfo.ImagePoint.Y)); } public override void Draw(Graphics g) { throw new NotImplementedException(); } protected override bool IsMouseInSide(System.Windows.Point point) { return Math.Sqrt(Math.Pow(PointInfo.ImagePoint.X - point.X, 2) + Math.Pow(PointInfo.ImagePoint.Y - point.Y, 2)) < halfLength; } protected override bool IsMouseHover(System.Windows.Point point) { return false; } } }