コード例 #1
0
        /// <summary>
        /// Create a new color picker Option.
        /// </summary>
        /// <param name="fixedHeight">
        ///   Whether <c cref="Height">Height</c> should return the maximum possible height given the style, or the current height.
        ///   Older versions of GMCM do not support options dynamically updating height.
        /// </param>
        /// <param name="getValue">A function that returns the current value in the underlying configuration object</param>
        /// <param name="setValue">A function that should save the given value to the underlying configuration object</param>
        /// <param name="showAlpha">Whether a slider should be shown for setting the Alpha channel or not</param>
        /// <param name="style">Specify which types of color picker to show</param>
        public ColorPickerOption(bool fixedHeight, Func <Color> getValue, Action <Color> setValue, bool showAlpha = true, ColorPickerStyle style = 0)
        {
            FixedHeight  = fixedHeight;
            GetValue     = getValue;
            SetValue     = setValue;
            ShowAlpha    = showAlpha;
            currentValue = getValue();

            if (style == ColorPickerStyle.Default)
            {
                style = ColorPickerStyle.AllStyles | ColorPickerStyle.ToggleChooser;
            }
            EffectiveStyle = style;

            ShowStylePicker = (style.HasFlag(ColorPickerStyle.RadioChooser) || style.HasFlag(ColorPickerStyle.ToggleChooser)) &&
                              BitOperations.PopCount((uint)(style & ColorPickerStyle.AllStyles)) > 1;
            Action <IconButton> styleButtonClick = style.HasFlag(ColorPickerStyle.ToggleChooser) ? IconButton.ToggleSelected : StyleButtonRadio;
            bool defaultSelected = !style.HasFlag(ColorPickerStyle.RadioChooser);

            RGBStyleButton = new IconButton(rgbStripe, null, "RGB", styleButtonClick, defaultSelected && style.HasFlag(ColorPickerStyle.RGBSliders));
            HSVStyleButton = new IconButton(smallColorWheel, null, "HSV", styleButtonClick, defaultSelected && style.HasFlag(ColorPickerStyle.HSVColorWheel));
            HSLStyleButton = new IconButton(smallColorWheel, null, "HSL", styleButtonClick, defaultSelected && style.HasFlag(ColorPickerStyle.HSLColorWheel));
            StyleButtons   = new List <IconButton>();
            if (style.HasFlag(ColorPickerStyle.RGBSliders))
            {
                StyleButtons.Add(RGBStyleButton);
            }
            if (style.HasFlag(ColorPickerStyle.HSVColorWheel))
            {
                StyleButtons.Add(HSVStyleButton);
            }
            if (style.HasFlag(ColorPickerStyle.HSLColorWheel))
            {
                StyleButtons.Add(HSLStyleButton);
            }
            if (ShowStylePicker && style.HasFlag(ColorPickerStyle.RadioChooser))
            {
                StyleButtons[0].Selected = true;
            }

            sliderR = new ColorSlider((b) => new Color((int)b, 0, 0, 255), currentValue.R, (b) => { currentValue.R = b; RGBChanged(); });
            sliderG = new ColorSlider((b) => new Color(0, (int)b, 0, 255), currentValue.G, (b) => { currentValue.G = b; RGBChanged(); });
            sliderB = new ColorSlider((b) => new Color(0, 0, (int)b, 255), currentValue.B, (b) => { currentValue.B = b; RGBChanged(); });
            sliderA = new ColorSlider((b) => new Color(0, 0, 0, (int)b), currentValue.A, (b) => { currentValue.A = b; });

            hsvWheel = new ColorWheel((h, s) => ColorUtil.FromHSV(h, s, vSlider.Value), HSVWheelChanged, 150);
            vSlider  = new VerticalSlider((v) => ColorUtil.FromHSV(hsvWheel.HueRadians, hsvWheel.Saturation, v), VSliderChanged, 150);
            hslWheel = new ColorWheel((h, s) => ColorUtil.FromHSL(h, s, lSlider.Value), HSLWheelChanged, 150);
            lSlider  = new VerticalSlider((v) => ColorUtil.FromHSL(hslWheel.HueRadians, hslWheel.Saturation, v), LSliderChanged, 150);
            ResetHSVWheel();
            ResetHSLWheel();
        }
コード例 #2
0
        /// <summary>
        /// Return the maxiumum height that this option can occupy.
        /// </summary>
        /// <returns>Height in pixels</returns>
        public int Height()
        {
            int top = sliderSpacing;

            if (ShowStylePicker)
            {
                int height = 0;
                foreach (IconButton btn in StyleButtons)
                {
                    height = Math.Max(height, btn.Height);
                }
                top += height + sliderSpacing;
            }
            if (ShowAlpha)
            {
                top += (ColorSlider.height + sliderSpacing);
            }
            if (FixedHeight)
            {
                if (EffectiveStyle.HasFlag(ColorPickerStyle.RadioChooser))
                {
                    // showing at most one of these anyway.
                    int height = 0;
                    if (EffectiveStyle.HasFlag(ColorPickerStyle.RGBSliders))
                    {
                        height = Math.Max(height, 3 * (ColorSlider.height + sliderSpacing));
                    }
                    if (EffectiveStyle.HasFlag(ColorPickerStyle.HSVColorWheel))
                    {
                        height = Math.Max(height, hsvWheel.Height);
                    }
                    if (EffectiveStyle.HasFlag(ColorPickerStyle.HSLColorWheel))
                    {
                        height = Math.Max(height, hslWheel.Height);
                    }
                    top += height;
                }
                else
                {
                    if (EffectiveStyle.HasFlag(ColorPickerStyle.RGBSliders))
                    {
                        top += 3 * (ColorSlider.height + sliderSpacing);
                    }
                    if (EffectiveStyle.HasFlag(ColorPickerStyle.HSVColorWheel) && EffectiveStyle.HasFlag(ColorPickerStyle.HSLColorWheel))
                    {
                        top = Math.Max(top, colorBoxOuterSize + sliderSpacing);
                    }
                    if (EffectiveStyle.HasFlag(ColorPickerStyle.HSVColorWheel) || EffectiveStyle.HasFlag(ColorPickerStyle.HSLColorWheel))
                    {
                        top += Math.Max(hsvWheel.Height, hslWheel.Height);
                    }
                }
            }
            else
            {
                if (RGBStyleButton.Selected)
                {
                    top += 3 * (ColorSlider.height + sliderSpacing);
                }
                if (HSVStyleButton.Selected && HSLStyleButton.Selected)
                {
                    top = Math.Max(top, colorBoxOuterSize + sliderSpacing);
                }
                if (HSVStyleButton.Selected || HSLStyleButton.Selected)
                {
                    top += Math.Max(hsvWheel.Height, hslWheel.Height);
                }
                top = Math.Max(top, colorBoxOuterSize + sliderSpacing);
            }

            return(top);
        }