00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "global.h"
00020
00021 #include <SDL_image.h>
00022 #include <signal.h>
00023
00024 #include <paragui.h>
00025 #include <pgapplication.h>
00026 #include <pgmessagebox.h>
00027 #include <pgdropdown.h>
00028 #include "pgbutton.h"
00029 #include "pglabel.h"
00030 #include "pgwindow.h"
00031 #include "pgscrollbar.h"
00032 #include "pgprogressbar.h"
00033 #include "pgradiobutton.h"
00034 #include "pgthemewidget.h"
00035 #include "pgcheckbutton.h"
00036 #include "pgslider.h"
00037 #include "pglistbox.h"
00038 #include "pgpopupmenu.h"
00039 #include "pgmenubar.h"
00040 #include "pgimage.h"
00041 #include "pgmessagebox.h"
00042 #include "pgwindow.h"
00043 #include "pgrichedit.h"
00044 #include "pgsdleventsupplier.h"
00045 #include "pgmultilineedit.h"
00046 #include "pgtooltiphelp.h"
00047 #include "pglog.h"
00048
00049 #include "widgets/multilistbox.h"
00050 #include "widgets/textrenderer.h"
00051 #include "widgets/autoprogressbar.h"
00052
00053 #include "dialogs/messagedialog.h"
00054
00055 #include "paradialog.h"
00056 #include "events.h"
00057 #include "gameoptions.h"
00058 #include "spfst.h"
00059 #include "strtmesg.h"
00060
00061 #include "graphics/drawing.h"
00062
00063 #include "util/messaginghub.h"
00064
00065
00066 #include "sdl/graphicsqueue.h"
00067
00068 class EventSupplier: public PG_SDLEventSupplier {
00069 public:
00070
00078 bool PollEvent(SDL_Event* event) {
00079 bool result = getQueuedEvent( *event );
00080 if ( result )
00081 CombineMouseMotionEvents( event );
00082 return result;
00083 };
00084
00092 bool PeepEvent(SDL_Event* event) {
00093 return peekEvent( *event );
00094 }
00095
00102 int WaitEvent(SDL_Event* event)
00103 {
00104 while ( !getQueuedEvent( *event ))
00105 releasetimeslice();
00106 CombineMouseMotionEvents( event );
00107 return 1;
00108 };
00109
00110 } eventSupplier;
00111
00112
00113
00114
00115
00116
00117 ASC_PG_App* pgApp = NULL;
00118
00119
00120 void signalQuit( int i )
00121 {
00122 getPGApplication().Quit();
00123 }
00124
00125
00126 class ASC_PG_ScreenUpdater : public PG_ScreenUpdater {
00127 public:
00128 void UpdateRect(SDL_Surface *screen, Sint32 x, Sint32 y, Sint32 w, Sint32 h)
00129 {
00130 #ifdef WIN32
00131 queueOperation( new UpdateRectOp( screen, x, y, w, h ));
00132 #else
00133 SDL_UpdateRect( screen,x,y,w,h);
00134 postScreenUpdate(screen);
00135 #endif
00136 };
00137
00138 void UpdateRects(SDL_Surface *screen, int numrects, SDL_Rect *rects)
00139 {
00140 #ifdef WIN32
00141 queueOperation( new UpdateRectsOp( screen, numrects, rects ));
00142 #else
00143 SDL_UpdateRects( screen, numrects, rects );
00144 postScreenUpdate(screen);
00145 #endif
00146 }
00147 } ascScreenUpdater;
00148
00149
00150 ASC_PG_App :: ASC_PG_App ( const ASCString& themeName ) : fullScreen(false), bitsperpixel(0)
00151 {
00152 this->themeName = themeName;
00153 EnableSymlinks(true);
00154 EnableAppIdleCalls();
00155 sigAppIdle.connect( idleEvent );
00156
00157 int i = 0;
00158 bool themeFound = false;
00159 ASCString path;
00160 do {
00161 path = getSearchPath ( i++ );
00162 if ( !path.empty() ) {
00163 AddArchive ( path );
00164 if ( !themeFound ){
00165 ASCString arch = path + themeName + ".zip";
00166 themeFound = AddArchive ( arch.c_str() );
00167 if ( themeFound )
00168 displayLogMessage( 4, "found dialog theme at " + arch );
00169
00170 }
00171 }
00172 } while ( !path.empty() );
00173 PG_LogConsole::SetLogLevel ( PG_LOG_ERR );
00174
00175 if ( !themeFound )
00176 displayLogMessage( 2, "did not found dialog theme!!" );
00177
00178 reloadTheme();
00179
00180 pgApp = this;
00181 SetEventSupplier ( &eventSupplier );
00182 SetScreenUpdater ( &ascScreenUpdater );
00183
00184 signal ( SIGINT, &signalQuit );
00185
00186 PG_LineEdit::SetBlinkingTime( 500 );
00187
00188 SetHighlightingTag( '~' );
00189
00190 setMouseUpdateFlag( &CGameOptions::Instance()->hideMouseOnScreenUpdates );
00191
00192 }
00193
00194 bool ASC_PG_App :: queueWidgetForDeletion( PG_Widget* widget )
00195 {
00196 deletionQueue.push_back( widget );
00197 widget->sigDelete.connect( SigC::slot( *this, &ASC_PG_App::removeFromDeletionQueue ));
00198 return true;
00199 }
00200
00201
00202 bool ASC_PG_App :: removeFromDeletionQueue( const PG_MessageObject* obj )
00203 {
00204 DeletionQueue::iterator i = find ( deletionQueue.begin(), deletionQueue.end(), obj );
00205 if ( i != deletionQueue.end() )
00206 deletionQueue.erase( i );
00207 return true;
00208 }
00209
00210
00211 void ASC_PG_App :: setIcon( const ASCString& filename )
00212 {
00213 SDL_Surface *icn = NULL;
00214 try {
00215 tnfilestream iconl ( filename, tnstream::reading );
00216 icn = IMG_Load_RW ( SDL_RWFromStream( &iconl ), 1);
00217
00218 if ( icn )
00219 SDL_WM_SetIcon( icn, NULL );
00220 } catch ( ... ) {}
00221 }
00222
00223 void ASC_PG_App :: Quit()
00224 {
00225 sigQuit(this);
00226 PG_Application::Quit();
00227 }
00228
00229
00230 bool ASC_PG_App::eventQuit(int id, PG_MessageObject* widget, unsigned long data)
00231 {
00232 sigQuit(this);
00233 return PG_Application::eventQuit( id, widget, data );
00234 }
00235
00236 void ASC_PG_App::eventIdle()
00237 {
00238 if ( redrawScreen ) {
00239 PG_Widget::UpdateScreen();
00240 PG_Application::UpdateRect(PG_Application::GetScreen(), 0,0,0,0);
00241 redrawScreen = false;
00242 }
00243
00244 if ( !deletionQueue.empty() )
00245 delete deletionQueue.front();
00246
00247 PG_Application::eventIdle();
00248 }
00249
00250 #include "sdl/graphicsqueue.h"
00251
00252 void ASC_PG_App::SetNewScreenSurface( SDL_Surface* surface )
00253 {
00254 SetScreen(surface, false);
00255 }
00256
00257
00258 bool ASC_PG_App::toggleFullscreen()
00259 {
00260 if ( !GetScreen() )
00261 return false;
00262
00263 int w = GetScreen()->w;
00264 int h = GetScreen()->h;
00265
00266
00267
00268 int flags = SDL_SWSURFACE;
00269 if ( !fullScreen )
00270 flags |= SDL_FULLSCREEN;
00271
00272 queueOperation( new InitScreenOp( w,h,bitsperpixel,flags, InitScreenOp::ScreenRegistrationFunctor( this, &ASC_PG_App::SetNewScreenSurface )), true );
00273 fullScreen = GetScreen()->flags & SDL_FULLSCREEN;
00274
00275
00276
00277
00278
00279
00280
00281
00282
00283
00284
00285
00286 PG_Widget::UpdateScreen();
00287
00288
00289
00290 return true;
00291 }
00292
00293
00294 ASC_PG_App& getPGApplication()
00295 {
00296 return *pgApp;
00297 }
00298
00299
00300
00301 StartupScreen::StartupScreen( const ASCString& filename, SigC::Signal0<void>& ticker ) : infoLabel(NULL), versionLabel(NULL), background(NULL), progressBar(NULL), fullscreenImage(NULL)
00302 {
00303 MessagingHub::Instance().statusInformation.connect( SigC::slot( *this, &StartupScreen::disp ));
00304
00305 tnfilestream s ( filename, tnstream::reading );
00306
00307
00308 int rt = 0;
00309 int gt = 0;
00310 int bt = 0;
00311
00312 fullscreenImage = Surface( IMG_Load_RW( SDL_RWFromStream( &s ), true ));
00313 if ( fullscreenImage.valid() ) {
00314 for ( int y = 0; y < fullscreenImage.h(); ++y ) {
00315 for ( int x = 0; x < fullscreenImage.w(); ++x ) {
00316 Uint8 r,g,b;
00317 fullscreenImage.GetPixelFormat().GetRGB( fullscreenImage.GetPixel(x,y), r,g,b );
00318 rt += r;
00319 gt += g;
00320 bt += b;
00321 }
00322 }
00323 rt /= fullscreenImage.h() * fullscreenImage.w();
00324 gt /= fullscreenImage.h() * fullscreenImage.w();
00325 bt /= fullscreenImage.h() * fullscreenImage.w();
00326 }
00327
00328
00329
00330
00331 background = new PG_ThemeWidget(NULL, PG_Rect(0,0,PG_Application::GetScreenWidth(), PG_Application::GetScreenHeight()));
00332 background->SetSimpleBackground(true);
00333 background->SetBackgroundColor( PG_Color( rt, gt, bt ));
00334
00335 if ( fullscreenImage.valid() ) {
00336 float enw = float(PG_Application::GetScreenWidth() )/float(fullscreenImage.w());
00337 float enh = float(PG_Application::GetScreenHeight())/float(fullscreenImage.h());
00338
00339 displayLogMessage(6, "Startupscreen : %f / %f", enw, enh );
00340
00341
00342 if ( enw / enh < 0.95 || enw / enh > 1.05 )
00343 enh = enw = min( enw, enh );
00344
00345 int w = int( ceil( enw * fullscreenImage.w()));
00346 int h = int( ceil( enh * fullscreenImage.h()));
00347 PG_Rect rect ( (PG_Application::GetScreenWidth()-w)/2, (PG_Application::GetScreenHeight()-h)/2, w,h);
00348 PG_ThemeWidget* image = new PG_ThemeWidget( background, rect );
00349 image->SetBackground ( fullscreenImage.getBaseSurface(), PG_Draw::STRETCH );
00350 }
00351
00352 int progressHeight = 15;
00353 SDL_Surface* screen = PG_Application::GetApp()->GetScreen();
00354 progressBar = new AutoProgressBar( ticker, background, PG_Rect( 0, screen->h - progressHeight, screen->w, progressHeight ) );
00355
00356 infoLabel = new PG_Label( background, PG_Rect( screen->w/2, screen->h - progressHeight - 25, screen->w/2 - 10, 20 ));
00357 infoLabel->SetAlignment( PG_Label::RIGHT );
00358
00359 if ( MessagingHub::Instance().getVerbosity() > 0 ) {
00360 versionLabel = new PG_Label( background, PG_Rect( 10, screen->h - progressHeight - 25, screen->w/2, 20 ));
00361 versionLabel->SetAlignment( PG_Label::LEFT );
00362 versionLabel->SetText( getVersionString() );
00363 }
00364
00365 background->Show();
00366 }
00367
00368 void StartupScreen::disp( const ASCString& s )
00369 {
00370 infoLabel->SetText( s );
00371 }
00372
00373
00374 StartupScreen::~StartupScreen()
00375 {
00376 progressBar->close();
00377 delete background;
00378 }
00379
00380
00381
00382 bool ASC_PG_App:: InitScreen ( int w, int h, int depth, Uint32 flags )
00383 {
00384 bitsperpixel = depth;
00385 bool result = PG_Application::InitScreen ( w, h, depth, flags );
00386 if ( result ) {
00387 initASCGraphicSubsystem ( GetScreen() );
00388 Surface::SetScreen( GetScreen() );
00389
00390 fullScreen = flags & SDL_FULLSCREEN;
00391
00392 MessagingHub::Instance().error.connect( SigC::bind( SigC::slot( *this, &ASC_PG_App:: messageDialog ), MessagingHubBase::Error ));
00393 MessagingHub::Instance().fatalError.connect( SigC::bind( SigC::slot( *this, &ASC_PG_App:: messageDialog ), MessagingHubBase::FatalError ));
00394 MessagingHub::Instance().warning.connect(SigC::bind( SigC::slot( *this, &ASC_PG_App:: messageDialog ), MessagingHubBase::Warning ));
00395 MessagingHub::Instance().infoMessage.connect( SigC::bind( SigC::slot( *this, &ASC_PG_App:: messageDialog ), MessagingHubBase::InfoMessage ));
00396 }
00397
00398 return result;
00399 }
00400
00401
00402 void ASC_PG_App :: reloadTheme()
00403 {
00404 if ( !LoadTheme(themeName ))
00405 fatalError ( "Could not load Paragui theme for ASC: " + themeName );
00406 }
00407
00408
00409 bool ASC_PG_App :: enableLegacyEventHandling( bool use )
00410 {
00411 return !setEventRouting ( !use, use );
00412 }
00413
00414
00415 void ASC_PG_App::processEvent( )
00416 {
00417 SDL_Event event;
00418 if ( GetEventSupplier()->PollEvent(&event))
00419 PumpIntoEventQueue(&event);
00420 }
00421
00422
00423 int ASC_PG_App::Run ( )
00424 {
00425 enableLegacyEventHandling ( false );
00426 PG_Application::Run();
00427
00428 return 0;
00429 }
00430
00431 ASC_PG_App :: ~ASC_PG_App()
00432 {
00433 while ( !deletionQueue.empty() )
00434 delete deletionQueue.front();
00435
00436 shutdownASCGraphicSubsystem();
00437 }
00438
00439
00440
00441 ASC_PG_Dialog :: ASC_PG_Dialog ( PG_Widget *parent, const PG_Rect &r, const ASCString& windowtext, WindowFlags flags, const ASCString& style, int heightTitlebar )
00442 :PG_Window ( parent, centerRectangle(r), windowtext, flags, style, heightTitlebar ),stdButtonNum(0), caller(0), standardButtonDir( Vertical )
00443 {
00444
00445
00446 int t = GetTransparency();
00447 if ( WindowCounter::num() >= 1 ) {
00448 SetTransparency ( t/2 );
00449 }
00450 }
00451
00452 int WindowCounter::windowNum = 0;
00453
00454
00455 int ASC_PG_Dialog::RunModal()
00456 {
00457 WindowCounter wc;
00458
00459 return PG_Window::RunModal();
00460 }
00461
00462
00463 PG_Rect ASC_PG_Dialog::centerRectangle( const PG_Rect& rect )
00464 {
00465 PG_Rect r = rect;
00466
00467 if ( r.w > PG_Application::GetScreenWidth() )
00468 r.w = PG_Application::GetScreenWidth();
00469
00470 if ( r.h > PG_Application::GetScreenHeight() )
00471 r.h = PG_Application::GetScreenHeight();
00472
00473
00474 if ( r.x < 0 )
00475 r.x = (PG_Application::GetScreenWidth() - r.w) / 2;
00476
00477 if ( r.y < 0 )
00478 r.y = (PG_Application::GetScreenHeight() - r.h) / 2;
00479
00480
00481 if ( r.x + r.w > PG_Application::GetScreenWidth() )
00482 r.x = PG_Application::GetScreenWidth() - r.w;
00483
00484 if ( r.y + r.h > PG_Application::GetScreenHeight() )
00485 r.y = PG_Application::GetScreenHeight() - r.h;
00486
00487 return r;
00488 }
00489
00490 void ASC_PG_Dialog::StandardButtonDirection ( StandardButtonDirectonType dir )
00491 {
00492 standardButtonDir = dir;
00493 }
00494
00495 PG_Button* ASC_PG_Dialog::AddStandardButton( const ASCString& name )
00496 {
00497 ++stdButtonNum;
00498
00499 if ( name.length() == 0 )
00500 return NULL;
00501
00502 if ( standardButtonDir == Vertical )
00503 return new PG_Button( this, PG_Rect( Width() - 110, Height() - stdButtonNum * 40, 100, 30 ), name );
00504 else
00505 return new PG_Button( this, PG_Rect( Width() - 110 * stdButtonNum, Height() -40 , 100, 30 ), name );
00506 }
00507
00508
00509
00510 bool ASC_PG_Dialog::eventKeyDown(const SDL_KeyboardEvent *key){
00511 if(key->keysym.sym == SDLK_ESCAPE) {
00512 closeWindow();
00513 }
00514 return true;
00515 }
00516
00517
00518
00519 bool ASC_PG_Dialog::quitModalLoop(int value )
00520 {
00521 SetModalStatus( value );
00522 PG_Window::QuitModal();
00523 return true;
00524 }
00525
00526
00527
00528
00529
00530
00531
00532
00533
00534
00535
00536
00537
00538
00539
00540
00541
00542
00543
00544
00545
00546
00547
00548
00549
00550
00551
00552
00553
00554 bool ASC_PG_Dialog::closeWindow(){
00555 PG_Window::QuitModal();
00556 if( caller != 0){
00557 caller->SetInputFocus();
00558 }
00559 return true;
00560 }
00561
00562
00563
00564
00565 class AntiBulkHandler {
00566 bool bulk;
00567 public:
00568 AntiBulkHandler() {
00569 bulk = PG_Application::GetBulkMode();
00570 if ( bulk )
00571 PG_Application::SetBulkMode(false);
00572 }
00573 ~AntiBulkHandler() {
00574 if ( bulk )
00575 PG_Application::SetBulkMode(true);
00576 }
00577 };
00578
00579
00580 void ASC_PG_App:: messageDialog( const ASCString& message, MessagingHubBase::MessageType mt )
00581 {
00582 AntiBulkHandler abh;
00583 ASCString title;
00584 ASCString style;
00585 switch ( mt ) {
00586 case MessagingHubBase::Error:
00587 title = "Error";
00588 style = "ErrorMessage";
00589 break;
00590 case MessagingHubBase::Warning:
00591 title = "Warning";
00592 style = "WarningMessage";
00593 break;
00594 case MessagingHubBase::InfoMessage:
00595 title = "Information";
00596 style = "Window";
00597 break;
00598 case MessagingHubBase::FatalError:
00599 title = "Fatal Error";
00600 style = "FatalErrorMessage";
00601 break;
00602 default: break;
00603 };
00604
00605 PG_Rect size = calcMessageBoxSize(message);
00606 MessageDialog msg( NULL, size, title, message,"OK", PG_Label::CENTER, style );
00607 msg.Show();
00608 msg.RunModal();
00609 }
00610
00611
00612 PG_StatusWindowData::PG_StatusWindowData( const ASCString& msg )
00613 {
00614 md = new MessageDialog( NULL, calcMessageBoxSize( msg ), "status", msg, PG_Label::CENTER, "Window" );
00615 md->Show();
00616 };
00617
00618 void PG_StatusWindowData::SetText( const ASCString& text )
00619 {
00620 md->SetText( text );
00621 }
00622
00623
00624 PG_StatusWindowData::~PG_StatusWindowData()
00625 {
00626 delete md;
00627 };
00628
00629
00630 class NewStringChooser : public ASC_PG_Dialog {
00631 PG_ListBox* listbox;
00632 int button;
00633 int item;
00634
00635 bool buttonpressed( int i )
00636 {
00637 button = i;
00638 QuitModal();
00639 return true;
00640 }
00641
00642 bool itemSelected( PG_ListBoxBaseItem* l )
00643 {
00644 PG_ListBoxDataItem<int>* listitem = dynamic_cast<PG_ListBoxDataItem<int>*>( l );
00645 if ( listitem ) {
00646 item = listitem->getData();
00647 return true;
00648 } else
00649 return false;
00650 }
00651
00652 public :
00653 NewStringChooser ( const ASCString& _title, const vector<ASCString>& _strings , const vector<ASCString>& _buttons, int defaultEntry ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 500, 300 ), _title ), button(-1), item(-1)
00654 {
00655 listbox = new PG_ListBox( this, PG_Rect( 10, 30, Width()-140, Height() - 40) );
00656 listbox->SetMultiSelect( false );
00657 listbox->sigSelectItem.connect( SigC::slot( *this, &NewStringChooser::itemSelected ));
00658
00659 int counter = 0;
00660 for ( vector<ASCString>::const_iterator i = _strings.begin(); i != _strings.end(); ++i ) {
00661 PG_ListBoxDataItem<int>* listitem = new PG_ListBoxDataItem<int>(listbox, 20, *i, counter );
00662 if ( counter == defaultEntry )
00663 listitem->Select();
00664 ++counter;
00665 }
00666
00667 counter = 0;
00668 for ( vector<ASCString>::const_iterator i = _buttons.begin(); i != _buttons.end(); ++i ) {
00669 AddStandardButton(*i)->sigClick.connect( SigC::bind( SigC::slot( *this, & NewStringChooser::buttonpressed ),counter ));
00670 ++counter;
00671 }
00672 }
00673
00674 int getButton()
00675 {
00676 return button;
00677 }
00678 int getItem()
00679 {
00680 return item;
00681 }
00682
00683 };
00684
00685
00686 pair<int,int> new_chooseString ( const ASCString& title, const vector<ASCString>& entries, const vector<ASCString>& buttons, int defaultEntry )
00687 {
00688 NewStringChooser nsc ( title, entries, buttons, defaultEntry );
00689 nsc.Show();
00690 nsc.RunModal();
00691 return make_pair(nsc.getButton(), nsc.getItem() );
00692 }
00693
00694
00695
00696 class MultiLineEditorDialog : public ASC_PG_Dialog {
00697 PG_MultiLineEdit* editor;
00698
00699 public:
00700 MultiLineEditorDialog( const ASCString& title, const ASCString& textToEdit ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 400, 400 ), title), editor(NULL)
00701 {
00702 editor = new PG_MultiLineEdit( this, PG_Rect( 10, 40, Width() - 20, Height() - 80 ) );
00703 editor->SetText( textToEdit );
00704 AddStandardButton( "OK" )->sigClick.connect( SigC::bind( SigC::slot( *this, &MultiLineEditorDialog::quitModalLoop ), 1 ));
00705 }
00706
00707 ASCString GetEditedText() { return editor->GetText(); };
00708 };
00709
00710 bool MultiLineEditor( const ASCString& title, ASCString& textToEdit )
00711 {
00712 MultiLineEditorDialog mle ( title, textToEdit );
00713 mle.Show();
00714 if ( mle.RunModal() ) {
00715 textToEdit = mle.GetEditedText();
00716 return true;
00717 } else
00718 return false;
00719
00720 }
00721
00722 BulkGraphicUpdates :: BulkGraphicUpdates( PG_Widget* parent )
00723 {
00724 bulk = PG_Application::GetBulkMode();
00725 this->parent = parent;
00726 PG_Application::SetBulkMode( true );
00727 active = true;
00728 };
00729
00730
00731 void BulkGraphicUpdates::release()
00732 {
00733 if ( !bulk && active ) {
00734 PG_Application::SetBulkMode( false );
00735 if ( parent )
00736 parent->Update();
00737 }
00738 active = false;
00739 }
00740
00741 BulkGraphicUpdates::~BulkGraphicUpdates()
00742 {
00743 release();
00744 }
00745
00746 void Emboss::eventBlit (SDL_Surface *surface, const PG_Rect &src, const PG_Rect &dst)
00747 {
00748 Surface s = Surface::Wrap( PG_Application::GetScreen() );
00749
00750 PG_Rect clip= dst.IntersectRect( PG_Application::GetScreen()->clip_rect );
00751 if ( inv )
00752 rectangle<4> ( s, SPoint(dst.x, dst.y), dst.w, dst.h, ColorMerger_Brightness<4>( 0.7 ), ColorMerger_Brightness<4>( 1.4 ), clip);
00753 else
00754 rectangle<4> ( s, SPoint(dst.x, dst.y), dst.w, dst.h, ColorMerger_Brightness<4>( 1.4 ), ColorMerger_Brightness<4>( 0.7 ), clip);
00755 };
00756
00757
00758 class StringEditor : public ASC_PG_Dialog {
00759 PG_LineEdit* editor;
00760
00761 public:
00762 StringEditor( const ASCString& title, const ASCString& textToEdit ) : ASC_PG_Dialog( NULL, PG_Rect( -1, -1, 400, 200 ), title), editor(NULL)
00763 {
00764 editor = new PG_LineEdit( this, PG_Rect( 10, 40, Width() - 20, 25 ) );
00765 editor->SetText( textToEdit );
00766 AddStandardButton( "OK" )->sigClick.connect( SigC::bind( SigC::slot( *this, &StringEditor::quitModalLoop ), 1 ));
00767 }
00768
00769 ASCString GetEditedText() { return editor->GetText(); };
00770 };
00771
00772 ASCString editString2( const ASCString& title, const ASCString& defaultValue )
00773 {
00774 StringEditor se ( title, defaultValue );
00775 se.Show();
00776 se.RunModal();
00777 return se.GetEditedText();
00778 }
00779
00780 int choiceDialog(const ASCString& text, const ASCString& button1, const ASCString& button2, const ASCString& shortLabel )
00781 {
00782
00783 map<ASCString,int>& answers = CGameOptions::Instance()->dialogAnswers;
00784
00785 map<ASCString,int>::iterator i = answers.find( shortLabel );
00786 if ( i != answers.end() )
00787 return i->second;
00788
00789 bool saveResult = false;
00790 int result = new_choice_dlg(text, shortLabel, button1, button2, saveResult);
00791
00792 if ( saveResult ) {
00793 answers[shortLabel] = result;
00794 CGameOptions::Instance()->setChanged();
00795 }
00796
00797 return result;
00798
00799 }
00800