Sign in to follow this  
eedok

File dialog for SDL project

Recommended Posts

eedok    982
Well I'm looking to make my map editor in SDL to try to keep the dependancies for my project down. Now I'm just wondering what's the best crossplatform way to implement a file choosing dialog(for opening and saving maps)? All I'm looking for is a way to list directory files and return a string the absolute path when they're chosen.

Share this post


Link to post
Share on other sites
Ryan Clark    212
Well, here is some code that contains functions for looping through subdirectories and finding files. It will work on all platforms, provided you compile it on Windows with MinGW. If you try to use it with VC++ you'll run into trouble, as VC++ doesn't have the "dirent.h" header file, for some reason.

Hope this helps!


Ryan

Share this post


Link to post
Share on other sites
Promit    13246
In case it wasn't clear, the actual dialog is something you'll have to write yourself. Unfortunately, this means you can't use the native file browser on any system, which is always annoying. But unless you want to write multiple OS-specialized code paths, you'll need to do it yourself.

Although I suppose a windowing toolkit such as Gtk+ or WxWindows might be very useful, since all the work is done.

Share this post


Link to post
Share on other sites
eedok    982
oops should have mentioned it was in plain C(not C++) looking for something that kind of fits this pseudocode

/**
* Creates a dialog that returns a filename to be passed to fopen
* type is either save or load type
*/
char * filedlg(char mode)
{
while(1){
/* get contents of current directory */
/* display them to screen */
/* allow user input */
/* if file return absolute path to file */
/* if change dir change to the dir */
/* if cancel return */
}
}

So what's the best crossplatform(Linux, BSD, Windows, Mac, Solaris) way to get the contents of current directory?

Share this post


Link to post
Share on other sites
Feidias    92
Quote:
So what's the best crossplatform(Linux, BSD, Windows, Mac, Solaris) way to get the contents of current directory?


I guess using standard library functions supported in all platforms or using a cross-platform library.
In Windows it's possible to use the default file browser because you can get the windows hwnd.

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this