mirror of
https://github.com/love2d/megasource.git
synced 2026-08-17 11:11:35 +02:00
Update SDL to 2.0.7
This commit is contained in:
+559
-215
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
Copyright (C) 1997-2016 Sam Lantinga <slouken@libsdl.org>
|
||||
Copyright (C) 1997-2017 Sam Lantinga <slouken@libsdl.org>
|
||||
|
||||
This software is provided 'as-is', without any express or implied
|
||||
warranty. In no event will the authors be held liable for any damages
|
||||
@@ -32,16 +32,124 @@
|
||||
#define MARKER_BUTTON 1
|
||||
#define MARKER_AXIS 2
|
||||
|
||||
typedef struct MappingStep
|
||||
enum
|
||||
{
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE,
|
||||
SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT,
|
||||
SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT,
|
||||
SDL_CONTROLLER_BINDING_AXIS_MAX,
|
||||
};
|
||||
|
||||
#define BINDING_COUNT (SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_MAX)
|
||||
|
||||
static struct
|
||||
{
|
||||
int x, y;
|
||||
double angle;
|
||||
int marker;
|
||||
char *field;
|
||||
int axis, button, hat, hat_value;
|
||||
char mapping[4096];
|
||||
}MappingStep;
|
||||
|
||||
} s_arrBindingDisplay[BINDING_COUNT] = {
|
||||
{ 387, 167, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_A */
|
||||
{ 431, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_B */
|
||||
{ 342, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_X */
|
||||
{ 389, 101, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_Y */
|
||||
{ 174, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_BACK */
|
||||
{ 233, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_GUIDE */
|
||||
{ 289, 132, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_START */
|
||||
{ 75, 154, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSTICK */
|
||||
{ 305, 230, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSTICK */
|
||||
{ 77, 40, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_LEFTSHOULDER */
|
||||
{ 396, 36, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_RIGHTSHOULDER */
|
||||
{ 154, 188, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_UP */
|
||||
{ 154, 249, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_DOWN */
|
||||
{ 116, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_LEFT */
|
||||
{ 186, 217, 0.0, MARKER_BUTTON }, /* SDL_CONTROLLER_BUTTON_DPAD_RIGHT */
|
||||
{ 74, 153, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE */
|
||||
{ 74, 153, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE */
|
||||
{ 74, 153, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE */
|
||||
{ 74, 153, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE */
|
||||
{ 306, 231, 270.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE */
|
||||
{ 306, 231, 90.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE */
|
||||
{ 306, 231, 0.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE */
|
||||
{ 306, 231, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE */
|
||||
{ 91, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT */
|
||||
{ 375, -20, 180.0, MARKER_AXIS }, /* SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT */
|
||||
};
|
||||
|
||||
static int s_arrBindingOrder[BINDING_COUNT] = {
|
||||
SDL_CONTROLLER_BUTTON_A,
|
||||
SDL_CONTROLLER_BUTTON_B,
|
||||
SDL_CONTROLLER_BUTTON_Y,
|
||||
SDL_CONTROLLER_BUTTON_X,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_LEFTSTICK,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE,
|
||||
SDL_CONTROLLER_BUTTON_RIGHTSTICK,
|
||||
SDL_CONTROLLER_BUTTON_LEFTSHOULDER,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT,
|
||||
SDL_CONTROLLER_BUTTON_RIGHTSHOULDER,
|
||||
SDL_CONTROLLER_BUTTON_MAX + SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_UP,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_RIGHT,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_DOWN,
|
||||
SDL_CONTROLLER_BUTTON_DPAD_LEFT,
|
||||
SDL_CONTROLLER_BUTTON_BACK,
|
||||
SDL_CONTROLLER_BUTTON_GUIDE,
|
||||
SDL_CONTROLLER_BUTTON_START,
|
||||
};
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_GameControllerBindType bindType;
|
||||
union
|
||||
{
|
||||
int button;
|
||||
|
||||
struct {
|
||||
int axis;
|
||||
int axis_min;
|
||||
int axis_max;
|
||||
} axis;
|
||||
|
||||
struct {
|
||||
int hat;
|
||||
int hat_mask;
|
||||
} hat;
|
||||
|
||||
} value;
|
||||
|
||||
SDL_bool committed;
|
||||
|
||||
} SDL_GameControllerExtendedBind;
|
||||
|
||||
static SDL_GameControllerExtendedBind s_arrBindings[BINDING_COUNT];
|
||||
|
||||
typedef struct
|
||||
{
|
||||
SDL_bool m_bMoving;
|
||||
int m_nStartingValue;
|
||||
int m_nFarthestValue;
|
||||
} AxisState;
|
||||
|
||||
static int s_nNumAxes;
|
||||
static AxisState *s_arrAxisState;
|
||||
|
||||
static int s_iCurrentBinding;
|
||||
static Uint32 s_unPendingAdvanceTime;
|
||||
static SDL_bool s_bBindingComplete;
|
||||
|
||||
SDL_Texture *
|
||||
LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
@@ -60,23 +168,6 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
if (transparent) {
|
||||
if (temp->format->palette) {
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint8 *) temp->pixels);
|
||||
} else {
|
||||
switch (temp->format->BitsPerPixel) {
|
||||
case 15:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint16 *) temp->pixels) & 0x00007FFF);
|
||||
break;
|
||||
case 16:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint16 *) temp->pixels);
|
||||
break;
|
||||
case 24:
|
||||
SDL_SetColorKey(temp, SDL_TRUE,
|
||||
(*(Uint32 *) temp->pixels) & 0x00FFFFFF);
|
||||
break;
|
||||
case 32:
|
||||
SDL_SetColorKey(temp, SDL_TRUE, *(Uint32 *) temp->pixels);
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,45 +184,186 @@ LoadTexture(SDL_Renderer *renderer, const char *file, SDL_bool transparent)
|
||||
return texture;
|
||||
}
|
||||
|
||||
static int
|
||||
StandardizeAxisValue(int nValue)
|
||||
{
|
||||
if (nValue > SDL_JOYSTICK_AXIS_MAX/2) {
|
||||
return SDL_JOYSTICK_AXIS_MAX;
|
||||
} else if (nValue < SDL_JOYSTICK_AXIS_MIN/2) {
|
||||
return SDL_JOYSTICK_AXIS_MIN;
|
||||
} else {
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
SetCurrentBinding(int iBinding)
|
||||
{
|
||||
int iIndex;
|
||||
SDL_GameControllerExtendedBind *pBinding;
|
||||
|
||||
if (iBinding < 0) {
|
||||
return;
|
||||
}
|
||||
|
||||
if (iBinding == BINDING_COUNT) {
|
||||
s_bBindingComplete = SDL_TRUE;
|
||||
return;
|
||||
}
|
||||
|
||||
s_iCurrentBinding = iBinding;
|
||||
|
||||
pBinding = &s_arrBindings[s_arrBindingOrder[s_iCurrentBinding]];
|
||||
SDL_zerop(pBinding);
|
||||
|
||||
for (iIndex = 0; iIndex < s_nNumAxes; ++iIndex) {
|
||||
s_arrAxisState[iIndex].m_nFarthestValue = s_arrAxisState[iIndex].m_nStartingValue;
|
||||
}
|
||||
|
||||
s_unPendingAdvanceTime = 0;
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
BBindingContainsBinding(const SDL_GameControllerExtendedBind *pBindingA, const SDL_GameControllerExtendedBind *pBindingB)
|
||||
{
|
||||
if (pBindingA->bindType != pBindingB->bindType)
|
||||
{
|
||||
return SDL_FALSE;
|
||||
}
|
||||
switch (pBindingA->bindType)
|
||||
{
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
if (pBindingA->value.axis.axis != pBindingB->value.axis.axis) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
if (!pBindingA->committed) {
|
||||
return SDL_FALSE;
|
||||
}
|
||||
{
|
||||
int minA = SDL_min(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
|
||||
int maxA = SDL_max(pBindingA->value.axis.axis_min, pBindingA->value.axis.axis_max);
|
||||
int minB = SDL_min(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
int maxB = SDL_max(pBindingB->value.axis.axis_min, pBindingB->value.axis.axis_max);
|
||||
return (minA <= minB && maxA >= maxB);
|
||||
}
|
||||
/* Not reached */
|
||||
default:
|
||||
return SDL_memcmp(pBindingA, pBindingB, sizeof(*pBindingA)) == 0;
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
ConfigureBinding(const SDL_GameControllerExtendedBind *pBinding)
|
||||
{
|
||||
SDL_GameControllerExtendedBind *pCurrent;
|
||||
int iIndex;
|
||||
int iCurrentElement = s_arrBindingOrder[s_iCurrentBinding];
|
||||
|
||||
/* Do we already have this binding? */
|
||||
for (iIndex = 0; iIndex < SDL_arraysize(s_arrBindings); ++iIndex) {
|
||||
pCurrent = &s_arrBindings[iIndex];
|
||||
if (BBindingContainsBinding(pCurrent, pBinding)) {
|
||||
if (iIndex == SDL_CONTROLLER_BUTTON_A && iCurrentElement != SDL_CONTROLLER_BUTTON_B) {
|
||||
/* Skip to the next binding */
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
return;
|
||||
}
|
||||
|
||||
if (iIndex == SDL_CONTROLLER_BUTTON_B) {
|
||||
/* Go back to the previous binding */
|
||||
SetCurrentBinding(s_iCurrentBinding - 1);
|
||||
return;
|
||||
}
|
||||
|
||||
/* Already have this binding, ignore it */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
switch ( pBinding->bindType )
|
||||
{
|
||||
case SDL_CONTROLLER_BINDTYPE_NONE:
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_BUTTON:
|
||||
SDL_Log("Configuring button binding for button %d\n", pBinding->value.button);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
SDL_Log("Configuring axis binding for axis %d %d/%d committed = %s\n", pBinding->value.axis.axis, pBinding->value.axis.axis_min, pBinding->value.axis.axis_max, pBinding->committed ? "true" : "false");
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_HAT:
|
||||
SDL_Log("Configuring hat binding for hat %d %d\n", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
}
|
||||
#endif /* DEBUG_CONTROLLERMAP */
|
||||
|
||||
/* Should the new binding override the existing one? */
|
||||
pCurrent = &s_arrBindings[iCurrentElement];
|
||||
if (pCurrent->bindType != SDL_CONTROLLER_BINDTYPE_NONE) {
|
||||
SDL_bool bNativeDPad, bCurrentDPad;
|
||||
SDL_bool bNativeAxis, bCurrentAxis;
|
||||
|
||||
bNativeDPad = (iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_UP ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_DOWN ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_LEFT ||
|
||||
iCurrentElement == SDL_CONTROLLER_BUTTON_DPAD_RIGHT);
|
||||
bCurrentDPad = (pCurrent->bindType == SDL_CONTROLLER_BINDTYPE_HAT);
|
||||
if (bNativeDPad && bCurrentDPad) {
|
||||
/* We already have a binding of the type we want, ignore the new one */
|
||||
return;
|
||||
}
|
||||
|
||||
bNativeAxis = (iCurrentElement >= SDL_CONTROLLER_BUTTON_MAX);
|
||||
bCurrentAxis = (pCurrent->bindType == SDL_CONTROLLER_BINDTYPE_AXIS);
|
||||
if (bNativeAxis == bCurrentAxis &&
|
||||
(pBinding->bindType != SDL_CONTROLLER_BINDTYPE_AXIS ||
|
||||
pBinding->value.axis.axis != pCurrent->value.axis.axis)) {
|
||||
/* We already have a binding of the type we want, ignore the new one */
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
*pCurrent = *pBinding;
|
||||
|
||||
if (pBinding->committed) {
|
||||
s_unPendingAdvanceTime = SDL_GetTicks();
|
||||
} else {
|
||||
s_unPendingAdvanceTime = 0;
|
||||
}
|
||||
}
|
||||
|
||||
static SDL_bool
|
||||
BMergeAxisBindings(int iIndex)
|
||||
{
|
||||
SDL_GameControllerExtendedBind *pBindingA = &s_arrBindings[iIndex];
|
||||
SDL_GameControllerExtendedBind *pBindingB = &s_arrBindings[iIndex+1];
|
||||
if (pBindingA->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingB->bindType == SDL_CONTROLLER_BINDTYPE_AXIS &&
|
||||
pBindingA->value.axis.axis == pBindingB->value.axis.axis) {
|
||||
if (pBindingA->value.axis.axis_min == pBindingB->value.axis.axis_min) {
|
||||
pBindingA->value.axis.axis_min = pBindingA->value.axis.axis_max;
|
||||
pBindingA->value.axis.axis_max = pBindingB->value.axis.axis_max;
|
||||
pBindingB->bindType = SDL_CONTROLLER_BINDTYPE_NONE;
|
||||
return SDL_TRUE;
|
||||
}
|
||||
}
|
||||
return SDL_FALSE;
|
||||
}
|
||||
|
||||
static void
|
||||
WatchJoystick(SDL_Joystick * joystick)
|
||||
{
|
||||
SDL_Window *window = NULL;
|
||||
SDL_Renderer *screen = NULL;
|
||||
SDL_Texture *background, *button, *axis, *marker;
|
||||
const char *name = NULL;
|
||||
SDL_bool retval = SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE, next=SDL_FALSE;
|
||||
SDL_bool done = SDL_FALSE;
|
||||
SDL_Event event;
|
||||
SDL_Rect dst;
|
||||
int s, _s;
|
||||
Uint8 alpha=200, alpha_step = -1;
|
||||
Uint32 alpha_ticks = 0;
|
||||
char mapping[4096], temp[4096];
|
||||
MappingStep *step, *prev_step;
|
||||
MappingStep steps[] = {
|
||||
{342, 132, 0.0, MARKER_BUTTON, "x", -1, -1, -1, -1, ""},
|
||||
{387, 167, 0.0, MARKER_BUTTON, "a", -1, -1, -1, -1, ""},
|
||||
{431, 132, 0.0, MARKER_BUTTON, "b", -1, -1, -1, -1, ""},
|
||||
{389, 101, 0.0, MARKER_BUTTON, "y", -1, -1, -1, -1, ""},
|
||||
{174, 132, 0.0, MARKER_BUTTON, "back", -1, -1, -1, -1, ""},
|
||||
{233, 132, 0.0, MARKER_BUTTON, "guide", -1, -1, -1, -1, ""},
|
||||
{289, 132, 0.0, MARKER_BUTTON, "start", -1, -1, -1, -1, ""},
|
||||
{116, 217, 0.0, MARKER_BUTTON, "dpleft", -1, -1, -1, -1, ""},
|
||||
{154, 249, 0.0, MARKER_BUTTON, "dpdown", -1, -1, -1, -1, ""},
|
||||
{186, 217, 0.0, MARKER_BUTTON, "dpright", -1, -1, -1, -1, ""},
|
||||
{154, 188, 0.0, MARKER_BUTTON, "dpup", -1, -1, -1, -1, ""},
|
||||
{77, 40, 0.0, MARKER_BUTTON, "leftshoulder", -1, -1, -1, -1, ""},
|
||||
{91, 0, 0.0, MARKER_BUTTON, "lefttrigger", -1, -1, -1, -1, ""},
|
||||
{396, 36, 0.0, MARKER_BUTTON, "rightshoulder", -1, -1, -1, -1, ""},
|
||||
{375, 0, 0.0, MARKER_BUTTON, "righttrigger", -1, -1, -1, -1, ""},
|
||||
{75, 154, 0.0, MARKER_BUTTON, "leftstick", -1, -1, -1, -1, ""},
|
||||
{305, 230, 0.0, MARKER_BUTTON, "rightstick", -1, -1, -1, -1, ""},
|
||||
{75, 154, 0.0, MARKER_AXIS, "leftx", -1, -1, -1, -1, ""},
|
||||
{75, 154, 90.0, MARKER_AXIS, "lefty", -1, -1, -1, -1, ""},
|
||||
{305, 230, 0.0, MARKER_AXIS, "rightx", -1, -1, -1, -1, ""},
|
||||
{305, 230, 90.0, MARKER_AXIS, "righty", -1, -1, -1, -1, ""},
|
||||
};
|
||||
SDL_JoystickID nJoystickID;
|
||||
int iIndex;
|
||||
|
||||
/* Create a window to display joystick axis position */
|
||||
window = SDL_CreateWindow("Game Controller Map", SDL_WINDOWPOS_CENTERED,
|
||||
@@ -139,14 +371,14 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
SCREEN_HEIGHT, 0);
|
||||
if (window == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create window: %s\n", SDL_GetError());
|
||||
return SDL_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
screen = SDL_CreateRenderer(window, -1, 0);
|
||||
if (screen == NULL) {
|
||||
SDL_LogError(SDL_LOG_CATEGORY_APPLICATION, "Couldn't create renderer: %s\n", SDL_GetError());
|
||||
SDL_DestroyWindow(window);
|
||||
return SDL_FALSE;
|
||||
return;
|
||||
}
|
||||
|
||||
background = LoadTexture(screen, "controllermap.bmp", SDL_FALSE);
|
||||
@@ -173,23 +405,24 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
To skip a button, press SPACE or click/touch the screen\n\
|
||||
To exit, press ESC\n\
|
||||
====================================================================================\n");
|
||||
|
||||
/* Initialize mapping with GUID and name */
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), temp, SDL_arraysize(temp));
|
||||
SDL_snprintf(mapping, SDL_arraysize(mapping), "%s,%s,platform:%s,",
|
||||
temp, name ? name : "Unknown Joystick", SDL_GetPlatform());
|
||||
|
||||
nJoystickID = SDL_JoystickInstanceID(joystick);
|
||||
|
||||
s_nNumAxes = SDL_JoystickNumAxes(joystick);
|
||||
s_arrAxisState = (AxisState *)SDL_calloc(s_nNumAxes, sizeof(*s_arrAxisState));
|
||||
for (iIndex = 0; iIndex < s_nNumAxes; ++iIndex) {
|
||||
AxisState *pAxisState = &s_arrAxisState[iIndex];
|
||||
Sint16 nInitialValue;
|
||||
pAxisState->m_bMoving = SDL_JoystickGetAxisInitialState(joystick, iIndex, &nInitialValue);
|
||||
pAxisState->m_nStartingValue = nInitialValue;
|
||||
pAxisState->m_nFarthestValue = nInitialValue;
|
||||
}
|
||||
|
||||
/* Loop, getting joystick events! */
|
||||
for(s=0; s<SDL_arraysize(steps) && !done;) {
|
||||
/* blank screen, set up for drawing this frame. */
|
||||
step = &steps[s];
|
||||
SDL_strlcpy(step->mapping, mapping, SDL_arraysize(step->mapping));
|
||||
step->axis = -1;
|
||||
step->button = -1;
|
||||
step->hat = -1;
|
||||
step->hat_value = -1;
|
||||
|
||||
switch(step->marker) {
|
||||
while (!done && !s_bBindingComplete) {
|
||||
int iElement = s_arrBindingOrder[s_iCurrentBinding];
|
||||
|
||||
switch (s_arrBindingDisplay[iElement].marker) {
|
||||
case MARKER_AXIS:
|
||||
marker = axis;
|
||||
break;
|
||||
@@ -200,137 +433,271 @@ WatchJoystick(SDL_Joystick * joystick)
|
||||
break;
|
||||
}
|
||||
|
||||
dst.x = step->x;
|
||||
dst.y = step->y;
|
||||
dst.x = s_arrBindingDisplay[iElement].x;
|
||||
dst.y = s_arrBindingDisplay[iElement].y;
|
||||
SDL_QueryTexture(marker, NULL, NULL, &dst.w, &dst.h);
|
||||
next=SDL_FALSE;
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
|
||||
while (!done && !next) {
|
||||
if (SDL_GetTicks() - alpha_ticks > 5) {
|
||||
alpha_ticks = SDL_GetTicks();
|
||||
alpha += alpha_step;
|
||||
if (alpha == 255) {
|
||||
alpha_step = -1;
|
||||
}
|
||||
if (alpha < 128) {
|
||||
alpha_step = 1;
|
||||
}
|
||||
if (SDL_GetTicks() - alpha_ticks > 5) {
|
||||
alpha_ticks = SDL_GetTicks();
|
||||
alpha += alpha_step;
|
||||
if (alpha == 255) {
|
||||
alpha_step = -1;
|
||||
}
|
||||
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
SDL_SetTextureAlphaMod(marker, alpha);
|
||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, step->angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
if (SDL_PollEvent(&event)) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYAXISMOTION:
|
||||
if ((event.jaxis.value > 20000 || event.jaxis.value < -20000) && event.jaxis.value != -32768) {
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].axis == event.jaxis.axis) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->axis = event.jaxis.axis;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":a%u,", event.jaxis.axis);
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
if (event.jhat.value == SDL_HAT_CENTERED) {
|
||||
break; /* ignore centering, we're probably just coming back to the center from the previous item we set. */
|
||||
}
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].hat == event.jhat.hat && steps[_s].hat_value == event.jhat.value) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->hat = event.jhat.hat;
|
||||
step->hat_value = event.jhat.value;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":h%u.%u,", event.jhat.hat, event.jhat.value );
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
break;
|
||||
case SDL_JOYBUTTONUP:
|
||||
for (_s = 0; _s < s; _s++) {
|
||||
if (steps[_s].button == event.jbutton.button) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (_s == s) {
|
||||
step->button = event.jbutton.button;
|
||||
SDL_strlcat(mapping, step->field, SDL_arraysize(mapping));
|
||||
SDL_snprintf(temp, SDL_arraysize(temp), ":b%u,", event.jbutton.button);
|
||||
SDL_strlcat(mapping, temp, SDL_arraysize(mapping));
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Skip this step */
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_AC_BACK) {
|
||||
/* Undo! */
|
||||
if (s > 0) {
|
||||
prev_step = &steps[--s];
|
||||
SDL_strlcpy(mapping, prev_step->mapping, SDL_arraysize(prev_step->mapping));
|
||||
next = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
/* Skip this step */
|
||||
s++;
|
||||
next=SDL_TRUE;
|
||||
break;
|
||||
}
|
||||
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
if (alpha < 128) {
|
||||
alpha_step = 1;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_SetRenderDrawColor(screen, 0xFF, 0xFF, 0xFF, SDL_ALPHA_OPAQUE);
|
||||
SDL_RenderClear(screen);
|
||||
SDL_RenderCopy(screen, background, NULL, NULL);
|
||||
SDL_SetTextureAlphaMod(marker, alpha);
|
||||
SDL_SetTextureColorMod(marker, 10, 255, 21);
|
||||
SDL_RenderCopyEx(screen, marker, NULL, &dst, s_arrBindingDisplay[iElement].angle, NULL, SDL_FLIP_NONE);
|
||||
SDL_RenderPresent(screen);
|
||||
|
||||
while (SDL_PollEvent(&event) > 0) {
|
||||
switch (event.type) {
|
||||
case SDL_JOYDEVICEREMOVED:
|
||||
if (event.jaxis.which == nJoystickID) {
|
||||
done = SDL_TRUE;
|
||||
}
|
||||
break;
|
||||
case SDL_JOYAXISMOTION:
|
||||
if (event.jaxis.which == nJoystickID) {
|
||||
AxisState *pAxisState = &s_arrAxisState[event.jaxis.axis];
|
||||
int nValue = event.jaxis.value;
|
||||
int nCurrentDistance, nFarthestDistance;
|
||||
if (!pAxisState->m_bMoving) {
|
||||
pAxisState->m_bMoving = SDL_TRUE;
|
||||
pAxisState->m_nStartingValue = nValue;
|
||||
pAxisState->m_nFarthestValue = nValue;
|
||||
}
|
||||
nCurrentDistance = SDL_abs(nValue - pAxisState->m_nStartingValue);
|
||||
nFarthestDistance = SDL_abs(pAxisState->m_nFarthestValue - pAxisState->m_nStartingValue);
|
||||
if (nCurrentDistance > nFarthestDistance) {
|
||||
pAxisState->m_nFarthestValue = nValue;
|
||||
nFarthestDistance = SDL_abs(pAxisState->m_nFarthestValue - pAxisState->m_nStartingValue);
|
||||
}
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
SDL_Log("AXIS %d nValue %d nCurrentDistance %d nFarthestDistance %d\n", event.jaxis.axis, nValue, nCurrentDistance, nFarthestDistance);
|
||||
#endif
|
||||
if (nFarthestDistance >= 16000) {
|
||||
/* If we've gone out far enough and started to come back, let's bind this axis */
|
||||
SDL_bool bCommitBinding = (nCurrentDistance <= 10000) ? SDL_TRUE : SDL_FALSE;
|
||||
SDL_GameControllerExtendedBind binding;
|
||||
SDL_zero(binding);
|
||||
binding.bindType = SDL_CONTROLLER_BINDTYPE_AXIS;
|
||||
binding.value.axis.axis = event.jaxis.axis;
|
||||
binding.value.axis.axis_min = StandardizeAxisValue(pAxisState->m_nStartingValue);
|
||||
binding.value.axis.axis_max = StandardizeAxisValue(pAxisState->m_nFarthestValue);
|
||||
binding.committed = bCommitBinding;
|
||||
ConfigureBinding(&binding);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYHATMOTION:
|
||||
if (event.jhat.which == nJoystickID) {
|
||||
if (event.jhat.value != SDL_HAT_CENTERED) {
|
||||
SDL_GameControllerExtendedBind binding;
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
SDL_Log("HAT %d %d\n", event.jhat.hat, event.jhat.value);
|
||||
#endif
|
||||
SDL_zero(binding);
|
||||
binding.bindType = SDL_CONTROLLER_BINDTYPE_HAT;
|
||||
binding.value.hat.hat = event.jhat.hat;
|
||||
binding.value.hat.hat_mask = event.jhat.value;
|
||||
binding.committed = SDL_TRUE;
|
||||
ConfigureBinding(&binding);
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_JOYBALLMOTION:
|
||||
break;
|
||||
case SDL_JOYBUTTONDOWN:
|
||||
if (event.jbutton.which == nJoystickID) {
|
||||
SDL_GameControllerExtendedBind binding;
|
||||
|
||||
#ifdef DEBUG_CONTROLLERMAP
|
||||
SDL_Log("BUTTON %d\n", event.jbutton.button);
|
||||
#endif
|
||||
SDL_zero(binding);
|
||||
binding.bindType = SDL_CONTROLLER_BINDTYPE_BUTTON;
|
||||
binding.value.button = event.jbutton.button;
|
||||
binding.committed = SDL_TRUE;
|
||||
ConfigureBinding(&binding);
|
||||
}
|
||||
break;
|
||||
case SDL_FINGERDOWN:
|
||||
case SDL_MOUSEBUTTONDOWN:
|
||||
/* Skip this step */
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
break;
|
||||
case SDL_KEYDOWN:
|
||||
if (event.key.keysym.sym == SDLK_BACKSPACE || event.key.keysym.sym == SDLK_AC_BACK) {
|
||||
SetCurrentBinding(s_iCurrentBinding - 1);
|
||||
break;
|
||||
}
|
||||
if (event.key.keysym.sym == SDLK_SPACE) {
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
break;
|
||||
}
|
||||
|
||||
if ((event.key.keysym.sym != SDLK_ESCAPE)) {
|
||||
break;
|
||||
}
|
||||
/* Fall through to signal quit */
|
||||
case SDL_QUIT:
|
||||
done = SDL_TRUE;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
SDL_Delay(15);
|
||||
|
||||
/* Wait 100 ms for joystick events to stop coming in,
|
||||
in case a controller sends multiple events for a single control (e.g. axis and button for trigger)
|
||||
*/
|
||||
if (s_unPendingAdvanceTime && SDL_GetTicks() - s_unPendingAdvanceTime >= 100) {
|
||||
SetCurrentBinding(s_iCurrentBinding + 1);
|
||||
}
|
||||
}
|
||||
|
||||
if (s == SDL_arraysize(steps) ) {
|
||||
if (s_bBindingComplete) {
|
||||
char mapping[1024];
|
||||
char trimmed_name[128];
|
||||
char *spot;
|
||||
int iIndex;
|
||||
char pszElement[12];
|
||||
|
||||
SDL_strlcpy(trimmed_name, name, SDL_arraysize(trimmed_name));
|
||||
while (SDL_isspace(trimmed_name[0])) {
|
||||
SDL_memmove(&trimmed_name[0], &trimmed_name[1], SDL_strlen(trimmed_name));
|
||||
}
|
||||
while (trimmed_name[0] && SDL_isspace(trimmed_name[SDL_strlen(trimmed_name) - 1])) {
|
||||
trimmed_name[SDL_strlen(trimmed_name) - 1] = '\0';
|
||||
}
|
||||
while ((spot = SDL_strchr(trimmed_name, ',')) != NULL) {
|
||||
SDL_memmove(spot, spot + 1, SDL_strlen(spot));
|
||||
}
|
||||
|
||||
/* Initialize mapping with GUID and name */
|
||||
SDL_JoystickGetGUIDString(SDL_JoystickGetGUID(joystick), mapping, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, trimmed_name, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, "platform:", SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, SDL_GetPlatform(), SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
|
||||
for (iIndex = 0; iIndex < SDL_arraysize(s_arrBindings); ++iIndex) {
|
||||
SDL_GameControllerExtendedBind *pBinding = &s_arrBindings[iIndex];
|
||||
if (pBinding->bindType == SDL_CONTROLLER_BINDTYPE_NONE) {
|
||||
continue;
|
||||
}
|
||||
|
||||
if (iIndex < SDL_CONTROLLER_BUTTON_MAX) {
|
||||
SDL_GameControllerButton eButton = (SDL_GameControllerButton)iIndex;
|
||||
SDL_strlcat(mapping, SDL_GameControllerGetStringForButton(eButton), SDL_arraysize(mapping));
|
||||
} else {
|
||||
const char *pszAxisName;
|
||||
switch (iIndex - SDL_CONTROLLER_BUTTON_MAX) {
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTX_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTX_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTY_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_LEFTY_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_LEFTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTX_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTX_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTX);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTY_NEGATIVE:
|
||||
if (!BMergeAxisBindings(iIndex)) {
|
||||
SDL_strlcat(mapping, "-", SDL_arraysize(mapping));
|
||||
}
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_RIGHTY_POSITIVE:
|
||||
SDL_strlcat(mapping, "+", SDL_arraysize(mapping));
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_RIGHTY);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_TRIGGERLEFT:
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_TRIGGERLEFT);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDING_AXIS_TRIGGERRIGHT:
|
||||
pszAxisName = SDL_GameControllerGetStringForAxis(SDL_CONTROLLER_AXIS_TRIGGERRIGHT);
|
||||
break;
|
||||
}
|
||||
SDL_strlcat(mapping, pszAxisName, SDL_arraysize(mapping));
|
||||
}
|
||||
SDL_strlcat(mapping, ":", SDL_arraysize(mapping));
|
||||
|
||||
pszElement[0] = '\0';
|
||||
switch (pBinding->bindType) {
|
||||
case SDL_CONTROLLER_BINDTYPE_BUTTON:
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "b%d", pBinding->value.button);
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_AXIS:
|
||||
if (pBinding->value.axis.axis_min == 0 && pBinding->value.axis.axis_max == SDL_JOYSTICK_AXIS_MIN) {
|
||||
/* The negative half axis */
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "-a%d", pBinding->value.axis.axis);
|
||||
} else if (pBinding->value.axis.axis_min == 0 && pBinding->value.axis.axis_max == SDL_JOYSTICK_AXIS_MAX) {
|
||||
/* The positive half axis */
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "+a%d", pBinding->value.axis.axis);
|
||||
} else {
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "a%d", pBinding->value.axis.axis);
|
||||
if (pBinding->value.axis.axis_min > pBinding->value.axis.axis_max) {
|
||||
/* Invert the axis */
|
||||
SDL_strlcat(pszElement, "~", SDL_arraysize(pszElement));
|
||||
}
|
||||
}
|
||||
break;
|
||||
case SDL_CONTROLLER_BINDTYPE_HAT:
|
||||
SDL_snprintf(pszElement, sizeof(pszElement), "h%d.%d", pBinding->value.hat.hat, pBinding->value.hat.hat_mask);
|
||||
break;
|
||||
default:
|
||||
SDL_assert(!"Unknown bind type");
|
||||
break;
|
||||
}
|
||||
SDL_strlcat(mapping, pszElement, SDL_arraysize(mapping));
|
||||
SDL_strlcat(mapping, ",", SDL_arraysize(mapping));
|
||||
}
|
||||
|
||||
SDL_Log("Mapping:\n\n%s\n\n", mapping);
|
||||
/* Print to stdout as well so the user can cat the output somewhere */
|
||||
printf("%s\n", mapping);
|
||||
}
|
||||
|
||||
while(SDL_PollEvent(&event)) {};
|
||||
|
||||
SDL_free(s_arrAxisState);
|
||||
s_arrAxisState = NULL;
|
||||
|
||||
SDL_DestroyRenderer(screen);
|
||||
SDL_DestroyWindow(window);
|
||||
return retval;
|
||||
}
|
||||
|
||||
int
|
||||
@@ -368,6 +735,7 @@ main(int argc, char *argv[])
|
||||
SDL_Log(" buttons: %d\n", SDL_JoystickNumButtons(joystick));
|
||||
SDL_Log("instance id: %d\n", SDL_JoystickInstanceID(joystick));
|
||||
SDL_Log(" guid: %s\n", guid);
|
||||
SDL_Log(" VID/PID: 0x%.4x/0x%.4x\n", SDL_JoystickGetVendor(joystick), SDL_JoystickGetProduct(joystick));
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
@@ -377,9 +745,6 @@ main(int argc, char *argv[])
|
||||
#else
|
||||
if (argv[1]) {
|
||||
#endif
|
||||
SDL_bool reportederror = SDL_FALSE;
|
||||
SDL_bool keepGoing = SDL_TRUE;
|
||||
SDL_Event event;
|
||||
int device;
|
||||
#ifdef __ANDROID__
|
||||
device = 0;
|
||||
@@ -387,34 +752,11 @@ main(int argc, char *argv[])
|
||||
device = atoi(argv[1]);
|
||||
#endif
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
|
||||
while ( keepGoing ) {
|
||||
if (joystick == NULL) {
|
||||
if ( !reportederror ) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
|
||||
keepGoing = SDL_FALSE;
|
||||
reportederror = SDL_TRUE;
|
||||
}
|
||||
} else {
|
||||
reportederror = SDL_FALSE;
|
||||
keepGoing = WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
|
||||
joystick = NULL;
|
||||
if (keepGoing) {
|
||||
SDL_Log("Waiting for attach\n");
|
||||
}
|
||||
while (keepGoing) {
|
||||
SDL_WaitEvent(&event);
|
||||
if ((event.type == SDL_QUIT) || (event.type == SDL_FINGERDOWN)
|
||||
|| (event.type == SDL_MOUSEBUTTONDOWN)) {
|
||||
keepGoing = SDL_FALSE;
|
||||
} else if (event.type == SDL_JOYDEVICEADDED) {
|
||||
joystick = SDL_JoystickOpen(device);
|
||||
break;
|
||||
}
|
||||
}
|
||||
if (joystick == NULL) {
|
||||
SDL_Log("Couldn't open joystick %d: %s\n", device, SDL_GetError());
|
||||
} else {
|
||||
WatchJoystick(joystick);
|
||||
SDL_JoystickClose(joystick);
|
||||
}
|
||||
}
|
||||
else {
|
||||
@@ -435,3 +777,5 @@ main(int argc, char *argv[])
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
/* vi: set ts=4 sw=4 expandtab: */
|
||||
|
||||
Reference in New Issue
Block a user