GG
|
00001 // -*- C++ -*- 00002 /* GG is a GUI for SDL and OpenGL. 00003 Copyright (C) 2003-2008 T. Zachary Laine 00004 00005 This library is free software; you can redistribute it and/or 00006 modify it under the terms of the GNU Lesser General Public License 00007 as published by the Free Software Foundation; either version 2.1 00008 of the License, or (at your option) any later version. 00009 00010 This library is distributed in the hope that it will be useful, 00011 but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 Lesser General Public License for more details. 00014 00015 You should have received a copy of the GNU Lesser General Public 00016 License along with this library; if not, write to the Free 00017 Software Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 00018 02111-1307 USA 00019 00020 If you do not wish to comply with the terms of the LGPL please 00021 contact the author as other terms are available for a fee. 00022 00023 Zach Laine 00024 whatwasthataddress@gmail.com */ 00025 00029 #ifndef _GG_Clr_h_ 00030 #define _GG_Clr_h_ 00031 00032 #include <GG/Export.h> 00033 00034 #include <boost/serialization/access.hpp> 00035 #include <boost/serialization/nvp.hpp> 00036 00037 00038 namespace GG { 00039 00048 struct GG_API Clr 00049 { 00051 00052 Clr() : 00053 r(0), g(0), b(0), a(0) 00054 {} 00055 00057 Clr(unsigned char r_, 00058 unsigned char g_, 00059 unsigned char b_, 00060 unsigned char a_) : 00061 r(r_), g(g_), b(b_), a(a_) 00062 {} 00064 00065 unsigned char r; 00066 unsigned char g; 00067 unsigned char b; 00068 unsigned char a; 00069 00070 private: 00071 friend class boost::serialization::access; 00072 template <class Archive> 00073 void serialize(Archive& ar, const unsigned int version); 00074 }; 00075 00078 inline Clr FloatClr(float r, float g, float b, float a) 00079 { 00080 return Clr(static_cast<unsigned char>(r * 255), 00081 static_cast<unsigned char>(g * 255), 00082 static_cast<unsigned char>(b * 255), 00083 static_cast<unsigned char>(a * 255)); 00084 } 00085 00087 inline bool operator==(const Clr& rhs, const Clr& lhs) 00088 { return rhs.r == lhs.r && rhs.g == lhs.g && rhs.b == lhs.b && rhs.a == lhs.a; } 00089 00091 inline bool operator!=(const Clr& rhs, const Clr& lhs) 00092 { return !(rhs == lhs); } 00093 00094 } // namespace GG 00095 00096 // template implementations 00097 template <class Archive> 00098 void GG::Clr::serialize(Archive& ar, const unsigned int version) 00099 { 00100 ar & BOOST_SERIALIZATION_NVP(r) 00101 & BOOST_SERIALIZATION_NVP(g) 00102 & BOOST_SERIALIZATION_NVP(b) 00103 & BOOST_SERIALIZATION_NVP(a); 00104 } 00105 00106 #endif // _GG_Clr_h_ 00107