Fixed: Drawing table and cell background image and modulating color from global.

--HG--
branch : html-improvements
hg/feature/html-improvements
Nimetu 5 years ago
parent 30e0018d0a
commit 036410af62

@ -174,6 +174,7 @@ namespace NLGUI
styleStackIndex++;
_StyleStack.push_back(Current);
Current.GlobalColor = false;
Current.DisplayBlock = false;
Current.Width=-1;
Current.Height=-1;

@ -92,8 +92,7 @@ namespace NLGUI
NLMISC::CRGBA BgColor;
// Texture
CViewRenderer::CTextureId _TextureId; /// Accelerator
bool _UserTexture;
CViewRenderer::CTextureId _TextureId;
bool _TextureTiled;
bool _TextureScaled;
// cached absolute coords for background texture
@ -191,7 +190,6 @@ namespace NLGUI
// Texture
CViewRenderer::CTextureId _TextureId;
bool _UserTexture;
bool _TextureTiled;
bool _TextureScaled;
// cached absolute coords for background texture

@ -3450,6 +3450,7 @@ namespace NLGUI
CViewBitmap *bitmap = dynamic_cast<CViewBitmap*> (view);
if (bitmap)
{
// TODO: background color should have separate bitmap from background texture
// Change the background color
bitmap->setColor (bgcolor);
bitmap->setModulateGlobalColor(false);
@ -3472,6 +3473,7 @@ namespace NLGUI
bitmap->setPosRef(Hotspot_TL);
bitmap->setX(0);
bitmap->setY(0);
// FIXME: renders behind container background
bitmap->setRenderLayer(-2);
bitmap->setScale(scale);
bitmap->setTile(tile);
@ -5219,9 +5221,7 @@ namespace NLGUI
{
CGroupHTML::CCellParams cellParams;
if (!_CellParams.empty() && inherit)
{
cellParams = _CellParams.back();
}
if (_Style.hasStyle("background-color"))
cellParams.BgColor = _Style.Current.BackgroundColor;
@ -6592,6 +6592,9 @@ namespace NLGUI
addImageDownload(image, table, CStyleParams(), TImageType::NormalImage, "");
}
// setting ModulateGlobalColor must be after addImageDownload
if (_Style.checkStyle("-ryzom-modulate-bgcolor", "true"))
table->setModulateGlobalColor(true);
table->setMarginLeft(getIndent());
addHtmlGroup (table, 0);
@ -6619,9 +6622,21 @@ namespace NLGUI
// ***************************************************************************
void CGroupHTML::htmlTD(const CHtmlElement &elm)
{
CRGBA rowColor = CRGBA::Transparent;
// remember row color so we can blend it with cell color
if (!_CellParams.empty())
rowColor = _CellParams.back().BgColor;
// Get cells parameters
getCellsParameters(elm, true);
// if cell has own background,then it must be blended with row
if (rowColor.A > 0 && (elm.hasNonEmptyAttribute("bgcolor") || _Style.hasStyle("background-color")))
{
if (_CellParams.back().BgColor.A < 255)
_CellParams.back().BgColor.blendFromui(rowColor, _CellParams.back().BgColor, _CellParams.back().BgColor.A);
}
if (elm.ID == HTML_TH)
{
if (!_Style.hasStyle("font-weight"))
@ -6691,6 +6706,11 @@ namespace NLGUI
getPercentage (_Cells.back()->Height, temp, elm.getAttribute("height").c_str());
_Cells.back()->NewLine = getTR();
// setting ModulateGlobalColor must be after addImageDownload
if (_Style.checkStyle("-ryzom-modulate-bgcolor", "true"))
_Cells.back()->setModulateGlobalColor(true);
table->addChild (_Cells.back());
// reusing indent pushed by table
@ -6799,6 +6819,10 @@ namespace NLGUI
// ***************************************************************************
void CGroupHTML::htmlTR(const CHtmlElement &elm)
{
// prevent inheriting background color
if (!_CellParams.empty())
_CellParams.back().BgColor = CRGBA::Transparent;
// Get cells parameters
getCellsParameters(elm, true);

@ -59,7 +59,6 @@ namespace NLGUI
IgnoreMaxWidth = false;
IgnoreMinWidth = false;
AddChildW = false;
_UserTexture = false;
_TextureTiled = false;
_TextureScaled = false;
_TextureXReal = 0;
@ -486,16 +485,23 @@ namespace NLGUI
}
// Draw the background
if (_UserTexture || BgColor.A != 0)
if (BgColor.A > 0 || !_TextureId.empty())
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
if (_UserTexture)
uint8 CurrentAlpha = 255;
if (getParent ())
{
CRGBA col;
if (BgColor.A == 0 )
col = CRGBA(255,255,255,255);
else
col = BgColor;
CGroupTable *table = static_cast<CGroupTable*> (getParent ());
CurrentAlpha = table->CurrentAlpha;
}
bool flush = false;
if (CurrentAlpha > 0 && !_TextureId.empty())
{
CRGBA col = CRGBA::White;
col.A = CurrentAlpha;
sint32 oldSciX, oldSciY, oldSciW, oldSciH;
makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH);
@ -513,22 +519,25 @@ namespace NLGUI
}
restoreClip (oldSciX, oldSciY, oldSciW, oldSciH);
flush = true;
}
else
{
CRGBA finalColor;
finalColor.modulateFromColor (BgColor, CWidgetManager::getInstance()->getGlobalColor());
// Get the parent table
if (getParent ())
if (BgColor.A > 0)
{
CGroupTable *table = static_cast<CGroupTable*> (getParent ());
finalColor.A = (uint8) (((uint16) table->CurrentAlpha * (uint16) finalColor.A) >> 8);
}
CRGBA finalColor = BgColor;
if (_ModulateGlobalColor)
finalColor.modulateFromColor (finalColor, CWidgetManager::getInstance()->getGlobalColor());
finalColor.A = (uint8) (((uint16) CurrentAlpha * (uint16) finalColor.A) >> 8);
//nlinfo("Blank Texture");
if (finalColor.A > 0)
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal, _WReal, _HReal, 0, false, rVR.getBlankTextureId(), finalColor);
flush = true;
}
if (flush)
rVR.flush();
}
// Get the parent table
@ -536,14 +545,14 @@ namespace NLGUI
{
CGroupTable *table = static_cast<CGroupTable*> (getParent ());
if (table->Border) {
CRGBA lighter = blend(table->BorderColor, CRGBA::White, 0.5f);
CRGBA borderColorTL;
borderColorTL.modulateFromColor (lighter, CWidgetManager::getInstance()->getGlobalColor());
CRGBA borderColorTL = blend(table->BorderColor, CRGBA::White, 0.5f);
if (_ModulateGlobalColor)
borderColorTL.modulateFromColor (borderColorTL, CWidgetManager::getInstance()->getGlobalColor());
borderColorTL.A = (uint8) (((uint16) table->CurrentAlpha * (uint16) borderColorTL.A) >> 8);
CRGBA borderColorBR;
borderColorBR.modulateFromColor (table->BorderColor, CWidgetManager::getInstance()->getGlobalColor());
CRGBA borderColorBR = table->BorderColor;
if (_ModulateGlobalColor)
borderColorBR.modulateFromColor (borderColorBR, CWidgetManager::getInstance()->getGlobalColor());
borderColorBR.A = (uint8) (((uint16) table->CurrentAlpha * (uint16) borderColorBR.A) >> 8);
CViewRenderer &rVR = *CViewRenderer::getInstance();
@ -575,13 +584,10 @@ namespace NLGUI
{
if (TxName.empty() || TxName == "none")
{
_UserTexture = false;
nlinfo("Set no texture");
_TextureId.clear();
}
else
{
nlinfo("Set texture to cell : %s", TxName.c_str());
_UserTexture = true;
_TextureId.setTexture (TxName.c_str (), 0, 0, -1, -1, false);
updateTextureCoords();
@ -607,7 +613,7 @@ namespace NLGUI
// ----------------------------------------------------------------------------
void CGroupCell::updateTextureCoords()
{
if (_TextureId < 0) return;
if (_TextureId.empty()) return;
CViewRenderer &rVR = *CViewRenderer::getInstance();
rVR.getTextureSizeFromId (_TextureId, _TextureWReal, _TextureHReal);
@ -724,7 +730,7 @@ namespace NLGUI
{
if (TxName.empty() || TxName == "none")
{
_TextureId.setTexture(NULL);
_TextureId.clear();
}
else
{
@ -749,7 +755,7 @@ namespace NLGUI
// ----------------------------------------------------------------------------
void CGroupTable::updateTextureCoords()
{
if (_TextureId < 0) return;
if (_TextureId.empty()) return;
CViewRenderer &rVR = *CViewRenderer::getInstance();
rVR.getTextureSizeFromId (_TextureId, _TextureWReal, _TextureHReal);
@ -1410,13 +1416,30 @@ namespace NLGUI
if (!_Columns.empty() && !_Rows.empty())
{
bool flush = false;
CViewRenderer &rVR = *CViewRenderer::getInstance();
if (BgColor.A > 0)
{
CRGBA finalColor = BgColor;
if (_ModulateGlobalColor)
finalColor.modulateFromColor (finalColor, CWidgetManager::getInstance()->getGlobalColor());
finalColor.A = (uint8) (((uint16) CurrentAlpha * (uint16) finalColor.A) >> 8);
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal, _WReal, _HReal, 0, false, rVR.getBlankTextureId(), finalColor);
flush = true;
}
// Draw the background
if (_TextureId >= 0 && CurrentAlpha != 0)
if (CurrentAlpha > 0 && !_TextureId.empty())
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
sint32 oldSciX, oldSciY, oldSciW, oldSciH;
makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH);
CRGBA col = CRGBA::White;
col.A = CurrentAlpha;
if (_TextureScaled && !_TextureTiled)
{
rVR.drawRotFlipBitmap(_RenderLayer, _TextureXReal, _TextureYReal, _WReal, _HReal, 0, false, _TextureId, col);
@ -1428,53 +1451,25 @@ namespace NLGUI
else
rVR.drawRotFlipBitmapTiled(_RenderLayer, _TextureXReal, _TextureYReal, _WReal, _TextureHReal, 0, false, _TextureId, 0, col);
}
}
sint32 border = Border + CellSpacing;
if (border && BgColor.A)
{
CRGBA finalColor;
finalColor.modulateFromColor (BgColor, CWidgetManager::getInstance()->getGlobalColor());
finalColor.A = CurrentAlpha;
// Draw the top line
CViewRenderer &rVR = *CViewRenderer::getInstance();
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal-border+_HReal, _WReal, border, 0, false, rVR.getBlankTextureId(), finalColor);
// Draw the left line
sint32 insideHeight = std::max((sint32)0, (sint32)_HReal - (sint32)border);
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal, border, insideHeight, 0, false, rVR.getBlankTextureId(), finalColor);
// Draw the inside borders
if (CellSpacing)
{
uint i;
sint32 x, y;
for (i=0; i<_Cells.size(); i++)
{
CGroupCell *cell = _Cells[i];
x = cell->getXReal();
y = cell->getYReal() - CellSpacing;
// right
rVR.drawRotFlipBitmap (_RenderLayer, x + cell->getW(), y, CellSpacing, cell->getH() + CellSpacing, 0, false, rVR.getBlankTextureId(), finalColor);
// bottom
rVR.drawRotFlipBitmap (_RenderLayer, x, y, cell->getW(), CellSpacing, 0, false, rVR.getBlankTextureId(), finalColor);
}
restoreClip (oldSciX, oldSciY, oldSciW, oldSciH);
flush = true;
}
}
// flush background color and image
if (flush)
rVR.flush();
if (Border)
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
CRGBA borderColorTL;
CRGBA lighter = blend(BorderColor, CRGBA::White, 0.5f);
borderColorTL.modulateFromColor (lighter, CWidgetManager::getInstance()->getGlobalColor());
CRGBA borderColorTL = blend(BorderColor, CRGBA::White, 0.5f);
if (_ModulateGlobalColor)
borderColorTL.modulateFromColor (borderColorTL, CWidgetManager::getInstance()->getGlobalColor());
borderColorTL.A = CurrentAlpha;
CRGBA borderColorBR;
borderColorBR.modulateFromColor (BorderColor, CWidgetManager::getInstance()->getGlobalColor());
CRGBA borderColorBR = BorderColor;
if (_ModulateGlobalColor)
borderColorBR.modulateFromColor (borderColorBR, CWidgetManager::getInstance()->getGlobalColor());
borderColorBR.A = CurrentAlpha;
// beveled table border

Loading…
Cancel
Save