From d6fb0646531172f23648441c224cdcccd721b894 Mon Sep 17 00:00:00 2001 From: xm <1271024303@qq.com> Date: 星期一, 14 十二月 2020 09:59:01 +0800 Subject: [PATCH] 请合并代码,完成晾衣架最终功能。 --- ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelColorSelectForm.cs | 474 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 files changed, 474 insertions(+), 0 deletions(-) diff --git a/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelColorSelectForm.cs b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelColorSelectForm.cs new file mode 100755 index 0000000..71725b2 --- /dev/null +++ b/ZigbeeApp/Shared/Phone/UserCenter/Device/Panel/PanelColorSelectForm.cs @@ -0,0 +1,474 @@ +锘縰sing System; +using System.Collections.Generic; +using System.Text; +using ZigBee.Device; + +namespace Shared.Phone.UserCenter.DevicePanel +{ + /// <summary> + /// 鎸夐敭闈㈡澘鐨勯鑹查�夋嫨鐣岄潰 + /// </summary> + public class PanelColorSelectForm : EditorCommonForm + { + #region 鈻� 鍙橀噺澹版槑___________________________ + + /// <summary> + /// 棰滆壊閫夋嫨缁撴潫鐨勪簨浠�(R,G,B) + /// </summary> + public Action<int, int, int> FinishSelectColorEvent; + /// <summary> + /// 閫夋嫨鐨凴GB + /// </summary> + private List<int> listRGB = null; + /// <summary> + /// 褰撳墠閫夋嫨鐨勬帶浠�(澶栨) + /// </summary> + private FrameLayoutStatuControl nowSelectIcon1 = null; + /// <summary> + /// 鍦嗙洏閫夋嫨鐨勯鑹叉樉绀烘帶浠�(澶栨) + /// </summary> + private FrameLayoutStatuControl wheelSelectIcon1 = null; + /// <summary> + /// 鍦嗙洏閫夋嫨鐨勯鑹叉樉绀烘帶浠�(鍐呮) + /// </summary> + private IconViewControl wheelSelectIcon2 = null; + /// <summary> + /// 鏄惁鏄鑹查�夋嫨 + /// </summary> + private bool isColorSelect = false; + /// <summary> + /// 棰滆壊鍊艰緭鍏ユ帶浠� + /// </summary> + private TextInputControl txtColorInput = null; + + #endregion + + #region 鈻� 鍒濆鍖朹____________________________ + + /// <summary> + /// 鐢婚潰鏄剧ず(搴曞眰浼氬浐瀹氳皟鐢ㄦ鏂规硶锛屽�熶互瀹屾垚鐢婚潰鍒涘缓) + /// </summary> + /// <param name="i_R">R</param> + /// <param name="i_G">G</param> + /// <param name="i_B">B</param> + public void ShowForm(int i_R, int i_G, int i_B) + { + this.ScrollEnabled = false; + + //璁剧疆澶撮儴淇℃伅 + base.SetTitleText(Language.StringByID(R.MyInternationalizationString.uSelectColor)); + + //鍒濆鍖栦腑閮ㄤ俊鎭� + this.InitMiddleFrame(i_R, i_G, i_B); + + //纭畾 + var btnfinish = new BottomClickButton(); + btnfinish.TextID = R.MyInternationalizationString.Confrim; + bodyFrameLayout.AddChidren(btnfinish); + btnfinish.MouseUpEventHandler += (sender, e) => + { + if (listRGB == null || FinishSelectColorEvent == null) + { + this.CloseForm(); + return; + } + //鍥炶皟鍑芥暟 + this.FinishSelectColorEvent(listRGB[0], listRGB[1], listRGB[2]); + this.CloseForm(); + }; + + } + + /// <summary> + /// 鍒濆鍖栦腑閮ㄤ俊鎭� + /// </summary> + /// <param name="i_R">R</param> + /// <param name="i_G">G</param> + /// <param name="i_B">B</param> + private void InitMiddleFrame(int i_R, int i_G, int i_B) + { + bodyFrameLayout.BackgroundColor = UserCenterColor.Current.White; + //娓呯┖bodyFrame + this.ClearBodyFrame(); + //鍒濆鍖栭鑹插渾鐩樻帶浠� + this.InitColorPictrueControl(); + //鍒濆鍖栧鐢ㄩ鑹茬殑鎺т欢 + this.InitSpareColorControl(i_R, i_G, i_B); + } + + #endregion + + #region 鈻� 鍒濆鍖栭鑹插渾鐩榑____________________ + + /// <summary> + /// 鍒濆鍖栭鑹插渾鐩樻帶浠� + /// </summary> + private void InitColorPictrueControl() + { + //鍒濆鍖栭鑹茶緭鍏ユ帶浠� + this.txtColorInput = this.InitColorInputControl(); + + var framePic = new FrameLayout(); + framePic.Width = this.GetPictrueRealSize(588); + framePic.Height = this.GetPictrueRealSize(588); + framePic.Gravity = Gravity.CenterHorizontal; + framePic.Y = Application.GetRealHeight(192); + bodyFrameLayout.AddChidren(framePic); + + //鍦嗙洏鎺т欢 + var colorPic = new ColorPicker(); + colorPic.ColorImagePath = "Item/PickerColorWheel.png"; + framePic.AddChidren(colorPic); + + //鐧界偣鎺т欢 + var btnWhiteView = new IconViewControl(30); + btnWhiteView.Visible = false; + btnWhiteView.BackgroundColor = UserCenterColor.Current.White; + btnWhiteView.Radius = (uint)this.GetPictrueRealSize(30) / 2; + framePic.AddChidren(btnWhiteView); + + bool pointIsRight = false; + //鍦嗙殑鍗婂緞 + int circleR = framePic.Width / 2 - this.GetPictrueRealSize(35); + colorPic.ColorChaged += (sender, eColor) => + { + if (pointIsRight == false) + { + //鐐圭殑鍖哄煙涓嶆槸鍦嗙洏鍐� + return; + } + listRGB = new List<int>(); + listRGB.Add(Convert.ToInt32(Convert.ToString(eColor[0]))); + listRGB.Add(Convert.ToInt32(Convert.ToString(eColor[1]))); + listRGB.Add(Convert.ToInt32(Convert.ToString(eColor[2]))); + + //鏄剧ず閫夋嫨棰滆壊鐨勬帶浠� + this.ShowNowSelectColorControl(eColor); + + //鑾峰彇棰滆壊鐨勭炕璇戞枃鏈� + isColorSelect = true; + this.txtColorInput.Text = this.GetColorTextTranslate(listRGB[0], listRGB[1], listRGB[2]); + }; + colorPic.MouseDownEventHandler += (sender, e) => + { + pointIsRight = this.CheckPoint(circleR, framePic.Width / 2, framePic.Height / 2, (int)e.X, (int)e.Y); + if (pointIsRight == false) + { + //鐐圭殑鍖哄煙涓嶆槸鍦嗙洏鍐� + return; + } + //鏄剧ず鐧界偣 + btnWhiteView.X = (int)e.X - btnWhiteView.Width / 2; + btnWhiteView.Y = (int)e.Y - btnWhiteView.Height / 2; + if (btnWhiteView.Visible == false) + { + btnWhiteView.Visible = true; + } + }; + colorPic.MouseMoveEventHandler += (sender, e) => + { + //褰撻紶鏍囩偣涓嬩簨浠跺鐞� + colorPic.MouseDownEventHandler(sender, e); + }; + + //鎵嬪姩杈撳叆鍊兼敼鍙樹簨浠� + this.txtColorInput.TextChangeEventHandler += (sender, value) => + { + if (isColorSelect == true) + { + //杩欓噷鏄敱鐐瑰嚮鑹茬洏杩涜璧嬪�艰Е鍙� + isColorSelect = false; + return; + } + //妫�娴嬭緭鍏ョ殑棰滆壊鍊� + var byteColor = this.CheckInputColorValue(value); + if (byteColor == null) + { + return; + } + if (btnWhiteView.Visible == true) + { + //鐧界偣闅愯棌 + btnWhiteView.Visible = false; + } + + //璁板綍缂撳瓨 + listRGB = new List<int>(); + listRGB.Add(Convert.ToInt32(Convert.ToString(byteColor[0]))); + listRGB.Add(Convert.ToInt32(Convert.ToString(byteColor[1]))); + listRGB.Add(Convert.ToInt32(Convert.ToString(byteColor[2]))); + + //鏄剧ず閫夋嫨棰滆壊鐨勬帶浠� + this.ShowNowSelectColorControl(byteColor); + }; + } + + /// <summary> + /// 鍒濆鍖栭鑹茶緭鍏ユ帶浠� + /// </summary> + /// <returns></returns> + private TextInputControl InitColorInputControl() + { + //鑷畾涔夎壊鍊肩殑澶栨 + var frameInput = new NormalFrameLayout(); + frameInput.Width = Application.GetRealWidth(458); + frameInput.Height = Application.GetRealHeight(104); + frameInput.Y = Application.GetRealHeight(1103); + frameInput.Gravity = Gravity.CenterHorizontal; + frameInput.BorderColor = 0xffcccccc; + frameInput.Radius = (uint)Application.GetRealWidth(17); + frameInput.BorderWidth = Application.GetRealWidth(3) == 0 ? 1 : (uint)Application.GetRealWidth(3); + bodyFrameLayout.AddChidren(frameInput); + var btnMark = new NormalViewControl(100, 58, true); + btnMark.X = Application.GetRealWidth(35); + btnMark.Gravity = Gravity.CenterVertical; + btnMark.IsBold = true; + btnMark.Text = "# "; + btnMark.Width = btnMark.GetRealWidthByText(); + btnMark.TextColor = UserCenterColor.Current.TextGrayColor2; + frameInput.AddChidren(btnMark); + //鑷畾涔夎壊鍊艰緭鍏ユ + var txtInput = new TextInputControl(400, 58, true); + txtInput.X = btnMark.Right; + txtInput.Gravity = Gravity.CenterVertical; + txtInput.TextSize = 16; + txtInput.FrameBorder = frameInput; + frameInput.AddChidren(txtInput); + //鑹插�煎彿涓�6浣嶏紙鐢变换鎰忔暟瀛�+瀛楁瘝缁勫悎锛� + var btnTipView = new NormalViewControl(bodyFrameLayout.Width, Application.GetRealHeight(55), false); + btnTipView.Y = frameInput.Bottom + Application.GetRealHeight(20); + btnTipView.IsBold = true; + btnTipView.TextAlignment = TextAlignment.Center; + btnTipView.TextColor = UserCenterColor.Current.TextGrayColor2; + btnTipView.TextSize = 12; + btnTipView.TextID = R.MyInternationalizationString.uColorLengthMsg; + bodyFrameLayout.AddChidren(btnTipView); + + return txtInput; + } + + /// <summary> + /// 鏄剧ず閫夋嫨棰滆壊鐨勬帶浠� + /// </summary> + /// <param name="eColor"></param> + private void ShowNowSelectColorControl(byte[] eColor) + { + //鏄剧ず閫夋嫨棰滆壊鐨勬帶浠� + if (nowSelectIcon1 != null) + { + nowSelectIcon1.BorderColor = UserCenterColor.Current.White; + } + var uintColor = this.GetColorByRGB(eColor[0], eColor[1], eColor[2]); + wheelSelectIcon2.BackgroundColor = uintColor; + wheelSelectIcon1.BorderColor = 0xffcccccc; + wheelSelectIcon1.Name = listRGB[0] + "-" + listRGB[1] + "-" + listRGB[2]; + nowSelectIcon1 = wheelSelectIcon1; + } + + #endregion + + #region 鈻� 鍒濆鍖栭閫夐鑹瞋____________________ + + /// <summary> + /// 鍒濆鍖栧鐢ㄩ鑹茬殑鎺т欢 + /// </summary> + /// <param name="i_R">R</param> + /// <param name="i_G">G</param> + /// <param name="i_B">B</param> + private void InitSpareColorControl(int i_R, int i_G, int i_B) + { + //鎺т欢鏁� + var listColor = this.InitSpareDefultColor(); + //X杞村垵濮嬪潗鏍� + int Xdefult = (bodyFrameLayout.Width - this.GetPictrueRealSize(80 + 24) * (listColor.Count - 1) - this.GetPictrueRealSize(80)) / 2; + for (int i = 0; i < listColor.Count; i++) + { + var dataColor = listColor[i]; + + var btnFrame = new FrameLayoutStatuControl(); + btnFrame.Height = this.GetPictrueRealSize(80); + btnFrame.Width = this.GetPictrueRealSize(80); + btnFrame.Radius = (uint)this.GetPictrueRealSize(80) / 2; + btnFrame.X = Xdefult + i * this.GetPictrueRealSize(80 + 24); + btnFrame.Y = Application.GetRealHeight(880); + btnFrame.BackgroundColor = UserCenterColor.Current.White; + btnFrame.BorderWidth = 1; + btnFrame.BorderColor = UserCenterColor.Current.White; + bodyFrameLayout.AddChidren(btnFrame); + + //鍒嗕袱姝ヨ绠楋紝涓嶇劧鏈夊彲鑳藉畠寰楀嚭鐨勭粨鏋滄湁璇樊瀵艰嚧涓嶅眳涓� + int iconWidth = btnFrame.Height - this.GetPictrueRealSize(10) - this.GetPictrueRealSize(10); + var btnIcon = new IconViewControl(iconWidth, false); + btnIcon.Gravity = Gravity.Center; + btnIcon.Radius = (uint)btnIcon.IconSize / 2; + btnFrame.AddChidren(btnIcon, ChidrenBindMode.BindEvent); + + if (dataColor != null) + { + //棰勮缃殑棰滆壊 + btnFrame.Name = dataColor[0] + "-" + dataColor[1] + "-" + dataColor[2]; + btnIcon.BackgroundColor = this.GetColorByRGB((byte)dataColor[0], (byte)dataColor[1], (byte)dataColor[2]); + } + else + { + //鍘熸潵鐨勯鑹� + btnFrame.BorderColor = 0xffcccccc; + btnIcon.BackgroundColor = this.GetColorByRGB((byte)i_R, (byte)i_G, (byte)i_B); + wheelSelectIcon1 = btnFrame; + wheelSelectIcon2 = btnIcon; + nowSelectIcon1 = btnFrame; + + //鑾峰彇棰滆壊鐨勭炕璇戞枃鏈� + isColorSelect = true; + this.txtColorInput.Text = this.GetColorTextTranslate(i_R, i_G, i_B); + } + + btnFrame.ButtonClickEvent += (sender, e) => + { + //鏄剧ず閫夋嫨棰滆壊鐨勬帶浠� + if (nowSelectIcon1 != null) + { + nowSelectIcon1.BorderColor = UserCenterColor.Current.White; + } + btnFrame.BorderColor = 0xffcccccc; + nowSelectIcon1 = btnFrame; + + if (btnFrame.Name != null) + { + listRGB = new List<int>(); + string[] Arry = btnFrame.Name.Split(new string[] { "-" }, StringSplitOptions.RemoveEmptyEntries); + listRGB.Add(Convert.ToInt32(Convert.ToString(Arry[0]))); + listRGB.Add(Convert.ToInt32(Convert.ToString(Arry[1]))); + listRGB.Add(Convert.ToInt32(Convert.ToString(Arry[2]))); + } + //鑾峰彇棰滆壊鐨勭炕璇戞枃鏈� + isColorSelect = true; + this.txtColorInput.Text = this.GetColorTextTranslate(listRGB[0], listRGB[1], listRGB[2]); + }; + } + } + + #endregion + + #region 鈻� 涓�鑸柟娉昣__________________________ + + /// <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> + /// 鍒濆鍖栧鐢ㄩ鑹茬殑榛樿鍊� + /// </summary> + /// <returns></returns> + private List<List<int>> InitSpareDefultColor() + { + var list = new List<List<int>>(); + + list.Add(new List<int>() { 253, 226, 39 }); + list.Add(new List<int>() { 121, 255, 197 }); + list.Add(null); + list.Add(new List<int>() { 198, 85, 250 }); + list.Add(new List<int>() { 255, 117, 67 }); + + return list; + } + + /// <summary> + /// 妫�娴嬭緭鍏ョ殑棰滆壊鍊� + /// </summary> + /// <param name="colorText"></param> + /// <returns></returns> + private byte[] CheckInputColorValue(string colorText) + { + //鍙湁闀垮害涓�6鎵嶅鐞� + if (colorText.Length != 6) { return null; } + + colorText = colorText.ToUpper(); + foreach (var c in colorText) + { + if (char.IsNumber(c) == true) + { + //鏁板瓧鐨勮瘽,OK + continue; + } + if ('A' <= c && c <= 'F') + { + //A-F鐨勮瘽,OK + continue; + } + return null; + } + int R = Convert.ToInt32(colorText.Substring(0, 2), 16); + int G = Convert.ToInt32(colorText.Substring(2, 2), 16); + int B = Convert.ToInt32(colorText.Substring(4, 2), 16); + return new byte[] { (byte)R, (byte)G, (byte)B }; + } + + /// <summary> + /// 鑾峰彇棰滆壊鐨勭炕璇戞枃鏈� + /// </summary> + /// <param name="i_R"></param> + /// <param name="i_G"></param> + /// <param name="i_B"></param> + /// <returns></returns> + private string GetColorTextTranslate(int i_R, int i_G, int i_B) + { + return Convert.ToString(i_R, 16).ToUpper().PadLeft(2, '0') + + Convert.ToString(i_G, 16).ToUpper().PadLeft(2, '0') + + Convert.ToString(i_B, 16).ToUpper().PadLeft(2, '0'); + } + + /// <summary> + /// 灏哛GB杞崲涓洪鑹� + /// </summary> + /// <param name="R"></param> + /// <param name="G"></param> + /// <param name="B"></param> + /// <returns></returns> + private uint GetColorByRGB(byte R, byte G, byte B) + { + return (uint)(0xFF000000 + R * 256 * 256 + G * 256 + B); + } + + #endregion + + #region 鈻� 鐣岄潰鍏抽棴___________________________ + + /// <summary> + /// 鐣岄潰鍏抽棴 + /// </summary> + public override void CloseFormBefore() + { + this.FinishSelectColorEvent = null; + + base.CloseFormBefore(); + } + + #endregion + } +} -- Gitblit v1.8.0