Esempio n. 1
0
Resource* BmpALoader(const std::string& resName)
{
  std::string img = resName.substr(0, resName.size() - 1);
  std::string alpha = GetFileNoExt(img) + "-a.bmp";

  unsigned int w = 0;
  unsigned int h = 0;
  
  unsigned char* rgbdata = LoadDIBitmap(img.c_str(), &w, &h);
  
  if (!rgbdata)
  {
//?    ReportError("Failed to load texture " + img);
    return 0;
  }

  // Add space for alpha
  unsigned char* withAlpha = AddAlpha(rgbdata, w, h);
  Assert(withAlpha);
  delete [] rgbdata;
  rgbdata = 0;

  // Load alpha image
  unsigned int aw = 0;
  unsigned int ah = 0;
  unsigned char* alphadata = LoadDIBitmap(alpha.c_str(), &aw, &ah);
  Assert(alphadata);
  Assert(aw == w);
  Assert(ah == h);

  // Copy alpha image to alpha channel of RGB image
  CopyAlpha(alphadata, withAlpha, w, h);
  delete [] alphadata;
  alphadata = 0;

  Texture* pTex = new Texture;
  pTex->Create(withAlpha, w, h, 4); // 4 bytes per pixel
  delete [] withAlpha;

  return (Resource*)pTex;
}
Esempio n. 2
0
void UIAnimation::LoadFromXML(tinyxml2::XMLElement* elem)
{
	if (!elem)
		return;

	const char* sz = elem->Attribute("id");
	if (sz)
		mID = StringConverter::ParseInt(sz);

	sz = elem->Attribute("name");
	if (sz)
		mName = sz;

	sz = elem->Attribute("length");
	if (sz)
		mLength = StringConverter::ParseReal(sz);

	sz = elem->Attribute("loop");
	if (sz)
		mLoop = StringConverter::ParseBool(sz);

	{
		tinyxml2::XMLElement* pC = elem->FirstChildElement("TextColor");
		if (pC)
		{
			tinyxml2::XMLElement* k = pC->FirstChildElement("key");
			while (k)
			{
				float time = 0;
				Color color;
				sz = k->Attribute("time");
				if (sz)
					time = StringConverter::ParseReal(sz);
				sz = k->Attribute("color");
				if (sz)
					color = StringMathConverter::ParseColor(sz);
				AddTextColor(time, color);
				k = k->NextSiblingElement("key");
			}
		}
	}

	{
		tinyxml2::XMLElement* pC = elem->FirstChildElement("BackColor");
		if (pC)
		{
			tinyxml2::XMLElement* k = pC->FirstChildElement("key");
			while (k)
			{
				float time = 0;
				Color color;
				sz = k->Attribute("time");
				if (sz)
					time = StringConverter::ParseReal(sz);
				sz = k->Attribute("color");
				if (sz)
					color = StringMathConverter::ParseColor(sz);
				AddBackColor(time, color);
				k = k->NextSiblingElement("key");
			}
		}
	}

	{
		tinyxml2::XMLElement* pC = elem->FirstChildElement("MaterialColor");
		if (pC)
		{
			tinyxml2::XMLElement* k = pC->FirstChildElement("key");
			while (k)
			{
				float time = 0;
				Color color;
				sz = k->Attribute("time");
				if (sz)
					time = StringConverter::ParseReal(sz);
				sz = k->Attribute("color");
				if (sz)
					color = StringMathConverter::ParseColor(sz);
				AddMaterialColor(time, color);
				k = k->NextSiblingElement("key");
			}
		}
	}

	{
		tinyxml2::XMLElement* pC = elem->FirstChildElement("Pos");
		if (pC)
		{
			tinyxml2::XMLElement* k = pC->FirstChildElement("key");
			while (k)
			{
				float time = 0;
				Vec2 pos;
				sz = k->Attribute("time");
				if (sz)
					time = StringConverter::ParseReal(sz);
				sz = k->Attribute("pos");
				if (sz)
					pos = StringMathConverter::ParseVec2(sz);
				AddPos(time, pos);
				k = k->NextSiblingElement("key");
			}
		}
	}

	{
		tinyxml2::XMLElement* pC = elem->FirstChildElement("Scale");
		if (pC)
		{
			tinyxml2::XMLElement* k = pC->FirstChildElement("key");
			while (k)
			{
				float time = 0;
				Vec2 scale;
				sz = k->Attribute("time");
				if (sz)
					time = StringConverter::ParseReal(sz);
				sz = k->Attribute("scale");
				if (sz)
					scale = StringMathConverter::ParseVec2(sz);
				AddScale(time, scale);
				k = k->NextSiblingElement("key");
			}
		}
	}

	{
		tinyxml2::XMLElement* pC = elem->FirstChildElement("Alpha");
		if (pC)
		{
			tinyxml2::XMLElement* k = pC->FirstChildElement("key");
			while (k)
			{
				float time = 0;
				float alpha;
				sz = k->Attribute("time");
				if (sz)
					time = StringConverter::ParseReal(sz);
				sz = k->Attribute("alpha");
				if (sz)
					alpha = StringConverter::ParseReal(sz);
				AddAlpha(time, alpha);
				k = k->NextSiblingElement("key");
			}
		}
	}
}