X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui.cpp;h=29f626dec4922bf90620e04bb9ad3da617666de5;hb=74e7dd93689112ab80538d98cc5fd9bfe7a08078;hp=db683ab9c0c5b8f19c7121fe0b05e40f5c9a4e59;hpb=a2f29c64b6ca441c51d6d1340907a1168c15fc7b;p=virtualjaguar diff --git a/src/gui.cpp b/src/gui.cpp index db683ab..29f626d 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -6,11 +6,18 @@ // #include +#include +#include #include "types.h" #include "tom.h" #include "font1.h" #include "gui.h" +// Private function prototypes + +uint32 CountROMFiles(char * path); + + void InitGUI(void) { } @@ -19,6 +26,33 @@ void GUIDone(void) { } +// +// Render the backbuffer to the primary screen surface +// +void BlitBackbuffer(void) +{ + extern SDL_Surface * surface, * mainSurface; + extern int16 * backbuffer; + + if (SDL_MUSTLOCK(surface)) + while (SDL_LockSurface(surface) < 0) + SDL_Delay(10); + + memcpy(surface->pixels, backbuffer, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2); + + if (SDL_MUSTLOCK(surface)) + SDL_UnlockSurface(surface); + + SDL_Rect srcrect, dstrect; + srcrect.x = srcrect.y = 0, srcrect.w = surface->w, srcrect.h = surface->h; + dstrect.x = dstrect.y = 0, dstrect.w = surface->w, dstrect.h = surface->h; + SDL_BlitSurface(surface, &srcrect, mainSurface, &dstrect); + SDL_Flip(mainSurface); +} + +// +// Draw text at the given x/y coordinates. Can invert text as well. +// void DrawText(int16 * screen, uint32 x, uint32 y, bool invert, const char * text, ...) { char string[4096]; @@ -48,3 +82,142 @@ void DrawText(int16 * screen, uint32 x, uint32 y, bool invert, const char * text address += 8; } } + +// +// Very very crude GUI file selector +// +bool UserSelectFile(char * path, char * filename) +{ + extern int16 * backbuffer; + uint32 numFiles = CountROMFiles(path); + + if (numFiles == 0) + return false; + + char * names = (char *)malloc(numFiles * 2048); + + if (names == NULL) + { + WriteLog("Could not allocate memory for %u files!\nAborting!\n", numFiles); + return false; + } + + int i = 0; + DIR * dp = opendir(path); + dirent * de; + + while ((de = readdir(dp)) != NULL) + { + char * ext = strrchr(de->d_name, '.'); + if (ext != NULL) + if (strcmpi(ext, ".zip") == 0 || strcmpi(ext, ".jag") == 0) + strcpy(&names[i++ * 2048], de->d_name); + } + + closedir(dp); + + // Main GUI selection loop + + uint32 cursor = 0, startFile = 0; + + if (numFiles > 1) // Only go GUI if more than one possibility! + { + bool done = false; + uint32 limit = (numFiles > 24 ? 24 : numFiles); + SDL_Event event; + + while (!done) + { + while (SDL_PollEvent(&event)) + { + // Draw the GUI... + memset(backbuffer, 0x11, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2); + + for(uint32 i=0; id_name, '.'); + if (ext != NULL) + if (strcmpi(ext, ".zip") == 0 || strcmpi(ext, ".jag") == 0) + numFiles++; + } + + closedir(dp); + } + + return numFiles; +}