Added joystick configuration support!

This commit is contained in:
evilynux 2007-01-12 22:51:57 +00:00
parent 2d92310faa
commit 2995bd8a78
4 changed files with 62 additions and 9 deletions

View File

@ -188,6 +188,14 @@ void on_menu_controls_activate (GtkMenuItem *menuitem, gpointer user_data)
edit_controls(); edit_controls();
} }
void on_menu_joy_controls_activate (GtkMenuItem *menuitem, gpointer
user_data)
{
GtkDialog * dlg = (GtkDialog*)glade_xml_get_widget(xml, "wJoyConfDlg");
init_joy_labels();
gtk_dialog_run(dlg);
}
void on_menu_audio_on_activate (GtkMenuItem *menuitem, gpointer user_data) { void on_menu_audio_on_activate (GtkMenuItem *menuitem, gpointer user_data) {
/* we want set audio emulation ON or OFF */ /* we want set audio emulation ON or OFF */
if (gtk_check_menu_item_get_active((GtkCheckMenuItem*)menuitem)) { if (gtk_check_menu_item_get_active((GtkCheckMenuItem*)menuitem)) {

View File

@ -272,6 +272,32 @@ void init_labels() {
} }
} }
/* Initialize the joystick controls labels for the configuration window */
void init_joy_labels() {
int i;
char text[50], bname[30];
GtkButton *b;
for (i=0; i<4; i++) {
/* Key not configured */
if( joypadCfg[i] == (u16)(-1) ) continue;
sprintf(text,"%s : %d\0\0",DESMUME_KEY_NAMES[i],joypadCfg[i]);
sprintf(bname,"button_joy_%s\0\0",DESMUME_KEY_NAMES[i]);
b = (GtkButton*)glade_xml_get_widget(xml, bname);
gtk_button_set_label(b,text);
}
/* Skipping Axis */
for (i=8; i<DESMUME_NB_KEYS; i++) {
/* Key not configured */
if( joypadCfg[i] == (u16)(-1) ) continue;
sprintf(text,"%s : %d\0\0",DESMUME_KEY_NAMES[i],joypadCfg[i]);
sprintf(bname,"button_joy_%s\0\0",DESMUME_KEY_NAMES[i]);
b = (GtkButton*)glade_xml_get_widget(xml, bname);
gtk_button_set_label(b,text);
}
}
void edit_controls() { void edit_controls() {
GtkDialog * dlg = (GtkDialog*)glade_xml_get_widget(xml, "wKeybConfDlg"); GtkDialog * dlg = (GtkDialog*)glade_xml_get_widget(xml, "wKeybConfDlg");
memcpy(&Keypad_Temp, &Keypad_Config, sizeof(Keypad_Config)); memcpy(&Keypad_Temp, &Keypad_Config, sizeof(Keypad_Config));
@ -337,7 +363,6 @@ void on_button_Debug_clicked (GtkButton *b, gpointer user_data) { ask(b,DESMU
void on_button_Boost_clicked (GtkButton *b, gpointer user_data) { ask(b,DESMUME_KEY_BOOST); } void on_button_Boost_clicked (GtkButton *b, gpointer user_data) { ask(b,DESMUME_KEY_BOOST); }
/* Joystick configuration / Key definition */ /* Joystick configuration / Key definition */
/* FIXME: popup is not shown!? */
void ask_joy_key(GtkButton*b, int key) void ask_joy_key(GtkButton*b, int key)
{ {
char text[50]; char text[50];
@ -345,15 +370,13 @@ void ask_joy_key(GtkButton*b, int key)
key--; /* remove 1 to get index */ key--; /* remove 1 to get index */
GtkDialog * dlg = (GtkDialog*)glade_xml_get_widget(xml, "wJoyDlg"); GtkDialog * dlg = (GtkDialog*)glade_xml_get_widget(xml, "wJoyDlg");
GtkDialog * parent = (GtkDialog*)glade_xml_get_widget(xml, "wJoyConfDlg");
gtk_widget_set_sensitive(parent, FALSE); /* Ugly workaround for bug below */
gtk_widget_show_now(dlg); gtk_widget_show_now(dlg);
/* FIXME: when the following line is not commented, the widget is not even shown!! */ /* Need to force event processing. Otherwise, popup won't show up. */
while ( gtk_events_pending() ) gtk_main_iteration();
joykey = get_set_joy_key(key); joykey = get_set_joy_key(key);
sprintf(text,"%s : %d\0\0",DESMUME_KEY_NAMES[key],joykey); sprintf(text,"%s : %d\0\0",DESMUME_KEY_NAMES[key],joykey);
gtk_button_set_label(b,text); gtk_button_set_label(b,text);
gtk_widget_hide((GtkWidget*)dlg); gtk_widget_hide((GtkWidget*)dlg);
gtk_widget_set_sensitive(parent, TRUE); /* Ugly workaround for bug below */
} }
void on_joy_button_A_clicked (GtkButton *b, gpointer user_data) void on_joy_button_A_clicked (GtkButton *b, gpointer user_data)

View File

@ -117,7 +117,7 @@
<signal name="activate" handler="on_menu_reset_activate" last_modification_time="Mon, 01 Jan 2007 16:40:47 GMT"/> <signal name="activate" handler="on_menu_reset_activate" last_modification_time="Mon, 01 Jan 2007 16:40:47 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image47"> <widget class="GtkImage" id="image49">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-refresh</property> <property name="stock">gtk-refresh</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -323,12 +323,33 @@
<child> <child>
<widget class="GtkImageMenuItem" id="menu_controls"> <widget class="GtkImageMenuItem" id="menu_controls">
<property name="visible">True</property> <property name="visible">True</property>
<property name="label" translatable="yes">Controls</property> <property name="label" translatable="yes">Keyboard controls</property>
<property name="use_underline">True</property> <property name="use_underline">True</property>
<signal name="activate" handler="on_menu_controls_activate" last_modification_time="Mon, 01 Jan 2007 16:53:11 GMT"/> <signal name="activate" handler="on_menu_controls_activate" last_modification_time="Mon, 01 Jan 2007 16:53:11 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image48"> <widget class="GtkImage" id="image50">
<property name="visible">True</property>
<property name="stock">gtk-preferences</property>
<property name="icon_size">1</property>
<property name="xalign">0.5</property>
<property name="yalign">0.5</property>
<property name="xpad">0</property>
<property name="ypad">0</property>
</widget>
</child>
</widget>
</child>
<child>
<widget class="GtkImageMenuItem" id="menu_joy_controls">
<property name="visible">True</property>
<property name="label" translatable="yes">Joystick controls</property>
<property name="use_underline">True</property>
<signal name="activate" handler="on_menu_joy_controls_activate" last_modification_time="Fri, 12 Jan 2007 22:26:36 GMT"/>
<child internal-child="image">
<widget class="GtkImage" id="image51">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-preferences</property> <property name="stock">gtk-preferences</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>
@ -402,7 +423,7 @@
<signal name="activate" handler="on_menu_IO_regs_activate" last_modification_time="Mon, 01 Jan 2007 16:53:11 GMT"/> <signal name="activate" handler="on_menu_IO_regs_activate" last_modification_time="Mon, 01 Jan 2007 16:53:11 GMT"/>
<child internal-child="image"> <child internal-child="image">
<widget class="GtkImage" id="image49"> <widget class="GtkImage" id="image52">
<property name="visible">True</property> <property name="visible">True</property>
<property name="stock">gtk-properties</property> <property name="stock">gtk-properties</property>
<property name="icon_size">1</property> <property name="icon_size">1</property>

View File

@ -68,6 +68,7 @@ gboolean ScreenGap;
void black_screen (); void black_screen ();
void edit_controls(); void edit_controls();
void init_joy_labels();
/* printscreen.c */ /* printscreen.c */
int WriteBMP(const char *filename,u16 *bmp); int WriteBMP(const char *filename,u16 *bmp);