Added: background-image for tables

--HG--
branch : html-improvements
hg/feature/html-improvements
Nimetu 5 years ago
parent ecc658703c
commit 2dee4e41ea

@ -164,6 +164,10 @@ namespace NLGUI
bool ContinuousUpdate;
void setTexture(const std::string & TxName);
void setTextureTile(bool tiled);
void setTextureScale(bool scaled);
std::string getProperties( const std::string &name ) const;
void setProperty( const std::string &name, const std::string &value );
xmlNodePtr serialize( xmlNodePtr parentNode, const char *type ) const;
@ -185,6 +189,19 @@ namespace NLGUI
virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup);
// Texture
CViewRenderer::CTextureId _TextureId;
bool _UserTexture;
bool _TextureTiled;
bool _TextureScaled;
// cached absolute coords for background texture
sint32 _TextureXReal;
sint32 _TextureYReal;
sint32 _TextureWReal;
sint32 _TextureHReal;
void updateTextureCoords();
// Content validated
bool _ContentValidated;

@ -286,9 +286,10 @@ namespace NLGUI
{
btn->setTextureOver(file);
}
return;
}
else
{
CViewBitmap *btm = dynamic_cast<CViewBitmap*>(view);
if(btm)
{
@ -296,9 +297,10 @@ namespace NLGUI
btm->invalidateCoords();
btm->invalidateContent();
paragraphChange();
return;
}
else
{
CGroupCell *btgc = dynamic_cast<CGroupCell*>(view);
if(btgc)
{
@ -306,8 +308,16 @@ namespace NLGUI
btgc->invalidateCoords();
btgc->invalidateContent();
paragraphChange();
return;
}
}
CGroupTable *table = dynamic_cast<CGroupTable*>(view);
if (table)
{
table->setTexture(file);
return;
}
}
@ -6571,6 +6581,18 @@ namespace NLGUI
scanHTMLColor(elm.getAttribute("bordercolor").c_str(), table->BorderColor);
}
if (_Style.hasStyle("background-image"))
{
if (_Style.checkStyle("background-repeat", "repeat"))
table->setTextureTile(true);
if (_Style.checkStyle("background-size", "100%"))
table->setTextureScale(true);
string image = _Style.getStyle("background-image");
addImageDownload(image, table);
}
table->setMarginLeft(getIndent());
addHtmlGroup (table, 0);

@ -645,6 +645,13 @@ namespace NLGUI
CellPadding=1;
CellSpacing=2;
ContinuousUpdate = false;
_TextureTiled = false;
_TextureScaled = false;
_TextureXReal = 0;
_TextureYReal = 0;
_TextureWReal = 0;
_TextureHReal = 0;
}
// ----------------------------------------------------------------------------
@ -712,7 +719,50 @@ namespace NLGUI
_Cells.clear ();*/
}
// ----------------------------------------------------------------------------
void CGroupTable::setTexture(const std::string & TxName)
{
if (TxName.empty() || TxName == "none")
{
_TextureId.setTexture(NULL);
}
else
{
_TextureId.setTexture (TxName.c_str (), 0, 0, -1, -1, false);
updateTextureCoords();
}
}
// ----------------------------------------------------------------------------
void CGroupTable::setTextureTile(bool tiled)
{
_TextureTiled = tiled;
}
// ----------------------------------------------------------------------------
void CGroupTable::setTextureScale(bool scaled)
{
_TextureScaled = scaled;
}
// ----------------------------------------------------------------------------
void CGroupTable::updateTextureCoords()
{
if (_TextureId < 0) return;
CViewRenderer &rVR = *CViewRenderer::getInstance();
rVR.getTextureSizeFromId (_TextureId, _TextureWReal, _TextureHReal);
_TextureXReal = _XReal;
_TextureYReal = _YReal + _HReal - _TextureHReal;
if (_TextureTiled && _TextureHReal > 0)
{
sint diff = (_HReal / _TextureHReal) * _TextureHReal;
_TextureYReal -= diff;
_TextureHReal += diff;
}
}
// ----------------------------------------------------------------------------
void CGroupTable::updateCoords()
@ -1178,7 +1228,7 @@ namespace NLGUI
CInterfaceGroup::updateCoords();
updateTextureCoords();
// Validated
@ -1360,6 +1410,26 @@ namespace NLGUI
if (!_Columns.empty() && !_Rows.empty())
{
// Draw the background
if (_TextureId >= 0 && CurrentAlpha != 0)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
CRGBA col = CRGBA::White;
col.A = CurrentAlpha;
if (_TextureScaled && !_TextureTiled)
{
rVR.drawRotFlipBitmap(_RenderLayer, _TextureXReal, _TextureYReal, _WReal, _HReal, 0, false, _TextureId, col);
}
else
{
if (!_TextureTiled)
rVR.drawRotFlipBitmap(_RenderLayer, _TextureXReal, _TextureYReal, _TextureWReal, _TextureHReal, 0, false, _TextureId, col);
else
rVR.drawRotFlipBitmapTiled(_RenderLayer, _TextureXReal, _TextureYReal, _WReal, _TextureHReal, 0, false, _TextureId, 0, col);
}
}
sint32 border = Border + CellSpacing;
if (border && BgColor.A)
{

Loading…
Cancel
Save