Algorithmic Solutions > LEDA > LEDA Guide > Windows and Panels > Timers

Timers

Each window has a timer clock that can be used to execute periodically a user-defined function. The function to be called and the time interval are specified in
  void W.start_timer(int msec, void (*func) window*));

The operation to stop the timer is

  void W.stop_timer();

Example

The following example implements a simple digital clock demo program.

On the right you see a screenshot of the program.

Picture of Convex Hull

#include <LEDA/graphics/window.h>
#include <time.h>

using namespace leda;

void display_time(window* wp)
{
  window& W=*wp;

  //get the current time
  time_t clock; time(&clock);
  tm* T=localtime(&clock);

  //display it (centered in W)
  double x=(wp->xmax()-wp->xmin())/2;
  double y=(wp->ymax()-wp->ymin())/2;

  int th=T->tm_hour;int tm=T->tm_min; int ts=T->tm_sec;
  string s=string("%2d:%02d:%02d",th,tm,ts);

  wp->clear(); wp->draw_ctext(x,y,s);
}

int main()
{
  window W(125,50,"dclock");
  W.set_bg_color(grey1); W.set_font("T32");
  W.set_redraw(display_time);
  W.display(window::center,window::center);

  W.start_timer(1000,display_time);

  W.read_mouse();
  W.screenshot("timer");

  return 0;
}

See also:

Windows and Panels

Mouse Input

Drawing Operations


Manual Pages:

Manual Page Windows




Please send any suggestions, comments or questions to leda@algorithmic-solutions.com
© Copyright 2001-2003, Algorithmic Solutions Software GmbH