mac
2024-07-25 3f6685c77beeb12baf840733fb890860f4c26e7c
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
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
using System;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI.UI2.Intelligence.Automation.LogicView
{
    public class RGBColorView
    {
        public RGBColorView()
        {
        }
        /// <summary>
                /// 加载rgb选择弹窗
                /// </summary>
                /// <param name="function"></param>
                /// <param name="btn"></param>
        public void LoadRGBDialog(string stateRGBValue, Action<string> action)
        {
            string rgbString = "";
 
            Light tempLight = new Light();
 
            if (string.IsNullOrEmpty(stateRGBValue))
            {
                stateRGBValue = "255,255,255";
            }
 
            Dialog dialog = new Dialog()
            {
                Height = Application.GetRealHeight(647),
            };
 
            var bodyView = new FrameLayout();
            dialog.AddChidren(bodyView);
 
            var contentView = new FrameLayout()
            {
                Gravity = Gravity.BottomCenter,
                BackgroundColor = CSS_Color.MainBackgroundColor,
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(300),
                Radius = (uint)Application.GetRealWidth(12),
            };
            bodyView.AddChidren(contentView);
 
            #region 标题区
            var titleView = new FrameLayout()
            {
                Width = Application.GetRealWidth(343),
                Height = Application.GetRealHeight(52),
            };
            contentView.AddChidren(titleView);
 
            var btnTitle = new Button()
            {
                Height = Application.GetRealHeight(52),
                Gravity = Gravity.Center,
                TextSize = CSS_FontSize.SubheadingFontSize,
                TextColor = CSS_Color.MainColor,
                Text = "RGB",
                TextAlignment = TextAlignment.Center,
            };
            titleView.AddChidren(btnTitle);
            titleView.AddChidren(new Button() { Height = 1, BackgroundColor = CSS_Color.DividingLineColor, Y = Application.GetRealHeight(51) });
 
            #endregion
 
            int attrViewHight = Application.GetRealHeight(245);
            //属性设置区域
            var attrView = new FrameLayout()
            {
                Y = Application.GetRealHeight(52),
                Width = Application.GetRealWidth(343),
                Height = attrViewHight
            };
            contentView.AddChidren(attrView);
            attrView.AddChidren(new Button() { Height = Application.GetRealHeight(18) });
 
            #region RGB
            var rgbView = new FrameLayout()
            {
                Height = Application.GetRealHeight(248)
            };
            attrView.AddChidren(rgbView);
 
            var btnCurColor = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(10),
                Width = Application.GetMinRealAverage(24),
                Height = Application.GetMinRealAverage(24),
                Radius = (uint)Application.GetMinRealAverage(8),
                BorderColor = CSS_Color.PromptingColor2,
                BorderWidth = 1,
                BackgroundColor = (uint)(0xFF000000 + tempLight.GetRGBcolor(stateRGBValue))
            };
            rgbView.AddChidren(btnCurColor);
 
            //色盘的桌布控件(限制那个白色滑动球使用)
            var framePickerBack = new FrameLayout();
            framePickerBack.Gravity = Gravity.CenterHorizontal;
            framePickerBack.Y = Application.GetRealHeight(20);
            framePickerBack.Width = Application.GetMinRealAverage(198);
            framePickerBack.Height = Application.GetMinRealAverage(198);
            rgbView.AddChidren(framePickerBack);
 
            var colorPicker = new ColorPicker()
            {
                ColorImagePath = "FunctionIcon/Light/ColorWheel.png",
            };
            framePickerBack.AddChidren(colorPicker);
 
 
            //白点控件
            var btnWhiteRound = new Button();
            btnWhiteRound.Width = Application.GetRealWidth(24);
            btnWhiteRound.Height = Application.GetRealWidth(24);
            btnWhiteRound.UnSelectedImagePath = "FunctionIcon/Light/ColorWheelTip.png";
            btnWhiteRound.Visible = false;
            framePickerBack.AddChidren(btnWhiteRound);
 
 
            //当前点击的【点】是否正确
            bool pointIsRight = false;
            //圆的半径(考虑边界,需要设置它的半径比较小一点)
            int circleR = colorPicker.Width / 2 - Application.GetRealWidth(12);
 
 
            colorPicker.ColorChaged += (sender2, e2) =>
            {
                rgbString = (e2[0] + "," + e2[1] + "," + e2[2]).ToString();
                //trait.value = rgbString;
                btnCurColor.BackgroundColor = (uint)(0xFF000000 + tempLight.GetRGBcolor(rgbString));
            };
            colorPicker.MouseDownEventHandler += (sender, e) =>
            {
                pointIsRight = this.CheckPoint(circleR, colorPicker.Width / 2, colorPicker.Height / 2, (int)e.X, (int)e.Y);
                if (pointIsRight == false)
                {
                    //点的区域不是圆盘内
                    return;
                }
                //显示白点
                btnWhiteRound.X = (int)e.X - btnWhiteRound.Width / 2;
                btnWhiteRound.Y = (int)e.Y - btnWhiteRound.Height / 2;
                if (btnWhiteRound.Visible == false)
                {
                    btnWhiteRound.Visible = true;
                }
            };
 
            colorPicker.MouseMoveEventHandler += (sender, e) =>
            {
                //当鼠标点下事件处理
                colorPicker.MouseDownEventHandler(sender, e);
            };
 
 
            #endregion
 
            #region 
            var btnCancel = new Button()
            {
                X = Application.GetRealWidth(20),
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealHeight(44),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = CSS_FontSize.TextFontSize,
                TextColor = CSS_Color.TextualColor,
                TextID = StringId.Cancel,
            };
            titleView.AddChidren(btnCancel);
            btnCancel.MouseUpEventHandler = (sender, e) =>
            {
                dialog.Close();
            };
 
            var btnComplete = new Button()
            {
                X = Application.GetRealWidth(223),
                Width = Application.GetRealWidth(100),
                Height = Application.GetRealHeight(46),
                TextColor = CSS_Color.MainColor,
                TextAlignment = TextAlignment.CenterRight,
                TextSize = CSS_FontSize.TextFontSize,
                TextID = StringId.Complete
            };
            titleView.AddChidren(btnComplete);
 
            //例:右下圆角 大小为50
            int mRectCornerID = HDLUtils.RectCornerBottomRight;
            btnComplete.SetCornerWithSameRadius((uint)Application.GetRealWidth(14), mRectCornerID);
            btnComplete.MouseUpEventHandler = (sender, e) =>
            {
                dialog.Close();
                action?.Invoke(rgbString);
                //trait.value = rgbString;
 
 
            };
 
            #endregion
 
 
            dialog.Show();
 
        }
 
        /// <summary>
        /// 检测点击点
        /// </summary>
        /// <param name="circleR">圆的半径</param>
        /// <param name="circleX">圆心X轴</param>
        /// <param name="circleY">圆心Y轴</param>
        /// <param name="pointX">点击点的X轴</param>
        /// <param name="pointY">点击点的Y轴</param>
        /// <returns></returns>
        private bool CheckPoint(int circleR, int circleX, int circleY, int pointX, int pointY)
        {
            int dwidth = circleX - pointX;
            if (dwidth < 0) { dwidth *= -1; }
 
            int dHeight = circleY - pointY;
            if (dHeight < 0) { dHeight *= -1; }
 
            //根据三角函数,求三角形的斜边长
            int dlength = dwidth * dwidth + dHeight * dHeight;
            //半径长度(不开方,所以是按平方算)
            circleR *= circleR;
            if (dlength < circleR)
            {
                //如果组成的三角形并没有长过半径,则代表还在圆内(不允许点边界)
                return true;
            }
            return false;
        }
        /// <summary>
        /// 获取控件背景值
        /// button.BackgroundColor =(uint)(0xFF000000 + new Light().GetRGBcolor(rgbValueStr))
        /// </summary>
        /// <param name="rgbString">rgb值</param>
        /// <returns></returns>
        public uint GetBackgroundColor(string rgbString)
        {
            return (uint)(0xFF000000 + new Light().GetRGBcolor(rgbString));
        }
    }
}