4 // Graphical User Interface support
20 using namespace std; // For STL stuff
22 // Private function prototypes
24 // Local global variables
31 0x03E0,0x0000,0x0000,0x0000,0x0000,0x0000, // +
32 0x0300,0x03E0,0x0000,0x0000,0x0000,0x0000, // @+
33 0x0300,0x03E0,0x03E0,0x0000,0x0000,0x0000, // @++
34 0x0300,0x0300,0x03E0,0x03E0,0x0000,0x0000, // @@++
35 0x0300,0x0300,0x03E0,0x03E0,0x03E0,0x0000, // @@+++
36 0x0300,0x0300,0x0300,0x03E0,0x03E0,0x03E0, // @@@+++
37 0x0300,0x0300,0x0300,0x0000,0x0000,0x0000, // @@@
38 0x0300,0x0000,0x0000,0x0000,0x0000,0x0000 // @
40 0xFFFF,0x0000,0x0000,0x0000,0x0000,0x0000, // +
41 0xE318,0xFFFF,0x0000,0x0000,0x0000,0x0000, // @+
42 0xE318,0xFFFF,0xFFFF,0x0000,0x0000,0x0000, // @++
43 0xE318,0xE318,0xFFFF,0xFFFF,0x0000,0x0000, // @@++
44 0xE318,0xE318,0xFFFF,0xFFFF,0xFFFF,0x0000, // @@+++
45 0xE318,0xE318,0xE318,0xFFFF,0xFFFF,0xFFFF, // @@@+++
46 0xE318,0xE318,0xE318,0x0000,0x0000,0x0000, // @@@
47 0xE318,0x0000,0x0000,0x0000,0x0000,0x0000 // @
50 // 1 111 00 11 100 1 1100 -> F39C
51 // 1 100 00 10 000 1 0000 -> C210
52 // 1 110 00 11 000 1 1000 -> E318
53 // 0 000 00 11 111 0 0000 -> 03E0
54 // 0 000 00 11 000 0 0000 -> 0300
58 SDL_ShowCursor(SDL_DISABLE);
59 SDL_GetMouseState(&mouseX, &mouseY);
67 // Draw text at the given x/y coordinates. Can invert text as well.
69 void DrawString(int16 * screen, uint32 x, uint32 y, bool invert, const char * text, ...)
75 vsprintf(string, text, arg);
78 uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words...
79 uint32 length = strlen(string), address = x + (y * pitch);
81 for(uint32 i=0; i<length; i++)
83 uint32 fontAddr = (uint32)string[i] * 64;
85 for(uint32 yy=0; yy<8; yy++)
87 for(uint32 xx=0; xx<8; xx++)
89 if ((font1[fontAddr] && !invert) || (!font1[fontAddr] && invert))
90 *(screen + address + xx + (yy * pitch)) = 0xFE00;
101 // Uses zero as transparent color
103 void DrawTransparentBitmap(int16 * screen, uint32 x, uint32 y, uint16 * bitmap)
105 uint16 width = bitmap[0], height = bitmap[1];
108 uint32 pitch = GetSDLScreenPitch() / 2; // Returns pitch in bytes but we need words...
109 uint32 address = x + (y * pitch);
111 for(int yy=0; yy<height; yy++)
113 for(int xx=0; xx<width; xx++)
115 if (*bitmap && x + xx < pitch) // NOTE: Still doesn't clip the Y val...
116 *(screen + address + xx + (yy * pitch)) = *bitmap;
123 // Very very crude GUI file selector
125 bool UserSelectFile(char * path, char * filename)
127 extern int16 * backbuffer;
128 vector<string> fileList;
130 // Read in the candidate files from the directory pointed to by "path"
132 DIR * dp = opendir(path);
135 while ((de = readdir(dp)) != NULL)
137 char * ext = strrchr(de->d_name, '.');
140 if (stricmp(ext, ".zip") == 0 || stricmp(ext, ".jag") == 0)
141 fileList.push_back(string(de->d_name));
146 // Main GUI selection loop
148 uint32 cursor = 0, startFile = 0;
150 if (fileList.size() > 1) // Only go GUI if more than one possibility!
152 sort(fileList.begin(), fileList.end());
155 uint32 limit = (fileList.size() > 30 ? 30 : fileList.size());
158 // Ensure that the GUI is drawn before any user input...
159 event.type = SDL_USEREVENT;
160 SDL_PushEvent(&event);
164 while (SDL_PollEvent(&event))
166 if (event.type == SDL_KEYDOWN)
168 SDLKey key = event.key.keysym.sym;
170 if (key == SDLK_DOWN)
172 if (cursor != limit - 1) // Cursor is within its window
174 else // Otherwise, scroll the window...
176 if (cursor + startFile != fileList.size() - 1)
190 if (key == SDLK_PAGEDOWN)
192 if (cursor != limit - 1)
197 if (startFile > fileList.size() - limit)
198 startFile = fileList.size() - limit;
201 if (key == SDLK_PAGEUP)
207 if (startFile < limit)
213 if (key == SDLK_RETURN)
215 if (key == SDLK_ESCAPE)
217 WriteLog("GUI: Aborting VJ by user request.\n");
218 return false; // Bail out!
220 if (key >= SDLK_a && key <= SDLK_z)
222 // Advance cursor to filename with first letter pressed...
223 uint8 which = (key - SDLK_a) + 65; // Convert key to A-Z char
225 for(uint32 i=0; i<fileList.size(); i++)
227 if ((fileList[i][0] & 0xDF) == which)
229 cursor = i - startFile;
230 if (i > startFile + limit - 1)
231 startFile = i - limit + 1,
241 else if (event.type == SDL_MOUSEMOTION)
243 mouseX = event.motion.x, mouseY = event.motion.y;
245 mouseX /= 2, mouseY /= 2;
247 else if (event.type == SDL_MOUSEBUTTONDOWN)
249 uint32 mx = event.button.x, my = event.button.y;
256 // memset(backbuffer, 0x11, tom_getVideoModeWidth() * tom_getVideoModeHeight() * 2);
257 memset(backbuffer, 0x11, tom_getVideoModeWidth() * 240 * 2);
259 for(uint32 i=0; i<limit; i++)
261 // Clip our strings to guarantee that they fit on the screen...
262 // (and strip off the extension too)
263 string s(fileList[startFile + i], 0, fileList[startFile + i].length() - 4);
266 DrawString(backbuffer, 0, i*8, (cursor == i ? true : false), " %s ", s.c_str());
269 DrawTransparentBitmap(backbuffer, mouseX, mouseY, mousePic);
276 strcpy(filename, path);
278 if (strlen(path) > 0)
279 if (path[strlen(path) - 1] != '/')
280 strcat(filename, "/");
282 strcat(filename, fileList[startFile + cursor].c_str());