--- a/src/gui/ctrl_dlg.c Wed Oct 17 11:26:45 2007 +0000 +++ b/src/gui/ctrl_dlg.c Sun Oct 21 05:21:35 2007 +0000 @@ -1,5 +1,5 @@ /** - * $Id: ctrl_dlg.c,v 1.2 2007-10-17 11:26:45 nkeynes Exp $ + * $Id: ctrl_dlg.c,v 1.3 2007-10-21 05:21:35 nkeynes Exp $ * * Define the main (emu) GTK window, along with its menubars, * toolbars, etc. @@ -26,6 +26,13 @@ #define MAX_DEVICES 4 +static void controller_device_configure(maple_device_t device); + +struct maple_config_class { + const char *name; + void (*config_func)(maple_device_t device); +}; + typedef struct maple_slot_data { maple_device_t old_device; maple_device_t new_device; @@ -33,15 +40,90 @@ GtkWidget *combo; } *maple_slot_data_t; +static struct maple_config_class maple_device_config[] = { + { "Sega Controller", controller_device_configure }, + { NULL, NULL } }; + static struct maple_slot_data maple_data[MAX_DEVICES]; +static gboolean config_key_keypress( GtkWidget *widget, GdkEventKey *event, gpointer user_data ) +{ + GdkKeymap *keymap = gdk_keymap_get_default(); + guint keyval; + + gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval, + NULL, NULL, NULL ); + gtk_entry_set_text( GTK_ENTRY(widget), gdk_keyval_name(keyval) ); + return TRUE; +} -gboolean controller_properties_activated( GtkButton *button, gpointer user_data ) +static void controller_config_done( GtkWidget *panel, gboolean isOK ) +{ + + +} + +static void controller_device_configure( maple_device_t device ) +{ + lxdream_config_entry_t conf = device->get_config(device); + int count, i; + for( count=0; conf[count].key != NULL; count++ ); + + GtkWidget *table = gtk_table_new( (count+1)>>1, 6, FALSE ); + for( i=0; i= (count+1)>>1 ) { + x = 3; + y -= (count+1)>>1; + } + gtk_table_attach( GTK_TABLE(table), gtk_label_new(conf[i].key), x, x+1, y, y+1, + GTK_SHRINK, GTK_SHRINK, 0, 0 ); + gchar **parts = g_strsplit(conf[i].value,",",3); + + text = gtk_entry_new(); + gtk_entry_set_width_chars( GTK_ENTRY(text), 8 ); + g_signal_connect( text, "key_press_event", + G_CALLBACK(config_key_keypress), NULL ); + gtk_table_attach_defaults( GTK_TABLE(table), text, x+1, x+2, y, y+1); + + text2 = gtk_entry_new(); + gtk_entry_set_width_chars( GTK_ENTRY(text2), 8 ); + g_signal_connect( text2, "key_press_event", + G_CALLBACK(config_key_keypress), NULL ); + gtk_table_attach_defaults( GTK_TABLE(table), text2, x+2, x+3, y, y+1); + if( parts[0] != NULL ) { + gtk_entry_set_text( GTK_ENTRY(text), g_strstrip(parts[0]) ); + if( parts[1] != NULL ) { + gtk_entry_set_text( GTK_ENTRY(text2), g_strstrip(parts[1]) ); + } + } + g_strfreev(parts); + } + gtk_gui_run_property_dialog( "Controller Configuration", table, controller_config_done ); +} + + +gboolean maple_properties_activated( GtkButton *button, gpointer user_data ) { maple_slot_data_t data = (maple_slot_data_t)user_data; + if( data->new_device != NULL ) { + int i; + for( i=0; maple_device_config[i].name != NULL; i++ ) { + if( strcmp(data->new_device->device_class->name, maple_device_config[i].name) == 0 ) { + maple_device_config[i].config_func(data->new_device); + break; + } + } + if( maple_device_config[i].name == NULL ) { + gui_error_dialog( "No configuration page available for device type" ); + } + } + return TRUE; } -gboolean controller_device_changed( GtkComboBox *combo, gpointer user_data ) +gboolean maple_device_changed( GtkComboBox *combo, gpointer user_data ) { maple_slot_data_t data = (maple_slot_data_t)user_data; int active = gtk_combo_box_get_active(combo); @@ -64,9 +146,10 @@ } data->new_device = NULL; } + return TRUE; } -void controller_commit_changes( ) +void maple_commit_changes( ) { int i; for( i=0; i