2013-08-09 23:33:15 +00:00
/* ScummVM - Graphic Adventure Engine
*
* ScummVM is the legal property of its developers , whose names
* are too numerous to list here . Please refer to the COPYRIGHT
* file distributed with this source distribution .
*
* This program is free software ; you can redistribute it and / or
* modify it under the terms of the GNU General Public License
* as published by the Free Software Foundation ; either version 2
* of the License , or ( at your option ) any later version .
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU General Public License for more details .
* You should have received a copy of the GNU General Public License
* along with this program ; if not , write to the Free Software
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
*
*/
# include "common/scummsys.h"
# include "common/system.h"
# include "graphics/pixelformat.h"
2013-08-11 18:42:00 +00:00
# include "graphics/cursorman.h"
2013-08-09 23:33:15 +00:00
# include "zvision/zvision.h"
# include "zvision/cursor_manager.h"
namespace ZVision {
2013-08-11 20:02:38 +00:00
const char * CursorManager : : _cursorNames [ NUM_CURSORS ] = { " active " , " arrow " , " backward " , " downarrow " , " forward " , " handpt " , " handpu " , " hdown " , " hleft " ,
" hright " , " hup " , " idle " , " leftarrow " , " rightarrow " , " suggest_surround " , " suggest_tilt " , " turnaround " , " zuparrow " } ;
2013-08-09 23:33:15 +00:00
2013-08-11 20:02:38 +00:00
const char * CursorManager : : _zgiCursorFileNames [ NUM_CURSORS ] = { " g0gbc011.zcr " , " g0gac001.zcr " , " g0gac021.zcr " , " g0gac031.zcr " , " g0gac041.zcr " , " g0gac051.zcr " , " g0gac061.zcr " , " g0gac071.zcr " , " g0gac081.zcr " ,
" g0gac091.zcr " , " g0gac101.zcr " , " g0gac011.zcr " , " g0gac111.zcr " , " g0gac121.zcr " , " g0gac131.zcr " , " g0gac141.zcr " , " g0gac151.zcr " , " g0gac161.zcr " } ;
2013-08-09 23:33:15 +00:00
2013-08-11 20:02:38 +00:00
const char * CursorManager : : _zNemCursorFileNames [ NUM_CURSORS ] = { " 00act " , " arrow " , " back " , " down " , " forw " , " handpt " , " handpu " , " hdown " , " hleft " ,
" hright " , " hup " , " 00idle " , " left " , " right " , " ssurr " , " stilt " , " turn " , " up " } ;
2013-08-09 23:33:15 +00:00
CursorManager : : CursorManager ( ZVision * engine , const Graphics : : PixelFormat * pixelFormat )
: _engine ( engine ) ,
_pixelFormat ( pixelFormat ) ,
2013-08-11 18:42:00 +00:00
_cursorIsPushed ( false ) {
2013-08-11 20:02:38 +00:00
// WARNING: The index IDLE_CURSOR_INDEX is hardcoded. If you change the order of _cursorNames/_zgiCursorFileNames/_zNemCursorFileNames, you HAVE to change the index accordingly
2013-08-09 23:33:15 +00:00
if ( _engine - > getGameId ( ) = = ZorkNemesis ) {
2013-08-11 20:02:38 +00:00
Common : : String name ( Common : : String : : format ( " %sa.zcr " , _zNemCursorFileNames [ IDLE_CURSOR_INDEX ] ) ) ;
2013-08-09 23:33:15 +00:00
_idleCursor = ZorkCursor ( name ) ;
} else if ( _engine - > getGameId ( ) = = ZorkGrandInquisitor ) {
2013-08-11 20:02:38 +00:00
_idleCursor = ZorkCursor ( _zgiCursorFileNames [ IDLE_CURSOR_INDEX ] ) ;
2013-08-09 23:33:15 +00:00
}
}
void CursorManager : : initialize ( ) {
2013-08-11 20:02:38 +00:00
revertToIdle ( ) ;
2013-08-11 18:42:00 +00:00
CursorMan . showMouse ( true ) ;
2013-08-09 23:33:15 +00:00
}
2013-08-11 18:42:00 +00:00
void CursorManager : : changeCursor ( const Common : : String & cursorName ) {
changeCursor ( cursorName , _cursorIsPushed ) ;
}
void CursorManager : : changeCursor ( const Common : : String & cursorName , bool pushed ) {
2013-08-14 15:17:24 +00:00
if ( _currentCursor . equals ( cursorName ) & & _cursorIsPushed = = pushed )
return ;
2013-08-11 18:42:00 +00:00
if ( _cursorIsPushed ! = pushed )
_cursorIsPushed = pushed ;
2013-08-09 23:33:15 +00:00
if ( cursorName = = " idle " & & ! pushed ) {
revertToIdle ( ) ;
return ;
}
2013-08-11 20:02:38 +00:00
for ( int i = 0 ; i < NUM_CURSORS ; i + + ) {
2013-08-09 23:33:15 +00:00
if ( _engine - > getGameId ( ) = = ZorkNemesis ) {
2013-08-11 18:42:00 +00:00
if ( cursorName . equals ( _cursorNames [ i ] ) ) {
_currentCursor = cursorName ;
2013-08-09 23:33:15 +00:00
// ZNem uses a/b at the end of the file to signify not pushed/pushed respectively
Common : : String pushedFlag = pushed ? " b " : " a " ;
2013-08-09 23:42:27 +00:00
Common : : String name = Common : : String : : format ( " %s%s.zcr " , _zNemCursorFileNames [ i ] , pushedFlag . c_str ( ) ) ;
2013-08-09 23:33:15 +00:00
changeCursor ( ZorkCursor ( name ) ) ;
return ;
}
} else if ( _engine - > getGameId ( ) = = ZorkGrandInquisitor ) {
2013-08-11 18:42:00 +00:00
if ( cursorName . equals ( _cursorNames [ i ] ) ) {
_currentCursor = cursorName ;
2013-08-09 23:33:15 +00:00
if ( ! pushed ) {
changeCursor ( ZorkCursor ( _zgiCursorFileNames [ i ] ) ) ;
} else {
// ZGI flips not pushed/pushed between a/c and b/d
// It flips the 4th character of the name
char buffer [ 25 ] ;
strcpy ( buffer , _zgiCursorFileNames [ i ] ) ;
buffer [ 3 ] + = 2 ;
}
return ;
}
}
}
// If we get here, something went wrong
warning ( " No cursor found for identifier %s " , cursorName . c_str ( ) ) ;
}
void CursorManager : : changeCursor ( const ZorkCursor & cursor ) {
2013-08-11 18:42:00 +00:00
CursorMan . replaceCursor ( cursor . getSurface ( ) , cursor . getWidth ( ) , cursor . getHeight ( ) , cursor . getHotspotX ( ) , cursor . getHotspotY ( ) , cursor . getKeyColor ( ) , false , _pixelFormat ) ;
2013-08-09 23:33:15 +00:00
}
void CursorManager : : cursorDown ( bool pushed ) {
if ( _cursorIsPushed = = pushed )
return ;
_cursorIsPushed = pushed ;
changeCursor ( _currentCursor , pushed ) ;
}
void CursorManager : : revertToIdle ( ) {
_currentCursor = " idle " ;
2013-08-11 18:42:00 +00:00
CursorMan . replaceCursor ( _idleCursor . getSurface ( ) , _idleCursor . getWidth ( ) , _idleCursor . getHeight ( ) , _idleCursor . getHotspotX ( ) , _idleCursor . getHotspotY ( ) , _idleCursor . getKeyColor ( ) , false , _pixelFormat ) ;
2013-08-09 23:33:15 +00:00
}
} // End of namespace ZVision