123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|301|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Blitz -> File/Folder browsing in Blitz3D...

Wed, 19 Mar 2008, 12:54
Forklift_Fred
I'm sure I saw it here somewhere but I can't find it now...

I'm looking for a quick solution for some basic file accessing. I've just about got by with what I've needed to do by placing my exe into the right folder and running it (it does various checks and stuff on whatever files are in the current folder) but I'd like to be able to run the program from a shortcut and navigate my way to the relevant folder from with it so I can also have a config/preferences file.

As I say, I'm sure someone posted a snippet of functions for a basic file browser... unless it was at BB.com (I don't go there very often)

So can anyone help? (either point me to it or give me some direction on doing it myself)

Thanks

-=-=-
Come rain or shine...
Wed, 19 Mar 2008, 13:10
Afr0
but I'd like to be able to run the program from a shortcut and navigate my way to the relevant folder from with it so I can also have a config/preferences file.


Not sure what you mean by this, really, but it sounds like you're looking at making your own registry entries with an install program. To read these from within Blitz, look at some dcls files that were written for use with various Windows libraries within Blitz. I'm sure I've seen some over at BlitzBasic.com

-=-=-
Afr0 Games

Project Dollhouse on Github - Please fork!
Wed, 19 Mar 2008, 15:31
Phoenix


At first, I just meant to write a little example, but it became a full file explorer instead Use the scroll wheel to scroll in big folders.
Wed, 19 Mar 2008, 16:14
Forklift_Fred
@ Afro: Thanks but that's a step further than I was wanting to go. Your right though, I think I confused things with my wording there!

@ Phoenix: Thank you, that will certainly do the job. I can tweak it and mold it from there.

Bit confused by the "." and ".." directories though, I thought "." was the root and ".." was the previous (up 1 level), they both appear to do the same here. Doesn't really matter though, I can easily add a root link and probably keep the two at the top for easy access.

Really appreciate that. Thanks.

-=-=-
Come rain or shine...
Wed, 19 Mar 2008, 16:22
Phoenix
Actually, they behave the same because I programmed them to do so. Couldn't be bothered giving the different behaviors

Update the folder checking code to this:


Wed, 19 Mar 2008, 18:21
Forklift_Fred
Aaah fair enough
Thanks for the update.

I've modified the scrolling to stop it going beyond the top and bottom. It's a bit patchy at the bottom (and looks messy anyway!) but it does the job.

Had to globalise n (which should probably be renamed now it's global) and added "Global static" and reset it with "static=MouseZ()" after the "scrollOffset = 0" in the folder checking.

Then replace the "scrollOffset = MouseZ()*20" with


Like I said, it's messy!

Next step is to add the keyboard function of Home to scroll to the top and maybe Page Up/Down because I like to use the keyboard sometimes

-=-=-
Come rain or shine...
Thu, 20 Mar 2008, 14:57
Forklift_Fred
OK, something wasn't right and like I said, it was "a bit patchy at the bottom" and now I know why.

Where you had it scrolling at a rate of MouseZ()*20 I took that to be the line spacing (although I usually use 15 myself and it clearly states in your comments that you used 14!!) thus all the messy calculations *20 and /20 were wrong.

When I added Home and End control it became all to apparent when the Windows folder listing wasn't even going half way!

So I eventually resolved that and added cursor control and struggled with setting the static value correctly... The easiest way was to change the fixed relationship between MouseZ() and scrollOffset into a relative increment relationship with MouseZSpeed() so it worked the same as the keyboard. Thus I have come to a much cleaner code and removed the static variable

I now have the following globals set up...



Where lineheight is variable depending on the size of the font used (and has to be set before the directories are read to prevent a divide by zero error!) and maxoffset stops the bottom of the list from scrolling too high up the screen. These are all set at the end of the GetDirInfo() function thus:



Now replace the scrolling section of the code (originaly just scrollOffset = MouseZ()*20 at the top of the While loop with this...



Note the addition of mzs = MouseZSpeed() to go along with the my, mx, mh1 abbreviations, this is what increments the scrolloffset.

Putting it all together, you end up with...



As you can see, It's still the same basic solution but with some added functionality and a tweak to allow for it. Built on Phoenix's original, I couldn't have done it on my own so big thanks to you

-=-=-
Come rain or shine...
Thu, 20 Mar 2008, 17:16
Phoenix
(Yes, I am bored!)

Now features a draggable window! Click the mouse to show the file selection dialog. Change wndW and wndH to get different window sizes.


Thu, 20 Mar 2008, 17:37
Forklift_Fred
Well, since we're sharing, I've added the current location in a bar at the top and have just been fighting with a scroll bar - more for an indicator of how far down you are than to scroll with... my brain hurts too much to use it to scroll with



And you'll see that I'm working with a larger window but it should all scale properly anyway, even down to your movable window, though the location along the top will get trimmed very early

Oh and I've also modified the lastDir part so that you can start anywhere and ".." will still take you up a level rather than having to know where you were. Previously, if you started within a few folders, if you clicked ".." first you would go to the root.

Oh and the only thing I want to add now is the ability to scroll down to files starting with "H" by pressing "H" on the keyboard (or whichever letter, obviously)... cycle through the scancodes with KeyHit() then through the file list perhaps?

-=-=-
Come rain or shine...
Thu, 20 Mar 2008, 18:26
spinal
I'm watching this closely, my movie converter is begging for a file browser, but I'm too lazy to do it myself.

-=-=-
Check out my excellent homepage!
Fri, 21 Mar 2008, 11:47
Forklift_Fred
Well at least you're honest
Fri, 21 Mar 2008, 14:13
Forklift_Fred
Another update then... You can now use the keyboard to jump to specific letters and use Backspace to go up a level like Windows Explorer

Add the scancodes to an array using Data statements:



At the end of the scroll code, before the file checking begins, check and note key presses and go up a level if Backspace has been pressed:



And finally, at the start of the file checking (before the mouse RectsOverlap part) do the scrolling:




So the whole thing now looks like this:



Just the scrollbar to action now... Not looking forward to that though because I'm expecting some ugly maths...

-=-=-
Come rain or shine...
Fri, 21 Mar 2008, 15:04
Forklift_Fred
Actually, it wasn't that hard
A couple of fiddly moments where the scrollbar insisted of scrolling up when the mouse was down but not moving - which I think was due to numbers being rounded off in the original code and then fall short when I converted it back.

I've added a global variable for the width of the scrollbar so when the file checking code sets the positioning it now says itemX = scrollbarwidth + 5 but apart from that, replace the existing scrollbar code with this...



Sorted!

|EDIT| had to add And maxoffset>0 to the If RectsOverlap... because if there isn't enough files to scroll then it would try to divide 0 and crash.

-=-=-
Come rain or shine...
Sat, 22 Mar 2008, 05:22
Phoenix
You know, there is a GetKey() command
Sat, 22 Mar 2008, 18:05
Forklift_Fred
Yes but... does it make much difference?

I avoided it thinking it was a 'wait until a key is pressed' command but that would be WaitKey()! I've just got into the habit of KeyHit() for using cursor keys.

I suppose you'd be checking ASCII values rather than looking up in an array.

Oh well, mine works well enough.

Mind you, Backspace, Home, End, PageUp and PageDown would still need to be KeyHit()

-=-=-
Come rain or shine...
Wed, 26 Mar 2008, 13:44
Forklift_Fred
One last update (I think...)

I thought I'd already put this to bed but after adding a load of my other code into it for its ultimate purpose and got that all working right, I was running a few tests and found that the scrollbar wasn't actually working correctly. It was OK for small listings where the bar doesn't move very much but longer file lists and therefore a smaller bar, lead to it jumping a lot further out of place. I went back in and after playing with the maths, resorted back to my original idea of adding a flag to indicate whether it is being dragged or not and basically attaching it to the pointer. I didn't try it originally because I thought it would be more work... turned out to be much easier and spot on!

I've not added the variables as Global or Local (I have never bothered with Local anyway!) as they are only needed when you first grab the scrollbar and get switched on then, otherwise the initial False and 0 are perfect...



You'll see it's grab and mousegrab that I've added (I've also abbreviated the GraphicsHeight() down to gfxh (defined at the start of the program, not here) and abbreviated the size of the overall scroller down to scrollerheight) I also made the scrollbar colour definition more dynamic rather than drawing it twice if it's being dragged.

Oh and while I was there, I added the ability to click above or below the bar to scroll whole pages.

I'm sure the whole thing can be repeated horizontally without much effort too if needed

-=-=-
Come rain or shine...
Fri, 02 Nov 2018, 14:32
Dan
Hello, for my project i'v used the code from Phoenix, and here are my modifications:


Fri, 02 Nov 2018, 16:42
rockford
Only 10 years late... Better late than never?
Fri, 02 Nov 2018, 18:21
zzoom
It's not late until it's too late, thanks for sharing

Great looking indentation as well

-=-=-
Happy coding!
Sat, 03 Nov 2018, 03:00
Dan
well, as long as blitz runs on windows its not late ^^;



Great looking indentation as well


Thanks, its ideal.

i mean, done by ideal. the ide, aI

(pun : that's big i in the last al ) (edit well it looks the same in the editor font)
Sat, 03 Nov 2018, 07:40
zzoom
IDEal, my fave UI for coding
Wed, 22 May 2024, 07:14
spinal
I used this for a basis for something I'm working on, so before I start adding all sorts of crap to it, I'll post the minor changes I made.



-=-=-
Check out my excellent homepage!