ref: ef6f989d0afa53f61bcc4d1b842b9d7f11df836b
parent: 9d7126c11b5f1577b00987b8d5f0f7f761b012d7
author: Simon Howard <[email protected]>
date: Mon Jun 4 14:34:24 EDT 2007
Completed joystick button selection widget (untested) Subversion-branch: /trunk/chocolate-doom Subversion-revision: 893
--- a/setup/txt_joybinput.c
+++ b/setup/txt_joybinput.c
@@ -30,10 +30,37 @@
#include "txt_gui.h"
#include "txt_io.h"
#include "txt_label.h"
+#include "txt_sdl.h"
#include "txt_window.h"
#define JOYSTICK_INPUT_WIDTH 10
+// Called in response to SDL events when the prompt window is open:
+
+static int EventCallback(SDL_Event *event, TXT_UNCAST_ARG(joystick_input))
+{
+ TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
+
+ // Got the joystick button press?
+
+ if (event->type == SDL_JOYBUTTONDOWN)
+ {
+ *joystick_input->variable = event->jbutton.button;
+ TXT_CloseWindow(joystick_input->prompt_window);
+ return 1;
+ }
+
+ return 0;
+}
+
+// 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))
+{
+ TXT_SDL_SetEventCallback(NULL, NULL);
+}
+
static void OpenPromptWindow(txt_joystick_input_t *joystick_input)
{
txt_window_t *window;
@@ -49,6 +76,9 @@
TXT_AddWidget(window, label);
TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER);
+ TXT_SDL_SetEventCallback(EventCallback, joystick_input);
+ TXT_SignalConnect(window, "closed", PromptWindowClosed, NULL);
+ joystick_input->prompt_window = window;
}
static void TXT_JoystickInputSizeCalc(TXT_UNCAST_ARG(joystick_input))