/* * Util.ColorFinder.cs * Authors: Adam Nabinger * Copyright (c) 2007-2008 Cornell University This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 2 of the License, or (at your option) any later version. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program; if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ namespace Util { /// /// A static class to facilitate finding the proper names of colors. /// public static class ColorFinder { /// /// Get the name of the specified Color. /// /// A Color. /// The Name of the Color, or 'Unknown Color'. public static string GetString(Microsoft.Xna.Framework.Graphics.Color color) { return GetString(color.A, color.R, color.G, color.B); } /// /// Get the name of the specified Color. /// /// A Color. /// The Name of the Color, or 'Unknown Color'. public static string GetString(System.Drawing.Color color) { return GetString(color.A, color.R, color.G, color.B); } /// /// Search through the list of Known Colors in System.Drawing to see if any match the given parameters. If so, retrun the name of that color. /// /// The value of the alpha parameter /// The value of the red parameter /// The value of the green parameter /// The value of the blue parameter /// The name of the color of the given RGBA values private static string GetString(int A, int R, int G, int B) { string[] names = System.Enum.GetNames(typeof(System.Drawing.KnownColor)); foreach (string name in names) { System.Drawing.KnownColor knownColor = (System.Drawing.KnownColor)System.Enum.Parse(typeof(System.Drawing.KnownColor), name); if (knownColor < System.Drawing.KnownColor.Transparent || knownColor > System.Drawing.KnownColor.YellowGreen) { continue; } System.Drawing.Color test = System.Drawing.Color.FromKnownColor(knownColor); if (test.A == A && test.R == R && test.G == G && test.B == B) { return test.Name; } } return "Unknown Color"; } } }