/*
 * Rubik's clock.
 *
 * This file is public domain, I just hate copy[left/right]s.
 *-------------
 * the event handling stuff include file
 */

#ifndef _EVENT_H_
#define _EVENT_H_

/* the event possible types */
#define	QUIT		(1L<<0)
#define	BUTTON		(1L<<1)
#define	CORNER		(1L<<2)
#define	TURN		(1L<<3)
/* the following are not currently implemented but should be ! */
#define	UNDO		(1L<<4)
#define	REDO		(1L<<5)
#define	SAVE		(1L<<6)
#define	LOAD		(1L<<7)

#define REDRAW		(1L<<8)
#define MOUSEMOVE	(1L<<9)

#define SELECT_CORNER	(1L<<10)

#define TIMEOUT		(1L<<11)

/* F2 = initialize to 0 */
#define F2		(1L<<11)
/* F3 = random */
#define F3		(1L<<12)
/* F4 = solve */
#define F4		(1L<<13)
/* forgot F1 (damned), so F1 if like F4, same effect */
#define F1		(1L<<14)

/* who generates an event */
#define HUMAN	0
#define MACHINE	1

typedef struct {
  /* the type of event, see above for possible values */
  int type;
  /* if button event, which button (see clock.h) */
  //int button;
  /* if a corner, which one and which direction (once again see clock.h) */
  //int corner;
  //int dir;
  /* if a mouse, here is the mouse position */
  int mousex, mousey;
#if 0
  /* for BUTTON and CORNER event, we need to know what button/corner */
  int which;
#endif
  /* above stuff is bad because new handling of events, we must separate != types of events, so != which */
  int which_button;
  int which_corner;
  int which_select_corner;
  /* we need a timer for the solver, it's in ms */
  int timer;
  /* we need to check who generated the event, for when we are in solver mode */
  int generator;
} EVENT;

/* It is good practice to include .h after defining structures.
 * Sometimes (but isn't it then a bad design of the code ?), you have recursive
 * needs of include, for example a function declaration in file A needs type defined in file B
 * and a function declaration in file B needs a type in file A. In that case, if you include
 * at the begining of the .h, you'll have problem at compile time (try to find out why)
 * (of course, if you don't protect your .h within #ifdef #define #endif, you won't have
 * this problem (but another one, infinite include)).
 * So, as I had this problem once (and as it tooks lotsa time to track down), I prefer include
 * after type definition. Safer. (Even if in this project, there is no recursive include.)
 */
#include "clock.h"
#include "screen.h"

/* we could mix those two functions in one, but it's cleaner to separate */
void wait_next_event(EVENT *, SCREEN *);
void handle_event(EVENT *, CLOCK *, SCREEN *);

#endif /* _EVENT_H_ */
