diff --git a/SConstruct b/SConstruct index a8b56178..d9a1978c 100644 --- a/SConstruct +++ b/SConstruct @@ -57,6 +57,9 @@ else: if not conf.CheckLib('z', autoadd=1): print 'Did not find libz or z.lib, exiting!' Exit(1) + ### TODO: clean this up + ## Uncomment below for experimental (broken) GTK support + #env.ParseConfig('pkg-config --cflags --libs gtk+-2.0') ### Lua platform defines ### Applies to all files even though only lua needs it, but should be ok diff --git a/src/drivers/sdl/gui.cpp b/src/drivers/sdl/gui.cpp index 22e8e22f..5287d1af 100644 --- a/src/drivers/sdl/gui.cpp +++ b/src/drivers/sdl/gui.cpp @@ -3,40 +3,57 @@ #include -#define WIDTH 600 -#define HEIGHT 600 +#include "../common/configSys.h" +#include "sdl.h" +#include "gui.h" + +//#define WIDTH 600 +//#define HEIGHT 600 + + +extern Config *g_config; + + +//SDL_Surface* screen = NULL; +//SDL_Surface* hello = NULL; + -GtkWidget* MainWindow; -SDL_Surface* screen = NULL; -SDL_Surface* hello = NULL; gint mainLoop(gpointer data) { - SDL_UpdateRect(screen, 0, 0, WIDTH, HEIGHT); + //SDL_UpdateRect(screen, 0, 0, xres, yres); // TODO: integrate main SDL loop here + // test render + //SDL_BlitSurface (hello, NULL, screen, NULL); - SDL_BlitSurface (hello, NULL, screen, NULL); + //SDL_Flip( screen ); + DoFun(0); - SDL_Flip( screen ); return TRUE; } gint configureEvent (GtkWidget* widget, GdkEventConfigure* event) { - screen = SDL_SetVideoMode(event->width, event->height, 0, 0); + //??? + //s_screen = SDL_SetVideoMode(event->width, event->height, 0, 0); return TRUE; } -int main(int argc, char** argv) +int InitGTKSubsystem(int argc, char** argv) { + GtkWidget* MainWindow; + int xres, yres; + + 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), "fceuX GTK GUI - WIP"); - gtk_widget_set_usize(MainWindow, WIDTH, HEIGHT); + gtk_widget_set_usize(MainWindow, xres, yres); gtk_widget_realize(MainWindow); // event handlers @@ -51,10 +68,7 @@ int main(int argc, char** argv) gtk_container_add (GTK_CONTAINER(MainWindow), socket); gtk_widget_realize (socket); - - - // Hack to get SDL to use GTK window - // broken as fuck? + char SDL_windowhack[24]; sprintf(SDL_windowhack, "SDL_WINDOWID=%ld", (long int)gtk_socket_get_id (GTK_SOCKET(socket))); putenv(SDL_windowhack); @@ -67,28 +81,25 @@ int main(int argc, char** argv) gtk_main_quit(); } - screen = SDL_SetVideoMode(WIDTH, HEIGHT, 0, 0); - - - hello = SDL_LoadBMP( "hello.bmp" ); - - SDL_BlitSurface (hello, NULL, screen, NULL); - - SDL_Flip( screen ); + //screen = SDL_SetVideoMode(xres, yres, 0, 0); + //hello = SDL_LoadBMP( "hello.bmp" ); + // signal handlers g_signal_connect(G_OBJECT(MainWindow), "delete-event", gtk_main_quit, NULL); - gtk_idle_add(mainLoop, MainWindow); + //gtk_idle_add(mainLoop, MainWindow); gtk_widget_show_all(MainWindow); - gtk_main(); - SDL_Quit(); + // TODO: we're not going to want to use gtk_main here so we can control + // the event loop and use SDL events rather than GTK events + //gtk_main(); + //SDL_Quit(); return 0; } diff --git a/src/drivers/sdl/sdl-video.cpp b/src/drivers/sdl/sdl-video.cpp index 079c1ac2..3989ef5f 100644 --- a/src/drivers/sdl/sdl-video.cpp +++ b/src/drivers/sdl/sdl-video.cpp @@ -45,7 +45,7 @@ extern Config *g_config; // STATIC GLOBALS -static SDL_Surface *s_screen; +extern SDL_Surface *s_screen; static SDL_Surface *s_BlitBuf; // Buffer when using hardware-accelerated blits. static SDL_Surface *s_IconSurface = NULL; diff --git a/src/drivers/sdl/sdl-video.h b/src/drivers/sdl/sdl-video.h index 002f4c8b..91b41e68 100644 --- a/src/drivers/sdl/sdl-video.h +++ b/src/drivers/sdl/sdl-video.h @@ -1,2 +1,8 @@ +#ifndef __FCEU_SDL_VIDEO_H +#define __FCEU_SDL_VIDEO_H uint32 PtoV(uint16 x, uint16 y); bool FCEUD_ShouldDrawInputAids(); + +static SDL_Surface *s_screen; + +#endif diff --git a/src/drivers/sdl/sdl.cpp b/src/drivers/sdl/sdl.cpp index aa5cff8f..8269323a 100644 --- a/src/drivers/sdl/sdl.cpp +++ b/src/drivers/sdl/sdl.cpp @@ -14,6 +14,12 @@ #include +//#define GTK_GUI +#ifdef GTK_GUI +#include +#include "gui.cpp" +#endif + #include "main.h" #include "throttle.h" #include "config.h" @@ -678,6 +684,11 @@ SDL_GL_LoadLibrary(0); // load the hotkeys from the config life setHotKeys(); + + #ifdef GTK_GUI + InitGTKSubsystem(argc, argv); + #endif + // load the specified game error = LoadGame(argv[romIndex]); if(error != 1) { @@ -726,11 +737,17 @@ SDL_GL_LoadLibrary(0); FCEU_LoadLuaCode(fname.c_str()); }*/ + //TODO: Work this bullshit out + // loop playing the game while(GameInfo) { DoFun(frameskip); + #ifdef GTK_GUI + while(gtk_events_pending()) + gtk_main_iteration_do(FALSE); + #endif } CloseGame(); diff --git a/src/drivers/sdl/sdl.h b/src/drivers/sdl/sdl.h index c261d1df..e88cda25 100644 --- a/src/drivers/sdl/sdl.h +++ b/src/drivers/sdl/sdl.h @@ -1,4 +1,11 @@ +#ifndef __FCEU_SDL_H +#define __FCEU_SDL_H + #include #include "main.h" #include "dface.h" #include "input.h" + +static void DoFun(int frameskip); + +#endif