Associating Data with Windows

#include "graphapp.h"

void draw_shapes(drawing d, rect r)
{
  setcolour(Red);
  fillrect(r);

  setcolour(Blue);
  fillellipse(insetr(r,4));

  setcolour(Green);
  drawline(pt(r.x,r.y),
           pt(r.x+r.width,r.y+r.height));
  drawline(pt(r.x,r.y+r.height),
           pt(r.x+r.width,r.y));
}

void resize_drawing(window w, rect r)
{
  /* retrieve stored pointer */
  drawing d = (drawing) getdata(w);
  resize(d, insetr(r,10));
}

void main(void)
{
  window w;
  drawing d; /* local */
  rect r;

  w = newwindow("Rectangles", rect(50,50,150,200),
                StandardWindow);
  setbackground(w, LightGrey);
  r = rect(10,10,100,100);
  d = newdrawing(r, draw_shapes);
  setdata(w, d); /* store pointer */
  setresize(w, resize_drawing);
  show(w);
  mainloop();
}

Notes: