示例#1
0
        /// <summary>
        /// 返回将 ColorX 结构表示的两种颜色在 RGB 色彩空间按指定比例线性混合得到的颜色。
        /// </summary>
        /// <param name="color1">ColorX 结构表示的第一种颜色。</param>
        /// <param name="color2">ColorX 结构表示的第二种颜色。</param>
        /// <param name="proportion">第一种颜色所占的比例,取值范围为 [0, 1] 或 (1, 100]。</param>
        /// <returns>ColorX 结构,表示将两种颜色在 RGB 色彩空间按指定比例线性混合得到的颜色。</returns>
        public static ColorX BlendByRGB(ColorX color1, ColorX color2, double proportion)
        {
            proportion = _CheckProportion(proportion);

            return(ColorX.FromRGB(color1.Alpha * proportion + color2.Alpha * (1 - proportion), color1.RGB * proportion + color2.RGB * (1 - proportion)));
        }
示例#2
0
        // 使用主题、主题色、表示是否在窗口标题栏上显示主题色的布尔值、表示是否在窗口阴影显示主题色的布尔值与表示窗口是否处于活动状态的布尔值初始化 RecommendColors 的新实例。
        internal RecommendColors(Theme theme, ColorX themeColor, bool showCaptionBarColor, bool showShadowColor, bool isActive)
        {
            switch (theme)
            {
            case Theme.Colorful:
            {
                _Main     = ColorManipulation.BlendByLAB(themeColor.AtLightness_HSL(56), themeColor, 0.75);
                _Main     = ColorManipulation.ShiftLightnessByLAB(_Main, (1 - _Main.Lightness_LAB / 50) * 0.25);
                _Main_DEC = ColorManipulation.ShiftLightnessByHSL(_Main, 0.2);
                _Main_INC = ColorManipulation.ShiftLightnessByHSL(_Main, -0.15);

                _FormBackground = themeColor.AtLightness_HSL(98);

                if (isActive)
                {
                    if (showCaptionBarColor)
                    {
                        _CaptionBar = _Main;
                        _Caption    = (!BackColorFitLightText(_CaptionBar) ? Color.FromArgb(16, 16, 16) : Color.FromArgb(240, 240, 240));
                    }
                    else
                    {
                        _CaptionBar = _FormBackground;
                        _Caption    = Color.FromArgb(16, 16, 16);
                    }
                }
                else
                {
                    _CaptionBar = _FormBackground.Grayscale;
                    _Caption    = Color.FromArgb(128, 128, 128);
                }

                if (showShadowColor)
                {
                    _Shadow = (isActive ? _Main : _Main.Grayscale);
                }
                else
                {
                    _Shadow = Color.Black;
                }

                _ControlButton     = ColorX.Transparent;
                _ControlButton_INC = (!BackColorFitLightText(_CaptionBar) ? ColorManipulation.ShiftLightnessByHSL(_CaptionBar, -0.2) : ColorManipulation.ShiftLightnessByHSL(_CaptionBar, 0.3)).AtOpacity(70);
                _ControlButton_DEC = _ControlButton_INC.AtOpacity(50);

                _ExitButton     = ColorX.Transparent;
                _ExitButton_DEC = ColorX.FromRGB(232, 17, 35);
                _ExitButton_INC = _ExitButton_DEC.AtOpacity(70);

                _MenuItemBackground = themeColor.AtLightness_HSL(98);
                _MenuItemText       = themeColor.AtLightness_HSL(24);

                _Text     = themeColor.AtLightness_HSL(40);
                _Text_DEC = themeColor.AtLightness_HSL(56);
                _Text_INC = themeColor.AtLightness_HSL(24);

                _Background     = themeColor.AtLightness_HSL(92);
                _Background_DEC = themeColor.AtLightness_HSL(96);
                _Background_INC = themeColor.AtLightness_HSL(88);

                _Border     = themeColor.AtLightness_HSL(68);
                _Border_DEC = themeColor.AtLightness_HSL(84);
                _Border_INC = themeColor.AtLightness_HSL(52);

                _Button     = themeColor.AtLightness_HSL(76);
                _Button_DEC = themeColor.AtLightness_HSL(82);
                _Button_INC = themeColor.AtLightness_HSL(70);

                _Slider     = themeColor.AtLightness_HSL(68);
                _Slider_DEC = themeColor.AtLightness_HSL(76);
                _Slider_INC = themeColor.AtLightness_HSL(60);

                _ScrollBar     = themeColor.AtLightness_HSL(84);
                _ScrollBar_DEC = themeColor.AtLightness_HSL(86);
                _ScrollBar_INC = themeColor.AtLightness_HSL(82);
            }
            break;

            case Theme.White:
            {
                _Main     = ColorManipulation.BlendByLAB(themeColor.AtLightness_HSL(56), themeColor, 0.75);
                _Main     = ColorManipulation.ShiftLightnessByLAB(_Main, (1 - _Main.Lightness_LAB / 50) * 0.25);
                _Main_DEC = ColorManipulation.ShiftLightnessByHSL(_Main, 0.2);
                _Main_INC = ColorManipulation.ShiftLightnessByHSL(_Main, -0.15);

                _FormBackground = themeColor.AtLightness_HSL(98).Grayscale;

                if (isActive)
                {
                    if (showCaptionBarColor)
                    {
                        _CaptionBar = _Main;
                        _Caption    = (!BackColorFitLightText(_CaptionBar) ? Color.FromArgb(16, 16, 16) : Color.FromArgb(240, 240, 240));
                    }
                    else
                    {
                        _CaptionBar = _FormBackground;
                        _Caption    = Color.FromArgb(16, 16, 16);
                    }
                }
                else
                {
                    _CaptionBar = _FormBackground.Grayscale;
                    _Caption    = Color.FromArgb(128, 128, 128);
                }

                if (showShadowColor)
                {
                    _Shadow = (isActive ? _Main : _Main.Grayscale);
                }
                else
                {
                    _Shadow = Color.Black;
                }

                _ControlButton     = ColorX.Transparent;
                _ControlButton_INC = (!BackColorFitLightText(_CaptionBar) ? ColorManipulation.ShiftLightnessByHSL(_CaptionBar, -0.2) : ColorManipulation.ShiftLightnessByHSL(_CaptionBar, 0.3)).AtOpacity(70);
                _ControlButton_DEC = _ControlButton_INC.AtOpacity(50);

                _ExitButton     = ColorX.Transparent;
                _ExitButton_DEC = ColorX.FromRGB(232, 17, 35);
                _ExitButton_INC = _ExitButton_DEC.AtOpacity(70);

                _MenuItemBackground = themeColor.AtLightness_HSL(98).Grayscale;
                _MenuItemText       = themeColor.AtLightness_HSL(24).Grayscale;

                _Text     = themeColor.AtLightness_HSL(40).Grayscale;
                _Text_DEC = themeColor.AtLightness_HSL(56).Grayscale;
                _Text_INC = themeColor.AtLightness_HSL(24).Grayscale;

                _Background     = themeColor.AtLightness_HSL(92).Grayscale;
                _Background_DEC = themeColor.AtLightness_HSL(96).Grayscale;
                _Background_INC = themeColor.AtLightness_HSL(88).Grayscale;

                _Border     = themeColor.AtLightness_HSL(68).Grayscale;
                _Border_DEC = themeColor.AtLightness_HSL(84).Grayscale;
                _Border_INC = themeColor.AtLightness_HSL(52).Grayscale;

                _Button     = themeColor.AtLightness_HSL(76).Grayscale;
                _Button_DEC = themeColor.AtLightness_HSL(82).Grayscale;
                _Button_INC = themeColor.AtLightness_HSL(70).Grayscale;

                _Slider     = themeColor.AtLightness_HSL(68).Grayscale;
                _Slider_DEC = themeColor.AtLightness_HSL(76).Grayscale;
                _Slider_INC = themeColor.AtLightness_HSL(60).Grayscale;

                _ScrollBar     = themeColor.AtLightness_HSL(84).Grayscale;
                _ScrollBar_DEC = themeColor.AtLightness_HSL(86).Grayscale;
                _ScrollBar_INC = themeColor.AtLightness_HSL(82).Grayscale;
            }
            break;

            case Theme.LightGray:
            {
                _Main     = ColorManipulation.BlendByLAB(themeColor.AtLightness_HSL(56), themeColor, 0.75);
                _Main     = ColorManipulation.ShiftLightnessByLAB(_Main, (1 - _Main.Lightness_LAB / 50) * 0.25).Grayscale;
                _Main_DEC = ColorManipulation.ShiftLightnessByHSL(_Main, 0.2);
                _Main_INC = ColorManipulation.ShiftLightnessByHSL(_Main, -0.15);

                _FormBackground = themeColor.AtLightness_HSL(98).Grayscale;

                if (isActive)
                {
                    if (showCaptionBarColor)
                    {
                        _CaptionBar = _Main;
                        _Caption    = (!BackColorFitLightText(_CaptionBar) ? Color.FromArgb(16, 16, 16) : Color.FromArgb(240, 240, 240));
                    }
                    else
                    {
                        _CaptionBar = _FormBackground;
                        _Caption    = Color.FromArgb(16, 16, 16);
                    }
                }
                else
                {
                    _CaptionBar = _FormBackground.Grayscale;
                    _Caption    = Color.FromArgb(128, 128, 128);
                }

                if (showShadowColor)
                {
                    _Shadow = (isActive ? _Main : _Main.Grayscale);
                }
                else
                {
                    _Shadow = Color.Black;
                }

                _ControlButton     = ColorX.Transparent;
                _ControlButton_INC = (!BackColorFitLightText(_CaptionBar) ? ColorManipulation.ShiftLightnessByHSL(_CaptionBar, -0.2) : ColorManipulation.ShiftLightnessByHSL(_CaptionBar, 0.3)).AtOpacity(70);
                _ControlButton_DEC = _ControlButton_INC.AtOpacity(50);

                _ExitButton     = ColorX.Transparent;
                _ExitButton_DEC = ColorX.FromRGB(232, 17, 35);
                _ExitButton_INC = _ExitButton_DEC.AtOpacity(70);

                _MenuItemBackground = themeColor.AtLightness_HSL(98).Grayscale;
                _MenuItemText       = themeColor.AtLightness_HSL(24).Grayscale;

                _Text     = themeColor.AtLightness_HSL(40).Grayscale;
                _Text_DEC = themeColor.AtLightness_HSL(56);
                _Text_INC = themeColor.AtLightness_HSL(24);

                _Background     = themeColor.AtLightness_HSL(92).Grayscale;
                _Background_DEC = themeColor.AtLightness_HSL(96);
                _Background_INC = themeColor.AtLightness_HSL(88);

                _Border     = themeColor.AtLightness_HSL(68).Grayscale;
                _Border_DEC = themeColor.AtLightness_HSL(84);
                _Border_INC = themeColor.AtLightness_HSL(52);

                _Button     = themeColor.AtLightness_HSL(76).Grayscale;
                _Button_DEC = themeColor.AtLightness_HSL(82);
                _Button_INC = themeColor.AtLightness_HSL(70);

                _Slider     = themeColor.AtLightness_HSL(68).Grayscale;
                _Slider_DEC = themeColor.AtLightness_HSL(76);
                _Slider_INC = themeColor.AtLightness_HSL(60);

                _ScrollBar     = themeColor.AtLightness_HSL(84).Grayscale;
                _ScrollBar_DEC = themeColor.AtLightness_HSL(86);
                _ScrollBar_INC = themeColor.AtLightness_HSL(82);
            }
            break;

            case Theme.DarkGray:
            {
                _Main     = ColorManipulation.BlendByLAB(themeColor.AtLightness_HSL(44), themeColor, 0.75);
                _Main     = ColorManipulation.ShiftLightnessByLAB(_Main, (1 - _Main.Lightness_LAB / 50) * 0.25).Grayscale;
                _Main_DEC = ColorManipulation.ShiftLightnessByHSL(_Main, -0.2);
                _Main_INC = ColorManipulation.ShiftLightnessByHSL(_Main, 0.15);

                _FormBackground = themeColor.AtLightness_HSL(2).Grayscale;

                if (isActive)
                {
                    if (showCaptionBarColor)
                    {
                        _CaptionBar = _Main;
                        _Caption    = (!BackColorFitLightText(_CaptionBar) ? Color.FromArgb(16, 16, 16) : Color.FromArgb(240, 240, 240));
                    }
                    else
                    {
                        _CaptionBar = _FormBackground;
                        _Caption    = Color.FromArgb(240, 240, 240);
                    }
                }
                else
                {
                    _CaptionBar = _FormBackground.Grayscale;
                    _Caption    = Color.FromArgb(192, 192, 192);
                }

                if (showShadowColor)
                {
                    _Shadow = (isActive ? _Main : _Main.Grayscale);
                }
                else
                {
                    _Shadow = Color.Black;
                }

                _ControlButton     = ColorX.Transparent;
                _ControlButton_INC = (!BackColorFitLightText(_CaptionBar) ? ColorManipulation.ShiftLightnessByHSL(_CaptionBar, -0.2) : ColorManipulation.ShiftLightnessByHSL(_CaptionBar, 0.3)).AtOpacity(70);
                _ControlButton_DEC = _ControlButton_INC.AtOpacity(50);

                _ExitButton     = ColorX.Transparent;
                _ExitButton_DEC = ColorX.FromRGB(232, 17, 35);
                _ExitButton_INC = _ExitButton_DEC.AtOpacity(70);

                _MenuItemBackground = themeColor.AtLightness_HSL(98).Grayscale;
                _MenuItemText       = themeColor.AtLightness_HSL(24).Grayscale;

                _Text     = themeColor.AtLightness_HSL(60).Grayscale;
                _Text_DEC = themeColor.AtLightness_HSL(44);
                _Text_INC = themeColor.AtLightness_HSL(76);

                _Background     = themeColor.AtLightness_HSL(8).Grayscale;
                _Background_DEC = themeColor.AtLightness_HSL(4);
                _Background_INC = themeColor.AtLightness_HSL(12);

                _Border     = themeColor.AtLightness_HSL(32).Grayscale;
                _Border_DEC = themeColor.AtLightness_HSL(16);
                _Border_INC = themeColor.AtLightness_HSL(48);

                _Button     = themeColor.AtLightness_HSL(24).Grayscale;
                _Button_DEC = themeColor.AtLightness_HSL(18);
                _Button_INC = themeColor.AtLightness_HSL(30);

                _Slider     = themeColor.AtLightness_HSL(32).Grayscale;
                _Slider_DEC = themeColor.AtLightness_HSL(24);
                _Slider_INC = themeColor.AtLightness_HSL(40);

                _ScrollBar     = themeColor.AtLightness_HSL(16).Grayscale;
                _ScrollBar_DEC = themeColor.AtLightness_HSL(14);
                _ScrollBar_INC = themeColor.AtLightness_HSL(18);
            }
            break;

            case Theme.Black:
            {
                _Main     = ColorManipulation.BlendByLAB(themeColor.AtLightness_HSL(44), themeColor, 0.75);
                _Main     = ColorManipulation.ShiftLightnessByLAB(_Main, (1 - _Main.Lightness_LAB / 50) * 0.25);
                _Main_DEC = ColorManipulation.ShiftLightnessByHSL(_Main, -0.2);
                _Main_INC = ColorManipulation.ShiftLightnessByHSL(_Main, 0.15);

                _FormBackground = themeColor.AtLightness_HSL(2).Grayscale;

                if (isActive)
                {
                    if (showCaptionBarColor)
                    {
                        _CaptionBar = _Main;
                        _Caption    = (!BackColorFitLightText(_CaptionBar) ? Color.FromArgb(16, 16, 16) : Color.FromArgb(240, 240, 240));
                    }
                    else
                    {
                        _CaptionBar = _FormBackground;
                        _Caption    = Color.FromArgb(240, 240, 240);
                    }
                }
                else
                {
                    _CaptionBar = _FormBackground.Grayscale;
                    _Caption    = Color.FromArgb(192, 192, 192);
                }

                if (showShadowColor)
                {
                    _Shadow = (isActive ? _Main : _Main.Grayscale);
                }
                else
                {
                    _Shadow = Color.Black;
                }

                _ControlButton     = ColorX.Transparent;
                _ControlButton_INC = (!BackColorFitLightText(_CaptionBar) ? ColorManipulation.ShiftLightnessByHSL(_CaptionBar, -0.2) : ColorManipulation.ShiftLightnessByHSL(_CaptionBar, 0.3)).AtOpacity(70);
                _ControlButton_DEC = _ControlButton_INC.AtOpacity(50);

                _ExitButton     = ColorX.Transparent;
                _ExitButton_DEC = ColorX.FromRGB(232, 17, 35);
                _ExitButton_INC = _ExitButton_DEC.AtOpacity(70);

                _MenuItemBackground = themeColor.AtLightness_HSL(98).Grayscale;
                _MenuItemText       = themeColor.AtLightness_HSL(24).Grayscale;

                _Text     = themeColor.AtLightness_HSL(60).Grayscale;
                _Text_DEC = themeColor.AtLightness_HSL(44).Grayscale;
                _Text_INC = themeColor.AtLightness_HSL(76).Grayscale;

                _Background     = themeColor.AtLightness_HSL(8).Grayscale;
                _Background_DEC = themeColor.AtLightness_HSL(4).Grayscale;
                _Background_INC = themeColor.AtLightness_HSL(12).Grayscale;

                _Border     = themeColor.AtLightness_HSL(32).Grayscale;
                _Border_DEC = themeColor.AtLightness_HSL(16).Grayscale;
                _Border_INC = themeColor.AtLightness_HSL(48).Grayscale;

                _Button     = themeColor.AtLightness_HSL(24).Grayscale;
                _Button_DEC = themeColor.AtLightness_HSL(18).Grayscale;
                _Button_INC = themeColor.AtLightness_HSL(30).Grayscale;

                _Slider     = themeColor.AtLightness_HSL(32).Grayscale;
                _Slider_DEC = themeColor.AtLightness_HSL(24).Grayscale;
                _Slider_INC = themeColor.AtLightness_HSL(40).Grayscale;

                _ScrollBar     = themeColor.AtLightness_HSL(16).Grayscale;
                _ScrollBar_DEC = themeColor.AtLightness_HSL(14).Grayscale;
                _ScrollBar_INC = themeColor.AtLightness_HSL(18).Grayscale;
            }
            break;
            }

            //

            double LShift = (themeColor.Lightness_LAB / 50 - 1) * 0.1;

            _Text     = ColorManipulation.ShiftLightnessByLAB(_Text, LShift);
            _Text_DEC = ColorManipulation.ShiftLightnessByLAB(_Text_DEC, LShift);
            _Text_INC = ColorManipulation.ShiftLightnessByLAB(_Text_INC, LShift);

            _Background     = ColorManipulation.ShiftLightnessByLAB(_Background, LShift);
            _Background_DEC = ColorManipulation.ShiftLightnessByLAB(_Background_DEC, LShift);
            _Background_INC = ColorManipulation.ShiftLightnessByLAB(_Background_INC, LShift);

            _Border     = ColorManipulation.ShiftLightnessByLAB(_Border, LShift);
            _Border_DEC = ColorManipulation.ShiftLightnessByLAB(_Border_DEC, LShift);
            _Border_INC = ColorManipulation.ShiftLightnessByLAB(_Border_INC, LShift);

            _Button     = ColorManipulation.ShiftLightnessByLAB(_Button, LShift);
            _Button_DEC = ColorManipulation.ShiftLightnessByLAB(_Button_DEC, LShift);
            _Button_INC = ColorManipulation.ShiftLightnessByLAB(_Button_INC, LShift);

            _Slider     = ColorManipulation.ShiftLightnessByLAB(_Slider, LShift);
            _Slider_DEC = ColorManipulation.ShiftLightnessByLAB(_Slider_DEC, LShift);
            _Slider_INC = ColorManipulation.ShiftLightnessByLAB(_Slider_INC, LShift);

            _ScrollBar     = ColorManipulation.ShiftLightnessByLAB(_ScrollBar, LShift);
            _ScrollBar_DEC = ColorManipulation.ShiftLightnessByLAB(_ScrollBar_DEC, LShift);
            _ScrollBar_INC = ColorManipulation.ShiftLightnessByLAB(_ScrollBar_INC, LShift);
        }