File dialog for SDL project

Started by
6 comments, last by Feidias 19 years, 6 months ago
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.
Advertisement
Best way is to do it yourself.
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
--Visit the Game Programming Wiki!
I've used the filesystem library from Boost before. You might wanna check it out

Drew Sikora
Executive Producer
GameDev.net

#include <stdilb.h>

void ScanDirectory(void)
{
system("dir *.bmp -b > temp.txt");
}

that should do it in dos.
HxRender | Cornerstone SDL TutorialsCurrently picking on: Hedos, Programmer One
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.
SlimDX | Ventspace Blog | Twitter | Diverse teams make better games. I am currently hiring capable C++ engine developers in Baltimore, MD.
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?
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