2007-05-30 21:56:52 +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 .
2003-07-22 16:05:51 +00:00
*
* 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
2005-10-18 01:30:26 +00:00
* Foundation , Inc . , 51 Franklin Street , Fifth Floor , Boston , MA 02110 - 1301 , USA .
2003-07-22 16:05:51 +00:00
*/
2008-05-13 09:30:23 +00:00
# include "engines/metaengine.h"
2006-07-31 13:41:21 +00:00
# include "base/plugins.h"
2004-02-09 01:27:27 +00:00
# include "base/version.h"
2007-03-17 16:05:16 +00:00
# include "common/events.h"
2005-01-10 22:06:49 +00:00
# include "common/system.h"
2010-06-15 10:44:51 +00:00
# include "common/translation.h"
2005-01-10 22:35:43 +00:00
# include "common/util.h"
2003-11-02 14:50:53 +00:00
# include "gui/about.h"
2010-11-16 10:19:01 +00:00
# include "gui/gui-manager.h"
2008-08-08 21:52:16 +00:00
# include "gui/ThemeEval.h"
2003-11-10 23:40:48 +00:00
namespace GUI {
2004-12-19 19:17:43 +00:00
enum {
2004-12-30 14:21:16 +00:00
kScrollStartDelay = 1500 ,
2005-12-19 02:23:01 +00:00
kScrollMillisPerPixel = 60
2004-12-19 19:17:43 +00:00
} ;
// The following commands can be put at the start of a line (all subject to change):
// \C, \L, \R -- set center/left/right alignment
// \c0 - \c4 -- set a custom color:
// 0 normal text (green)
// 1 highlighted text (light green)
// 2 light border (light gray)
// 3 dark border (dark gray)
// 4 background (black)
2005-05-17 23:41:35 +00:00
// TODO: Maybe add a tab/indent feature; that is, make it possible to specify
// an amount by which that line shall be indented (the indent of course would have
// to be considered while performing any word wrapping, too).
2005-12-19 02:23:01 +00:00
//
// TODO: Add different font sizes (for bigger headlines)
// TODO: Allow color change in the middle of a line...
2007-06-13 20:37:24 +00:00
static const char * copyright_text [ ] = {
2008-11-20 13:46:34 +00:00
" " ,
2010-12-31 23:04:49 +00:00
" C0 " " Copyright (C) 2001-2011 The ScummVM project " ,
2008-11-20 13:46:34 +00:00
" C0 " " http://www.scummvm.org " ,
" " ,
" C0 " " 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 binary. " ,
" " ,
2007-06-13 20:37:24 +00:00
} ;
2006-07-31 13:41:21 +00:00
static const char * gpl_text [ ] = {
2008-11-20 13:46:34 +00:00
" " ,
" C0 " " 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. " ,
" C0 " " " ,
" C0 " " 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. " ,
" " ,
" C0 " " 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. " ,
" " ,
2004-12-19 19:17:43 +00:00
} ;
2004-12-22 01:07:13 +00:00
# include "gui/credits.h"
2003-11-02 02:18:16 +00:00
AboutDialog : : AboutDialog ( )
2004-12-19 19:17:43 +00:00
: Dialog ( 10 , 20 , 300 , 174 ) ,
2007-03-17 16:05:16 +00:00
_scrollPos ( 0 ) , _scrollTime ( 0 ) , _willClose ( false ) {
2005-07-30 21:11:48 +00:00
2010-05-27 20:29:39 +00:00
reflowLayout ( ) ;
2004-12-19 19:17:43 +00:00
int i ;
2005-07-30 21:11:48 +00:00
2004-12-19 19:17:43 +00:00
for ( i = 0 ; i < 1 ; i + + )
_lines . push_back ( " " ) ;
2008-11-20 13:46:34 +00:00
Common : : String version ( " C0 " " ScummVM " ) ;
2003-07-22 16:05:51 +00:00
version + = gScummVMVersion ;
2004-12-19 19:17:43 +00:00
_lines . push_back ( version ) ;
2003-07-22 16:05:51 +00:00
2010-11-01 16:02:28 +00:00
Common : : String date = Common : : String : : format ( _ ( " (built on %s) " ) , gScummVMBuildDate ) ;
2010-06-26 15:48:03 +00:00
_lines . push_back ( " C2 " + date ) ;
2003-07-22 16:05:51 +00:00
2007-06-13 20:37:24 +00:00
for ( i = 0 ; i < ARRAYSIZE ( copyright_text ) ; i + + )
addLine ( copyright_text [ i ] ) ;
2006-07-31 13:41:21 +00:00
2010-06-26 15:48:03 +00:00
Common : : String features ( " C1 " ) ;
features + = _ ( " Features compiled in: " ) ;
2005-05-17 23:41:35 +00:00
addLine ( features . c_str ( ) ) ;
2010-06-26 15:48:03 +00:00
Common : : String featureList ( " C0 " ) ;
featureList + = gScummVMFeatures ;
addLine ( featureList . c_str ( ) ) ;
2004-12-19 19:17:43 +00:00
_lines . push_back ( " " ) ;
2005-07-30 21:11:48 +00:00
2010-06-26 15:48:03 +00:00
Common : : String engines ( " C1 " ) ;
engines + = _ ( " Available engines: " ) ;
addLine ( engines . c_str ( ) ) ;
2008-05-26 00:28:48 +00:00
const EnginePlugin : : List & plugins = EngineMan . getPlugins ( ) ;
EnginePlugin : : List : : const_iterator iter = plugins . begin ( ) ;
2006-07-31 13:41:21 +00:00
for ( ; iter ! = plugins . end ( ) ; + + iter ) {
Common : : String str ;
2008-11-20 13:46:34 +00:00
str = " C0 " ;
2006-07-31 13:41:21 +00:00
str + = ( * * iter ) . getName ( ) ;
addLine ( str . c_str ( ) ) ;
2008-11-20 13:46:34 +00:00
str = " C2 " ;
2009-03-05 12:04:58 +00:00
str + = ( * * iter ) - > getOriginalCopyright ( ) ;
2006-07-31 13:41:21 +00:00
addLine ( str . c_str ( ) ) ;
//addLine("");
}
2007-06-13 20:37:24 +00:00
for ( i = 0 ; i < ARRAYSIZE ( gpl_text ) ; i + + )
addLine ( gpl_text [ i ] ) ;
2006-07-31 13:41:21 +00:00
_lines . push_back ( " " ) ;
2005-07-30 21:11:48 +00:00
2004-12-22 01:07:13 +00:00
for ( i = 0 ; i < ARRAYSIZE ( credits ) ; i + + )
2005-05-17 23:41:35 +00:00
addLine ( credits [ i ] ) ;
2004-12-19 19:17:43 +00:00
}
2005-05-17 23:41:35 +00:00
void AboutDialog : : addLine ( const char * str ) {
if ( * str = = 0 ) {
2008-11-20 13:46:34 +00:00
_lines . push_back ( " " ) ;
2005-05-17 23:41:35 +00:00
} else {
2008-11-20 13:46:34 +00:00
Common : : String format ( str , 2 ) ;
str + = 2 ;
2010-03-18 15:09:24 +00:00
StringArray wrappedLines ;
2007-03-17 15:52:35 +00:00
g_gui . getFont ( ) . wordWrapText ( str , _w - 2 * _xOff , wrappedLines ) ;
2005-07-30 21:11:48 +00:00
2010-03-18 15:09:24 +00:00
for ( StringArray : : const_iterator i = wrappedLines . begin ( ) ; i ! = wrappedLines . end ( ) ; + + i ) {
2005-05-17 23:41:35 +00:00
_lines . push_back ( format + * i ) ;
}
}
}
2004-12-19 19:17:43 +00:00
void AboutDialog : : open ( ) {
2010-03-11 23:41:28 +00:00
_scrollTime = g_system - > getMillis ( ) + kScrollStartDelay ;
2004-12-19 19:17:43 +00:00
_scrollPos = 0 ;
2004-12-30 14:55:20 +00:00
_willClose = false ;
2004-12-19 19:17:43 +00:00
Dialog : : open ( ) ;
}
2005-04-16 11:40:15 +00:00
void AboutDialog : : close ( ) {
Dialog : : close ( ) ;
}
2004-12-19 19:17:43 +00:00
void AboutDialog : : drawDialog ( ) {
2008-07-23 22:32:00 +00:00
// g_gui.theme()->setDrawArea(Common::Rect(_x, _y, _x+_w, _y+_h));
2006-01-27 15:43:23 +00:00
Dialog : : drawDialog ( ) ;
2004-12-19 19:17:43 +00:00
// Draw text
// TODO: Add a "fade" effect for the top/bottom text lines
2005-04-16 11:40:15 +00:00
// TODO: Maybe prerender all of the text into another surface,
// and then simply compose that over the screen surface
// in the right way. Should be even faster...
2004-12-19 19:17:43 +00:00
const int firstLine = _scrollPos / _lineHeight ;
2004-12-20 22:54:20 +00:00
const int lastLine = MIN ( ( _scrollPos + _h ) / _lineHeight + 1 , ( uint32 ) _lines . size ( ) ) ;
2007-03-17 15:52:35 +00:00
int y = _y + _yOff - ( _scrollPos % _lineHeight ) ;
2004-12-19 19:17:43 +00:00
for ( int line = firstLine ; line < lastLine ; line + + ) {
const char * str = _lines [ line ] . c_str ( ) ;
2008-11-12 14:30:16 +00:00
Graphics : : TextAlign align = Graphics : : kTextAlignCenter ;
2008-11-10 11:24:55 +00:00
ThemeEngine : : WidgetStateInfo state = ThemeEngine : : kStateEnabled ;
2008-11-20 13:46:34 +00:00
if ( * str ) {
switch ( str [ 0 ] ) {
2004-12-19 19:17:43 +00:00
case ' C ' :
2008-11-12 14:30:16 +00:00
align = Graphics : : kTextAlignCenter ;
2004-12-19 19:17:43 +00:00
break ;
case ' L ' :
2008-11-12 14:30:16 +00:00
align = Graphics : : kTextAlignLeft ;
2004-12-19 19:17:43 +00:00
break ;
case ' R ' :
2008-11-12 14:30:16 +00:00
align = Graphics : : kTextAlignRight ;
2004-12-19 19:17:43 +00:00
break ;
default :
2008-11-20 13:46:34 +00:00
error ( " Unknown scroller opcode '%c' " , str [ 0 ] ) ;
2004-12-19 19:17:43 +00:00
break ;
}
2008-11-20 13:46:34 +00:00
switch ( str [ 1 ] ) {
case ' 0 ' :
state = ThemeEngine : : kStateEnabled ;
break ;
case ' 1 ' :
state = ThemeEngine : : kStateHighlight ;
break ;
case ' 2 ' :
state = ThemeEngine : : kStateDisabled ;
break ;
case ' 3 ' :
warning ( " Need state for color 3 " ) ;
// color = g_gui._shadowcolor;
break ;
case ' 4 ' :
warning ( " Need state for color 4 " ) ;
// color = g_gui._bgcolor;
break ;
default :
error ( " Unknown color type '%c' " , str [ 1 ] ) ;
}
2004-12-19 19:17:43 +00:00
str + = 2 ;
}
// Trim leading whitespaces if center mode is on
2008-11-12 14:30:16 +00:00
if ( align = = Graphics : : kTextAlignCenter )
2004-12-19 19:17:43 +00:00
while ( * str & & * str = = ' ' )
str + + ;
2005-07-30 21:11:48 +00:00
2008-11-20 13:46:34 +00:00
if ( * str & & y > _y & & y + g_gui . theme ( ) - > getFontHeight ( ) < _y + _h )
2009-07-15 18:05:37 +00:00
g_gui . theme ( ) - > drawText ( Common : : Rect ( _x + _xOff , y , _x + _w - _xOff , y + g_gui . theme ( ) - > getFontHeight ( ) ) , str , state , align , ThemeEngine : : kTextInversionNone , 0 , false ) ;
2004-12-19 19:17:43 +00:00
y + = _lineHeight ;
}
2003-07-22 16:05:51 +00:00
}
2004-12-19 19:17:43 +00:00
void AboutDialog : : handleTickle ( ) {
2010-03-11 23:41:28 +00:00
const uint32 t = g_system - > getMillis ( ) ;
2004-12-19 19:17:43 +00:00
int scrollOffset = ( ( int ) t - ( int ) _scrollTime ) / kScrollMillisPerPixel ;
if ( scrollOffset > 0 ) {
2007-03-17 16:05:16 +00:00
int modifiers = g_system - > getEventManager ( ) - > getModifierState ( ) ;
2004-12-30 14:21:16 +00:00
// Scroll faster when shift is pressed
2007-03-17 19:02:05 +00:00
if ( modifiers & Common : : KBD_SHIFT )
2004-12-30 14:21:16 +00:00
scrollOffset * = 4 ;
// Reverse scrolling when alt is pressed
2007-03-17 19:02:05 +00:00
if ( modifiers & Common : : KBD_ALT )
2004-12-30 14:21:16 +00:00
scrollOffset * = - 1 ;
2004-12-19 19:17:43 +00:00
_scrollPos + = scrollOffset ;
_scrollTime = t ;
if ( _scrollPos < 0 ) {
_scrollPos = 0 ;
} else if ( ( uint32 ) _scrollPos > _lines . size ( ) * _lineHeight ) {
_scrollPos = 0 ;
_scrollTime + = kScrollStartDelay ;
}
2005-04-16 11:40:15 +00:00
drawDialog ( ) ;
2004-12-19 19:17:43 +00:00
}
}
void AboutDialog : : handleMouseUp ( int x , int y , int button , int clickCount ) {
// Close upon any mouse click
close ( ) ;
}
2007-06-30 12:26:59 +00:00
void AboutDialog : : handleKeyDown ( Common : : KeyState state ) {
if ( state . ascii )
2004-12-30 14:55:20 +00:00
_willClose = true ;
2004-12-19 19:17:43 +00:00
}
2007-06-30 12:26:59 +00:00
void AboutDialog : : handleKeyUp ( Common : : KeyState state ) {
if ( state . ascii & & _willClose )
2004-12-30 14:21:16 +00:00
close ( ) ;
2004-12-19 19:17:43 +00:00
}
2006-08-04 13:55:53 +00:00
void AboutDialog : : reflowLayout ( ) {
Dialog : : reflowLayout ( ) ;
2010-05-27 19:34:12 +00:00
int i ;
2006-04-19 01:05:28 +00:00
const int screenW = g_system - > getOverlayWidth ( ) ;
const int screenH = g_system - > getOverlayHeight ( ) ;
2008-08-08 21:52:16 +00:00
_xOff = g_gui . xmlEval ( ) - > getVar ( " Globals.About.XOffset " , 5 ) ;
_yOff = g_gui . xmlEval ( ) - > getVar ( " Globals.About.YOffset " , 5 ) ;
int outerBorder = g_gui . xmlEval ( ) - > getVar ( " Globals.About.OuterBorder " ) ;
2006-04-19 01:05:28 +00:00
_w = screenW - 2 * outerBorder ;
_h = screenH - 2 * outerBorder ;
_lineHeight = g_gui . getFontHeight ( ) + 3 ;
// Heuristic to compute 'optimal' dialog width
2007-03-17 15:52:35 +00:00
int maxW = _w - 2 * _xOff ;
2006-04-19 01:05:28 +00:00
_w = 0 ;
2010-05-27 19:34:12 +00:00
for ( i = 0 ; i < ARRAYSIZE ( credits ) ; i + + ) {
2006-04-19 01:05:28 +00:00
int tmp = g_gui . getStringWidth ( credits [ i ] + 5 ) ;
2009-09-30 16:16:53 +00:00
if ( _w < tmp & & tmp < = maxW ) {
2006-04-19 01:05:28 +00:00
_w = tmp ;
}
}
2007-03-17 15:52:35 +00:00
_w + = 2 * _xOff ;
2006-04-19 01:05:28 +00:00
2010-05-27 19:34:12 +00:00
// Center the dialog
2006-04-19 01:05:28 +00:00
_x = ( screenW - _w ) / 2 ;
_y = ( screenH - _h ) / 2 ;
}
2003-11-10 23:40:48 +00:00
} // End of namespace GUI