00001 #include "OSDLMouseCursor.h"
00002
00003 #include "OSDLSurface.h"
00004 #include "OSDLGLTexture.h"
00005 #include "OSDLUtils.h"
00006
00007 #include "Ceylan.h"
00008
00009 #include "SDL.h"
00010
00011
00012
00013 using std::string ;
00014
00015 using namespace Ceylan::Log ;
00016
00017 using namespace OSDL::Video ;
00018 using namespace OSDL::Video::TwoDimensional ;
00019
00020
00021
00022 MouseCursorException::MouseCursorException( const std::string & reason )
00023 throw() :
00024 VideoException( reason )
00025 {
00026
00027 }
00028
00029
00030 MouseCursorException::~MouseCursorException() throw()
00031 {
00032
00033 }
00034
00035
00036
00037
00038 MouseCursor::MouseCursor( Length width, Length height,
00039 const Ceylan::Uint8 & data, const Ceylan::Uint8 & mask,
00040 Coordinate hotSpotAbscissa, Coordinate hotSpotOrdinate )
00041 throw( MouseCursorException ) :
00042 _type( SystemCursor ),
00043 _systemCursor(),
00044 _width( width ),
00045 _height( height ),
00046 _surface( 0 ),
00047 _texture( 0 ),
00048 _hotSpotAbscissa( hotSpotAbscissa ),
00049 _hotSpotOrdinate( hotSpotOrdinate )
00050 {
00051
00052 _systemCursor = SDL_CreateCursor(
00053 const_cast<Ceylan::Uint8 *>( & data ),
00054 const_cast<Ceylan::Uint8 *>( & mask ),
00055 static_cast<int>( _width ),
00056 static_cast<int>( _height ),
00057 static_cast<int>( _hotSpotAbscissa ),
00058 static_cast<int>( _hotSpotOrdinate ) ) ;
00059
00060 if ( _systemCursor == 0 )
00061 throw MouseCursorException(
00062 "MouseCursor constructor failed for system cursor : "
00063 + Utils::getBackendLastError() ) ;
00064
00065 }
00066
00067
00068 MouseCursor::MouseCursor( const Surface & cursorSurface,
00069 Coordinate hotSpotAbscissa, Coordinate hotSpotOrdinate )
00070 throw( MouseCursorException ) :
00071 _type( BlittedCursor ),
00072 _systemCursor( 0 ),
00073 _width(),
00074 _height(),
00075 _surface( 0 ),
00076 _texture( 0 ),
00077 _hotSpotAbscissa( hotSpotAbscissa ),
00078 _hotSpotOrdinate( hotSpotOrdinate )
00079 {
00080
00081
00082 #if 0
00083
00084
00085 if ( Video::IsUsingOpenGL() )
00086 {
00087
00088
00089
00090
00091
00092
00093
00094
00095 _texture = new GLTexture( sourceSurface, None ) ;
00096
00097 }
00098
00099 #endif
00100
00101 }
00102
00103
00104 MouseCursor::~MouseCursor() throw()
00105 {
00106
00107 if ( _systemCursor != 0 )
00108 SDL_FreeCursor( _systemCursor ) ;
00109
00110
00111 if ( _surface != 0 )
00112 delete _surface ;
00113
00114
00115 if ( _texture != 0 )
00116 delete _texture ;
00117
00118 }
00119
00120
00121 MouseCursor::CursorType MouseCursor::getType() const throw()
00122 {
00123
00124 return _type ;
00125
00126 }
00127
00128
00129 const string MouseCursor::toString( Ceylan::VerbosityLevels level)
00130 const throw()
00131 {
00132
00133 string res = "MouseCursor corresponding to a " ;
00134
00135 switch( _type )
00136 {
00137
00138 case SystemCursor:
00139 res += "system cursor" ;
00140 break ;
00141
00142 case BlittedCursor:
00143 res += "OSDL-blitted cursor" ;
00144 break ;
00145
00146 case TexturedCursor:
00147 res += "OpenGL-rendered cursor" ;
00148 break ;
00149
00150 default:
00151 res += "unknown cursor (abnormal)" ;
00152 break ;
00153 }
00154
00155
00156 return res ;
00157
00158 }
00159