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++; styleStackIndex++;
_StyleStack.push_back(Current); _StyleStack.push_back(Current);
Current.GlobalColor = false;
Current.DisplayBlock = false; Current.DisplayBlock = false;
Current.Width=-1; Current.Width=-1;
Current.Height=-1; Current.Height=-1;

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

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

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

Loading…
Cancel
Save