2006-04-12 01:59:08 +02:00
|
|
|
/**
|
|
|
|
* =========================================================================
|
|
|
|
* File : input.h
|
|
|
|
* Project : 0 A.D.
|
|
|
|
* Description : SDL input redirector; dispatches to multiple handlers and
|
|
|
|
* : allows record/playback of events.
|
|
|
|
*
|
|
|
|
* @author Jan.Wassenberg@stud.uni-karlsruhe.de
|
|
|
|
* =========================================================================
|
|
|
|
*/
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright (c) 2002 Jan Wassenberg
|
|
|
|
*
|
|
|
|
* Redistribution and/or modification are also permitted under the
|
|
|
|
* terms of the GNU General Public License as published by the
|
|
|
|
* Free Software Foundation (version 2 or later, at your option).
|
|
|
|
*
|
|
|
|
* This program 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.
|
|
|
|
*/
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-01-27 16:31:06 +01:00
|
|
|
#ifndef INPUT_H__
|
|
|
|
#define INPUT_H__
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-10-20 19:44:56 +02:00
|
|
|
// note: cannot forward-declare SDL_Event since it is a nameless union.
|
2005-01-27 16:31:06 +01:00
|
|
|
#include "sdl.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
extern "C" {
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
2005-10-20 17:27:39 +02:00
|
|
|
// input handler return values.
|
|
|
|
enum InReaction
|
2004-06-24 16:05:39 +02:00
|
|
|
{
|
2005-10-20 19:44:56 +02:00
|
|
|
// (the handlers' return values are checked and these
|
|
|
|
// 'strange' values might bring errors to light)
|
|
|
|
|
2004-06-24 16:05:39 +02:00
|
|
|
// pass the event to the next handler in the chain
|
2005-10-20 19:44:56 +02:00
|
|
|
IN_PASS = 4,
|
2004-06-24 16:05:39 +02:00
|
|
|
|
|
|
|
// we've handled it; no other handlers will receive this event.
|
2005-10-20 19:44:56 +02:00
|
|
|
IN_HANDLED = 2
|
2004-06-24 16:05:39 +02:00
|
|
|
};
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-10-20 17:27:39 +02:00
|
|
|
typedef InReaction (*InHandler)(const SDL_Event*);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-01-27 16:31:06 +01:00
|
|
|
// register an input handler, which will receive all subsequent events first.
|
2005-10-20 19:44:56 +02:00
|
|
|
// events are passed to other handlers if handler returns IN_PASS.
|
2005-10-20 17:27:39 +02:00
|
|
|
extern void in_add_handler(InHandler handler);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-08-15 01:34:37 +02:00
|
|
|
// send event to each handler (newest first) until one returns true
|
|
|
|
extern void in_dispatch_event(const SDL_Event* event);
|
|
|
|
|
|
|
|
extern void in_dispatch_recorded_events();
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2005-12-11 23:23:55 +01:00
|
|
|
extern LibError in_record(const char* fn);
|
|
|
|
extern LibError in_playback(const char* fn);
|
2005-01-23 18:54:20 +01:00
|
|
|
extern void in_stop(void);
|
2003-11-03 17:22:45 +01:00
|
|
|
|
|
|
|
|
|
|
|
#ifdef __cplusplus
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2005-01-27 16:31:06 +01:00
|
|
|
#endif // #ifndef INPUT_H__
|