diff options
-rw-r--r-- | setup/txt_joybinput.c | 36 |
1 files changed, 34 insertions, 2 deletions
diff --git a/setup/txt_joybinput.c b/setup/txt_joybinput.c index 4a6ae0ef..56aaa47e 100644 --- a/setup/txt_joybinput.c +++ b/setup/txt_joybinput.c @@ -23,6 +23,8 @@ #include <stdlib.h> #include <string.h> +#include "SDL_joystick.h" + #include "doomkeys.h" #include "joystick.h" @@ -56,15 +58,45 @@ static int EventCallback(SDL_Event *event, TXT_UNCAST_ARG(joystick_input)) // When the prompt window is closed, disable the event callback function; // we are no longer interested in receiving notification of events. -static void PromptWindowClosed(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(data)) +static void PromptWindowClosed(TXT_UNCAST_ARG(widget), TXT_UNCAST_ARG(joystick)) { + TXT_CAST_ARG(SDL_Joystick, joystick); + + SDL_JoystickClose(joystick); TXT_SDL_SetEventCallback(NULL, NULL); } +static void OpenErrorWindow(void) +{ + txt_window_t *window; + + window = TXT_NewWindow(NULL); + + TXT_AddWidget(window, TXT_NewLabel("Please configure a joystick first!")); + + TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL); + TXT_SetWindowAction(window, TXT_HORIZ_CENTER, + TXT_NewWindowEscapeAction(window)); + TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL); +} + static void OpenPromptWindow(txt_joystick_input_t *joystick_input) { txt_window_t *window; txt_label_t *label; + SDL_Joystick *joystick; + + // Check the current joystick is valid + + joystick = SDL_JoystickOpen(joystick_index); + + if (joystick == NULL) + { + OpenErrorWindow(); + return; + } + + // Open the prompt window window = TXT_NewWindow(NULL); TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL); @@ -77,7 +109,7 @@ static void OpenPromptWindow(txt_joystick_input_t *joystick_input) TXT_AddWidget(window, label); TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER); TXT_SDL_SetEventCallback(EventCallback, joystick_input); - TXT_SignalConnect(window, "closed", PromptWindowClosed, NULL); + TXT_SignalConnect(window, "closed", PromptWindowClosed, joystick); joystick_input->prompt_window = window; } |