#ifndef GLHAND_H
#define GLHAND_H

typedef struct action_s {
  char* name ; /* symbolic name for this action, ie. ACTION_GLCAM_PITCHLEFT */
  int (*callback)(void*,int event, int eventdata, int x,int y) ; 
  /* ^returns whether the event was accepted or not */
  void* data ; /* data passed to previous callback */
} action_t ;

typedef struct actionlist_s {
  char* name ; /* symbolic name for this actionlist */
  int n_actions ;
  action_t* actions ;
  struct actionlist_s* next ;
} actionlist_t ;

#define EVENT_KEY        1
#define EVENT_SPECIALKEY 2
#define EVENT_MOUSEDOWN  3
#define EVENT_MOUSEUP    4
#define EVENT_MOUSEMOVE  5
typedef struct mapping_s {
  int event ;
  int eventdata ; /* keynumber, button ... */
  action_t* action ;
} mapping_t ;

#define ZONE_NOTHING     0
#define ZONE_WHOLESCREEN 1
#define ZONE_RECTANGLE   2
typedef struct zone_s {
  int type ;
  void* data ;
  int n_mappings ;
  mapping_t* mappings ;
  struct zone_s* next ;
} zone_t ;

typedef struct glhand_s {
  zone_t* root ;
  actionlist_t* actionlist ;
  int lastx, lasty ; /* mouse tracking */
} glhand_t ;
extern glhand_t glhand ;

actionlist_t* actionlist_new (char* name) ;
void actionlist_chain (actionlist_t*,actionlist_t*) ;
void actionlist_delete (actionlist_t*) ;

void glhand_postevent (int eventtype, int eventdata, int x, int y) ;
void glhand_keyboardFunc(unsigned char key, int x, int y) ;
void glhand_motionFunc(int x, int y) ;
void glhand_mouseFunc(int button, int state, int x, int y) ;
void glhand_specialFunc(int code, int x, int y) ;

void glhand_addzone (zone_t*) ; /* plus tard ca prendra aussi une altitude */
void glhand_addactionlist (actionlist_t*) ;
void glhand_installcallbacks () ;
void glhand_dump () ;

#endif
