4 // Graphical User Interface support
19 using namespace std; // For STL stuff
21 // Private function prototypes
23 // Local global variables
30 SDL_ShowCursor(SDL_DISABLE);
31 SDL_GetMouseState(&mouseX, &mouseY);
39 // Draw text at the given x/y coordinates. Can invert text as well.
41 void DrawString(int16 * screen, uint32 x, uint32 y, bool invert, const char * text, ...)
47 vsprintf(string, text, arg);
50 uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words...
51 uint32 length = strlen(string), address = x + (y * pitch);
53 for(uint32 i=0; i<length; i++)
55 uint32 fontAddr = (uint32)string[i] * 64;
57 for(uint32 yy=0; yy<8; yy++)
59 for(uint32 xx=0; xx<8; xx++)
61 if ((font1[fontAddr] && !invert) || (!font1[fontAddr] && invert))
62 *(screen + address + xx + (yy * pitch)) = 0xFE00;
72 // Very very crude GUI file selector
74 bool UserSelectFile(char * path, char * filename)
76 extern int16 * backbuffer;
77 vector<string> fileList;
79 // Read in the candidate files from the directory pointed to by "path"
81 DIR * dp = opendir(path);
84 while ((de = readdir(dp)) != NULL)
86 char * ext = strrchr(de->d_name, '.');
89 if (stricmp(ext, ".zip") == 0 || stricmp(ext, ".jag") == 0)
90 fileList.push_back(string(de->d_name));
95 // Main GUI selection loop
97 uint32 cursor = 0, startFile = 0;
99 if (fileList.size() > 1) // Only go GUI if more than one possibility!
101 sort(fileList.begin(), fileList.end());
104 uint32 limit = (fileList.size() > 30 ? 30 : fileList.size());
109 while (SDL_PollEvent(&event))
112 // memset(backbuffer, 0x11, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2);
113 memset(backbuffer, 0x11, tom_getVideoModeWidth() * 240 * 2);
115 for(uint32 i=0; i<limit; i++)
117 bool invert = (cursor == i ? true : false);
118 // Clip our strings to guarantee that they fit on the screen...
119 string s = fileList[startFile + i];
122 DrawString(backbuffer, 0, i*8, invert, " %s ", s.c_str());
125 uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words...
126 // uint32 address = x + (y * pitch);
127 backbuffer[mouseX + (mouseY * pitch)] = 0xFFFF;
132 if (event.type == SDL_KEYDOWN)
134 SDLKey key = event.key.keysym.sym;
136 if (key == SDLK_DOWN)
138 if (cursor != limit - 1) // Cursor is within its window
140 else // Otherwise, scroll the window...
142 if (cursor + startFile != fileList.size() - 1)
156 if (key == SDLK_PAGEDOWN)
159 if (key == SDLK_PAGEUP)
162 if (key == SDLK_RETURN)
164 if (key == SDLK_ESCAPE)
166 WriteLog("GUI: Aborting VJ by user request.\n");
167 return false; // Bail out!
169 if (key >= SDLK_a && key <= SDLK_z)
171 // Advance cursor to filename with first letter pressed...
172 uint8 which = (key - SDLK_a) + 65; // Convert key to A-Z char
174 for(uint32 i=0; i<fileList.size(); i++)
176 if ((fileList[i][0] & 0xDF) == which)
178 cursor = i - startFile;
179 if (i > startFile + limit - 1)
180 startFile = i - limit + 1,
190 else if (event.type == SDL_MOUSEMOTION)
192 //Kludge: divide by two in order to display properly on our blown up
194 mouseX = event.motion.x / 2, mouseY = event.motion.y / 2;
200 strcpy(filename, path);
202 if (strlen(path) > 0)
203 if (path[strlen(path) - 1] != '/')
204 strcat(filename, "/");
206 strcat(filename, fileList[startFile + cursor].c_str());