ui example: use the object timer for the progress bar animation

This commit is contained in:
Markus Gans 2015-07-02 01:00:30 +02:00
parent 561351cb6a
commit 5d8bbf2cd9
1 changed files with 22 additions and 9 deletions

View File

@ -25,6 +25,7 @@ class ProgressDialog : public FDialog
~ProgressDialog(); // destructor ~ProgressDialog(); // destructor
void onShow (FShowEvent*); void onShow (FShowEvent*);
void onTimer (FTimerEvent*);
void cb_reset_bar (FWidget*, void*); void cb_reset_bar (FWidget*, void*);
void cb_more_bar (FWidget*, void*); void cb_more_bar (FWidget*, void*);
void cb_exit_bar (FWidget*, void*); void cb_exit_bar (FWidget*, void*);
@ -91,6 +92,7 @@ ProgressDialog::ProgressDialog (FWidget* parent) : FDialog(parent)
//---------------------------------------------------------------------- //----------------------------------------------------------------------
ProgressDialog::~ProgressDialog() ProgressDialog::~ProgressDialog()
{ {
delAllTimer();
delCallback(quit); delCallback(quit);
delCallback(more); delCallback(more);
delCallback(reset); delCallback(reset);
@ -103,12 +105,22 @@ ProgressDialog::~ProgressDialog()
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::onShow (FShowEvent*) void ProgressDialog::onShow (FShowEvent*)
{ {
for (int i=0; i <= 100; i++) addTimer(15);
{
progressBar->setPercentage(i);
flush_out();
usleep(12500); // wait 12,5 ms
} }
//----------------------------------------------------------------------
void ProgressDialog::onTimer (FTimerEvent*)
{
int p = progressBar->getPercentage();
if ( p < 100 )
{
progressBar->setPercentage(++p);
flush_out();
}
else
{
delAllTimer();
reset->setEnable(); reset->setEnable();
reset->redraw(); reset->redraw();
more->setEnable(); more->setEnable();
@ -116,6 +128,7 @@ void ProgressDialog::onShow (FShowEvent*)
quit->setEnable(); quit->setEnable();
quit->redraw(); quit->redraw();
} }
}
//---------------------------------------------------------------------- //----------------------------------------------------------------------
void ProgressDialog::cb_reset_bar (FWidget*, void*) void ProgressDialog::cb_reset_bar (FWidget*, void*)