Beispiel #1
0
        public Color ResetColour(ColourTableGroup colourGroup)
        {
            Color baseColor = defaultColours[colourGroup];

            colours[colourGroup] = baseColor;
            return(baseColor);
        }
Beispiel #2
0
        public Color OverrideColour(ColourTableGroup colourGroup, Color colour)
        {
            var old = colours[colourGroup];

            colours[colourGroup] = colour;
            return(old);
        }
        public static void LoadFrom(CustomisableColourTable table, string filePath)
        {
            if (table == null)
            {
                throw new ArgumentNullException("table");
            }
            if (filePath == null)
            {
                throw new ArgumentNullException("filePath");
            }

            // VB or C#?
            bool vb = IsVbFile(filePath);

            Regex regex = new Regex(
                vb ? VbPattern : CsPattern,
                RegexOptions.CultureInvariant | RegexOptions.IgnorePatternWhitespace |
                RegexOptions.Multiline | RegexOptions.IgnoreCase);

            // Try to open and read file.
            string text = File.ReadAllText(filePath);

            Match match = regex.Match(text);

            if (!match.Success)
            {
                throw new InvalidOperationException();
            }

            // Reset all colors to their default values.
            table.InitFromBase(true);

            bool modified = false;

            while (match.Success)
            {
                string property = match.Groups["Property"].Value;
                string name     = match.Groups["Name"].Value;

                Color colour;
                if (!string.IsNullOrEmpty(name))
                {
                    colour = Color.FromName(name);
                }
                else
                {
                    int r = int.Parse(match.Groups["R"].Value);
                    int g = int.Parse(match.Groups["G"].Value);
                    int b = int.Parse(match.Groups["B"].Value);

                    // Alpha chanel is optional.
                    int a;
                    if (!int.TryParse(match.Groups["A"].Value, out a))
                    {
                        a = 255;
                    }

                    colour = Color.FromArgb(a, r, g, b);
                }

                try
                {
                    ColourTableGroup colourGroup = (ColourTableGroup)Enum.Parse(
                        typeof(ColourTableGroup), property);
                    table[colourGroup] = colour;
                    modified           = true;
                }
                catch (ArgumentException)
                {
                }

                match = match.NextMatch();
            }

            if (modified)
            {
                table.MakeColorsDefault();
            }
        }
Beispiel #4
0
 public Color this[ColourTableGroup colourGroup]
 {
     get { return(colours[colourGroup]); }
     set { colours[colourGroup] = value; }
 }