Ejemplo n.º 1
0
        public PickColor(AMath.Color clr)
        {
            InitializeComponent();
            Closing += (_, __) => Color = apply ? Color : clr;

            (H, S, V) = (clr.H, clr.S, clr.V);

            Loaded += (_, __) => Update();
        }
Ejemplo n.º 2
0
        private void HexTB_KeyUp(object sender, KeyEventArgs e)
        {
            if (!hex.IsMatch((sender as TextBox).Text))
            {
                return;
            }

            AMath.Color color = AMath.Color.FromHex((sender as TextBox).Text);

            H = color.H;
            S = color.S;
            V = color.V;

            Update();
        }
Ejemplo n.º 3
0
        private void Update()
        {
            Resources["PreviewColorHue"] = (Color)AMath.Color.FromHSV(H, 1, 1, 1);
            Resources["PreviewColorSat"] = (Color)AMath.Color.FromHSV(H, S, 1, 1);
            Resources["PreviewColorVal"] = (Color)AMath.Color.FromHSV(H, S, V, 1);
            Resources["PreviewColor"]    = (Color)AMath.Color.FromHSV(H, S, V, 1);

            Color = AMath.Color.FromHSV(H, S, V);

            if (HexTB is TextBox && HueTB is TextBox && SaturationTB is TextBox && ValueTB is TextBox)
            {
                if (HueCaret is Rectangle && SatCaret is Rectangle && ValCaret is Rectangle)
                {
                    HueCaret.Margin = new Thickness(H / 360d * (HueGrid.ActualWidth - 6), -3, 0, -3);
                    SatCaret.Margin = new Thickness(S * (SatGrid.ActualWidth - 6), -3, 0, -3);
                    ValCaret.Margin = new Thickness(V * (ValGrid.ActualWidth - 6), -3, 0, -3);
                }

                int hexTBcaret        = HexTB.CaretIndex,
                    hueTBcaret        = HueTB.CaretIndex,
                    saturationTBcaret = SaturationTB.CaretIndex,
                    valueTBcaret      = ValueTB.CaretIndex;

                HueTB.Text        = $"{H:0.000}";
                SaturationTB.Text = $"{S:0.000}";
                ValueTB.Text      = $"{V:0.000}";

                HexTB.Text = Color.ToString().Remove(1, 2);

                HexTB.CaretIndex        = hexTBcaret;
                HueTB.CaretIndex        = hueTBcaret;
                SaturationTB.CaretIndex = saturationTBcaret;
                ValueTB.CaretIndex      = valueTBcaret;

                HexTB.Foreground = Color.L > 0.5 ? Brushes.Black : Brushes.White;
            }
        }