Ok then. A quick tutorial:
I think you know the basics:
get dir$() is the current directory
perform checklist for files makes a list of files in the current directory
find first finds the first file in the directory.
find next finds the next file in the directory.
get file name$() returns the filename
get file type() returns the file type
Well, I think this is all the commands we need...
First we start with the
perform checklist for files command.
Since it has to be done once, we do it before the loop. Also the
checklist quantity() has to be done once, so also before the loop and we store it in the variable cq. (The current directory is the one where the file is)
`sync on
sync on
`perform checklist and get number of items
perform checklist for files
cq = checklist quantity()
Next, we have to add the buttons and the list of all files in the directory:
To add the buttons it's pretty handy to use a function.
And I think you're pretty familiar with the code, so I didn't comment it:
function button(x,y,text$)
pressed=0
tx=text width(text$)
ty=text height(text$)/2
if mousex()<x+tx and mousex()>x
if mousey()<y+ty and mousey()>y-ty
pressed=1
endif
endif
if pressed=1 then ink rgb(0,0,255),0 else ink rgb(255,255,255),0
text x,y-ty,text$
if mouseclick()=0 then pressed=0
endfunction pressed
To display the list, we're probably going to need
find first, find next and get file name$().
The back button is standard the second file in the list. (Find first : find next)
sync on
`perform checklist
perform checklist for files
cq = checklist quantity()
`reset variables
scrolly = 0
do
`clear screen
cls
`find first and next file in the folder (back button)
find first
find next
if button(10,10 + scrolly,"Back") > 0 and hold = 0
hold = 1
endif
`display the whole list
for file = 3 to cq
find next
if button(10,10 + scrolly + ((file-2)*20),get file name$()) > 0 and hold = 0
endif
next file
`unlock mouse
if mouseclick() = 0 then hold = 0
sync
loop
function button(x,y,text$)
pressed=0
tx=text width(text$)
ty=text height(text$)/2
if mousex()<x+tx and mousex()>x
if mousey()<y+ty and mousey()>y-ty
pressed=1
endif
endif
if pressed=1 then ink rgb(0,0,255),0 else ink rgb(255,255,255),0
text x,y-ty,text$
if mouseclick()=0 then pressed=0
endfunction pressed
Note that the 'scrolly' variable will have to decrement for going up, and increment for going down (scrolling).
Ofcourse, buttons are pretty useless when they don't do anything. So we're using the
cd (change dir) command to change the current directory,
get file type() to check if the file is a directory or not and ofcourse, the well known
perfom checklist for files and
checklist quantity() will be a part of the code.
To configure the 'back' buttons, we'll first have to check if the file is directory. (This value also changes to 'not' when the directory is a drive, wich will be very handy). If so, we change the directory (cd) and perform again a checklist + check number of items.
So it becomes:
if button(10,10+scrolly,"back") > 0 and hold = 0
hold = 1
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
endif
endif
This can also be adapted to the list:
`display the whole list
for file = 3 to cq
find next
if button(10,10 + scrolly + ((file-2)*20),get file name$()) > 0 and hold = 0
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
else
text 100,10,get dir$() + "\" + get file name$
endif
endif
next file
Now you can freely browse through windows.
The whole code:
sync on
`perform checklist
perform checklist for files
cq = checklist quantity()
`reset variables
scrolly = 0
do
`clear screen
cls
`find first and next file in the folder (back button)
find first
find next
if button(10,10 + scrolly,"Back") > 0 and hold = 0
hold = 1
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
endif
endif
`display the whole list
for file = 3 to cq
find next
if button(10,10 + scrolly + ((file-2)*20),get file name$()) > 0 and hold = 0
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
hold = 1
else
ink rgb(255,255,255),0
center text 320,5,get dir$() + "\" + get file name$()
endif
endif
next file
`unlock mouse
if mouseclick() = 0 then hold = 0
sync
loop
function button(x,y,text$)
pressed=0
tx=text width(text$)
ty=text height(text$)/2
if mousex()<x+tx and mousex()>x
if mousey()<y+ty and mousey()>y-ty
pressed=1
endif
endif
if pressed=1 then ink rgb(0,0,255),0 else ink rgb(255,255,255),0
text x,y-ty,text$
if mouseclick()=0 then pressed=0
endfunction pressed
Ofcourse, you can change the scrolly value too, wich will cause the scrolling effect.
For example:
using up/downkeys
if upkey() = 1 then inc scrolly
if downkey() = 1 then dec scrolly
Or the scrollwheel:
mousez = mousemovez()
if mousez <> oldmousez
dec y, (oldmousez - mousez) / 30
oldmousez = mousez
endif
That all for the browsing.
Next: the list.
Arrays are probably the easiest way to create a list. So that's also exactly what we're going to use:
`this will create a list wich can store up to 100 file directories
dim list$(100)
nroffiles = 0
When adding an items, we simply increase 'nrofffiles' and put the data in the array list$().
sync on
`perform checklist
perform checklist for files
cq = checklist quantity()
`reset variables
scrolly = 0
`this will create a list that can story up to 100 files
dim list$(100)
nroffiles = 0
do
`clear screen
cls
`find first and next file in the folder (back button)
find first
find next
if button(10,10 + scrolly,"Back") > 0 and hold = 0
hold = 1
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
endif
endif
`display the whole list
for file = 3 to cq
find next
if button(10,10 + scrolly + ((file-2)*20),get file name$()) > 0 and hold = 0
hold = 1
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
else
inc nroffiles
list$(nroffiles) = get dir$() + "\" + get file name$()
endif
endif
next file
`unlock mouse
if mouseclick() = 0 then hold = 0
`exit
if returnkey() = 1 then exit
sync
loop
`display all files and terminate program
cls
ink rgb(255,255,255),0
for files = 1 to nroffiles
print list$(files)
next files
wait 1000
suspend for key
end
function button(x,y,text$)
pressed=0
tx=text width(text$)
ty=text height(text$)/2
if mousex()<x+tx and mousex()>x
if mousey()<y+ty and mousey()>y-ty
pressed=1
endif
endif
if pressed=1 then ink rgb(0,0,255),0 else ink rgb(255,255,255),0
text x,y-ty,text$
if mouseclick()=0 then pressed=0
endfunction pressed
Press enter and you'll see all data that is stored in the array list$().
Next, we have to search for the extension of the file.
For example, we only have to be able to click mp3's, wich have the extension: '.mp3' and has 4 characters.
These 4 characters always come AFTER the file name. So it's easy to find them:
name$ = get file name$()
l = len(name$)
ext$ = mid$(name$,l-3) + mid($name$,l-2) + mid$(name$,l-1) + mid$(name$,l)
if lower$(ext$) = ".mp3" then add_to_list
Now we have found the extension. To be sure it's spelled in lowercase, we add the function lower$().
When adding this to our browser:
Try clicking on a couple of mp3's and other files. Then press enter.
sync on
`perform checklist
perform checklist for files
cq = checklist quantity()
`reset variables
scrolly = 0
`this will create a list that can story up to 100 files
dim list$(100)
nroffiles = 0
do
`clear screen
cls
`find first and next file in the folder (back button)
find first
find next
if button(10,10 + scrolly,"Back") > 0 and hold = 0
hold = 1
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
endif
endif
`display the whole list
for file = 3 to cq
find next
if button(10,10 + scrolly + ((file-2)*20),get file name$()) > 0 and hold = 0
hold = 1
`search if the file is a directory
if get file type() = 1
cd get file name$()
perform checklist for files
cq = checklist quantity()
else
`get the extension
name$ = get file name$()
l = len(name$)
ext$ = mid$(name$,l-3) + mid$(name$,l-2) + mid$(name$,l-1) + mid$(name$,l)
`if the extension matches ".mp3" then add it to the list.
if lower$(ext$) = ".mp3"
inc nroffiles
list$(nroffiles) = get dir$() + "\" + get file name$()
endif
endif
endif
next file
`unlock mouse
if mouseclick() = 0 then hold = 0
`exit
if returnkey() = 1 then exit
sync
loop
`display all files and terminate program
cls
ink rgb(255,255,255),0
for files = 1 to nroffiles
print list$(files)
next files
wait 1000
suspend for key
end
function button(x,y,text$)
pressed=0
tx=text width(text$)
ty=text height(text$)/2
if mousex()<x+tx and mousex()>x
if mousey()<y+ty and mousey()>y-ty
pressed=1
endif
endif
if pressed=1 then ink rgb(0,0,255),0 else ink rgb(255,255,255),0
text x,y-ty,text$
if mouseclick()=0 then pressed=0
endfunction pressed
That concludes the tutorial for now.
I hope it helped,
Sven B
Immunity and Annihalation makes Immunihalation...