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 447:3e095bfcb476
next450:207461e79f21
author nkeynes
date Tue Oct 16 12:36:29 2007 +0000 (12 years ago)
permissions -rw-r--r--
last change Add gui error reporting
Add initial controller settings dialog
file annotate diff log raw
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/src/gui/ctrl_dlg.c Tue Oct 16 12:36:29 2007 +0000
1.3 @@ -0,0 +1,156 @@
1.4 +/**
1.5 + * $Id: ctrl_dlg.c,v 1.1 2007-10-16 12:36:29 nkeynes Exp $
1.6 + *
1.7 + * Define the main (emu) GTK window, along with its menubars,
1.8 + * toolbars, etc.
1.9 + *
1.10 + * Copyright (c) 2005 Nathan Keynes.
1.11 + *
1.12 + * This program is free software; you can redistribute it and/or modify
1.13 + * it under the terms of the GNU General Public License as published by
1.14 + * the Free Software Foundation; either version 2 of the License, or
1.15 + * (at your option) any later version.
1.16 + *
1.17 + * This program is distributed in the hope that it will be useful,
1.18 + * but WITHOUT ANY WARRANTY; without even the implied warranty of
1.19 + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
1.20 + * GNU General Public License for more details.
1.21 + */
1.22 +
1.23 +#include <assert.h>
1.24 +#include <gtk/gtk.h>
1.25 +
1.26 +#include "dream.h"
1.27 +#include "gui/gtkui.h"
1.28 +#include "maple/maple.h"
1.29 +
1.30 +#define MAX_DEVICES 4
1.31 +
1.32 +typedef struct maple_slot_data {
1.33 + maple_device_t old_device;
1.34 + maple_device_t new_device;
1.35 + GtkWidget *button;
1.36 + GtkWidget *combo;
1.37 +} *maple_slot_data_t;
1.38 +
1.39 +static struct maple_slot_data maple_data[MAX_DEVICES];
1.40 +
1.41 +
1.42 +gboolean controller_properties_activated( GtkButton *button, gpointer user_data )
1.43 +{
1.44 + maple_slot_data_t data = (maple_slot_data_t)user_data;
1.45 +}
1.46 +
1.47 +gboolean controller_device_changed( GtkComboBox *combo, gpointer user_data )
1.48 +{
1.49 + maple_slot_data_t data = (maple_slot_data_t)user_data;
1.50 + int active = gtk_combo_box_get_active(combo);
1.51 + gtk_widget_set_sensitive(data->button, active != 0);
1.52 + if( active != 0 ) {
1.53 + gchar *devname = gtk_combo_box_get_active_text(combo);
1.54 + const maple_device_class_t devclz = maple_get_device_class(devname);
1.55 + assert(devclz != NULL);
1.56 + if( data->new_device != NULL ) {
1.57 + if( data->new_device->device_class != devclz ) {
1.58 + data->new_device->destroy(data->new_device);
1.59 + data->new_device = maple_new_device(devname);
1.60 + }
1.61 + } else {
1.62 + data->new_device = maple_new_device(devname);
1.63 + }
1.64 + } else {
1.65 + if( data->new_device != NULL && data->new_device != data->old_device ) {
1.66 + data->new_device->destroy(data->new_device);
1.67 + }
1.68 + data->new_device = NULL;
1.69 + }
1.70 +}
1.71 +
1.72 +void controller_commit_changes( )
1.73 +{
1.74 + int i;
1.75 + for( i=0; i<MAX_DEVICES; i++ ) {
1.76 + if( maple_data[i].new_device != maple_data[i].old_device ) {
1.77 + if( maple_data[i].old_device != NULL ) {
1.78 + maple_detach_device(i,0);
1.79 + }
1.80 + if( maple_data[i].new_device != NULL ) {
1.81 + maple_attach_device(maple_data[i].new_device, i, 0 );
1.82 + }
1.83 + }
1.84 + }
1.85 + dreamcast_save_config("testrc");
1.86 +}
1.87 +
1.88 +void controller_cancel_changes( )
1.89 +{
1.90 + int i;
1.91 + for( i=0; i<MAX_DEVICES; i++ ) {
1.92 + if( maple_data[i].new_device != NULL &&
1.93 + maple_data[i].new_device != maple_data[i].old_device ) {
1.94 + maple_data[i].new_device->destroy(maple_data[i].new_device);
1.95 + }
1.96 + }
1.97 +}
1.98 +
1.99 +GtkWidget *controller_pane_new()
1.100 +{
1.101 + GtkWidget *table = gtk_table_new(4, 3, TRUE);
1.102 + GtkTreeIter iter;
1.103 + int i,j;
1.104 + const struct maple_device_class **devices = maple_get_device_classes();
1.105 +
1.106 + for( i=0; i< MAX_DEVICES; i++ ) {
1.107 + char buf[12];
1.108 + GtkWidget *combo, *button;
1.109 + int active = 0;
1.110 + maple_device_t device = maple_get_device(i,0);
1.111 + sprintf( buf, "Slot %d.", i );
1.112 + gtk_table_attach_defaults( GTK_TABLE(table), gtk_label_new(buf), 0, 1, i, i+1 );
1.113 + combo = gtk_combo_box_new_text();
1.114 + gtk_combo_box_append_text( GTK_COMBO_BOX(combo), "<empty>" );
1.115 + for( j=0; devices[j] != NULL; j++ ) {
1.116 + gtk_combo_box_append_text(GTK_COMBO_BOX(combo), devices[j]->name);
1.117 + if( device != NULL && device->device_class == devices[j] ) {
1.118 + active = j+1;
1.119 + }
1.120 + }
1.121 + gtk_combo_box_set_active(GTK_COMBO_BOX(combo), active);
1.122 + gtk_table_attach_defaults( GTK_TABLE(table), combo, 1, 2, i, i+1 );
1.123 + button = gtk_button_new_from_stock( GTK_STOCK_PROPERTIES );
1.124 + gtk_widget_set_sensitive(button, active != 0);
1.125 + gtk_table_attach_defaults( GTK_TABLE(table), button, 2, 3, i, i+1 );
1.126 +
1.127 + maple_data[i].old_device = device;
1.128 + maple_data[i].new_device = device;
1.129 + maple_data[i].combo = combo;
1.130 + maple_data[i].button = button;
1.131 + g_signal_connect( button, "activate",
1.132 + G_CALLBACK( controller_properties_activated ), &maple_data[i] );
1.133 + g_signal_connect( combo, "changed",
1.134 + G_CALLBACK( controller_device_changed ), &maple_data[i] );
1.135 +
1.136 + }
1.137 + return table;
1.138 +}
1.139 +
1.140 +void controller_dialog_run( GtkWindow *parent )
1.141 +{
1.142 + GtkWidget *dialog =
1.143 + gtk_dialog_new_with_buttons("Controller Settings", parent,
1.144 + GTK_DIALOG_MODAL|GTK_DIALOG_DESTROY_WITH_PARENT,
1.145 + GTK_STOCK_OK, GTK_RESPONSE_ACCEPT,
1.146 + GTK_STOCK_CANCEL, GTK_RESPONSE_REJECT,
1.147 + NULL);
1.148 + GtkWidget *panel = controller_pane_new();
1.149 + gint result;
1.150 + gtk_widget_show_all(panel);
1.151 + gtk_container_add( GTK_CONTAINER(GTK_DIALOG(dialog)->vbox), panel );
1.152 + result = gtk_dialog_run( GTK_DIALOG(dialog) );
1.153 + gtk_widget_destroy( dialog );
1.154 + if( result == GTK_RESPONSE_ACCEPT ) {
1.155 + controller_commit_changes();
1.156 + } else {
1.157 + controller_cancel_changes();
1.158 + }
1.159 +}
.