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