Exemple #1
0
        private static ResourceDictionary GetAccentResource(Color color)
        {
            // Windows のテーマがアルファ チャネル 255 以外の色を返してくるけど、
            // HSV で Active と Highlight 用の色を作る過程で結局失われるので、
            // アルファ チャネルは 255 しかサポートしないようにしてしまおう感。
            color.A = 255;

            var hsv   = color.ToHsv();
            var dark  = hsv;
            var light = hsv;

            dark.V  *= 0.8;
            light.S *= 0.6;

            var activeColor    = dark.ToRgb();
            var highlightColor = light.ToRgb();

            var luminocity = Luminosity.FromRgb(color);
            var foreground = luminocity < 128 ? Colors.White : Colors.Black;

            var dic = new ResourceDictionary
            {
                ["AccentColorKey"]           = color,
                ["AccentBrushKey"]           = new SolidColorBrush(color),
                ["AccentActiveColorKey"]     = activeColor,
                ["AccentActiveBrushKey"]     = new SolidColorBrush(activeColor),
                ["AccentHighlightColorKey"]  = highlightColor,
                ["AccentHighlightBrushKey"]  = new SolidColorBrush(highlightColor),
                ["AccentForegroundColorKey"] = foreground,
                ["AccentForegroundBrushKey"] = new SolidColorBrush(foreground),
            };

            return(dic);
        }
Exemple #2
0
        public ImmersiveColorSamples()
        {
            InitializeComponent();
            this.DataContext = typeof(ImmersiveColorNames).GetFields(BindingFlags.Static | BindingFlags.Public)
                               .Select(x => (string)x.GetValue(null))
                               .Select(name =>
            {
                var background = new SolidColorBrush(ImmersiveColor.GetColorByTypeName(name));
                var luminocity = Luminosity.FromRgb(background.Color);
                var foreground = new SolidColorBrush(luminocity < 128 ? Colors.White : Colors.Black);

                return(new { name, background, foreground, });
            })
                               .ToArray();
        }
        private void Update()
        {
            var h = this.hSlider.Value;
            var s = this.sSlider.Value / 100.0;
            var v = this.vSlider.Value / 100.0;

            var hsv = HsvColor.FromHsv(h, s, v);
            var c   = hsv.ToRgb();

            var l = Luminosity.FromRgb(c);
            var w = l <= 128;

            this.colorbox.Background = new SolidColorBrush(c);
            this.colorbox.Foreground = w ? Brushes.White : Brushes.Black;
            this.colorbox.Text       = $"Color: {c}, Luminosity: {l}";
        }
Exemple #4
0
        private void Update()
        {
            var h = this.hSlider.Value;
            var s = this.sSlider.Value / 100.0;
            var l = this.lSlider.Value / 100.0;

            var hsl = HslColor.FromHsl(h, s, l);
            var c   = hsl.ToRgb();

            var lu = Luminosity.FromRgb(c);
            var w  = lu <= 128;

            this.colorbox.Background = new SolidColorBrush(c);
            this.colorbox.Foreground = w ? Brushes.White : Brushes.Black;
            this.colorbox.Text       = $"Color: {c}({c.R},{c.G},{c.B}), Luminosity: {lu}";
        }