2 --------------------------------------------------------
4 Menu de calibracion del joystick
5 --------------------------------------------------------
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
)
27 int pos_x
= 0 , pos_y
= 0; // posicion (-1 = abj,izq, 1 = arr,der )
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!
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
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
);
87 msg
= MSG_IDLE
; // chequear que paso...
92 /* cuando esta idle, dibujar la posicion del joystick */
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;
107 if (pos_y
== 1) new_pos
= 7;
117 if (pos_y
== 1) new_pos
= 9;
127 if (pos_y
== 1) new_pos
= 8;
132 if (new_pos
!= d
->d2
)
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);
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 */
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
;
186 /* Tenemos un joystick presente? */
189 alert(get_config_text("No joystick found"), NULL
, NULL
, get_config_text("OK"), NULL
, 0, 0);
190 quiere_usar_joystick
= FALSE
;
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);
212 Esto hace el menu de configuracion y calibracion del joystick
214 void joystick_configuration_menu()
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? */
232 alert(get_config_text("No joystick found"), NULL
, NULL
, get_config_text("OK"), NULL
, 0, 0);
233 quiere_usar_joystick
= FALSE
;
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 ;
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
;
263 quiere_usar_joystick
= FALSE
;