Pyrogenesis
13997
Main Page
Related Pages
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Friends
Macros
Pages
source
lib
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
33
#include "
lib/external_libraries/libsdl.h
"
34
35
const
size_t
MAX_HANDLERS
= 8;
36
static
InHandler
handler_stack
[
MAX_HANDLERS
];
37
static
size_t
handler_stack_top
= 0;
38
39
void
in_add_handler
(
InHandler
handler
)
40
{
41
ENSURE
(handler);
42
43
if
(
handler_stack_top
>=
MAX_HANDLERS
)
44
WARN_IF_ERR
(
ERR::LIMIT
);
45
46
handler_stack
[
handler_stack_top
++] =
handler
;
47
}
48
49
void
in_reset_handlers
()
50
{
51
handler_stack_top
= 0;
52
}
53
54
// send ev to each handler until one returns IN_HANDLED
55
void
in_dispatch_event
(
const
SDL_Event_
* ev)
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
}
ERR::LOGIC
const Status LOGIC
Definition:
status.h:409
libsdl.h
WARN_IF_ERR
#define WARN_IF_ERR(expression)
Definition:
status.h:265
input.h
in_dispatch_event
void in_dispatch_event(const SDL_Event_ *ev)
Definition:
input.cpp:55
precompiled.h
InHandler
InReaction(* InHandler)(const SDL_Event_ *)
Definition:
input.h:46
in_add_handler
void in_add_handler(InHandler handler)
Definition:
input.cpp:39
handler_stack_top
static size_t handler_stack_top
Definition:
input.cpp:37
vm::handler
static PVOID handler
Definition:
wvm.cpp:515
SDL_Event_
Definition:
libsdl.h:54
IN_HANDLED
Definition:
input.h:43
ENSURE
#define ENSURE(expr)
ensure the expression <expr> evaluates to non-zero.
Definition:
debug.h:282
in_reset_handlers
void in_reset_handlers()
Definition:
input.cpp:49
ERR::LIMIT
const Status LIMIT
Definition:
status.h:428
InReaction
InReaction
Definition:
input.h:34
IN_PASS
Definition:
input.h:40
DEBUG_WARN_ERR
#define DEBUG_WARN_ERR(status)
display the error dialog with text corresponding to the given error code.
Definition:
debug.h:331
handler_stack
static InHandler handler_stack[MAX_HANDLERS]
Definition:
input.cpp:36
MAX_HANDLERS
const size_t MAX_HANDLERS
Definition:
input.cpp:35
Generated on Mon Oct 14 2013 00:58:07 for Pyrogenesis by
1.8.5