public ColorPicker() { base.SetStyle(ControlStyles.UserPaint | ControlStyles.ResizeRedraw | ControlStyles.SupportsTransparentBackColor | ControlStyles.AllPaintingInWmPaint | ControlStyles.DoubleBuffer, true); base.UpdateStyles(); this.m_Style = ColorPickerStyle.ColorBoxAndText; this.m_PropertyAdapter = new PlugInEditorControlPropertyAdapter(); this.BackColor = SystemColors.Window; this.IsValid = true; this.ColorChanged += this.ColorPicker_ColorChanged; }
/// <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(); }