Smiley with a Button

#include "graphapp.h"

void draw_smile(Control *c, Graphics *g)
{
  Rect r;
  Rect r1, r2;
  point p;

  r = get_control_area(c);
  r1 = insetr(r, 10);          /* inset from edge */

  set_colour(g, LIGHT_BLUE);   /* blue face */
  fill_ellipse(g, r1);         /* draw face */

  set_colour(g, RED);          /* red lips */
  setlinewidth(g, 2);          /* thicker lips */
  r2 = inset_rect(r1, 30);     /* inset from face */
  draw_arc(g, r2, 270-60, 270+60); /* smile arc */

  set_colour(g, BROWN);        /* brown eyes */
  p.x = r1.x + r1.width  * 1/2;
  p.y = r1.y + r1.height * 1/4;

  r2 = rect(p.x - 30, p.y, 20,20);
  fill_ellipse(g, r2);         /* draw left eye */

  r2 = rect(p.x + 10, p.y, 20,20);
  fill_ellipse(g, r2);         /* draw right eye */
}

void quit(Control *c)
{
  exit(0);
}

void resize_smile(Window *w)
{
  /* retrieve remembered drawing */
  Rect r = get_window_area(w);
  Control *c = get_window_data(w);
  set_control_area(c, rect(0,25,r.width,r.height-25));
}

int main(int argc, char *argv[])
{
  App *app;
  Window *w;
  Control *c;
  Control *b;

  app = new_app(argc, argv);
  w = new_window(app, rect(50,50,120,145),
                 "Smile!", STANDARD_WINDOW);
  b = new_button(w, rect(0,0,80,25), "Quit", quit);
  c = new_control(w, rect(0,25,120,120));
  on_control_redraw(c, draw_smile);
  set_window_data(w, d); /* store control pointer */
  on_window_resize(w, resize_smile);
  show_window(w);
  main_loop(app);
  return 0;
}

Notes: