3 #include "FileMenu.h"
\r
5 class FileMenu FileMenu;
\r
9 memset(this,0,sizeof(*this));
\r
12 int FileMenu::init()
\r
14 memset(this,0,sizeof(*this));
\r
15 strcpy(currentPath,HOME "roms");
\r
20 int FileMenu::scan()
\r
24 memset(path,0,sizeof(path));
\r
26 // Scan for all the roms in the current directory:
\r
29 sprintf(path,"%.240s\\*.bin", currentPath); nameFind(path);
\r
30 sprintf(path,"%.240s\\*.smd", currentPath); nameFind(path);
\r
31 sprintf(path,"%.240s\\*.zip",currentPath); nameFind(path);
\r
36 void FileMenu::exit()
\r
39 memset(this,0,sizeof(*this));
\r
42 int FileMenu::render()
\r
49 memset(text,0,sizeof(text));
\r
52 y-=(choiceFocus*height)>>8;
\r
54 while (pos<nameSize)
\r
60 if (y>-height && y<MainHeight)
\r
62 unsigned int colour=0xffffff;
\r
64 // If this line is visible:
\r
65 wsprintfW(text,L"%.42S",name);
\r
66 if (index==(choiceFocus>>8)) colour=0x00ff40;
\r
68 FontSetColour(colour);
\r
73 pos+=strlen(name)+1; // Skip to next string
\r
80 int FileMenu::scroll(int amount)
\r
84 choiceFocus+=amount;
\r
87 if (choiceFocus<0) choiceFocus=0;
\r
88 if (choiceFocus>=max) choiceFocus=max-1;
\r
93 // Get the currently highlighted filename
\r
94 int FileMenu::getFilePath(char *path)
\r
100 // Find where the user is focused
\r
101 focus=choiceFocus>>8;
\r
102 pos=nameOffset(focus); if (pos<0) return 1;
\r
106 // Return path and name:
\r
107 sprintf(path,"%.128s\\%.128s",currentPath,name);
\r
111 // ----------------------------------------------------------------------
\r
112 int FileMenu::nameReset()
\r
114 free(nameList); nameList=NULL;
\r
115 nameSize=nameMax=nameCount=0;
\r
120 int FileMenu::nameFind(char *path)
\r
123 WIN32_FIND_DATA wfd;
\r
125 memset(&wfd,0,sizeof(wfd));
\r
127 find=FindFirstFile(path,&wfd);
\r
128 if (find==INVALID_HANDLE_VALUE) return 1;
\r
132 nameAdd(wfd.cFileName); // Add the name to the list
\r
134 if (FindNextFile(find,&wfd)==0) break;
\r
141 int FileMenu::nameAdd(char *entry)
\r
146 // Check we have room for this entry:
\r
147 if (nameSize+len+1>nameMax) nameSizeUp();
\r
148 if (nameSize+len+1>nameMax) return 1;
\r
150 // Add entry with zero at the end:
\r
151 memcpy(nameList+nameSize,entry,len);
\r
158 int FileMenu::nameSizeUp()
\r
164 // Allocate more memory for the list:
\r
165 mem=realloc(nameList,nameMax+add); if (mem==NULL) return 1;
\r
167 nameList=(char *)mem;
\r
168 memset(nameList+nameMax,0,add); // Blank new memory
\r
173 int FileMenu::nameOffset(int index)
\r
177 while (pos<nameSize)
\r
179 char *name=nameList+pos;
\r
181 if (i==index) return pos;
\r
183 pos+=strlen(name)+1; // Skip to next string
\r
187 return -1; // Unknown index
\r