Select texture in a dir

Blitz3D Forums/Blitz3D Beginners Area/Select texture in a dir

jigga619(Posted 2004) [#1]
Does any body know a funtion that allows a person to select different bmp textures from within a directory and each time the person select a texture, it is shown on the screen?


Rob Farley(Posted 2004) [#2]
You could check out some of the guis, they might... However, personally I think your best bet is to write one yourself.


Rob Farley(Posted 2004) [#3]
Here's something I knocked together... very basic but it should give you an idea of where to start...

Graphics 640,480,0,2

SetBuffer BackBuffer()

; create a blank image
temp=CreateImage(1,1)

; directory to look in
filedir$=CurrentDir$()+"pages\"


Type files
Field filename$
End Type

; find all the picture files in the directory
myDir$=ReadDir(filedir)
Repeat
thisfile$=NextFile$(myDir)
ext$=Lower(Right(thisfile,4))

If thisfile<>""
	If ext=".jpg" Or ext=".bmp" Or ext=".png"
		f.files=New files
		f\filename=thisfile
		EndIf
	EndIf
Until thisfile=""


; main loop
Repeat
Cls
y=0

; loop through the files
For f.files = Each files

; change colour and log file name if mouse if over it
If Int(MouseY()/10)=y
	Color 255,255,255
	loadfile$=f\filename
	Else
	Color 160,160,160
	EndIf

; display the filename	
Text 0,y*10,f\filename
y=y+1

Next

; load the selected image if mouse clicked
If MouseHit(1) Then temp=LoadImage(filedir+loadfile)

; draw the image
DrawBlock temp,300,100

Flip
Until KeyHit(1)