using ryCommon;
using ryControls;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using WeifenLuo.WinFormsUI.Docking;

namespace 开发辅助工具.Tools
{
    public partial class FrmColor : DockContent
    {
        public FrmColor()
        {
            InitializeComponent();
        }

        private void SuperColor1_BackColorChanged(object sender, EventArgs e)
        {
            Color color = superColor1.BackColor;
            ryControls.ColorRGB RGB =new ryControls.ColorRGB(color.R,color.G,color.B);
            var hsl= ryControls.ColorHelper.RgbToHsl(RGB);
            var hsv = ryControls.ColorHelper.RgbToHsv(RGB);
            tableModel1.Rows.Clear();
            AddList("RGB颜色值", "rgb(" + color.R + "," + color.G + "," + color.B + ")","");
            AddList("RGBA颜色值", "rgba(" + color.R + "," + color.G + "," + color.B + "," + color.A + ")", "HTML5、CSS3常用");
            AddList("ARGB颜色值", String.Format("#{0:X2}{1:X2}{2:X2}{3:X2}", color.A, color.R, color.G, color.B), "android常用");
            AddList("16进制颜色值", String.Format("#{0:X2}{1:X2}{2:X2}", color.R, color.G, color.B), "");
            AddList("HSL颜色值", "hsl(" + color.GetHue().ToString("0.00") + "," + color.GetSaturation().ToString("0.00%") + "," + (hsl.L / 255m).ToString("0.00%") + ")", "");
            AddList("HSV颜色值", "hsv(" + color.GetHue().ToString("0.00") + "," + (hsv.S / 255m).ToString("0.00") + "," + (hsv.V / 255m).ToString("0.00") + ")", "");
            ColorHelper.RGB2CMYK(RGB, out var c, out var m, out var y, out var k);
            AddList("CMYK", c.ToInt().ToString()+","+m.ToInt().ToString() + "," + y.ToInt().ToString() + "," + k.ToInt().ToString(), "印刷四色模式");
            ColorHelper.RGB2XYZ(RGB, out var x, out var y1, out var z);
            AddList("XYZ", x.ToString("0.000") + "," + y1.ToString("0.000") + "," + z.ToString("0.000"), "D65/2°");
            ColorHelper.RGB2Yxy(RGB, out var Y, out var x2, out var y2);
            AddList("Yxy", Y.ToString("0.000") + "," + x2.ToString("0.000") + "," + y2.ToString("0.000"), "D65/2°");
            void AddList(string title,string value,string des)
            {
                XPTable.Models.Row itemList = new XPTable.Models.Row()
                {
                    Tag = ""
                };
                //需要修改此处
                itemList.Cells.Add(new XPTable.Models.Cell(title));//示例
                itemList.Cells.Add(new XPTable.Models.Cell(value));//示例
                var cell = new XPTable.Models.Cell(des)
                {
                    ForeColor = Color.Gray
                };
                itemList.Cells.Add(cell);
                tableModel1.Rows.Add(itemList);
            }
        }
        private void FrmColor_Load(object sender, EventArgs e)
        {
        }

        private void TableModel1_SelectionChanged(object sender, XPTable.Events.SelectionEventArgs e)
        {
            if (e.NewSelectedIndicies.Length <= 0) { TxtType.Text = "";TxtValue.Text = ""; return; }
            int row = e.NewSelectedIndicies[0];
            TxtType.Text = table1.TableModel.Rows[row].Cells[ColTitle.Index].Text;
            TxtValue.Text = table1.TableModel.Rows[row].Cells[ColValue.Index].Text;
        }
    }
}
