wxr
2024-11-01 c0c734d7a84cf7105401878ffc4b64cbb67621d1
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
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
using System;
using HDL_ON.DriverLayer;
using HDL_ON.Entity;
using HDL_ON.UI.CSS;
using Shared;
 
namespace HDL_ON.UI
{
    public class ColorfulSettingPage : FrameLayout
    {
        FrameLayout bodyView;
 
        Action<uint> backAction;
        public uint curColor = 0;
        bool isSatrtColor = false;
        byte redColor = 0;
        byte greenColor = 0;
        byte blueColor = 0;
        Function function;
        public ColorfulSettingPage(Function device, Action<uint> action,bool isStart)
        {
            bodyView = this;
            function = device;
            backAction = action;
            isSatrtColor = isStart;
        }
 
        public void LoadPage(string curColorString)
        {
            uint.TryParse(curColorString, out curColor);
 
            bodyView.BackgroundColor = CSS_Color.BackgroundColor;
            new TopViewDiv(bodyView, Language.StringByID(StringId.Setting)).LoadTopView(()=> {
            });
 
            var contentView = new VerticalScrolViewLayout()
            {
                Y = Application.GetRealHeight(64+34),
                Height = Application.GetRealHeight(570),
                ScrollEnabled = false,
            };
            bodyView.AddChidren(contentView);
 
            #region 色盘
            //色盘的桌布控件(限制那个白色滑动球使用)
            var framePickerBack = new FrameLayout();
            framePickerBack.Gravity = Gravity.CenterHorizontal;
            framePickerBack.Y = Application.GetRealHeight(100);
            framePickerBack.Width = Application.GetMinRealAverage(216 );
            framePickerBack.Height = Application.GetMinRealAverage(216);
            //framePickerBack.BackgroundColor = 0xFFFF0000;
            contentView.AddChidren(framePickerBack);
 
            var colorPicker = new ColorPicker()
            {
                Gravity = Gravity.Center,
                ColorImagePath = "FunctionIcon/Light/ColorWheel.png",
            };
            framePickerBack.AddChidren(colorPicker);
 
            //白点控件
            var diameter = Application.GetRealWidth(12);
            var btnWhiteRound = new Button()
            {
                Width = diameter,
                Height = diameter,
                Radius = (uint)Application.GetRealWidth(6),
                BorderWidth = (uint)Application.GetRealWidth(1),
                BorderColor = CSS_Color.MainBackgroundColor,
                Enable = false,
            };
            btnWhiteRound.Visible = false;
            framePickerBack.AddChidren(btnWhiteRound);
 
 
            bool pointIsRight = false;
            int circleR = colorPicker.Width / 2 - Application.GetRealWidth(2);
            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 recommendView = new FrameLayout()
            {
                Height = Application.GetRealHeight(120),
            };
            contentView.AddChidren(recommendView);
 
            var btnRecommenTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = Application.GetRealHeight(20),
                TextAlignment = TextAlignment.CenterLeft,
                Height = Application.GetRealHeight(41),
                TextSize = 18,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextID = StringId.Recommen,
            };
            recommendView.AddChidren(btnRecommenTitle);
 
            var recommendColorView = new HorizontalScrolViewLayout() {
                Y = btnRecommenTitle.Bottom,
                Height = Application.GetRealHeight(40),
            };
            recommendView.AddChidren(recommendColorView);
 
 
            recommendColorView.AddChidren(new Button() { Width = Application.GetRealWidth(16)});
            var btnRecommenColor1 = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = 0xFFFC4645,
                Radius = (uint)Application.GetRealWidth(14),
            };
            recommendColorView.AddChidren(btnRecommenColor1);
 
 
            recommendColorView.AddChidren(new Button() { Width = Application.GetRealWidth(23) });
            var btnRecommenColor2 = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = 0xFFFD834D,
                Radius = (uint)Application.GetRealWidth(14),
            };
            recommendColorView.AddChidren(btnRecommenColor2);
 
 
            recommendColorView.AddChidren(new Button() { Width = Application.GetRealWidth(23) });
            var btnRecommenColor3 = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = 0xFFFEF267,
                Radius = (uint)Application.GetRealWidth(14),
            };
            recommendColorView.AddChidren(btnRecommenColor3);
 
 
            recommendColorView.AddChidren(new Button() { Width = Application.GetRealWidth(23) });
            var btnRecommenColor4 = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = 0xFF73FD7B,
                Radius = (uint)Application.GetRealWidth(14),
            };
            recommendColorView.AddChidren(btnRecommenColor4);
 
            recommendColorView.AddChidren(new Button() { Width = Application.GetRealWidth(23) });
            var btnRecommenColor5 = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = 0xFF45B7FD,
                Radius = (uint)Application.GetRealWidth(14),
            };
            recommendColorView.AddChidren(btnRecommenColor5);
 
 
            recommendColorView.AddChidren(new Button() { Width = Application.GetRealWidth(23) });
            var btnRecommenColor6 = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = 0xFF5558fd,
                Radius = (uint)Application.GetRealWidth(14),
            };
            recommendColorView.AddChidren(btnRecommenColor6);
 
            recommendColorView.AddChidren(new Button() { Width = Application.GetRealWidth(23) });
            var btnRecommenColor7 = new Button()
            {
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = 0xFF962eff,
                Radius = (uint)Application.GetRealWidth(14),
            };
            recommendColorView.AddChidren(btnRecommenColor7);
            
 
            #endregion
 
            #region 当前颜色
            var curColorView = new FrameLayout()
            {
                Height = Application.GetRealHeight(120),
            };
            contentView.AddChidren(curColorView);
 
            var btnCurColorTitle = new Button()
            {
                X = Application.GetRealWidth(16),
                Height = Application.GetRealHeight(36),
                TextAlignment = TextAlignment.TopLeft,
                TextSize = 18,
                TextColor = CSS_Color.FirstLevelTitleColor,
                TextID = StringId.CurColor,
            };
            curColorView.AddChidren(btnCurColorTitle);
 
            var curColorInfoView = new FrameLayout()
            {
                Width = Application.GetRealWidth(330),
                Height =Application.GetRealHeight(51),
                Gravity = Gravity.CenterHorizontal,
                Y = Application.GetRealHeight(36),
                BackgroundColor = 0xFFe9ebed,
                Radius = (uint)Application.GetRealWidth(8),
            };
            curColorView.AddChidren(curColorInfoView);
 
            var btnCurColor = new Button()
            {
                X = Application.GetRealWidth(20),
                Gravity = Gravity.CenterVertical,
                Width = Application.GetRealWidth(28),
                Height = Application.GetRealWidth(28),
                BackgroundColor = curColor,
                Radius = (uint)Application.GetRealWidth(14),
            };
            curColorInfoView.AddChidren(btnCurColor);
 
            var btnHex = new Button()
            {
                Width = Application.GetRealWidth(60),
                TextAlignment = TextAlignment.CenterRight,
                TextColor = 0xFF222222,
                TextSize = 15,
                X = Application.GetRealWidth(48),
                Text = "Hex"
            };
            curColorInfoView.AddChidren(btnHex);
 
            var btnLine = new Button()
            {
                Width = 1,
                Height = Application.GetRealHeight(28),
                Gravity = Gravity.CenterVertical,
                BackgroundColor = 0xFFBBBBBB,
                X = btnHex.Right+Application.GetRealWidth(18),
            };
            curColorInfoView.AddChidren(btnLine);
 
            var btnS = new Button()
            {
                X = btnLine.Right,
                Width = Application.GetRealWidth(61),
                TextAlignment = TextAlignment.CenterRight,
                TextSize = 15,
                TextColor = 0x99000000,
                Text = "#",
            };
            curColorInfoView.AddChidren(btnS);
 
            var etCurColorHexInfo = new EditText()
            {
                X = btnS.Right + Application.GetRealWidth(12),
                Width = Application.GetRealWidth(100),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 15,
                Text = curColor.ToString("X"),
                TextColor = 0x21000000,
            };
            curColorInfoView.AddChidren(etCurColorHexInfo);
 
            var btnHexTip = new Button()
            {
                X = Application.GetRealWidth(16),
                Y = curColorInfoView.Bottom,
                Height = Application.GetRealWidth(35),
                Width = Application.GetRealWidth(300),
                TextAlignment = TextAlignment.CenterLeft,
                TextSize = 12,
                TextColor = 0x21000000,
                TextID = StringId.CurHexTip,
            };
            curColorView.AddChidren(btnHexTip);
 
 
            #endregion
 
            contentView.AddChidren(new Button()
            {
                Height = Application.GetRealHeight(12)
            });
            if (isSatrtColor)
            {
                var btnSelectColorTip = new Button()
                {
                    X = Application.GetRealWidth(16),
                    Height = Application.GetRealWidth(35),
                    Width = Application.GetRealWidth(300),
                    TextAlignment = TextAlignment.CenterLeft,
                    TextSize = 12,
                    TextColor = 0x21000000,
                    TextID = StringId.ColorfulSetTip,// = "提示:起始颜色选择越靠近色环边缘,炫彩效果越明显。越靠近白色中心,炫彩效果越不明显。",
                    IsMoreLines = true,
                };
                contentView.AddChidren(btnSelectColorTip);
 
                contentView.AddChidren(new Button()
                {
                    Height = Application.GetRealHeight(12)
                });
            }
            #region 保存
            var btnConfrim = new Button()
            {
                Gravity = Gravity.CenterHorizontal,
                Width = Application.GetRealWidth(220),
                Height = Application.GetRealHeight(44),
                Radius = (uint)Application.GetRealHeight(22),
                TextAlignment = TextAlignment.Center,
                TextColor = CSS_Color.MainBackgroundColor,
                BackgroundColor = CSS_Color.MainColor,
                TextID = StringId.Save,
                TextSize = CSS_FontSize.SubheadingFontSize,
            };
            contentView.AddChidren(btnConfrim);
            btnConfrim.MouseUpEventHandler = (sender, e) =>
            {
                backAction?.Invoke(curColor) ;
                var d = new System.Collections.Generic.Dictionary<string, string>();
                if (isSatrtColor)
                {
                    d.Add(FunctionAttributeKey.ColorfulBegin, redColor + "," + greenColor + "," + blueColor);
                    function.SetAttrState(FunctionAttributeKey.ColorfulBegin, redColor + "," + greenColor + "," + blueColor);
                    //var color = function.GetAttrState(FunctionAttributeKey.ColorfulEnd).Split(",");
                    //var sendColorString = color[0] + "," + color[1] + "," + color[2];
                    //d.Add(FunctionAttributeKey.ColorfulEnd, sendColorString);
                    //d.Add(FunctionAttributeKey.ColorfulTime, function.GetAttrState(FunctionAttributeKey.ColorfulTime));
                }
                else
                {
                    //var color = function.GetAttrState(FunctionAttributeKey.ColorfulBegin).Split(",");
                    //var sendColorString = color[0] + "," + color[1] + "," + color[2];
                    //d.Add(FunctionAttributeKey.ColorfulBegin, sendColorString);
                    //d.Add(FunctionAttributeKey.ColorfulTime, function.GetAttrState(FunctionAttributeKey.ColorfulTime));
                    d.Add(FunctionAttributeKey.ColorfulEnd, redColor + "," + greenColor + "," + blueColor);
                    function.SetAttrState(FunctionAttributeKey.ColorfulEnd, redColor + "," + greenColor + "," + blueColor);
                }
                //d.Add(FunctionAttributeKey.Colorful, "off");
                Control.Ins.SendWriteCommand(function, d);
                this.RemoveFromParent();
            };
 
 
            #endregion
 
            colorPicker.ColorChaged += (sender2, color) => {
                 redColor = color[0];
                 greenColor = color[1];
                 blueColor = color[2];
 
                int recolor = redColor * 256 * 256 + greenColor * 256 + blueColor;
 
                btnCurColor.BackgroundColor = curColor = (uint)(0xFF000000 + recolor);
                etCurColorHexInfo.Text = recolor.ToString("X");
            };
            btnRecommenColor1.MouseUpEventHandler = (sender, e) => {
                curColor = btnCurColor.BackgroundColor = btnRecommenColor1.BackgroundColor;
                etCurColorHexInfo.Text = "FC4645";
                redColor = 252;
                greenColor = 70;
                blueColor = 69;
 
            };
            btnRecommenColor2.MouseUpEventHandler = (sender, e) => {
                curColor = btnCurColor.BackgroundColor = btnRecommenColor2.BackgroundColor;
                etCurColorHexInfo.Text = "FD834D";
                redColor = 253;
                greenColor = 131;
                blueColor = 77;
            };
            btnRecommenColor3.MouseUpEventHandler = (sender, e) => {
                curColor = btnCurColor.BackgroundColor = btnRecommenColor3.BackgroundColor;
                etCurColorHexInfo.Text = "FEF267";
                redColor = 254;
                greenColor = 242;
                blueColor = 103;
            };
            btnRecommenColor4.MouseUpEventHandler = (sender, e) => {
                curColor = btnCurColor.BackgroundColor = btnRecommenColor4.BackgroundColor;
                etCurColorHexInfo.Text = "73FD7B";
                redColor = 115;
                greenColor = 253;
                blueColor = 123;
            };
            btnRecommenColor5.MouseUpEventHandler = (sender, e) => {
                curColor = btnCurColor.BackgroundColor = btnRecommenColor5.BackgroundColor;
                etCurColorHexInfo.Text = "45B7FD";
                redColor = 69;
                greenColor = 183;
                blueColor = 253;
            };
            btnRecommenColor6.MouseUpEventHandler = (sender, e) => {
                curColor = btnCurColor.BackgroundColor = btnRecommenColor6.BackgroundColor;
                etCurColorHexInfo.Text = "5558fd";
                redColor = 85;
                greenColor = 88;
                blueColor = 253;
            };
            btnRecommenColor7.MouseUpEventHandler = (sender, e) => {
                curColor = btnCurColor.BackgroundColor = btnRecommenColor7.BackgroundColor;
                etCurColorHexInfo.Text = "962eff";
                redColor = 150;
                greenColor = 26;
                blueColor = 255;
            };
        }
 
 
 
        /// <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;
        }
 
    }
}