# 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:

- The control has no resize call-back, so it remains fixed in size and location.
- Different mouse buttons cause different bits in the `buttons` field to be set. The constants `LEFT_BUTTON`, `RIGHT_BUTTON` and `MIDDLE_BUTTON` can be used to detect which button is pressed down, by a bitwise-and operation.