Clr.h
Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00029 #ifndef _GG_Clr_h_
00030 #define _GG_Clr_h_
00031
00032 #include <boost/serialization/access.hpp>
00033 #include <boost/serialization/nvp.hpp>
00034
00035 #ifndef GG_API
00036 # ifdef _MSC_VER
00037 # define WIN32_LEAN_AND_MEAN
00038 # include <windows.h>
00039 # undef min
00040 # undef max
00041 # ifdef GiGi_EXPORTS
00042 # define GG_API __declspec(dllexport)
00043 # else
00044 # define GG_API __declspec(dllimport)
00045 # endif
00046 # else
00047 # define GG_API
00048 # endif
00049 #endif
00050
00051
00052 namespace GG {
00053
00062 struct GG_API Clr
00063 {
00065
00066 Clr() :
00067 r(0), g(0), b(0), a(0)
00068 {}
00069
00071 Clr(unsigned char r_,
00072 unsigned char g_,
00073 unsigned char b_,
00074 unsigned char a_) :
00075 r(r_), g(g_), b(b_), a(a_)
00076 {}
00078
00079 unsigned char r;
00080 unsigned char g;
00081 unsigned char b;
00082 unsigned char a;
00083
00084 private:
00085 friend class boost::serialization::access;
00086 template <class Archive>
00087 void serialize(Archive& ar, const unsigned int version);
00088 };
00089
00092 inline Clr FloatClr(float r, float g, float b, float a)
00093 {
00094 return Clr(static_cast<unsigned char>(r * 255),
00095 static_cast<unsigned char>(g * 255),
00096 static_cast<unsigned char>(b * 255),
00097 static_cast<unsigned char>(a * 255));
00098 }
00099
00101 inline bool operator==(const Clr& rhs, const Clr& lhs)
00102 { return rhs.r == lhs.r && rhs.g == lhs.g && rhs.b == lhs.b && rhs.a == lhs.a; }
00103
00105 inline bool operator!=(const Clr& rhs, const Clr& lhs)
00106 { return !(rhs == lhs); }
00107
00108 }
00109
00110
00111 template <class Archive>
00112 void GG::Clr::serialize(Archive& ar, const unsigned int version)
00113 {
00114 ar & BOOST_SERIALIZATION_NVP(r)
00115 & BOOST_SERIALIZATION_NVP(g)
00116 & BOOST_SERIALIZATION_NVP(b)
00117 & BOOST_SERIALIZATION_NVP(a);
00118 }
00119
00120 #endif // _GG_Clr_h_
00121