From 4b6d0c4b3f6fe459e4091414edbcab7545bbab91 Mon Sep 17 00:00:00 2001 From: punkrockguy318 Date: Mon, 21 Dec 2009 10:49:20 +0000 Subject: [PATCH] cleaned up gtk2 code quite a bit until direct sdl rendering on gtk2 can occur, the file menu will be in a seperate window however this will allow direct interfacing with the emulator rather than just command line options like gfceux --- SConstruct | 2 +- src/drivers/sdl/gui.cpp | 70 ++++++++++++++++++++++++++++++++++++++--- 2 files changed, 66 insertions(+), 6 deletions(-) diff --git a/SConstruct b/SConstruct index 364d034e..10cb531e 100644 --- a/SConstruct +++ b/SConstruct @@ -12,7 +12,7 @@ opts.AddVariables( BoolVariable('NEWPPU', 'Enable new PPU core', 0), BoolVariable('CREATE_AVI', 'Enable avi creation support (SDL only)', 0), BoolVariable('LOGO', 'Enable a logoscreen when creating avis (SDL only)', '1'), - BoolVariable('GTK2', 'Enable experimental integrated GTK2 GUI (BROKEN, SDL Devs only!)', 0) + BoolVariable('GTK2', 'Enable GTK2 GUI (SDL only) (EXPERIMENTAL!)', 0) ) env = Environment(options = opts) diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index eb3b49c5..00d61dce 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -36,6 +36,13 @@ gint mainLoop(gpointer data) return TRUE; } +void quit () +{ + SDL_Quit(); + gtk_main_quit(); + exit(0); +} + // this is not used currently; it is used in rendering sdl in // the gtk window which is broken gint configureEvent (GtkWidget* widget, GdkEventConfigure* event) @@ -46,20 +53,73 @@ gint configureEvent (GtkWidget* widget, GdkEventConfigure* event) return TRUE; } +/* 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/Save _As", NULL, NULL, 0, "" }, + { "/File/sep1", NULL, NULL, 0, "" }, + { "/File/_Quit", "Q", quit, 0, "", GTK_STOCK_QUIT }, + { "/_Options", NULL, NULL, 0, "" }, + { "/Options/tear", NULL, NULL, 0, "" }, + { "/Options/Check", NULL, NULL, 1, "" }, + { "/Options/sep", NULL, NULL, 0, "" }, + { "/Options/Rad1", NULL, NULL, 1, "" }, + { "/Options/Rad2", NULL, NULL, 2, "/Options/Rad1" }, + { "/Options/Rad3", NULL, NULL, 3, "/Options/Rad1" }, + { "/_Help", NULL, NULL, 0, "" }, + { "/_Help/About", NULL, NULL, 0, "" }, +}; + +static gint nmenu_items = sizeof (menu_items) / sizeof (menu_items[0]); + +static GtkWidget* CreateMenubar( GtkWidget* window) +{ + GtkItemFactory *item_factory; + GtkAccelGroup *accel_group; + + /* Make an accelerator group (shortcut keys) */ + accel_group = gtk_accel_group_new (); + + /* Make an ItemFactory (that makes a menubar) */ + item_factory = gtk_item_factory_new (GTK_TYPE_MENU_BAR, "
", accel_group); + + /* This function generates the menu items. Pass the item factory, + the number of items in the array, the array itself, and any + callback data for the the menu items. */ + gtk_item_factory_create_items (item_factory, nmenu_items, menu_items, NULL); + + /* Attach the new accelerator group to the window. */ + gtk_window_add_accel_group (GTK_WINDOW (window), accel_group); + + /* Finally, return the actual menu bar created by the item factory. */ + return gtk_item_factory_get_widget (item_factory, "
"); +} + + int InitGTKSubsystem(int argc, char** argv) { GtkWidget* MainWindow; + GtkWidget* Menubar; int xres, yres; g_config->getOption("SDL.XResolution", &xres); - g_config->getOption("SDL.YResolution", &yres); + g_config->getOption("SDL.YResolution", &yres); gtk_init(&argc, &argv); MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL); gtk_window_set_title(GTK_WINDOW(MainWindow), "fceuX GTK GUI - WIP"); - gtk_widget_set_usize(MainWindow, xres, yres); - gtk_widget_realize(MainWindow); + + Menubar = CreateMenubar(MainWindow); + + gtk_container_add(GTK_CONTAINER(MainWindow), Menubar); + + // broken SDL embedding code + //gtk_widget_set_usize(MainWindow, xres, yres); + //gtk_widget_realize(MainWindow); // event handlers gtk_widget_add_events(MainWindow, GDK_BUTTON_PRESS_MASK); @@ -68,7 +128,7 @@ int InitGTKSubsystem(int argc, char** argv) // PRG: this code here is the the windowID "hack" to render SDL - // in a GTK window. however, I can't get it to work right now + // in a GTK window. however, I can't get it to work right now // so i'm commenting it out and haivng a seperate GTK2 window with // controls // 12/21/09 @@ -99,7 +159,7 @@ int InitGTKSubsystem(int argc, char** argv) */ // signal handlers - g_signal_connect(G_OBJECT(MainWindow), "delete-event", gtk_main_quit, NULL); + g_signal_connect(G_OBJECT(MainWindow), "delete-event", quit, NULL); //gtk_idle_add(mainLoop, MainWindow); gtk_widget_show_all(MainWindow);