using System; using System.Collections.Generic; using HDL_ON.Entity; using HDL_ON.UI.CSS; using Shared; namespace HDL_ON.UI { /// /// 灯光场景编辑弹窗 /// public class GroupControlPage : Dialog { GroupControl group; public GroupControlPage(GroupControl groupControl) { group = groupControl; if(group == null) { group = new GroupControl(); } } public void ShowDialog() { var hadDimming = false; var hadCCT = false; var hadRGB = false; foreach (var temp in group.sids) { if (temp.spk == SPK.LightRGB) { hadRGB = true; } else if (temp.spk == SPK.LightCCT) { hadCCT = true; }else if (temp.spk == SPK.LightDimming) { hadDimming = true; } if(hadDimming && hadCCT && hadRGB) { break; } } var bodyView = new FrameLayout(); this.AddChidren(bodyView); //bodyView.MouseUpEventHandler = (sender, e) => //{ // this.Close(); //}; var contentView = new FrameLayout() { BackgroundColor = CSS_Color.MainBackgroundColor, Width = Application.GetRealWidth(343), 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, TextID = StringId.CombinedDimming, TextAlignment = TextAlignment.Center, }; if (btnTitle.GetTextWidth() > Application.GetRealWidth(197))//247 { btnTitle.Width = Application.GetRealWidth(197); btnTitle.IsMoreLines = true; } else { btnTitle.Width = btnTitle.GetTextWidth() + Application.GetRealWidth(10); btnTitle.IsMoreLines = false; } titleView.AddChidren(btnTitle); var btnEditIcon = new Button() { Width = Application.GetRealWidth(24), Height = Application.GetRealWidth(24), X = Application.GetRealWidth(12) + btnTitle.Right, Gravity = Gravity.CenterVertical, UnSelectedImagePath = "Public/Edit.png", }; btnTitle.Text = group.name; btnTitle.Width = btnTitle.GetTextWidth() + Application.GetRealWidth(10); btnTitle.Gravity = Gravity.Center; titleView.AddChidren(new Button() { Height = 1, BackgroundColor = CSS_Color.DividingLineColor, Y = Application.GetRealHeight(51) }); #endregion //属性设置区域 var attrView = new VerticalScrolViewLayout() { Y = Application.GetRealHeight(52), Width = Application.GetRealWidth(343), ScrollEnabled = false, }; //属性设置区域高度 int attrViewHight = Application.GetRealHeight(18 + 22); attrViewHight += Application.GetRealHeight(50); if (hadRGB) { attrViewHight += Application.GetRealHeight(248); hadDimming = true; } if (hadCCT) { attrViewHight += Application.GetRealHeight(75 + 11); hadDimming = true; } if (hadDimming) { attrViewHight += Application.GetRealHeight(54 + 11); } attrView.Height = attrViewHight; contentView.AddChidren(attrView); attrView.AddChidren(new Button() { Height = Application.GetRealHeight(18) }); if (hadDimming) { LoadDimmingAttrView(attrView); } if (hadCCT) { LoadCctAttrView(attrView); } if (hadRGB) { LoadRgbAttrView(attrView); } var view = new FrameLayout() { Width = Application.GetRealWidth(343), Height = Application.GetRealHeight(50), }; attrView.AddChidren(view); var btnClose = new Button() { X = Application.GetRealWidth(50), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(98), Height = Application.GetRealHeight(40), TextColor = CSS_Color.TextualColor, SelectedBackgroundColor = CSS_Color.MainColor, SelectedTextColor = CSS_Color.MainBackgroundColor, BackgroundColor = CSS_Color.DividingLineColor, TextID = StringId.OFF, TextSize = CSS_FontSize.TextFontSize, Radius = (uint)Application.GetRealWidth(5), }; view.AddChidren(btnClose); var btnOpen = new Button() { X = Application.GetRealWidth(100 + 98), Gravity = Gravity.CenterVertical, Width = Application.GetRealWidth(98), Height = Application.GetRealHeight(40), TextColor = CSS_Color.TextualColor, SelectedBackgroundColor = CSS_Color.MainColor, SelectedTextColor = CSS_Color.MainBackgroundColor, BackgroundColor = CSS_Color.DividingLineColor, TextID = StringId.On, TextSize = CSS_FontSize.TextFontSize, Radius = (uint)Application.GetRealWidth(5), }; view.AddChidren(btnOpen); btnClose.MouseUpEventHandler = (sender, e) => { btnClose.IsSelected = true; btnOpen.IsSelected = false; var d = new Dictionary(); d.Add(FunctionAttributeKey.OnOff, "off"); group.Control(d); }; btnOpen.MouseUpEventHandler = (sender, e) => { btnClose.IsSelected = false; btnOpen.IsSelected = true; var d = new Dictionary(); d.Add(FunctionAttributeKey.OnOff, "on"); group.Control(d); }; contentView.Height = Application.GetRealHeight(52 + 44) + attrViewHight; contentView.Gravity = Gravity.Center; var bottomView = new FrameLayout() { Y = Application.GetRealHeight(52) + attrViewHight, Height = Application.GetRealHeight(46), }; contentView.AddChidren(bottomView); bottomView.AddChidren(new Button() { Height = 1, BackgroundColor = CSS_Color.DividingLineColor }); var btnCloseDialog = new Button() { TextAlignment = TextAlignment.Center, TextColor = CSS_Color.TextualColor, TextID = StringId.Close, TextSize = CSS_FontSize.SubheadingFontSize, }; bottomView.AddChidren(btnCloseDialog); btnCloseDialog.MouseUpEventHandler = (sender, e) => { this.Close(); }; this.Show(); } /// /// 加载调光属性设置控件 /// /// void LoadDimmingAttrView(VerticalScrolViewLayout attrView) { var dimmingView = new FrameLayout() { Height = Application.GetRealHeight(54 + 11) }; attrView.AddChidren(dimmingView); #region 亮度调节 var btnBrightnessText = new Button() { X = Application.GetRealWidth(35), Y = Application.GetRealHeight(1), Width = Application.GetRealWidth(224), Height = Application.GetRealHeight(25), TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.FirstLevelTitleColor, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, TextID = StringId.Brightness, }; btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + group.GetAttrState(FunctionAttributeKey.Brightness) + "%"; dimmingView.AddChidren(btnBrightnessText); var btnMinValuesText = new Button() { X = Application.GetRealWidth(35), Y = btnBrightnessText.Bottom, Width = Application.GetRealWidth(40), Height = Application.GetRealHeight(21), Text = "0%", TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, }; dimmingView.AddChidren(btnMinValuesText); var dimmerBar = new DiyImageSeekBar() { X = Application.GetRealWidth(45 + 10), Y = Application.GetRealHeight(11), Width = Application.GetRealWidth(220), Height = Application.GetRealHeight(54), SeekBarViewHeight = Application.GetRealHeight(8), ThumbImagePath = "Public/ThumbImage.png", ThumbImageHeight = Application.GetRealHeight(54), ProgressTextColor = CSS_Color.FirstLevelTitleColor, ProgressTextSize = CSS_FontSize.PromptFontSize_FirstLevel, ProgressBarColor = CSS_Color.AuxiliaryColor1, MaxValue = 100, SeekBarPadding = Application.GetRealWidth(20), IsProgressTextShow = false, ProgressChangeDelayTime = 0, }; dimmingView.AddChidren(dimmerBar); dimmerBar.OnProgressChangedEvent = (sender, e) => { btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + e + "%"; }; dimmerBar.OnStopTrackingTouchEvent = (sender, e) => { btnBrightnessText.Text = Language.StringByID(StringId.Brightness) + " " + e + "%"; var d = new Dictionary(); d.Add(FunctionAttributeKey.Brightness, e.ToString()); group.Control(d); }; var btnMaxValuesText = new Button() { X = dimmerBar.Right, Y = btnBrightnessText.Bottom, Width = Application.GetRealWidth(55), Height = Application.GetRealHeight(21), Text = "100%", TextAlignment = TextAlignment.CenterLeft, TextColor = CSS_Color.PromptingColor1, TextSize = CSS_FontSize.PromptFontSize_FirstLevel, }; dimmingView.AddChidren(btnMaxValuesText); #endregion } /// /// 加载cct属性设置控件 /// /// void LoadCctAttrView(VerticalScrolViewLayout attrView) { #region 色温 var cctView = new FrameLayout() { Height = Application.GetRealHeight(75 + 11) }; attrView.AddChidren(cctView); //色温 var btnTempClolor = new Button(); btnTempClolor.X = Application.GetRealWidth(35); btnTempClolor.Y = Application.GetRealHeight(1); btnTempClolor.Width = Application.GetRealWidth(224); btnTempClolor.Height = Application.GetRealHeight(42); btnTempClolor.TextAlignment = TextAlignment.CenterLeft; btnTempClolor.TextColor = CSS_Color.FirstLevelTitleColor; btnTempClolor.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; btnTempClolor.TextID = StringId.ColorTemperature; cctView.AddChidren(btnTempClolor); //2700K var btnTempClolorMin = new Button() { X = Application.GetRealWidth(35), Y = btnTempClolor.Bottom, Width = Application.GetRealWidth(40), Height = Application.GetRealHeight(21), }; btnTempClolorMin.Width = Application.GetRealWidth(54); btnTempClolorMin.Height = Application.GetRealHeight(21); btnTempClolorMin.Text = "2700K"; btnTempClolorMin.TextAlignment = TextAlignment.CenterLeft; btnTempClolorMin.TextColor = CSS_Color.PromptingColor1; btnTempClolorMin.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; cctView.AddChidren(btnTempClolorMin); //滑动条的背景图片 var btnColorTemplatrueBack = new Button() { X = Application.GetRealWidth(55 + 22 + 15), Y = Application.GetRealHeight(11), Width = Application.GetRealWidth(180), Height = Application.GetRealHeight(54), }; btnColorTemplatrueBack.UnSelectedImagePath = "FunctionIcon/Light/ColorTemperatureBar.png"; btnColorTemplatrueBack.Height = Application.GetRealHeight(8); btnColorTemplatrueBack.Gravity = Gravity.CenterHorizontal; cctView.AddChidren(btnColorTemplatrueBack); //滑动条控件 var barColorTemplatrue = new CCTSeekBarControl() { X = Application.GetRealWidth(55 + 22), Y = Application.GetRealHeight(11), Width = Application.GetRealWidth(220), Height = Application.GetRealHeight(54), }; barColorTemplatrue.MinValue = 27; barColorTemplatrue.MaxValue = 65; barColorTemplatrue.ProgressBarColor = 0x00000000;//全部透明 barColorTemplatrue.ProgressBarUnEnableColor = 0x00000000; barColorTemplatrue.SeekBarBackgroundColor = 0x00000000; cctView.AddChidren(barColorTemplatrue); barColorTemplatrue.Y = btnTempClolorMin.Y - (barColorTemplatrue.Height - btnTempClolorMin.Height) / 2; //设置初始值 btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K"); barColorTemplatrue.OnProgressChangedEvent = (sender, e) => { btnTempClolor.Text = Language.StringByID(StringId.ColorTemperature) + " " + (barColorTemplatrue.Progress * 100 + "K"); }; barColorTemplatrue.OnStopTrackingTouchEvent = (sender, e) => { var d = new Dictionary(); d.Add(FunctionAttributeKey.CCT, (barColorTemplatrue.Progress * 100).ToString()); group.Control(d); }; //变更背景图的Y轴坐标 btnColorTemplatrueBack.Y = barColorTemplatrue.Y + (barColorTemplatrue.Height - btnColorTemplatrueBack.Height) / 2; //6500K var btnTempClolorMax = new Button(); btnTempClolorMax.Y = btnTempClolorMin.Y; btnTempClolorMax.X = barColorTemplatrue.Right - Application.GetRealWidth(30); btnTempClolorMax.Width = Application.GetRealWidth(54); btnTempClolorMax.Height = Application.GetRealHeight(21); btnTempClolorMax.Text = "6500K"; btnTempClolorMax.TextAlignment = TextAlignment.CenterRight; btnTempClolorMax.TextColor = CSS_Color.PromptingColor1; btnTempClolorMax.TextSize = CSS_FontSize.PromptFontSize_FirstLevel; cctView.AddChidren(btnTempClolorMax); #endregion } /// /// 加载rgb属性设置控件 /// /// void LoadRgbAttrView(VerticalScrolViewLayout attrView) { #region RGB var rgbView = new FrameLayout() { Height = Application.GetRealHeight(248) }; attrView.AddChidren(rgbView); var btnCurColor = new Button() { X = Application.GetRealWidth(24), 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(commandDic[FunctionAttributeKey.RGB])) }; 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); string rgbString = "255,255,255"; var rgbTemp = new Light(); colorPicker.MouseUpEventHandler = (sender2, e2) => { var d = new Dictionary(); d.Add(FunctionAttributeKey.RGB, rgbString); group.Control(d); }; colorPicker.ColorChaged += (sender2, e2) => { rgbString = (e2[0] + "," + e2[1] + "," + e2[2]).ToString(); btnCurColor.BackgroundColor = (uint)(0xFF000000 + rgbTemp.GetRGBcolor(rgbString)); var d = new Dictionary(); d.Add(FunctionAttributeKey.RGB, rgbString); group.Control(d); }; 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 } /// /// 检测点击点 /// /// 圆的半径 /// 圆心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; } } }