Exemplo n.º 1
0
bool TextureHandler::Load (const char *zip) 
{
	FILE *f = fopen (zip, "rb");

	if (f) {
		ZipFile *zf = new ZipFile;
		if (zf->Init (f) == RET_FAIL) {
			logger.Trace (NL_Error, "Failed to load zip archive %s\n", zip);
			fclose (f);
			return false;
		}

		const char *imgExt[]={ "bmp", "jpg", "tga", "png", "dds", "pcx", "pic", "gif", "ico", 0 };

		// Add the zip entries to the texture set
		for (int a=0;a<zf->GetNumFiles ();a++)
		{
			char tempFile[64];
			zf->GetFilename (a, tempFile, sizeof(tempFile));

			char *ext=FixTextureName (tempFile);
			if (ext)
			{
				int x=0;
				for (x=0;imgExt[x];x++)
					if (!strcmp(imgExt[x],ext)) break;

				if (!imgExt[x])
					continue;

				if (textures.find(tempFile) != textures.end())
					continue;

				TexRef ref;
				ref.zip = zips.size();
				ref.index = a;
				ref.texture = LoadTexture (zf,a, tempFile);

				if(textures.find(tempFile)!=textures.end())
					logger.Trace(NL_Debug,"Texture %s already loaded\n", tempFile);

				TexRef &tr = textures[tempFile];
				tr.texture = ref.texture;
				tr.index = a;;
				tr.zip = zips.size();
			}
		}

		fclose (f);

		zips.push_back (zf);
	}

	return false;
}
Exemplo n.º 2
0
void Tools::LoadImages()
{
	FILE *f = fopen("data/data.ups", "rb");
	if (!f) {
		fltk::message("Failed to load data.ups");
	}
	else
	{
		ZipFile zf;
		zf.Init(f);

		for(unsigned int a=0;a<tools.size();a++) {
			if (!tools[a]->imageFile)
				continue;

			std::string fn = tools[a]->imageFile;

			int zipIndex=-1;
			for (int fi=0;fi<zf.GetNumFiles();fi++) {
				char zfn [64];
				zf.GetFilename(fi, zfn, sizeof(zfn));
				if (!STRCASECMP(zfn, fn.c_str())) {
					zipIndex = fi;
					break;
				}
			}

			if (zipIndex>=0) {
				int len = zf.GetFileLen(zipIndex);
				char *buf = new char[len];
				zf.ReadFile(zipIndex, buf);

				tools[a]->image = FltkImage::Load(buf, len);
				if (!tools[a]->image) {
					fltk::message("Failed to load texture %s\n", fn.c_str());
					delete[] buf;
					continue;
				}
				delete[] buf;

				tools[a]->button->image(tools[a]->image->img);
				tools[a]->button->label("");
			} else
				fltk::message("Couldn't find %s", fn.c_str());
		}
		fclose(f);
	}
}