Draw table background/border using css renderers

develop
Nimetu 3 years ago
parent 37eec8cd7f
commit e0d54f7897

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

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

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

Loading…
Cancel
Save