X-Git-Url: http://shamusworld.gotdns.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fgui.cpp;h=404af7e4f481fbf71ebdf01686c64bc9e3bb0830;hb=007583184c38430a9642ed2d71624141e8cd4f7a;hp=17e522c9b7074ee6ed8ef272450c393f5ec42850;hpb=99461abfcbc562e740a5e0900167ece9a4a5a035;p=virtualjaguar diff --git a/src/gui.cpp b/src/gui.cpp index 17e522c..404af7e 100644 --- a/src/gui.cpp +++ b/src/gui.cpp @@ -5,19 +5,281 @@ // by James L. Hammons // +#include +#include +#include +#include +#include #include "types.h" +#include "settings.h" #include "tom.h" +#include "video.h" +#include "font1.h" #include "gui.h" +using namespace std; // For STL stuff + +// Private function prototypes + +// Local global variables + +int mouseX, mouseY; + +uint16 mousePic[] = { + 6, 8, + + 0x03E0,0x0000,0x0000,0x0000,0x0000,0x0000, // + + 0x0300,0x03E0,0x0000,0x0000,0x0000,0x0000, // @+ + 0x0300,0x03E0,0x03E0,0x0000,0x0000,0x0000, // @++ + 0x0300,0x0300,0x03E0,0x03E0,0x0000,0x0000, // @@++ + 0x0300,0x0300,0x03E0,0x03E0,0x03E0,0x0000, // @@+++ + 0x0300,0x0300,0x0300,0x03E0,0x03E0,0x03E0, // @@@+++ + 0x0300,0x0300,0x0300,0x0000,0x0000,0x0000, // @@@ + 0x0300,0x0000,0x0000,0x0000,0x0000,0x0000 // @ +/* + 0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000, // + + 0xE318,0xFFFF,0x0000,0x0000,0x0000,0x0000, // @+ + 0xE318,0xFFFF,0xFFFF,0x0000,0x0000,0x0000, // @++ + 0xE318,0xE318,0xFFFF,0xFFFF,0x0000,0x0000, // @@++ + 0xE318,0xE318,0xFFFF,0xFFFF,0xFFFF,0x0000, // @@+++ + 0xE318,0xE318,0xE318,0xFFFF,0xFFFF,0xFFFF, // @@@+++ + 0xE318,0xE318,0xE318,0x0000,0x0000,0x0000, // @@@ + 0xE318,0x0000,0x0000,0x0000,0x0000,0x0000 // @ +*/ +}; +// 1 111 00 11 100 1 1100 -> F39C +// 1 100 00 10 000 1 0000 -> C210 +// 1 110 00 11 000 1 1000 -> E318 +// 0 000 00 11 111 0 0000 -> 03E0 +// 0 000 00 11 000 0 0000 -> 0300 + void InitGUI(void) { + SDL_ShowCursor(SDL_DISABLE); + SDL_GetMouseState(&mouseX, &mouseY); } void GUIDone(void) { } -void DrawText(uint16 * screen, uint32 x, uint32 y, const char * string) +// +// Draw text at the given x/y coordinates. Can invert text as well. +// +void DrawString(int16 * screen, uint32 x, uint32 y, bool invert, const char * text, ...) +{ + char string[4096]; + va_list arg; + + va_start(arg, text); + vsprintf(string, text, arg); + va_end(arg); + + 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; + + // Read in the candidate files from the directory pointed to by "path" + + DIR * dp = opendir(path); + dirent * de; + + while ((de = readdir(dp)) != NULL) + { + char * ext = strrchr(de->d_name, '.'); + + if (ext != NULL) + if (stricmp(ext, ".zip") == 0 || stricmp(ext, ".jag") == 0) + fileList.push_back(string(de->d_name)); + } + + closedir(dp); + + // Main GUI selection loop + + uint32 cursor = 0, startFile = 0; + + if (fileList.size() > 1) // Only go GUI if more than one possibility! + { + sort(fileList.begin(), fileList.end()); + + bool done = false; + uint32 limit = (fileList.size() > 30 ? 30 : fileList.size()); + SDL_Event event; + + // Ensure that the GUI is drawn before any user input... + event.type = SDL_USEREVENT; + SDL_PushEvent(&event); + + while (!done) + { + while (SDL_PollEvent(&event)) + { + if (event.type == SDL_KEYDOWN) + { + SDLKey key = event.key.keysym.sym; + + if (key == SDLK_DOWN) + { + if (cursor != limit - 1) // Cursor is within its window + cursor++; + else // Otherwise, scroll the window... + { + if (cursor + startFile != fileList.size() - 1) + startFile++; + } + } + if (key == SDLK_UP) + { + if (cursor != 0) + cursor--; + else + { + if (startFile != 0) + startFile--; + } + } + if (key == SDLK_PAGEDOWN) + { + if (cursor != limit - 1) + cursor = limit - 1; + else + { + startFile += limit; + if (startFile > fileList.size() - limit) + startFile = fileList.size() - limit; + } + } + if (key == SDLK_PAGEUP) + { + if (cursor != 0) + cursor = 0; + else + { + if (startFile < limit) + startFile = 0; + else + startFile -= limit; + } + } + if (key == SDLK_RETURN) + done = true; + if (key == SDLK_ESCAPE) + { + 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) + { + mouseX = event.motion.x, mouseY = event.motion.y; + if (vjs.useOpenGL) + mouseX /= 2, mouseY /= 2; + } + else if (event.type == SDL_MOUSEBUTTONDOWN) + { + uint32 mx = event.button.x, my = event.button.y; + if (vjs.useOpenGL) + mx /= 2, my /= 2; + cursor = my / 8; + } + + // Draw the GUI... +// 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, (cursor == i ? true : false), " %s ", s.c_str()); + } + + DrawTransparentBitmap(backbuffer, mouseX, mouseY, mousePic); + + RenderBackbuffer(); + } + } + } + + strcpy(filename, path); + + if (strlen(path) > 0) + if (path[strlen(path) - 1] != '/') + strcat(filename, "/"); + + strcat(filename, fileList[startFile + cursor].c_str()); + + return true; }