Using the Mouse

#include <stdio.h>
#include "graphapp.h"

void mouse_click(Control *c, int buttons, Point p)
{  
  if (buttons & LEFT_BUTTON)
    set_colour(g, RED);
  else if (buttons & MIDDLE_BUTTON)
    set_colour(g, GREEN);
  else if (buttons & RIGHT_BUTTON)
    set_colour(g, BLUE);

  draw_point(g, p);
}

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

  app = new_app(argc, argv);
  w = new_window(app, rect(50,50,200,200),
                 "Dots", STANDARD_WINDOW);
  c = new_control(w, rect(10,10,180,180));
  set_window_background(w, LIGHT_GREY);

  on_control_mouse_down(c, mouse_click);
  on_control_mouse_drag(c, mouse_click);

  show_window(w);
  main_loop(app);
  return 0;
}

Notes: