PtRect.h

Go to the documentation of this file.
00001 // -*- C++ -*-
00002 /* GG is a GUI for SDL and OpenGL.
00003    Copyright (C) 2003 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@hotmail.com */
00025 
00029 #ifndef _GG_PtRect_h_
00030 #define _GG_PtRect_h_
00031 
00032 #include <GG/Base.h>
00033 
00034 #include <boost/serialization/access.hpp>
00035 #include <boost/serialization/nvp.hpp>
00036 
00037 #include <iosfwd>
00038 
00039 
00040 namespace GG {
00041 
00043 struct GG_API Pt
00044 { 
00046     Pt();                       
00047     Pt(int x_, int y_);         
00048 
00049  
00051 
00053     bool Less(const Pt& rhs) const {return x < rhs.x ? true : (x == rhs.x ? (y < rhs.y ? true : false) : false);}
00055  
00057     void  operator+=(const Pt& rhs)      {x += rhs.x; y += rhs.y;} 
00058     void  operator-=(const Pt& rhs)      {x -= rhs.x; y -= rhs.y;} 
00059     Pt    operator-() const              {return Pt(-x, -y);}      
00060 
00061 
00062     int x; 
00063     int y; 
00064 
00065 private:
00066     friend class boost::serialization::access;
00067     template <class Archive>
00068     void serialize(Archive& ar, const unsigned int version);
00069 };
00070 
00072 struct GG_API Rect
00073 { 
00075     Rect();                                
00076     Rect(const Pt& pt1, const Pt& pt2);    
00077     Rect(int x1, int y1, int x2, int y2);  
00078 
00079  
00081     int   Left() const         {return ul.x;}        
00082     int   Right() const        {return lr.x;}        
00083     int   Top() const          {return ul.y;}        
00084     int   Bottom() const       {return lr.y;}        
00085     Pt    UpperLeft() const    {return ul;}          
00086     Pt    LowerRight() const   {return lr;}          
00087     int   Width() const        {return lr.x - ul.x;} 
00088     int   Height() const       {return lr.y - ul.y;} 
00089 
00090     bool  Contains(const Pt& pt) const; 
00091 
00092  
00094     void operator+=(const Pt& pt)      {ul += pt; lr += pt;} 
00095     void operator-=(const Pt& pt)      {ul -= pt; lr -= pt;} 
00096 
00097 
00098     Pt ul; 
00099     Pt lr; 
00100 
00101 private:
00102     friend class boost::serialization::access;
00103     template <class Archive>
00104     void serialize(Archive& ar, const unsigned int version);
00105 };
00106 
00107 GG_API inline bool operator==(const Pt& lhs, const Pt& rhs) {return lhs.x == rhs.x && lhs.y == rhs.y;} 
00108 GG_API inline bool operator!=(const Pt& lhs, const Pt& rhs) {return !(lhs == rhs);}                    
00109 GG_API inline bool operator<(const Pt& lhs, const Pt& rhs)  {return lhs.x < rhs.x && lhs.y < rhs.y;}   
00110 GG_API inline bool operator>(const Pt& lhs, const Pt& rhs)  {return lhs.x > rhs.x && lhs.y > rhs.y;}   
00111 GG_API inline bool operator<=(const Pt& lhs, const Pt& rhs) {return lhs.x <= rhs.x && lhs.y <= rhs.y;} 
00112 GG_API inline bool operator>=(const Pt& lhs, const Pt& rhs) {return lhs.x >= rhs.x && lhs.y >= rhs.y;} 
00113 GG_API inline Pt   operator+(const Pt& lhs, const Pt& rhs)  {return Pt(lhs.x + rhs.x, lhs.y + rhs.y);} 
00114 GG_API inline Pt   operator-(const Pt& lhs, const Pt& rhs)  {return Pt(lhs.x - rhs.x, lhs.y - rhs.y);} 
00115 
00116 GG_API std::ostream& operator<<(std::ostream& os, const Pt& pt); 
00117 
00119 GG_API inline bool operator==(const Rect& lhs, const Rect& rhs) {return lhs.ul.x == rhs.ul.x && lhs.lr.x == rhs.lr.x && lhs.lr.x == rhs.lr.x && lhs.lr.y == rhs.lr.y;}
00120 
00122 GG_API inline bool operator!=(const Rect& lhs, const Rect& rhs) {return !(lhs == rhs);}
00123 
00124 GG_API inline Rect operator+(const Rect& rect, const Pt& pt) {return Rect(rect.ul + pt, rect.lr + pt);} 
00125 GG_API inline Rect operator-(const Rect& rect, const Pt& pt) {return Rect(rect.ul - pt, rect.lr - pt);} 
00126 GG_API inline Rect operator+(const Pt& pt, const Rect& rect) {return rect + pt;} 
00127 GG_API inline Rect operator-(const Pt& pt, const Rect& rect) {return rect - pt;} 
00128 
00129 GG_API std::ostream& operator<<(std::ostream& os, const Rect& rect); 
00130 
00131 } // namepace GG
00132 
00133 // template implementations
00134 template <class Archive>
00135 void GG::Pt::serialize(Archive& ar, const unsigned int version)
00136 {
00137     ar  & BOOST_SERIALIZATION_NVP(x)
00138         & BOOST_SERIALIZATION_NVP(y);
00139 }
00140 
00141 template <class Archive>
00142 void GG::Rect::serialize(Archive& ar, const unsigned int version)
00143 {
00144     ar  & BOOST_SERIALIZATION_NVP(ul)
00145         & BOOST_SERIALIZATION_NVP(lr);
00146 }
00147 
00148 #endif // _GG_PtRect_h_
00149 

Generated on Wed Mar 26 14:35:42 2008 for GG by  doxygen 1.5.2