Fix html img not showing on some cases, clean up addImage method

This commit is contained in:
Nimetu 2014-10-18 01:20:56 +03:00
parent e9256d3b0b
commit ea2e8d1b92

View file

@ -3153,37 +3153,28 @@ namespace NLGUI
void CGroupHTML::addImage(const char *img, bool globalColor, bool reloadImg) void CGroupHTML::addImage(const char *img, bool globalColor, bool reloadImg)
{ {
// In a paragraph ? // In a paragraph ?
if (_Paragraph) if (!_Paragraph)
{ {
newParagraph (0);
paragraphChange ();
}
string finalUrl; string finalUrl;
// No more text in this text view
_CurrentViewLink = NULL;
// Not added ?
CViewBitmap *newImage = new CViewBitmap (TCtorParam());
// //
// 1/ try to load the image with the old system (local files in bnp) // 1/ try to load the image with the old system (local files in bnp)
// //
string image = CFile::getPath(img) + CFile::getFilenameWithoutExtension(img) + ".tga"; string image = CFile::getPath(img) + CFile::getFilenameWithoutExtension(img) + ".tga";
if (lookupLocalFile (finalUrl, image.c_str(), false)) if (lookupLocalFile (finalUrl, image.c_str(), false))
{ {
// No more text in this text view
_CurrentViewLink = NULL;
// Not added ?
CViewBitmap *newImage = new CViewBitmap (TCtorParam());
/* todo link in image
if (getA())
{
newImage->Link = getLink();
newImage->setHTMLView (this);
}*/
newImage->setRenderLayer(getRenderLayer()+1); newImage->setRenderLayer(getRenderLayer()+1);
newImage->setTexture (finalUrl); image = finalUrl;
newImage->setModulateGlobalColor(globalColor);
/* todo link in image
if (getA())
getParagraph()->addChildLink(newImage);
else*/
getParagraph()->addChild(newImage);
paragraphChange ();
} }
else else
{ {
@ -3193,72 +3184,27 @@ namespace NLGUI
image = localImageName(img); image = localImageName(img);
if (!reloadImg && lookupLocalFile (finalUrl, image.c_str(), false)) if (!reloadImg && lookupLocalFile (finalUrl, image.c_str(), false))
{ {
// No more text in this text view
_CurrentViewLink = NULL;
// Not added ?
CViewBitmap *newImage = new CViewBitmap (TCtorParam());
/* todo link in image
if (getA())
{
newImage->Link = getLink();
newImage->setHTMLView (this);
}*/
// don't display image that are not power of 2 // don't display image that are not power of 2
uint32 w, h; uint32 w, h;
CBitmap::loadSize (image, w, h); CBitmap::loadSize (image, w, h);
if (w == 0 || h == 0 || ((!NLMISC::isPowerOf2(w) || !NLMISC::isPowerOf2(h)) && !NL3D::CTextureFile::supportNonPowerOfTwoTextures())) if (w == 0 || h == 0 || ((!NLMISC::isPowerOf2(w) || !NLMISC::isPowerOf2(h)) && !NL3D::CTextureFile::supportNonPowerOfTwoTextures()))
image.clear(); image.clear();
newImage->setTexture (image);
// newImage->setTexture (finalUrl);
newImage->setModulateGlobalColor(globalColor);
/* todo link in image
if (getA())
getParagraph()->addChildLink(newImage);
else*/
getParagraph()->addChild(newImage);
paragraphChange ();
} }
else else
{ {
// //
// 3/ if it doesn't work, display a placeholder and ask to dl the image into the cache // 3/ if it doesn't work, display a placeholder and ask to dl the image into the cache
// //
image = "web_del.tga"; image = "web_del.tga";
if (lookupLocalFile (finalUrl, image.c_str(), false)) addImageDownload(img, newImage);
{ }
// No more text in this text view }
_CurrentViewLink = NULL;
// Not added ?
CViewBitmap *newImage = new CViewBitmap (TCtorParam());
/* todo link in image
if (getA())
{
newImage->Link = getLink();
newImage->setHTMLView (this);
}*/
newImage->setTexture (image); newImage->setTexture (image);
// newImage->setTexture (finalUrl);
newImage->setModulateGlobalColor(globalColor); newImage->setModulateGlobalColor(globalColor);
addImageDownload(img, newImage);
/* todo link in image
if (getA())
getParagraph()->addChildLink(newImage);
else*/
getParagraph()->addChild(newImage); getParagraph()->addChild(newImage);
paragraphChange (); paragraphChange ();
} }
}
}
}
}
// *************************************************************************** // ***************************************************************************