领胜LDS 键盘AOI检测项目
xcd
2020-07-14 d511823e84953e616da9a24484d730c49c457c08
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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
using Bro.Common.Helper;
using Bro.Common.Model;
using Bro.UI.Model.Winform;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Drawing.Design;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
 
namespace Bro.M071.Process.UI
{
    public class KeyIndicator : ElementBase
    {
        [Browsable(false)]
        public override string ID { get => base.ID; set => base.ID = value; }
        [Browsable(false)]
        public override string Name { get => base.Name; set => base.Name = value; }
        [Browsable(false)]
        public override Font Font { get => base.Font; set => base.Font = value; }
        [Browsable(false)]
        public override int FontDistance { get => base.FontDistance; set => base.FontDistance = value; }
        [Browsable(false)]
        public override int Index { get => base.Index; set => base.Index = value; }
        [Browsable(false)]
        public override bool IsShowRemark { get => base.IsShowRemark; set => base.IsShowRemark = value; }
        [Browsable(false)]
        public override bool IsEnabled { get => base.IsEnabled; set => base.IsEnabled = value; }
 
        [Category("显示设置")]
        [Description("标签显示区域")]
        [DisplayName("标签显示区域")]
        public Rectangle DisplayRect { get; set; } = new Rectangle();
 
        [Browsable(false)]
        public string Text { get; set; } = "";
        [Browsable(false)]
        public bool? ResultState { get; set; } = null;
 
        public KeyIndicator() { }
 
        public KeyIndicator(string id, Rectangle rect)
        {
            ID = id;
            DisplayRect = rect;
        }
 
        public override object Clone()
        {
            return new KeyIndicator()
            {
                DisplayRect = this.DisplayRect,
            };
        }
 
        protected override void SetSelectedPen()
        {
            Pen = new Pen(Color.Red, 3);
        }
 
        public override void Draw(Graphics g)
        {
            if (ResultState == null)
            {
                g.DrawRectangle(Pen, DisplayRect);
            }
            RectangleF rectFill = new RectangleF(DisplayRect.X + 1, DisplayRect.Y + 1, DisplayRect.Width - 2, DisplayRect.Height - 2);
            if (ResultState != null)
            {
                var txtSize = g.MeasureString(Text, Font);
 
                Color backColor = Color.Green;
                Color foreColor = Color.Black;
                if (!ResultState.Value)
                {
                    backColor = Color.Red;
                    //foreColor = Color.White;
                }
 
                g.FillRectangle(new SolidBrush(Color.FromArgb(85, backColor)), rectFill);
                g.DrawString(Text, Font, new SolidBrush(foreColor), (float)(DisplayRect.X + DisplayRect.Width / 2.0 - txtSize.Width / 2.0), (float)(DisplayRect.Y + DisplayRect.Height));
            }
        }
 
        public override string GetDisplayText()
        {
            return $"{DisplayRect.X} {DisplayRect.Y} {DisplayRect.Width} {DisplayRect.Height}";
        }
 
        public override bool IsIntersect(Rectangle rect)
        {
            return false;
        }
 
        public override bool IsMouseHover(Point p)
        {
            return false;
        }
 
        public override bool IsMouseInSide(Point p)
        {
            return p.X >= DisplayRect.X && p.X <= DisplayRect.X + DisplayRect.Width && p.Y >= DisplayRect.Y && p.Y <= DisplayRect.Y + DisplayRect.Height;
        }
 
        public override bool IsMouseCanMoveElement(Point p)
        {
            return IsMouseInSide(p);
        }
 
        public override void OnKeyDown(object sender, KeyEventArgs e)
        {
        }
 
        public override void OnKeyUp(object sender, KeyEventArgs e)
        {
        }
 
        public override void OnMouseDownWhenNew(Point p)
        {
        }
 
        public override void OnMouseMoveWhenNew(Point p)
        {
        }
 
        public override void OnMouseUpWhenNew(Point p)
        {
        }
 
        public override void Translate(int x, int y)
        {
            DisplayRect = new Rectangle(DisplayRect.X + x, DisplayRect.Y + y, DisplayRect.Width, DisplayRect.Height);
        }
 
        public override void Relocate(Point point)
        {
            DisplayRect = new Rectangle(point.X - DisplayRect.Width / 2, point.Y - DisplayRect.Height / 2, DisplayRect.Width, DisplayRect.Height);
        }
 
        public override bool IsMouseCanStretchBottom(Point p)
        {
 
            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width / 2)) < (DisplayRect.Width / 3) && Math.Abs(p.Y - DisplayRect.Y - DisplayRect.Height) < (DisplayRect.Height / 3);
        }
 
        public override bool IsMouseCanStretchRight(Point p)
        {
            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < (DisplayRect.Width / 3) && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height / 2)) < (DisplayRect.Height / 3);
        }
 
        public override bool IsMouseCanStretchRightLowerCorner(Point p)
        {
            return Math.Abs(p.X - (DisplayRect.X + DisplayRect.Width)) < (DisplayRect.Width / 3) && Math.Abs(p.Y - (DisplayRect.Y + DisplayRect.Height)) < (DisplayRect.Height / 3);
        }
 
        int x, y = 0;
        public override void StretchBottom(Point p)
        {
            if (p.Y > DisplayRect.Y)
            {
                DisplayRect = new Rectangle(DisplayRect.X, DisplayRect.Y, DisplayRect.Width, p.Y - DisplayRect.Y);
            }
        }
 
        public override void StretchRight(Point p)
        {
            if (p.X > DisplayRect.X)
            {
                DisplayRect = new Rectangle(DisplayRect.X, DisplayRect.Y, p.X - DisplayRect.X, DisplayRect.Height);
            }
        }
 
        public override void StretchRightLowerCorner(Point p)
        {
            if (p.X > DisplayRect.X && p.Y > DisplayRect.Y)
            {
                DisplayRect = new Rectangle(DisplayRect.X, DisplayRect.Y, p.X - DisplayRect.X, p.Y - DisplayRect.Y);
            }
        }
 
        protected override void DrawResult(Graphics g)
        {
        }
    }
}