X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui.cpp;h=613cf88206cc1e7ce76f535508643eee3f740736;hb=d840c416a27a17287406fadf152bb72b43a563fb;hp=29f626dec4922bf90620e04bb9ad3da617666de5;hpb=cd61d997688c71e8eeecf39e4ce9d77a08872d7b;p=virtualjaguar diff --git a/src/gui.cpp b/src/gui.cpp index 29f626d..613cf88 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -5,55 +5,40 @@ // by James L. Hammons // -#include #include #include +#include +#include +#include #include "types.h" #include "tom.h" +#include "video.h" #include "font1.h" #include "gui.h" +using namespace std; // For STL stuff + // Private function prototypes -uint32 CountROMFiles(char * path); +// Local global variables + +int mouseX, mouseY; void InitGUI(void) { + SDL_ShowCursor(SDL_DISABLE); + SDL_GetMouseState(&mouseX, &mouseY); } 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, ...) +void DrawString(int16 * screen, uint32 x, uint32 y, bool invert, const char * text, ...) { char string[4096]; va_list arg; @@ -62,7 +47,7 @@ void DrawText(int16 * screen, uint32 x, uint32 y, bool invert, const char * text vsprintf(string, text, arg); va_end(arg); - uint32 pitch = TOMGetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words... + uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words... uint32 length = strlen(string), address = x + (y * pitch); for(uint32 i=0; i fileList; - if (numFiles == 0) - return false; + // Read in the candidate files from the directory pointed to by "path" - 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); + if (stricmp(ext, ".zip") == 0 || stricmp(ext, ".jag") == 0) + fileList.push_back(string(de->d_name)); } closedir(dp); @@ -120,10 +96,12 @@ bool UserSelectFile(char * path, char * filename) uint32 cursor = 0, startFile = 0; - if (numFiles > 1) // Only go GUI if more than one possibility! + if (fileList.size() > 1) // Only go GUI if more than one possibility! { + sort(fileList.begin(), fileList.end()); + bool done = false; - uint32 limit = (numFiles > 24 ? 24 : numFiles); + uint32 limit = (fileList.size() > 30 ? 30 : fileList.size()); SDL_Event event; while (!done) @@ -131,19 +109,25 @@ bool UserSelectFile(char * path, char * filename) while (SDL_PollEvent(&event)) { // Draw the GUI... - memset(backbuffer, 0x11, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2); +// memset(backbuffer, 0x11, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2); + memset(backbuffer, 0x11, tom_getVideoModeWidth() * 240 * 2); for(uint32 i=0; i 38) + s[38] = 0; + DrawString(backbuffer, 0, i*8, invert, " %s ", s.c_str()); } - BlitBackbuffer(); + uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words... +// uint32 address = x + (y * pitch); + backbuffer[mouseX + (mouseY * pitch)] = 0xFFFF; + + + RenderBackbuffer(); if (event.type == SDL_KEYDOWN) { @@ -155,7 +139,7 @@ bool UserSelectFile(char * path, char * filename) cursor++; else // Otherwise, scroll the window... { - if (cursor + startFile != numFiles - 1) + if (cursor + startFile != fileList.size() - 1) startFile++; } } @@ -169,6 +153,12 @@ bool UserSelectFile(char * path, char * filename) startFile--; } } + if (key == SDLK_PAGEDOWN) + { + } + if (key == SDLK_PAGEUP) + { + } if (key == SDLK_RETURN) done = true; if (key == SDLK_ESCAPE) @@ -176,48 +166,44 @@ bool UserSelectFile(char * path, char * filename) WriteLog("GUI: Aborting VJ by user request.\n"); return false; // Bail out! } + if (key >= SDLK_a && key <= SDLK_z) + { + // Advance cursor to filename with first letter pressed... + uint8 which = (key - SDLK_a) + 65; // Convert key to A-Z char + + for(uint32 i=0; i startFile + limit - 1) + startFile = i - limit + 1, + cursor = limit - 1; + if (i < startFile) + startFile = i, + cursor = 0; + break; + } + } + } + } + else if (event.type == SDL_MOUSEMOTION) + { + //Kludge: divide by two in order to display properly on our blown up + // screen... + mouseX = event.motion.x / 2, mouseY = event.motion.y / 2; } } } } strcpy(filename, path); - // Potential GPF here: If length of dir is zero, then this will cause a page fault! - if (path[strlen(path) - 1] != '/') - strcat(filename, "/"); - strcat(filename, &names[(cursor + startFile) * 2048]); - free(names); - return true; -} + if (strlen(path) > 0) + if (path[strlen(path) - 1] != '/') + strcat(filename, "/"); -// -// Count # of possible ROM files in the current directory -// -uint32 CountROMFiles(char * path) -{ - uint32 numFiles = 0; - DIR * dp = opendir(path); - - if (dp == NULL) - { - WriteLog("VJ: Could not open directory \"%s\"!\nAborting!\n", path); - return 0; - } - else - { - dirent * de; + strcat(filename, fileList[startFile + cursor].c_str()); - while ((de = readdir(dp)) != NULL) - { - char * ext = strrchr(de->d_name, '.'); - if (ext != NULL) - if (strcmpi(ext, ".zip") == 0 || strcmpi(ext, ".jag") == 0) - numFiles++; - } - - closedir(dp); - } - - return numFiles; + return true; }