-
-
Notifications
You must be signed in to change notification settings - Fork 31
/
api_event.h
128 lines (112 loc) · 4 KB
/
api_event.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
/** @file api_event.h Public API for input events and bindings.
* @ingroup input
*
* @authors Copyright © 2013-2017 Jaakko Keränen <jaakko.keranen@iki.fi>
* @authors Copyright © 2013-2014 Daniel Swanson <danij@dengine.net>
*
* @par License
* GPL: http://www.gnu.org/licenses/gpl.html
*
* <small>This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version. 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. See the GNU General
* Public License for more details. You should have received a copy of the GNU
* General Public License along with this program; if not, see:
* http://www.gnu.org/licenses</small>
*/
#ifndef DOOMSDAY_API_EVENT_H
#define DOOMSDAY_API_EVENT_H
#include "api_base.h"
/// Event types. @ingroup input
typedef enum {
EV_KEY,
EV_MOUSE_AXIS,
EV_MOUSE_BUTTON,
EV_JOY_AXIS, ///< Joystick main axes (xyz + Rxyz).
EV_JOY_SLIDER, ///< Joystick sliders.
EV_JOY_BUTTON,
EV_POV,
EV_SYMBOLIC, ///< Symbol text pointed to by data_u64 (data1+data2).
EV_FOCUS, ///< Change in game window focus (data1=gained, data2=windowID).
NUM_EVENT_TYPES
} evtype_t;
/// Event states. @ingroup input
typedef enum {
EVS_DOWN,
EVS_UP,
EVS_REPEAT,
NUM_EVENT_STATES
} evstate_t;
/// Input event. @ingroup input
typedef struct event_s {
evtype_t type;
evstate_t state; ///< Only used with digital controls.
union {
struct {
int data1; ///< Keys/mouse/joystick buttons.
int data2; ///< Mouse/joystick x move.
};
uint64_t data_u64;
};
int data3; ///< Mouse/joystick y move.
int data4;
int data5;
int data6;
} event_t;
/// The mouse wheel is considered two extra mouse buttons.
#define DD_MWHEEL_UP 3
#define DD_MWHEEL_DOWN 4
#define DD_MICKEY_ACCURACY 1000
/// @addtogroup bindings
///@{
DE_API_TYPEDEF(B)
{
de_api_t api;
void (*SetContextFallback)(char const *name, int (*responderFunc)(event_t *));
/**
* Looks through the bindings to find the ones that are bound to the
* specified command. The result is a space-separated list of bindings
* such as (idnum is the binding ID number):
*
* <tt>idnum@@game:key-space-down idnum@@game:key-e-down</tt>
*
* @param cmd Command to look for.
* @param buf Output buffer for the result.
* @param bufSize Size of output buffer.
*
* @return Number of bindings found for the command.
*/
int (*BindingsForCommand)(char const *cmd, char *buf, size_t bufSize);
/**
* Looks through the bindings to find the ones that are bound to the
* specified control. The result is a space-separated list of bindings.
*
* @param localPlayer Number of the local player (first one always 0).
* @param controlName Name of the player control.
* @param inverse One of BFCI_*.
* @param buf Output buffer for the result.
* @param bufSize Size of output buffer.
*
* @return Number of bindings found for the command.
*/
int (*BindingsForControl)(int localPlayer, char const *controlName, int inverse, char *buf, size_t bufSize);
/**
* Return the key code that corresponds the given key identifier name.
*/
int (*GetKeyCode)(const char* name);
}
DE_API_T(B);
#ifndef DE_NO_API_MACROS_BINDING
#define B_SetContextFallback _api_B.SetContextFallback
#define B_BindingsForCommand _api_B.BindingsForCommand
#define B_BindingsForControl _api_B.BindingsForControl
#define DD_GetKeyCode _api_B.GetKeyCode
#endif
#ifdef __DOOMSDAY__
DE_USING_API(B);
#endif
///@}
#endif // DOOMSDAY_API_EVENT_H