Pyrogenesis  13997
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
input.cpp
Go to the documentation of this file.
1 /* Copyright (c) 2012 Wildfire Games
2  *
3  * Permission is hereby granted, free of charge, to any person obtaining
4  * a copy of this software and associated documentation files (the
5  * "Software"), to deal in the Software without restriction, including
6  * without limitation the rights to use, copy, modify, merge, publish,
7  * distribute, sublicense, and/or sell copies of the Software, and to
8  * permit persons to whom the Software is furnished to do so, subject to
9  * the following conditions:
10  *
11  * The above copyright notice and this permission notice shall be included
12  * in all copies or substantial portions of the Software.
13  *
14  * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15  * EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16  * MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
17  * IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
18  * CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
19  * TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
20  * SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
21  */
22 
23 /*
24  * SDL input redirector; dispatches to multiple handlers.
25  */
26 
27 #include "precompiled.h"
28 #include "input.h"
29 
30 #include <stdio.h>
31 #include <stdlib.h>
32 
34 
35 const size_t MAX_HANDLERS = 8;
37 static size_t handler_stack_top = 0;
38 
40 {
41  ENSURE(handler);
42 
45 
47 }
48 
50 {
52 }
53 
54 // send ev to each handler until one returns IN_HANDLED
56 {
57  for(int i = (int)handler_stack_top-1; i >= 0; i--)
58  {
59  ENSURE(handler_stack[i] && ev);
60  InReaction ret = handler_stack[i](ev);
61  // .. done, return
62  if(ret == IN_HANDLED)
63  return;
64  // .. next handler
65  else if(ret == IN_PASS)
66  continue;
67  // .. invalid return value
68  else
69  DEBUG_WARN_ERR(ERR::LOGIC); // invalid handler return value
70  }
71 }
const Status LOGIC
Definition: status.h:409
#define WARN_IF_ERR(expression)
Definition: status.h:265
void in_dispatch_event(const SDL_Event_ *ev)
Definition: input.cpp:55
InReaction(* InHandler)(const SDL_Event_ *)
Definition: input.h:46
void in_add_handler(InHandler handler)
Definition: input.cpp:39
static size_t handler_stack_top
Definition: input.cpp:37
static PVOID handler
Definition: wvm.cpp:515
#define ENSURE(expr)
ensure the expression &lt;expr&gt; evaluates to non-zero.
Definition: debug.h:282
void in_reset_handlers()
Definition: input.cpp:49
const Status LIMIT
Definition: status.h:428
InReaction
Definition: input.h:34
Definition: input.h:40
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
Definition: debug.h:331
static InHandler handler_stack[MAX_HANDLERS]
Definition: input.cpp:36
const size_t MAX_HANDLERS
Definition: input.cpp:35