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() { } ///          /// 加载rgb选择弹窗         ///          ///          ///  public void LoadRGBDialog(string stateRGBValue, Action 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(); } /// /// 检测点击点 /// /// 圆的半径 /// 圆心X轴 /// 圆心Y轴 /// 点击点的X轴 /// 点击点的Y轴 /// 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; } /// /// 获取控件背景值 /// button.BackgroundColor =(uint)(0xFF000000 + new Light().GetRGBcolor(rgbValueStr)) /// /// rgb值 /// public uint GetBackgroundColor(string rgbString) { return (uint)(0xFF000000 + new Light().GetRGBcolor(rgbString)); } } }