A5 Make Path Absolute
James Bunting

In Allegro 5, al_make_path_canonical does not seem to convert relative paths to absolute, whereas Allegro 4's canonicalize_filename did (as I recall).

I concede that the newer approach makes perfect sense as a relative path is arguably more simple but don't worry about all that.

Anyway, I could missing something simple so...

Does Allegro 5 have a simple "1 liner" method to make a path absolute, or do I have to code my way around it by getting the CWD manually and appending the path?

al_make_path_absolute_where_possible()?

Edgar Reynaldo

Here ya go :

string RelativeToAbsolute(string relative) {
   return string(al_get_current_directory()) + ALLEGRO_NATIVE_PATH_SEP + relative;
}

Matthew Leverton

First create a path for the current working directory:

char *tmp = al_get_current_directory();
ALLEGRO_PATH *cwd = al_create_path_for_directory(tmp);
al_free(tmp);

Then whenever you want an absolute path:

al_rebase_path(cwd, path);

So it's a one liner if you first create a global path object for the current working directory. (Be sure to free it later.)

Here ya go :

Leaks memory due to the call to al_get_current_directory().

Thomas Fjellstrom

Hm, I thought it existed, but it looks like it slipped my mind. All it would likely do is just append cwd and the path, which can be done easily enough.

Edgar Reynaldo

Leaks memory due to the call to al_get_current_directory().

Whoops.

Fixed :

string RelativeToAbsolute(string relative) {
   char* cwd = al_get_current_directory();
   string path = string(cwd) + ALLEGRO_NATIVE_PATH_SEP + relative;
   al_free(cwd);
   return path;
}

Matthew Leverton

Hm, I thought it existed, but it looks like it slipped my mind

It's kind of a specialty function that I'm not sure should exist in Allegro. That is, creating an absolute path from the current working directory is two discrete steps.

It might be nice to have something like: al_get_standard_path(ALLEGRO_CURRENT_PATH), but even that is just a convenience wrapper around the code I wrote above.

James Bunting

Thanks for the help people.

For the record I am working on porting a file picker dialog I originally wrote for AllegroGL under Allegro 4. I could not find a file dialog in 5 (apart from the native one which crashes in full screen and would require a mode switch anyway).

Edgar Reynaldo

If it crashes in full screen, then cheat : al_set_new_display_flags(ALLEGRO_FULLSCREEN_WINDOW);.

James Bunting

Sounds promising, I will look into that thanks.

Shot of work in progress picker here BTW
http://www.jbserver.com/temp/picker.jpg

Edgar Reynaldo

RE: pic
Looks pretty good. I think the scrollbar handles should be shrunk to fit inside the scrollbar area though, just by a pixel though. They almost look oversized right now.

If you're feeling ambitious, you might want to implement a folder tree.

Thread #608723. Printed from Allegro.cc