문제

I am writing a FLTK-based GUI application - RAM Machine.

I would like my method to sleep for let's say 1 second after each executed order, keep the screen up to date and accessible, not to block events handling etc. at the same time. And the problem is that every function that I use sleeps for random time.

For example:

void FlowControl::_runProgram (void) {

//Inside a loop:

    _step(); //execute next order
    clock_t start = timer.start(); //initialize clock
    do{
        //wait max. 1-passed_time() [seconds] until 'something happens'
        Fl::wait(1-timer.passed_time()); 

    }while ( timer.passed_time() < 1 ); // check if 1 second has passed

    //...
}

Result: GUI doesn't block, everything works but I have to wait between 0 and even 6 (!!) seconds instead of exactly one second for next step.

What I've already tried: Fl::wait()/Fl::check()/Fl::ready() + Sleep()/SetTimer()/clock_t/time_t with or without multithreading.

How do I solve this problem?

FLTK doc: http://www.fltk.org/doc-1.3/index.html

도움이 되었습니까?

해결책

The easiest way that I can think of is to use Fl::add_timeout() and Fl::repeat_timeout() functions. Check for an example how Greg Ercolano does it in this small demo: http://seriss.com/people/erco/fltk/#AnimateDrawing

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top