diff --git a/eflxx_examples/src/ecorexx/3dstars/main.cpp b/eflxx_examples/src/ecorexx/3dstars/main.cpp index 9658997..c1aa3e8 100644 --- a/eflxx_examples/src/ecorexx/3dstars/main.cpp +++ b/eflxx_examples/src/ecorexx/3dstars/main.cpp @@ -78,13 +78,15 @@ typedef list Starfield; typedef list::iterator StarfieldIterator; Starfield starfield; -void advance() +bool advance (Ecorexx::Timer &timer) { for (StarfieldIterator it = starfield.begin(); it != starfield.end(); ++it ) { Star* star = *it; star->advance( speed, rotation ); } + + return true; } int main( int argc, const char **argv ) @@ -108,16 +110,18 @@ int main( int argc, const char **argv ) // better use CountedPtr or delete it at the end starfield.push_back( new Star( evas ) ); } + + sigc::slot timerSlot = sigc::ptr_fun (&::advance); - // FIXME: Memory leak, but ok for this example - // better use CountedPtr or delete it at the end - (new Ecorexx::Timer( 0.05 ) )->timeout.connect( sigc::ptr_fun( ::advance ) ); + Ecorexx::Timer *timer = Ecorexx::Timer::factory (0.05, timerSlot); mw->show(); /* Enter the application main loop */ app->exec(); + timer->destroy (); + return 0; } diff --git a/eflxx_examples/src/ecorexx/callbacks/main.cpp b/eflxx_examples/src/ecorexx/callbacks/main.cpp index f35ebde..feb7be4 100644 --- a/eflxx_examples/src/ecorexx/callbacks/main.cpp +++ b/eflxx_examples/src/ecorexx/callbacks/main.cpp @@ -56,12 +56,19 @@ public: balls[i]->show(); } - ecoreTimer = new Ecorexx::Timer( 1.0 / 25 ); - ecoreTimer->timeout.connect( sigc::mem_fun( this, &TimerApp::timerEvent ) ); + + sigc::slot timerSlot = sigc::mem_fun (*this, &TimerApp::timerEvent); + + ecoreTimer = Ecorexx::Timer::factory (1.0 / 25, timerSlot); mw->show(); } + ~TimerApp () + { + ecoreTimer->destroy (); + } + Evasxx::Image* image, *shadow, *logo; Evasxx::Image* balls[NUMBALLS]; double xoffset; @@ -76,7 +83,7 @@ public: double yaddfactor; Ecorexx::Timer* ecoreTimer; - void timerEvent() + bool timerEvent(Ecorexx::Timer &timer) { logo->setColor( Color (255, 255, 255, alpha) ); @@ -100,6 +107,8 @@ public: xaddfactor = -2 + (4.0*rand()/(RAND_MAX)); yaddfactor = -2 + (4.0*rand()/(RAND_MAX)); } + + return true; } }; diff --git a/eflxx_examples/src/ecorexx/stars/main.cpp b/eflxx_examples/src/ecorexx/stars/main.cpp index 48f5e7b..667f76d 100644 --- a/eflxx_examples/src/ecorexx/stars/main.cpp +++ b/eflxx_examples/src/ecorexx/stars/main.cpp @@ -4,6 +4,7 @@ #include #include #include +#include using namespace Eflxx; using namespace std; @@ -19,7 +20,7 @@ Starfield starfield; int width = 0; -void advance( ) +bool advance (Ecorexx::Timer &timer) { for (StarfieldIterator it = starfield.begin(); it != starfield.end(); ++it ) { @@ -29,12 +30,14 @@ void advance( ) Rect g = line->getGeometry(); line->setGeometry( Rect ((g.x()+speed ) % width, g.y(), 1, 0) ); } + + return true; } int main( int argc, const char **argv ) { - Ecorexx::Application* app = new Ecorexx::Application( argc, argv, "Ecore Stars Test" ); - Ecorexx::EvasWindowSoftwareX11* mw = new Ecorexx::EvasWindowSoftwareX11( Size (WIDTH, HEIGHT) ); + auto_ptr app (new Ecorexx::Application( argc, argv, "Ecore Stars Test" )); + auto_ptr mw (new Ecorexx::EvasWindowSoftwareX11( Size (WIDTH, HEIGHT) )); Evasxx::Canvas &evas = mw->getCanvas(); Rect bg = evas.getGeometry(); @@ -57,15 +60,18 @@ int main( int argc, const char **argv ) starfield.push_back( new Star( line, speed ) ); } - ( new Ecorexx::Timer( 0.08 ) )->timeout.connect( sigc::ptr_fun( ::advance ) ); + sigc::slot timerSlot = sigc::ptr_fun (&::advance); + + Ecorexx::Timer *timer = Ecorexx::Timer::factory (0.08, timerSlot); + +// ( new Ecorexx::Timer( 0.08 ) )->timeout.connect( sigc::ptr_fun( ::advance ) ); mw->show (); /* Enter the application main loop */ app->exec(); - /* Delete the application */ - delete app; + timer->destroy (); return 0; } diff --git a/eflxx_examples/src/ecorexx/timers/main.cpp b/eflxx_examples/src/ecorexx/timers/main.cpp index 7f02082..b66923c 100644 --- a/eflxx_examples/src/ecorexx/timers/main.cpp +++ b/eflxx_examples/src/ecorexx/timers/main.cpp @@ -55,8 +55,9 @@ public: balls[i]->show(); } - ecoreTimer = new Ecorexx::Timer( 1.0 / 25 ); - ecoreTimer->timeout.connect( sigc::mem_fun( this, &TimerApp::timerEvent ) ); + sigc::slot timerSlot = sigc::mem_fun (*this, &TimerApp::timerEvent); + + ecoreTimer = Ecorexx::Timer::factory (1.0 / 25, timerSlot); mw->show(); } @@ -76,7 +77,7 @@ public: double yaddfactor; Ecorexx::Timer* ecoreTimer; - void timerEvent() + bool timerEvent (Ecorexx::Timer &timer) { logo->setColor( Color (255, 255, 255, alpha) ); @@ -100,11 +101,13 @@ public: xaddfactor = -2 + (4.0*rand()/(RAND_MAX)); yaddfactor = -2 + (4.0*rand()/(RAND_MAX)); } + + return true; } ~TimerApp () { - delete ecoreTimer; + ecoreTimer->destroy (); } }; diff --git a/eflxx_examples/src/elementaryxx/full/test_progressbar.cpp b/eflxx_examples/src/elementaryxx/full/test_progressbar.cpp index 4f5cefb..8caf152 100644 --- a/eflxx_examples/src/elementaryxx/full/test_progressbar.cpp +++ b/eflxx_examples/src/elementaryxx/full/test_progressbar.cpp @@ -17,7 +17,7 @@ typedef struct _MyProgressbar static MyProgressbar _test_progressbar; -static void _my_progressbar_value_set () +bool _my_progressbar_value_set (Ecorexx::Timer &timer) { double progress; @@ -40,9 +40,10 @@ static void _my_progressbar_value_set () if (progress > 1.0) { _test_progressbar.run = false; - //timer->del (); - // FIXME: new design offern no timers pointer! + return false; // don't run again and delete timer } + + return true; } static void my_progressbar_test_start (Evasxx::Object &obj, void *event_info) @@ -53,8 +54,10 @@ static void my_progressbar_test_start (Evasxx::Object &obj, void *event_info) if (!_test_progressbar.run) { - _test_progressbar.timer = new Ecorexx::Timer (0.1); - _test_progressbar.timer->timeout.connect (sigc::ptr_fun (&_my_progressbar_value_set)); + sigc::slot timerSlot = sigc::ptr_fun (&_my_progressbar_value_set); + + _test_progressbar.timer = Ecorexx::Timer::factory (0.1, timerSlot); + _test_progressbar.run = true; } } @@ -67,7 +70,7 @@ static void _test_stop () if (_test_progressbar.run) { - _test_progressbar.timer->del (); + _test_progressbar.timer->destroy (); _test_progressbar.run = false; } }