2012-01-13 00:32:27 +01:00
|
|
|
/* Copyright (c) 2012 Wildfire Games
|
2009-04-18 19:00:33 +02:00
|
|
|
*
|
2010-02-08 17:23:39 +01:00
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining
|
|
|
|
* a copy of this software and associated documentation files (the
|
|
|
|
* "Software"), to deal in the Software without restriction, including
|
|
|
|
* without limitation the rights to use, copy, modify, merge, publish,
|
|
|
|
* distribute, sublicense, and/or sell copies of the Software, and to
|
|
|
|
* permit persons to whom the Software is furnished to do so, subject to
|
|
|
|
* the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included
|
|
|
|
* in all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
|
|
|
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
|
|
|
* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
|
|
|
|
* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
|
|
|
|
* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
|
|
|
|
* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
|
|
|
|
* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
2009-04-18 19:00:33 +02:00
|
|
|
*/
|
|
|
|
|
2009-04-18 19:51:05 +02:00
|
|
|
/*
|
2011-04-30 02:06:30 +02:00
|
|
|
* SDL input redirector; dispatches to multiple handlers.
|
2006-04-12 01:59:08 +02:00
|
|
|
*/
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#ifndef INCLUDED_INPUT
|
|
|
|
#define INCLUDED_INPUT
|
2003-11-03 17:22:45 +01:00
|
|
|
|
2006-08-26 23:52:18 +02:00
|
|
|
|
2012-01-13 00:32:27 +01:00
|
|
|
#include "lib/external_libraries/libsdl_fwd.h"
|
2003-11-03 17:22:45 +01:00
|
|
|
|
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
|
|
|
|
2006-08-26 23:52:18 +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
|
|
|
|
2010-07-07 23:47:31 +02:00
|
|
|
// remove all registered input handlers
|
|
|
|
extern void in_reset_handlers();
|
|
|
|
|
2005-08-15 01:34:37 +02:00
|
|
|
// send event to each handler (newest first) until one returns true
|
2006-08-26 23:52:18 +02:00
|
|
|
extern void in_dispatch_event(const SDL_Event_* event);
|
2005-08-15 01:34:37 +02:00
|
|
|
|
Improve correctness of hotkeys at low framerates.
SDL queues up all the input events received in a frame. When the hotkey
system saw a key up/down event, it immediately updated its
HotkeyIsPressed state and then pushed a hotkey event onto the end of the
queue.
If the initial queue was e.g. [key-down shift, key-press Z, key-up
shift], the hotkey event triggered by Z would be processed after the
key-up shift had updated the HotkeyIsPressed state, so the handler of
the Z hotkey would not think the shift hotkey was pressed.
If the initial queue was e.g. [key-press Z, mouse-click], the hotkey
triggered by Z would be processed after the mouse-click event, so it
could apply to the wrong building selection.
Fix by pushing the hotkey events onto a special queue that gets
processed before any subsequent SDL input events.
Also update the HotkeyIsPressed status when the HOTKEYDOWN/HOTKEYUP
events are processed, not when they are generated, to guarantee they are
consistent with the DOWN/UP events.
Fixes #1869.
This was SVN commit r14057.
2013-10-30 02:38:32 +01:00
|
|
|
// push an event onto the back of a high-priority queue - the new event will
|
|
|
|
// be returned by in_poll_event before any standard SDL events
|
|
|
|
extern void in_push_priority_event(const SDL_Event_* event);
|
|
|
|
|
|
|
|
// reads events that were pushed by in_push_priority_event, or (if there are
|
|
|
|
// no high-priority events) reads from the SDL event queue with SDL_PollEvent.
|
|
|
|
// returns 1 if an event was read, 0 otherwise.
|
|
|
|
extern int in_poll_event(SDL_Event_* event);
|
|
|
|
|
2007-05-07 18:33:24 +02:00
|
|
|
#endif // #ifndef INCLUDED_INPUT
|