From 441b0460aa97e7847f256ef49b0404dc6f6de49b Mon Sep 17 00:00:00 2001 From: terminx Date: Sat, 7 Dec 2019 23:50:01 +0000 Subject: [PATCH] Map SDL joystick device trackball input to mouse input git-svn-id: https://svn.eduke32.com/eduke32@8367 1a8010ca-5511-0410-912e-c29ae57300e0 # Conflicts: # source/build/src/sdlayer.cpp --- source/build/include/baselayer.h | 1 + source/build/src/sdlayer.cpp | 11 +++++++++-- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/source/build/include/baselayer.h b/source/build/include/baselayer.h index 53b93b5d6..851b7289e 100644 --- a/source/build/include/baselayer.h +++ b/source/build/include/baselayer.h @@ -116,6 +116,7 @@ typedef struct void (*pCallback)(int32_t, int32_t); int32_t bits; int32_t numAxes; + int32_t numBalls; int32_t numButtons; int32_t numHats; int32_t isGameController; diff --git a/source/build/src/sdlayer.cpp b/source/build/src/sdlayer.cpp index 112bd5193..9cc9992d9 100644 --- a/source/build/src/sdlayer.cpp +++ b/source/build/src/sdlayer.cpp @@ -748,8 +748,10 @@ void joyScanDevices() buildprintf("Using controller %s\n", SDL_GameControllerName(controller)); joystick.numAxes = SDL_CONTROLLER_AXIS_MAX; + joystick.numBalls = 0; joystick.numButtons = SDL_CONTROLLER_BUTTON_MAX; joystick.numHats = 0; + joystick.isGameController = 1; Xfree(joystick.pAxis); @@ -772,11 +774,15 @@ void joyScanDevices() // KEEPINSYNC duke3d/src/gamedefs.h, mact/include/_control.h joystick.numAxes = min(9, SDL_JoystickNumAxes(joydev)); + joystick.numBalls = SDL_JoystickNumBalls(joydev); joystick.numButtons = min(32, SDL_JoystickNumButtons(joydev)); - joystick.numHats = min((36-joystick.numButtons)/4,SDL_JoystickNumHats(joydev)); + joystick.numHats = min((36 - joystick.numButtons) / 4, SDL_JoystickNumHats(joydev)); + joystick.isGameController = 0; - initprintf("Joystick %d has %d axes, %d buttons, and %d hat(s).\n", i+1, joystick.numAxes, joystick.numButtons, joystick.numHats); + buildprint("Joystick ", i+1, " has ", joystick.numAxes, " axes, ", joystick.numButtons, " buttons, ", + (joystick.numHats ? std::to_string(joystick.numHats).c_str() : "no"), " hats, and ", + (joystick.numBalls ? std::to_string(joystick.numBalls).c_str() : "no"), " balls.\n"); Xfree(joystick.pAxis); joystick.pAxis = (int32_t *)Xcalloc(joystick.numAxes, sizeof(int32_t)); @@ -1659,6 +1665,7 @@ int32_t handleevents_sdlcommon(SDL_Event *ev) switch (ev->type) { case SDL_MOUSEMOTION: + //case SDL_JOYBALLMOTION: { // The menus need this, even in non GUI-capture mode event_t event;