Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

autoprogressbar.cpp

Go to the documentation of this file.
00001 
00002 /***************************************************************************
00003  *                                                                         *
00004  *   This program is free software; you can redistribute it and/or modify  *
00005  *   it under the terms of the GNU General Public License as published by  *
00006  *   the Free Software Foundation; either version 2 of the License, or     *
00007  *   (at your option) any later version.                                   *
00008  *                                                                         *
00009  ***************************************************************************/
00010 
00011 #include "autoprogressbar.h"
00012 
00013 #include <pgapplication.h>
00014 #include "../events.h"
00015 
00016 #include "../basestrm.h"
00017 
00018 void AutoProgressBar :: tick()
00019 {
00020 
00021    newTickTimes.push_back ( ticker - starttime );
00022 
00023    // limit to 25 Hz to reduce graphic updates
00024    if ( lastdisplaytime + 4 < ticker ) {
00025       double p;
00026       // double p = double(ticker - starttime) * 100  / time;
00027       if ( counter < prevTickTimes.size() && time ) {
00028          int a = prevTickTimes[counter];
00029          p = 100 * a / time;
00030       } else
00031          p = counter / 100;
00032 
00033          if ( p > 99 )
00034             p = 99;
00035 
00036          SetProgress( p );
00037          lastdisplaytime = ticker;
00038    }
00039 
00040    ++counter;
00041 
00042 
00043    lastticktime = ticker;
00044 };
00045 
00046 AutoProgressBar :: AutoProgressBar( SigC::Signal0<void>& tickSignal, PG_Widget *parent, const PG_Rect &r, const std::string &style ) : PG_ProgressBar( parent, r, style ), lastticktime(-1), counter(0)
00047 {
00048    lastdisplaytime = starttime = ticker;
00049 
00050    tickSignal.connect( SigC::slot( *this, &AutoProgressBar::tick ));
00051 
00052    try {
00053       tnfilestream stream ( "progress.dat", tnstream::reading  );
00054       stream.readInt(); // version
00055       time = stream.readInt( );
00056       readClassContainer( prevTickTimes, stream );
00057    }
00058    catch ( ... ) {
00059       time = 200;
00060    };
00061 };
00062 
00063 void AutoProgressBar :: close( )
00064 {
00065    try {
00066       tnfilestream stream ( "progress.dat", tnstream::writing  );
00067       stream.writeInt( 1 );
00068       stream.writeInt( lastticktime - starttime );
00069       writeClassContainer( newTickTimes, stream );
00070    }
00071    catch ( ... ) {
00072    }
00073 }
00074 

Generated on Tue Jun 24 01:27:35 2008 for Advanced Strategic Command by  doxygen 1.4.2