private void OnColorChanged <T>(AvaloniaPropertyChangedEventArgs <T> args)
        {
            // If we're in the process of internally updating the color, then we don't want to respond to the Color property changing,
            // aside from raising the ColorChanged event.
            if (!m_updatingColor)
            {
                var color = Color;

                m_currentRgb   = new Rgb(color.R / 255.0, color.G / 255.0, color.B / 255.0);
                m_currentAlpha = color.A / 255.0;
                m_currentHsv   = ColorConversion.RgbToHsv(m_currentRgb);
                m_currentHex   = GetCurrentHexValue();

                UpdateColorControls(ColorUpdateReason.ColorPropertyChanged);
            }

            var oldColor = args.OldValue.GetValueOrDefault <Color>();
            var newColor = args.NewValue.GetValueOrDefault <Color>();

            if (oldColor.A != newColor.A ||
                oldColor.R != newColor.R ||
                oldColor.G != newColor.G ||
                oldColor.B != newColor.B)
            {
                var colorChangedEventArgs = new ColorChangedEventArgs(oldColor, newColor);
                ColorChanged?.Invoke(this, colorChangedEventArgs);
            }
        }
        private void UpdateColor(Rgb rgb, ColorUpdateReason reason)
        {
            m_currentRgb = rgb;
            m_currentHsv = ColorConversion.RgbToHsv(m_currentRgb);
            m_currentHex = GetCurrentHexValue();

            SetColorAndUpdateControls(reason);
        }
        private void InitializeColor()
        {
            var color = Color;

            m_currentRgb   = new Rgb(color.R / 255.0, color.G / 255.0, color.B / 255.0);
            m_currentHsv   = ColorConversion.RgbToHsv(m_currentRgb);
            m_currentAlpha = color.A / 255.0;
            m_currentHex   = GetCurrentHexValue();

            SetColorAndUpdateControls(ColorUpdateReason.InitializingColor);
        }
        private Rgb ApplyConstraintsToRgbColor(Rgb rgb)
        {
            double minHue        = MinHue;
            double maxHue        = MaxHue;
            var    minSaturation = MinSaturation / 100.0;
            var    maxSaturation = MaxSaturation / 100.0;
            var    minValue      = MinValue / 100.0;
            var    maxValue      = MaxValue / 100.0;

            var hsv = ColorConversion.RgbToHsv(rgb);

            hsv.H = Math.Min(Math.Max(hsv.H, minHue), maxHue);
            hsv.S = Math.Min(Math.Max(hsv.S, minSaturation), maxSaturation);
            hsv.V = Math.Min(Math.Max(hsv.V, minValue), maxValue);

            return(ColorConversion.HsvToRgb(hsv));
        }