File dialog for SDL project
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.
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
Hope this helps!
Ryan
#include <stdilb.h>
void ScanDirectory(void)
{
system("dir *.bmp -b > temp.txt");
}
that should do it in dos.
void ScanDirectory(void)
{
system("dir *.bmp -b > temp.txt");
}
that should do it in dos.
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.
Although I suppose a windowing toolkit such as Gtk+ or WxWindows might be very useful, since all the work is done.
oops should have mentioned it was in plain C(not C++) looking for something that kind of fits this pseudocode
So what's the best crossplatform(Linux, BSD, Windows, Mac, Solaris) way to get the contents of current directory?
/** * 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?
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.
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement