Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
emscripten-core
GitHub Repository: emscripten-core/emscripten
Path: blob/main/system/include/SDL/SDL_joystick.h
6169 views
1
/*
2
Simple DirectMedia Layer
3
Copyright (C) 1997-2011 Sam Lantinga <[email protected]>
4
5
This software is provided 'as-is', without any express or implied
6
warranty. In no event will the authors be held liable for any damages
7
arising from the use of this software.
8
9
Permission is granted to anyone to use this software for any purpose,
10
including commercial applications, and to alter it and redistribute it
11
freely, subject to the following restrictions:
12
13
1. The origin of this software must not be misrepresented; you must not
14
claim that you wrote the original software. If you use this software
15
in a product, an acknowledgment in the product documentation would be
16
appreciated but is not required.
17
2. Altered source versions must be plainly marked as such, and must not be
18
misrepresented as being the original software.
19
3. This notice may not be removed or altered from any source distribution.
20
*/
21
22
/**
23
* \file SDL_joystick.h
24
*
25
* Include file for SDL joystick event handling
26
*/
27
28
#ifndef _SDL_joystick_h
29
#define _SDL_joystick_h
30
31
#include "SDL_stdinc.h"
32
#include "SDL_error.h"
33
34
#include "begin_code.h"
35
/* Set up for C function definitions, even when using C++ */
36
#ifdef __cplusplus
37
/* *INDENT-OFF* */
38
extern "C" {
39
/* *INDENT-ON* */
40
#endif
41
42
/**
43
* \file SDL_joystick.h
44
*
45
* In order to use these functions, SDL_Init() must have been called
46
* with the ::SDL_INIT_JOYSTICK flag. This causes SDL to scan the system
47
* for joysticks, and load appropriate drivers.
48
*/
49
50
/* The joystick structure used to identify an SDL joystick */
51
struct _SDL_Joystick;
52
typedef struct _SDL_Joystick SDL_Joystick;
53
54
55
/* Function prototypes */
56
/**
57
* Count the number of joysticks attached to the system
58
*/
59
extern DECLSPEC int SDLCALL SDL_NumJoysticks(void);
60
61
/**
62
* Get the implementation dependent name of a joystick.
63
* This can be called before any joysticks are opened.
64
* If no name can be found, this function returns NULL.
65
*/
66
extern DECLSPEC const char *SDLCALL SDL_JoystickName(int device_index);
67
68
/**
69
* Open a joystick for use.
70
* The index passed as an argument refers tothe N'th joystick on the system.
71
* This index is the value which will identify this joystick in future joystick
72
* events.
73
*
74
* \return A joystick identifier, or NULL if an error occurred.
75
*/
76
extern DECLSPEC SDL_Joystick *SDLCALL SDL_JoystickOpen(int device_index);
77
78
/**
79
* Returns 1 if the joystick has been opened, or 0 if it has not.
80
*/
81
extern DECLSPEC int SDLCALL SDL_JoystickOpened(int device_index);
82
83
/**
84
* Get the device index of an opened joystick.
85
*/
86
extern DECLSPEC int SDLCALL SDL_JoystickIndex(SDL_Joystick * joystick);
87
88
/**
89
* Get the number of general axis controls on a joystick.
90
*/
91
extern DECLSPEC int SDLCALL SDL_JoystickNumAxes(SDL_Joystick * joystick);
92
93
/**
94
* Get the number of trackballs on a joystick.
95
*
96
* Joystick trackballs have only relative motion events associated
97
* with them and their state cannot be polled.
98
*/
99
extern DECLSPEC int SDLCALL SDL_JoystickNumBalls(SDL_Joystick * joystick);
100
101
/**
102
* Get the number of POV hats on a joystick.
103
*/
104
extern DECLSPEC int SDLCALL SDL_JoystickNumHats(SDL_Joystick * joystick);
105
106
/**
107
* Get the number of buttons on a joystick.
108
*/
109
extern DECLSPEC int SDLCALL SDL_JoystickNumButtons(SDL_Joystick * joystick);
110
111
/**
112
* Update the current state of the open joysticks.
113
*
114
* This is called automatically by the event loop if any joystick
115
* events are enabled.
116
*/
117
extern DECLSPEC void SDLCALL SDL_JoystickUpdate(void);
118
119
/**
120
* Enable/disable joystick event polling.
121
*
122
* If joystick events are disabled, you must call SDL_JoystickUpdate()
123
* yourself and check the state of the joystick when you want joystick
124
* information.
125
*
126
* The state can be one of ::SDL_QUERY, ::SDL_ENABLE or ::SDL_IGNORE.
127
*/
128
extern DECLSPEC int SDLCALL SDL_JoystickEventState(int state);
129
130
/**
131
* Get the current state of an axis control on a joystick.
132
*
133
* The state is a value ranging from -32768 to 32767.
134
*
135
* The axis indices start at index 0.
136
*/
137
extern DECLSPEC Sint16 SDLCALL SDL_JoystickGetAxis(SDL_Joystick * joystick,
138
int axis);
139
140
/**
141
* \name Hat positions
142
*/
143
/*@{*/
144
#define SDL_HAT_CENTERED 0x00
145
#define SDL_HAT_UP 0x01
146
#define SDL_HAT_RIGHT 0x02
147
#define SDL_HAT_DOWN 0x04
148
#define SDL_HAT_LEFT 0x08
149
#define SDL_HAT_RIGHTUP (SDL_HAT_RIGHT|SDL_HAT_UP)
150
#define SDL_HAT_RIGHTDOWN (SDL_HAT_RIGHT|SDL_HAT_DOWN)
151
#define SDL_HAT_LEFTUP (SDL_HAT_LEFT|SDL_HAT_UP)
152
#define SDL_HAT_LEFTDOWN (SDL_HAT_LEFT|SDL_HAT_DOWN)
153
/*@}*/
154
155
/**
156
* Get the current state of a POV hat on a joystick.
157
*
158
* The hat indices start at index 0.
159
*
160
* \return The return value is one of the following positions:
161
* - ::SDL_HAT_CENTERED
162
* - ::SDL_HAT_UP
163
* - ::SDL_HAT_RIGHT
164
* - ::SDL_HAT_DOWN
165
* - ::SDL_HAT_LEFT
166
* - ::SDL_HAT_RIGHTUP
167
* - ::SDL_HAT_RIGHTDOWN
168
* - ::SDL_HAT_LEFTUP
169
* - ::SDL_HAT_LEFTDOWN
170
*/
171
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetHat(SDL_Joystick * joystick,
172
int hat);
173
174
/**
175
* Get the ball axis change since the last poll.
176
*
177
* \return 0, or -1 if you passed it invalid parameters.
178
*
179
* The ball indices start at index 0.
180
*/
181
extern DECLSPEC int SDLCALL SDL_JoystickGetBall(SDL_Joystick * joystick,
182
int ball, int *dx, int *dy);
183
184
/**
185
* Get the current state of a button on a joystick.
186
*
187
* The button indices start at index 0.
188
*/
189
extern DECLSPEC Uint8 SDLCALL SDL_JoystickGetButton(SDL_Joystick * joystick,
190
int button);
191
192
/**
193
* Close a joystick previously opened with SDL_JoystickOpen().
194
*/
195
extern DECLSPEC void SDLCALL SDL_JoystickClose(SDL_Joystick * joystick);
196
197
198
/* Ends C function definitions when using C++ */
199
#ifdef __cplusplus
200
/* *INDENT-OFF* */
201
}
202
/* *INDENT-ON* */
203
#endif
204
#include "close_code.h"
205
206
#endif /* _SDL_joystick_h */
207
208
/* vi: set ts=4 sw=4 expandtab: */
209
210