Exemplo n.º 1
0
        /// <summary>
        /// The update thumb position.
        /// </summary>
        private void UpdateThumbPosition()
        {
            this.thumbTransform.X = this.Saturation * 0.01 * this.ActualWidth;
            this.thumbTransform.Y = (100 - this.Value) * 0.01 * this.ActualHeight;

            this.SelectedColor = ColorHelper.HsvToColor(this.Hue / 360.0, this.Saturation / 100.0, this.Value / 100.0);
        }
Exemplo n.º 2
0
        /// <summary>
        /// Converts a value.
        /// </summary>
        /// <param name="value">The value produced by the binding source.</param>
        /// <param name="targetType">The type of the binding target property.</param>
        /// <param name="parameter">The converter parameter to use.</param>
        /// <param name="culture">The culture to use in the converter.</param>
        /// <returns>
        /// A converted value. If the method returns <c>null</c>, the valid <c>null</c> value is used.
        /// </returns>
        public object Convert(object value, Type targetType, object parameter, CultureInfo culture)
        {
            var doubleValue = (double)value;

            return(ColorHelper.HsvToColor(doubleValue / 360, 1, 1));
        }
Exemplo n.º 3
0
        /// <summary>
        /// The update selected color.
        /// </summary>
        private void UpdateSelectedColor()
        {
            this.SelectedColor = ColorHelper.HsvToColor(this.Hue / 360.0, this.Saturation / 100.0, this.Value / 100.0);

            // ColorUtils.FireSelectedColorChangedEvent(this, SelectedColorChangedEvent, oldColor, newColor);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Called when a color component is changed.
        /// </summary>
        /// <param name="e">
        /// The <see cref="System.Windows.DependencyPropertyChangedEventArgs"/> instance containing the event data.
        /// </param>
        protected virtual void OnComponentChanged(DependencyPropertyChangedEventArgs e)
        {
            if (this.withinColorChange)
            {
                return;
            }

            if (this.SelectedColor == null)
            {
                return;
            }

            Debug.WriteLine("ColorPickerPanel.OnComponentChanged {0}", this.SelectedColor);

            var color = this.SelectedColor.Value;

            this.withinComponentChange = true;
            this.withinColorChange     = true;
            var  i = Convert.ToInt32(e.NewValue);
            byte x = i <= 255 ? (byte)i : (byte)255;

            if (e.Property == AlphaProperty)
            {
                this.SelectedColor = Color.FromArgb(x, color.R, color.G, color.B);
            }

            if (e.Property == RedProperty)
            {
                this.SelectedColor = Color.FromArgb(color.A, x, color.G, color.B);
                this.UpdateHSV(color);
            }

            if (e.Property == GreenProperty)
            {
                this.SelectedColor = Color.FromArgb(color.A, color.R, x, color.B);
                this.UpdateHSV(color);
            }

            if (e.Property == BlueProperty)
            {
                this.SelectedColor = Color.FromArgb(color.A, color.R, color.G, x);
                this.UpdateHSV(color);
            }

            var    hsv = color.ColorToHsv();
            double y   = Convert.ToDouble(e.NewValue);

            if (e.Property == HueProperty)
            {
                this.SelectedColor = ColorHelper.HsvToColor(y / 360, hsv[1], hsv[2], color.A / 255.0);
                this.UpdateRGB(this.SelectedColor.Value);
            }

            if (e.Property == SaturationProperty)
            {
                this.SelectedColor = ColorHelper.HsvToColor(hsv[0], y / 100, hsv[2], color.A / 255.0);
                this.UpdateRGB(this.SelectedColor.Value);
            }

            if (e.Property == BrightnessProperty)
            {
                this.SelectedColor = ColorHelper.HsvToColor(hsv[0], hsv[1], y / 100, color.A / 255.0);
                this.UpdateRGB(this.SelectedColor.Value);
            }

            this.withinColorChange     = false;
            this.withinComponentChange = false;
        }