Ejemplo n.º 1
0
        internal static Color_ FromBGR(int bgr)
        {
            Color_ result = Color_.FromArgb(0xFF, (bgr & 0xFF), ((bgr >> 8) & 0xFF), ((bgr >> 16) & 0xFF));
            Color_ known  = KnownColors.FindColorMatch(result);

            return((known.IsEmpty) ? result : known);
        }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            lock (creatingCached)
            {
                if (cached != null)
                {
                    return(cached);
                }
#if TARGET_JVM
                Color [] colors = new Color [KnownColors.Values.Length - 1];
                Array.Copy(KnownColors.Values, 1, colors, 0, colors.Length);
#else
                Array colors = Array.CreateInstance(typeof(Color), KnownColors.ArgbValues.Length - 1);
                for (int i = 1; i < KnownColors.ArgbValues.Length; i++)
                {
                    colors.SetValue(KnownColors.FromKnownColor((KnownColor)i), i - 1);
                }
#endif

                Array.Sort(colors, 0, colors.Length, new CompareColors());
                cached = new StandardValuesCollection(colors);
            }

            return(cached);
        }
Ejemplo n.º 3
0
        internal static Color FromArgbNamed(int alpha, int red, int green, int blue, string name, KnownColor knownColor)
        {
            Color color = FromArgb(alpha, red, green, blue);

            color.state      = (short)(ColorType.Known | ColorType.Named);
            color.name       = KnownColors.GetName(knownColor);
            color.knownColor = (short)knownColor;
            return(color);
        }
 internal Color FromKnownColor(KnownColors color)
 {
     if ((ProfessionalColors.ColorFreshnessKey != this.colorFreshnessKey) || (ProfessionalColors.ColorScheme != this.lastKnownColorScheme))
     {
         this.ResetRGBTable();
     }
     this.colorFreshnessKey = ProfessionalColors.ColorFreshnessKey;
     this.lastKnownColorScheme = ProfessionalColors.ColorScheme;
     return this.ColorTable[color];
 }
Ejemplo n.º 5
0
 public static Color FromName(string name)
 {
     try {
         KnownColor kc = (KnownColor)Enum.Parse(typeof(KnownColor), name, true);
         return(KnownColors.FromKnownColor(kc));
     }
     catch {
         // This is what it returns!
         Color d = FromArgb(0, 0, 0, 0);
         return(d);
     }
 }
Ejemplo n.º 6
0
        public static Color FindColorMatch(Color c)
        {
            uint argb = (uint)c.ToArgb();

            for (int i = 0; i < KnownColors.ArgbValues.Length; i++)
            {
                if (argb == KnownColors.ArgbValues [i])
                {
                    return(KnownColors.FromKnownColor((KnownColor)i));
                }
            }
            return(Color.Empty);
        }
Ejemplo n.º 7
0
 public static Color_ FromName(string name)
 {
     try {
         KnownColor kc = (KnownColor)Enum.Parse(typeof(KnownColor), name, true);
         return(KnownColors.FromKnownColor(kc));
     }
     catch {
         // This is what it returns!
         Color_ d = FromArgb(0, 0, 0, 0);
         d.name   = name;
         d.state |= (short)ColorType.Named;
         return(d);
     }
 }
        public override StandardValuesCollection GetStandardValues(ITypeDescriptorContext context)
        {
            lock (creatingCached) {
                if (cached != null)
                {
                    return(cached);
                }
                Array colors = Array.CreateInstance(typeof(Color), KnownColors.Count - 1);
                for (int i = 1; i < KnownColors.Count; i++)
                {
                    colors.SetValue(KnownColors.FromKnownColor((KnownColor)i), i - 1);
                }

                Array.Sort(colors, 0, colors.Length, new CompareColors());
                cached = new StandardValuesCollection(colors);
            }

            return(cached);
        }
 private Color FromKnownColor(KnownColors color) 
 { 
     return ColorTable[color]; 
 }
Ejemplo n.º 10
0
        internal static Color StaticConvertFromString(ITypeDescriptorContext context, string s, CultureInfo culture)
        {
            if (culture == null)
            {
                culture = CultureInfo.InvariantCulture;
            }

            s = s.Trim();

            if (s.Length == 0)
            {
                return(Color.Empty);
            }

            // Try to process both NamedColor and SystemColors from the KnownColor enumeration
            if (Char.IsLetter(s [0]))
            {
                KnownColor kc;
                try {
                    kc = (KnownColor)Enum.Parse(typeof(KnownColor), s, true);
                }
                catch (Exception e) {
                    // whatever happens MS throws an basic Exception
                    string msg = Locale.GetText("Invalid color name '{0}'.", s);
                    throw new Exception(msg, new FormatException(msg, e));
                }
                return(KnownColors.FromKnownColor(kc));
            }

            String numSeparator = culture.TextInfo.ListSeparator;
            Color  result       = Color.Empty;

            if (s.IndexOf(numSeparator) == -1)
            {
                bool sharp = (s[0] == '#');
                int  start = sharp ? 1 : 0;
                bool hex   = false;
                // deal with #hex, 0xhex and #0xhex
                if ((s.Length > start + 1) && (s[start] == '0'))
                {
                    hex = ((s[start + 1] == 'x') || (s[start + 1] == 'X'));
                    if (hex)
                    {
                        start += 2;
                    }
                }

                if (sharp || hex)
                {
                    s = s.Substring(start);
                    int argb;
                    try {
                        argb = Int32.Parse(s, NumberStyles.HexNumber);
                    }
                    catch (Exception e) {
                        // whatever happens MS throws an basic Exception
                        string msg = Locale.GetText("Invalid Int32 value '{0}'.", s);
                        throw new Exception(msg, e);
                    }

                    // note that the default alpha value for a 6 hex digit (i.e. when none are present) is
                    // 0xFF while shorter string defaults to 0xFF - unless both # an 0x are specified
                    if ((s.Length < 6) || ((s.Length == 6) && sharp && hex))
                    {
                        argb &= 0x00FFFFFF;
                    }
                    else if ((argb >> 24) == 0)
                    {
                        argb |= unchecked ((int)0xFF000000);
                    }
                    result = Color.FromArgb(argb);
                }
            }

            if (result.IsEmpty)
            {
                Int32Converter converter  = new Int32Converter();
                String []      components = s.Split(numSeparator.ToCharArray());

                // MS seems to convert the indivual component to int before
                // checking the number of components
                int[] numComponents = new int[components.Length];
                for (int i = 0; i < numComponents.Length; i++)
                {
                    numComponents[i] = (int)converter.ConvertFrom(context,
                                                                  culture, components[i]);
                }

                switch (components.Length)
                {
                case 1:
                    result = Color.FromArgb(numComponents[0]);
                    break;

                case 3:
                    result = Color.FromArgb(numComponents[0], numComponents[1],
                                            numComponents[2]);
                    break;

                case 4:
                    result = Color.FromArgb(numComponents[0], numComponents[1],
                                            numComponents[2], numComponents[3]);
                    break;

                default:
                    throw new ArgumentException(s + " is not a valid color value.");
                }
            }

            if (!result.IsEmpty)
            {
                // Look for a named or system color with those values
                Color known = KnownColors.FindColorMatch(result);
                if (!known.IsEmpty)
                {
                    return(known);
                }
            }

            return(result);
        }
Ejemplo n.º 11
0
        public static string ToHtml(Color_ c)
        {
            if (c.IsEmpty)
            {
                return(String.Empty);
            }

            if (c.IsSystemColor)
            {
                KnownColor kc = c.ToKnownColor();
                switch (kc)
                {
                case KnownColor.ActiveBorder:
                case KnownColor.ActiveCaption:
                case KnownColor.AppWorkspace:
                case KnownColor.GrayText:
                case KnownColor.Highlight:
                case KnownColor.HighlightText:
                case KnownColor.InactiveBorder:
                case KnownColor.InactiveCaption:
                case KnownColor.InactiveCaptionText:
                case KnownColor.InfoText:
                case KnownColor.Menu:
                case KnownColor.MenuText:
                case KnownColor.ScrollBar:
                case KnownColor.Window:
                case KnownColor.WindowFrame:
                case KnownColor.WindowText:
                    return(KnownColors.GetName(kc).ToLower());

                case KnownColor.ActiveCaptionText:
                    return("captiontext");

                case KnownColor.Control:
                    return("buttonface");

                case KnownColor.ControlDark:
                    return("buttonshadow");

                case KnownColor.ControlDarkDark:
                    return("threeddarkshadow");

                case KnownColor.ControlLight:
                    return("buttonface");

                case KnownColor.ControlLightLight:
                    return("buttonhighlight");

                case KnownColor.ControlText:
                    return("buttontext");

                case KnownColor.Desktop:
                    return("background");

                case KnownColor.HotTrack:
                    return("highlight");

                case KnownColor.Info:
                    return("infobackground");

                default:
                    return(String.Empty);
                }
            }

            if (c.IsNamedColor)
            {
                if (c == Color_.LightGray)
                {
                    return("LightGrey");
                }
                else
                {
                    return(c.Name);
                }
            }

            return(FormatHtml(c.R, c.G, c.B));
        }
Ejemplo n.º 12
0
 public static Color FromKnownColor(KnownColor color)
 {
     return(KnownColors.FromKnownColor(color));
 }
        internal Color FromKnownColor(KnownColors color)
        {
			return (Color)this.ColorTable[color];
        }