;; /*
;;     SDL - Simple DirectMedia Layer
;;     Copyright (C) 1997, 1998, 1999, 2000, 2001  Sam Lantinga
;; 
;;     This library is free software; you can redistribute it and/or
;;     modify it under the terms of the GNU Library General Public
;;     License as published by the Free Software Foundation; either
;;     version 2 of the License, or (at your option) any later version.
;; 
;;     This library is distributed in the hope that it will be useful,
;;     but WITHOUT ANY WARRANTY; without even the implied warranty of
;;     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
;;     Library General Public License for more details.
;; 
;;     You should have received a copy of the GNU Library General Public
;;     License along with this library; if not, write to the Free
;;     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
;; 
;;     Sam Lantinga
;;     slouken@devolution.com
;; */
;; 
;; #ifdef SAVE_RCSID
;; static char rcsid =
;;  "@(#) $Id: SDL_events.lsh,v 1.2 2002/10/01 22:34:22 profshadoko Exp $";
;; #endif
;; 
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; dummy function to load the header
;;
(de SDL_events_dummy () (sdlheader "SDL_events.h"))

;; /* Include file for SDL event handling */
;; 
;; #ifndef _SDL_events_h
;; #define _SDL_events_h
;; 
;; #include "SDL_types.h"
;; #include "SDL_active.h"
;; #include "SDL_keyboard.h"
;; #include "SDL_mouse.h"
;; #include "SDL_joystick.h"
;; #include "SDL_quit.h"
;; 
;; #include "begin_code.h"
;; /* Set up for C function definitions, even when using C++ */
;; #ifdef __cplusplus
;; extern "C" {
;; #endif
;; 
;; /* Event enumerations */
(libload "libc/constants")


(defconstant "SDL_NOEVENT" 0) ;			/* Unused (do not remove) */ 
(defconstant "SDL_ACTIVEEVENT" 1) ;		/* Application loses/gains visibility */
(defconstant "SDL_KEYDOWN" 2) ;		/* Keys pressed */
(defconstant "SDL_KEYUP" 3) ;		/* Keys released */
(defconstant "SDL_MOUSEMOTION" 4) ;		/* Mouse moved */
(defconstant "SDL_MOUSEBUTTONDOWN" 5) ;	/* Mouse button pressed */
(defconstant "SDL_MOUSEBUTTONUP" 6) ;	/* Mouse button released */
(defconstant "SDL_JOYAXISMOTION" 7) ;	/* Joystick axis motion */
(defconstant "SDL_JOYBALLMOTION" 8) ;	/* Joystick trackball motion */
(defconstant "SDL_JOYHATMOTION" 9) ;	/* Joystick hat position change */
(defconstant "SDL_JOYBUTTONDOWN" 10) ;	/* Joystick button pressed */
(defconstant "SDL_JOYBUTTONUP" 11) ;		/* Joystick button released */
(defconstant "SDL_USERQUIT" 12) ;		/* User-requested quit */
(defconstant "SDL_SYSWMEVENT" 13) ;		/* System specific event */
(defconstant "SDL_EVENT_RESERVEDA" 14) ;	/* Reserved for future use.. */
(defconstant "SDL_EVENT_RESERVEDB" 15) ;	/* Reserved for future use.. */
(defconstant "SDL_VIDEORESIZE" 16) ;		/* User resized video mode */
(defconstant "SDL_VIDEOEXPOSE" 17) ;		/* Screen needs to be redrawn */
(defconstant "SDL_EVENT_RESERVED2" 18) ;	/* Reserved for future use.. */
(defconstant "SDL_EVENT_RESERVED3" 19) ;	/* Reserved for future use.. */
(defconstant "SDL_EVENT_RESERVED4" 20) ;	/* Reserved for future use.. */
(defconstant "SDL_EVENT_RESERVED5" 21) ;	/* Reserved for future use.. */
(defconstant "SDL_EVENT_RESERVED6" 22) ;	/* Reserved for future use.. */
(defconstant "SDL_EVENT_RESERVED7" 23) ;	/* Reserved for future use.. */
;;        /* Events SDL_USEREVENT through SDL_MAXEVENTS-1 are for your use */
(defconstant "SDL_USEREVENT" 24) ;;;        /* This last event is only for bounding internal arrays
;; 	  It is the number of bits in the event mask datatype -- Uint32
;;         */
(defconstant "SDL_NUMEVENTS" 32)
;; };
;; 
;; /* Predefined event masks */
;; #define SDL_EVENTMASK(X)	(1<<(X))
(dmd SDL_EVENTMASK(x) `(int (** 2 ,x)))

(defconstant "SDL_ACTIVEEVENTMASK"	(SDL_EVENTMASK @@SDL_ACTIVEEVENT))
(defconstant "SDL_KEYDOWNMASK"		(SDL_EVENTMASK @@SDL_KEYDOWN))
(defconstant "SDL_KEYUPMASK"		(SDL_EVENTMASK @@SDL_KEYUP))
(defconstant "SDL_MOUSEMOTIONMASK"	(SDL_EVENTMASK @@SDL_MOUSEMOTION))
(defconstant "SDL_MOUSEBUTTONDOWNMASK"	(SDL_EVENTMASK @@SDL_MOUSEBUTTONDOWN))
(defconstant "SDL_MOUSEBUTTONUPMASK"	(SDL_EVENTMASK @@SDL_MOUSEBUTTONUP))
(defconstant "SDL_MOUSEEVENTMASK"	(+ (SDL_EVENTMASK @@SDL_MOUSEMOTION)
 	                           (SDL_EVENTMASK @@SDL_MOUSEBUTTONDOWN)
 	                           (SDL_EVENTMASK @@SDL_MOUSEBUTTONUP)))
(defconstant "SDL_JOYAXISMOTIONMASK"	(SDL_EVENTMASK @@SDL_JOYAXISMOTION))
(defconstant "SDL_JOYBALLMOTIONMASK"	(SDL_EVENTMASK @@SDL_JOYBALLMOTION))
(defconstant "SDL_JOYHATMOTIONMASK"	(SDL_EVENTMASK @@SDL_JOYHATMOTION))
(defconstant "SDL_JOYBUTTONDOWNMASK"	(SDL_EVENTMASK @@SDL_JOYBUTTONDOWN))
(defconstant "SDL_JOYBUTTONUPMASK"	(SDL_EVENTMASK @@SDL_JOYBUTTONUP))
(defconstant "SDL_JOYEVENTMASK"	(+ (SDL_EVENTMASK @@SDL_JOYAXISMOTION)
			   (SDL_EVENTMASK @@SDL_JOYBALLMOTION)
			   (SDL_EVENTMASK @@SDL_JOYHATMOTION)
			   (SDL_EVENTMASK @@SDL_JOYBUTTONDOWN)
			   (SDL_EVENTMASK @@SDL_JOYBUTTONUP)))
(defconstant "SDL_VIDEORESIZEMASK"	(SDL_EVENTMASK @@SDL_VIDEORESIZE))
(defconstant "SDL_VIDEOEXPOSEMASK"	(SDL_EVENTMASK @@SDL_VIDEOEXPOSE))
(defconstant "SDL_QUITMASK"		(SDL_EVENTMASK @@SDL_USERQUIT))
(defconstant "SDL_SYSWMEVENTMASK"	(SDL_EVENTMASK @@SDL_SYSWMEVENT));; };

(defconstant "SDL_ALLEVENTS"		0xFFFFFFFF)

;; 
;; /* Application visibility event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_ACTIVEEVENT */
;; 	Uint8 gain;	/* Whether given states were gained or lost (1/0) */
;; 	Uint8 state;	/* A mask of the focus states */
;; } SDL_ActiveEvent;
;; 
;; /* Keyboard event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_KEYDOWN or SDL_KEYUP */
;; 	Uint8 which;	/* The keyboard device index */
;; 	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
;; 	SDL_keysym keysym;
;; } SDL_KeyboardEvent;
;; 
;; /* Mouse motion event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_MOUSEMOTION */
;; 	Uint8 which;	/* The mouse device index */
;; 	Uint8 state;	/* The current button state */
;; 	Uint16 x, y;	/* The X/Y coordinates of the mouse */
;; 	Sint16 xrel;	/* The relative motion in the X direction */
;; 	Sint16 yrel;	/* The relative motion in the Y direction */
;; } SDL_MouseMotionEvent;
;; 
;; /* Mouse button event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_MOUSEBUTTONDOWN or SDL_MOUSEBUTTONUP */
;; 	Uint8 which;	/* The mouse device index */
;; 	Uint8 button;	/* The mouse button index */
;; 	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
;; 	Uint16 x, y;	/* The X/Y coordinates of the mouse at press time */
;; } SDL_MouseButtonEvent;
;; 
;; /* Joystick axis motion event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_JOYAXISMOTION */
;; 	Uint8 which;	/* The joystick device index */
;; 	Uint8 axis;	/* The joystick axis index */
;; 	Sint16 value;	/* The axis value (range: -32768 to 32767) */
;; } SDL_JoyAxisEvent;
;; 
;; /* Joystick trackball motion event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_JOYBALLMOTION */
;; 	Uint8 which;	/* The joystick device index */
;; 	Uint8 ball;	/* The joystick trackball index */
;; 	Sint16 xrel;	/* The relative motion in the X direction */
;; 	Sint16 yrel;	/* The relative motion in the Y direction */
;; } SDL_JoyBallEvent;
;; 
;; /* Joystick hat position change event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_JOYHATMOTION */
;; 	Uint8 which;	/* The joystick device index */
;; 	Uint8 hat;	/* The joystick hat index */
;; 	Uint8 value;	/* The hat position value:
;; 				8   1   2
;; 				7   0   3
;; 				6   5   4
;; 			   Note that zero means the POV is centered.
;; 			*/
;; } SDL_JoyHatEvent;
;; 
;; /* Joystick button event structure */
;; typedef struct {
;; 	Uint8 type;	/* SDL_JOYBUTTONDOWN or SDL_JOYBUTTONUP */
;; 	Uint8 which;	/* The joystick device index */
;; 	Uint8 button;	/* The joystick button index */
;; 	Uint8 state;	/* SDL_PRESSED or SDL_RELEASED */
;; } SDL_JoyButtonEvent;
;; 
;; /* The "window resized" event
;;    When you get this event, you are responsible for setting a new video
;;    mode with the new width and height.
;;  */
;; typedef struct {
;; 	Uint8 type;	/* SDL_VIDEORESIZE */
;; 	int w;		/* New width */
;; 	int h;		/* New height */
;; } SDL_ResizeEvent;
;; 
;; /* The "screen redraw" event */
;; typedef struct {
;; 	Uint8 type;	/* SDL_VIDEOEXPOSE */
;; } SDL_ExposeEvent;
;; 
;; /* The "quit requested" event */
;; typedef struct {
;; 	Uint8 type;	/* SDL_QUIT */
;; } SDL_QuitEvent;
;; 
;; /* A user-defined event type */
;; typedef struct {
;; 	Uint8 type;	/* SDL_USEREVENT through SDL_NUMEVENTS-1 */
;; 	int code;	/* User defined event code */
;; 	void *data1;	/* User defined data pointer */
;; 	void *data2;	/* User defined data pointer */
;; } SDL_UserEvent;
;; 
;; /* If you want to use this event, you should include SDL_syswm.h */
;; struct SDL_SysWMmsg;
;; typedef struct SDL_SysWMmsg SDL_SysWMmsg;
;; typedef struct {
;; 	Uint8 type;
;; 	SDL_SysWMmsg *msg;
;; } SDL_SysWMEvent;
;; 
;; /* General event structure */
;; typedef union {
;; 	Uint8 type;
;; 	SDL_ActiveEvent active;
;; 	SDL_KeyboardEvent key;
;; 	SDL_MouseMotionEvent motion;
;; 	SDL_MouseButtonEvent button;
;; 	SDL_JoyAxisEvent jaxis;
;; 	SDL_JoyBallEvent jball;
;; 	SDL_JoyHatEvent jhat;
;; 	SDL_JoyButtonEvent jbutton;
;; 	SDL_ResizeEvent resize;
;; 	SDL_ExposeEvent expose;
;; 	SDL_QuitEvent quit;
;; 	SDL_UserEvent user;
;; 	SDL_SysWMEvent syswm;
;; } SDL_Event;
;; 
;; 
;; /* Function prototypes */
;; 
#? (SDL_PumpEvents) 
;;.PRE
;; /* Pumps the event loop, gathering events from the input devices.
;;    This function updates the event queue and internal input device state.
;;    This should only be run in the thread that sets the video mode.
;; */
;; extern DECLSPEC void SDL_PumpEvents(void);
(de SDL_PumpEvents() #{ SDL_PumpEvents() #} ())

#? (SDL_PeepEvents <events> <numevents> <action> <mask>)
;;.PRE
;; /* Checks the event queue for messages and optionally returns them.
;;    If 'action' is SDL_ADDEVENT, up to 'numevents' events will be added to
;;    the back of the event queue.
;;    If 'action' is SDL_PEEKEVENT, up to 'numevents' events at the front
;;    of the event queue, matching 'mask', will be returned and will not
;;    be removed from the queue.
;;    If 'action' is SDL_GETEVENT, up to 'numevents' events at the front 
;;    of the event queue, matching 'mask', will be returned and will be
;;    removed from the queue.
;;    This function returns the number of events actually stored, or -1
;;    if there was an error.  This function is thread-safe.
;; */
;; typedef enum {
;; 	SDL_ADDEVENT,
;; 	SDL_PEEKEVENT,
;; 	SDL_GETEVENT
;; } SDL_eventaction;
;; /* */
;; extern DECLSPEC int SDL_PeepEvents(SDL_Event *events, int numevents,
;; 				SDL_eventaction action, Uint32 mask);
(de SDL_PeepEvents(events numevents action mask)
    ((-gptr- "SDL_Event *") events)
    ((-int-) numevents)
    ((-int-)  action)
    ((Uint32) mask)
    (int #{  SDL_PeepEvents($events, $numevents, $action, $mask) #}))

#? (SDL_PollEvent <event>)
;;.PRE
;; /* Polls for currently pending events, and returns 1 if there are any pending
;;    events, or 0 if there are none available.  If 'event' is not NULL, the next
;;    event is removed from the queue and stored in that area.
;;  */
;; extern DECLSPEC int SDL_PollEvent(SDL_Event *event);
(de SDL_PollEvent(event)
    ((-gptr- "SDL_Event *") event)
    (int #{ SDL_PollEvent($event) #}))

#? (SDL_WaitEvent <event>)
;;.PRE
;; /* Waits indefinitely for the next available event, returning 1, or 0 if there
;;    was an error while waiting for events.  If 'event' is not NULL, the next
;;    event is removed from the queue and stored in that area.
;;  */
;; extern DECLSPEC int SDL_WaitEvent(SDL_Event *event);
(de SDL_WaitEvent(event)
    ((-gptr- "SDL_Event *") event)
    (int #{ SDL_WaitEvent($event) #}))

#? (SDL_PushEvent <event>)
;;.PRE
;; /* Add an event to the event queue.
;;    This function returns 0, or -1 if the event couldn't be added to
;;    the event queue.  If the event queue is full, this function fails.
;;  */
;; extern DECLSPEC int SDL_PushEvent(SDL_Event *event);
(de SDL_PushEvent(event)
    ((-gptr- "SDL_Event *") event)
    (int #{ SDL_PushEvent($event) #}))

#? (SDL_SetEventFilter <filter>)
;;.PRE
;; /*
;;   This function sets up a filter to process all events before they
;;   change internal state and are posted to the internal event queue.
;; 
;;   The filter is protypted as:
;; */
;; typedef int (*SDL_EventFilter)(const SDL_Event *event);
;; /*
;;   If the filter returns 1, then the event will be added to the internal queue.
;;   If it returns 0, then the event will be dropped from the queue, but the 
;;   internal state will still be updated.  This allows selective filtering of
;;   dynamically arriving events.
;; 
;;   WARNING:  Be very careful of what you do in the event filter function, as 
;;             it may run in a different thread!
;; 
;;   There is one caveat when dealing with the SDL_QUITEVENT event type.  The
;;   event filter is only called when the window manager desires to close the
;;   application window.  If the event filter returns 1, then the window will
;;   be closed, otherwise the window will remain open if possible.
;;   If the quit event is generated by an interrupt signal, it will bypass the
;;   internal queue and be delivered to the application at the next event poll.
;; */

;; extern DECLSPEC void SDL_SetEventFilter(SDL_EventFilter filter);
(de SDL_SetEventFilter(filter)
    ((-gptr-) filter)
    #{  SDL_SetEventFilter( (SDL_EventFilter)$filter) #} ())

#? (SDL_GetEventFilter)
;;.PRE
;; /*
;;   Return the current event filter - can be used to "chain" filters.
;;   If there is no event filter set, this function returns NULL.
;; */
;; extern DECLSPEC SDL_EventFilter SDL_GetEventFilter(void);
(de SDL_GetEventFilter()
    (gptr #{ SDL_GetEventFilter() #}))

#? (SDL_EventState <type> <state>)
;;.PRE
;; /*
;;   This function allows you to set the state of processing certain events.
;;   If 'state' is set to SDL_IGNORE, that event will be automatically dropped
;;   from the event queue and will not event be filtered.
;;   If 'state' is set to SDL_ENABLE, that event will be processed normally.
;;   If 'state' is set to SDL_QUERY, SDL_EventState() will return the 
;;   current processing state of the specified event.
;; */
(defconstant "SDL_QUERY" -1)
(defconstant "SDL_IGNORE" 0)
(defconstant "SDL_DISABLE" 0)
(defconstant "SDL_ENABLE" 1)

;; extern DECLSPEC Uint8 SDL_EventState(Uint8 type, int state);
(de SDL_EventState(type state)
    ((Uint8) type)
    ((-int-) state)
    (int #{  SDL_EventState($type, $state) #}))

;; /* Ends C function definitions when using C++ */
;; #ifdef __cplusplus
;; }
;; #endif
;; #include "close_code.h"
;; 
;; #endif /* _SDL_events_h */

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

(sdladdfuncs     SDL_PumpEvents SDL_PeepEvents
		 SDL_PollEvent SDL_WaitEvent SDL_PushEvent
                 SDL_SetEventFilter SDL_GetEventFilter
		 SDL_EventState)
