Imported contents: kraptor_final_apr_03_2004.tar.gz
[kraptor.git] / src / joymnu.c
blob24aaa389273b5d3851f89d337b90ae64e614200f
1 /*
2 --------------------------------------------------------
3 joymnu.c
4 Menu de calibracion del joystick
5 --------------------------------------------------------
6 */
8 #include <allegro.h>
9 #include "joymnu.h"
10 #include "global.h"
11 #include "guitrans.h"
12 #include "guiprocs.h"
15 Probar el joystick
16 Pasarle el numero de joystick a probar
18 void probar_el_joystick(int nj)
20 /* este objeto para dialogo dibuja hacia donde esta apuntando el joystick
21 y cambia de color cuando presiona el boton 1,2 o 3
22 usa d2 para propositos internos...
24 static int xbox_joystick_test_proc(int msg, DIALOG *d, int c)
26 int new_pos = 0;
27 int pos_x = 0 , pos_y = 0; // posicion (-1 = abj,izq, 1 = arr,der )
28 if (msg == MSG_START)
30 d->d2 = -1;
33 if(msg == MSG_DRAW)
35 rectfill(screen, d->x, d->y, d->x+d->w-2, d->y+d->h-2,gui_white_color);
36 gui_rect(screen, d->x, d->y, d->w - 1, d->h - 1, F_IN);
38 // dibujar pos del joystick - chetoooo!
39 switch (d->d2)
41 case 1:
42 rectfill(screen, d->x, d->y+d->h/3*2-1, d->x+d->w/3-2, d->y+d->h-2, gui_light_color);
43 gui_rect(screen, d->x, d->y+d->h/3*2-1, d->w/3, d->h/3, F_LIGHT);
44 break;
46 case 2:
47 rectfill(screen, d->x+d->w/3, d->y+d->h/3*2-1, d->x+d->w/3*2-2, d->y+d->h-2, gui_light_color);
48 gui_rect(screen, d->x+d->w/3, d->y+d->h/3*2-1, d->w/3, d->h/3, F_LIGHT);
49 break;
51 case 3:
52 rectfill(screen, d->x+d->w/3*2, d->y+d->h/3*2-1, d->x+d->w-2, d->y+d->h-2, gui_light_color);
53 gui_rect(screen, d->x+d->w/3*2, d->y+d->h/3*2-1, d->w/3, d->h/3, F_LIGHT);
54 break;
56 case 4:
57 rectfill(screen, d->x, d->y+d->h/3-1, d->x+d->w/3-2, d->y+d->h/3*2-2, gui_light_color);
58 gui_rect(screen, d->x, d->y+d->h/3-1, d->w/3, d->h/3, F_LIGHT);
59 break;
61 case 5:
62 rectfill(screen, d->x+d->w/3, d->y+d->h/3-1, d->x+d->w/3*2-2, d->y+d->h/3*2-2, gui_light_color);
63 gui_rect(screen, d->x+d->w/3, d->y+d->h/3-1, d->w/3, d->h/3, F_LIGHT);
64 break;
66 case 6:
67 rectfill(screen, d->x+d->w/3*2, d->y+d->h/3-1, d->x+d->w-2, d->y+d->h/3*2-2, gui_light_color);
68 gui_rect(screen, d->x+d->w/3*2, d->y+d->h/3-1, d->w/3, d->h/3, F_LIGHT);
69 break;
71 case 7:
72 rectfill(screen, d->x, d->y+d->h/3-2, d->x+d->w/3-2, d->y, gui_light_color);
73 gui_rect(screen, d->x, d->y, d->w/3, d->h/3, F_LIGHT);
74 break;
76 case 8:
77 rectfill(screen, d->x+d->w/3, d->y+d->h/3-2, d->x+d->w/3*2-2, d->y, gui_light_color);
78 gui_rect(screen, d->x+d->w/3,d->y, d->w/3, d->h/3, F_LIGHT);
79 break;
81 case 9:
82 rectfill(screen, d->x+d->w/3*2, d->y+d->h/3-2, d->x+d->w-2, d->y, gui_light_color);
83 gui_rect(screen, d->x+d->w/3*2,d->y, d->w/3, d->h/3, F_LIGHT);
84 break;
86 default:
87 msg = MSG_IDLE; // chequear que paso...
88 break;
92 /* cuando esta idle, dibujar la posicion del joystick */
93 if (msg == MSG_IDLE)
95 poll_joystick(); // absolutamente NECESARIO
97 if (joy[nj].stick[0].axis[0].d1) pos_x = -1;
98 if (joy[nj].stick[0].axis[0].d2) pos_x = 1;
100 if (joy[nj].stick[0].axis[1].d2) pos_y = -1;
101 if (joy[nj].stick[0].axis[1].d1) pos_y = 1;
102 if (pos_x == -1)
104 if (pos_y == -1)
105 new_pos = 1;
106 else
107 if (pos_y == 1) new_pos = 7;
108 else
109 new_pos = 4;
111 else
112 if (pos_x == 1)
114 if (pos_y == -1)
115 new_pos = 3;
116 else
117 if (pos_y == 1) new_pos = 9;
118 else
119 new_pos = 6;
122 else
124 if (pos_y == -1)
125 new_pos = 2;
126 else
127 if (pos_y == 1) new_pos = 8;
128 else
129 new_pos = 5;
132 if (new_pos != d->d2)
134 d->d2 = new_pos;
135 return D_REDRAWME;
137 } // fin IDLE
139 return D_O_K;
140 } // fin del proc de test del joystick
142 /* dialogo de prueba */
143 DIALOG joy_test_dlg[] =
145 /* (proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
146 { xbox_proc, 0, 0, 160, 160, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
147 { xtext_proc, 4, 4, 152, 16, 0, 0, 0, 0, 0, 0, "Joystick", NULL, NULL },
148 { xtext_proc, 4, 16, 152, 16, 0, 0, 0, 0, 0, 0, "Test", NULL, NULL },
149 { xbox_joystick_test_proc, 35, 40, 90, 90, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
150 { xbutton_proc, 28, 140, 104, 16, 0, 0, 0, D_EXIT, 0, 0, "OK", NULL, NULL },
151 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
154 /* ver si debo calibrar primero */
155 if (joy[nj].flags & JOYFLAG_CALIBRATE) dialog_joystick_calibrate(nj);
157 /* mostrar el dialogo */
158 traducir_DIALOG_dp(joy_test_dlg);
159 centre_dialog(joy_test_dlg);
160 set_dialog_color(joy_test_dlg, makecol(0,0,0), makecol(255,255,255));
162 popup_dialog(joy_test_dlg, 0);
167 Calibrar el joystick
168 Pasarle el numero de joystick a calibrar
170 void dialog_joystick_calibrate(int nj)
172 AL_CONST char *msg; /* mensaje de calibracion */
174 /* reiniciar el joystick */
175 remove_joystick();
177 alert(get_config_text("Center the joystick"), NULL, NULL, get_config_text("OK"), NULL, 0, 0);
179 if (install_joystick(JOY_TYPE_AUTODETECT) != 0)
181 alert(get_config_text("Error initialising joystick"), get_config_text(allegro_error), NULL, get_config_text("OK"), NULL, 0, 0);
182 quiere_usar_joystick = FALSE;
183 return;
186 /* Tenemos un joystick presente? */
187 if (!num_joysticks)
189 alert(get_config_text("No joystick found"), NULL, NULL, get_config_text("OK"), NULL, 0, 0);
190 quiere_usar_joystick = FALSE;
191 return;
194 /* calibrar si es necesario */
195 while (joy[nj].flags & JOYFLAG_CALIBRATE)
197 msg = calibrate_joystick_name(nj);
199 /* informar la accion a tomar */
200 alert(get_config_text(msg), get_config_text("and press ENTER"), NULL, get_config_text("ENTER"), NULL, 0, 0);
202 if (calibrate_joystick(nj) != 0)
204 alert(get_config_text("Error calibrating joystick!"), NULL, NULL, get_config_text("OK"), NULL, 0, 0);
205 return;
212 Esto hace el menu de configuracion y calibracion del joystick
214 void joystick_configuration_menu()
216 int ret = -1;
217 DIALOG joystick_config_dlg[] =
219 /* (proc) (x) (y) (w) (h) (fg) (bg) (key) (flags) (d1) (d2) (dp) (dp2) (dp3) */
220 { xbox_proc, 0, 0, 200, 136, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL },
221 { xtext_proc, 8, 4, 180, 12, 0, 0, 0, 0, 0, 0, "Joystick", NULL, NULL },
222 { xcheck_proc, 8, 24, 184, 16, 0, 0, 0, 0, 1, 0, "Enable", NULL, NULL },
223 { xbutton_proc, 8, 44, 184, 24, 0, 0, 0, D_EXIT, 0, 0, "Test", NULL, NULL },
224 { xbutton_proc, 8, 72, 184, 24, 0, 0, 0, D_EXIT, 0, 0, "Calibrate", NULL, NULL },
225 { xbutton_proc, 46, 104, 100, 24, 0, 0, 0, D_EXIT, 0, 0, "OK", NULL, NULL },
226 { NULL, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, NULL, NULL, NULL }
229 /* Tenemos un joystick presente? */
230 if (!num_joysticks)
232 alert(get_config_text("No joystick found"), NULL, NULL, get_config_text("OK"), NULL, 0, 0);
233 quiere_usar_joystick = FALSE;
234 return;
237 traducir_DIALOG_dp(joystick_config_dlg);
238 centre_dialog(joystick_config_dlg);
239 set_dialog_color(joystick_config_dlg, makecol(0,0,0), makecol(255,255,255));
241 joystick_config_dlg[2].flags = (quiere_usar_joystick) ? D_SELECTED : 0 ;
243 while (ret != 5)
245 ret = popup_dialog(joystick_config_dlg, 0); /* mostrar dialogo */
246 if (ret == 3) // testear
248 probar_el_joystick(numero_de_joystick);
251 if (ret == 4) // calibrar
253 /* calibrar el joystick */
254 if ((numero_de_joystick < 0) || (numero_de_joystick > num_joysticks-1)) numero_de_joystick = 0;
255 dialog_joystick_calibrate(numero_de_joystick);
260 if (joystick_config_dlg[2].flags & D_SELECTED)
261 quiere_usar_joystick = TRUE;
262 else
263 quiere_usar_joystick = FALSE;