replayrecorder.cpp

Go to the documentation of this file.
00001 /*
00002      This file is part of Advanced Strategic Command; http://www.asc-hq.de
00003      Copyright (C) 1994-2010  Martin Bickel  and  Marc Schellenberger
00004  
00005      This program is free software; you can redistribute it and/or modify
00006      it under the terms of the GNU General Public License as published by
00007      the Free Software Foundation; either version 2 of the License, or
00008      (at your option) any later version.
00009  
00010      This program is distributed in the hope that it will be useful,
00011      but WITHOUT ANY WARRANTY; without even the implied warranty of
00012      MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013      GNU General Public License for more details.
00014  
00015      You should have received a copy of the GNU General Public License
00016      along with this program; see the file COPYING. If not, write to the 
00017      Free Software Foundation, Inc., 59 Temple Place, Suite 330, 
00018      Boston, MA  02111-1307  USA
00019 */
00020 
00021 
00022 #include <sstream>
00023 #include <pgimage.h>
00024 
00025 #include "replayrecorder.h"
00026 #include "../paradialog.h"
00027 #include "../dialog.h"
00028 
00029 #include "fileselector.h"
00030 #include "../gameoptions.h"
00031 
00032 
00033 bool ReplayRecorderDialog::selectFilename()
00034 {
00035    ASCString filename = selectFile( "*.avi", false );
00036    if ( !filename.empty() )
00037       this->filename->SetText( filename );
00038    return true;
00039 }
00040       
00041 bool ReplayRecorderDialog::ok()
00042 {
00043    if ( !filename->GetText().empty() ) {
00044       tfindfile ff ( getFilename() );
00045       tfindfile::FileInfo fi;
00046       bool fileExists = false;
00047       if ( ff.getnextname( fi ))
00048          if ( fi.directoryLevel <= 0 )
00049             fileExists = true;
00050       
00051       if ( !fileExists || getAppend() || choice_dlg( "overwrite " + getFilename() +" ?", "~y~es","~n~o") == 1 ) {
00052          
00053          CGameOptions::Instance()->video.ascframeratelimit = getASCFramerateLimit();
00054          CGameOptions::Instance()->video.framerate = getFramerate();
00055          CGameOptions::Instance()->video.quality = getQuality();
00056          CGameOptions::Instance()->setChanged(true);
00057          
00058          QuitModal();
00059          return true;
00060       }
00061       return false;
00062    } else
00063       return false;
00064 }
00065       
00066 ReplayRecorderDialog::ReplayRecorderDialog( const ASCString& file, bool fileAlreadyOpen ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 400, 290 ), "Replay Recorder" ), append(NULL)
00067 {
00068    new PG_Label(this, PG_Rect(20,30,80,25),"File:");
00069    filename = new PG_LineEdit( this, PG_Rect( 120, 30, 150, 25 ));
00070    filename->SetText( file );
00071    (new PG_Button(this, PG_Rect( 290, 30, 90, 25), "Browse"))->sigClick.connect( SigC::slot( *this, &ReplayRecorderDialog::selectFilename ));
00072    
00073    if ( !file.empty() && fileAlreadyOpen ) {
00074       append = new PG_CheckButton( this, PG_Rect( 120, 70, 150, 25), "append to video");
00075       append->SetPressed();
00076    }
00077    
00078    new PG_Label(this, PG_Rect(20,100,120,25),"Video Framerate:");
00079    frameRate = new PG_LineEdit( this, PG_Rect( 150, 100, 150, 25 ));
00080    frameRate->SetText( ASCString::toString( CGameOptions::Instance()->video.framerate ));
00081    
00082    new PG_Label(this, PG_Rect(20,140,120,25),"ASC Framerate limit:");
00083    frameRateLimit = new PG_LineEdit( this, PG_Rect( 150, 140, 150, 25 ));
00084    frameRateLimit->SetText( ASCString::toString( CGameOptions::Instance()->video.ascframeratelimit ));
00085    
00086       
00087    
00088    new PG_Label(this, PG_Rect(20,180,80,25),"Quality:");
00089    quality   = new PG_LineEdit( this, PG_Rect( 150, 180, 150, 25 ));
00090    quality->SetText( ASCString::toString( CGameOptions::Instance()->video.quality ));
00091    
00092    
00093    
00094    (new PG_Button( this, PG_Rect( 20, 240, 100, 30 ), "OK"))->sigClick.connect( SigC::slot(*this, &ReplayRecorderDialog::ok ));
00095    
00096 }
00097 
00098 ASCString ReplayRecorderDialog::getFilename()
00099 {
00100    if ( filename->GetText().find('.') == ASCString::npos ) 
00101       return filename->GetText() + ".avi";
00102    else
00103       return filename->GetText();
00104 }
00105       
00106 bool ReplayRecorderDialog::getAppend()
00107 {
00108    if ( append )
00109       return append->GetPressed();  
00110    else
00111       return false;
00112 }
00113 
00114 int ReplayRecorderDialog::getQuality()
00115 {
00116    int res = atoi(quality->GetText().c_str() );
00117    if ( res < 1 )
00118       res = 1;
00119    if ( res > 100 )
00120       res = 100;
00121    return res;
00122 }
00123 
00124 int ReplayRecorderDialog::getFramerate()
00125 {
00126    int res = atoi(frameRate->GetText().c_str() );
00127    
00128    if ( res < 1 )
00129       res = 1;
00130    if ( res > 100 )
00131       res = 100;
00132    return res;
00133    
00134 }
00135 
00136 int ReplayRecorderDialog::getASCFramerateLimit()
00137 {
00138    int res = atoi(frameRateLimit->GetText().c_str() );
00139    
00140    if ( res < 1 )
00141       res = 1;
00142    if ( res > 100 )
00143       res = 100;
00144    return res;
00145    
00146 }

Generated on Mon May 21 01:26:36 2012 for Advanced Strategic Command by  doxygen 1.5.1