Main Page   Namespace List   Class Hierarchy   Compound List   File List   Compound Members   File Members  

cliprect.cpp

Go to the documentation of this file.
00001 /*
00002         $Id: cliprect.cpp,v 1.1 2001/03/06 15:09:17 mbn Exp $
00003 
00004         ------------------------------------------------------------------------
00005         ClanLib, the platform independent game SDK.
00006 
00007         This library is distributed under the GNU LIBRARY GENERAL PUBLIC LICENSE
00008         version 2. See COPYING for details.
00009 
00010         For a total list of contributers see CREDITS.
00011 
00012         ------------------------------------------------------------------------
00013 */
00014 
00015 #include "Core/precomp.h"
00016 
00017 #include <API/Display/Display/cliprect.h>
00018 
00019 CL_ClipRect::CL_ClipRect()
00020 {
00021 }
00022 
00023 CL_ClipRect::CL_ClipRect(const CL_ClipRect &rect)
00024 {
00025         m_x1 = rect.m_x1;
00026         m_y1 = rect.m_y1;
00027         m_x2 = rect.m_x2;
00028         m_y2 = rect.m_y2;
00029 }
00030 
00031 CL_ClipRect::CL_ClipRect(int x1, int y1, int x2, int y2)
00032 {
00033         if (x1 <= x2)
00034         {
00035                 m_x1 = x1;
00036                 m_x2 = x2;
00037         }
00038         else
00039         {
00040                 m_x1 = x2;
00041                 m_x2 = x1;
00042         }
00043 
00044         if (y1 <= y2)
00045         {
00046                 m_y1 = y1;
00047                 m_y2 = y2;
00048         }
00049         else
00050         {
00051                 m_y1 = y2;
00052                 m_y2 = y1;
00053         }
00054 }
00055 
00056 bool CL_ClipRect::test_clipped(const CL_ClipRect &rect) const
00057 {
00058         if (m_x1 > rect.m_x1) return true;
00059         if (m_x2 < rect.m_x2) return true;
00060         if (m_y1 > rect.m_y1) return true;
00061         if (m_y2 < rect.m_y2) return true;
00062 
00063         return false;
00064 }
00065 
00066 bool CL_ClipRect::test_unclipped(const CL_ClipRect &rect) const
00067 {
00068         return m_x1 <= rect.m_x1 &&
00069                m_y1 <= rect.m_y1 &&
00070                m_x2 >= rect.m_x2 &&
00071                m_y2 >= rect.m_y2;
00072 }
00073 
00074 bool CL_ClipRect::test_all_clipped(const CL_ClipRect &rect) const
00075 {
00076         CL_ClipRect clipped_rect = clip(rect);
00077 
00078         return (clipped_rect.m_x1 > clipped_rect.m_x2) ||
00079                (clipped_rect.m_y1 > clipped_rect.m_y2);
00080 }
00081 
00082 CL_ClipRect CL_ClipRect::clip(const CL_ClipRect &rect) const
00083 {
00084         CL_ClipRect res;
00085 
00086         if (m_x1 > rect.m_x1) res.m_x1 = m_x1; else res.m_x1 = rect.m_x1;
00087         if (m_x2 < rect.m_x2) res.m_x2 = m_x2; else res.m_x2 = rect.m_x2;
00088         if (m_y1 > rect.m_y1) res.m_y1 = m_y1; else res.m_y1 = rect.m_y1;
00089         if (m_y2 < rect.m_y2) res.m_y2 = m_y2; else res.m_y2 = rect.m_y2;
00090         
00091         return res;
00092 }
00093 
00094 bool CL_ClipRect::operator ==(const CL_ClipRect &rect) const
00095 {
00096         return m_x1 == rect.m_x1 &&
00097                m_y1 == rect.m_y1 &&
00098                m_x2 == rect.m_x2 &&
00099                m_y2 == rect.m_y2;
00100 }
00101 
00102 /*std::ostream& operator << (std::ostream &os, CL_ClipRect &rect)
00103 {
00104         os << "(" << rect.m_x1 << ", " << rect.m_y1 << ")-(" << rect.m_x2 << ", " << rect.m_y2 << ")";
00105 
00106         return os;
00107 }
00108 */

Generated at Wed Apr 4 19:53:59 2001 for ClanLib by doxygen1.2.6 written by Dimitri van Heesch, © 1997-2001