/* Function: al_make_path_absolute */ bool al_make_path_absolute(ALLEGRO_PATH *path) { ALLEGRO_PATH *cwd_path; int i; ASSERT(path); if (path_is_absolute(path)) { return true; } cwd_path = al_get_current_directory(); if (!cwd_path) return false; al_set_path_drive(path, al_get_path_drive(cwd_path)); for (i = al_get_path_num_components(cwd_path) - 1; i >= 0; i--) { al_insert_path_component(path, 0, al_get_path_component(cwd_path, i)); } al_destroy_path(cwd_path); return true; }
const char* getResource(const char* fmt, ...) { va_list ap; static char res[512]; static ALLEGRO_PATH *dir; static ALLEGRO_PATH *path; va_start(ap, fmt); memset(res, 0, 512); snprintf(res, 511, fmt, ap); if (!dir) { dir = al_get_standard_path(ALLEGRO_RESOURCES_PATH); #ifdef ALLEGRO_MSVC { /* Hack to cope automatically with MSVC workspaces. */ const char *last = al_get_path_component(dir, -1); if (0 == strcmp(last, "Debug") || 0 == strcmp(last, "RelWithDebInfo") || 0 == strcmp(last, "Release") || 0 == strcmp(last, "Profile")) { al_remove_path_component(dir, -1); } } #endif al_append_path_component(dir, "data"); } if (path) al_destroy_path(path); path = al_create_path(res); al_rebase_path(dir, path); return al_path_cstr(path, '/'); }
static int allua_Path_get_component(lua_State * L) { ALLUA_path path = allua_check_path(L, 1); int i = luaL_checkint(L, 2); lua_pushstring(L, al_get_path_component(path, i)); return 1; }
/* Function: al_get_path_tail */ const char *al_get_path_tail(const ALLEGRO_PATH *path) { ASSERT(path); if (al_get_path_num_components(path) == 0) return NULL; return al_get_path_component(path, -1); }
//////////////////////////////////////////////////////////////////////////////// // A helper function for loading an Allegro dat file where cursors are // supposed to be stored. MAS::Error MAS::Skin::LoadCursors(ALLEGRO_PATH *dir, ALLEGRO_CONFIG *config) { if (!dir || !al_is_path_present(dir)) { return Error(Error::NO_FILE); } MAS::Cursor::ReadSkinData(config); al_set_path_filename(dir, al_get_path_component(dir, -1)); al_set_path_extension(dir, ".ini"); const char *config_path_t = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP); ALLEGRO_CONFIG *mouse_config = al_load_config_file(config_path_t); int i; char tmp[256]; char *config_path = strdup(config_path_t); int x, y, frames, interval; const char *str; // Look for each bitmap inside the dat file and load it if it exists for (i=0; i<nCursors; i++) { al_set_path_filename(dir, cursorName[i]); al_set_path_extension(dir, ".png"); const char *fullPath = al_path_cstr(dir, ALLEGRO_NATIVE_PATH_SEP); Bitmap bmp; if (bmp.Load(fullPath, Bitmap::MEMORY) == Error::NONE) { snprintf(tmp, 256, "%s_FCSX", cursorName[i]); x = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0; snprintf(tmp, 256, "%s_FCSY", cursorName[i]); y = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 0; snprintf(tmp, 256, "%s_FRMS", cursorName[i]); frames = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 1; snprintf(tmp, 256, "%s_FDUR", cursorName[i]); interval = (str = al_get_config_value(mouse_config, "HOTSPOTS", tmp)) ? strtol(str, NULL, 10) : 20; curList[i]->Create(bmp, frames); curList[i]->SetFocus(x, y); curList[i]->SetAnimationInterval(interval); } } al_set_path_filename(dir, ""); free(config_path); al_destroy_config(mouse_config); return Error(Error::NONE); }