fix bug when mapping a joystick axis control but no button
This commit is contained in:
parent
f59094e033
commit
e2dc98d144
|
@ -125,21 +125,30 @@ void JoyMappingName(int id, char* str)
|
|||
return;
|
||||
}
|
||||
|
||||
if (id & 0x100)
|
||||
{
|
||||
int hatnum = ((id >> 4) & 0xF) + 1;
|
||||
bool hasbtn = ((id & 0xFFFF) != 0xFFFF);
|
||||
|
||||
switch (id & 0xF)
|
||||
if (hasbtn)
|
||||
{
|
||||
if (id & 0x100)
|
||||
{
|
||||
case 0x1: sprintf(str, "Hat %d up", hatnum); break;
|
||||
case 0x2: sprintf(str, "Hat %d right", hatnum); break;
|
||||
case 0x4: sprintf(str, "Hat %d down", hatnum); break;
|
||||
case 0x8: sprintf(str, "Hat %d left", hatnum); break;
|
||||
int hatnum = ((id >> 4) & 0xF) + 1;
|
||||
|
||||
switch (id & 0xF)
|
||||
{
|
||||
case 0x1: sprintf(str, "Hat %d up", hatnum); break;
|
||||
case 0x2: sprintf(str, "Hat %d right", hatnum); break;
|
||||
case 0x4: sprintf(str, "Hat %d down", hatnum); break;
|
||||
case 0x8: sprintf(str, "Hat %d left", hatnum); break;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(str, "Button %d", (id & 0xFFFF) + 1);
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
sprintf(str, "Button %d", (id & 0xFFFF) + 1);
|
||||
strcpy(str, "");
|
||||
}
|
||||
|
||||
if (id & 0x10000)
|
||||
|
@ -151,9 +160,9 @@ void JoyMappingName(int id, char* str)
|
|||
|
||||
switch ((id >> 20) & 0xF)
|
||||
{
|
||||
case 0: sprintf(str, "%s / Axis %d +", tmp, axisnum); break;
|
||||
case 1: sprintf(str, "%s / Axis %d -", tmp, axisnum); break;
|
||||
case 2: sprintf(str, "%s / Trigger %d", tmp, axisnum); break;
|
||||
case 0: sprintf(str, "%s%sAxis %d +", tmp, hasbtn?" / ":"", axisnum); break;
|
||||
case 1: sprintf(str, "%s%sAxis %d -", tmp, hasbtn?" / ":"", axisnum); break;
|
||||
case 2: sprintf(str, "%s%sTrigger %d", tmp, hasbtn?" / ":"", axisnum); break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -287,7 +296,7 @@ Uint32 JoyPoll(Uint32 interval, void* param)
|
|||
}
|
||||
|
||||
int oldmap;
|
||||
if (dlg->joymap[id] == -1) oldmap = 0;
|
||||
if (dlg->joymap[id] == -1) oldmap = 0xFFFF;
|
||||
else oldmap = dlg->joymap[id];
|
||||
|
||||
int nbuttons = SDL_JoystickNumButtons(joy);
|
||||
|
|
|
@ -710,26 +710,31 @@ bool JoystickButtonDown(int val)
|
|||
{
|
||||
if (val == -1) return false;
|
||||
|
||||
if (val & 0x100)
|
||||
bool hasbtn = ((val & 0xFFFF) != 0xFFFF);
|
||||
|
||||
if (hasbtn)
|
||||
{
|
||||
int hatnum = (val >> 4) & 0xF;
|
||||
int hatdir = val & 0xF;
|
||||
Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum);
|
||||
if (val & 0x100)
|
||||
{
|
||||
int hatnum = (val >> 4) & 0xF;
|
||||
int hatdir = val & 0xF;
|
||||
Uint8 hatval = SDL_JoystickGetHat(Joystick, hatnum);
|
||||
|
||||
bool pressed = false;
|
||||
if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP);
|
||||
else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN);
|
||||
else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT);
|
||||
else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT);
|
||||
bool pressed = false;
|
||||
if (hatdir == 0x1) pressed = (hatval & SDL_HAT_UP);
|
||||
else if (hatdir == 0x4) pressed = (hatval & SDL_HAT_DOWN);
|
||||
else if (hatdir == 0x2) pressed = (hatval & SDL_HAT_RIGHT);
|
||||
else if (hatdir == 0x8) pressed = (hatval & SDL_HAT_LEFT);
|
||||
|
||||
if (pressed) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int btnnum = val & 0xFFFF;
|
||||
Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum);
|
||||
if (pressed) return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
int btnnum = val & 0xFFFF;
|
||||
Uint8 btnval = SDL_JoystickGetButton(Joystick, btnnum);
|
||||
|
||||
if (btnval) return true;
|
||||
if (btnval) return true;
|
||||
}
|
||||
}
|
||||
|
||||
if (val & 0x10000)
|
||||
|
|
Loading…
Reference in New Issue