Clr.h

Go to the documentation of this file.
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 <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 } // namespace GG
00109 
00110 // template implementations
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 

Generated on Sat Mar 26 07:08:37 2011 for GG by  doxygen 1.5.9