aboutsummaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorArisotura <thetotalworm@gmail.com>2019-06-20 16:31:28 +0200
committerArisotura <thetotalworm@gmail.com>2019-06-20 16:31:28 +0200
commite2dc98d1449c3e6682837f04eda60814f8d6a5fc (patch)
tree77a5ac99cff93aecd54bea97827a495e2a320019 /src
parentf59094e033fafc28664700061e2726be70a1568c (diff)
fix bug when mapping a joystick axis control but no button
Diffstat (limited to 'src')
-rw-r--r--src/libui_sdl/DlgInputConfig.cpp33
-rw-r--r--src/libui_sdl/main.cpp37
2 files changed, 42 insertions, 28 deletions
diff --git a/src/libui_sdl/DlgInputConfig.cpp b/src/libui_sdl/DlgInputConfig.cpp
index 8882275..3818c04 100644
--- a/src/libui_sdl/DlgInputConfig.cpp
+++ b/src/libui_sdl/DlgInputConfig.cpp
@@ -125,21 +125,30 @@ void JoyMappingName(int id, char* str)
return;
}
- if (id & 0x100)
+ bool hasbtn = ((id & 0xFFFF) != 0xFFFF);
+
+ if (hasbtn)
{
- int hatnum = ((id >> 4) & 0xF) + 1;
+ if (id & 0x100)
+ {
+ int hatnum = ((id >> 4) & 0xF) + 1;
- switch (id & 0xF)
+ 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
{
- 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;
+ 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);
diff --git a/src/libui_sdl/main.cpp b/src/libui_sdl/main.cpp
index 693e9e3..01f67d7 100644
--- a/src/libui_sdl/main.cpp
+++ b/src/libui_sdl/main.cpp
@@ -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)