From 5d8bbf2cd94fe990f3e0743abe393d7c917e46b2 Mon Sep 17 00:00:00 2001 From: Markus Gans Date: Thu, 2 Jul 2015 01:00:30 +0200 Subject: [PATCH] ui example: use the object timer for the progress bar animation --- test/ui.cpp | 31 ++++++++++++++++++++++--------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/test/ui.cpp b/test/ui.cpp index e4df37cf..f491787b 100644 --- a/test/ui.cpp +++ b/test/ui.cpp @@ -25,6 +25,7 @@ class ProgressDialog : public FDialog ~ProgressDialog(); // destructor void onShow (FShowEvent*); + void onTimer (FTimerEvent*); void cb_reset_bar (FWidget*, void*); void cb_more_bar (FWidget*, void*); void cb_exit_bar (FWidget*, void*); @@ -91,6 +92,7 @@ ProgressDialog::ProgressDialog (FWidget* parent) : FDialog(parent) //---------------------------------------------------------------------- ProgressDialog::~ProgressDialog() { + delAllTimer(); delCallback(quit); delCallback(more); delCallback(reset); @@ -103,18 +105,29 @@ ProgressDialog::~ProgressDialog() //---------------------------------------------------------------------- void ProgressDialog::onShow (FShowEvent*) { - for (int i=0; i <= 100; i++) + addTimer(15); +} + +//---------------------------------------------------------------------- +void ProgressDialog::onTimer (FTimerEvent*) +{ + int p = progressBar->getPercentage(); + + if ( p < 100 ) { - progressBar->setPercentage(i); + progressBar->setPercentage(++p); flush_out(); - usleep(12500); // wait 12,5 ms } - reset->setEnable(); - reset->redraw(); - more->setEnable(); - more->redraw(); - quit->setEnable(); - quit->redraw(); + else + { + delAllTimer(); + reset->setEnable(); + reset->redraw(); + more->setEnable(); + more->redraw(); + quit->setEnable(); + quit->redraw(); + } } //----------------------------------------------------------------------