OK, sure! There are built-in commands in DBPro,
perform checklist for files
which gets the string names of all the files in the directory
checklist string(#)
which retrieves and returns the string of filename #... So, using these codes, here is the code that I used. There are comments after // which denote what you can change...
Here is the Browsing Function... The loop is for detecring the user's click:
NOTE: THIS IS FOR BLUEGUI!
function browse()
global bpanel
global listView
global lbStatus
global imageList
global appdir as string
bpanel=createWindow(100,100,640,500,"Textures",WINDOW_CLOSEBUTTON,0,0,0)
listView=createListView(10,10,620,440,bpanel)
lbStatus=createLabel(10,455,640,15,"Loading Thumbnails...",bpanel)
paintGadget lbStatus
imageList=createImageList(64,64)
appdir=get dir$()
set dir "Textures" // !- Here is the part where is changes directories to the "Textures" directory
perform checklist for files
count=checklist quantity()
for i=1 to count
if file exist(checklist string$(i))
addImageListItem imageList,loadAndScaleImage(checklist string$(i),64,64)
inc successCount
setGadgetText lbStatus,"Loading Thumbnails... ("+str$(successCount)+")"
endif
next i
setListViewImageList listView,imageList
local ext as string
for i=1 to count
if file exist(checklist string$(i))
ext=lower$(right$(checklist string$(i),4))
if (ext <> ".bmp") and (ext <> ".jpg") and (ext <> "jpeg") and (ext <> ".tga") and (ext <> ".dds") and (ext <> ".dib") and (ext <> ".png")
else
addListViewItem listView,checklist string$(i),loadedCount
inc loadedCount
endif
endif
next i
setGadgetText lbStatus,str$(loadedCount) + " textures loaded."
for i=1 to 10000 //Will delete the sprites used to scale textures... This is needed because they will remain on the screen
if sprite exist(i)
delete sprite i
endif
next i
set dir ".." //Sets back a directory...
global name$
global texID as integer : texID=5000 //Will return the image as TexID, which is set to 5000
do
getevent
if eventType()=MOUSE_CLICK
if eventSource()=listView
if selectedListViewItem(listView)<>0
global name$ : name$ = getListViewItemText(listView,selectedListViewItem(listView),0)
global texID : texID=findFreeImage() //findFreeImage is a function that finds a free, unused image number
if file exist("Textures"+name$)=1 then load image "Textures"+name$,texID
deleteGadget bpanel
exit
endif
endif
endif
sync
loop
endfunction
Here are the two extra functions that scale the thumbnails and then retrieve the image width:
function loadAndScaleImage(fileName as string,width as float,height)
ink rgb(255,255,255),rgb(255,255,255)
box 0,0,width,height
local ext as string
ext=lower$(right$(fileName,4))
if (ext <> ".bmp") and (ext <> ".jpg") and (ext <> "jpeg") and (ext <> ".tga") and (ext <> ".dds") and (ext <> ".dib") and (ext <> ".png")
exitfunction 2
endif
if image exist(1) then delete image 1
load image fileName,1,1
sprite 1,0,0,1
scale sprite 1,(width/imageWidth(1))*100.0
paste sprite 1,0,0
get image 1,0,0,width,height,1
cls
endfunction 1
function imageWidth(imageIndex)
make memblock from image 1,imageIndex
result=memblock dword(1,0)
delete memblock 1
endfunction result
Let me know if you have any troubles!