This is a file browser I wrote some time in 2004. It uses no media, instead it generates everything itself. The function is about 500 lines long but the important thing is it works.
Also note that this was originally written for use in DBC.
One thing though, you may want to try and implement some mouse click resets. At the moment it is currently counting a variable from 0 -> 10 which, if you are using a fast computer, will result in very fast browsing!
Language:
Dark Basic Pro
Code:
` Initialize sync on : sync rate 0 ` write browser arrays Dim File$(9999) : ` Do NOT edit this line!! Dim EntryY(9999) : ` Do NOT edit this line!! Dim File(2) : ` Do NOT edit this line!! Dim Filename$(1) : ` Do NOT edit this line!! Dim FileDir$(1) : ` Do NOT edit this line!! Dim Title$(1) : ` Do NOT edit this line!! Dim Drive(1) : ` Do NOT edit this line!! Dim Drive$(26) : ` Do NOT edit this line!! Dim DriveY(26) : ` Do NOT edit this line!! Dim Filter(1) : ` Do NOT edit this line!! ` number of filters Filter(1)=5 : ` Nr of Total Filters, you CAN edit this line. (only to replace the '5' number with something else...) Filter(1)=Filter(1)+1 : ` Do NOT edit this line!! nr_filter=Filter(1) : ` Do NOT edit this line!! ` continue arrays Dim Filter$(nr_filter,2): ` Do NOT edit this line!! Dim FilterY(nr_filter) : ` Do NOT edit this line!! ` browser setup title$(1) = "Browser System Pro version" dir$ = get dir$() ` filter setup Filter$(0,1) = "Any File" Filter$(1,1) = "Image file" Filter$(2,1) = "Object file" Filter$(3,1) = "Movie file" Filter$(4,1) = "Sound File" Filter$(5,1) = "Music File" Filter$(0,2) = "*.*" Filter$(1,2) = "bmp" Filter$(2,2) = "3ds" Filter$(3,2) = "avi" Filter$(4,2) = "wav" Filter$(5,2) = "mid" ` call browser result = Browser_System_v2( dir$ , 100 , 50 ) ` variable info: ` result = 1 : OK button was pressed ` result = 2 : CANCEL button was pressed ` result = 0 : an error must have happen, it cannot be 0 ` if OK was pressed, print File name and File Path, else if cancel was pressed, Exit Demo. if result = 1 do:sync cls rgb(64,196,100) ink rgb(32,128,32),0 print "Dir: "+FileDir$(1) print "File: "+FileName$(1) print "Path: "+FileDir$(1)+""+FileName$(1) wait 100 if mouseclick()>0 then end if scancode()>0 then end loop else do:sync:cls rgb(64,196,100) ink rgb(0,32,0),0 print "Press a Key To Exit Demo" print wait 100 if mouseclick()>0 then end if scancode()>0 then end loop endif rem ****************************** rem BROWSER v2 FUNCTION rem ****************************** function Browser_System_v2( dir$ , x , y ) cls rgb(64,196,100) : cd dir$ : Cancel = 2 : OK = 1 : selected_filter = 0 : selected=0 get_browser( x , y ) get_drives() get_filter( x , y ) get_drive_menu( x , y ) get_current_dir() refresh_list( x , y , selected_filter ) repeat cls rgb(64,196,100) paste image 1 , x , y mx=mousex() my=mousey() mc=mouseclick() timerr=timerr+1 ink 0,0 print_list( x , y ) ink 0,0 if len(FileDir$(1))>=30 then text x+12,y+35,Drive$(Drive(1))+".."+right$(FileDir$(1),23) if len(FileDir$(1))<30 then text x+12,y+35,right$(FileDir$(1),29) text x+50,y+270,FileName$(1) text x+20,y+294,Filter$(selected_filter,1) + " ["+Filter$(selected_filter,2)+"]" rem -------------------- rem SELECT DRIVE rem -------------------- if mc=1 if mx>=x+191 and mx<=x+212 and my>=y+28 and my<=y+47 if (display_it=0 and timerr>9) or (display_it=1 and timerr>9) then display_it=2:timerr=0 endif endif if display_it=2 paste image 3,x+159,y+28 if mx>= x+159 and mx<= x+(158+32) for xd = 1 to DriveY(0) if my>= y+28+DriveY(xd)+1 and my<= y+28+DriveY(xd)+14 ink rgb(64,196,64),0 line x+159,y+28+DriveY(xd)+9,x+171,y+28+DriveY(xd)+9 if mc= 1 Drive(1)=xd FileDir$(1) = Left$(Drive$(Drive(1)),1) FileDir$(1) = FileDir$(1)+":" set dir FileDir$(1) get_current_dir() refresh_list( x , y , selected_filter ) endif endif next xd endif if mc>0 if timerr>9 then display_it=0:timerr=0 endif endif rem -------------------- rem ------------------ rem SHOW FILTER BOX rem ------------------ if mx>=x+181 and mx<= x+198 and my>= y+288 and my<= y+304 if mc = 1 if (display_it=0 and timerr>9) or (display_it=2 and timerr>9) then display_it=1:timerr=0 endif endif if display_it = 1 paste image 2,x+14,y+305 if mx>= x+14 and mx<= x+174 for xd = 0 to Filter(1) if my>= y+305+FilterY(xd)+1 and my<= y+305+FilterY(xd)+14 ink rgb(64,196,64),0 line x+14,y+305+FilterY(xd)+9,x+172,y+305+FilterY(xd)+9 if mc= 1 filter$=Filter$(xd,2) selected_filter=xd refresh_list( x , y , selected_filter ) endif endif next xd endif if mc>0 if timerr>9 then display_it=0:timerr=0 endif endif rem ------------------ rem ------------------- rem SELECT FILE rem ------------------- if mx>=x+35 and mx<=x+233 and display_it=0 for xd = File(1) to File(2) if my>= EntryY(xd)+1 and my<= EntryY(xd)+14 ink rgb(64,196,64),0 line x+35,EntryY(xd)+9,x+233,EntryY(xd)+9 if mc=1 and timerr>9 timerr=0 : FileName$(1) = File$(xd) if left$(FileName$(1),1)="[" and right$(FileName$(1),1)="]" letters=len(FileName$(1)) poop1$=right$(FileName$(1),letters-1) letters=len(poop1$) poop2$=left$(poop1$,letters-1) FileName$(1)=poop2$ set dir FileDir$(1)+"/"+FileName$(1) get_current_dir() refresh_list( x , y , selected_filter ) endif endif endif next xd endif rem -------------------- rem -------------------- rem SCROLL ITEMS rem -------------------- if mc=1 if mx>=x+241 and mx<=x+258 if my>= y+53 and my<= y+70 if File(1)>3 then File(1) = File(1) - 1 : File(2) = File(2) - 1 endif if my>= y+239 and my<= y+257 if File(2)<File(0) then File(1) = File(1) + 1 : File(2) = File(2) + 1 endif endif endif rem -------------------- rem -------------------------------------------- rem PREVIOUS FOLDER AND NEW FOLDER BUTTON rem -------------------------------------------- if mc=1 and timerr>9 timerr=0 if mx>=x+220 and mx<=x+237 and my>=y+29 and my<=y+46 FileName$(1)=".." set dir FileDir$(1)+"/"+FileName$(1) get_current_dir() refresh_list( x , y , selected_filter ) endif if mx>=x+241 and mx<=x+258 and my>=y+29 and my<=y+46 FileName$(1)="" clear entry buffer line$="New Folder" repeat new$=entry$() for n=1 to len(new$) if asc(mid$(new$,n))=8 line$=left$(line$,len(line$)-1) else line$=line$+mid$(new$,n) endif next n clear entry buffer if flash$="" then flash$="|" else flash$="" cls rgb(64,196,100) paste image 1 , x , y ink 0,0 text x+45,y+270,line$+flash$ mx=mousex() my=mousey() mc=mouseclick() timerr=timerr+1 ink 0,0 print_list( x , y ) ink 0,0 text x+12,y+35,right$(FileDir$(1),29) text x+50,y+270,FileName$(1) text x+20,y+294,Filter$(selected_filter,1) + " ["+Filter$(selected_filter,2)+"]" sync until returnkey()=1 FolderName$=line$ if Path exist(FileDir$(1)+""+FolderName$)=0 make directory FolderName$ FileName$(1)="" get_current_dir() refresh_list( x , y , selected_filter ) endif endif endif rem -------------------------------------------- rem -------------- rem OK BUTTON rem -------------- if mc=1 if mx>=x+203 and mx<=x+258 and my>=y+266 and my<=y+280 if FileName$(1)<>"" selected=OK endif endif endif rem -------------- rem -------------- rem CANCEL BUTTON rem -------------- if mc=1 if mx>=x+203 and mx<=x+258 and my>=y+289 and my<=y+304 selected=CANCEL endif endif rem -------------- sync until selected>0 endfunction selected function get_current_dir() FileDir$(1) = get dir$() perform checklist for files File(0)=checklist quantity() File(1)=3 File(2)=File(0) if File(2)>9 then File(2)=9 FileName$(1)="" endfunction function refresh_list( x , y , s) perform checklist for files File(0)=checklist quantity() EntryY(File(1))=(y+57) file2=1 for xd = 1 to file(0) file$=checklist string$(xd) letters=len(file$) for t= 1 to letters file2$=lower$(file$) next t if checklist value a(xd)=1 file2=file2+1 file$(file2)="["+file2$+"]" else if Filter$(s,2)="*.*" file2=file2+1 file$(file2)=file2$ else if right$(file2$,1)=Filter$(s,2) then file2=file2+1:file$(file2)=file2$ if right$(file2$,2)=Filter$(s,2) then file2=file2+1:file$(file2)=file2$ if right$(file2$,3)=Filter$(s,2) then file2=file2+1:file$(file2)=file2$ if right$(file2$,4)=Filter$(s,2) then file2=file2+1:file$(file2)=file2$ endif endif next x File(1)=3 File(2)=file2 File(0)=file2 if File(2)>15 then File(2)=15 endfunction function print_list( x , y ) EntryY(File(1)) = y+57 for xd = File(1) to File(2) ink 0,0 text x+35,EntryY(xd),file$(xd) if left$(file$(xd),2)="[." and right$(file$(xd),2)=".]" draw_folder_image(x+13,(EntryY(xd)-2)) draw_arrow_up(x+22,(EntryY(xd)-2)) endif if left$(file$(xd),1)="[" and right$(file$(xd),1)="]" draw_folder_image(x+13,(EntryY(xd)-2)) else draw_file_image(x+13,(EntryY(xd)-2)) endif EntryY(xd+1)=EntryY(xd)+15 next x endfunction function draw_folder_image( x , y ) ink 0,0 line x,y,x+5,y line x,y,x,y+10 line x,y+10,x+10,y+10 line x+10,y+10,x+10,y+3 line x+5,y+3,x+10,y+3 line x+5,y+0,x+5,y+3 ink rgb(240,201,128),0 box x+1,y+1,x+4,y+4 box x+1,y+4,x+9,y+9 endfunction function draw_arrow_up( x , y ) ink 0,0 line x+4,y,x,y+3 line x+4,y,x+7,y+2 dot x+7,y+2 line x,y+3,x+2,y+3 line x+2,y+3,x+2,y+8 line x+3,y+8,x+5,y+8 line x+5,y+8,x+5,y+3 line x+5,y+3,x+7,y+3 ink rgb(250,64,64),0 line x+3,y+2,x+3,y+7 line x+4,y+2,x+4,y+7 line x+1,y+2,x+6,y+2 dot x+3,y+1 dot x+4,y+1 endfunction function draw_arrow_down( x , y ) ink 0,0 line x+2,y,x+5,y line x+2,y,x+2,y+5 line x+5,y,x+5,y+5 dot x,y+5 dot x+1,y+5 dot x+6,y+5 dot x+7,y+5 dot x,y+6 dot x+7,y+6 dot x+1,y+7 dot x+2,y+7 dot x+6,y+7 dot x+5,y+7 dot x+3,y+8 dot x+4,y+8 ink rgb(250,64,64),0 dot x+3,y+1 dot x+4,y+1 dot x+3,y+2 dot x+4,y+2 dot x+3,y+3 dot x+4,y+3 dot x+3,y+4 dot x+4,y+4 dot x+3,y+5 dot x+4,y+5 dot x+1,y+6 dot x+2,y+6 dot x+3,y+6 dot x+4,y+6 dot x+5,y+6 dot x+6,y+6 dot x+3,y+7 dot x+4,y+7 endfunction function draw_file_image( x , y ) ink 0,0 line x,y,x+5,y line x,y,x,y+10 line x,y+10,x+7,y+10 line x+7,y+10,x+7,y+3 line x+5,y,x+7,y+3 ink rgb(255,255,255),0 box x+1,y+1,x+5,y+9 line x+5,y+4,x+5,y+9 line x+6,y+4,x+6,y+9 endfunction function get_filter( x , y ) ink 0,0 box 0,0,167,Filter(1)*16 ink rgb(255,255,255),0 box 1,1,165,(Filter(1)*16)-2 ink 0,0 FilterY(0)=3 for xx = 0 to (Filter(1)-1) text 3,FilterY(xx),Filter$(xx,1)+" ["+Filter$(xx,2)+"]" FilterY(xx+1)=FilterY(xx)+16 next xx get image 2,0,0,167,Filter(1)*16 endfunction function get_drives() Perform Checklist For Drives DriveY(0)=checklist quantity() For x= 1 To DriveY(0) a$ = Checklist String$(x) Drive$(x)=left$(a$,2) Next x endfunction function get_drive_menu( x , y ) ink 0,0 box 0,0,32,DriveY(0)*15 ink rgb(255,255,255),0 box 1,1,30,((DriveY(0)*15)-2) ink 0,0 DriveY(1)=3 for xx = 1 to DriveY(0) text 3,DriveY(xx),Drive$(xx) DriveY(xx+1)=DriveY(xx)+16 next xx get image 3,0,0,32,DriveY(0)*15 endfunction function get_browser( x , y ) Ink 0,0 box x,y,x+266,y+316 ink rgb(116,255,116),0 box x+1,y+1,x+265,y+21 ink rgb(64,200,64),0 box x+2,y+2,x+265,y+21 ink rgb(116,255,116),0 set text to normal set text font "Terminal",3 set text size 9 text x+5,y+8,Title$(1) ink 0,0 line x+0,y+21,x+265,y+21 ink rgb(255,255,255),0 box x+1,y+22,x+265,y+315 ink rgb(215,215,215),0 box x+2,y+23,x+265,y+315 ink 0,0 box x+9,y+28,x+212,y+47 box x+219,y+28,x+238,y+47 box x+240,y+28,x+259,y+47 box x+9,y+52,x+238,y+258 box x+240,y+52,x+259,y+258 text x+8,y+270,"Name:" box x+42,y+264,x+199,y+281 box x+201,y+264,x+259,y+281 box x+201,y+287,x+259,y+305 box x+9,y+287,x+199,y+305 ink rgb(192,192,192),0 box x+10,y+29,x+211,y+46 box x+31,y+53,x+237,y+257 box x+241,y+53,x+258,y+257 box x+43,y+265,x+198,y+280 box x+10,y+288,x+179,y+304 ink rgb(255,255,255),0 box x+11,y+30,x+211,y+46 box x+32,y+54,x+237,y+257 box x+242,y+54,x+258,y+257 box x+44,y+266,x+198,y+280 box x+11,y+289,x+178,y+304 ink 0,0 box x+241,y+53,x+258,y+70 box x+241,y+239,x+258,y+257 box x+191,y+28,x+212,y+47 box x+180,y+287,x+199,y+305 ink rgb(255,255,255),0 box x+220,y+29,x+237,y+46 box x+241,y+29,x+258,y+46 box x+202,y+265,x+258,y+280 box x+202,y+288,x+258,y+304 box x+241,y+53,x+258,y+69 box x+241,y+240,x+258,y+257 box x+192,y+29,x+211,y+46 box x+181,y+288,x+198,y+304 ink rgb(215,215,215),0 box x+221,y+30,x+237,y+46 box x+242,y+30,x+258,y+46 box x+203,y+266,x+258,y+280 box x+203,y+289,x+258,y+304 box x+242,y+54,x+258,y+69 box x+242,y+241,x+258,y+257 box x+193,y+30,x+211,y+46 box x+182,y+289,x+198,y+304 ink 0,0 box x+10,y+53,x+30,y+257 ink rgb(116,255,116),0 box x+10,y+53,x+29,y+257 ink rgb(64,200,64),0 box x+11,y+54,x+29,y+257 ink 0,0 text x+223,y+269,"OK" text x+212,y+293,"Cancel" line x+198,y+37,x+204,y+37 line x+199,y+38,x+203,y+38 line x+200,y+39,x+202,y+39 line x+201,y+40,x+201,y+40 line x+187,y+295,x+193,y+295 line x+188,y+296,x+192,y+296 line x+189,y+297,x+191,y+297 line x+190,y+298,x+190,y+298 draw_folder_image( x+222 , y+34 ) draw_arrow_up( x+228 , y+31 ) draw_folder_image( x+243 , y+34 ) ink rgb(250,64,64),0 text x+250,y+30,"+" draw_arrow_up( x+246 , y+57 ) draw_arrow_down( x+246 , y+244 ) get image 1,x,y,x+267,y+317 endfunction
(1 vote)