From 5011579ba14430dfbbef53227eb5aec4744236c2 Mon Sep 17 00:00:00 2001 From: punkrockguy318 Date: Tue, 22 Dec 2009 05:12:25 +0000 Subject: [PATCH] added preferences window to gtk gui added sound option in gui removed uncessary parameters from InitSound so it can be used from gui --- src/drivers/sdl/dface.h | 2 +- src/drivers/sdl/gui.cpp | 61 +++++++++++++++++++++++++++++++++++ src/drivers/sdl/sdl-sound.cpp | 2 +- src/drivers/sdl/sdl.cpp | 2 +- 4 files changed, 64 insertions(+), 3 deletions(-) diff --git a/src/drivers/sdl/dface.h b/src/drivers/sdl/dface.h index 990797d8..c34d2454 100644 --- a/src/drivers/sdl/dface.h +++ b/src/drivers/sdl/dface.h @@ -9,7 +9,7 @@ extern char *DriverUsage; void DoDriverArgs(void); -int InitSound(FCEUGI *gi); +int InitSound(); void WriteSound(int32 *Buffer, int Count); int KillSound(void); uint32 GetMaxSound(void); diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index 1433e017..c31591b5 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -71,6 +71,66 @@ void showAbout () } +GtkWidget* prefsWin; + +void toggleSound(GtkWidget* check, gpointer data) +{ + if(gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(check))) + { + g_config->setOption("SDL.Sound", 1); + InitSound(); + } + else + { + g_config->setOption("SDL.Sound", 0); + KillSound(); + } +} + +void closePrefs(void) +{ + gtk_widget_hide_all(prefsWin); + //g_free(prefsWin); +} + +void openPrefs(void) +{ + + GtkWidget* vbox; + GtkWidget* hbox; + GtkWidget* soundLabel; + GtkWidget* soundCheck; + GtkWidget* closeButton; + + prefsWin = gtk_window_new(GTK_WINDOW_TOPLEVEL); + gtk_window_set_title(GTK_WINDOW(prefsWin), "Preferences"); + vbox = gtk_vbox_new(TRUE, 5); + hbox = gtk_hbox_new(TRUE, 5); + soundLabel = gtk_label_new("Enable sound: "); + soundCheck = gtk_check_button_new(); + closeButton = gtk_button_new_from_stock(GTK_STOCK_CLOSE); + int s; + g_config->getOption("SDL.Sound", &s); + if(s) + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(soundCheck), TRUE); + else + gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(soundCheck), FALSE); + + gtk_container_add(GTK_CONTAINER(prefsWin), vbox); + gtk_box_pack_start(GTK_BOX(vbox), hbox, TRUE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(hbox), soundLabel, TRUE, TRUE, 5); + gtk_box_pack_start(GTK_BOX(hbox), soundCheck, TRUE, TRUE, 5); + gtk_box_pack_end(GTK_BOX(vbox), closeButton, TRUE, TRUE, 5); + + gtk_widget_show_all(prefsWin); + + gtk_signal_connect(GTK_OBJECT(soundCheck), "clicked", G_CALLBACK(toggleSound), NULL); + gtk_signal_connect(GTK_OBJECT(prefsWin), "delete-event", closePrefs, NULL); + gtk_signal_connect(GTK_OBJECT(closeButton), "clicked", closePrefs, NULL); + + +} + #ifdef _S9XLUA_H void loadLua () { @@ -137,6 +197,7 @@ static GtkItemFactoryEntry menu_items[] = { #endif { "/File/_Quit", "Q", quit, 0, "", GTK_STOCK_QUIT }, { "/_Options", NULL, NULL, 0, "" }, + { "/Options/_Preferences", "P" , openPrefs, 0, "", GTK_STOCK_PREFERENCES }, { "/Options/tear", NULL, NULL, 0, "" }, { "/Options/Check", NULL, NULL, 1, "" }, { "/Options/sep", NULL, NULL, 0, "" }, diff --git a/src/drivers/sdl/sdl-sound.cpp b/src/drivers/sdl/sdl-sound.cpp index 46b1c69a..9da1996a 100644 --- a/src/drivers/sdl/sdl-sound.cpp +++ b/src/drivers/sdl/sdl-sound.cpp @@ -77,7 +77,7 @@ fillaudio(void *udata, * Initialize the audio subsystem. */ int -InitSound(FCEUGI *gi) +InitSound() { int sound, soundrate, soundbufsize, soundvolume, soundtrianglevolume, soundsquare1volume, soundsquare2volume, soundnoisevolume, soundpcmvolume, soundq; SDL_AudioSpec spec; diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 06f7af4d..ac7f6e83 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -270,7 +270,7 @@ DriverInitialize(FCEUGI *gi) if(InitVideo(gi) < 0) return 0; inited|=4; - if(InitSound(gi)) + if(InitSound()) inited|=1; if(InitJoysticks())