コード例 #1
0
        private void ColorPage_Loaded(object sender, Windows.UI.Xaml.RoutedEventArgs e)
        {
            var colorinfo = new DistinctColors();
            var array     = colorinfo.ToArray();

            for (int i = 0; i < array.Length; i++)
            {
                DistinctColorInfo info = array[i];

                var tb = new TextBlock
                {
                    Margin     = new Windows.UI.Xaml.Thickness(10, 3, 10, 3),
                    Text       = $"{info.Name} {i}",
                    Foreground = info.ForegroundBrush,
                };

                var grid = new Grid
                {
                    Height     = 32,
                    Children   = { tb },
                    Background = info.BackgroundBrush
                };

                stackpanel.Children.Add(grid);
            }
        }
コード例 #2
0
        private List <Color> FilterColorInfos()
        {
            var colorInfoList   = _distinctColors.Values.ToList();
            var foundColorCount = colorInfoList.Count;
            var maxColorCount   = _colorCount;

            if (foundColorCount < maxColorCount)
            {
                return(colorInfoList.Select(info => Color.FromArgb(info.Color)).ToList());
            }

            var random = new FastRandom(13);

            colorInfoList = colorInfoList.
                            OrderBy(info => random.Next(foundColorCount)).
                            ToList();

            DistinctColorInfo background = colorInfoList.MaxBy(info => info.Count);

            colorInfoList.Remove(background);
            maxColorCount--;

            // Filter by hue, saturation and brightness
            var comparers = new List <IEqualityComparer <DistinctColorInfo> > {
                new ColorHueComparer(), new ColorSaturationComparer(), new ColorBrightnessComparer()
            };

            while (ProcessList(maxColorCount, colorInfoList, comparers,
                               out colorInfoList))
            {
            }

            int listColorCount = colorInfoList.Count;

            if (listColorCount > 0)
            {
                int allowedTake = Math.Min(maxColorCount, listColorCount);
                colorInfoList = colorInfoList.Take(allowedTake).ToList();
            }

            var palette = new List <Color>
            {
                Color.FromArgb(background.Color)
            };

            palette.AddRange(colorInfoList.Select(colorInfo => Color.FromArgb(colorInfo.Color)));

            return(palette);
        }
コード例 #3
0
        internal TabData(string tab_caption, string page_caption, SmartPage page, DistinctColorInfo colorinfo, string unique_id)
        {
            if (unique_id == null || unique_id.Length == 0)
            {
                throw new ArgumentOutOfRangeException("a unique_id must be specified");
            }

            _tab_caption = tab_caption;
            _colorinfo   = colorinfo;
            _unique_id   = unique_id;
            _is_selected = false;

            _pages = new ObservableCollection <SmartPage>();

            page.PageCaption = page_caption;

            _pages.Add(page);
        }