领胜LDS 键盘AOI检测项目
xcd
2020-06-24 d6c577e17ee7bb5331dd51d803f9b42441b0f0e5
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
using System;
using System.Drawing;
using System.Windows;
using System.Windows.Media;
 
namespace Bro.Common.ImageCanvas.Shapes
{
    public class PointIndicator : ShapeElementBase
    {
        public float X { get; set; }
        public float Y { get; set; }
 
        public float Radius { get; set; }
 
        public PointIndicator(float x, float y, float radius = 35.0f)
        {
            X = x;
            Y = y;
            Radius = radius;
 
            Text = $"{X.ToString("f2")},{Y.ToString("f2")}";
        }
 
        protected override void DrawShape(DrawingContext dc)
        {
            dc.DrawEllipse(null, Pen, new System.Windows.Point(X, Y), Radius, Radius);
            dc.DrawEllipse(null, Pen, new System.Windows.Point(X, Y), Radius * 0.8, Radius * 0.8);
 
            dc.DrawLine(Pen, new System.Windows.Point(X, Y - Radius), new System.Windows.Point(X, Y + Radius));
            dc.DrawLine(Pen, new System.Windows.Point(X - Radius, Y), new System.Windows.Point(X + Radius, Y));
 
            FormattedText fTxt = new FormattedText(Text, System.Globalization.CultureInfo.CurrentCulture, FlowDirection.LeftToRight, Typeface, FontSize, Pen.Brush);
            dc.DrawText(fTxt, new System.Windows.Point(X - fTxt.WidthIncludingTrailingWhitespace / 2, Y - Radius / 2 - fTxt.MaxTextHeight));
        }
 
        public override void Draw(Graphics g)
        {
            throw new NotImplementedException();
        }
 
        protected override bool IsMouseInSide(System.Windows.Point point)
        {
            return Math.Sqrt(Math.Pow(X - point.X, 2) + Math.Pow(Y - point.Y, 2)) < Radius;
        }
 
        protected override bool IsMouseHover(System.Windows.Point point)
        {
            return false;
        }
 
        public override void SetNormalPen()
        {
            Pen = new System.Windows.Media.Pen(new SolidColorBrush(Colors.GreenYellow), 3);
        }
    }
}