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;
|
}
|
|
}
|
}
|