void SNM_ImageVWnd::SetImage(const char* _fn) { if (_fn && *_fn) if (m_img = LICE_LoadPNG(_fn, NULL)) { m_fn.Set(_fn); return; } DELETE_NULL(m_img); m_fn.Set(""); }
static LICE_IBitmap *loadfunc(const char *filename, bool checkFileName, LICE_IBitmap *bmpbase) { if (checkFileName) { const char *p=filename; while (*p)p++; while (p>filename && *p != '\\' && *p != '/' && *p != '.') p--; if (stricmp(p,".png")) return 0; } return LICE_LoadPNG(filename,bmpbase); }
LICE_IBitmap *LICE_LoadPNGFromNamedResource(const char *name, LICE_IBitmap *bmp) // returns a bitmap (bmp if nonzero) on success { char buf[2048]; buf[0]=0; if (strlen(name)>400) return NULL; // max name for this is 400 chars #ifdef __APPLE__ CFBundleRef bund = CFBundleGetMainBundle(); if (bund) { CFURLRef url=CFBundleCopyBundleURL(bund); if (url) { CFURLGetFileSystemRepresentation(url,true,(UInt8*)buf,sizeof(buf)-512); CFRelease(url); } } if (!buf[0]) return 0; strcat(buf,"/Contents/Resources/"); #else int sz = readlink("/proc/self/exe", buf, sizeof(buf)-512); if (sz < 1) { static char tmp; // this will likely not work if the program was launched with a relative path // and the cwd has changed, but give it a try anyway Dl_info inf={0,}; if (dladdr(&tmp,&inf) && inf.dli_fname) sz = (int) strlen(inf.dli_fname); else sz = 0; } if ((unsigned int)sz >= sizeof(buf)-512) sz = sizeof(buf)-512-1; buf[sz]=0; char *p = buf; while (*p) p++; while (p > buf && *p != '/') p--; *p=0; strcat(buf,"/Resources/"); #endif // !__APPLE__ strcat(buf,name); return LICE_LoadPNG(buf,bmp); }
LICE_IBitmap *LICE_LoadPNGFromNamedResource(const char *name, LICE_IBitmap *bmp) // returns a bitmap (bmp if nonzero) on success { char buf[2048]; buf[0]=0; if (strlen(name)>400) return NULL; // max name for this is 400 chars #ifdef __APPLE__ CFBundleRef bund = CFBundleGetMainBundle(); if (bund) { CFURLRef url=CFBundleCopyBundleURL(bund); if (url) { CFURLGetFileSystemRepresentation(url,true,(UInt8*)buf,sizeof(buf)-512); CFRelease(url); } } if (!buf[0]) return 0; strcat(buf,"/Contents/Resources/"); #else char tmp[64]; sprintf(tmp,"/proc/%d/exe",getpid()); int sz = readlink(tmp, buf, sizeof(buf)-512); if (sz<0) sz=0; else if (sz >= sizeof(buf)-512) sz = sizeof(buf)-512-1; buf[sz]=0; char *p = buf; while (*p) p++; while (p > buf && *p != '/') p--; *p=0; strcat(buf,"/Resources/"); #endif // !__APPLE__ strcat(buf,name); return LICE_LoadPNG(buf,bmp); }