00001 #ifndef GSGL_PLATFORM_COLOR_H
00002 #define GSGL_PLATFORM_COLOR_H
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037 #include "platform/platform.hpp"
00038 #include "data/config.hpp"
00039
00040 namespace gsgl
00041 {
00042
00043 namespace platform
00044 {
00045
00046
00047 class PLATFORM_API color
00048 : public platform_object
00049 {
00050 float val[4];
00051
00052 public:
00053 enum component { COMPONENT_RED = 0, COMPONENT_GREEN = 1, COMPONENT_BLUE = 2, COMPONENT_ALPHA = 3, NUM_COMPONENTS = 4 };
00054
00055 color(float red = 1.0f, float green = 1.0f, float blue = 1.0f, float alpha = 1.0f)
00056 {
00057 val[COMPONENT_RED] = red;
00058 val[COMPONENT_GREEN] = green;
00059 val[COMPONENT_BLUE] = blue;
00060 val[COMPONENT_ALPHA] = alpha;
00061 }
00062
00063 color(const color & c)
00064 {
00065 for (int i = 0; i < NUM_COMPONENTS; ++i)
00066 val[i] = c.val[i];
00067 }
00068
00069 color & operator= (const color & c)
00070 {
00071 for (int i = 0; i < NUM_COMPONENTS; ++i)
00072 val[i] = c.val[i];
00073 return *this;
00074 }
00075
00076
00077 inline const float & get_val(const component c) const { return val[c]; }
00078 inline float & get_val(const component c) { return val[c]; }
00079
00080 inline const float & operator[] (const component c) const { return get_val(c); }
00081 inline float & operator[] (const component c) { return get_val(c); }
00082
00083
00084
00085 void set() const;
00086
00087 const float *get_val() const { return val; }
00088
00089
00090
00091 static const color BLACK;
00092 static const color WHITE;
00093 };
00094
00095
00096 }
00097
00098
00099 namespace data
00100 {
00101
00102 template <>
00103 inline gsgl::string gsgl::data::config_variable<gsgl::platform::color>::get_string() const
00104 {
00105 return gsgl::string::format(L"%f %f %f %f", value.get_val()[0], value.get_val()[1], value.get_val()[2], value.get_val()[3]);
00106 }
00107
00108
00109 template <>
00110 inline void gsgl::data::config_variable<gsgl::platform::color>::assign_from_string(const gsgl::string & s)
00111 {
00112 gsgl::data::list<gsgl::string> numbers = s.split(L" ");
00113 int pos = 0;
00114 for (gsgl::data::list<gsgl::string>::iterator i = numbers.iter(); pos < 4 && i.is_valid(); ++i)
00115 {
00116 if (!i->is_empty())
00117 const_cast<float *>(value.get_val())[pos++] = static_cast<float>(i->to_double());
00118 }
00119 }
00120
00121 }
00122
00123 }
00124
00125 #endif