Esempio n. 1
0
        private string GetValueString(Color color, int value)
        {
            if (DownlevelHelper.ToDisplayNameExists())
            {
                string resourceStringWithName;
                switch (_owner.ColorChannel)
                {
                case ColorPickerHsvChannel.Hue:
                    resourceStringWithName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringHueSliderWithColorName);
                    break;

                case ColorPickerHsvChannel.Saturation:
                    resourceStringWithName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringSaturationSliderWithColorName);
                    break;

                case ColorPickerHsvChannel.Value:
                    resourceStringWithName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringValueSliderWithColorName);
                    break;

                default:
                    return(string.Empty);
                }

                return(string.Format(
                           CultureInfo.CurrentUICulture,
                           resourceStringWithName,
                           value,
                           ColorHelper.ToDisplayName(color)));
            }
            else
            {
                string resourceStringWithoutName;
                switch (_owner.ColorChannel)
                {
                case ColorPickerHsvChannel.Hue:
                    resourceStringWithoutName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringHueSliderWithoutColorName);
                    break;

                case ColorPickerHsvChannel.Saturation:
                    resourceStringWithoutName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringSaturationSliderWithoutColorName);
                    break;

                case ColorPickerHsvChannel.Value:
                    resourceStringWithoutName = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringValueSliderWithoutColorName);
                    break;

                default:
                    return(string.Empty);
                }

                return(string.Format(
                           CultureInfo.CurrentUICulture,
                           resourceStringWithoutName,
                           value));
            }
        }
Esempio n. 2
0
        private string GetValueString(Color color, Vector4 hsvColor)
        {
            var hue        = (uint)Math.Round(Hsv.GetHue(hsvColor));
            var saturation = (uint)Math.Round(Hsv.GetSaturation(hsvColor) * 100);
            var value      = (uint)Math.Round(Hsv.GetValue(hsvColor) * 100);

            if (DownlevelHelper.ToDisplayNameExists())
            {
                return(StringUtil.FormatString(
                           ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringColorSpectrumWithColorName),
                           ColorHelper.ToDisplayName(color),
                           hue, saturation, value));
            }
            else
            {
                return(StringUtil.FormatString(
                           ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ValueStringColorSpectrumWithoutColorName),
                           hue, saturation, value));
            }
        }
Esempio n. 3
0
        private string GetToolTipString()
        {
            uint sliderValue = (uint)(Math.Round(this.Value));

            if (this.ColorChannel == ColorPickerHsvChannel.Alpha)
            {
                return(StringUtil.FormatString(
                           ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringAlphaSlider),
                           sliderValue));
            }
            else
            {
                ColorPicker parentColorPicker = GetParentColorPicker();
                if (parentColorPicker != null && DownlevelHelper.ToDisplayNameExists())
                {
                    Hsv    currentHsv = parentColorPicker.GetCurrentHsv();
                    string localizedString;

                    switch (this.ColorChannel)
                    {
                    case ColorPickerHsvChannel.Hue:
                        currentHsv.H    = this.Value;
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringHueSliderWithColorName);
                        break;

                    case ColorPickerHsvChannel.Saturation:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringSaturationSliderWithColorName);
                        currentHsv.S    = this.Value / 100;
                        break;

                    case ColorPickerHsvChannel.Value:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringValueSliderWithColorName);
                        currentHsv.V    = this.Value / 100;
                        break;

                    default:
                        throw new InvalidOperationException("Invalid ColorPickerHsvChannel.");                                 // Uno Doc: 'throw winrt::hresult_error(E_FAIL);'
                    }

                    return(StringUtil.FormatString(
                               localizedString,
                               sliderValue,
                               ColorHelper.ToDisplayName(ColorConversion.ColorFromRgba(ColorConversion.HsvToRgb(currentHsv)))));
                }
                else
                {
                    string localizedString;
                    switch (this.ColorChannel)
                    {
                    case ColorPickerHsvChannel.Hue:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringHueSliderWithoutColorName);
                        break;

                    case ColorPickerHsvChannel.Saturation:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringSaturationSliderWithoutColorName);
                        break;

                    case ColorPickerHsvChannel.Value:
                        localizedString = ResourceAccessor.GetLocalizedStringResource(ResourceAccessor.SR_ToolTipStringValueSliderWithoutColorName);
                        break;

                    default:
                        throw new InvalidOperationException("Invalid ColorPickerHsvChannel.");                                 // Uno Doc: 'throw winrt::hresult_error(E_FAIL);'
                    }

                    return(StringUtil.FormatString(
                               localizedString,
                               sliderValue));
                }
            }
        }
Esempio n. 4
0
        public static Hsv IncrementColorChannel(
            Hsv originalHsv,
            ColorPickerHsvChannel channel,
            IncrementDirection direction,
            IncrementAmount amount,
            bool shouldWrap,
            double minBound,
            double maxBound)
        {
            Hsv newHsv = originalHsv;

            if (amount == IncrementAmount.Small || !DownlevelHelper.ToDisplayNameExists())
            {
                // In order to avoid working with small values that can incur rounding issues,
                // we'll multiple saturation and value by 100 to put them in the range of 0-100 instead of 0-1.
                newHsv.S *= 100;
                newHsv.V *= 100;

                // Uno Doc: *valueToIncrement replaced with ref local variable for C#, must be initialized
                ref double valueToIncrement = ref newHsv.H;
                double     incrementAmount  = 0.0;

                // If we're adding a small increment, then we'll just add or subtract 1.
                // If we're adding a large increment, then we want to snap to the next
                // or previous major value - for hue, this is every increment of 30;
                // for saturation and value, this is every increment of 10.
                switch (channel)
                {
                case ColorPickerHsvChannel.Hue:
                    valueToIncrement = ref newHsv.H;
                    incrementAmount  = amount == IncrementAmount.Small ? 1 : 30;
                    break;

                case ColorPickerHsvChannel.Saturation:
                    valueToIncrement = ref newHsv.S;
                    incrementAmount  = amount == IncrementAmount.Small ? 1 : 10;
                    break;

                case ColorPickerHsvChannel.Value:
                    valueToIncrement = ref newHsv.V;
                    incrementAmount  = amount == IncrementAmount.Small ? 1 : 10;
                    break;

                default:
                    throw new InvalidOperationException("Invalid ColorPickerHsvChannel.");                             // Uno Doc: 'winrt::hresult_error(E_FAIL);'
                }

                double previousValue = valueToIncrement;

                valueToIncrement += (direction == IncrementDirection.Lower ? -incrementAmount : incrementAmount);

                // If the value has reached outside the bounds, we were previous at the boundary, and we should wrap,
                // then we'll place the selection on the other side of the spectrum.
                // Otherwise, we'll place it on the boundary that was exceeded.
                if (valueToIncrement < minBound)
                {
                    valueToIncrement = (shouldWrap && previousValue == minBound) ? maxBound : minBound;
                }

                if (valueToIncrement > maxBound)
                {
                    valueToIncrement = (shouldWrap && previousValue == maxBound) ? minBound : maxBound;
                }

                // We multiplied saturation and value by 100 previously, so now we want to put them back in the 0-1 range.
                newHsv.S /= 100;
                newHsv.V /= 100;
            }