summaryrefslogtreecommitdiff
path: root/setup
diff options
context:
space:
mode:
authorSimon Howard2007-05-31 23:16:23 +0000
committerSimon Howard2007-05-31 23:16:23 +0000
commit7127f6c844ee24e3629f292a8301395111266a7e (patch)
tree1fc7378f54432279f70517f098c33666f66bd317 /setup
parentf37794b0e04ba617e2908f445858803abbf576e9 (diff)
downloadchocolate-doom-7127f6c844ee24e3629f292a8301395111266a7e.tar.gz
chocolate-doom-7127f6c844ee24e3629f292a8301395111266a7e.tar.bz2
chocolate-doom-7127f6c844ee24e3629f292a8301395111266a7e.zip
Initial joystick support.
Subversion-branch: /trunk/chocolate-doom Subversion-revision: 887
Diffstat (limited to 'setup')
-rw-r--r--setup/Makefile.am2
-rw-r--r--setup/configfile.c11
-rw-r--r--setup/joystick.c111
-rw-r--r--setup/joystick.h40
-rw-r--r--setup/keyboard.c2
-rw-r--r--setup/mainmenu.c3
-rw-r--r--setup/txt_joybinput.c156
-rw-r--r--setup/txt_joybinput.h44
8 files changed, 363 insertions, 6 deletions
diff --git a/setup/Makefile.am b/setup/Makefile.am
index d5eebfbf..10085218 100644
--- a/setup/Makefile.am
+++ b/setup/Makefile.am
@@ -10,6 +10,7 @@ SOURCE_FILES = \
compatibility.c compatibility.h \
configfile.c configfile.h \
display.c display.h \
+ joystick.c joystick.h \
keyboard.c keyboard.h \
m_argv.c m_argv.h \
mainmenu.c \
@@ -17,6 +18,7 @@ SOURCE_FILES = \
multiplayer.c multiplayer.h \
sound.c sound.h \
execute.c execute.h \
+ txt_joybinput.c txt_joybinput.h \
txt_keyinput.c txt_keyinput.h \
txt_mouseinput.c txt_mouseinput.h
diff --git a/setup/configfile.c b/setup/configfile.c
index 3b2326d5..96f8bdd3 100644
--- a/setup/configfile.c
+++ b/setup/configfile.c
@@ -50,6 +50,7 @@
#include "compatibility.h"
#include "display.h"
+#include "joystick.h"
#include "keyboard.h"
#include "mouse.h"
#include "multiplayer.h"
@@ -136,11 +137,6 @@ static int screenblocks = 9;
static int detailLevel = 0;
static int usegamma = 0;
-static int usejoystick = 0;
-static int joybfire = 0;
-static int joybstrafe = 1;
-static int joybuse = 2;
-
// dos specific options: these are unused but should be maintained
// so that the config file can be shared between chocolate
// doom and doom.exe
@@ -270,6 +266,11 @@ static default_t extra_defaults_list[] =
{"player_name", &net_player_name, DEFAULT_STRING, 0, 0},
#endif
{"video_driver", &video_driver, DEFAULT_STRING, 0, 0},
+ {"joystick_index", &joystick_index, DEFAULT_INT, 0, 0},
+ {"joystick_x_axis", &joystick_x_axis, DEFAULT_INT, 0, 0},
+ {"joystick_x_invert", &joystick_x_invert, DEFAULT_INT, 0, 0},
+ {"joystick_y_axis", &joystick_y_axis, DEFAULT_INT, 0, 0},
+ {"joystick_y_invert", &joystick_y_invert, DEFAULT_INT, 0, 0},
};
static default_collection_t extra_defaults =
diff --git a/setup/joystick.c b/setup/joystick.c
new file mode 100644
index 00000000..435a864c
--- /dev/null
+++ b/setup/joystick.c
@@ -0,0 +1,111 @@
+// Emacs style mode select -*- C++ -*-
+//-----------------------------------------------------------------------------
+//
+// Copyright(C) 2007 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 <stdlib.h>
+
+#include "textscreen.h"
+#include "txt_joybinput.h"
+
+#include "joystick.h"
+
+// Joystick enable/disable
+
+int usejoystick = 0;
+
+// Button mappings
+
+int joybfire = 0;
+int joybstrafe = 1;
+int joybuse = 2;
+int joybspeed = 3;
+
+// Joystick to use, as an SDL joystick index:
+
+int joystick_index = -1;
+
+// Which joystick axis to use for horizontal movement, and whether to
+// invert the direction:
+
+int joystick_x_axis = 0;
+int joystick_x_invert = 0;
+
+// Which joystick axis to use for vertical movement, and whether to
+// invert the direction:
+
+int joystick_y_axis = 1;
+int joystick_y_invert = 0;
+
+static txt_button_t *joystick_button;
+
+static void SetJoystickButtonLabel(void)
+{
+ char *name;
+
+ name = "None set";
+
+ if (joystick_index >= 0 && joystick_index < SDL_NumJoysticks())
+ {
+ name = (char *) SDL_JoystickName(joystick_index);
+ }
+
+ TXT_SetButtonLabel(joystick_button, name);
+}
+
+void ConfigJoystick(void)
+{
+ txt_window_t *window;
+ txt_table_t *button_table;
+ txt_table_t *joystick_table;
+
+ SDL_Init(SDL_INIT_JOYSTICK);
+
+ window = TXT_NewWindow("Joystick configuration");
+
+ TXT_AddWidgets(window,
+ TXT_NewCheckBox("Enable joystick", &usejoystick),
+ joystick_table = TXT_NewTable(2),
+ TXT_NewSeparator("Joystick buttons"),
+ button_table = TXT_NewTable(2),
+ NULL);
+
+ TXT_SetColumnWidths(joystick_table, 20, 15);
+
+ TXT_AddWidgets(joystick_table,
+ TXT_NewLabel("Current joystick"),
+ joystick_button = TXT_NewButton("zzzz"),
+ NULL);
+
+ TXT_SetColumnWidths(button_table, 20, 15);
+
+ TXT_AddWidgets(button_table,
+ TXT_NewLabel("Fire"),
+ TXT_NewJoystickInput(&joybfire),
+ TXT_NewLabel("Speed"),
+ TXT_NewJoystickInput(&joybspeed),
+ TXT_NewLabel("Use"),
+ TXT_NewJoystickInput(&joybuse),
+ TXT_NewLabel("Strafe"),
+ TXT_NewJoystickInput(&joybstrafe),
+ NULL);
+
+ SetJoystickButtonLabel();
+}
+
diff --git a/setup/joystick.h b/setup/joystick.h
new file mode 100644
index 00000000..30b568ad
--- /dev/null
+++ b/setup/joystick.h
@@ -0,0 +1,40 @@
+// 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.
+//
+
+#ifndef SETUP_JOYSTICK_H
+#define SETUP_JOYSTICK_H
+
+extern int usejoystick;
+extern int joybfire;
+extern int joybstrafe;
+extern int joybuse;
+extern int joybspeed;
+
+extern int joystick_index;
+extern int joystick_x_axis;
+extern int joystick_x_invert;
+extern int joystick_y_axis;
+extern int joystick_y_invert;
+
+void ConfigJoystick(void);
+
+#endif /* #ifndef SETUP_JOYSTICK_H */
+
diff --git a/setup/keyboard.c b/setup/keyboard.c
index c10b9ce4..bb749d4d 100644
--- a/setup/keyboard.c
+++ b/setup/keyboard.c
@@ -23,6 +23,7 @@
#include "execute.h"
#include "txt_keyinput.h"
+#include "joystick.h"
#include "keyboard.h"
int key_left = KEY_LEFTARROW;
@@ -35,7 +36,6 @@ int key_fire = KEY_RCTRL;
int key_use = ' ';
int key_strafe = KEY_RALT;
int key_speed = KEY_RSHIFT;
-int joybspeed = 3;
int vanilla_keyboard_mapping = 1;
diff --git a/setup/mainmenu.c b/setup/mainmenu.c
index cb645463..48472bed 100644
--- a/setup/mainmenu.c
+++ b/setup/mainmenu.c
@@ -32,6 +32,7 @@
#include "compatibility.h"
#include "display.h"
+#include "joystick.h"
#include "keyboard.h"
#include "mouse.h"
#include "multiplayer.h"
@@ -106,6 +107,8 @@ void MainMenu(void)
TXT_AddWidgets(window,
TXT_NewButton2("Configure Display",
(TxtWidgetSignalFunc) ConfigDisplay, NULL),
+ TXT_NewButton2("Configure Joystick",
+ (TxtWidgetSignalFunc) ConfigJoystick, NULL),
TXT_NewButton2("Configure Keyboard",
(TxtWidgetSignalFunc) ConfigKeyboard, NULL),
TXT_NewButton2("Configure Mouse",
diff --git a/setup/txt_joybinput.c b/setup/txt_joybinput.c
new file mode 100644
index 00000000..ff82a88c
--- /dev/null
+++ b/setup/txt_joybinput.c
@@ -0,0 +1,156 @@
+// 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 <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+
+#include "doomkeys.h"
+#include "joystick.h"
+
+#include "txt_joybinput.h"
+#include "txt_gui.h"
+#include "txt_io.h"
+#include "txt_label.h"
+#include "txt_window.h"
+
+#define JOYSTICK_INPUT_WIDTH 10
+
+static void OpenPromptWindow(txt_joystick_input_t *joystick_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 joystick button...");
+
+ TXT_AddWidget(window, label);
+ TXT_SetWidgetAlign(label, TXT_HORIZ_CENTER);
+}
+
+static void TXT_JoystickInputSizeCalc(TXT_UNCAST_ARG(joystick_input))
+{
+ TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
+
+ // All joystickinputs are the same size.
+
+ joystick_input->widget.w = JOYSTICK_INPUT_WIDTH;
+ joystick_input->widget.h = 1;
+}
+
+static void GetJoystickButtonDescription(int button, char *buf)
+{
+ sprintf(buf, "BUTTON #%i", button + 1);
+}
+
+static void TXT_JoystickInputDrawer(TXT_UNCAST_ARG(joystick_input), int selected)
+{
+ TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
+ char buf[20];
+ int i;
+
+ if (*joystick_input->variable == -1)
+ {
+ strcpy(buf, "");
+ }
+ else
+ {
+ GetJoystickButtonDescription(*joystick_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); i<JOYSTICK_INPUT_WIDTH; ++i)
+ {
+ TXT_DrawString(" ");
+ }
+}
+
+static void TXT_JoystickInputDestructor(TXT_UNCAST_ARG(joystick_input))
+{
+}
+
+static int TXT_JoystickInputKeyPress(TXT_UNCAST_ARG(joystick_input), int joystick)
+{
+ TXT_CAST_ARG(txt_joystick_input_t, joystick_input);
+
+ if (joystick == KEY_ENTER)
+ {
+ // Open a window to prompt for the new joystick press
+
+ OpenPromptWindow(joystick_input);
+
+ return 1;
+ }
+
+ return 0;
+}
+
+static void TXT_JoystickInputMousePress(TXT_UNCAST_ARG(widget), int x, int y, int b)
+{
+ TXT_CAST_ARG(txt_joystick_input_t, widget);
+
+ // Clicking is like pressing enter
+
+ if (b == TXT_MOUSE_LEFT)
+ {
+ TXT_JoystickInputKeyPress(widget, KEY_ENTER);
+ }
+}
+
+txt_widget_class_t txt_joystick_input_class =
+{
+ TXT_JoystickInputSizeCalc,
+ TXT_JoystickInputDrawer,
+ TXT_JoystickInputKeyPress,
+ TXT_JoystickInputDestructor,
+ TXT_JoystickInputMousePress,
+ NULL,
+};
+
+txt_joystick_input_t *TXT_NewJoystickInput(int *variable)
+{
+ txt_joystick_input_t *joystick_input;
+
+ joystick_input = malloc(sizeof(txt_joystick_input_t));
+
+ TXT_InitWidget(joystick_input, &txt_joystick_input_class);
+ joystick_input->variable = variable;
+
+ return joystick_input;
+}
+
diff --git a/setup/txt_joybinput.h b/setup/txt_joybinput.h
new file mode 100644
index 00000000..9a3b9c46
--- /dev/null
+++ b/setup/txt_joybinput.h
@@ -0,0 +1,44 @@
+// Emacs style mode select -*- C++ -*-
+//-----------------------------------------------------------------------------
+//
+// Copyright(C) 2007 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.
+//
+
+#ifndef TXT_JOYB_INPUT_H
+#define TXT_JOYB_INPUT_H
+
+typedef struct txt_joystick_input_s txt_joystick_input_t;
+
+#include "txt_widget.h"
+
+//
+// A joystick input is like an input box. When selected, a box pops up
+// allowing a joystick button to be pressed to select it.
+//
+
+struct txt_joystick_input_s
+{
+ txt_widget_t widget;
+ int *variable;
+};
+
+txt_joystick_input_t *TXT_NewJoystickInput(int *variable);
+
+#endif /* #ifndef TXT_JOYB_INPUT_H */
+
+