/* * Timer * ----- * Every program can have a timer. This program demonstrates the * use of the timer function. * * Use settimerfn to set the call-back function which is called by * the timer. The call-back takes one parameter, a void pointer, * and returns nothing. * * Use settimer to start or stop the timer. The number passed to * this function is the number of milliseconds between timeouts. * In the example, the function draw_something will occur every * 2 seconds (2000 milliseconds). * * Because the timer call-back is passed a void pointer, that * pointer must be cast back to a window, then the drawto function * is called to explicitly allow drawing to that window. * (Ordinarily a call-back which belongs to a window is set up to * draw to the window when it is called, but not with timers.) */ #include rect r; void draw_something(void * w) { drawto((window) w); drawellipse(r); r.x += 10; r.y += 10; } void main(void) { window w; w = newwindow("Timer", rect(20,20,400,300), StandardWindow); show(w); r = rect(10,10,30,15); settimerfn(draw_something, w); settimer(2000); draw_something(w); mainloop(); }