GTK GUI: Open, Close, and Quit menu options now work properly
Games can now be opened and closed on the fly without exiting fceux
This commit is contained in:
parent
4b6d0c4b3f
commit
ea64540d0f
|
@ -17,6 +17,7 @@ extern Config *g_config;
|
||||||
//SDL_Surface* screen = NULL;
|
//SDL_Surface* screen = NULL;
|
||||||
//SDL_Surface* hello = NULL;
|
//SDL_Surface* hello = NULL;
|
||||||
|
|
||||||
|
GtkWidget* MainWindow = NULL;
|
||||||
|
|
||||||
|
|
||||||
// we're not using this loop right now since integrated sdl is broken
|
// we're not using this loop right now since integrated sdl is broken
|
||||||
|
@ -43,6 +44,28 @@ void quit ()
|
||||||
exit(0);
|
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
|
// this is not used currently; it is used in rendering sdl in
|
||||||
// the gtk window which is broken
|
// the gtk window which is broken
|
||||||
gint configureEvent (GtkWidget* widget, GdkEventConfigure* event)
|
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 */
|
/* Our menu, an array of GtkItemFactoryEntry structures that defines each menu item */
|
||||||
static GtkItemFactoryEntry menu_items[] = {
|
static GtkItemFactoryEntry menu_items[] = {
|
||||||
{ "/_File", NULL, NULL, 0, "<Branch>" },
|
{ "/_File", NULL, NULL, 0, "<Branch>" },
|
||||||
{ "/File/_New", "<control>N", NULL, 0, "<StockItem>", GTK_STOCK_NEW },
|
//{ "/File/_New", "<control>N", NULL, 0, "<StockItem>", GTK_STOCK_NEW },
|
||||||
{ "/File/_Open", "<control>O", NULL, 0, "<StockItem>", GTK_STOCK_OPEN },
|
{ "/File/_Open", "<control>O", loadGame, 0, "<StockItem>", GTK_STOCK_OPEN },
|
||||||
{ "/File/_Save", "<control>S", NULL, 0, "<StockItem>", GTK_STOCK_SAVE },
|
{ "/File/_Close", "<control>C", closeGame, 0, "<StockItem>", GTK_STOCK_CLOSE },
|
||||||
{ "/File/Save _As", NULL, NULL, 0, "<Item>" },
|
{ "/File/Save _As", NULL, NULL, 0, "<Item>" },
|
||||||
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
|
{ "/File/sep1", NULL, NULL, 0, "<Separator>" },
|
||||||
{ "/File/_Quit", "<CTRL>Q", quit, 0, "<StockItem>", GTK_STOCK_QUIT },
|
{ "/File/_Quit", "<CTRL>Q", quit, 0, "<StockItem>", GTK_STOCK_QUIT },
|
||||||
|
@ -101,8 +124,9 @@ static GtkWidget* CreateMenubar( GtkWidget* window)
|
||||||
|
|
||||||
int InitGTKSubsystem(int argc, char** argv)
|
int InitGTKSubsystem(int argc, char** argv)
|
||||||
{
|
{
|
||||||
GtkWidget* MainWindow;
|
//GtkWidget* MainWindow;
|
||||||
GtkWidget* Menubar;
|
GtkWidget* Menubar;
|
||||||
|
GtkWidget* vbox;
|
||||||
int xres, yres;
|
int xres, yres;
|
||||||
|
|
||||||
g_config->getOption("SDL.XResolution", &xres);
|
g_config->getOption("SDL.XResolution", &xres);
|
||||||
|
@ -113,9 +137,14 @@ int InitGTKSubsystem(int argc, char** argv)
|
||||||
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
|
||||||
gtk_window_set_title(GTK_WINDOW(MainWindow), "fceuX GTK GUI - WIP");
|
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);
|
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
|
// broken SDL embedding code
|
||||||
//gtk_widget_set_usize(MainWindow, xres, yres);
|
//gtk_widget_set_usize(MainWindow, xres, yres);
|
||||||
|
@ -161,7 +190,8 @@ int InitGTKSubsystem(int argc, char** argv)
|
||||||
// signal handlers
|
// signal handlers
|
||||||
g_signal_connect(G_OBJECT(MainWindow), "delete-event", quit, NULL);
|
g_signal_connect(G_OBJECT(MainWindow), "delete-event", quit, NULL);
|
||||||
//gtk_idle_add(mainLoop, MainWindow);
|
//gtk_idle_add(mainLoop, MainWindow);
|
||||||
|
gtk_widget_set_size_request (GTK_WIDGET(MainWindow), 300, 200);
|
||||||
|
|
||||||
gtk_widget_show_all(MainWindow);
|
gtk_widget_show_all(MainWindow);
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -642,12 +642,16 @@ SDL_GL_LoadLibrary(0);
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#ifndef _GTK2
|
||||||
if(romIndex <= 0) {
|
if(romIndex <= 0) {
|
||||||
|
|
||||||
ShowUsage(argv[0]);
|
ShowUsage(argv[0]);
|
||||||
FCEUD_Message("\nError parsing command line arguments\n");
|
FCEUD_Message("\nError parsing command line arguments\n");
|
||||||
SDL_Quit();
|
SDL_Quit();
|
||||||
return -1;
|
return -1;
|
||||||
}
|
}
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -687,13 +691,16 @@ SDL_GL_LoadLibrary(0);
|
||||||
InitGTKSubsystem(argc, argv);
|
InitGTKSubsystem(argc, argv);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
// load the specified game
|
if(romIndex >= 0)
|
||||||
error = LoadGame(argv[romIndex]);
|
{
|
||||||
if(error != 1) {
|
// load the specified game
|
||||||
DriverKill();
|
error = LoadGame(argv[romIndex]);
|
||||||
SDL_Quit();
|
if(error != 1) {
|
||||||
return -1;
|
DriverKill();
|
||||||
}
|
SDL_Quit();
|
||||||
|
return -1;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// movie playback
|
// movie playback
|
||||||
std::string fname;
|
std::string fname;
|
||||||
|
@ -735,12 +742,14 @@ SDL_GL_LoadLibrary(0);
|
||||||
FCEU_LoadLuaCode(fname.c_str());
|
FCEU_LoadLuaCode(fname.c_str());
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
//TODO: Work this bullshit out
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
// loop playing the game
|
// loop playing the game
|
||||||
|
#ifndef _GTK2
|
||||||
while(GameInfo) {
|
while(GameInfo) {
|
||||||
|
#else
|
||||||
|
while(1) {
|
||||||
|
if(GameInfo)
|
||||||
|
#endif
|
||||||
DoFun(frameskip);
|
DoFun(frameskip);
|
||||||
#ifdef _GTK2
|
#ifdef _GTK2
|
||||||
while(gtk_events_pending())
|
while(gtk_events_pending())
|
||||||
|
|
|
@ -8,4 +8,7 @@
|
||||||
|
|
||||||
static void DoFun(int frameskip);
|
static void DoFun(int frameskip);
|
||||||
|
|
||||||
|
int LoadGame(const char *path);
|
||||||
|
int CloseGame(void);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue