Search
lxdream.org :: lxdream/src/gui/ctrl_dlg.c :: diff
lxdream 0.9.1
released Jun 29
Download Now
filename src/gui/ctrl_dlg.c
changeset 455:3080881d00d4
prev450:207461e79f21
next460:a0c865b74c63
author nkeynes
date Sun Oct 21 05:21:35 2007 +0000 (16 years ago)
permissions -rw-r--r--
last change More GUI WIP
file annotate diff log raw
1.1 --- a/src/gui/ctrl_dlg.c Wed Oct 17 11:26:45 2007 +0000
1.2 +++ b/src/gui/ctrl_dlg.c Sun Oct 21 05:21:35 2007 +0000
1.3 @@ -1,5 +1,5 @@
1.4 /**
1.5 - * $Id: ctrl_dlg.c,v 1.2 2007-10-17 11:26:45 nkeynes Exp $
1.6 + * $Id: ctrl_dlg.c,v 1.3 2007-10-21 05:21:35 nkeynes Exp $
1.7 *
1.8 * Define the main (emu) GTK window, along with its menubars,
1.9 * toolbars, etc.
1.10 @@ -26,6 +26,13 @@
1.11
1.12 #define MAX_DEVICES 4
1.13
1.14 +static void controller_device_configure(maple_device_t device);
1.15 +
1.16 +struct maple_config_class {
1.17 + const char *name;
1.18 + void (*config_func)(maple_device_t device);
1.19 +};
1.20 +
1.21 typedef struct maple_slot_data {
1.22 maple_device_t old_device;
1.23 maple_device_t new_device;
1.24 @@ -33,15 +40,90 @@
1.25 GtkWidget *combo;
1.26 } *maple_slot_data_t;
1.27
1.28 +static struct maple_config_class maple_device_config[] = {
1.29 + { "Sega Controller", controller_device_configure },
1.30 + { NULL, NULL } };
1.31 +
1.32 static struct maple_slot_data maple_data[MAX_DEVICES];
1.33
1.34 +static gboolean config_key_keypress( GtkWidget *widget, GdkEventKey *event, gpointer user_data )
1.35 +{
1.36 + GdkKeymap *keymap = gdk_keymap_get_default();
1.37 + guint keyval;
1.38 +
1.39 + gdk_keymap_translate_keyboard_state( keymap, event->hardware_keycode, 0, 0, &keyval,
1.40 + NULL, NULL, NULL );
1.41 + gtk_entry_set_text( GTK_ENTRY(widget), gdk_keyval_name(keyval) );
1.42 + return TRUE;
1.43 +}
1.44
1.45 -gboolean controller_properties_activated( GtkButton *button, gpointer user_data )
1.46 +static void controller_config_done( GtkWidget *panel, gboolean isOK )
1.47 +{
1.48 +
1.49 +
1.50 +}
1.51 +
1.52 +static void controller_device_configure( maple_device_t device )
1.53 +{
1.54 + lxdream_config_entry_t conf = device->get_config(device);
1.55 + int count, i;
1.56 + for( count=0; conf[count].key != NULL; count++ );
1.57 +
1.58 + GtkWidget *table = gtk_table_new( (count+1)>>1, 6, FALSE );
1.59 + for( i=0; i<count; i++ ) {
1.60 + GtkWidget *text, *text2;
1.61 + int x=0;
1.62 + int y=i;
1.63 + if( i >= (count+1)>>1 ) {
1.64 + x = 3;
1.65 + y -= (count+1)>>1;
1.66 + }
1.67 + gtk_table_attach( GTK_TABLE(table), gtk_label_new(conf[i].key), x, x+1, y, y+1,
1.68 + GTK_SHRINK, GTK_SHRINK, 0, 0 );
1.69 + gchar **parts = g_strsplit(conf[i].value,",",3);
1.70 +
1.71 + text = gtk_entry_new();
1.72 + gtk_entry_set_width_chars( GTK_ENTRY(text), 8 );
1.73 + g_signal_connect( text, "key_press_event",
1.74 + G_CALLBACK(config_key_keypress), NULL );
1.75 + gtk_table_attach_defaults( GTK_TABLE(table), text, x+1, x+2, y, y+1);
1.76 +
1.77 + text2 = gtk_entry_new();
1.78 + gtk_entry_set_width_chars( GTK_ENTRY(text2), 8 );
1.79 + g_signal_connect( text2, "key_press_event",
1.80 + G_CALLBACK(config_key_keypress), NULL );
1.81 + gtk_table_attach_defaults( GTK_TABLE(table), text2, x+2, x+3, y, y+1);
1.82 + if( parts[0] != NULL ) {
1.83 + gtk_entry_set_text( GTK_ENTRY(text), g_strstrip(parts[0]) );
1.84 + if( parts[1] != NULL ) {
1.85 + gtk_entry_set_text( GTK_ENTRY(text2), g_strstrip(parts[1]) );
1.86 + }
1.87 + }
1.88 + g_strfreev(parts);
1.89 + }
1.90 + gtk_gui_run_property_dialog( "Controller Configuration", table, controller_config_done );
1.91 +}
1.92 +
1.93 +
1.94 +gboolean maple_properties_activated( GtkButton *button, gpointer user_data )
1.95 {
1.96 maple_slot_data_t data = (maple_slot_data_t)user_data;
1.97 + if( data->new_device != NULL ) {
1.98 + int i;
1.99 + for( i=0; maple_device_config[i].name != NULL; i++ ) {
1.100 + if( strcmp(data->new_device->device_class->name, maple_device_config[i].name) == 0 ) {
1.101 + maple_device_config[i].config_func(data->new_device);
1.102 + break;
1.103 + }
1.104 + }
1.105 + if( maple_device_config[i].name == NULL ) {
1.106 + gui_error_dialog( "No configuration page available for device type" );
1.107 + }
1.108 + }
1.109 + return TRUE;
1.110 }
1.111
1.112 -gboolean controller_device_changed( GtkComboBox *combo, gpointer user_data )
1.113 +gboolean maple_device_changed( GtkComboBox *combo, gpointer user_data )
1.114 {
1.115 maple_slot_data_t data = (maple_slot_data_t)user_data;
1.116 int active = gtk_combo_box_get_active(combo);
1.117 @@ -64,9 +146,10 @@
1.118 }
1.119 data->new_device = NULL;
1.120 }
1.121 + return TRUE;
1.122 }
1.123
1.124 -void controller_commit_changes( )
1.125 +void maple_commit_changes( )
1.126 {
1.127 int i;
1.128 for( i=0; i<MAX_DEVICES; i++ ) {
1.129 @@ -82,7 +165,7 @@
1.130 lxdream_save_config();
1.131 }
1.132
1.133 -void controller_cancel_changes( )
1.134 +void maple_cancel_changes( )
1.135 {
1.136 int i;
1.137 for( i=0; i<MAX_DEVICES; i++ ) {
1.138 @@ -93,7 +176,7 @@
1.139 }
1.140 }
1.141
1.142 -GtkWidget *controller_panel_new()
1.143 +GtkWidget *maple_panel_new()
1.144 {
1.145 GtkWidget *table = gtk_table_new(4, 3, TRUE);
1.146 GtkTreeIter iter;
1.147 @@ -126,20 +209,20 @@
1.148 maple_data[i].combo = combo;
1.149 maple_data[i].button = button;
1.150 g_signal_connect( button, "clicked",
1.151 - G_CALLBACK( controller_properties_activated ), &maple_data[i] );
1.152 + G_CALLBACK( maple_properties_activated ), &maple_data[i] );
1.153 g_signal_connect( combo, "changed",
1.154 - G_CALLBACK( controller_device_changed ), &maple_data[i] );
1.155 + G_CALLBACK( maple_device_changed ), &maple_data[i] );
1.156
1.157 }
1.158 return table;
1.159 }
1.160
1.161 -void controller_dialog_run( GtkWindow *parent )
1.162 +void maple_dialog_run( GtkWindow *parent )
1.163 {
1.164 - gint result = gtk_gui_run_property_dialog( "Controller Settings", controller_panel_new() );
1.165 + gint result = gtk_gui_run_property_dialog( "Controller Settings", maple_panel_new(), NULL );
1.166 if( result == GTK_RESPONSE_ACCEPT ) {
1.167 - controller_commit_changes();
1.168 + maple_commit_changes();
1.169 } else {
1.170 - controller_cancel_changes();
1.171 + maple_cancel_changes();
1.172 }
1.173 }
.