00001
00002 #include "vgui_color_text.h"
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
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 vcl_string colors[][2] = {
00021 { "white", "1.000 1.000 1.000" },
00022 { "black", "0.000 0.000 0.000" },
00023 { "blue", "0.000 0.000 1.000" },
00024 { "red", "1.000 0.000 0.000" },
00025 { "green", "0.000 1.000 0.000" },
00026 { "yellow", "1.000 1.000 0.000" },
00027 { "grey", "0.745 0.745 0.745" },
00028 { "orange", "1.000 0.647 0.000" },
00029 { "pink", "1.000 0.752 0.796" },
00030 { "purple", "0.627 0.125 0.941" },
00031 { "cyan", "0.000 1.000 1.000" },
00032 { "brown", "0.647 0.165 0.165" },
00033 { "light blue", "0.678 0.847 0.902" },
00034 { "sky blue", "0.529 0.808 0.922" },
00035 { "dark blue", "0.000 0.000 0.545" },
00036 { "light pink", "1.000 0.714 0.757" },
00037 { "deep pink", "1.000 0.078 0.576" },
00038 { "orange red", "1.000 0.270 0.000" },
00039 { "light green", "0.565 0.933 0.565" },
00040 { "dark green", "0.000 0.392 0.000" },
00041 { "gold", "1.000 0.843 0.000" },
00042 { "tan", "0.824 0.706 0.549" },
00043 { "dim grey", "0.412 0.412 0.412" },
00044 { "dark slate grey","0.184 0.310 0.310" }
00045 };
00046 #define NB_COLORS (sizeof(colors)/sizeof(colors[0]))
00047
00048
00049 vcl_string text_to_color(const vcl_string& txt)
00050 {
00051 vcl_string color = "";
00052 if (txt[0] == '0' || txt[0] == '1')
00053 color = txt;
00054
00055 for (unsigned int i = 0; i < NB_COLORS; i++)
00056 {
00057 if (txt == colors[i][0])
00058 color = colors[i][1];
00059 }
00060
00061 if (color == ""){
00062 vgui_macro_warning << "Unknown color string: " << txt << vcl_endl;
00063 color = colors[1][1];
00064 }
00065
00066 if (debug){
00067 float red, green, blue;
00068 vcl_sscanf(color.c_str(), "%f %f %f", &red, &green, &blue);
00069 vcl_cerr << "vgui_color_text:: color string= " << color << ", red="
00070 << red << ", green=" << green << ", blue=" << blue << vcl_endl;
00071 }
00072
00073 return color;
00074 }
00075
00076 float red_value(const vcl_string& txt)
00077 {
00078 vcl_string nb_txt = text_to_color(txt);
00079 float red, green, blue;
00080 vcl_sscanf(nb_txt.c_str(), "%f %f %f", &red, &green, &blue);
00081 return red;
00082 }
00083
00084 float green_value(const vcl_string& txt)
00085 {
00086 vcl_string nb_txt = text_to_color(txt);
00087 float red, green, blue;
00088 vcl_sscanf(nb_txt.c_str(), "%f %f %f", &red, &green, &blue);
00089 return green;
00090 }
00091
00092 float blue_value(const vcl_string& txt)
00093 {
00094 vcl_string nb_txt = text_to_color(txt);
00095 float red, green, blue;
00096 vcl_sscanf(nb_txt.c_str(), "%f %f %f", &red, &green, &blue);
00097 return blue;
00098 }
00099