2009-10-03 20:49:18 +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 .
*
* $ URL $
* $ Id $
*
*/
2009-10-06 16:14:40 +00:00
# include "common/timer.h"
2009-10-03 20:49:18 +00:00
# include "common/util.h"
# include "sci/sci.h"
2009-10-06 17:45:57 +00:00
# include "sci/debug.h" // for g_debug_sleeptime_factor
2009-10-03 20:49:18 +00:00
# include "sci/engine/state.h"
# include "sci/tools.h"
2009-10-04 22:43:30 +00:00
# include "sci/gui/gui.h"
2009-10-03 20:49:18 +00:00
# include "sci/gui/gui_screen.h"
2009-10-06 16:14:40 +00:00
# include "sci/gui/gui_palette.h"
2009-10-07 12:47:53 +00:00
# include "sci/gui/gui_cursor.h"
2009-10-03 20:49:18 +00:00
# include "sci/gui/gui_gfx.h"
# include "sci/gui/gui_windowmgr.h"
2009-10-13 15:28:27 +00:00
# include "sci/gui/gui_animate.h"
2009-10-13 21:18:47 +00:00
# include "sci/gui/gui_transitions.h"
2009-10-03 20:49:18 +00:00
# include "sci/gui/gui_view.h"
# include "sci/gfx/operations.h"
namespace Sci {
2009-10-09 19:19:34 +00:00
// for debug purposes
// class SciGui32 : public SciGui {
// public:
// SciGui32(EngineState *s, SciGuiScreen *screen, SciGuiPalette *palette, SciGuiCursor *cursor);
// ~SciGui32();
// };
2009-10-07 12:47:53 +00:00
SciGui : : SciGui ( EngineState * state , SciGuiScreen * screen , SciGuiPalette * palette , SciGuiCursor * cursor )
: _s ( state ) , _screen ( screen ) , _palette ( palette ) , _cursor ( cursor ) {
2009-10-06 16:14:40 +00:00
2009-10-06 17:18:44 +00:00
_gfx = new SciGuiGfx ( _s , _screen , _palette ) ;
2009-10-14 12:47:51 +00:00
_transitions = new SciGuiTransitions ( this , _screen , _palette , _s - > resMan - > isVGA ( ) ) ;
2009-10-13 15:28:27 +00:00
_animate = new SciGuiAnimate ( _s , _gfx , _screen , _palette ) ;
_windowMgr = new SciGuiWindowMgr ( _screen , _gfx , _animate ) ;
2009-10-13 17:17:40 +00:00
// _gui32 = new SciGui32(_s, _screen, _palette, _cursor); // for debug purposes
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
SciGui : : SciGui ( ) {
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
SciGui : : ~ SciGui ( ) {
2009-10-06 16:14:40 +00:00
}
2009-10-11 16:47:01 +00:00
void SciGui : : resetEngineState ( EngineState * s ) {
_s = s ;
_gfx - > resetEngineState ( s ) ;
2009-10-13 15:47:05 +00:00
_animate - > resetEngineState ( s ) ;
2009-10-11 16:47:01 +00:00
}
2009-10-06 16:14:40 +00:00
void SciGui : : init ( bool usesOldGfxFunctions ) {
2009-10-13 16:18:17 +00:00
_usesOldGfxFunctions = usesOldGfxFunctions ;
initPriorityBands ( ) ;
}
void SciGui : : initPriorityBands ( ) {
if ( _usesOldGfxFunctions ) {
2009-10-09 19:50:20 +00:00
_gfx - > PriorityBandsInit ( 15 , 42 , 200 ) ;
} else {
_gfx - > PriorityBandsInit ( 14 , 42 , 190 ) ;
}
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : wait ( int16 ticks ) {
2009-10-06 17:45:57 +00:00
uint32 time ;
time = g_system - > getMillis ( ) ;
_s - > r_acc = make_reg ( 0 , ( ( long ) time - ( long ) _s - > last_wait_time ) * 60 / 1000 ) ;
_s - > last_wait_time = time ;
ticks * = g_debug_sleeptime_factor ;
gfxop_sleep ( _s - > gfx_state , ticks * 1000 / 60 ) ;
// Reset speed throttler: Game is playing along nicely anyway
if ( ticks > 0 )
_s - > speedThrottler - > reset ( ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : setPort ( uint16 portPtr ) {
2009-10-03 20:49:18 +00:00
switch ( portPtr ) {
2009-10-04 21:27:24 +00:00
case 0 :
_gfx - > SetPort ( _windowMgr - > _wmgrPort ) ;
break ;
case 0xFFFF :
_gfx - > SetPort ( _gfx - > _menuPort ) ;
break ;
default :
_gfx - > SetPort ( _windowMgr - > getPortById ( portPtr ) ) ;
2009-10-03 20:49:18 +00:00
} ;
}
2009-10-13 16:18:17 +00:00
void SciGui : : setPortPic ( Common : : Rect rect , int16 picTop , int16 picLeft , bool initPriorityBandsFlag ) {
2009-10-03 20:49:18 +00:00
_windowMgr - > _picWind - > rect = rect ;
_windowMgr - > _picWind - > top = picTop ;
_windowMgr - > _picWind - > left = picLeft ;
2009-10-13 16:18:17 +00:00
if ( initPriorityBandsFlag )
initPriorityBands ( ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
reg_t SciGui : : getPort ( ) {
2009-10-04 21:27:24 +00:00
return make_reg ( 0 , _gfx - > GetPort ( ) - > id ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : globalToLocal ( int16 * x , int16 * y ) {
GuiPort * curPort = _gfx - > GetPort ( ) ;
2009-10-03 20:49:18 +00:00
* x = * x - curPort - > left ;
* y = * y - curPort - > top ;
}
2009-10-05 07:10:01 +00:00
void SciGui : : localToGlobal ( int16 * x , int16 * y ) {
GuiPort * curPort = _gfx - > GetPort ( ) ;
2009-10-03 20:49:18 +00:00
* x = * x + curPort - > left ;
* y = * y + curPort - > top ;
}
2009-10-09 13:15:37 +00:00
int16 SciGui : : coordinateToPriority ( int16 y ) {
return _gfx - > CoordinateToPriority ( y ) ;
}
int16 SciGui : : priorityToCoordinate ( int16 priority ) {
return _gfx - > PriorityToCoordinate ( priority ) ;
}
2009-10-05 07:10:01 +00:00
reg_t SciGui : : newWindow ( Common : : Rect dims , Common : : Rect restoreRect , uint16 style , int16 priority , int16 colorPen , int16 colorBack , const char * title ) {
GuiWindow * wnd = NULL ;
2009-10-03 20:49:18 +00:00
2009-10-04 15:44:10 +00:00
if ( restoreRect . top ! = 0 & & restoreRect . left ! = 0 & & restoreRect . height ( ) ! = 0 & & restoreRect . width ( ) ! = 0 )
2009-10-05 09:23:59 +00:00
wnd = _windowMgr - > NewWindow ( dims , & restoreRect , title , style , priority , false ) ;
2009-10-03 20:49:18 +00:00
else
2009-10-05 09:23:59 +00:00
wnd = _windowMgr - > NewWindow ( dims , NULL , title , style , priority , false ) ;
2009-10-03 20:49:18 +00:00
wnd - > penClr = colorPen ;
wnd - > backClr = colorBack ;
_windowMgr - > DrawWindow ( wnd ) ;
2009-10-04 21:27:24 +00:00
return make_reg ( 0 , wnd - > id ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : disposeWindow ( uint16 windowPtr , int16 arg2 ) {
GuiWindow * wnd = ( GuiWindow * ) _windowMgr - > getPortById ( windowPtr ) ;
2009-10-03 20:49:18 +00:00
_windowMgr - > DisposeWindow ( wnd , arg2 ) ;
}
2009-10-11 09:31:48 +00:00
# define SCI_DISPLAY_MOVEPEN 100
# define SCI_DISPLAY_SETALIGNMENT 101
# define SCI_DISPLAY_SETPENCOLOR 102
# define SCI_DISPLAY_SETBACKGROUNDCOLOR 103
# define SCI_DISPLAY_SETTEXTFACE 104
# define SCI_DISPLAY_SETFONT 105
# define SCI_DISPLAY_WIDTH 106
# define SCI_DISPLAY_SAVEUNDER 107
# define SCI_DISPLAY_RESTOREUNDER 108
# define SCI_DISPLAY_DONTSHOWBITS 121
2009-10-05 07:10:01 +00:00
void SciGui : : display ( const char * text , int argc , reg_t * argv ) {
2009-10-03 20:49:18 +00:00
int displayArg ;
int16 align = 0 ;
2009-10-03 21:30:36 +00:00
int16 bgcolor = - 1 , width = - 1 , bRedraw = 1 ;
2009-10-11 09:31:48 +00:00
bool doSaveUnder = false ;
2009-10-05 07:10:01 +00:00
Common : : Rect rect , * orect = & ( ( GuiWindow * ) _gfx - > GetPort ( ) ) - > dims ;
2009-10-03 20:49:18 +00:00
2009-10-04 21:27:24 +00:00
// Make a "backup" of the port settings
2009-10-05 07:10:01 +00:00
GuiPort oldPort = * _gfx - > GetPort ( ) ;
2009-10-04 21:27:24 +00:00
2009-10-03 20:49:18 +00:00
// setting defaults
_gfx - > PenMode ( 0 ) ;
_gfx - > PenColor ( 0 ) ;
_gfx - > TextFace ( 0 ) ;
// processing codes in argv
while ( argc > 0 ) {
displayArg = argv [ 0 ] . toUint16 ( ) ;
argc - - ; argv + + ;
2009-10-11 09:31:48 +00:00
switch ( displayArg ) {
case SCI_DISPLAY_MOVEPEN :
2009-10-03 20:49:18 +00:00
_gfx - > MoveTo ( argv [ 0 ] . toUint16 ( ) , argv [ 1 ] . toUint16 ( ) ) ;
argc - = 2 ; argv + = 2 ;
2009-10-11 09:31:48 +00:00
break ;
case SCI_DISPLAY_SETALIGNMENT :
2009-10-03 20:49:18 +00:00
align = argv [ 0 ] . toUint16 ( ) ;
argc - - ; argv + + ;
2009-10-11 09:31:48 +00:00
break ;
case SCI_DISPLAY_SETPENCOLOR :
2009-10-03 20:49:18 +00:00
_gfx - > PenColor ( argv [ 0 ] . toUint16 ( ) ) ;
argc - - ; argv + + ;
2009-10-11 09:31:48 +00:00
break ;
case SCI_DISPLAY_SETBACKGROUNDCOLOR :
2009-10-03 20:49:18 +00:00
bgcolor = argv [ 0 ] . toUint16 ( ) ;
argc - - ; argv + + ;
break ;
2009-10-11 09:31:48 +00:00
case SCI_DISPLAY_SETTEXTFACE :
2009-10-03 20:49:18 +00:00
_gfx - > TextFace ( argv [ 0 ] . toUint16 ( ) ) ;
argc - - ; argv + + ;
2009-10-11 09:31:48 +00:00
break ;
case SCI_DISPLAY_SETFONT :
2009-10-03 20:49:18 +00:00
_gfx - > SetFont ( argv [ 0 ] . toUint16 ( ) ) ;
argc - - ; argv + + ;
2009-10-11 09:31:48 +00:00
break ;
case SCI_DISPLAY_WIDTH :
2009-10-03 20:49:18 +00:00
width = argv [ 0 ] . toUint16 ( ) ;
argc - - ; argv + + ;
break ;
2009-10-11 09:31:48 +00:00
case SCI_DISPLAY_SAVEUNDER :
doSaveUnder = true ;
2009-10-03 20:49:18 +00:00
break ;
2009-10-11 09:31:48 +00:00
case SCI_DISPLAY_RESTOREUNDER :
// TODO: get rect from SciMemoryHandle (argv[0])
//rect.translate(-_gfx->GetPort()->left, -_gfx->GetPort()->top);
2009-10-11 09:47:12 +00:00
_gfx - > BitsRestore ( argv [ 0 ] ) ;
2009-10-11 09:31:48 +00:00
// TODO: ReAnimate(pArgs)
2009-10-03 20:49:18 +00:00
// finishing loop
argc = 0 ;
break ;
2009-10-11 09:31:48 +00:00
case SCI_DISPLAY_DONTSHOWBITS :
2009-10-03 20:49:18 +00:00
bRedraw = 0 ;
break ;
default :
warning ( " Unknown kDisplay argument %X " , displayArg ) ;
break ;
}
}
2009-10-05 20:46:19 +00:00
2009-10-03 20:49:18 +00:00
// now drawing the text
_gfx - > TextSize ( rect , text , - 1 , width ) ;
2009-10-10 18:18:12 +00:00
_gfx - > Move ( ( orect - > left < = _screen - > _width ? 0 : _screen - > _width - orect - > left ) , ( orect - > top < = _screen - > _height ? 0 : _screen - > _height - orect - > top ) ) ; // move port to (0,0)
2009-10-03 20:49:18 +00:00
rect . moveTo ( _gfx - > GetPort ( ) - > curLeft , _gfx - > GetPort ( ) - > curTop ) ;
2009-10-11 09:31:48 +00:00
if ( doSaveUnder )
2009-10-11 09:47:12 +00:00
_s - > r_acc = _gfx - > BitsSave ( rect , SCI_SCREEN_MASK_VISUAL ) ;
2009-10-03 20:49:18 +00:00
if ( bgcolor ! = - 1 )
2009-10-11 09:31:48 +00:00
_gfx - > FillRect ( rect , SCI_SCREEN_MASK_VISUAL , bgcolor , 0 , 0 ) ;
2009-10-03 21:30:36 +00:00
_gfx - > TextBox ( text , 0 , rect , align , - 1 ) ;
2009-10-14 12:39:39 +00:00
if ( _screen - > _picNotValid = = 0 & & bRedraw )
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-03 20:49:18 +00:00
// restoring port and cursor pos
2009-10-05 07:10:01 +00:00
GuiPort * currport = _gfx - > GetPort ( ) ;
2009-10-03 20:49:18 +00:00
uint16 tTop = currport - > curTop ;
uint16 tLeft = currport - > curLeft ;
2009-10-04 21:27:24 +00:00
* currport = oldPort ;
2009-10-03 20:49:18 +00:00
currport - > curTop = tTop ;
currport - > curLeft = tLeft ;
}
2009-10-05 07:10:01 +00:00
void SciGui : : textSize ( const char * text , int16 font , int16 maxWidth , int16 * textWidth , int16 * textHeight ) {
2009-10-03 20:49:18 +00:00
Common : : Rect rect ( 0 , 0 , * textWidth , * textHeight ) ;
_gfx - > TextSize ( rect , text , font , maxWidth ) ;
* textWidth = rect . width ( ) ; * textHeight = rect . height ( ) ;
}
// Used SCI1+ for text codes
2009-10-05 07:10:01 +00:00
void SciGui : : textFonts ( int argc , reg_t * argv ) {
2009-10-04 05:22:49 +00:00
_gfx - > SetTextFonts ( argc , argv ) ;
2009-10-03 20:49:18 +00:00
}
// Used SCI1+ for text codes
2009-10-05 07:10:01 +00:00
void SciGui : : textColors ( int argc , reg_t * argv ) {
2009-10-04 05:22:49 +00:00
_gfx - > SetTextColors ( argc , argv ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 19:20:52 +00:00
void SciGui : : drawStatus ( const char * text , int16 colorPen , int16 colorBack ) {
GuiPort * oldPort = _gfx - > SetPort ( _gfx - > _menuPort ) ;
2009-10-05 20:46:19 +00:00
2009-10-05 19:46:38 +00:00
_gfx - > FillRect ( _gfx - > _menuRect , 1 , colorBack ) ;
_gfx - > PenColor ( colorPen ) ;
_gfx - > MoveTo ( 0 , 1 ) ;
_gfx - > Draw_String ( text ) ;
_gfx - > SetPort ( oldPort ) ;
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( _gfx - > _menuRect ) ;
2009-10-05 19:20:52 +00:00
}
2009-10-09 17:47:33 +00:00
void SciGui : : drawMenuBar ( ) {
// TODO: Implement menubar
}
void SciGui : : clearMenuBar ( ) {
// TODO: Implement menubar
}
2009-10-07 20:58:33 +00:00
void SciGui : : drawPicture ( GuiResourceId pictureId , int16 animationNr , bool mirroredFlag , bool addToFlag , int16 EGApaletteNo ) {
2009-10-05 07:10:01 +00:00
GuiPort * oldPort = _gfx - > SetPort ( ( GuiPort * ) _windowMgr - > _picWind ) ;
2009-10-03 20:49:18 +00:00
if ( _windowMgr - > isFrontWindow ( _windowMgr - > _picWind ) ) {
2009-10-14 12:39:39 +00:00
_screen - > _picNotValid = 1 ;
2009-10-07 20:58:33 +00:00
_gfx - > drawPicture ( pictureId , animationNr , mirroredFlag , addToFlag , EGApaletteNo ) ;
2009-10-13 21:18:47 +00:00
_transitions - > setup ( animationNr ) ;
2009-10-03 20:49:18 +00:00
} else {
_windowMgr - > BeginUpdate ( _windowMgr - > _picWind ) ;
2009-10-07 20:58:33 +00:00
_gfx - > drawPicture ( pictureId , animationNr , mirroredFlag , addToFlag , EGApaletteNo ) ;
2009-10-03 20:49:18 +00:00
_windowMgr - > EndUpdate ( _windowMgr - > _picWind ) ;
}
_gfx - > SetPort ( oldPort ) ;
}
2009-10-05 07:10:01 +00:00
void SciGui : : drawCel ( GuiResourceId viewId , GuiViewLoopNo loopNo , GuiViewCelNo celNo , uint16 leftPos , uint16 topPos , int16 priority , uint16 paletteNo ) {
_gfx - > drawCel ( viewId , loopNo , celNo , leftPos , topPos , priority , paletteNo ) ;
2009-10-06 16:14:40 +00:00
_palette - > setOnScreen ( ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-06 16:36:28 +00:00
void SciGui : : drawControlButton ( Common : : Rect rect , reg_t obj , const char * text , int16 fontId , int16 style , bool hilite ) {
if ( ! hilite ) {
2009-10-03 20:49:18 +00:00
rect . grow ( 1 ) ;
2009-10-06 16:36:28 +00:00
_gfx - > EraseRect ( rect ) ;
2009-10-03 20:49:18 +00:00
_gfx - > FrameRect ( rect ) ;
2009-10-06 16:36:28 +00:00
rect . grow ( - 2 ) ;
_gfx - > TextFace ( style & 1 ? 0 : 1 ) ;
_gfx - > TextBox ( text , 0 , rect , 1 , fontId ) ;
_gfx - > TextFace ( 0 ) ;
2009-10-12 07:11:22 +00:00
rect . grow ( 1 ) ;
if ( style & 8 ) // selected
2009-10-06 16:36:28 +00:00
_gfx - > FrameRect ( rect ) ;
2009-10-14 12:39:39 +00:00
if ( _screen - > _picNotValid = = 0 ) {
2009-10-12 07:11:22 +00:00
rect . grow ( 1 ) ;
_gfx - > BitsShow ( rect ) ;
2009-10-06 16:36:28 +00:00
}
} else {
_gfx - > InvertRect ( rect ) ;
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-03 20:49:18 +00:00
}
}
2009-10-06 16:36:28 +00:00
void SciGui : : drawControlText ( Common : : Rect rect , reg_t obj , const char * text , int16 fontId , int16 mode , int16 style , bool hilite ) {
if ( ! hilite ) {
rect . grow ( 1 ) ;
_gfx - > EraseRect ( rect ) ;
rect . grow ( - 1 ) ;
_gfx - > TextBox ( text , 0 , rect , mode , fontId ) ;
if ( style & 8 ) { // selected
_gfx - > FrameRect ( rect ) ;
}
2009-10-12 07:11:22 +00:00
rect . grow ( 1 ) ;
2009-10-14 12:39:39 +00:00
if ( _screen - > _picNotValid = = 0 )
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-06 16:36:28 +00:00
} else {
_gfx - > InvertRect ( rect ) ;
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-03 20:49:18 +00:00
}
}
2009-10-11 14:28:20 +00:00
void SciGui : : drawControlTextEdit ( Common : : Rect rect , reg_t obj , const char * text , int16 fontId , int16 mode , int16 style , int16 cursorPos , int16 maxChars , bool hilite ) {
2009-10-11 20:46:04 +00:00
Common : : Rect textRect = rect ;
uint16 oldFontId = _gfx - > GetFontId ( ) ;
textRect . translate ( 0 , 1 ) ;
rect . grow ( 1 ) ;
_gfx - > TexteditCursorErase ( ) ;
_gfx - > EraseRect ( rect ) ;
_gfx - > TextBox ( text , 0 , textRect , 0 , fontId ) ;
_gfx - > FrameRect ( rect ) ;
if ( style & 8 ) {
_gfx - > SetFont ( fontId ) ;
rect . grow ( - 1 ) ;
_gfx - > TexteditCursorDraw ( rect , text , cursorPos ) ;
_gfx - > SetFont ( oldFontId ) ;
2009-10-12 07:11:22 +00:00
rect . grow ( 1 ) ;
2009-10-11 20:46:04 +00:00
}
2009-10-14 12:39:39 +00:00
if ( _screen - > _picNotValid = = 0 )
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-11 14:28:20 +00:00
}
2009-10-06 16:36:28 +00:00
void SciGui : : drawControlIcon ( Common : : Rect rect , reg_t obj , GuiResourceId viewId , GuiViewLoopNo loopNo , GuiViewCelNo celNo , int16 style , bool hilite ) {
if ( ! hilite ) {
_gfx - > drawCel ( viewId , loopNo , celNo , rect . left , rect . top , 255 , 0 ) ;
if ( style & 0x20 ) {
_gfx - > FrameRect ( rect ) ;
}
2009-10-14 12:39:39 +00:00
if ( _screen - > _picNotValid = = 0 )
2009-10-12 10:34:31 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-06 16:36:28 +00:00
} else {
_gfx - > InvertRect ( rect ) ;
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-05 11:42:04 +00:00
}
}
2009-10-11 15:41:52 +00:00
void SciGui : : drawControlList ( Common : : Rect rect , reg_t obj , int16 maxChars , int16 count , const char * * entries , GuiResourceId fontId , int16 style , int16 upperPos , int16 cursorPos , bool isAlias , bool hilite ) {
if ( ! hilite ) {
rect . grow ( 1 ) ;
_gfx - > drawListControl ( rect , obj , maxChars , count , entries , fontId , upperPos , cursorPos , isAlias ) ;
if ( isAlias & & ( style & 8 ) ) {
_gfx - > FrameRect ( rect ) ;
}
2009-10-14 12:39:39 +00:00
if ( _screen - > _picNotValid = = 0 )
2009-10-12 07:11:22 +00:00
_gfx - > BitsShow ( rect ) ;
2009-10-11 15:41:52 +00:00
}
2009-10-11 12:45:40 +00:00
}
2009-10-11 12:15:17 +00:00
void SciGui : : editControl ( reg_t controlObject , reg_t eventObject ) {
2009-10-11 20:46:04 +00:00
SegManager * segMan = _s - > _segMan ;
int16 controlType = GET_SEL32V ( controlObject , type ) ;
2009-10-13 19:08:40 +00:00
switch ( controlType ) {
case SCI_CONTROLS_TYPE_TEXTEDIT :
2009-10-11 20:46:04 +00:00
// Only process textedit controls in here
_gfx - > TexteditChange ( controlObject , eventObject ) ;
2009-10-13 19:08:40 +00:00
return ;
2009-10-11 20:46:04 +00:00
}
2009-10-11 12:15:17 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : graphFillBoxForeground ( Common : : Rect rect ) {
2009-10-03 20:49:18 +00:00
_gfx - > PaintRect ( rect ) ;
}
2009-10-05 07:10:01 +00:00
void SciGui : : graphFillBoxBackground ( Common : : Rect rect ) {
2009-10-03 20:49:18 +00:00
_gfx - > EraseRect ( rect ) ;
}
2009-10-05 07:10:01 +00:00
void SciGui : : graphFillBox ( Common : : Rect rect , uint16 colorMask , int16 color , int16 priority , int16 control ) {
2009-10-03 20:49:18 +00:00
_gfx - > FillRect ( rect , colorMask , color , priority , control ) ;
}
2009-10-05 13:33:26 +00:00
void SciGui : : graphDrawLine ( Common : : Point startPoint , Common : : Point endPoint , int16 color , int16 priority , int16 control ) {
2009-10-12 08:25:38 +00:00
_gfx - > OffsetLine ( startPoint , endPoint ) ;
_screen - > drawLine ( startPoint . x , startPoint . y , endPoint . x , endPoint . y , color , priority , control ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
reg_t SciGui : : graphSaveBox ( Common : : Rect rect , uint16 flags ) {
2009-10-11 09:47:12 +00:00
return _gfx - > BitsSave ( rect , flags ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : graphRestoreBox ( reg_t handle ) {
2009-10-11 09:47:12 +00:00
_gfx - > BitsRestore ( handle ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-12 07:11:22 +00:00
void SciGui : : graphUpdateBox ( Common : : Rect rect ) {
_gfx - > BitsShow ( rect ) ;
}
2009-10-12 11:36:42 +00:00
void SciGui : : graphRedrawBox ( Common : : Rect rect ) {
2009-10-13 15:28:27 +00:00
_animate - > reAnimate ( rect ) ;
2009-10-12 11:36:42 +00:00
}
2009-10-12 07:30:55 +00:00
int16 SciGui : : picNotValid ( int16 newPicNotValid ) {
int16 oldPicNotValid = _screen - > _picNotValid ;
if ( newPicNotValid ! = - 1 )
_screen - > _picNotValid = newPicNotValid ;
return oldPicNotValid ;
}
2009-10-12 07:11:22 +00:00
2009-10-05 07:10:01 +00:00
void SciGui : : paletteSet ( int resourceNo , int flags ) {
2009-10-06 16:14:40 +00:00
_palette - > setFromResource ( resourceNo , flags ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
int16 SciGui : : paletteFind ( int r , int g , int b ) {
2009-10-06 16:14:40 +00:00
return _palette - > matchColor ( & _palette - > _sysPalette , r , g , b ) & 0xFF ;
2009-10-03 20:49:18 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : paletteSetIntensity ( int fromColor , int toColor , int intensity , bool setPalette ) {
2009-10-06 16:14:40 +00:00
_palette - > setIntensity ( fromColor , toColor , intensity , & _palette - > _sysPalette ) ;
2009-10-04 19:49:47 +00:00
if ( setPalette ) {
2009-10-06 16:14:40 +00:00
_palette - > setOnScreen ( ) ;
2009-10-04 19:49:47 +00:00
}
}
2009-10-05 07:10:01 +00:00
void SciGui : : paletteAnimate ( int fromColor , int toColor , int speed ) {
2009-10-06 16:14:40 +00:00
_palette - > animate ( fromColor , toColor , speed ) ;
2009-10-03 20:49:18 +00:00
}
2009-10-11 08:52:23 +00:00
void SciGui : : shakeScreen ( uint16 shakeCount , uint16 directions ) {
while ( shakeCount - - ) {
if ( directions & SCI_SHAKE_DIRECTION_VERTICAL )
_screen - > setVerticalShakePos ( 10 ) ;
// TODO: horizontal shakes
g_system - > updateScreen ( ) ;
wait ( 3 ) ;
if ( directions & SCI_SHAKE_DIRECTION_VERTICAL )
_screen - > setVerticalShakePos ( 0 ) ;
g_system - > updateScreen ( ) ;
wait ( 3 ) ;
}
}
2009-10-09 16:51:10 +00:00
uint16 SciGui : : onControl ( byte screenMask , Common : : Rect rect ) {
2009-10-05 07:10:01 +00:00
GuiPort * oldPort = _gfx - > SetPort ( ( GuiPort * ) _windowMgr - > _picWind ) ;
2009-10-09 16:51:10 +00:00
uint16 result ;
2009-10-04 10:46:25 +00:00
result = _gfx - > onControl ( screenMask , rect ) ;
_gfx - > SetPort ( oldPort ) ;
return result ;
}
2009-10-14 11:23:46 +00:00
void SciGui : : animateShowPic ( ) {
2009-10-14 12:39:39 +00:00
GuiPort * picPort = _windowMgr - > _picWind ;
Common : : Rect picRect = picPort - > rect ;
2009-10-14 11:23:46 +00:00
2009-10-14 12:39:39 +00:00
// Adjust picRect to become relative to screen
picRect . top + = picPort - > top ; picRect . bottom + = picPort - > top ;
picRect . left + = picPort - > left ; picRect . right + = picPort - > left ;
_transitions - > doit ( picRect ) ;
2009-10-14 11:23:46 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : animate ( reg_t listReference , bool cycle , int argc , reg_t * argv ) {
2009-10-08 10:02:26 +00:00
byte old_picNotValid = _screen - > _picNotValid ;
2009-10-04 18:34:53 +00:00
if ( listReference . isNull ( ) ) {
2009-10-13 15:28:27 +00:00
_animate - > disposeLastCast ( ) ;
2009-10-12 07:11:22 +00:00
if ( _screen - > _picNotValid )
2009-10-14 11:23:46 +00:00
animateShowPic ( ) ;
2009-10-04 18:34:53 +00:00
return ;
}
2009-10-07 23:34:24 +00:00
List * list = _s - > _segMan - > lookupList ( listReference ) ;
2009-10-06 16:14:40 +00:00
if ( ! list )
2009-10-04 18:34:53 +00:00
error ( " kAnimate called with non-list as parameter " ) ;
2009-10-06 16:14:40 +00:00
if ( cycle )
2009-10-13 15:28:27 +00:00
_animate - > invoke ( list , argc , argv ) ;
2009-10-04 18:34:53 +00:00
2009-10-05 07:10:01 +00:00
GuiPort * oldPort = _gfx - > SetPort ( ( GuiPort * ) _windowMgr - > _picWind ) ;
2009-10-13 15:28:27 +00:00
_animate - > disposeLastCast ( ) ;
2009-10-04 18:34:53 +00:00
2009-10-13 15:28:27 +00:00
_animate - > makeSortedList ( list ) ;
_animate - > fill ( old_picNotValid ) ;
2009-10-04 18:34:53 +00:00
if ( old_picNotValid ) {
2009-10-08 20:13:52 +00:00
_windowMgr - > BeginUpdate ( _windowMgr - > _picWind ) ;
2009-10-13 15:28:27 +00:00
_animate - > update ( ) ;
2009-10-08 20:13:52 +00:00
_windowMgr - > EndUpdate ( _windowMgr - > _picWind ) ;
2009-10-04 18:34:53 +00:00
}
2009-10-13 15:28:27 +00:00
_animate - > drawCels ( ) ;
2009-10-04 18:34:53 +00:00
2009-10-13 21:18:47 +00:00
if ( _screen - > _picNotValid )
2009-10-14 11:23:46 +00:00
animateShowPic ( ) ;
2009-10-04 18:34:53 +00:00
2009-10-13 15:28:27 +00:00
_animate - > updateScreen ( old_picNotValid ) ;
_animate - > restoreAndDelete ( argc , argv ) ;
2009-10-04 18:34:53 +00:00
_gfx - > SetPort ( oldPort ) ;
2009-10-04 14:59:51 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : addToPicList ( reg_t listReference , int argc , reg_t * argv ) {
2009-10-06 16:14:40 +00:00
List * list ;
_gfx - > SetPort ( ( GuiPort * ) _windowMgr - > _picWind ) ;
2009-10-07 23:34:24 +00:00
list = _s - > _segMan - > lookupList ( listReference ) ;
2009-10-06 16:14:40 +00:00
if ( ! list )
error ( " kAddToPic called with non-list as parameter " ) ;
2009-10-13 15:28:27 +00:00
_animate - > makeSortedList ( list ) ;
_animate - > addToPicDrawCels ( list ) ;
2009-10-06 16:14:40 +00:00
2009-10-09 07:50:37 +00:00
_screen - > _picNotValid = 2 ;
2009-10-04 14:59:51 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : addToPicView ( GuiResourceId viewId , GuiViewLoopNo loopNo , GuiViewCelNo celNo , int16 leftPos , int16 topPos , int16 priority , int16 control ) {
2009-10-11 07:21:59 +00:00
_gfx - > SetPort ( ( GuiPort * ) _windowMgr - > _picWind ) ;
2009-10-13 15:28:27 +00:00
_animate - > addToPicDrawView ( viewId , loopNo , celNo , leftPos , topPos , priority , control ) ;
2009-10-04 14:59:51 +00:00
}
2009-10-05 07:10:01 +00:00
void SciGui : : setNowSeen ( reg_t objectReference ) {
2009-10-04 16:39:46 +00:00
_gfx - > SetNowSeen ( objectReference ) ;
2009-10-04 14:59:51 +00:00
}
2009-10-09 16:51:10 +00:00
bool SciGui : : canBeHere ( reg_t curObject , reg_t listReference ) {
SegManager * segMan = _s - > _segMan ;
GuiPort * oldPort = _gfx - > SetPort ( ( GuiPort * ) _windowMgr - > _picWind ) ;
Common : : Rect checkRect ;
uint16 signal , controlMask ;
bool result ;
checkRect . left = GET_SEL32V ( curObject , brLeft ) ;
checkRect . top = GET_SEL32V ( curObject , brTop ) ;
checkRect . right = GET_SEL32V ( curObject , brRight ) ;
checkRect . bottom = GET_SEL32V ( curObject , brBottom ) ;
signal = GET_SEL32V ( curObject , signal ) ;
controlMask = GET_SEL32V ( curObject , illegalBits ) ;
result = ( _gfx - > onControl ( SCI_SCREEN_MASK_CONTROL , checkRect ) & controlMask ) ? false : true ;
2009-10-13 17:17:40 +00:00
if ( ( result ) & & ( signal & ( SCI_ANIMATE_SIGNAL_IGNOREACTOR | SCI_ANIMATE_SIGNAL_REMOVEVIEW ) ) ) {
2009-10-11 07:54:20 +00:00
List * list = _s - > _segMan - > lookupList ( listReference ) ;
if ( ! list )
error ( " kCanBeHere called with non-list as parameter " ) ;
result = _gfx - > CanBeHereCheckRectList ( curObject , checkRect , list ) ;
2009-10-09 16:51:10 +00:00
}
_gfx - > SetPort ( oldPort ) ;
return result ;
}
2009-10-07 21:29:47 +00:00
void SciGui : : hideCursor ( ) {
2009-10-07 14:53:15 +00:00
_cursor - > hide ( ) ;
}
2009-10-07 21:29:47 +00:00
void SciGui : : showCursor ( ) {
2009-10-07 14:53:15 +00:00
_cursor - > show ( ) ;
}
void SciGui : : setCursorShape ( GuiResourceId cursorId ) {
_cursor - > setShape ( cursorId ) ;
}
2009-10-13 17:09:32 +00:00
void SciGui : : setCursorView ( GuiResourceId viewNum , int loopNum , int cellNum , Common : : Point * hotspot ) {
_cursor - > setView ( viewNum , loopNum , cellNum , hotspot ) ;
}
2009-10-07 12:47:53 +00:00
void SciGui : : setCursorPos ( Common : : Point pos ) {
2009-10-12 07:11:22 +00:00
pos . y + = _gfx - > GetPort ( ) - > top ;
pos . x + = _gfx - > GetPort ( ) - > left ;
2009-10-07 12:47:53 +00:00
moveCursor ( pos ) ;
}
void SciGui : : moveCursor ( Common : : Point pos ) {
pos . y + = _windowMgr - > _picWind - > rect . top ;
pos . x + = _windowMgr - > _picWind - > rect . left ;
2009-10-03 20:49:18 +00:00
2009-10-07 12:47:53 +00:00
pos . y = CLIP < int16 > ( pos . y , _windowMgr - > _picWind - > rect . top , _windowMgr - > _picWind - > rect . bottom - 1 ) ;
pos . x = CLIP < int16 > ( pos . x , _windowMgr - > _picWind - > rect . left , _windowMgr - > _picWind - > rect . right - 1 ) ;
2009-10-03 20:49:18 +00:00
2009-10-07 12:47:53 +00:00
if ( pos . x > _screen - > _width | | pos . y > _screen - > _height ) {
warning ( " attempt to place cursor at invalid coordinates (%d, %d) " , pos . y , pos . x ) ;
2009-10-05 16:43:24 +00:00
return ; // Not fatal
}
2009-10-07 12:47:53 +00:00
_cursor - > setPosition ( pos ) ;
2009-10-05 16:43:24 +00:00
// Trigger event reading to make sure the mouse coordinates will
// actually have changed the next time we read them.
2009-10-07 12:47:53 +00:00
//gfxop_get_event(_s->gfx_state, SCI_EVT_PEEK);
// FIXME!
2009-10-03 20:49:18 +00:00
}
2009-10-14 09:28:58 +00:00
int16 SciGui : : getCelWidth ( int view , int loop , int cel ) {
2009-10-14 09:32:49 +00:00
SciGuiView * tmpView = new SciGuiView ( _s - > resMan , _screen , _palette , view ) ;
sciViewCelInfo * celInfo = tmpView - > getCelInfo ( loop , cel ) ;
2009-10-14 09:28:58 +00:00
int16 width = celInfo - > width ;
2009-10-14 09:32:49 +00:00
delete tmpView ;
2009-10-14 09:28:58 +00:00
return width ;
}
int16 SciGui : : getCelHeight ( int view , int loop , int cel ) {
2009-10-14 09:32:49 +00:00
SciGuiView * tmpView = new SciGuiView ( _s - > resMan , _screen , _palette , view ) ;
sciViewCelInfo * celInfo = tmpView - > getCelInfo ( loop , cel ) ;
2009-10-14 09:28:58 +00:00
int16 height = celInfo - > height ;
2009-10-14 09:32:49 +00:00
delete tmpView ;
2009-10-14 09:28:58 +00:00
return height ;
}
2009-10-07 21:47:34 +00:00
bool SciGui : : debugUndither ( bool flag ) {
_screen - > unditherSetState ( flag ) ;
return false ;
}
2009-10-07 15:53:34 +00:00
bool SciGui : : debugShowMap ( int mapNo ) {
_screen - > debugShowMap ( mapNo ) ;
return false ;
}
2009-10-03 20:49:18 +00:00
} // End of namespace Sci