Ejemplo n.º 1
0
        private void UpdateRecentColors(WpfRichText.ColorPicker.ColorItem colorItem)
        {
            if (!RecentColors.Contains(colorItem))
            {
                RecentColors.Add(colorItem);
            }

            if (RecentColors.Count > 10) //don't allow more than ten, maybe make a property that can be set by the user.
            {
                RecentColors.RemoveAt(0);
            }
        }
Ejemplo n.º 2
0
        private static ObservableCollection <WpfRichText.ColorPicker.ColorItem> CreateAvailableColors()
        {
            ObservableCollection <WpfRichText.ColorPicker.ColorItem> standardColors = new ObservableCollection <WpfRichText.ColorPicker.ColorItem>();

            foreach (var item in ColorUtilities.KnownColors)
            {
                if (!String.Equals(item.Key, "Transparent"))
                {
                    var colorItem = new WpfRichText.ColorPicker.ColorItem(item.Value, item.Key);
                    if (!standardColors.Contains(colorItem))
                    {
                        standardColors.Add(colorItem);
                    }
                }
            }

            return(standardColors);
        }
Ejemplo n.º 3
0
        public int Compare(object firstItem, object secondItem)
        {
            if (firstItem == null || secondItem == null)
            {
                return(-1);
            }

            WpfRichText.ColorPicker.ColorItem colorItem1 = (WpfRichText.ColorPicker.ColorItem)firstItem;
            WpfRichText.ColorPicker.ColorItem colorItem2 = (WpfRichText.ColorPicker.ColorItem)secondItem;

            if ((colorItem1.Color == null) || !colorItem1.Color.HasValue ||
                (colorItem2.Color == null) || !colorItem2.Color.HasValue)
            {
                return(-1);
            }

            System.Drawing.Color drawingColor1 = System.Drawing.Color.FromArgb(colorItem1.Color.Value.A, colorItem1.Color.Value.R, colorItem1.Color.Value.G, colorItem1.Color.Value.B);
            System.Drawing.Color drawingColor2 = System.Drawing.Color.FromArgb(colorItem2.Color.Value.A, colorItem2.Color.Value.R, colorItem2.Color.Value.G, colorItem2.Color.Value.B);

            // Compare Hue
            double hueColor1 = Math.Round(( double )drawingColor1.GetHue(), 3);
            double hueColor2 = Math.Round(( double )drawingColor2.GetHue(), 3);

            if (hueColor1 > hueColor2)
            {
                return(1);
            }
            else if (hueColor1 < hueColor2)
            {
                return(-1);
            }
            else
            {
                // Hue is equal, compare Saturation
                double satColor1 = Math.Round(( double )drawingColor1.GetSaturation(), 3);
                double satColor2 = Math.Round(( double )drawingColor2.GetSaturation(), 3);

                if (satColor1 > satColor2)
                {
                    return(1);
                }
                else if (satColor1 < satColor2)
                {
                    return(-1);
                }
                else
                {
                    // Saturation is equal, compare Brightness
                    double brightColor1 = Math.Round(( double )drawingColor1.GetBrightness(), 3);
                    double brightColor2 = Math.Round(( double )drawingColor2.GetBrightness(), 3);

                    if (brightColor1 > brightColor2)
                    {
                        return(1);
                    }
                    else if (brightColor1 < brightColor2)
                    {
                        return(-1);
                    }
                }
            }

            return(0);
        }