OSDLGLUprightRectangle.cc

Go to the documentation of this file.
00001 #include "OSDLGLUprightRectangle.h"
00002 
00003 
00004 #ifdef OSDL_USES_CONFIG_H
00005 #include <OSDLConfig.h>     // for OSDL_USES_OPENGL and al 
00006 #endif // OSDL_USES_CONFIG_H
00007 
00008 
00009 #if OSDL_USES_OPENGL
00010 #include "SDL_opengl.h"     // for glRectf
00011 #endif // OSDL_USES_OPENGL
00012 
00013 
00014 
00015 using std::string ;
00016 
00017 using namespace OSDL::Video ;
00018 using namespace OSDL::Video::OpenGL ;
00019 using namespace OSDL::Video::TwoDimensional ;
00020 
00021 
00022 using Ceylan::Maths::Linear::Bipoint ;
00023 
00024 
00025 
00026 UprightRectangleGL::UprightRectangleGL( const Bipoint & upperLeftCorner,
00027         const Bipoint & lowerRightCorner ) throw( VideoException ) :
00028     _x( upperLeftCorner.getX() ),
00029     _y( upperLeftCorner.getY() ),
00030     _width( static_cast<GLLength>( lowerRightCorner.getX() -
00031         upperLeftCorner.getX() ) ),
00032     _height( static_cast<GLLength>( lowerRightCorner.getY() -
00033         upperLeftCorner.getY() ) )
00034 {
00035 
00036 #if OSDL_DEBUG
00037 
00038     if ( lowerRightCorner.getX() < upperLeftCorner.getX() )
00039         throw VideoException( 
00040             "UprightRectangleGL constructor : width is negative ( " 
00041             + Ceylan::toString( 
00042                 lowerRightCorner.getX() - upperLeftCorner.getX() ) 
00043             + " ) " ) ;
00044         
00045         throw VideoException( 
00046             "UprightRectangleGL constructor : height is negative ( " 
00047             + Ceylan::toString( 
00048                 lowerRightCorner.getY() - upperLeftCorner.getY() ) 
00049             + " ) " ) ;
00050         
00051 #endif // OSDL_DEBUG
00052 
00053 }
00054 
00055 
00056 UprightRectangleGL::UprightRectangleGL( const Bipoint & upperLeftCorner,
00057         GLLength width, GLLength height ) throw() :
00058     _x( upperLeftCorner.getX() ),
00059     _y( upperLeftCorner.getY() ),
00060     _width( width ),
00061     _height( height )
00062 {
00063 
00064 }   
00065     
00066             
00067 UprightRectangleGL::UprightRectangleGL( GLCoordinate x, GLCoordinate y,
00068          GLLength width, GLLength height ) throw() :
00069     _x( x ),
00070     _y( y ),
00071     _width( width ),
00072     _height( height )
00073 {
00074 
00075 }
00076 
00077 
00078 UprightRectangleGL::~UprightRectangleGL() throw()
00079 {
00080 
00081 }
00082 
00083 
00084 Bipoint UprightRectangleGL::getUpperLeftCorner() const throw()
00085 {
00086 
00087     return Bipoint( _x, _y ) ;
00088     
00089 }
00090 
00091 
00092 void UprightRectangleGL::setUpperLeftCorner( 
00093     Bipoint & newUpperLeftCorner ) throw()
00094 {
00095 
00096     _x = newUpperLeftCorner.getX() ;
00097     _y = newUpperLeftCorner.getY() ;    
00098     
00099 }
00100 
00101 
00102 GLCoordinate UprightRectangleGL::getUpperLeftAbscissa() const throw()
00103 {
00104 
00105     return _x ;
00106     
00107 }
00108  
00109  
00110 GLCoordinate UprightRectangleGL::getUpperLeftOrdinate() const throw()
00111 {
00112 
00113     return _y ;
00114     
00115 }
00116  
00117  
00118 GLLength UprightRectangleGL::getWidth() const throw()
00119 {
00120     return _width ;
00121 }
00122 
00123 
00124 void UprightRectangleGL::setWidth( GLLength newWidth ) throw()
00125 {
00126 
00127     _width = newWidth ;
00128     
00129 }
00130 
00131 
00132 GLLength UprightRectangleGL::getHeight() const throw()
00133 {
00134 
00135     return _height ;
00136     
00137 }
00138 
00139 
00140 void UprightRectangleGL::setHeight( GLLength newHeight ) throw()
00141 {
00142 
00143     _height = newHeight ;
00144     
00145 }
00146         
00147         
00148 bool UprightRectangleGL::draw() const throw()
00149 {
00150     
00151 #ifdef OSDL_HAVE_OPENGL
00152 
00153     glRectf( _x, _y, _x + _width, _y + _height ) ;
00154     
00155 #else // OSDL_HAVE_OPENGL
00156 
00157     Ceylan::emergencyShutdown( "UprightRectangleGL::draw "
00158         "called whereas no OpenGL support available." ) ;
00159         
00160 #endif //OSDL_HAVE_OPENGL 
00161     
00162     return true ;
00163     
00164 }
00165 
00166 
00167 const string UprightRectangleGL::toString( Ceylan::VerbosityLevels level ) 
00168     const throw()
00169 {
00170 
00171     return "OpenGL rectangle whose upper-left corner is " 
00172         + Bipoint( _x, _y ).toString( level ) 
00173         + " ( width = "  + Ceylan::toString( _width )
00174         + " ; height = " + Ceylan::toString( _height ) + " )" ;
00175         
00176 }
00177     
00178 
00179 
00180 std::ostream & operator << ( std::ostream & os, UprightRectangleGL & rect )
00181     throw()
00182 {
00183 
00184     return os << rect.toString() ;
00185     
00186 }
00187 

Generated on Fri Mar 30 14:46:59 2007 for OSDL by  doxygen 1.5.1