4 // Graphical User Interface support
19 using namespace std; // For STL stuff
21 // Private function prototypes
33 // Draw text at the given x/y coordinates. Can invert text as well.
35 void DrawString(int16 * screen, uint32 x, uint32 y, bool invert, const char * text, ...)
41 vsprintf(string, text, arg);
44 uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words...
45 uint32 length = strlen(string), address = x + (y * pitch);
47 for(uint32 i=0; i<length; i++)
49 uint32 fontAddr = (uint32)string[i] * 64;
51 for(uint32 yy=0; yy<8; yy++)
53 for(uint32 xx=0; xx<8; xx++)
55 if ((font1[fontAddr] && !invert) || (!font1[fontAddr] && invert))
56 *(screen + address + xx + (yy * pitch)) = 0xFE00;
66 // Very very crude GUI file selector
68 bool UserSelectFile(char * path, char * filename)
70 extern int16 * backbuffer;
71 vector<string> fileList;
73 // Read in the candidate files from the directory pointed to by "path"
75 DIR * dp = opendir(path);
78 while ((de = readdir(dp)) != NULL)
80 char * ext = strrchr(de->d_name, '.');
83 if (stricmp(ext, ".zip") == 0 || stricmp(ext, ".jag") == 0)
84 fileList.push_back(string(de->d_name));
89 // Main GUI selection loop
91 uint32 cursor = 0, startFile = 0;
93 if (fileList.size() > 1) // Only go GUI if more than one possibility!
95 sort(fileList.begin(), fileList.end());
98 uint32 limit = (fileList.size() > 24 ? 24 : fileList.size());
103 while (SDL_PollEvent(&event))
106 memset(backbuffer, 0x11, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2);
108 for(uint32 i=0; i<limit; i++)
110 bool invert = (cursor == i ? true : false);
111 // Clip our strings to guarantee that they fit on the screen...
112 string s = fileList[startFile + i];
115 DrawString(backbuffer, 0, i*8, invert, " %s ", s.c_str());
120 if (event.type == SDL_KEYDOWN)
122 SDLKey key = event.key.keysym.sym;
124 if (key == SDLK_DOWN)
126 if (cursor != limit - 1) // Cursor is within its window
128 else // Otherwise, scroll the window...
130 if (cursor + startFile != fileList.size() - 1)
144 if (key == SDLK_PAGEDOWN)
147 if (key == SDLK_PAGEUP)
150 if (key == SDLK_RETURN)
152 if (key == SDLK_ESCAPE)
154 WriteLog("GUI: Aborting VJ by user request.\n");
155 return false; // Bail out!
157 if (key >= SDLK_a && key <= SDLK_z)
159 // Advance cursor to filename with first letter pressed...
160 uint8 which = (key - SDLK_a) + 65; // Convert key to A-Z char
162 for(uint32 i=0; i<fileList.size(); i++)
164 if ((fileList[i][0] & 0xDF) == which)
166 cursor = i - startFile;
167 if (i > startFile + limit - 1)
168 startFile = i - limit + 1,
182 strcpy(filename, path);
184 if (strlen(path) > 0)
185 if (path[strlen(path) - 1] != '/')
186 strcat(filename, "/");
188 strcat(filename, fileList[startFile + cursor].c_str());