My filebrowser

Post your FreeBASIC tips and tricks here. Please don’t post your code without including an explanation.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

My filebrowser

Postby Westbeam » Oct 06, 2011 12:12

Hey, i wrote a little filebrowser:

Code: Select all

Screen 12

#Include "dir.bi"
#Include "fbgfx.bi"
Dim As Any Ptr folder,file,folder2,scrollptr,scroller
folder=Imagecreate(32,32)
file=Imagecreate(32,32)
folder2=Imagecreate(32,32)
scrollptr=Imagecreate(16,2)
scroller=Imagecreate(16,50)

line folder,(0,0)-(31,31),15,BF
line folder,(2,7)-(31,28),7,BF
pset folder,(31,7),15
pset folder,(31,28),15
pset folder,(30,28),15
pset folder,(31,27),15
line folder,(5,3)-(13,3),0
Pset folder,(14,4),0
line folder,(0,8)-(5,3),0
line folder,(15,5)-(28,5),0
line folder,(1,7)-(26,7),0
line folder,(0,8)-(0,26),0
line folder,(29,6)-(29,24),0
line folder,(27,8)-(27,26),0
pset folder,(28,25),0
line folder,(0,26)-(27,26),0
line folder,(1,8)-(26,8),14,,&b10101010101010101010101010
line folder,(1,10)-(26,10),14,,&b10101010101010101010101010
line folder,(1,12)-(26,12),14,,&b10101010101010101010101010
line folder,(1,14)-(26,14),14,,&b10101010101010101010101010
line folder,(1,16)-(26,16),14,,&b10101010101010101010101010
line folder,(1,18)-(26,18),14,,&b10101010101010101010101010
line folder,(1,20)-(26,20),14,,&b10101010101010101010101010
line folder,(1,22)-(26,22),14,,&b10101010101010101010101010
line folder,(1,24)-(26,24),14,,&b10101010101010101010101010
line folder,(1,9)-(26,9),14,,&b01010101010101010101010101
line folder,(1,11)-(26,11),14,,&b01010101010101010101010101
line folder,(1,13)-(26,13),14,,&b01010101010101010101010101
line folder,(1,15)-(26,15),14,,&b01010101010101010101010101
line folder,(1,17)-(26,17),14,,&b01010101010101010101010101
line folder,(1,19)-(26,19),14,,&b01010101010101010101010101
line folder,(1,21)-(26,21),14,,&b01010101010101010101010101
line folder,(1,23)-(26,23),14,,&b01010101010101010101010101
line folder,(1,25)-(26,25),14,,&b01010101010101010101010101
line folder,(2,8)-(27,8),15,,&b10101010101010101010101010
line folder,(2,10)-(27,10),15,,&b10101010101010101010101010
line folder,(2,12)-(27,12),15,,&b10101010101010101010101010
line folder,(2,14)-(27,14),15,,&b10101010101010101010101010
line folder,(2,16)-(27,16),15,,&b10101010101010101010101010
line folder,(2,18)-(27,18),15,,&b10101010101010101010101010
line folder,(2,20)-(27,20),15,,&b10101010101010101010101010
line folder,(2,22)-(27,22),15,,&b10101010101010101010101010
line folder,(2,24)-(27,24),15,,&b10101010101010101010101010
line folder,(1,9)-(26,9),15,,&b10101010101010101010101010
line folder,(1,11)-(26,11),15,,&b10101010101010101010101010
line folder,(1,13)-(26,13),15,,&b10101010101010101010101010
line folder,(1,15)-(26,15),15,,&b10101010101010101010101010
line folder,(1,17)-(26,17),15,,&b10101010101010101010101010
line folder,(1,19)-(26,19),15,,&b10101010101010101010101010
line folder,(1,21)-(26,21),15,,&b10101010101010101010101010
line folder,(1,23)-(26,23),15,,&b10101010101010101010101010
line folder,(1,25)-(26,25),15,,&b10101010101010101010101010
line folder,(3,6)-(27,6),14,,&b10101010101010101010101010
line folder,(4,6)-(28,6),15,,&b10101010101010101010101010
pset folder,(27,7),15
line folder,(28,7)-(28,24),14,,&b1010101010101010
line folder,(28,7)-(28,24),15,,&b0101010101010101
pset folder,(5,4),14
pset folder,(6,4),15
pset folder,(7,4),14
pset folder,(8,4),15
pset folder,(9,4),14
pset folder,(10,4),15
pset folder,(11,4),14
pset folder,(12,4),15
pset folder,(13,4),14
line folder,(0,5)-(14,5),14,,&b01010101010
line folder,(0,5)-(14,5),15,,&b10101010101
pset folder,(3,5),0
pset folder,(4,5),14

line file,(0,0)-(31,31),15,BF
line file,(5,12)-(28,31),7,BF
line file,(3,0)-(15,0),0
line file,(3,0)-(3,29),0
line file,(3,29)-(26,29),0
line file,(26,29)-(26,11),0
line file,(26,11)-(15,0),0
line file,(15,0)-(15,11),0
line file,(15,11)-(26,11),0
paint file,(5,2),15,0
paint file,(18,7),7,0

line folder2,(0,0)-(31,31),15,BF
line folder2,(2,7)-(31,28),7,BF
pset folder2,(31,7),15
pset folder2,(31,28),15
pset folder2,(30,28),15
pset folder2,(31,27),15
line folder2,(5,3)-(13,3),0
Pset folder2,(14,4),0
line folder2,(0,8)-(5,3),0
line folder2,(15,5)-(28,5),0
line folder2,(1,7)-(26,7),0
line folder2,(0,8)-(0,26),0
line folder2,(29,6)-(29,24),0
line folder2,(27,8)-(27,26),0
pset folder2,(28,25),0
line folder2,(0,26)-(27,26),0
line folder2,(1,8)-(26,8),14,,&b10101010101010101010101010
line folder2,(1,10)-(26,10),14,,&b10101010101010101010101010
line folder2,(1,12)-(26,12),14,,&b10101010101010101010101010
line folder2,(1,14)-(26,14),14,,&b10101010101010101010101010
line folder2,(1,16)-(26,16),14,,&b10101010101010101010101010
line folder2,(1,18)-(26,18),14,,&b10101010101010101010101010
line folder2,(1,20)-(26,20),14,,&b10101010101010101010101010
line folder2,(1,22)-(26,22),14,,&b10101010101010101010101010
line folder2,(1,24)-(26,24),14,,&b10101010101010101010101010
line folder2,(1,9)-(26,9),14,,&b01010101010101010101010101
line folder2,(1,11)-(26,11),14,,&b01010101010101010101010101
line folder2,(1,13)-(26,13),14,,&b01010101010101010101010101
line folder2,(1,15)-(26,15),14,,&b01010101010101010101010101
line folder2,(1,17)-(26,17),14,,&b01010101010101010101010101
line folder2,(1,19)-(26,19),14,,&b01010101010101010101010101
line folder2,(1,21)-(26,21),14,,&b01010101010101010101010101
line folder2,(1,23)-(26,23),14,,&b01010101010101010101010101
line folder2,(1,25)-(26,25),14,,&b01010101010101010101010101
line folder2,(2,8)-(27,8),15,,&b10101010101010101010101010
line folder2,(2,10)-(27,10),15,,&b10101010101010101010101010
line folder2,(2,12)-(27,12),15,,&b10101010101010101010101010
line folder2,(2,14)-(27,14),15,,&b10101010101010101010101010
line folder2,(2,16)-(27,16),15,,&b10101010101010101010101010
line folder2,(2,18)-(27,18),15,,&b10101010101010101010101010
line folder2,(2,20)-(27,20),15,,&b10101010101010101010101010
line folder2,(2,22)-(27,22),15,,&b10101010101010101010101010
line folder2,(2,24)-(27,24),15,,&b10101010101010101010101010
line folder2,(1,9)-(26,9),15,,&b10101010101010101010101010
line folder2,(1,11)-(26,11),15,,&b10101010101010101010101010
line folder2,(1,13)-(26,13),15,,&b10101010101010101010101010
line folder2,(1,15)-(26,15),15,,&b10101010101010101010101010
line folder2,(1,17)-(26,17),15,,&b10101010101010101010101010
line folder2,(1,19)-(26,19),15,,&b10101010101010101010101010
line folder2,(1,21)-(26,21),15,,&b10101010101010101010101010
line folder2,(1,23)-(26,23),15,,&b10101010101010101010101010
line folder2,(1,25)-(26,25),15,,&b10101010101010101010101010
line folder2,(3,6)-(27,6),14,,&b10101010101010101010101010
line folder2,(4,6)-(28,6),15,,&b10101010101010101010101010
pset folder2,(27,7),15
line folder2,(28,7)-(28,24),14,,&b1010101010101010
line folder2,(28,7)-(28,24),15,,&b0101010101010101
pset folder2,(5,4),14
pset folder2,(6,4),15
pset folder2,(7,4),14
pset folder2,(8,4),15
pset folder2,(9,4),14
pset folder2,(10,4),15
pset folder2,(11,4),14
pset folder2,(12,4),15
pset folder2,(13,4),14
line folder2,(0,5)-(14,5),14,,&b01010101010
line folder2,(0,5)-(14,5),15,,&b10101010101
pset folder2,(3,5),0
pset folder2,(4,5),14
line folder2,(22,20)-(8,20),0
line folder2,(8,20)-(8,15),0
line folder2,(5,14)-(11,14),0
line folder2,(5,14)-(8,11),0
line folder2,(9,12)-(11,14),0
paint folder2,(8,13),0

line scrollptr,(0,0)-(16,2),15,BF
line scrollptr,(0,0)-(0,2),7
line scrollptr,(1,0)-(16,2),7,,&b100010001000100
line scrollptr,(1,0)-(16,2),7,,&b001000100010001

line scroller,(0,0)-(16,50),7,BF
line scroller,(0,0)-(16,50),8,B
line scroller,(0,49)-(16,49),8
line scroller,(1,1)-(16,1),15
line scroller,(1,2)-(1,48),15

Chdir("../..")

Dim Shared As String filename,foldername

Type Icon
   As String nam,typ
   As Integer x,y,lenx
End Type

Color 0,15

ReDim Shared As Icon Files(999)
Declare Sub AddFile()
Dim Shared As Integer anzfiles,mx,my,mb,tempx,tempy,mz,oldmz,scroll,scrptry,maxy,tim,clicktim,clickbit

Declare Sub getMouseEvent()   

Declare Sub ShowFiles()
ShowFiles()
scrptry=0
Do
   Sleep 1,1
   tim+=1
   Getmouse mx,my,mz,mb
   If mb <> -1 Then ' otherwise it will "jump" when you move the mouse out of the window
      scroll += (mz - oldmz) * 10
      oldmz = mz
   End If
   Var maxscroll = -(maxy + 60 - 480)
    If scroll > 0 Then scroll = 0
   Screenlock
      Line (0,0)-(640,480),15,BF
      For i As Integer=0 To 240
         Put (628,i*2),scrollptr,Pset
      Next
      If scroll>-anzfiles*9 Then
         Put (628,-scroll/anzfiles*50),scroller,Pset
      Else
         Put (628,430),scroller,Pset
      End If
      For i As Integer=1 To anzfiles
         If Files(i).typ="Folder" Then Put (Files(i).x,Files(i).y+scroll),folder,Pset
         If Files(i).typ="File" Or Files(i).typ="Picture" Then Put (Files(i).x,Files(i).y+scroll),file,Pset
         If Files(i).typ="Bfolder" Then Put (Files(i).x,Files(i).y+scroll),folder2,Pset
         If Len(Files(i).nam)<10 Then
            If CurDir<>"/" Then Color 0,15
            If CurDir="/" Then Color 12,0
            Draw String(Files(1).lenx,Files(1).y+34+scroll),".."
            Color 0,15
            Draw String (Files(i).lenx,Files(i).y+34+scroll),Files(i).nam
         Else   
            Draw String (Files(i).lenx,Files(i).y+34+scroll),Left(Files(i).nam,10)+"..."
         End If
         If mx>Files(i).x And mx<Files(i).x+32 And my>Files(i).y+scroll And my<Files(i).y+32+scroll And mb=1 And (Files(i).typ="Folder" Or Files(i).typ="Bfolder") Then
            Chdir(Files(i).nam)
            scroll=0
            anzfiles=0
            Files(i).x=0
            Files(i).y=10
            ShowFiles()
            Sleep 200
         End If
      Next
   Screenunlock
   WindowTitle CurDIr
Loop Until Inkey= Chr(255, 107)
ImageDestroy folder
ImageDestroy folder2
ImageDestroy file
End


Sub AddFile()
    anzfiles+=1                     
    If anzfiles > UBound(Files) Then ReDim Preserve Files(UBound(Files) + 1000)
    With Files(anzfiles)                       
        .y = ((anzfiles - 1) \ 4) * 60 +5   
        If .y > maxy Then maxy = .y
        .x = ((anzfiles - 1) mod 4) * (600 \ 4) +20
    End With
End Sub

Sub ShowFiles()
 anzfiles=0
 maxy=0
 Dim As Integer attr
 AddFile()
 With Files(anzfiles)                       
        .y = ((anzfiles - 1) \ 4) * 60 +5
        .x = ((anzfiles - 1) mod 4) * (600 \ 4) +20
        .nam=".."
        .typ="Bfolder"
End With
Files(anzfiles).lenx=(Files(anzfiles).x+16)-Len(Files(anzfiles).nam)*4
foldername = Dir("*",fbDirectory Or fbReadOnly,@attr)
 Do
  If (attr And fbDirectory) AndAlso foldername<>"" AndAlso foldername <> "." AndAlso foldername <> ".."  Then
     AddFile()
     Files(anzfiles).nam=foldername
     Files(anzfiles).typ="Folder"
     If Len(Files(anzfiles).nam)<10 Then
      Files(anzfiles).lenx=(Files(anzfiles).x+16)-Len(Files(anzfiles).nam)*4
   Else
      Files(anzfiles).lenx=(Files(anzfiles).x+16)-36
   End If
   end if
   foldername =dir("",0)
 Loop While Len(foldername)

filename = dir("*",&H00)
 Do
  if filename<>"" then
     AddFile()
     Files(anzfiles).nam=filename
    If Right(Ucase(Files(anzfiles).nam),3)="BMP" Then
      Files(anzfiles).typ="Picture"
   Else
      Files(anzfiles).typ="File"
   End If
     If Len(Files(anzfiles).nam)<10 Then
      Files(anzfiles).lenx=(Files(anzfiles).x+16)-Len(Files(anzfiles).nam)*4
   Else
      Files(anzfiles).lenx=(Files(anzfiles).x+16)-36
   End If
   end if
   filename = dir("",0)
 Loop While Len(filename)
 End Sub

It works with Linux, but i think it will work with Windows too. ;)

Feedback?
Last edited by Westbeam on Oct 06, 2011 20:50, edited 4 times in total.
pestery
Posts: 493
Joined: Jun 16, 2007 2:00
Location: Australia

Postby pestery » Oct 06, 2011 12:25

Ha! Really cool. Works fine on Windows.

Only improvement would be a scroll thingy, for if there are a lot of files or folders.
Ivan, Zagreb
Posts: 16
Joined: Oct 04, 2011 19:44
Location: Croatia

File Browser

Postby Ivan, Zagreb » Oct 06, 2011 12:29

It works with Windows.
Develop it further.
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Postby Cherry » Oct 06, 2011 12:35

For Windows it might be good to change line 259 to...

Code: Select all

  if filename<>"" AndAlso filename<>"." AndAlso filename<>".." then


...otherwise it will display a "." and a second ".." folder in every directory.
podvornyak
Posts: 148
Joined: Nov 12, 2007 11:46
Location: Russia

Postby podvornyak » Oct 06, 2011 12:38

Works fine. Ubuntu 10.04 64. Awesome!
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Oct 06, 2011 15:25

Thx for the feedback. I updated my code in the first post. You can scroll down and up now. ;-)
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Postby Cherry » Oct 06, 2011 15:37

Bugs:
1) If you move the mouse out of the window, the view "jumps" to the top. Probably you don't check if scroll = -1.

2) If you navigate to a folder with 1000 or more files in it, the app crashes.

I'd do it like this: Change "Dim Shared As Icon Files(999)" to "ReDim......", and change AddFile like this:

Code: Select all

Sub AddFile()
    anzfiles+=1       
    If anzfiles > UBound(Files) Then ReDim Preserve Files(UBound(Files) + 1000))             
    With Files(anzfiles)                       
        .y = ((anzfiles - 1) \ 4) * 60 +5   
        .x = ((anzfiles - 1) mod 4) * (600 \ 4) +20
    End With
End Sub
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Oct 06, 2011 15:46

Cherry wrote:I'd do it like this: Change "Dim Shared As Icon Files(999)" to "ReDim......"

To what? I never used "Redim" and something like that. :-/

I have a problem with my browser too:
I need to reset the mousewheel, because when i scroll up more and more, the mousewheel doesnt reset and i have to scroll down the whole way again. :-/
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Postby Cherry » Oct 06, 2011 16:50

I meant using ReDim instead of Dim to make it dynamic, and then (as in my example) letting AddFile increase the array size if necessary.

(Well, you could also just do a "If anzfiles > UBound(Files) Then Return" to prevent the program from crashing, but then you couldn't display more than 1000 files.)

For scrolling: I'd maintain a custom scroll-pos variable, and save the old "scroll" variable before requesting it. Then, compare the old a the new scroll value and add it to your custom scroll variable. You can then just contrain your custom variable to upper and lower limits.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Oct 06, 2011 18:04

Hm, like this?

Code: Select all

Dim As Int oldscroll, newscroll

...

Do
   Getmouse oldscroll
   If oldscroll=newscroll Then
      newscroll+=oldscroll
   End If
   ...
Loop


Sorry, i dont know exactly what you mean, my English is not very good. :-/
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Postby Cherry » Oct 06, 2011 18:19

Code: Select all

Dim Shared As Integer anzfiles,mx,my,mb,tempx,tempy,mz,oldmz,scroll,maxy ' new: oldmz and maxy

' .............other code.............................

Do
        Sleep 1,1
        Getmouse mx,my,mz,mb
        If mb <> -1 Then ' otherwise it will "jump" when you move the mouse out of the window
            scroll += (mz - oldmz) * 10
            oldmz = mz
        EndIf
        Var maxscroll = -(maxy + 60 - 480)
        If scroll < maxscroll Then scroll = maxscroll
        If scroll > 0 Then scroll = 0
        Screenlock


' .............other code.............................


Sub AddFile()
    anzfiles+=1                     
    If anzfiles > UBound(Files) Then ReDim Preserve Files(UBound(Files) + 1000)
    With Files(anzfiles)                       
        .y = ((anzfiles - 1) \ 4) * 60 +5   
        If .y > maxy Then maxy = .y
        .x = ((anzfiles - 1) mod 4) * (600 \ 4) +20
    End With
End Sub

Sub ShowFiles()
    anzfiles=0
    maxy = 0


 ' .............other code.............................


=======

Sprichst du vielleicht Deutsch? Das "anz" im Namen "anzfiles" hat mich auf die Idee gebracht.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Oct 06, 2011 18:43

Ich spreche auch deutsch.
I also speak german.

Mit dem Code funktioniert es leider gar nicht, ich kann überhaupt nicht scrollen.
This code doesnt work, i cant scroll now.

EDIT: Wenn ich diese Zeile lösche, dann klappt es.
When i remove this it works:

Code: Select all

 If scroll < maxscroll Then scroll = maxscroll


I updated the code in my first post. Try it ;)
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Postby Cherry » Oct 06, 2011 19:45

Here, a working version.

I also improved some other things.

Code: Select all

Screen 12

#Include "dir.bi"

Var folder = ImageCreate(32,32)
Var file = ImageCreate(32,32)
Var folder2 = ImageCreate(32,32)

Line folder,(0,0)-(31,31),15,BF
Line folder,(2,7)-(31,28),7,BF
PSet folder,(31,7),15
PSet folder,(31,28),15
PSet folder,(30,28),15
PSet folder,(31,27),15
Line folder,(5,3)-(13,3),0
PSet folder,(14,4),0
Line folder,(0,8)-(5,3),0
Line folder,(15,5)-(28,5),0
Line folder,(1,7)-(26,7),0
Line folder,(0,8)-(0,26),0
Line folder,(29,6)-(29,24),0
Line folder,(27,8)-(27,26),0
PSet folder,(28,25),0
Line folder,(0,26)-(27,26),0
Line folder,(1,8)-(26,8),14,,&b10101010101010101010101010
Line folder,(1,10)-(26,10),14,,&b10101010101010101010101010
Line folder,(1,12)-(26,12),14,,&b10101010101010101010101010
Line folder,(1,14)-(26,14),14,,&b10101010101010101010101010
Line folder,(1,16)-(26,16),14,,&b10101010101010101010101010
Line folder,(1,18)-(26,18),14,,&b10101010101010101010101010
Line folder,(1,20)-(26,20),14,,&b10101010101010101010101010
Line folder,(1,22)-(26,22),14,,&b10101010101010101010101010
Line folder,(1,24)-(26,24),14,,&b10101010101010101010101010
Line folder,(1,9)-(26,9),14,,&b01010101010101010101010101
Line folder,(1,11)-(26,11),14,,&b01010101010101010101010101
Line folder,(1,13)-(26,13),14,,&b01010101010101010101010101
Line folder,(1,15)-(26,15),14,,&b01010101010101010101010101
Line folder,(1,17)-(26,17),14,,&b01010101010101010101010101
Line folder,(1,19)-(26,19),14,,&b01010101010101010101010101
Line folder,(1,21)-(26,21),14,,&b01010101010101010101010101
Line folder,(1,23)-(26,23),14,,&b01010101010101010101010101
Line folder,(1,25)-(26,25),14,,&b01010101010101010101010101
Line folder,(2,8)-(27,8),15,,&b10101010101010101010101010
Line folder,(2,10)-(27,10),15,,&b10101010101010101010101010
Line folder,(2,12)-(27,12),15,,&b10101010101010101010101010
Line folder,(2,14)-(27,14),15,,&b10101010101010101010101010
Line folder,(2,16)-(27,16),15,,&b10101010101010101010101010
Line folder,(2,18)-(27,18),15,,&b10101010101010101010101010
Line folder,(2,20)-(27,20),15,,&b10101010101010101010101010
Line folder,(2,22)-(27,22),15,,&b10101010101010101010101010
Line folder,(2,24)-(27,24),15,,&b10101010101010101010101010
Line folder,(1,9)-(26,9),15,,&b10101010101010101010101010
Line folder,(1,11)-(26,11),15,,&b10101010101010101010101010
Line folder,(1,13)-(26,13),15,,&b10101010101010101010101010
Line folder,(1,15)-(26,15),15,,&b10101010101010101010101010
Line folder,(1,17)-(26,17),15,,&b10101010101010101010101010
Line folder,(1,19)-(26,19),15,,&b10101010101010101010101010
Line folder,(1,21)-(26,21),15,,&b10101010101010101010101010
Line folder,(1,23)-(26,23),15,,&b10101010101010101010101010
Line folder,(1,25)-(26,25),15,,&b10101010101010101010101010
Line folder,(3,6)-(27,6),14,,&b10101010101010101010101010
Line folder,(4,6)-(28,6),15,,&b10101010101010101010101010
PSet folder,(27,7),15
Line folder,(28,7)-(28,24),14,,&b1010101010101010
Line folder,(28,7)-(28,24),15,,&b0101010101010101
PSet folder,(5,4),14
PSet folder,(6,4),15
PSet folder,(7,4),14
PSet folder,(8,4),15
PSet folder,(9,4),14
PSet folder,(10,4),15
PSet folder,(11,4),14
PSet folder,(12,4),15
PSet folder,(13,4),14
Line folder,(0,5)-(14,5),14,,&b01010101010
Line folder,(0,5)-(14,5),15,,&b10101010101
PSet folder,(3,5),0
PSet folder,(4,5),14

Line file,(0,0)-(31,31),15,BF
Line file,(5,12)-(28,31),7,BF
Line file,(3,0)-(15,0),0
Line file,(3,0)-(3,29),0
Line file,(3,29)-(26,29),0
Line file,(26,29)-(26,11),0
Line file,(26,11)-(15,0),0
Line file,(15,0)-(15,11),0
Line file,(15,11)-(26,11),0
Paint file,(5,2),15,0
Paint file,(18,7),7,0

Line folder2,(0,0)-(31,31),15,BF
Line folder2,(2,7)-(31,28),7,BF
PSet folder2,(31,7),15
PSet folder2,(31,28),15
PSet folder2,(30,28),15
PSet folder2,(31,27),15
Line folder2,(5,3)-(13,3),0
PSet folder2,(14,4),0
Line folder2,(0,8)-(5,3),0
Line folder2,(15,5)-(28,5),0
Line folder2,(1,7)-(26,7),0
Line folder2,(0,8)-(0,26),0
Line folder2,(29,6)-(29,24),0
Line folder2,(27,8)-(27,26),0
PSet folder2,(28,25),0
Line folder2,(0,26)-(27,26),0
Line folder2,(1,8)-(26,8),14,,&b10101010101010101010101010
Line folder2,(1,10)-(26,10),14,,&b10101010101010101010101010
Line folder2,(1,12)-(26,12),14,,&b10101010101010101010101010
Line folder2,(1,14)-(26,14),14,,&b10101010101010101010101010
Line folder2,(1,16)-(26,16),14,,&b10101010101010101010101010
Line folder2,(1,18)-(26,18),14,,&b10101010101010101010101010
Line folder2,(1,20)-(26,20),14,,&b10101010101010101010101010
Line folder2,(1,22)-(26,22),14,,&b10101010101010101010101010
Line folder2,(1,24)-(26,24),14,,&b10101010101010101010101010
Line folder2,(1,9)-(26,9),14,,&b01010101010101010101010101
Line folder2,(1,11)-(26,11),14,,&b01010101010101010101010101
Line folder2,(1,13)-(26,13),14,,&b01010101010101010101010101
Line folder2,(1,15)-(26,15),14,,&b01010101010101010101010101
Line folder2,(1,17)-(26,17),14,,&b01010101010101010101010101
Line folder2,(1,19)-(26,19),14,,&b01010101010101010101010101
Line folder2,(1,21)-(26,21),14,,&b01010101010101010101010101
Line folder2,(1,23)-(26,23),14,,&b01010101010101010101010101
Line folder2,(1,25)-(26,25),14,,&b01010101010101010101010101
Line folder2,(2,8)-(27,8),15,,&b10101010101010101010101010
Line folder2,(2,10)-(27,10),15,,&b10101010101010101010101010
Line folder2,(2,12)-(27,12),15,,&b10101010101010101010101010
Line folder2,(2,14)-(27,14),15,,&b10101010101010101010101010
Line folder2,(2,16)-(27,16),15,,&b10101010101010101010101010
Line folder2,(2,18)-(27,18),15,,&b10101010101010101010101010
Line folder2,(2,20)-(27,20),15,,&b10101010101010101010101010
Line folder2,(2,22)-(27,22),15,,&b10101010101010101010101010
Line folder2,(2,24)-(27,24),15,,&b10101010101010101010101010
Line folder2,(1,9)-(26,9),15,,&b10101010101010101010101010
Line folder2,(1,11)-(26,11),15,,&b10101010101010101010101010
Line folder2,(1,13)-(26,13),15,,&b10101010101010101010101010
Line folder2,(1,15)-(26,15),15,,&b10101010101010101010101010
Line folder2,(1,17)-(26,17),15,,&b10101010101010101010101010
Line folder2,(1,19)-(26,19),15,,&b10101010101010101010101010
Line folder2,(1,21)-(26,21),15,,&b10101010101010101010101010
Line folder2,(1,23)-(26,23),15,,&b10101010101010101010101010
Line folder2,(1,25)-(26,25),15,,&b10101010101010101010101010
Line folder2,(3,6)-(27,6),14,,&b10101010101010101010101010
Line folder2,(4,6)-(28,6),15,,&b10101010101010101010101010
PSet folder2,(27,7),15
Line folder2,(28,7)-(28,24),14,,&b1010101010101010
Line folder2,(28,7)-(28,24),15,,&b0101010101010101
PSet folder2,(5,4),14
PSet folder2,(6,4),15
PSet folder2,(7,4),14
PSet folder2,(8,4),15
PSet folder2,(9,4),14
PSet folder2,(10,4),15
PSet folder2,(11,4),14
PSet folder2,(12,4),15
PSet folder2,(13,4),14
Line folder2,(0,5)-(14,5),14,,&b01010101010
Line folder2,(0,5)-(14,5),15,,&b10101010101
PSet folder2,(3,5),0
PSet folder2,(4,5),14
Line folder2,(22,20)-(8,20),0
Line folder2,(8,20)-(8,15),0
Line folder2,(5,14)-(11,14),0
Line folder2,(5,14)-(8,11),0
Line folder2,(9,12)-(11,14),0
Paint folder2,(8,13),0

Dim Shared As String filename, foldername

Enum IconType ' enumeration for icon type - strings are "bad" in this case
   TYPE_FOLDER
   TYPE_FILE
   TYPE_BFOLDER
End Enum

Type Icon
   As String nam
   As IconType typ
   As Integer x, y, lenx
End Type

Color 0, 15

ReDim Shared As Icon Files(1 To 1000)
Declare Sub AddFile()
Dim Shared As Integer anzfiles ,maxy
Dim As Integer mx, my, mb, tempx, tempy, mz, oldmz, scroll

Declare Sub ShowFiles()
ShowFiles()
Do
   Sleep 1,1
   GetMouse mx,my,mz,mb
   If mb <> -1 Then ' otherwise it will "jump" when you move the mouse out of the window
      scroll += (mz - oldmz) * 30
      oldmz = mz
   EndIf
   Var maxscroll = -(maxy + 60 - 480) ' get maximum for scrolling
   If scroll < maxscroll Then scroll = maxscroll
   If scroll > 0 Then scroll = 0
   ScreenLock
   Cls
   Line (0,0)-(640,480),15,BF
   Dim root As Integer = 0 ' Check if we are in the root directory, for both Windows and Linux
   #Ifdef __FB_WIN32__
      If Dir("..*",fbDirectory Or fbReadOnly) = "" Then root = 1
   #Else
      If CurDir() = "/" Then root = 1
   #EndIf
   For i As Integer=1 To anzfiles
      If Files(i).typ = TYPE_FOLDER Then Put (Files(i).x,Files(i).y+scroll),folder,PSet
      If Files(i).typ = TYPE_FILE Then Put (Files(i).x,Files(i).y+scroll),file,PSet
      If Files(i).typ = TYPE_BFOLDER Then Put (Files(i).x,Files(i).y+scroll),folder2,PSet
      If root AndAlso Files(i).typ = TYPE_BFOLDER Then
         Color 12
      Else
         Color 0
      EndIf
      If Len(Files(i).nam)<13 Then
         Draw String (Files(i).lenx,Files(i).y+34+scroll),Files(i).nam
      Else
         Draw String (Files(i).lenx,Files(i).y+34+scroll),Left(Files(i).nam,10)+"..."
      End If
      If mx>Files(i).x And mx<Files(i).x+32 And my>Files(i).y+scroll And my<Files(i).y+32+scroll And mb=1 Then
         If ChDir(Files(i).nam) = 0 Then
            scroll=0
            anzfiles=0
            Files(i).x=0
            Files(i).y=10
            ShowFiles()
            Sleep 200
         Else
            #Ifdef __FB_WIN32__
               ScreenUnLock()
               Cls()
               Print "Opening " & Files(i).nam & "..."
               Shell("start """" """ & Files(i).nam & """") ' If we are on Windows, open the file
               ScreenLock
            #Else
               ' I don't know how to open a file with linux... does it work with a simple Shell(...) command too?
            #EndIf
         EndIf
      EndIf
      Draw String(500,460),CurDir
   Next
   ScreenUnLock
   
   Var ink = InKey()
   If ink = Chr(27) OrElse ink = Chr(255, 107) Then Exit Do ' also check if "X" button was clicked
Loop
ImageDestroy folder
ImageDestroy folder2
ImageDestroy file
End

Sub AddFile()
   anzfiles+=1
   If anzfiles > UBound(Files) Then ReDim Preserve Files(UBound(Files) + 1000)
   With Files(anzfiles)
      .y = ((anzfiles - 1) \ 4) * 60 +5
      If .y > maxy Then maxy = .y
      .x = ((anzfiles - 1) Mod 4) * (600 \ 4) +20
   End With
End Sub

Sub ShowFiles()
   anzfiles=0
   maxy = 0
   AddFile()
   With Files(anzfiles)
      .y = ((anzfiles - 1) \ 4) * 60 +5
      .x = ((anzfiles - 1) Mod 4) * (600 \ 4) +20
      .nam=".."
      .typ=TYPE_BFOLDER
   End With
   Files(anzfiles).lenx=(Files(anzfiles).x+16)-Len(Files(anzfiles).nam)*4
   Dim attr As Integer ' we need to check if the file is REALLY a directory, because otherwise files without ANY attributes will be considered directories too
   foldername = Dir("*",fbDirectory Or fbReadOnly,@attr)
   Do
      If (attr And fbDirectory) AndAlso foldername<>"" AndAlso foldername <> "." AndAlso foldername <> ".."  Then
         AddFile()
         Files(anzfiles).nam=foldername
         Files(anzfiles).typ=TYPE_FOLDER
         If Len(Files(anzfiles).nam)<10 Then
            Files(anzfiles).lenx=(Files(anzfiles).x+16)-Len(Files(anzfiles).nam)*4
         Else
            Files(anzfiles).lenx=(Files(anzfiles).x+16)-36
         End If
      End If
      foldername =Dir("",0,@attr)
   Loop While Len(foldername)

   filename = Dir("*",0)
   Do
      If filename<>""Then
         AddFile()
         Files(anzfiles).nam=filename
         Files(anzfiles).typ=TYPE_FILE
         If Len(Files(anzfiles).nam)<10 Then
            Files(anzfiles).lenx=(Files(anzfiles).x+16)-Len(Files(anzfiles).nam)*4
         Else
            Files(anzfiles).lenx=(Files(anzfiles).x+16)-36
         End If
      End If
      filename = Dir("",0)
   Loop While Len(filename)
End Sub


=========

Das Scrollen funktioniert, außerdem funktioniert das rote ".." auch unter Windows. Unter Windows kann man jetzt auch Dateien öffnen, außerdem werden unter Windows nicht "." und ein zweites ".." dazu angezeigt.

Man kann jetzt auch mit dem "X"-Knopf das Fenster schließen, es funktionieren mehr als 100 Dateien, und es werden nicht mehr Dateien ohne jegliche Attribute zusätzliche als Ordner angezeigt (das war ein Fehler).^

Nebenbei verwende ich für den Typ jetzt statt einem String einen (weniger Fehler-anfälligen, speicherplatzsparenden und "schöneren") Enum-Typ namens "IconTyp".
Last edited by Cherry on Oct 06, 2011 20:33, edited 1 time in total.
Westbeam
Posts: 239
Joined: Dec 22, 2009 9:24
Contact:

Postby Westbeam » Oct 06, 2011 20:00

Danke Cherry, aber ich habe eine eigene Lösung gefunden(siehe vorherigen Post und den editierten Code im ersten Post). ;)
Habe aber mal trotzdem den Teil, mit dem Verhindern vom doppelten ".." von dir übernommen.

Thank you Cherry, but i found an own solution(watch my last post and the edited code in my first post). ;)
But I use some parts from your solution, for example the part, where you prevent the secound ".."-folder.
Cherry
Posts: 351
Joined: Oct 23, 2007 12:06
Location: Austria
Contact:

Postby Cherry » Oct 06, 2011 20:26

Erm, but in your version you can still scroll beyond the end of the list...
===
In deiner Version kann man aber noch immer über das Ende der Liste hinaus scrollen... dazu war mein Code da.

Die anderen Probleme bestehen in deiner neuen Version auch noch immer, also dass das ".." unter Windows nicht rot angezeigt wird im Wurzelverzeichnis, dass auch Dateien ohne jegliches Attribut fälschlicherweise als Verzeichnisse angezeigt werden, dass ein Klick auf eine Datei zurück an den Anfang scrollt weil nicht überprüft wird ob das ein Verzeichnis ist (und wenn nicht, die Datei geöffnet wird), etc. Und man kann das Fenster auch noch immer nicht mit dem Schließen-Button schließen.

Außerdem werden, obwohl du gesagt hast du hättest das übenommen, unter Windows noch immer ein "." und ein ".." Ordner zusätzlich zu deinem eigenen ".."-Ordner angezeigt.

(Unter Windows listet Dir nämlich auch . und .. als Verzeichnisse auf.)

Return to “Tips and Tricks”

Who is online

Users browsing this forum: No registered users and 7 guests