ref: b5ca5da5f73f49a382e5db3e3f5449676ca999db
parent: 5193587afe42a06f8f73cbc1fc4bedd3e0506562
author: Simon Howard <[email protected]>
date: Sat Jun 9 13:49:05 EDT 2007
Open the joystick when prompting for a new button. Subversion-branch: /trunk/chocolate-doom Subversion-revision: 897
--- 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,16 +58,46 @@
// 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);
TXT_SetWindowAction(window, TXT_HORIZ_CENTER,
@@ -77,7 +109,7 @@
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;
}