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 "OSDLMouseCursor.h"
00028
00029 #include "OSDLSurface.h"
00030 #include "OSDLGLTexture.h"
00031 #include "OSDLUtils.h"
00032
00033 #include "Ceylan.h"
00034
00035
00036
00037 using std::string ;
00038
00039 using namespace Ceylan::Log ;
00040
00041 using namespace OSDL::Video ;
00042 using namespace OSDL::Video::TwoDimensional ;
00043
00044
00045 #ifdef OSDL_USES_CONFIG_H
00046 #include "OSDLConfig.h"
00047 #endif // OSDL_USES_CONFIG_H
00048
00049 #if OSDL_ARCH_NINTENDO_DS
00050 #include "OSDLConfigForNintendoDS.h"
00051 #endif // OSDL_ARCH_NINTENDO_DS
00052
00053
00054 #if OSDL_USES_SDL
00055 #include "SDL.h"
00056 #endif // OSDL_USES_SDL
00057
00058
00059
00060
00061 MouseCursorException::MouseCursorException( const std::string & reason ) :
00062 VideoException( reason )
00063 {
00064
00065 }
00066
00067
00068 MouseCursorException::~MouseCursorException() throw()
00069 {
00070
00071 }
00072
00073
00074
00075
00076
00077 MouseCursor::MouseCursor( Length width, Length height,
00078 const Ceylan::Uint8 & data, const Ceylan::Uint8 & mask,
00079 Coordinate hotSpotAbscissa, Coordinate hotSpotOrdinate ) :
00080 _type( SystemCursor ),
00081 _systemCursor(),
00082 _width( width ),
00083 _height( height ),
00084 _surface( 0 ),
00085 _texture( 0 ),
00086 _hotSpotAbscissa( hotSpotAbscissa ),
00087 _hotSpotOrdinate( hotSpotOrdinate )
00088 {
00089
00090 #if OSDL_USES_SDL
00091
00092 _systemCursor = SDL_CreateCursor(
00093 const_cast<Ceylan::Uint8 *>( & data ),
00094 const_cast<Ceylan::Uint8 *>( & mask ),
00095 static_cast<int>( _width ),
00096 static_cast<int>( _height ),
00097 static_cast<int>( _hotSpotAbscissa ),
00098 static_cast<int>( _hotSpotOrdinate ) ) ;
00099
00100 if ( _systemCursor == 0 )
00101 throw MouseCursorException(
00102 "MouseCursor constructor failed for system cursor: "
00103 + Utils::getBackendLastError() ) ;
00104
00105 #else // OSDL_USES_SDL
00106
00107 throw MouseCursorException( "MouseCursor constructor failed: "
00108 "no SDL support available" ) ;
00109
00110 #endif // OSDL_USES_SDL
00111
00112 }
00113
00114
00115
00116 MouseCursor::MouseCursor( const Surface & cursorSurface,
00117 Coordinate hotSpotAbscissa, Coordinate hotSpotOrdinate ) :
00118 _type( BlittedCursor ),
00119 _systemCursor( 0 ),
00120 _width(),
00121 _height(),
00122 _surface( 0 ),
00123 _texture( 0 ),
00124 _hotSpotAbscissa( hotSpotAbscissa ),
00125 _hotSpotOrdinate( hotSpotOrdinate )
00126 {
00127
00128 #if OSDL_USES_SDL
00129
00130
00131 #if 0
00132
00133 if ( Video::IsUsingOpenGL() )
00134 {
00135
00136
00137
00138
00139
00140
00141
00142
00143 _texture = new GLTexture( sourceSurface, None ) ;
00144
00145 }
00146
00147 #endif // 0
00148
00149 #else // OSDL_USES_SDL
00150
00151 throw MouseCursorException( "MouseCursor constructor failed: "
00152 "no SDL support available" ) ;
00153
00154 #endif // OSDL_USES_SDL
00155
00156 }
00157
00158
00159
00160 MouseCursor::~MouseCursor() throw()
00161 {
00162
00163 #if OSDL_USES_SDL
00164
00165 if ( _systemCursor != 0 )
00166 SDL_FreeCursor( _systemCursor ) ;
00167
00168 #endif // OSDL_USES_SDL
00169
00170
00171 if ( _surface != 0 )
00172 delete _surface ;
00173
00174
00175 if ( _texture != 0 )
00176 delete _texture ;
00177
00178 }
00179
00180
00181
00182 MouseCursor::CursorType MouseCursor::getType() const
00183 {
00184
00185 return _type ;
00186
00187 }
00188
00189
00190
00191 const string MouseCursor::toString( Ceylan::VerbosityLevels level) const
00192 {
00193
00194 string res = "MouseCursor corresponding to a " ;
00195
00196 switch( _type )
00197 {
00198
00199 case SystemCursor:
00200 res += "system cursor" ;
00201 break ;
00202
00203 case BlittedCursor:
00204 res += "OSDL-blitted cursor" ;
00205 break ;
00206
00207 case TexturedCursor:
00208 res += "OpenGL-rendered cursor" ;
00209 break ;
00210
00211 default:
00212 res += "unknown cursor (abnormal)" ;
00213 break ;
00214 }
00215
00216
00217 return res ;
00218
00219 }
00220