![]() |
|
Navigation |
Synopsis Define interactive, time-dependent, behaviour.
Function
FProperty timer (TimerAction (TimerInfo) ti, void () cbb)
Description This property allows you to execute a callback
cbb after a specified time, and also allows you to delay, cancel and restart the timer.
At the start and after each event (i.e. other callback) the callback ti will be called. This callback should have type TimerAction (TimerInfo) . The callback is given a TimerInfo structure:
rascal>data TimerInfo = stopped(int timeSinceLast) >>>>>>> | running(int timeLeft); okThis indicates if the timer has stopped and the time since the last execution of the timer (in milliseconds, initially 0) or if the timer is running and the time that is still left till the callback cbb will be executed.
The callback ti must then return a TimerAction which indicates what action it want to undertake:
rascal>data TimerAction = restart(int delay) >>>>>>> | stop() >>>>>>> | noChange(); ok
Examples
c = false; void executeTimer(){ c = !c; } TimerAction timeAction(TimerInfo t){ if(stopped(_) := t){ return restart(300); } else { return noChange(); } } Color getColor(){ return c ? color("red") : color("green"); } e = ellipse(fillColor(getColor), timer(timeAction,executeTimer),shrink(0.5)); render(e); ![]()
Pitfalls Unfortunately we cannot show an animated version of the figure above, try it out in rascal yourself.
![]() |