21 #include "../SDL_internal.h" 31 #if !SDL_EVENTS_DISABLED 32 #include "../events/SDL_events_c.h" 42 if (hint && *hint ==
'1') {
58 #if !SDL_EVENTS_DISABLED 104 SDL_Joystick *joysticklist;
105 const char *joystickname =
NULL;
116 while (joysticklist) {
118 joystick = joysticklist;
119 ++joystick->ref_count;
122 joysticklist = joysticklist->next;
126 joystick = (SDL_Joystick *)
SDL_malloc((
sizeof *joystick));
127 if (joystick ==
NULL) {
142 joystick->name =
NULL;
144 if (joystick->naxes > 0) {
146 (joystick->naxes *
sizeof(
Sint16));
148 if (joystick->nhats > 0) {
150 (joystick->nhats *
sizeof(
Uint8));
152 if (joystick->nballs > 0) {
153 joystick->balls = (
struct balldelta *)
SDL_malloc 154 (joystick->nballs *
sizeof(*joystick->balls));
156 if (joystick->nbuttons > 0) {
158 (joystick->nbuttons *
sizeof(
Uint8));
160 if (((joystick->naxes > 0) && !joystick->axes)
161 || ((joystick->nhats > 0) && !joystick->hats)
162 || ((joystick->nballs > 0) && !joystick->balls)
163 || ((joystick->nbuttons > 0) && !joystick->buttons)) {
168 if (joystick->axes) {
171 if (joystick->hats) {
174 if (joystick->balls) {
176 joystick->nballs *
sizeof(*joystick->balls));
178 if (joystick->buttons) {
184 ++joystick->ref_count;
203 if (joystick ==
NULL) {
222 return (joystick->naxes);
234 return (joystick->nhats);
246 return (joystick->nballs);
258 return (joystick->nbuttons);
272 if (axis < joystick->naxes) {
273 state = joystick->axes[
axis];
275 SDL_SetError(
"Joystick only has %d axes", joystick->naxes);
292 if (hat < joystick->nhats) {
293 state = joystick->hats[hat];
295 SDL_SetError(
"Joystick only has %d hats", joystick->nhats);
314 if (ball < joystick->nballs) {
316 *dx = joystick->balls[ball].dx;
319 *dy = joystick->balls[ball].dy;
321 joystick->balls[ball].dx = 0;
322 joystick->balls[ball].dy = 0;
324 return SDL_SetError(
"Joystick only has %d balls", joystick->nballs);
340 if (button < joystick->nbuttons) {
341 state = joystick->buttons[
button];
343 SDL_SetError(
"Joystick only has %d buttons", joystick->nbuttons);
373 return (joystick->instance_id);
384 if (joystick->instance_id == joyid) {
387 joystick = joystick->next;
403 return (joystick->name);
412 SDL_Joystick *joysticklist;
413 SDL_Joystick *joysticklistprev;
420 if (--joystick->ref_count > 0) {
429 joystick->hwdata =
NULL;
432 joysticklistprev =
NULL;
433 while (joysticklist) {
434 if (joystick == joysticklist) {
435 if (joysticklistprev) {
437 joysticklistprev->next = joysticklist->next;
443 joysticklistprev = joysticklist;
444 joysticklist = joysticklist->next;
472 #if !SDL_EVENTS_DISABLED 506 if (axis >= joystick->naxes) {
509 if (value == joystick->axes[axis]) {
517 if ((value > 0 && value >= joystick->axes[axis]) ||
528 #if !SDL_EVENTS_DISABLED 532 event.jaxis.which = joystick->instance_id;
533 event.jaxis.axis =
axis;
534 event.jaxis.value =
value;
547 if (hat >= joystick->nhats) {
550 if (value == joystick->hats[hat]) {
564 joystick->hats[hat] =
value;
568 #if !SDL_EVENTS_DISABLED 572 event.jhat.which = joystick->instance_id;
573 event.jhat.hat = hat;
574 event.jhat.value =
value;
588 if (ball >= joystick->nballs) {
598 joystick->balls[ball].dx += xrel;
599 joystick->balls[ball].dy += yrel;
603 #if !SDL_EVENTS_DISABLED 607 event.jball.which = joystick->instance_id;
608 event.jball.ball = ball;
609 event.jball.xrel = xrel;
610 event.jball.yrel = yrel;
621 #if !SDL_EVENTS_DISABLED 638 if (button >= joystick->nbuttons) {
641 if (state == joystick->buttons[button]) {
658 #if !SDL_EVENTS_DISABLED 660 event.jbutton.which = joystick->instance_id;
661 event.jbutton.button =
button;
662 event.jbutton.state =
state;
672 SDL_Joystick *joystick;
676 SDL_Joystick *joysticknext;
680 joysticknext = joystick->next;
686 if (joystick->force_recentering) {
690 for (i = 0; i < joystick->naxes; i++) {
694 for (i = 0; i < joystick->nbuttons; i++) {
698 for (i = 0; i < joystick->nhats; i++) {
708 if (joystick->ref_count <= 0) {
712 joystick = joysticknext;
724 #if SDL_EVENTS_DISABLED 727 const Uint32 event_list[] = {
779 static const char k_rgchHexToASCII[] =
"0123456789abcdef";
782 if ((pszGUID ==
NULL) || (cbGUID <= 0)) {
786 for (i = 0; i <
sizeof(guid.
data) && i < (cbGUID-1)/2; i++) {
789 unsigned char c = guid.
data[
i];
791 *pszGUID++ = k_rgchHexToASCII[c >> 4];
792 *pszGUID++ = k_rgchHexToASCII[c & 0x0F];
805 if ((c >=
'0') && (c <=
'9')) {
806 return (
unsigned char)(c -
'0');
809 if ((c >=
'A') && (c <=
'F')) {
810 return (
unsigned char)(c -
'A' + 0x0a);
813 if ((c >=
'a') && (c <=
'f')) {
814 return (
unsigned char)(c -
'a' + 0x0a);
827 int maxoutputbytes=
sizeof(guid);
838 for (i = 0; (i <
len) && ((p - (
Uint8 *)&guid) < maxoutputbytes); i+=2, p++) {
849 joystick->epowerlevel = ePowerLevel;
859 return joystick->epowerlevel;
void SDL_JoystickUpdate(void)
#define SDL_HINT_JOYSTICK_ALLOW_BACKGROUND_EVENTS
A variable that lets you enable joystick (and gamecontroller) events even when your app is in the bac...
int SDL_JoystickGetBall(SDL_Joystick *joystick, int ball, int *dx, int *dy)
int SDL_PrivateJoystickValid(SDL_Joystick *joystick)
static SDL_Joystick * SDL_updating_joystick
GLuint GLfloat GLfloat GLfloat x1
void SDL_JoystickClose(SDL_Joystick *joystick)
uint32_t Uint32
An unsigned 32-bit integer type.
int SDL_PrivateJoystickHat(SDL_Joystick *joystick, Uint8 hat, Uint8 value)
int SDL_SYS_NumJoysticks()
#define SDL_QuitSubSystem
int SDL_JoystickInit(void)
int SDL_PrivateJoystickButton(SDL_Joystick *joystick, Uint8 button, Uint8 state)
int SDL_JoystickNumHats(SDL_Joystick *joystick)
#define SDL_InitSubSystem
GLuint const GLchar * name
void SDL_SYS_JoystickQuit(void)
#define SDL_GetKeyboardFocus
int SDL_PrivateJoystickAxis(SDL_Joystick *joystick, Uint8 axis, Sint16 value)
SDL_JoystickPowerLevel SDL_JoystickCurrentPowerLevel(SDL_Joystick *joystick)
const char * SDL_JoystickName(SDL_Joystick *joystick)
int SDL_JoystickEventState(int state)
int SDL_PrivateJoystickBall(SDL_Joystick *joystick, Uint8 ball, Sint16 xrel, Sint16 yrel)
int SDL_NumJoysticks(void)
static SDL_bool SDL_joystick_allows_background_events
#define SDL_GetEventState(type)
GLsizei const GLfloat * value
uint8_t Uint8
An unsigned 8-bit integer type.
SDL_bool SDL_SYS_JoystickAttached(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_JoystickGetGUID(SDL_Joystick *joystick)
void SDL_SYS_JoystickDetect()
const char * SDL_SYS_JoystickNameForDeviceIndex(int device_index)
SDL_Joystick * SDL_JoystickOpen(int device_index)
int SDL_JoystickNumAxes(SDL_Joystick *joystick)
void SDL_SYS_JoystickUpdate(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetGUID(SDL_Joystick *joystick)
SDL_Joystick * SDL_JoystickFromInstanceID(SDL_JoystickID joyid)
return Display return Display Bool Bool int int int return Display XEvent Bool(*) XPointer return Display return Display Drawable _Xconst char unsigned int unsigned int return Display Pixmap Pixmap XColor XColor unsigned int unsigned int return Display _Xconst char char int char return Display Visual unsigned int int int char unsigned int unsigned int in i)
#define SDL_assert(condition)
int SDL_SYS_JoystickInit(void)
SDL_JoystickGUID SDL_JoystickGetDeviceGUID(int device_index)
SDL_JoystickGUID SDL_JoystickGetGUIDFromString(const char *pchGUID)
int SDL_JoystickNumBalls(SDL_Joystick *joystick)
#define SDL_OutOfMemory()
static unsigned char nibble(char c)
SDL_JoystickID SDL_JoystickInstanceID(SDL_Joystick *joystick)
void SDL_PrivateJoystickBatteryLevel(SDL_Joystick *joystick, SDL_JoystickPowerLevel ePowerLevel)
#define SDL_AddHintCallback
int SDL_JoystickNumButtons(SDL_Joystick *joystick)
void SDL_JoystickGetGUIDString(SDL_JoystickGUID guid, char *pszGUID, int cbGUID)
SDL_JoystickID SDL_SYS_GetInstanceIdOfDeviceIndex(int device_index)
static SDL_bool SDL_PrivateJoystickShouldIgnoreEvent()
#define SDL_arraysize(array)
int SDL_SYS_JoystickOpen(SDL_Joystick *joystick, int device_index)
Uint8 SDL_JoystickGetButton(SDL_Joystick *joystick, int button)
Uint8 SDL_JoystickGetHat(SDL_Joystick *joystick, int hat)
void SDL_JoystickQuit(void)
static void SDL_JoystickAllowBackgroundEventsChanged(void *userdata, const char *name, const char *oldValue, const char *hint)
SDL_bool SDL_JoystickGetAttached(SDL_Joystick *joystick)
void SDL_SYS_JoystickClose(SDL_Joystick *joystick)
SDL_JoystickGUID SDL_SYS_JoystickGetDeviceGUID(int device_index)
const char * SDL_JoystickNameForIndex(int device_index)
int16_t Sint16
A signed 16-bit integer type.
static SDL_Joystick * SDL_joysticks
Sint16 SDL_JoystickGetAxis(SDL_Joystick *joystick, int axis)