Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | Directories | File List | Class Members | File Members

vgui_color_text.cxx

Go to the documentation of this file.
00001 // This is core/vgui/vgui_color_text.cxx
00002 #include "vgui_color_text.h"
00003 //:
00004 // \file
00005 // \brief  See vgui_color_text.h for a description of this file.
00006 // \author K.Y.McGaul
00007 // \date   25-FEB-2000
00008 //
00009 // \verbatim
00010 //  Modifications
00011 //   25-FEB-2000 K.Y.McGaul - Initial version.
00012 // \endverbatim
00013 
00014 #include <vcl_cstdio.h>
00015 #include <vcl_iostream.h>
00016 #include <vgui/vgui_macro.h>
00017 
00018 static bool debug = false;
00019 
00020 static float red;
00021 static float green;
00022 static float blue;
00023 
00024 vcl_string colors[][2] = {
00025   { "white",          "1.000 1.000 1.000" },
00026   { "black",          "0.000 0.000 0.000" },
00027   { "blue",           "0.000 0.000 1.000" },
00028   { "red",            "1.000 0.000 0.000" },
00029   { "green",          "0.000 1.000 0.000" },
00030   { "yellow",         "1.000 1.000 0.000" },
00031   { "grey",           "0.745 0.745 0.745" },
00032   { "orange",         "1.000 0.647 0.000" },
00033   { "pink",           "1.000 0.752 0.796" },
00034   { "purple",         "0.627 0.125 0.941" },
00035   { "cyan",           "0.000 1.000 1.000" },
00036   { "brown",          "0.647 0.165 0.165" },
00037   { "light blue",     "0.678 0.847 0.902" },
00038   { "sky blue",       "0.529 0.808 0.922" },
00039   { "dark blue",      "0.000 0.000 0.545" },
00040   { "light pink",     "1.000 0.714 0.757" },
00041   { "deep pink",      "1.000 0.078 0.576" },
00042   { "orange red",     "1.000 0.270 0.000" },
00043   { "light green",    "0.565 0.933 0.565" },
00044   { "dark green",     "0.000 0.392 0.000" },
00045   { "gold",           "1.000 0.843 0.000" },
00046   { "tan",            "0.824 0.706 0.549" },
00047   { "dim grey",       "0.412 0.412 0.412" },
00048   { "dark slate grey","0.184 0.310 0.310" }
00049 };
00050 #define NB_COLORS (sizeof(colors)/sizeof(colors[0]))
00051 
00052 //:
00053 vcl_string text_to_color(vcl_string txt)
00054 {
00055   vcl_string color = "";
00056   if (txt[0] == '0' || txt[0] == '1')
00057     color = txt;
00058 
00059   for (unsigned int i = 0; i < NB_COLORS; i++)
00060   {
00061     if (txt == colors[i][0])
00062       color =  colors[i][1];
00063   }
00064 
00065   if (color == "")
00066     vgui_macro_warning << "Unknown color string: " << txt << vcl_endl;
00067   else
00068     vcl_sscanf(color.c_str(), "%f %f %f", &red, &green, &blue);
00069 
00070   if (debug)
00071     vcl_cerr << "vgui_color_text:: color string= " << color << ", red="
00072              << red << ", green=" << green << ", blue=" << blue << vcl_endl;
00073   return color;
00074 }
00075 
00076 float red_value(vcl_string txt)
00077 {
00078   vcl_string nb_txt = text_to_color(txt);
00079   return red;
00080 }
00081 
00082 float green_value(vcl_string txt)
00083 {
00084   vcl_string nb_txt = text_to_color(txt);
00085   return green;
00086 }
00087 
00088 float blue_value(vcl_string txt)
00089 {
00090   vcl_string nb_txt = text_to_color(txt);
00091   return blue;
00092 }
00093 

Generated on Thu Jan 10 14:42:07 2008 for core/vgui by  doxygen 1.4.4