]> icculus.org git repositories - btb/d2x.git/blob - arch/sdl/joydefs.c
show borders in SDL and OGL, optimized and cleaned
[btb/d2x.git] / arch / sdl / joydefs.c
1 /*
2  *
3  * SDL joystick support
4  *
5  *
6  */
7
8 #ifdef HAVE_CONFIG_H
9 #include <conf.h>
10 #endif
11
12 #include "joydefs.h"
13 #include "pstypes.h"
14 #include "newmenu.h"
15 #include "inferno.h"
16 #include "text.h"
17 #include "kconfig.h"
18
19 extern int num_joysticks;
20
21 int joydefs_calibrate_flag = 0;
22
23 void joydefs_calibrate()
24 {
25         joydefs_calibrate_flag = 0;
26
27         if (!num_joysticks) {
28                 nm_messagebox( NULL, 1, TXT_OK, TXT_NO_JOYSTICK );
29                 return;
30         }
31
32         //Actual calibration if necessary
33
34 }
35
36 void joydef_menuset_1(int nitems, newmenu_item * items, int *last_key, int citem )
37 {
38         int oc_joy = Config_control_joystick.intval;
39         int oc_mouse = Config_control_mouse.intval;
40
41         cvar_setint(&Config_control_joystick, items[0].value);
42         cvar_setint(&Config_control_mouse, items[1].value);
43
44         if (!oc_joy && Config_control_joystick.intval)
45                 joydefs_calibrate_flag = 1;
46
47         if (oc_joy != Config_control_joystick.intval || oc_mouse != Config_control_mouse.intval)
48                 kc_set_controls();
49 }
50
51
52 void joydefs_sensitivity(void)
53 {
54         newmenu_item m[6];
55         int i1 = 0;
56         int nitems = 6;
57
58         m[0].type = NM_TYPE_SLIDER; m[0].text = TXT_TURN_LR;  m[0].value = f2i(8 * Config_joystick_sensitivity[AXIS_TURN-1].value);      m[0].min_value = 0; m[0].max_value = 16;
59         m[1].type = NM_TYPE_SLIDER; m[1].text = TXT_PITCH_UD; m[1].value = f2i(8 * Config_joystick_sensitivity[AXIS_PITCH-1].value);     m[1].min_value = 0; m[1].max_value = 16;
60         m[2].type = NM_TYPE_SLIDER; m[2].text = TXT_SLIDE_LR; m[2].value = f2i(8 * Config_joystick_sensitivity[AXIS_LEFTRIGHT-1].value); m[2].min_value = 0; m[2].max_value = 16;
61         m[3].type = NM_TYPE_SLIDER; m[3].text = TXT_SLIDE_UD; m[3].value = f2i(8 * Config_joystick_sensitivity[AXIS_UPDOWN-1].value);    m[3].min_value = 0; m[3].max_value = 16;
62         m[4].type = NM_TYPE_SLIDER; m[4].text = TXT_BANK_LR;  m[4].value = f2i(8 * Config_joystick_sensitivity[AXIS_BANK-1].value);      m[4].min_value = 0; m[4].max_value = 16;
63         m[5].type = NM_TYPE_SLIDER; m[5].text = TXT_THROTTLE; m[5].value = f2i(8 * Config_joystick_sensitivity[AXIS_THROTTLE-1].value);  m[5].min_value = 0; m[5].max_value = 16;
64
65         do
66                 i1 = newmenu_do1(NULL, TXT_JOYS_SENSITIVITY, nitems, m, NULL, i1);
67         while ( i1 > -1 );
68
69         cvar_setfl(&Config_joystick_sensitivity[AXIS_TURN-1],      m[0].value / 8.0);
70         cvar_setfl(&Config_joystick_sensitivity[AXIS_PITCH-1],     m[1].value / 8.0);
71         cvar_setfl(&Config_joystick_sensitivity[AXIS_LEFTRIGHT-1], m[2].value / 8.0);
72         cvar_setfl(&Config_joystick_sensitivity[AXIS_UPDOWN-1],    m[3].value / 8.0);
73         cvar_setfl(&Config_joystick_sensitivity[AXIS_BANK-1],      m[4].value / 8.0);
74         cvar_setfl(&Config_joystick_sensitivity[AXIS_THROTTLE-1],  m[5].value / 8.0);
75 }
76
77
78 void joydefs_config()
79 {
80         newmenu_item m[13];
81         int i1 = 3;
82         int nitems = 9;
83
84         m[0].type = NM_TYPE_CHECK;  m[0].text = TXT_CONTROL_JOYSTICK; m[0].value = Config_control_joystick.intval;
85         m[1].type = NM_TYPE_CHECK;  m[1].text = TXT_CONTROL_MOUSE;    m[1].value = Config_control_mouse.intval;
86         m[2].type = NM_TYPE_TEXT;   m[2].text = "";
87         m[3].type = NM_TYPE_MENU;   m[3].text = TXT_CUST_KEYBOARD;
88         m[4].type = NM_TYPE_MENU;   m[4].text = "CUSTOMIZE ANALOG CONTROLS";
89         m[5].type = NM_TYPE_MENU;   m[5].text = "CUSTOMIZE D2X KEYS";
90         m[6].type = NM_TYPE_TEXT;   m[6].text = "";
91         m[7].type = NM_TYPE_MENU;   m[7].text = TXT_JOYS_SENSITIVITY;
92         m[8].type = NM_TYPE_TEXT;   m[8].text = "";
93
94         do {
95                 i1 = newmenu_do1(NULL, TXT_CONTROLS, nitems, m, joydef_menuset_1, i1);
96
97                 cvar_setint(&Config_control_joystick, m[0].value);
98                 cvar_setint(&Config_control_mouse, m[1].value);
99
100                 switch (i1) {
101                 case 3: kconfig(0, TXT_KEYBOARD); break;
102                 case 4: kconfig(1, TXT_AXES); break;
103                 case 5: kconfig(2, "D2X KEYS"); break;
104                 case 7: joydefs_sensitivity();
105                 }
106
107         } while (i1>-1);
108
109 }