1 #include "gtk_main.h"
2 #include "interface.h"
3 #include "support.h"
4 #include "callbacks.h"
5 #include "sys_inp.h"
6 #include "iniconfig.h"
7
8
9 #if defined(SDL)
10 #include "SDL.h"
11 #endif
12
13 #if defined(SDL_mixer)
14 #include "SDL_mixer.h"
15 #endif
16
17 void gtk_show_config_device(int device_index);
18 void attach_input_signal(GtkWidget* input_window);
19 void gtk_update_configuration(gboolean);
20 void gtk_update_player_configuration(int player_index, individual_input_config individual_configuration, gboolean);
21
22 static char tmp_buf[100];
23
24 static input_config temporary_configuration[16];
25
26 GtkWidget* fileselector_window = NULL;
27 GtkWidget* fileselector_cd_path = NULL;
28 GtkWidget* fileselector_cd_system = NULL;
29 GtkWidget* fileselector_rom_path = NULL;
30
31 GtkWidget* input_settings_window = NULL;
32 GtkWidget* general_settings_window = NULL;
33 GtkWidget* main_window = NULL;
34 GtkWidget* about_window = NULL;
35 GtkWidget* manual_window = NULL;
36
37 int gtk_stop_asked = 0;
38
39 void gtk_show_config_player(int player_index);
40
41 #include "manual.h"
42
43 //! Construct the gtk interface
build_gtk_interface(int argc,char * argv[])44 void build_gtk_interface (int argc, char* argv[])
45 {
46 GtkTextView* manual_text = NULL;
47
48 gtk_set_locale ();
49 gtk_init (&argc, &argv);
50
51 add_pixmap_directory (".");
52 add_pixmap_directory ("/usr/share/hugo/pixmaps");
53 add_pixmap_directory (PACKAGE_DATA_DIR "/pixmaps");
54 add_pixmap_directory ("./pixmaps");
55 add_pixmap_directory(short_exe_name);
56 /*
57 add_pixmap_directory (PACKAGE_SOURCE_DIR "/pixmaps");
58 */
59
60 fileselector_window = create_fileselection1();
61 fileselector_cd_path = create_fileselection_cd_path();
62 fileselector_cd_system = create_fileselection_cd_system();
63 fileselector_rom_path = create_fileselection_rom_path();
64
65 input_settings_window = create_window_input_settings();
66 about_window = create_window_about();
67 general_settings_window = create_general_settings_window();
68 manual_window = create_window_manual();
69
70 attach_input_signal(input_settings_window);
71
72 manual_text = (GtkTextView*)lookup_widget(manual_window, "text_manual");
73
74 gtk_text_buffer_insert_at_cursor(gtk_text_view_get_buffer(manual_text),
75 manual_content,
76 strlen(manual_content));
77
78 get_directory_from_filename(initial_path);
79 gtk_file_selection_set_filename( (GtkFileSelection*) fileselector_window, initial_path);
80
81 main_window = create_mainWindow ();
82 gtk_widget_show (main_window);
83
84 gtk_main ();
85 }
86
87 static int gui_configuration_index = 0;
88
89 static int player_index = 0;
90
91 //! Setter for gui_configuration_index
set_gui_configuration_index(int new_index)92 void set_gui_configuration_index(int new_index)
93 {
94 gui_configuration_index = new_index;
95 gtk_update_configuration(TRUE);
96 }
97
98 //! Getter for gui_configuration_index
get_gui_configuration_index()99 int get_gui_configuration_index()
100 {
101 return gui_configuration_index;
102 }
103
104 #if defined(ENABLE_NETPLAY)
105 //! Read a single input mapping for netplay
106 void
gtk_input_mapping_setting_grab(int slot_number)107 gtk_input_mapping_setting_grab(int slot_number)
108 {
109 GtkOptionMenu* temp_option_menu;
110 GtkWidget* temp_widget;
111 char tmp_buf[100];
112 int index;
113
114 sprintf(tmp_buf, "optionmenu_slot%d", slot_number);
115 temp_option_menu = (GtkOptionMenu*)lookup_widget(general_settings_window, tmp_buf);
116
117 temp_widget = gtk_menu_get_active (GTK_MENU (temp_option_menu->menu));
118 index = g_list_index ( GTK_MENU(temp_option_menu->menu)->menu_shell.children, temp_widget);
119
120 if ((index > 1) && (index < 7))
121 {
122 option.local_input_mapping[slot_number] = index - 2;
123 }
124 else
125 {
126 option.local_input_mapping[slot_number] = -1;
127 }
128 }
129
130 //! Seta single input mapping for netplay
131 void
gtk_input_mapping_setting_set(int slot_number)132 gtk_input_mapping_setting_set(int slot_number)
133 {
134 GtkOptionMenu* temp_option_menu;
135 char tmp_buf[100];
136
137 sprintf(tmp_buf, "optionmenu_slot%d", slot_number);
138 temp_option_menu = (GtkOptionMenu*)lookup_widget(general_settings_window, tmp_buf);
139
140 if (0xFF == option.local_input_mapping[slot_number])
141 {
142 gtk_option_menu_set_history(temp_option_menu, 0);
143 }
144 else
145 {
146 gtk_option_menu_set_history(temp_option_menu, option.local_input_mapping[slot_number] + 2);
147 }
148 }
149 #endif
150
151 //! Read configuration done in the general settings window to alter real variables used in emulation
152 void
gtk_general_settings_grab()153 gtk_general_settings_grab()
154 {
155 GtkCheckButton* temp_check_button;
156 GtkEntry* temp_entry;
157 GtkSpinButton* temp_spin_button;
158 GtkOptionMenu* temp_option_menu;
159 GtkWidget* temp_widget;
160 int i;
161
162 // get start at fullscreen mode setting
163 temp_check_button = (GtkCheckButton*)lookup_widget(general_settings_window, "checkbutton_start_fullscreen");
164 option.want_fullscreen = gtk_toggle_button_get_active( (GtkToggleButton*) temp_check_button) ? 1 : 0;
165
166 // want fullscreen aspect?
167 temp_check_button = (GtkCheckButton *) lookup_widget(general_settings_window, "checkbutton_maintain_aspect");
168 option.want_fullscreen_aspect = gtk_toggle_button_get_active( (GtkToggleButton*) temp_check_button) ? 1 : 0;
169
170 // get cd system filename setting
171 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_cd_system_filename");
172 strcpy(cdsystem_path, gtk_entry_get_text(temp_entry));
173
174 // get rom initial path setting
175 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_rom_basedir");
176 strcpy(initial_path, gtk_entry_get_text(temp_entry));
177
178 // get minimal bios setting
179 temp_check_button = (GtkCheckButton*)lookup_widget(general_settings_window, "checkbutton_minimal_bios");
180 minimum_bios_hooking = gtk_toggle_button_get_active( (GtkToggleButton*) temp_check_button) ? 1 : 0;
181
182 // get cd path setting
183 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_cd_path");
184 strcpy(ISO_filename, gtk_entry_get_text(temp_entry));
185
186 // want stereo sound?
187 temp_check_button = (GtkCheckButton *) lookup_widget(general_settings_window, "checkbutton_stereo_sound");
188 option.want_stereo = gtk_toggle_button_get_active( (GtkToggleButton*) temp_check_button) ? 1 : 0;
189
190 // get output frequency
191 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_output_frequency");
192 option.want_snd_freq = atoi(gtk_entry_get_text(temp_entry));
193
194 // get sound buffer size
195 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_buffer_size");
196 sbuf_size = atoi(gtk_entry_get_text(temp_entry));
197
198 // get window size
199 temp_spin_button = (GtkSpinButton *)lookup_widget(general_settings_window, "spinbutton_window_size");
200 option.window_size = gtk_spin_button_get_value_as_int(temp_spin_button);
201
202 // get fullscreen height
203 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_fullscreen_height");
204 option.fullscreen_height = atoi(gtk_entry_get_text(temp_entry));
205
206 // get fullscreen height
207 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_fullscreen_width");
208 option.fullscreen_width = atoi(gtk_entry_get_text(temp_entry));
209
210 // get hardware scaling setting
211 temp_check_button = (GtkCheckButton*)lookup_widget(general_settings_window, "checkbutton_use_overlay");
212 option.want_hardware_scaling = gtk_toggle_button_get_active( (GtkToggleButton*) temp_check_button) ? 1 : 0;
213
214 // get arcade card emulation flag
215 temp_check_button = (GtkCheckButton*)lookup_widget(general_settings_window, "checkbutton_use_arcade_card");
216 option.want_arcade_card_emulation = gtk_toggle_button_get_active( (GtkToggleButton*) temp_check_button) ? 1 : 0;
217
218 // get tv size emulation flag
219 temp_check_button = (GtkCheckButton*)lookup_widget(general_settings_window, "checkbutton_tv_size");
220 option.want_television_size_emulation = gtk_toggle_button_get_active( (GtkToggleButton*) temp_check_button) ? 1 : 0;
221
222 // get hardware format setting
223 temp_option_menu = (GtkOptionMenu*)lookup_widget(general_settings_window, "optionmenu_overlay_format");
224
225 temp_widget = gtk_menu_get_active (GTK_MENU (temp_option_menu->menu));
226 switch ( g_list_index ( GTK_MENU(temp_option_menu->menu)->menu_shell.children, temp_widget) )
227 {
228 case 1:
229 option.wanted_hardware_format = SDL_UYVY_OVERLAY;
230 break;
231 case 2:
232 option.wanted_hardware_format = SDL_YUY2_OVERLAY;
233 break;
234 default:
235 option.wanted_hardware_format = 0;
236 }
237
238 #if defined(ENABLE_NETPLAY)
239 // get netplay mode / protocol
240 temp_option_menu = (GtkOptionMenu*)lookup_widget(general_settings_window, "optionmenu_netplay");
241
242 temp_widget = gtk_menu_get_active (GTK_MENU (temp_option_menu->menu));
243 switch ( g_list_index ( GTK_MENU(temp_option_menu->menu)->menu_shell.children, temp_widget) )
244 {
245 case 2:
246 option.want_netplay = LAN_PROTOCOL;
247 break;
248 case 3:
249 option.want_netplay = INTERNET_PROTOCOL;
250 break;
251 default:
252 option.want_netplay = LOCAL_PROTOCOL;
253 }
254
255 // get cd system filename setting
256 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_server_hostname");
257 strcpy(option.server_hostname, gtk_entry_get_text(temp_entry));
258
259 // get netplay input mapping
260 for (i = 0; i < 5; i++)
261 {
262 gtk_input_mapping_setting_grab(i);
263 }
264 #endif
265 }
266
267 //! Read current configuration and put the widgets in the corresponding mode
268 void
gtk_general_settings_set()269 gtk_general_settings_set()
270 {
271 GtkCheckButton* temp_check_button;
272 GtkEntry* temp_entry;
273 GtkSpinButton* temp_spin_button;
274 GtkOptionMenu* temp_option_menu;
275 char temp_string[10];
276 int i;
277
278 temp_check_button = (GtkCheckButton*)lookup_widget(general_settings_window, "checkbutton_start_fullscreen");
279 gtk_toggle_button_set_active( (GtkToggleButton*) temp_check_button, option.want_fullscreen ? TRUE : FALSE);
280
281 temp_check_button = (GtkCheckButton *) lookup_widget(general_settings_window, "checkbutton_maintain_aspect");
282 gtk_toggle_button_set_active( (GtkToggleButton*) temp_check_button, option.want_fullscreen_aspect ? TRUE : FALSE);
283
284 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_cd_system_filename");
285 gtk_entry_set_text(temp_entry, cdsystem_path);
286
287 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_rom_basedir");
288 gtk_entry_set_text(temp_entry, initial_path);
289
290 temp_check_button = (GtkCheckButton*)lookup_widget(general_settings_window, "checkbutton_minimal_bios");
291 gtk_toggle_button_set_active( (GtkToggleButton*) temp_check_button, minimum_bios_hooking ? TRUE : FALSE);
292
293 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_cd_path");
294 gtk_entry_set_text(temp_entry, ISO_filename);
295
296 temp_check_button = (GtkCheckButton *) lookup_widget(general_settings_window, "checkbutton_stereo_sound");
297 gtk_toggle_button_set_active( (GtkToggleButton*) temp_check_button, option.want_stereo ? TRUE : FALSE);
298
299 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_output_frequency");
300 if (option.want_snd_freq == 0)
301 strcpy(temp_string, "");
302 else
303 sprintf(temp_string, "%d", option.want_snd_freq);
304 gtk_entry_set_text(temp_entry, temp_string);
305
306 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_buffer_size");
307 if (sbuf_size == 0)
308 strcpy(temp_string, "");
309 else
310 sprintf(temp_string, "%d", sbuf_size);
311 gtk_entry_set_text(temp_entry, temp_string);
312
313 // set window size
314 temp_spin_button = (GtkSpinButton*)lookup_widget(general_settings_window, "spinbutton_window_size");
315 gtk_spin_button_set_value (temp_spin_button, option.window_size);
316
317 // set window width
318 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_fullscreen_width");
319 if (option.fullscreen_width == 0)
320 strcpy(temp_string, "640");
321 else
322 sprintf(temp_string, "%d", option.fullscreen_width);
323 gtk_entry_set_text(temp_entry, temp_string);
324
325 // set window height
326 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_fullscreen_height");
327 if (option.fullscreen_height == 0)
328 strcpy(temp_string, "480");
329 else
330 sprintf(temp_string, "%d", option.fullscreen_height);
331 gtk_entry_set_text(temp_entry, temp_string);
332
333 temp_check_button = (GtkCheckButton *) lookup_widget(general_settings_window, "checkbutton_use_overlay");
334 gtk_toggle_button_set_active( (GtkToggleButton*) temp_check_button, option.want_hardware_scaling ? TRUE : FALSE);
335
336 temp_check_button = (GtkCheckButton *) lookup_widget(general_settings_window, "checkbutton_use_arcade_card");
337 gtk_toggle_button_set_active( (GtkToggleButton*) temp_check_button, option.want_arcade_card_emulation ? TRUE : FALSE);
338
339 temp_check_button = (GtkCheckButton *) lookup_widget(general_settings_window, "checkbutton_tv_size");
340 gtk_toggle_button_set_active( (GtkToggleButton*) temp_check_button, option.want_television_size_emulation ? TRUE : FALSE);
341
342 temp_option_menu = (GtkOptionMenu *) lookup_widget(general_settings_window, "optionmenu_overlay_format");
343 switch (option.wanted_hardware_format)
344 {
345 case SDL_UYVY_OVERLAY:
346 gtk_option_menu_set_history(temp_option_menu, 1);
347 break;
348 case SDL_YUY2_OVERLAY:
349 gtk_option_menu_set_history(temp_option_menu, 2);
350 break;
351 default:
352 gtk_option_menu_set_history(temp_option_menu, 0);
353 }
354
355 #if defined(ENABLE_NETPLAY)
356 temp_option_menu = (GtkOptionMenu *) lookup_widget(general_settings_window, "optionmenu_netplay");
357 switch (option.want_netplay)
358 {
359 case LAN_PROTOCOL:
360 gtk_option_menu_set_history(temp_option_menu, 2);
361 break;
362 case INTERNET_PROTOCOL:
363 gtk_option_menu_set_history(temp_option_menu, 3);
364 break;
365 default:
366 gtk_option_menu_set_history(temp_option_menu, 0);
367 }
368
369 temp_entry = (GtkEntry*)lookup_widget(general_settings_window, "entry_server_hostname");
370 gtk_entry_set_text(temp_entry, option.server_hostname);
371
372 // get netplay input mapping
373 for (i = 0; i < 5; i++)
374 {
375 gtk_input_mapping_setting_set(i);
376 }
377 #endif
378 }
379
380 #define attach_all_signals(player_number) \
381 attach_signal(UP ## player_number);\
382 attach_signal(DOWN ## player_number);\
383 attach_signal(LEFT ## player_number);\
384 attach_signal(RIGHT ## player_number);\
385 attach_signal(SELECT ## player_number);\
386 attach_signal(RUN ## player_number);\
387 attach_signal(I ## player_number);\
388 attach_signal(AUTOI ## player_number);\
389 attach_signal(II ## player_number);\
390 attach_signal(AUTOII ## player_number);\
391 attach_signal(PXAXIS ## player_number);\
392 attach_signal(PYAXIS ## player_number);\
393 attach_signal(PSELECT ## player_number);\
394 attach_signal(PRUN ## player_number);\
395 attach_signal(PI ## player_number);\
396 attach_signal(PAUTOI ## player_number);\
397 attach_signal(PII ## player_number);\
398 attach_signal(PAUTOII ## player_number);
399
400
401 #define attach_signal(input_name) temp_button = (GtkButton*)lookup_widget(input_window, "button_" #input_name ); \
402 g_signal_connect ((gpointer) temp_button, "clicked", \
403 G_CALLBACK (on_button_input_configuration_clicked), \
404 #input_name )
405
406
407 //! Attach the signals for input configuration buttons
attach_input_signal(GtkWidget * input_window)408 void attach_input_signal(GtkWidget* input_window)
409 {
410 GtkButton* temp_button;
411
412 attach_all_signals(0);
413 attach_all_signals(1);
414 attach_all_signals(2);
415 attach_all_signals(3);
416 attach_all_signals(4);
417
418 }
419
420 //! show the configuration for the current selected configuration
gtk_update_configuration(gboolean update_joydev)421 void gtk_update_configuration(gboolean update_joydev)
422 {
423 int player_index = 0;
424
425 //! Added to be sure that SDL can figure out the name of the key
426 // Pretty silly IMHO but we have to cope with it
427 if (!SDL_WasInit(SDL_INIT_VIDEO))
428 {
429 SDL_InitSubSystem(SDL_INIT_VIDEO);
430 }
431
432 printf("Showing configuration #%d\n", gui_configuration_index);
433 fflush(stdout);
434
435 for (player_index = 0; player_index < 5; player_index++)
436 {
437 gtk_update_player_configuration(player_index,
438 temporary_configuration[gui_configuration_index].individual_config[player_index],
439 update_joydev);
440 }
441
442 }
443
gtk_update_player_configuration(int player_index,individual_input_config individual_configuration,gboolean update_joydev)444 void gtk_update_player_configuration(int player_index,
445 individual_input_config individual_configuration,
446 gboolean update_joydev)
447 {
448 GtkButton* button = NULL;
449 GtkSpinButton* spin_button = NULL;
450 int button_index = 0;
451 gboolean enabled_joypad = FALSE;
452
453 for (button_index = 0; button_index < J_PAD_START; button_index++)
454 {
455 sprintf(tmp_buf, "button_%s%d", joymap_reverse[button_index], player_index);
456 button = (GtkButton*)lookup_widget(input_settings_window, tmp_buf);
457 if (0 != individual_configuration.joy_mapping[button_index])
458 {
459 sprintf(tmp_buf, "%s", SDL_GetKeyName(individual_configuration.joy_mapping[button_index]));
460 }
461 else
462 {
463 sprintf(tmp_buf, "--");
464 }
465 gtk_button_set_label(button, tmp_buf);
466 }
467
468 if (update_joydev)
469 {
470 sprintf(tmp_buf, "spinbutton_joydev%d", player_index);
471 spin_button = (GtkSpinButton*)lookup_widget(input_settings_window, tmp_buf);
472 gtk_spin_button_set_value (spin_button, (double)individual_configuration.joydev);
473 }
474
475 enabled_joypad = (gboolean)(individual_configuration.joydev > 0);
476
477 for (; button_index < J_PXAXIS; button_index++)
478 {
479 sprintf(tmp_buf, "button_%s%d", joymap_reverse[button_index], player_index);
480 button = (GtkButton*)lookup_widget(input_settings_window, tmp_buf);
481 if ((0xffff != individual_configuration.joy_mapping[button_index]) && enabled_joypad)
482 {
483 sprintf(tmp_buf, "But. %d", individual_configuration.joy_mapping[button_index]);
484 }
485 else
486 {
487 sprintf(tmp_buf, "--");
488 }
489 gtk_button_set_label(button, tmp_buf);
490 gtk_widget_set_sensitive((GtkWidget*)button, enabled_joypad);
491 }
492
493 for (; button_index < J_MAX; button_index++)
494 {
495 sprintf(tmp_buf, "button_%s%d", joymap_reverse[button_index], player_index);
496 button = (GtkButton*)lookup_widget(input_settings_window, tmp_buf);
497 if ((0xffff != individual_configuration.joy_mapping[button_index]) && enabled_joypad)
498 {
499 sprintf(tmp_buf, "Axis %d", individual_configuration.joy_mapping[button_index]);
500 }
501 else
502 {
503 sprintf(tmp_buf, "--");
504 }
505 gtk_button_set_label(button, tmp_buf);
506 gtk_widget_set_sensitive((GtkWidget*)button, enabled_joypad);
507 }
508
509 }
510
511 //! Creates a surface for grabbing config if no game is running, else grabs it
gtk_init_grab_config(char * caption)512 static void gtk_init_grab_config(char* caption)
513 {
514 SDL_Surface *grab_window;
515
516 #if defined(SDL) && !defined(SDL_mixer)
517 SDL_PauseAudio(SDL_ENABLE);
518 #endif
519
520 #if defined(SDL_mixer)
521 Mix_Resume(-1);
522 #endif
523
524 if (physical_screen == NULL)
525 {
526
527 if (!SDL_WasInit(SDL_INIT_VIDEO))
528 {
529 SDL_InitSubSystem(SDL_INIT_VIDEO);
530 }
531
532 if ((grab_window = SDL_SetVideoMode(200, 50, 8, 0)) == NULL)
533 {
534 fprintf(stderr,"Couldn't create the window for grabbing key\n");
535 Log("Couldn't create the window for grabbing key\n");
536 }
537 SDL_WM_SetCaption(caption, NULL);
538 }
539 else
540 {
541 grab_window = physical_screen;
542 }
543
544 if (SDL_WM_GrabInput(SDL_GRAB_ON) != SDL_GRAB_ON)
545 printf("Couldn't grab input focus.\n");
546 }
547
548 //! Releases the capture surface used for grabbing configuration
gtk_close_grab_config()549 static void gtk_close_grab_config()
550 {
551 if (physical_screen == NULL)
552 {
553 SDL_QuitSubSystem(SDL_INIT_VIDEO);
554 }
555
556 if (SDL_WM_GrabInput(SDL_GRAB_OFF) != SDL_GRAB_OFF)
557 printf("Couldn't release window focus.\n");
558
559 #if defined(SDL) && !defined(SDL_mixer)
560 SDL_PauseAudio(SDL_DISABLE);
561 #endif
562
563 #if defined(SDL_mixer)
564 Mix_Pause(-1);
565 #endif
566
567 }
568
569 //! Read the value of a pressed key when asked for a new value in the configuration change
gtk_grab_config_for_key()570 UInt16 gtk_grab_config_for_key()
571 {
572 SDL_Event event;
573 UInt16 result_value = 0;
574
575 gtk_init_grab_config("Press a key");
576
577 while (SDL_WaitEvent(&event))
578 {
579 if (event.type == SDL_KEYDOWN)
580 {
581 result_value = (SDLK_ESCAPE == event.key.keysym.sym)
582 ? 0 : event.key.keysym.sym;
583 break;
584 }
585 }
586
587 gtk_close_grab_config();
588
589 return result_value;
590
591 }
592
593 //! Read the value of a pressed joypad button when asked for a new value in the configuration change
gtk_grab_config_for_pad_button(int joypad_index)594 UInt16 gtk_grab_config_for_pad_button(int joypad_index)
595 {
596 SDL_Event event;
597 UInt16 result_value = 0;
598
599 sprintf(tmp_buf, "Press a button of %s", SDL_JoystickName(joypad_index));
600 gtk_init_grab_config(tmp_buf);
601
602 while (SDL_WaitEvent(&event))
603 {
604 if (event.type == SDL_KEYDOWN)
605 {
606 if (SDLK_ESCAPE == event.key.keysym.sym)
607 {
608 result_value = -1;
609 break;
610 }
611 }
612
613 if (event.type == SDL_JOYBUTTONDOWN)
614 {
615
616 if (event.jbutton.which == joypad_index)
617 {
618 printf("Grabbed button %d\n", event.jbutton.button);
619 result_value = event.jbutton.button;
620 break;
621 }
622 }
623 }
624
625 gtk_close_grab_config();
626
627 return result_value;
628
629 }
630
631 //! Read the value of a pressed joypad axis when asked for a new value in the configuration change
gtk_grab_config_for_pad_axis(int joypad_index)632 UInt16 gtk_grab_config_for_pad_axis(int joypad_index)
633 {
634 SDL_Event event;
635 UInt16 result_value = 0;
636
637 sprintf(tmp_buf, "Move an axis of %s", SDL_JoystickName(joypad_index));
638 gtk_init_grab_config(tmp_buf);
639
640 while (SDL_WaitEvent(&event))
641 {
642
643 if (event.type == SDL_KEYDOWN)
644 {
645 if (SDLK_ESCAPE == event.key.keysym.sym)
646 {
647 result_value = -1;
648 break;
649 }
650 }
651
652 if (event.type == SDL_JOYAXISMOTION)
653 {
654
655 if (event.jaxis.which == joypad_index)
656 {
657 if ((event.jaxis.value < -16384) || (event.jaxis.value > 16383))
658 {
659 printf("Grabbed axis %d (value %d)\n", event.jaxis.axis, event.jaxis.value);
660 result_value = event.jaxis.axis;
661 break;
662 }
663 }
664 }
665 }
666
667 gtk_close_grab_config();
668
669 return result_value;
670
671 }
672
673
674 //! Copy the current configuration to the temporary one
gtk_copy_current_configuration()675 void gtk_copy_current_configuration()
676 {
677 memcpy(temporary_configuration, config, 16 * sizeof(input_config));
678 gtk_update_configuration(TRUE);
679 }
680
681 //! Copy back the temporary configuration into the reference one
gtk_confirm_configuration()682 void gtk_confirm_configuration()
683 {
684 memcpy(config, temporary_configuration, 16 * sizeof(input_config));
685 }
686
687 //! Grab the value for the given 'direction' and the given player
gtk_grab_control(int direction_index,int player_number)688 void gtk_grab_control(int direction_index, int player_number)
689 {
690 if (direction_index < J_PAD_START)
691 {
692 // It's a simple key we're looking for
693 temporary_configuration[get_gui_configuration_index()].
694 individual_config[player_number].joy_mapping[direction_index] =
695 gtk_grab_config_for_key();
696 }
697 else
698 {
699 if (direction_index < J_PXAXIS)
700 {
701 // It is a joystick button
702 temporary_configuration[get_gui_configuration_index()].
703 individual_config[player_number].joy_mapping[direction_index] =
704 gtk_grab_config_for_pad_button(
705 temporary_configuration[get_gui_configuration_index()].
706 individual_config[player_number].joydev - 1);
707 }
708 else
709 {
710 // It is a joystick axis
711 temporary_configuration[get_gui_configuration_index()].
712 individual_config[player_number].joy_mapping[direction_index] =
713 gtk_grab_config_for_pad_axis(
714 temporary_configuration[get_gui_configuration_index()].
715 individual_config[player_number].joydev - 1);
716 }
717 }
718 gtk_update_configuration(FALSE);
719 }
720
set_gui_joydev(int player_number,int new_value)721 void set_gui_joydev(int player_number,int new_value)
722 {
723 temporary_configuration[get_gui_configuration_index()].
724 individual_config[player_number].joydev = new_value;
725 printf("joydev[%d] = %d\n", player_number, new_value);
726 }
727