Here is an update:
sync on
for i = 1 to 10
x = rnd(640)
y = rnd(480)
ink rgb(0,0,255),0
box x,y,x + rnd(50),y + rnd(50)
next i
file$ = browser_window(20,10,200,300,"C:\",rgb(255,255,0),1,1)
cls
print file$
suspend for key
end
`************
`the function
`************
function browser_window(posx, posy, sizex, sizey, firstdir$, color1, resize, move)
`preparations
set text font "Arial" : set text size 16
` if sizex < 150 then sizex = 150
` if sizey < 100 then sizey = 100
dir$ = firstdir$
set dir firstdir$
perform checklist for files
`get background
get image 65535,0,0,screen width(),screen height()
y = 0
oldmousez = mousemovez()
mousez = mousemovez()
show mouse
do
`boundries
if posx < 0 then posx = 0
if posy < 0 then posy = 0
if sizex > screen width() - 1 then sizex = screen width() - 1
if sizey > screen height() - 1 then sizey = screen height() - 1
`paste background
paste image 65535,0,0
`handle mousemovez
mousez = mousemovez()
if mousez <> oldmousez
dec y, (oldmousez - mousez) / 30
oldmousez = mousez
endif
`scroll
maxy = (checklist quantity() - 1) * 17 + 16
if y < (maxy - (sizey - 50)) * -1 then y = (maxy - (sizey - 50)) * -1
if y > 0 then y = 0
`make main window
ink rgb(255,255,255),0
endx = posx + sizex
endy = posy + sizey
if endx > screen width()-1 then endx = screen width()-1
if endy > screen height()-1 then endy = screen height()-1
box posx, posy, endx - 1, endy - 1
ink rgb(10, 10, 10), 0
box posx + 1, posy + 1, endx, endy
ink color1,0
box posx + 1, posy + 1, endx-1, endy-1
`make directory
ink rgb(10, 10, 10), 0
endx = posx + sizex - 5
endy = posy + 25
if endx > screen width()-1 then endx = screen width()-1
if endy > screen height()-1 then endy = screen height()-1
box posx + 5, posy + 5, endx - 1, endy - 1
ink rgb(200,200,200),0
box posx + 6, posy + 6, endx, endy
ink rgb(255,255,255),0
box posx + 6, posy + 6, endx - 1, endy - 1
`display directory
ink 0,0 : dispdir$ = ""
for i = 1 to len(dir$)
if text width(dispdir$) < sizex - 20
dispdir$ = dispdir$ + mid$(dir$, i)
endif
next i
text posx + 7, posy + 6, dispdir$
`make file window
endx = posx + sizex - 5
endy = posy + sizey - 5
if endx > screen width() - 1 then endx = screen width() - 1
if endy > screen height() - 1 then endy = screen height() - 1
ink rgb(10, 10, 10), 0
box posx + 5, posy + 30, endx - 1, endy - 1
ink rgb(200,200,200),0
box posx + 6, posy + 31, endx, endy
ink rgb(255,255,255),0
box posx + 6, posy + 31, endx - 1, endy - 1
`display files
find first : find next
name$ = get file name$()
if y => 0
if textbutton(posx + 7, posy + 40 + y, "parent", color1) > 0 and hold = 0
hold = 1
if get file type() = 1
dir$ = dir$ + "\" + name$
set dir dir$
dir$ = get dir$()
set dir dir$
perform checklist for files
y = 0
endif
endif
endif
for file = 2 to checklist quantity() - 1
find next : name$ = ""
for char = 1 to len(get file name$())
if text width(name$) < sizex - 18
name$ = name$ + mid$(get file name$(), char)
endif
next char
fileposy = y + ((file - 1) * 17)
if fileposy > 0 and fileposy < sizey - 50
if textbutton(posx + 7, posy + 40 + fileposy, name$, color1) > 0 and hold = 0
hold = 1
if get file type() = 1
if path exist( dir$ + "\" + get file name$() ) > 0
set dir dir$ + "\" + get file name$()
dir$ = get dir$()
perform checklist for files
y = 0
endif
else
filename$ = dir$ + "\" + get file name$()
exitfunction filename$
endif
endif
endif
next file
`move window
if move = 1
if mousex() > posx and mousex() < posx + sizex
if mousey() > posy and mousey() < posy + 10
if mouseclick() = 1 and moving = 0
difx = mousex() - posx
dify = mousey() - posy
moving = 1
endif
endif
endif
if moving = 1
posx = mousex() - difx
posy = mousey() - dify
if mouseclick() = 0 then moving = 0
endif
endif
`resize window
if resize = 1
if mousex() > posx + sizex - 5 and mousex() > posx + sizex
if mousey() > posy + 10 and mousey() < posy + sizey - 5
if mouseclick() = 1 and resising = 0
resising = 1
endif
endif
endif
if mousex() > posx and mousex() < posx + sizex - 5
if mousey() > posy + sizey - 5 and mousey() < posy + sizey
if mouseclick() = 1 and resising = 0
resising = 2
endif
endif
endif
if mousex() > posx + sizex - 5 and mousex() < posx + sizex
if mousey() > posy + sizey - 5 and mousey() < posy + sizey
if mouseclick() = 1 and resising = 0
resising = 3
endif
endif
endif
select resising
case 1
sizex = sizex + mousemovex()
endcase
case 2
sizey = sizey + mousemovey()
endcase
case 3
sizex = sizex + mousemovex()
sizey = sizey + mousemovey()
endcase
endselect
if resising > 0 and mouseclick() = 0 then resising = 0
endif
`unlock mouse
if mouseclick() = 0 then hold = 0
sync
loop
endfunction filename$
function textbutton(x, y, text$, color)
tx = text width(text$)
ty = text height(text$)/2
pressed = 0
if mousex() > x and mousex() < x + tx
if mousey() < y + ty and mousey() > y - ty
pressed = 1
endif
endif
if pressed = 1 then ink color,0 else ink rgb(0,0,0),0
text x, y - (text size()/2), text$
if mouseclick() = 0 then pressed = 0
endfunction pressed
new features:
- resizing
- movement
- buttons coloured the same as the window. (when mouse-over)
- background saving (image 65 535 -> max number of image)
Immunity and Annihalation makes Immunihalation...