GTK: removed dependency on zenity

SDL: added GTK_LITE option which enables GTK for dialog boxes but sticks to a command-line interface
GTK: changed the name of some macros; enable with GTK instead of GTK2
This commit is contained in:
punkrockguy318 2010-02-25 06:22:07 +00:00
parent 3f99f5d6bc
commit 1481f6491f
8 changed files with 147 additions and 73 deletions

View File

@ -12,7 +12,8 @@ opts.AddVariables(
BoolVariable('NEWPPU', 'Enable new PPU core', 1), BoolVariable('NEWPPU', 'Enable new PPU core', 1),
BoolVariable('CREATE_AVI', 'Enable avi creation support (SDL only)', 0), BoolVariable('CREATE_AVI', 'Enable avi creation support (SDL only)', 0),
BoolVariable('LOGO', 'Enable a logoscreen when creating avis (SDL only)', '1'), BoolVariable('LOGO', 'Enable a logoscreen when creating avis (SDL only)', '1'),
BoolVariable('GTK2', 'Enable GTK2 GUI (SDL only)', 0) BoolVariable('GTK', 'Enable GTK2 GUI (SDL only)', 1),
BoolVariable('GTK_LITE', 'Enable GTK2 for dialogs only', 0)
) )
env = Environment(options = opts) env = Environment(options = opts)
@ -58,10 +59,15 @@ else:
if not conf.CheckLib('z', autoadd=1): if not conf.CheckLib('z', autoadd=1):
print 'Did not find libz or z.lib, exiting!' print 'Did not find libz or z.lib, exiting!'
Exit(1) Exit(1)
if env['GTK2']: if env['GTK'] or env['GTK_LITE']:
# Add compiler and linker flags from pkg-config # Add compiler and linker flags from pkg-config
env.Append(CPPDEFINES=["_GTK2"]) env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0') env.Append(CPPDEFINES=["_GTK2"])
if env['GTK']:
env.Append(CCFLAGS = ["-D_GTK"])
env.Append(CCFLAGS =["-D_GTK_LITE"])
if env['GTK_LITE']:
env.Append(CCFLAGS =["-D_GTK_LITE"])
### Lua platform defines ### Lua platform defines
### Applies to all files even though only lua needs it, but should be ok ### Applies to all files even though only lua needs it, but should be ok
@ -73,31 +79,6 @@ else:
# If we're POSIX, we use LUA_USE_LINUX since that combines usual lua posix defines with dlfcn calls for dynamic library loading. # If we're POSIX, we use LUA_USE_LINUX since that combines usual lua posix defines with dlfcn calls for dynamic library loading.
# Should work on any *nix # Should work on any *nix
env.Append(CCFLAGS = ["-DLUA_USE_LINUX"]) env.Append(CCFLAGS = ["-DLUA_USE_LINUX"])
### Search for zenity if we're not in windows
if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin':
path = os.getenv('PATH')
directories = []
dir = ''
# check for '$' so last entry is processed
for x in path + '$':
if x != ':' and x != '$':
dir += x
else:
directories.append(dir)
dir = ''
zenity = 0
print "Checking for zenity...",
for x in directories:
if os.path.isfile(os.path.join(x, "zenity")):
zenity = 1
if zenity:
print 'yes'
else:
print "*** WARNING ***"
print "Zenity could not be found in the PATH. File dialogs will not work without zenity installed."
raw_input('Press any key to continue. . .')
### Search for gd if we're not in Windows ### Search for gd if we're not in Windows
if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI'] and env['LOGO']: if env['PLATFORM'] != 'win32' and env['PLATFORM'] != 'cygwin' and env['CREATE_AVI'] and env['LOGO']:

View File

@ -14,9 +14,8 @@ description=
run_cmd=gksudo scons install run_cmd=gksudo scons install
[files] [files]
current_page=2 current_page=3
FILE_NAME_0=663;None;0;16;1;1;0;/home/lukas/code/fceultra/fceu/SConstruct;0 FILE_NAME_0=3845;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/sdl-sound.cpp;0
FILE_NAME_1=5288;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/gui.cpp;0 FILE_NAME_1=6651;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/win/sound.cpp;0
FILE_NAME_2=6783;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/sdl.cpp;0 FILE_NAME_2=3961;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/sound.cpp;0
FILE_NAME_3=956;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/gui.h;0 FILE_NAME_3=0;C++;0;16;1;1;0;/home/lukas/code/vba-m/src/Sound.cpp;0
FILE_NAME_4=215;C;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/sdl.h;0

View File

@ -353,7 +353,7 @@ InitConfig()
config->addOption("SDL.Zapper.0.DeviceType", "Mouse"); config->addOption("SDL.Zapper.0.DeviceType", "Mouse");
config->addOption("SDL.Zapper.0.DeviceNum", 0); config->addOption("SDL.Zapper.0.DeviceNum", 0);
return config; return config;
} }

View File

@ -5,7 +5,7 @@
#include <fstream> #include <fstream>
#include <iostream> #include <iostream>
#include <cstdlib>
//#include <vte/vte.h> //#include <vte/vte.h>
#include "../../types.h" #include "../../types.h"
@ -802,7 +802,9 @@ void recordMovieAs ()
// TODO: don't use GetUserText; or implement it in GTK rather than zenity // TODO: don't use GetUserText; or implement it in GTK rather than zenity
GtkWidget* ad = gtk_input_dialog_new(); GtkWidget* ad = gtk_input_dialog_new();
std::wstring author = (wchar_t*)GetUserText("Author name").c_str(); // the author can be empty, so no need to check here std::string s = GetUserText("Author name");
std::wstring author(s.begin(), s.end());
FCEUI_SaveMovie(fname.c_str(), MOVIE_FLAG_FROM_POWERON, author); FCEUI_SaveMovie(fname.c_str(), MOVIE_FLAG_FROM_POWERON, author);
} }
@ -938,7 +940,9 @@ void loadGame ()
filterNes = gtk_file_filter_new(); filterNes = gtk_file_filter_new();
filterFds = gtk_file_filter_new(); filterFds = gtk_file_filter_new();
gtk_file_filter_add_pattern(filterNes, "*.nes"); gtk_file_filter_add_pattern(filterNes, "*.nes");
gtk_file_filter_add_pattern(filterNes, "*.NES");
gtk_file_filter_add_pattern(filterFds, "*.fds"); gtk_file_filter_add_pattern(filterFds, "*.fds");
gtk_file_filter_add_pattern(filterFds, "*.FDS");
gtk_file_filter_set_name(filterNes, "NES ROM files"); gtk_file_filter_set_name(filterNes, "NES ROM files");
gtk_file_filter_set_name(filterFds, "FDS ROM files"); gtk_file_filter_set_name(filterFds, "FDS ROM files");
@ -963,6 +967,15 @@ void loadGame ()
g_free(filename); g_free(filename);
} }
gtk_widget_destroy (fileChooser); gtk_widget_destroy (fileChooser);
#ifdef _S9XLUA_H
std::string s;
g_config->getOption("SDL.LuaRC", &s);
if (!s.empty())
{
FCEU_LoadLuaCode(s.c_str());
}
#endif
} }
@ -1128,7 +1141,6 @@ int InitGTKSubsystem(int argc, char** argv)
g_config->getOption("SDL.XResolution", &xres); 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); MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(MainWindow), FCEU_NAME_AND_VERSION); gtk_window_set_title(GTK_WINDOW(MainWindow), FCEU_NAME_AND_VERSION);

View File

@ -19,6 +19,7 @@
#ifndef FCEUX_GUI_H #ifndef FCEUX_GUI_H
#define FCEUX_GUI_H #define FCEUX_GUI_H
#define GTK_LITE
int InitGTKSubsystem(int argc, char** argv); int InitGTKSubsystem(int argc, char** argv);
void pushOutputToGTK(const char* str); void pushOutputToGTK(const char* str);
void showGui(bool b); void showGui(bool b);

View File

@ -39,6 +39,10 @@
#include "../../fceulua.h" #include "../../fceulua.h"
#endif #endif
#ifdef _GTK_LITE
#include<gtk/gtk.h>
#endif
/** GLOBALS **/ /** GLOBALS **/
int NoWaiting=1; int NoWaiting=1;
@ -262,7 +266,7 @@ std::string GetFilename(const char* title, bool save, const char* filter)
FCEUI_ToggleEmulationPause(); FCEUI_ToggleEmulationPause();
std::string fname = ""; std::string fname = "";
#ifdef WIN32 // seriously? #ifdef WIN32
OPENFILENAME ofn; // common dialog box structure OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name char szFile[260]; // buffer for file name
HWND hwnd; // owner window HWND hwnd; // owner window
@ -287,11 +291,50 @@ std::string GetFilename(const char* title, bool save, const char* filter)
// Display the Open dialog box. // Display the Open dialog box.
fname = GetOpenFileName(&ofn); fname = GetOpenFileName(&ofn);
#else #endif
#ifdef _GTK_LITE
int fullscreen = 0; int fullscreen = 0;
g_config->getOption("SDL.Fullscreen", &fullscreen); g_config->getOption("SDL.Fullscreen", &fullscreen);
if(fullscreen) if(fullscreen)
ToggleFS(); ToggleFS();
GtkWidget* fileChooser;
GtkFileFilter* filterX;
GtkFileFilter* filterAll;
filterX = gtk_file_filter_new();
gtk_file_filter_add_pattern(filterX, filter);
gtk_file_filter_set_name(filterX, filter);
filterAll = gtk_file_filter_new();
gtk_file_filter_add_pattern(filterAll, "*");
gtk_file_filter_set_name(filterAll, "All Files");
if(save)
fileChooser = gtk_file_chooser_dialog_new ("Save as", NULL,
GTK_FILE_CHOOSER_ACTION_SAVE, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_SAVE_AS, GTK_RESPONSE_ACCEPT, NULL);
else
fileChooser = gtk_file_chooser_dialog_new ("Open", NULL,
GTK_FILE_CHOOSER_ACTION_OPEN, GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL,
GTK_STOCK_OPEN, GTK_RESPONSE_ACCEPT, NULL);
// TODO: make file filters case insensitive
//gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterX);
gtk_file_chooser_add_filter(GTK_FILE_CHOOSER(fileChooser), filterAll);
int response = gtk_dialog_run (GTK_DIALOG (fileChooser));
while(gtk_events_pending())
gtk_main_iteration_do(TRUE);
fname = gtk_file_chooser_get_filename (GTK_FILE_CHOOSER (fileChooser));
gtk_widget_destroy (fileChooser);
while(gtk_events_pending())
gtk_main_iteration_do(TRUE);
/*
FILE *fpipe; FILE *fpipe;
std::string command = "zenity --file-selection --title=\""; std::string command = "zenity --file-selection --title=\"";
command.append(title); command.append(title);
@ -316,8 +359,8 @@ std::string GetFilename(const char* title, bool save, const char* filter)
break; break;
fname += c; fname += c;
} }
pclose(fpipe); pclose(fpipe);*/
#endif #endif
FCEUI_ToggleEmulationPause(); FCEUI_ToggleEmulationPause();
return fname; return fname;
} }
@ -327,14 +370,33 @@ std::string GetFilename(const char* title, bool save, const char* filter)
*/ */
std::string GetUserText(const char* title) std::string GetUserText(const char* title)
{ {
if (FCEUI_EmulationPaused() == 0) #ifdef _GTK_LITE
GtkWidget* d;
GtkWidget* entry;
d = gtk_dialog_new_with_buttons(title, NULL, GTK_DIALOG_MODAL, GTK_STOCK_OK, GTK_RESPONSE_OK);
entry = gtk_entry_new();
gtk_container_add(GTK_CONTAINER(GTK_DIALOG(d)->vbox), entry);
gtk_widget_show_all(d);
int response = gtk_dialog_run(GTK_DIALOG(d));
while(gtk_events_pending())
gtk_main_iteration_do(TRUE);
std::string input = gtk_entry_get_text(GTK_ENTRY(entry));
if (FCEUI_EmulationPaused() == 0)
FCEUI_ToggleEmulationPause(); // pause emulation FCEUI_ToggleEmulationPause(); // pause emulation
int fullscreen = 0; int fullscreen = 0;
g_config->getOption("SDL.Fullscreen", &fullscreen); g_config->getOption("SDL.Fullscreen", &fullscreen);
if(fullscreen) if(fullscreen)
ToggleFS(); // disable fullscreen emulation ToggleFS(); // disable fullscreen emulation
/*
FILE *fpipe; FILE *fpipe;
std::string command = "zenity --entry --title=\""; std::string command = "zenity --entry --title=\"";
command.append(title); command.append(title);
@ -352,9 +414,18 @@ std::string GetUserText(const char* title)
break; break;
input += c; input += c;
} }
pclose(fpipe); pclose(fpipe);*/
FCEUI_ToggleEmulationPause(); // unpause emulation gtk_widget_destroy(d);
return input;
while(gtk_events_pending())
gtk_main_iteration_do(TRUE);
FCEUI_ToggleEmulationPause(); // unpause emulation
return input;
#endif
return "";
} }

View File

@ -41,7 +41,7 @@
#include "../videolog/nesvideos-piece.h" #include "../videolog/nesvideos-piece.h"
#endif #endif
#ifdef _GTK2 #ifdef _GTK
#include "gui.h" #include "gui.h"
#endif #endif
@ -446,7 +446,7 @@ ToggleFS()
// flip the fullscreen flag // flip the fullscreen flag
g_config->setOption("SDL.Fullscreen", !fullscreen); g_config->setOption("SDL.Fullscreen", !fullscreen);
#ifdef _GTK2 #ifdef _GTK
if(!fullscreen) if(!fullscreen)
showGui(0); showGui(0);
else else

View File

@ -13,8 +13,10 @@
#include <limits.h> #include <limits.h>
#include <math.h> #include <math.h>
#ifdef _GTK2 #ifdef _GTK_LITE
#include <gtk/gtk.h> #include <gtk/gtk.h>
#endif
#ifdef _GTK
#include "gui.cpp" #include "gui.cpp"
#endif #endif
@ -143,15 +145,18 @@ static void ShowUsage(char *prog)
printf("\nUsage is as follows:\n%s <options> filename\n\n",prog); printf("\nUsage is as follows:\n%s <options> filename\n\n",prog);
puts("Options:"); puts("Options:");
puts(DriverUsage); puts(DriverUsage);
#ifdef _S9XLUA_H #ifdef _S9XLUA_H
puts ("--loadlua f Loads lua script from filename f."); puts ("--loadlua f Loads lua script from filename f.");
#endif #endif
#ifdef CREATE_AVI #ifdef CREATE_AVI
puts ("--videolog c Calls mencoder to grab the video and audio streams to\n encode them. Check the documentation for more on this."); puts ("--videolog c Calls mencoder to grab the video and audio streams to\n encode them. Check the documentation for more on this.");
puts ("--mute {0|1} Mutes FCEUX while still passing the audio stream to\n mencoder."); puts ("--mute {0|1} Mutes FCEUX while still passing the audio stream to\n mencoder.");
#endif #endif
puts(""); puts("");
printf("Compiled with SDL version %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL ); printf("Compiled with SDL version %d.%d.%d\n", SDL_MAJOR_VERSION, SDL_MINOR_VERSION, SDL_PATCHLEVEL );
#ifdef GTK_LITE
printf("Compiled with GTK version %d.%d.%d\n", GTK_MAJOR_VERSION, GTK_MINOR_VERSION, GTK_MICRO_VERSION );
#endif
} }
@ -665,7 +670,9 @@ SDL_GL_LoadLibrary(0);
SDL_Quit(); SDL_Quit();
return 0; return 0;
} }
g_config->setOption("SDL.RipSubs", "");
if (!s.empty())
for(int i=0; i<argc;i++) for(int i=0; i<argc;i++)
{ {
if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0)
@ -676,7 +683,7 @@ SDL_GL_LoadLibrary(0);
} }
} }
#ifndef _GTK2 #ifndef _GTK
if(romIndex <= 0) { if(romIndex <= 0) {
ShowUsage(argv[0]); ShowUsage(argv[0]);
@ -684,7 +691,7 @@ SDL_GL_LoadLibrary(0);
SDL_Quit(); SDL_Quit();
return -1; return -1;
} }
#endif #endif
@ -720,10 +727,13 @@ SDL_GL_LoadLibrary(0);
// load the hotkeys from the config life // load the hotkeys from the config life
setHotKeys(); setHotKeys();
#ifdef _GTK_LITE
#ifdef _GTK2 gtk_init(&argc, &argv);
#endif
#ifdef _GTK
InitGTKSubsystem(argc, argv); InitGTKSubsystem(argc, argv);
#endif #endif
if(romIndex >= 0) if(romIndex >= 0)
{ {
@ -781,19 +791,19 @@ SDL_GL_LoadLibrary(0);
// loop playing the game // loop playing the game
#ifndef _GTK2 #ifndef _GTK
while(GameInfo) { while(GameInfo) {
#else #else
while(1) { while(1) {
if(GameInfo) if(GameInfo)
#endif #endif
DoFun(frameskip); DoFun(frameskip);
#ifdef _GTK2 #ifdef _GTK
else else
SDL_Delay(10); SDL_Delay(10);
while(gtk_events_pending()) while(gtk_events_pending())
gtk_main_iteration_do(FALSE); gtk_main_iteration_do(FALSE);
#endif #endif
} }
CloseGame(); CloseGame();
@ -834,9 +844,9 @@ FCEUD_GetTimeFreq(void)
void FCEUD_Message(const char *text) void FCEUD_Message(const char *text)
{ {
fputs(text, stdout); fputs(text, stdout);
#ifdef _GTK2 #ifdef _GTK
pushOutputToGTK(text); pushOutputToGTK(text);
#endif #endif
} }
/** /**