Draw table background/border using css renderers

develop
Nimetu 3 years ago
parent 37eec8cd7f
commit e0d54f7897

@ -31,6 +31,7 @@
namespace NLGUI
{
class CSSBorderRenderer;
class CSSBackgroundRenderer;
/**
* This group is used to simulate HTML cells.
@ -94,22 +95,10 @@ namespace NLGUI
// Memorize max width
sint32 WidthMax;
// The cell color
NLMISC::CRGBA BgColor;
CSSBorderRenderer* Border;
CSSBackgroundRenderer *Background;
uint32 PaddingTop, PaddingRight, PaddingBottom, PaddingLeft;
// Texture
CViewRenderer::CTextureId _TextureId;
bool _TextureTiled;
bool _TextureScaled;
// cached absolute coords for background texture
sint32 _TextureXReal;
sint32 _TextureYReal;
sint32 _TextureWReal;
sint32 _TextureHReal;
// Alignment
TAlign Align;
TVAlign VAlign;
@ -121,6 +110,7 @@ namespace NLGUI
// The cell is nowrap
bool NoWrap;
// deprecated background image
void setTexture(const std::string & TxName);
void setTextureTile(bool tiled);
void setTextureScale(bool scaled);
@ -134,8 +124,6 @@ namespace NLGUI
static bool getDebugUICell(){ return DebugUICell; }
private:
void updateTextureCoords();
void setEnclosedGroupDefaultParams();
static bool DebugUICell;
};
@ -164,18 +152,18 @@ namespace NLGUI
sint32 ForceWidthMin;
CSSBorderRenderer* Border;
CSSBackgroundRenderer *Background;
// Cell has 1px solid border when <table> has 'border' attribute with width > 0
bool CellBorder;
sint32 CellPadding;
sint32 CellSpacing;
// The table color
NLMISC::CRGBA BgColor;
uint8 CurrentAlpha;
bool ContinuousUpdate;
// deprecated background image
void setTexture(const std::string & TxName);
void setTextureTile(bool tiled);
void setTextureScale(bool scaled);
@ -201,18 +189,6 @@ namespace NLGUI
virtual bool parse (xmlNodePtr cur, CInterfaceGroup * parentGroup);
// Texture
CViewRenderer::CTextureId _TextureId;
bool _TextureTiled;
bool _TextureScaled;
// cached absolute coords for background texture
sint32 _TextureXReal;
sint32 _TextureYReal;
sint32 _TextureWReal;
sint32 _TextureHReal;
void updateTextureCoords();
// Content validated
bool _ContentValidated;

@ -5147,10 +5147,13 @@ namespace NLGUI
if (!_CellParams.empty() && inherit)
cellParams = _CellParams.back();
if (_Style.hasStyle("background-color"))
cellParams.BgColor = _Style.Current.Background.color;
else if (elm.hasNonEmptyAttribute("bgcolor"))
scanHTMLColor(elm.getAttribute("bgcolor").c_str(), cellParams.BgColor);
if (!_Style.hasStyle("background-color") && elm.hasNonEmptyAttribute("bgcolor"))
{
CRGBA c;
if (scanHTMLColor(elm.getAttribute("bgcolor").c_str(), c))
_Style.Current.Background.color = c;
}
cellParams.BgColor = _Style.Current.Background.color;
if (elm.hasAttribute("nowrap") || _Style.Current.WhiteSpace == "nowrap")
cellParams.NoWrap = true;
@ -6109,7 +6112,7 @@ namespace NLGUI
uint32 width = _Style.Current.Width > -1 ? _Style.Current.Width : _Style.Current.FontSize * 5;
uint32 height = _Style.Current.Height > -1 ? _Style.Current.Height : _Style.Current.FontSize;
// FIXME: only using border-top
uint32 border = _Style.Current.BorderTopWidth > -1 ? _Style.Current.BorderTopWidth : 0;
uint32 border = _Style.Current.Border.Top.Width.getValue() > -1 ? _Style.Current.Border.Top.Width.getValue() : 0;
uint barw = (uint) (width * meter.getValueRatio());
CRGBA bgColor = meter.getBarColor(elm, _Style);
@ -6331,7 +6334,7 @@ namespace NLGUI
uint32 width = _Style.Current.Width > -1 ? _Style.Current.Width : _Style.Current.FontSize * 10;
uint32 height = _Style.Current.Height > -1 ? _Style.Current.Height : _Style.Current.FontSize;
// FIXME: only using border-top
uint32 border = _Style.Current.BorderTopWidth > -1 ? _Style.Current.BorderTopWidth : 0;
uint32 border = _Style.Current.Border.Top.Width.getValue() > -1 ? _Style.Current.Border.Top.Width.getValue() : 0;
uint barw = (uint) (width * progress.getValueRatio());
CRGBA bgColor = progress.getBarColor(elm, _Style);
@ -6459,7 +6462,7 @@ namespace NLGUI
getCellsParameters(elm, false);
CGroupTable *table = new CGroupTable(TCtorParam());
table->BgColor = _CellParams.back().BgColor;
if (elm.hasNonEmptyAttribute("id"))
table->setId(getCurrentGroup()->getId() + ":" + elm.getAttribute("id"));
else
@ -6502,11 +6505,17 @@ namespace NLGUI
// border from css or from attribute
{
uint32 borderWidth = 0;
CRGBA borderColor = CRGBA::Transparent;
CSSRect<CSSBorder> border;
border.Top.Color = _Style.Current.TextColor;
border.Right.Color = _Style.Current.TextColor;
border.Bottom.Color = _Style.Current.TextColor;
border.Left.Color = _Style.Current.TextColor;
if (elm.hasAttribute("border"))
{
uint32 borderWidth = 0;
CRGBA borderColor = CRGBA::Transparent;
std::string s = elm.getAttribute("border");
if (s.empty())
borderWidth = 1;
@ -6519,48 +6528,36 @@ namespace NLGUI
borderColor = CRGBA(128, 128, 128, 255);
table->CellBorder = (borderWidth > 0);
table->Border->setWidth(borderWidth, borderWidth, borderWidth, borderWidth);
table->Border->setColor(borderColor, borderColor, borderColor, borderColor);
table->Border->setStyle(CSS_LINE_STYLE_OUTSET, CSS_LINE_STYLE_OUTSET, CSS_LINE_STYLE_OUTSET, CSS_LINE_STYLE_OUTSET);
}
else
{
table->CellBorder = false;
border.Top.set(borderWidth, CSS_LINE_STYLE_OUTSET, borderColor);
border.Right.set(borderWidth, CSS_LINE_STYLE_OUTSET, borderColor);
border.Bottom.set(borderWidth, CSS_LINE_STYLE_OUTSET, borderColor);
border.Left.set(borderWidth, CSS_LINE_STYLE_OUTSET, borderColor);
}
if (_Style.hasStyle("border-top-width")) table->Border->TopWidth = _Style.Current.BorderTopWidth;
if (_Style.hasStyle("border-right-width")) table->Border->RightWidth = _Style.Current.BorderRightWidth;
if (_Style.hasStyle("border-bottom-width")) table->Border->BottomWidth = _Style.Current.BorderBottomWidth;
if (_Style.hasStyle("border-left-width")) table->Border->LeftWidth = _Style.Current.BorderLeftWidth;
if (_Style.hasStyle("border-top-width")) border.Top.Width = _Style.Current.Border.Top.Width;
if (_Style.hasStyle("border-right-width")) border.Right.Width = _Style.Current.Border.Right.Width;
if (_Style.hasStyle("border-bottom-width")) border.Bottom.Width = _Style.Current.Border.Bottom.Width;
if (_Style.hasStyle("border-left-width")) border.Left.Width = _Style.Current.Border.Left.Width;
if (_Style.hasStyle("border-top-color")) table->Border->TopColor = _Style.Current.BorderTopColor;
if (_Style.hasStyle("border-right-color")) table->Border->RightColor = _Style.Current.BorderRightColor;
if (_Style.hasStyle("border-bottom-color")) table->Border->BottomColor = _Style.Current.BorderBottomColor;
if (_Style.hasStyle("border-left-color")) table->Border->LeftColor = _Style.Current.BorderLeftColor;
if (_Style.hasStyle("border-top-color")) border.Top.Color = _Style.Current.Border.Top.Color;
if (_Style.hasStyle("border-right-color")) border.Right.Color = _Style.Current.Border.Right.Color;
if (_Style.hasStyle("border-bottom-color")) border.Bottom.Color = _Style.Current.Border.Bottom.Color;
if (_Style.hasStyle("border-left-color")) border.Left.Color = _Style.Current.Border.Left.Color;
if (_Style.hasStyle("border-top-style")) table->Border->TopStyle = _Style.Current.BorderTopStyle;
if (_Style.hasStyle("border-right-style")) table->Border->RightStyle = _Style.Current.BorderRightStyle;
if (_Style.hasStyle("border-bottom-style")) table->Border->BottomStyle = _Style.Current.BorderBottomStyle;
if (_Style.hasStyle("border-left-style")) table->Border->LeftStyle = _Style.Current.BorderLeftStyle;
}
if (_Style.hasStyle("border-top-style")) border.Top.Style = _Style.Current.Border.Top.Style;
if (_Style.hasStyle("border-right-style")) border.Right.Style = _Style.Current.Border.Right.Style;
if (_Style.hasStyle("border-bottom-style")) border.Bottom.Style = _Style.Current.Border.Bottom.Style;
if (_Style.hasStyle("border-left-style")) border.Left.Style = _Style.Current.Border.Left.Style;
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, CStyleParams(), NormalImage, "");
}
else
{
// will be set in addImageDownload if background-image exists
table->setModulateGlobalColor(_Style.Current.GlobalColor);
table->Border->setBorder(border);
table->Border->setFontSize(_Style.Root.FontSize, _Style.Current.FontSize);
table->Border->setViewport(getList()->getParentPos() ? getList()->getParentPos() : this);
}
setupBackground(table->Background);
table->setModulateGlobalColor(_Style.Current.GlobalColor);
table->setMarginLeft(getIndent());
addHtmlGroup (table, 0);
@ -6597,10 +6594,10 @@ namespace NLGUI
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 (rowColor.A > 0 && _Style.Current.Background.color.A < 255)
{
if (_CellParams.back().BgColor.A < 255)
_CellParams.back().BgColor.blendFromui(rowColor, _CellParams.back().BgColor, _CellParams.back().BgColor.A);
_Style.Current.Background.color.blendFromui(rowColor,
_Style.Current.Background.color, _Style.Current.Background.color.A);
}
if (elm.ID == HTML_TH)
@ -6633,29 +6630,14 @@ namespace NLGUI
// inner cell content
_Cells.back()->Group->setId(_Cells.back()->getId() + ":CELL");
if (_Style.checkStyle("background-repeat", "repeat"))
_Cells.back()->setTextureTile(true);
if (_Style.checkStyle("background-size", "100%"))
_Cells.back()->setTextureScale(true);
if (_Style.hasStyle("background-image"))
{
string image = _Style.getStyle("background-image");
addImageDownload(image, _Cells.back(), CStyleParams(), NormalImage, "");
}
else
{
// will be set in addImageDownload if background-image is set
_Cells.back()->setModulateGlobalColor(_Style.Current.GlobalColor);
}
setupBackground(_Cells.back()->Background);
_Cells.back()->setModulateGlobalColor(_Style.Current.GlobalColor);
if (elm.hasNonEmptyAttribute("colspan"))
fromString(elm.getAttribute("colspan"), _Cells.back()->ColSpan);
if (elm.hasNonEmptyAttribute("rowspan"))
fromString(elm.getAttribute("rowspan"), _Cells.back()->RowSpan);
_Cells.back()->BgColor = _CellParams.back().BgColor;
_Cells.back()->Align = _CellParams.back().Align;
_Cells.back()->VAlign = _CellParams.back().VAlign;
_Cells.back()->LeftMargin = _CellParams.back().LeftMargin;
@ -6685,32 +6667,35 @@ namespace NLGUI
_Cells.back()->NewLine = getTR();
// border from <table border="1">
if (table->CellBorder)
{
_Cells.back()->Border->setWidth(1, 1, 1, 1);
_Cells.back()->Border->setColor(table->Border->TopColor, table->Border->RightColor, table->Border->BottomColor, table->Border->LeftColor);
_Cells.back()->Border->setStyle(CSS_LINE_STYLE_INSET, CSS_LINE_STYLE_INSET, CSS_LINE_STYLE_INSET, CSS_LINE_STYLE_INSET);
}
CSSRect<CSSBorder> border;
border.Top.set( table->CellBorder ? 1 : 0, CSS_LINE_STYLE_INSET, _Style.Current.TextColor);
border.Right.set( table->CellBorder ? 1 : 0, CSS_LINE_STYLE_INSET, _Style.Current.TextColor);
border.Bottom.set(table->CellBorder ? 1 : 0, CSS_LINE_STYLE_INSET, _Style.Current.TextColor);
border.Left.set( table->CellBorder ? 1 : 0, CSS_LINE_STYLE_INSET, _Style.Current.TextColor);
if (_Style.hasStyle("border-top-width")) border.Top.Width = _Style.Current.Border.Top.Width;
if (_Style.hasStyle("border-right-width")) border.Right.Width = _Style.Current.Border.Right.Width;
if (_Style.hasStyle("border-bottom-width")) border.Bottom.Width = _Style.Current.Border.Bottom.Width;
if (_Style.hasStyle("border-left-width")) border.Left.Width = _Style.Current.Border.Left.Width;
if (_Style.hasStyle("border-top-width")) _Cells.back()->Border->TopWidth = _Style.Current.BorderTopWidth;
if (_Style.hasStyle("border-right-width")) _Cells.back()->Border->RightWidth = _Style.Current.BorderRightWidth;
if (_Style.hasStyle("border-bottom-width")) _Cells.back()->Border->BottomWidth = _Style.Current.BorderBottomWidth;
if (_Style.hasStyle("border-left-width")) _Cells.back()->Border->LeftWidth = _Style.Current.BorderLeftWidth;
if (_Style.hasStyle("border-top-color")) border.Top.Color = _Style.Current.Border.Top.Color;
if (_Style.hasStyle("border-right-color")) border.Right.Color = _Style.Current.Border.Right.Color;
if (_Style.hasStyle("border-bottom-color")) border.Bottom.Color = _Style.Current.Border.Bottom.Color;
if (_Style.hasStyle("border-left-color")) border.Left.Color = _Style.Current.Border.Left.Color;
if (_Style.hasStyle("border-top-color")) _Cells.back()->Border->TopColor = _Style.Current.BorderTopColor;
if (_Style.hasStyle("border-right-color")) _Cells.back()->Border->RightColor = _Style.Current.BorderRightColor;
if (_Style.hasStyle("border-bottom-color")) _Cells.back()->Border->BottomColor = _Style.Current.BorderBottomColor;
if (_Style.hasStyle("border-left-color")) _Cells.back()->Border->LeftColor = _Style.Current.BorderLeftColor;
if (_Style.hasStyle("border-top-style")) border.Top.Style = _Style.Current.Border.Top.Style;
if (_Style.hasStyle("border-right-style")) border.Right.Style = _Style.Current.Border.Right.Style;
if (_Style.hasStyle("border-bottom-style")) border.Bottom.Style = _Style.Current.Border.Bottom.Style;
if (_Style.hasStyle("border-left-style")) border.Left.Style = _Style.Current.Border.Left.Style;
if (_Style.hasStyle("border-top-style")) _Cells.back()->Border->TopStyle = _Style.Current.BorderTopStyle;
if (_Style.hasStyle("border-right-style")) _Cells.back()->Border->RightStyle = _Style.Current.BorderRightStyle;
if (_Style.hasStyle("border-bottom-style")) _Cells.back()->Border->BottomStyle = _Style.Current.BorderBottomStyle;
if (_Style.hasStyle("border-left-style")) _Cells.back()->Border->LeftStyle = _Style.Current.BorderLeftStyle;
_Cells.back()->Border->setBorder(border);
_Cells.back()->Border->setFontSize(_Style.Root.FontSize, _Style.Current.FontSize);
_Cells.back()->Border->setViewport(getList()->getParentPos() ? getList()->getParentPos() : this);
// padding from <table cellpadding="1">
if (table->CellPadding)
{
// FIXME: padding is ignored by vertical align
_Cells.back()->PaddingTop = table->CellPadding;
_Cells.back()->PaddingRight = table->CellPadding;
_Cells.back()->PaddingBottom = table->CellPadding;

@ -29,6 +29,7 @@
#include "nel/misc/i18n.h"
#include "nel/misc/xml_auto_ptr.h"
#include "nel/gui/css_border_renderer.h"
#include "nel/gui/css_background_renderer.h"
using namespace std;
using namespace NLMISC;
@ -44,9 +45,7 @@ namespace NLGUI
// ----------------------------------------------------------------------------
CGroupCell::CGroupCell(const TCtorParam &param)
: CInterfaceGroup(param),
BgColor (0,0,0,0)
: CInterfaceGroup(param)
{
NewLine = false;
TableRatio = 0.f;
@ -58,6 +57,7 @@ namespace NLGUI
Group = new CInterfaceGroup(CViewBase::TCtorParam());
// TODO: only initialize if border is set
Border = new CSSBorderRenderer();
Background = new CSSBackgroundRenderer();
PaddingTop = PaddingRight = PaddingBottom = PaddingLeft = 0;
Align = Left;
VAlign = Middle;
@ -66,12 +66,6 @@ namespace NLGUI
IgnoreMaxWidth = false;
IgnoreMinWidth = false;
AddChildW = false;
_TextureTiled = false;
_TextureScaled = false;
_TextureXReal = 0;
_TextureYReal = 0;
_TextureWReal = 0;
_TextureHReal = 0;
setEnclosedGroupDefaultParams();
addGroup (Group);
}
@ -84,6 +78,11 @@ namespace NLGUI
delete Border;
Border = NULL;
}
if (Background)
{
delete Background;
Background = NULL;
}
}
// ----------------------------------------------------------------------------
@ -151,7 +150,9 @@ namespace NLGUI
else
if( name == "bgcolor" )
{
return toString( BgColor );
if (Background)
return toString( Background->getColor() );
return toString(CRGBA::Transparent);
}
else
if( name == "width" )
@ -233,9 +234,12 @@ namespace NLGUI
else
if( name == "bgcolor" )
{
if (!Background)
Background = new CSSBackgroundRenderer();
CRGBA c;
if( fromString( value, c ) )
BgColor = c;
Background->setColor(c);
return;
}
else
@ -342,7 +346,8 @@ namespace NLGUI
xmlSetProp( node, BAD_CAST "valign", BAD_CAST "" );
xmlSetProp( node, BAD_CAST "left_margin", BAD_CAST toString( LeftMargin ).c_str() );
xmlSetProp( node, BAD_CAST "nowrap", BAD_CAST toString( NoWrap ).c_str() );
xmlSetProp( node, BAD_CAST "bgcolor", BAD_CAST toString( BgColor ).c_str() );
if (Background)
xmlSetProp( node, BAD_CAST "bgcolor", BAD_CAST toString( Background->getColor() ).c_str() );
if( WidthWanted != 0 )
xmlSetProp( node, BAD_CAST "width", BAD_CAST toString( WidthWanted ).c_str() );
@ -435,7 +440,9 @@ namespace NLGUI
ptr = (char*) xmlGetProp( cur, (xmlChar*)"bgcolor" );
if (ptr)
{
BgColor = convertColor(ptr);
if (!Background)
Background = new CSSBackgroundRenderer();
Background->setColor(convertColor(ptr));
}
//
ptr = (char*) xmlGetProp( cur, (xmlChar*)"width" );
@ -501,76 +508,39 @@ namespace NLGUI
rVR.drawRotFlipBitmap (_RenderLayer, _XReal+_WReal-1, _YReal, 1, _HReal, 0, false, rVR.getBlankTextureId(), CRGBA(0,255,255,255) );
}
uint8 CurrentAlpha = 255;
CGroupTable *table = NULL;
if (getParent ())
{
table = static_cast<CGroupTable*> (getParent ());
CurrentAlpha = table->CurrentAlpha;
}
// Draw the background
if (BgColor.A > 0 || !_TextureId.empty())
{
CViewRenderer &rVR = *CViewRenderer::getInstance();
// flush draw queue to force correct draw order for color+image
// flush draw queue to force correct draw order
rVR.flush();
bool flush = false;
if (BgColor.A > 0)
{
CRGBA finalColor = BgColor;
if (_ModulateGlobalColor)
finalColor.modulateFromColor (finalColor, CWidgetManager::getInstance()->getGlobalColor());
finalColor.A = (uint8) (((uint16) CurrentAlpha * (uint16) finalColor.A) >> 8);
if (finalColor.A > 0)
rVR.drawRotFlipBitmap (_RenderLayer, _XReal, _YReal, _WReal, _HReal, 0, false, rVR.getBlankTextureId(), finalColor);
flush = true;
}
if (CurrentAlpha > 0 && !_TextureId.empty())
if (Background)
{
CRGBA col = CRGBA::White;
col.A = CurrentAlpha;
sint32 oldSciX, oldSciY, oldSciW, oldSciH;
makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH);
if (_TextureScaled && !_TextureTiled)
uint8 CurrentAlpha = 255;
CGroupTable *table = NULL;
if (getParent ())
{
rVR.drawRotFlipBitmap(_RenderLayer, _TextureXReal, _TextureYReal, _WReal, _HReal, 0, false, _TextureId, col);
table = static_cast<CGroupTable*> (getParent ());
CurrentAlpha = table->CurrentAlpha;
}
else
if (CurrentAlpha > 0)
{
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);
Background->CurrentAlpha = CurrentAlpha;
Background->setModulateGlobalColor(_ModulateGlobalColor);
Background->draw();
rVR.flush();
}
restoreClip (oldSciX, oldSciY, oldSciW, oldSciH);
flush = true;
}
if (flush)
rVR.flush();
}
if (Border)
{
// TODO: monitor these in checkCoords and update when changed
uint8 contentAlpha = CWidgetManager::getInstance()->getGlobalColorForContent().A;
if (contentAlpha > 0)
if (Border)
{
Border->CurrentAlpha = contentAlpha;
Border->setRenderLayer(_RenderLayer);
Border->setModulateGlobalColor(_ModulateGlobalColor);
Border->draw();
Border->CurrentAlpha = CWidgetManager::getInstance()->getGlobalColorForContent().A;
if (Border->CurrentAlpha > 0)
{
Border->setRenderLayer(_RenderLayer);
Border->setModulateGlobalColor(_ModulateGlobalColor);
Border->draw();
rVR.flush();
}
}
}
@ -599,62 +569,35 @@ namespace NLGUI
// ----------------------------------------------------------------------------
void CGroupCell::setTexture(const std::string & TxName)
{
if (TxName.empty() || TxName == "none")
{
_TextureId.clear();
}
else
{
_TextureId.setTexture (TxName.c_str (), 0, 0, -1, -1, false);
updateTextureCoords();
}
if (Background)
Background->setImage(TxName);
}
// ----------------------------------------------------------------------------
void CGroupCell::setTextureTile(bool tiled)
{
_TextureTiled = tiled;
if (Background)
Background->setImageRepeat(tiled);
}
// ----------------------------------------------------------------------------
void CGroupCell::setTextureScale(bool scaled)
{
_TextureScaled = scaled;
}
// ----------------------------------------------------------------------------
void CGroupCell::updateTextureCoords()
{
if (_TextureId.empty()) 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;
}
if (Background)
Background->setImageCover(scaled);
}
// ----------------------------------------------------------------------------
void CGroupCell::updateCoords()
{
CInterfaceGroup::updateCoords();
updateTextureCoords();
}
// ----------------------------------------------------------------------------
NLMISC_REGISTER_OBJECT(CViewBase, CGroupTable, std::string, "table");
CGroupTable::CGroupTable(const TCtorParam &param)
: CInterfaceGroup(param),
BgColor(0,0,0,255)
: CInterfaceGroup(param)
{
_ContentValidated = false;
TableRatio = 0.f;
@ -662,18 +605,12 @@ namespace NLGUI
// TODO: only initialize when needed
Border = new CSSBorderRenderer();
Background = new CSSBackgroundRenderer();
CellBorder = false;
CellPadding=1;
CellSpacing=2;
ContinuousUpdate = false;
_TextureTiled = false;
_TextureScaled = false;
_TextureXReal = 0;
_TextureYReal = 0;
_TextureWReal = 0;
_TextureHReal = 0;
}
// ----------------------------------------------------------------------------
@ -741,6 +678,12 @@ namespace NLGUI
Border = NULL;
}
if (Background)
{
delete Background;
Background = NULL;
}
/* uint i;
for (i=0; i<_Cells.size(); i++)
delete _Cells[i];
@ -750,46 +693,22 @@ namespace NLGUI
// ----------------------------------------------------------------------------
void CGroupTable::setTexture(const std::string & TxName)
{
if (TxName.empty() || TxName == "none")
{
_TextureId.clear();
}
else
{
_TextureId.setTexture (TxName.c_str (), 0, 0, -1, -1, false);
updateTextureCoords();
}
if (Background)
Background->setImage(TxName);
}
// ----------------------------------------------------------------------------
void CGroupTable::setTextureTile(bool tiled)
{
_TextureTiled = tiled;
if (Background)
Background->setImageRepeat(tiled);
}
// ----------------------------------------------------------------------------
void CGroupTable::setTextureScale(bool scaled)
{
_TextureScaled = scaled;
}
// ----------------------------------------------------------------------------
void CGroupTable::updateTextureCoords()
{
if (_TextureId.empty()) 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;
}
if (Background)
Background->setImageCover(scaled);
}
// ----------------------------------------------------------------------------
@ -1303,14 +1222,35 @@ namespace NLGUI
CInterfaceGroup::updateCoords();
updateTextureCoords();
// update borders if present
if (Border)
{
Border->setRect(_XReal + _MarginLeft, _YReal, _WReal, _HReal);
}
if (Background)
{
sint32 l = _XReal + _MarginLeft;
sint32 b = _YReal;
sint32 w = _WReal;
sint32 h = _HReal;
Background->setBorderArea(l, b, w, h);
if (Border) {
l += Border->getLeftWidth();
b += Border->getBottomWidth();
w -= Border->getLeftRightWidth();
h -= Border->getTopBottomWidth();
}
Background->setPaddingArea(l, b, w, h);
// TODO: padding
//CSSRect<sint32> Padding;
//l += Padding.Left;
//b += Padding.Bottom;
//w -= Padding.Left - Padding.Right;
//h -= Padding.Top - Padding.Bottom;
Background->setContentArea(l, b, w, h);
}
// update cell borders if present
for (uint32 i=0; i<_Cells.size(); i++)
{
@ -1318,6 +1258,28 @@ namespace NLGUI
{
_Cells[i]->Border->setRect(_Cells[i]->_XReal, _Cells[i]->_YReal, _Cells[i]->_WReal, _Cells[i]->_HReal);
}
if (_Cells[i]->Background)
{
sint32 l = _Cells[i]->_XReal;
sint32 b = _Cells[i]->_YReal;
sint32 w = _Cells[i]->_WReal;
sint32 h = _Cells[i]->_HReal;
_Cells[i]->Background->setBorderArea(l, b, w, h);
if (_Cells[i]->Border) {
l += Border->getLeftWidth();
b += Border->getBottomWidth();
w -= Border->getLeftRightWidth();
h -= Border->getTopBottomWidth();
}
_Cells[i]->Background->setPaddingArea(l, b, w, h);
// TODO: padding
//CSSRect<sint32> Padding;
//l += Padding.Left;
//b += Padding.Bottom;
//w -= Padding.Left - Padding.Right;
//h -= Padding.Top - Padding.Bottom;
_Cells[i]->Background->setContentArea(l, b, w, h);
}
}
// Validated
@ -1506,60 +1468,24 @@ namespace NLGUI
bool flush = false;
CViewRenderer &rVR = *CViewRenderer::getInstance();
// flush draw queue to force correct draw order for color+image
if (BgColor.A >0 || !_TextureId.empty())
rVR.flush();
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 (CurrentAlpha > 0 && !_TextureId.empty())
// TODO: monitor these in checkCoords and update when changed
uint8 contentAlpha = CWidgetManager::getInstance()->getGlobalColorForContent().A;
if (contentAlpha > 0)
{
sint32 oldSciX, oldSciY, oldSciW, oldSciH;
makeNewClip (oldSciX, oldSciY, oldSciW, oldSciH);
CRGBA col = CRGBA::White;
col.A = CurrentAlpha;
if (_TextureScaled && !_TextureTiled)
if (Background)
{
rVR.drawRotFlipBitmap(_RenderLayer, _TextureXReal, _TextureYReal, _WReal, _HReal, 0, false, _TextureId, col);
Background->CurrentAlpha = CurrentAlpha;
Background->setModulateGlobalColor(_ModulateGlobalColor);
Background->draw();
rVR.flush();
}
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);
}
restoreClip (oldSciX, oldSciY, oldSciW, oldSciH);
flush = true;
}
if (flush)
rVR.flush();
if (Border)
{
// TODO: monitor these in checkCoords and update when changed
uint8 contentAlpha = CWidgetManager::getInstance()->getGlobalColorForContent().A;
if (contentAlpha > 0)
if (Border)
{
Border->CurrentAlpha = CurrentAlpha;
Border->setRenderLayer(_RenderLayer);
Border->setModulateGlobalColor(_ModulateGlobalColor);
Border->draw();
rVR.flush();
}
}
}
@ -1575,14 +1501,14 @@ namespace NLGUI
if( name == "border" )
{
if (Border)
return toString( Border->TopWidth );
return toString( Border->getTopWidth() );
return "0";
}
else
if( name == "bordercolor" )
{
if (Border)
return toString( Border->TopColor );
return toString( Border->getTopColor() );
return toString(CRGBA::Transparent);
}
else
@ -1598,7 +1524,9 @@ namespace NLGUI
else
if( name == "bgcolor" )
{
return toString( BgColor );
if (Background)
return toString( Background->getColor() );
return toString( CRGBA::Transparent );
}
else
if( name == "width" )
@ -1621,10 +1549,7 @@ namespace NLGUI
{
if (!Border)
Border = new CSSBorderRenderer();
Border->TopWidth = i;
Border->RightWidth = i;
Border->BottomWidth = i;
Border->LeftWidth = i;
Border->setWidth(i);
}
return;
}
@ -1636,10 +1561,7 @@ namespace NLGUI
{
if (!Border)
Border = new CSSBorderRenderer();
Border->TopColor = c;
Border->RightColor = c;
Border->BottomColor = c;
Border->LeftColor = c;
Border->setColor(c);
}
return;
}
@ -1662,9 +1584,12 @@ namespace NLGUI
else
if( name == "bgcolor" )
{
if (!Background)
Background = new CSSBackgroundRenderer();
CRGBA c;
if( fromString( value, c ) )
BgColor = c;
Background->setColor(c);
return;
}
else
@ -1687,12 +1612,16 @@ namespace NLGUI
xmlSetProp( node, BAD_CAST "type", BAD_CAST "table" );
if (Border)
{
xmlSetProp( node, BAD_CAST "border", BAD_CAST toString( Border->TopWidth ).c_str() );
xmlSetProp( node, BAD_CAST "bordercolor", BAD_CAST toString( Border->TopColor ).c_str() );
xmlSetProp( node, BAD_CAST "border", BAD_CAST toString( Border->getTopWidth() ).c_str() );
xmlSetProp( node, BAD_CAST "bordercolor", BAD_CAST toString( Border->getTopColor() ).c_str() );
}
xmlSetProp( node, BAD_CAST "cellpadding", BAD_CAST toString( CellPadding ).c_str() );
xmlSetProp( node, BAD_CAST "cellspacing", BAD_CAST toString( CellSpacing ).c_str() );
xmlSetProp( node, BAD_CAST "bgcolor", BAD_CAST toString( BgColor ).c_str() );
if (Background)
{
xmlSetProp( node, BAD_CAST "bgcolor", BAD_CAST toString( Background->getColor() ).c_str() );
// TODO: Texture
}
if( ForceWidthMin != 0 )
xmlSetProp( node, BAD_CAST "width", BAD_CAST toString( ForceWidthMin ).c_str() );
@ -1715,7 +1644,7 @@ namespace NLGUI
fromString((const char*)ptr, w);
if (!Border)
Border = new CSSBorderRenderer();
Border->setWidth(w, w, w, w);
Border->setWidth(w);
}
//
ptr = (char*) xmlGetProp( cur, (xmlChar*)"bordercolor" );
@ -1724,7 +1653,7 @@ namespace NLGUI
CRGBA c = convertColor((const char*)ptr);
if (!Border)
Border = new CSSBorderRenderer();
Border->setColor(c, c, c, c);
Border->setColor(c);
}
//
ptr = (char*) xmlGetProp( cur, (xmlChar*)"cellpadding" );
@ -1742,7 +1671,10 @@ namespace NLGUI
ptr = (char*) xmlGetProp( cur, (xmlChar*)"bgcolor" );
if (ptr)
{
BgColor = convertColor((const char *) ptr);
if (!Background)
Background = new CSSBackgroundRenderer();
Background->setColor(convertColor((const char *) ptr));
}
//
ptr = (char*) xmlGetProp( cur, (xmlChar*)"width" );

Loading…
Cancel
Save