summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Howard2007-06-09 17:49:05 +0000
committerSimon Howard2007-06-09 17:49:05 +0000
commitb5ca5da5f73f49a382e5db3e3f5449676ca999db (patch)
tree9ebd71ca96fe57bae9e63f0f6078fd55acd1b1bb
parent5193587afe42a06f8f73cbc1fc4bedd3e0506562 (diff)
downloadchocolate-doom-b5ca5da5f73f49a382e5db3e3f5449676ca999db.tar.gz
chocolate-doom-b5ca5da5f73f49a382e5db3e3f5449676ca999db.tar.bz2
chocolate-doom-b5ca5da5f73f49a382e5db3e3f5449676ca999db.zip
Open the joystick when prompting for a new button.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 897
-rw-r--r--setup/txt_joybinput.c36
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;
}