From ae18d8c4b6f7f918aa5ec496ca32899793cbe41e Mon Sep 17 00:00:00 2001 From: Simon Howard Date: Fri, 21 Nov 2008 18:03:06 +0000 Subject: Move setup/ into src/ and merge with main codebase. Remove duplicated code. Split out I_Endoom to separate i_endoom.c file. Subversion-branch: /branches/raven-branch Subversion-revision: 1384 --- src/setup/txt_keyinput.c | 181 +++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 181 insertions(+) create mode 100644 src/setup/txt_keyinput.c (limited to 'src/setup/txt_keyinput.c') diff --git a/src/setup/txt_keyinput.c b/src/setup/txt_keyinput.c new file mode 100644 index 00000000..b7e68f44 --- /dev/null +++ b/src/setup/txt_keyinput.c @@ -0,0 +1,181 @@ +// Emacs style mode select -*- C++ -*- +//----------------------------------------------------------------------------- +// +// Copyright(C) 2006 Simon Howard +// +// This program is free software; you can redistribute it and/or +// modify it under the terms of the GNU General Public License +// as published by the Free Software Foundation; either version 2 +// of the License, or (at your option) any later version. +// +// This program is distributed in the hope that it will be useful, +// but WITHOUT ANY WARRANTY; without even the implied warranty of +// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +// GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License +// along with this program; if not, write to the Free Software +// Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA +// 02111-1307, USA. +// + +#include +#include + +#include "doomkeys.h" + +#include "txt_keyinput.h" +#include "txt_gui.h" +#include "txt_io.h" +#include "txt_label.h" +#include "txt_window.h" + +#define KEY_INPUT_WIDTH 8 + +static int KeyPressCallback(txt_window_t *window, int key, + TXT_UNCAST_ARG(key_input)) +{ + TXT_CAST_ARG(txt_key_input_t, key_input); + + if (key != KEY_ESCAPE) + { + // Got the key press. Save to the variable and close the window. + + *key_input->variable = key; + TXT_EmitSignal(key_input, "set"); + TXT_CloseWindow(window); + + // Re-enable key mappings now that we have the key + + TXT_EnableKeyMapping(1); + + return 1; + } + else + { + return 0; + } +} + +static void OpenPromptWindow(txt_key_input_t *key_input) +{ + txt_window_t *window; + txt_label_t *label; + + window = TXT_NewWindow(NULL); + TXT_SetWindowAction(window, TXT_HORIZ_LEFT, NULL); + TXT_SetWindowAction(window, TXT_HORIZ_CENTER, + TXT_NewWindowAbortAction(window)); + TXT_SetWindowAction(window, TXT_HORIZ_RIGHT, NULL); + + label = TXT_NewLabel("Press the new key..."); + + TXT_AddWidget(window, label); + TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER); + + TXT_SetKeyListener(window, KeyPressCallback, key_input); + + // Disable key mappings while we prompt for the key press + + TXT_EnableKeyMapping(0); +} + +static void TXT_KeyInputSizeCalc(TXT_UNCAST_ARG(key_input)) +{ + TXT_CAST_ARG(txt_key_input_t, key_input); + + // All keyinputs are the same size. + + key_input->widget.w = KEY_INPUT_WIDTH; + key_input->widget.h = 1; +} + + +static void TXT_KeyInputDrawer(TXT_UNCAST_ARG(key_input), int selected) +{ + TXT_CAST_ARG(txt_key_input_t, key_input); + char buf[20]; + int i; + + if (*key_input->variable == 0) + { + strcpy(buf, ""); + } + else + { + TXT_GetKeyDescription(*key_input->variable, buf); + } + + if (selected) + { + TXT_BGColor(TXT_COLOR_GREY, 0); + } + else + { + TXT_BGColor(TXT_COLOR_BLUE, 0); + } + + TXT_FGColor(TXT_COLOR_BRIGHT_WHITE); + + TXT_DrawString(buf); + + for (i=strlen(buf); ivariable = variable; + + return key_input; +} + -- cgit v1.2.3