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('CREATE_AVI', 'Enable avi creation support (SDL only)', 0),
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)
@ -58,10 +59,15 @@ else:
if not conf.CheckLib('z', autoadd=1):
print 'Did not find libz or z.lib, exiting!'
Exit(1)
if env['GTK2']:
# Add compiler and linker flags from pkg-config
env.Append(CPPDEFINES=["_GTK2"])
env.ParseConfig('pkg-config --cflags --libs gtk+-2.0')
if env['GTK'] or env['GTK_LITE']:
# Add compiler and linker flags from pkg-config
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
### 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.
# Should work on any *nix
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
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
[files]
current_page=2
FILE_NAME_0=663;None;0;16;1;1;0;/home/lukas/code/fceultra/fceu/SConstruct;0
FILE_NAME_1=5288;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/gui.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_3=956;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/gui.h;0
FILE_NAME_4=215;C;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/sdl/sdl.h;0
current_page=3
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=6651;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/drivers/win/sound.cpp;0
FILE_NAME_2=3961;C++;0;16;1;1;0;/home/lukas/code/fceultra/fceu/src/sound.cpp;0
FILE_NAME_3=0;C++;0;16;1;1;0;/home/lukas/code/vba-m/src/Sound.cpp;0

View File

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

View File

@ -5,7 +5,7 @@
#include <fstream>
#include <iostream>
#include <cstdlib>
//#include <vte/vte.h>
#include "../../types.h"
@ -802,7 +802,9 @@ void recordMovieAs ()
// TODO: don't use GetUserText; or implement it in GTK rather than zenity
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);
}
@ -938,7 +940,9 @@ void loadGame ()
filterNes = 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(filterFds, "*.fds");
gtk_file_filter_add_pattern(filterFds, "*.FDS");
gtk_file_filter_set_name(filterNes, "NES ROM files");
gtk_file_filter_set_name(filterFds, "FDS ROM files");
@ -963,6 +967,15 @@ void loadGame ()
g_free(filename);
}
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.YResolution", &yres);
gtk_init(&argc, &argv);
MainWindow = gtk_window_new(GTK_WINDOW_TOPLEVEL);
gtk_window_set_title(GTK_WINDOW(MainWindow), FCEU_NAME_AND_VERSION);

View File

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

View File

@ -39,6 +39,10 @@
#include "../../fceulua.h"
#endif
#ifdef _GTK_LITE
#include<gtk/gtk.h>
#endif
/** GLOBALS **/
int NoWaiting=1;
@ -262,7 +266,7 @@ std::string GetFilename(const char* title, bool save, const char* filter)
FCEUI_ToggleEmulationPause();
std::string fname = "";
#ifdef WIN32 // seriously?
#ifdef WIN32
OPENFILENAME ofn; // common dialog box structure
char szFile[260]; // buffer for file name
HWND hwnd; // owner window
@ -287,11 +291,50 @@ std::string GetFilename(const char* title, bool save, const char* filter)
// Display the Open dialog box.
fname = GetOpenFileName(&ofn);
#else
#endif
#ifdef _GTK_LITE
int fullscreen = 0;
g_config->getOption("SDL.Fullscreen", &fullscreen);
if(fullscreen)
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;
std::string command = "zenity --file-selection --title=\"";
command.append(title);
@ -316,8 +359,8 @@ std::string GetFilename(const char* title, bool save, const char* filter)
break;
fname += c;
}
pclose(fpipe);
#endif
pclose(fpipe);*/
#endif
FCEUI_ToggleEmulationPause();
return fname;
}
@ -327,14 +370,33 @@ std::string GetFilename(const char* title, bool save, const char* filter)
*/
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
int fullscreen = 0;
g_config->getOption("SDL.Fullscreen", &fullscreen);
if(fullscreen)
ToggleFS(); // disable fullscreen emulation
int fullscreen = 0;
g_config->getOption("SDL.Fullscreen", &fullscreen);
if(fullscreen)
ToggleFS(); // disable fullscreen emulation
/*
FILE *fpipe;
std::string command = "zenity --entry --title=\"";
command.append(title);
@ -352,9 +414,18 @@ std::string GetUserText(const char* title)
break;
input += c;
}
pclose(fpipe);
FCEUI_ToggleEmulationPause(); // unpause emulation
return input;
pclose(fpipe);*/
gtk_widget_destroy(d);
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"
#endif
#ifdef _GTK2
#ifdef _GTK
#include "gui.h"
#endif
@ -446,7 +446,7 @@ ToggleFS()
// flip the fullscreen flag
g_config->setOption("SDL.Fullscreen", !fullscreen);
#ifdef _GTK2
#ifdef _GTK
if(!fullscreen)
showGui(0);
else

View File

@ -13,8 +13,10 @@
#include <limits.h>
#include <math.h>
#ifdef _GTK2
#ifdef _GTK_LITE
#include <gtk/gtk.h>
#endif
#ifdef _GTK
#include "gui.cpp"
#endif
@ -143,15 +145,18 @@ static void ShowUsage(char *prog)
printf("\nUsage is as follows:\n%s <options> filename\n\n",prog);
puts("Options:");
puts(DriverUsage);
#ifdef _S9XLUA_H
#ifdef _S9XLUA_H
puts ("--loadlua f Loads lua script from filename f.");
#endif
#ifdef CREATE_AVI
#endif
#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 ("--mute {0|1} Mutes FCEUX while still passing the audio stream to\n mencoder.");
#endif
#endif
puts("");
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();
return 0;
}
g_config->setOption("SDL.RipSubs", "");
if (!s.empty())
for(int i=0; i<argc;i++)
{
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) {
ShowUsage(argv[0]);
@ -684,7 +691,7 @@ SDL_GL_LoadLibrary(0);
SDL_Quit();
return -1;
}
#endif
#endif
@ -720,10 +727,13 @@ SDL_GL_LoadLibrary(0);
// load the hotkeys from the config life
setHotKeys();
#ifdef _GTK2
#ifdef _GTK_LITE
gtk_init(&argc, &argv);
#endif
#ifdef _GTK
InitGTKSubsystem(argc, argv);
#endif
#endif
if(romIndex >= 0)
{
@ -781,19 +791,19 @@ SDL_GL_LoadLibrary(0);
// loop playing the game
#ifndef _GTK2
#ifndef _GTK
while(GameInfo) {
#else
#else
while(1) {
if(GameInfo)
#endif
#endif
DoFun(frameskip);
#ifdef _GTK2
#ifdef _GTK
else
SDL_Delay(10);
while(gtk_events_pending())
gtk_main_iteration_do(FALSE);
#endif
#endif
}
CloseGame();
@ -834,9 +844,9 @@ FCEUD_GetTimeFreq(void)
void FCEUD_Message(const char *text)
{
fputs(text, stdout);
#ifdef _GTK2
#ifdef _GTK
pushOutputToGTK(text);
#endif
#endif
}
/**