diff options
author | Simon Howard | 2007-06-04 18:34:24 +0000 |
---|---|---|
committer | Simon Howard | 2007-06-04 18:34:24 +0000 |
commit | ef6f989d0afa53f61bcc4d1b842b9d7f11df836b (patch) | |
tree | be5418c774bedb485348e30f248538e080abd7fa /setup/txt_joybinput.c | |
parent | 9d7126c11b5f1577b00987b8d5f0f7f761b012d7 (diff) | |
download | chocolate-doom-ef6f989d0afa53f61bcc4d1b842b9d7f11df836b.tar.gz chocolate-doom-ef6f989d0afa53f61bcc4d1b842b9d7f11df836b.tar.bz2 chocolate-doom-ef6f989d0afa53f61bcc4d1b842b9d7f11df836b.zip |
Completed joystick button selection widget (untested)
Subversion-branch: /trunk/chocolate-doom
Subversion-revision: 893
Diffstat (limited to 'setup/txt_joybinput.c')
-rw-r--r-- | setup/txt_joybinput.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/setup/txt_joybinput.c b/setup/txt_joybinput.c index ff82a88c..4a6ae0ef 100644 --- 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 @@ 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); + joystick_input->prompt_window = window; } static void TXT_JoystickInputSizeCalc(TXT_UNCAST_ARG(joystick_input)) |