diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index 00d61dce..e231369e 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -17,6 +17,7 @@ extern Config *g_config; //SDL_Surface* screen = NULL; //SDL_Surface* hello = NULL; +GtkWidget* MainWindow = NULL; // we're not using this loop right now since integrated sdl is broken @@ -43,6 +44,28 @@ void quit () exit(0); } +void loadGame () +{ + GtkWidget* fileChooser; + + fileChooser = gtk_file_chooser_dialog_new ("Open ROM", GTK_WINDOW(MainWindow), + GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, + GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL); + + if (gtk_dialog_run (GTK_DIALOG (fileChooser)) ==GTK_RESPONSE_ACCEPT) + { + char* filename; + + filename = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser)); + LoadGame(filename); + g_free(filename); + } + gtk_widget_destroy (fileChooser); + +} + +void closeGame() { CloseGame(); } + // this is not used currently; it is used in rendering sdl in // the gtk window which is broken gint configureEvent (GtkWidget* widget, GdkEventConfigure* event) @@ -56,9 +79,9 @@ gint configureEvent (GtkWidget* widget, GdkEventConfigure* event) /* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */ static GtkItemFactoryEntry menu_items[] = { { "/_File", NULL, NULL, 0, "" }, - { "/File/_New", "N", NULL, 0, "", GTK_STOCK_NEW }, - { "/File/_Open", "O", NULL, 0, "", GTK_STOCK_OPEN }, - { "/File/_Save", "S", NULL, 0, "", GTK_STOCK_SAVE }, + //{ "/File/_New", "N", NULL, 0, "", GTK_STOCK_NEW }, + { "/File/_Open", "O", loadGame, 0, "", GTK_STOCK_OPEN }, + { "/File/_Close", "C", closeGame, 0, "", GTK_STOCK_CLOSE }, { "/File/Save _As", NULL, NULL, 0, "" }, { "/File/sep1", NULL, NULL, 0, "" }, { "/File/_Quit", "Q", quit, 0, "", GTK_STOCK_QUIT }, @@ -101,8 +124,9 @@ static GtkWidget* CreateMenubar( GtkWidget* window) int InitGTKSubsystem(int argc, char** argv) { - GtkWidget* MainWindow; + //GtkWidget* MainWindow; GtkWidget* Menubar; + GtkWidget* vbox; int xres, yres; g_config->getOption("SDL.XResolution", &xres); @@ -113,9 +137,14 @@ int InitGTKSubsystem(int argc, char** argv) MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(MainWindow), "fceuX GTK GUI - WIP"); + vbox = gtk_vbox_new(FALSE, 3); + gtk_container_add(GTK_CONTAINER(MainWindow), vbox); + Menubar = CreateMenubar(MainWindow); - gtk_container_add(GTK_CONTAINER(MainWindow), Menubar); + //gtk_container_add(GTK_CONTAINER(vbox), Menubar); + gtk_box_pack_start (GTK_BOX(vbox), Menubar, FALSE, TRUE, 0); + // broken SDL embedding code //gtk_widget_set_usize(MainWindow, xres, yres); @@ -161,7 +190,8 @@ int InitGTKSubsystem(int argc, char** argv) // signal handlers g_signal_connect(G_OBJECT(MainWindow), "delete-event", quit, NULL); //gtk_idle_add(mainLoop, MainWindow); - + gtk_widget_set_size_request (GTK_WIDGET(MainWindow), 300, 200); + gtk_widget_show_all(MainWindow); diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index 9f05fa05..06f7af4d 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -642,12 +642,16 @@ SDL_GL_LoadLibrary(0); return 0; } + #ifndef _GTK2 if(romIndex <= 0) { + ShowUsage(argv[0]); FCEUD_Message("\nError parsing command line arguments\n"); SDL_Quit(); return -1; } + #endif + @@ -687,13 +691,16 @@ SDL_GL_LoadLibrary(0); InitGTKSubsystem(argc, argv); #endif - // load the specified game - error = LoadGame(argv[romIndex]); - if(error != 1) { - DriverKill(); - SDL_Quit(); - return -1; - } + if(romIndex >= 0) + { + // load the specified game + error = LoadGame(argv[romIndex]); + if(error != 1) { + DriverKill(); + SDL_Quit(); + return -1; + } + } // movie playback std::string fname; @@ -735,12 +742,14 @@ SDL_GL_LoadLibrary(0); FCEU_LoadLuaCode(fname.c_str()); }*/ - //TODO: Work this bullshit out - - // loop playing the game + #ifndef _GTK2 while(GameInfo) { + #else + while(1) { + if(GameInfo) + #endif DoFun(frameskip); #ifdef _GTK2 while(gtk_events_pending()) diff --git a/src/drivers/sdl/sdl.h b/src/drivers/sdl/sdl.h index e88cda25..71ac2129 100644 --- a/src/drivers/sdl/sdl.h +++ b/src/drivers/sdl/sdl.h @@ -8,4 +8,7 @@ static void DoFun(int frameskip); +int LoadGame(const char *path); +int CloseGame(void); + #endif