Advanced Strategic Command
replayrecorder.cpp
Go to the documentation of this file.
1 /*
2  This file is part of Advanced Strategic Command; http://www.asc-hq.de
3  Copyright (C) 1994-2010 Martin Bickel and Marc Schellenberger
4 
5  This program is free software; you can redistribute it and/or modify
6  it under the terms of the GNU General Public License as published by
7  the Free Software Foundation; either version 2 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU General Public License for more details.
14 
15  You should have received a copy of the GNU General Public License
16  along with this program; see the file COPYING. If not, write to the
17  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18  Boston, MA 02111-1307 USA
19 */
20 
21 
22 #include <sstream>
23 #include <pgimage.h>
24 
25 #include "replayrecorder.h"
26 #include "../paradialog.h"
27 #include "../dialog.h"
28 
29 #include "fileselector.h"
30 #include "../gameoptions.h"
31 
32 
33 bool ReplayRecorderDialog::selectFilename()
34 {
35  ASCString filename = selectFile( "*.avi", false );
36  if ( !filename.empty() )
37  this->filename->SetText( filename );
38  return true;
39 }
40 
41 bool ReplayRecorderDialog::ok()
42 {
43  if ( !filename->GetText().empty() ) {
44  tfindfile ff ( getFilename() );
46  bool fileExists = false;
47  if ( ff.getnextname( fi ))
48  if ( fi.directoryLevel <= 0 )
49  fileExists = true;
50 
51  if ( !fileExists || getAppend() || choice_dlg( "overwrite " + getFilename() +" ?", "~y~es","~n~o") == 1 ) {
52 
57 
58  QuitModal();
59  return true;
60  }
61  return false;
62  } else
63  return false;
64 }
65 
66 ReplayRecorderDialog::ReplayRecorderDialog( const ASCString& file, bool fileAlreadyOpen ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 400, 290 ), "Replay Recorder" ), append(NULL)
67 {
68  new PG_Label(this, PG_Rect(20,30,80,25),"File:");
69  filename = new PG_LineEdit( this, PG_Rect( 120, 30, 150, 25 ));
70  filename->SetText( file );
71  (new PG_Button(this, PG_Rect( 290, 30, 90, 25), "Browse"))->sigClick.connect( sigc::hide( sigc::mem_fun( *this, &ReplayRecorderDialog::selectFilename )));
72 
73  if ( !file.empty() && fileAlreadyOpen ) {
74  append = new PG_CheckButton( this, PG_Rect( 120, 70, 150, 25), "append to video");
75  append->SetPressed();
76  }
77 
78  new PG_Label(this, PG_Rect(20,100,120,25),"Video Framerate:");
79  frameRate = new PG_LineEdit( this, PG_Rect( 150, 100, 150, 25 ));
80  frameRate->SetText( ASCString::toString( CGameOptions::Instance()->video.framerate ));
81 
82  new PG_Label(this, PG_Rect(20,140,120,25),"ASC Framerate limit:");
83  frameRateLimit = new PG_LineEdit( this, PG_Rect( 150, 140, 150, 25 ));
84  frameRateLimit->SetText( ASCString::toString( CGameOptions::Instance()->video.ascframeratelimit ));
85 
86 
87 
88  new PG_Label(this, PG_Rect(20,180,80,25),"Quality:");
89  quality = new PG_LineEdit( this, PG_Rect( 150, 180, 150, 25 ));
90  quality->SetText( ASCString::toString( CGameOptions::Instance()->video.quality ));
91 
92 
93 
94  (new PG_Button( this, PG_Rect( 20, 240, 100, 30 ), "OK"))->sigClick.connect( sigc::hide( sigc::mem_fun(*this, &ReplayRecorderDialog::ok )));
95 
96 }
97 
99 {
100  if ( filename->GetText().find('.') == ASCString::npos )
101  return filename->GetText() + ".avi";
102  else
103  return filename->GetText();
104 }
105 
107 {
108  if ( append )
109  return append->GetPressed();
110  else
111  return false;
112 }
113 
115 {
116  int res = atoi(quality->GetText().c_str() );
117  if ( res < 1 )
118  res = 1;
119  if ( res > 100 )
120  res = 100;
121  return res;
122 }
123 
125 {
126  int res = atoi(frameRate->GetText().c_str() );
127 
128  if ( res < 1 )
129  res = 1;
130  if ( res > 100 )
131  res = 100;
132  return res;
133 
134 }
135 
137 {
138  int res = atoi(frameRateLimit->GetText().c_str() );
139 
140  if ( res < 1 )
141  res = 1;
142  if ( res > 100 )
143  res = 100;
144  return res;
145 
146 }
The ASCString class provides an abstract way to manipulate strings.
Definition: ascstring.h:14
int ascframeratelimit
Definition: gameoptions.h:243
static ASCString toString(int i)
converts the parameter to a String
Definition: ascstring.cpp:193
void setChanged(bool flag=true)
Definition: gameoptions.h:272
Adapter class for using Paragui Dialogs in ASC. This class transfers the event control from ASC to Pa...
Definition: paradialog.h:127
Searching for files.
Definition: basestrm.h:484
static CGameOptions * Instance()
returns the only Instance
Definition: gameoptions.cpp:38
ASCString selectFile(const ASCString &ext, bool load, bool overwriteMessage)
int atoi(const std::string &s)
Definition: misc.cpp:152
ReplayRecorderDialog(const ASCString &file, bool fileAlreadyOpen)
struct CGameOptions::@11 video
int choice_dlg(const ASCString &title, const ASCString &leftButton, const ASCString &rightButton)
Definition: dialog.cpp:616