Added: html progress element
--HG-- branch : develop
This commit is contained in:
parent
cb0d6c74f3
commit
f5424aac3e
4 changed files with 147 additions and 0 deletions
|
@ -502,6 +502,29 @@ namespace NLGUI
|
|||
float optimum;
|
||||
};
|
||||
|
||||
class HTMLProgressElement
|
||||
{
|
||||
public:
|
||||
HTMLProgressElement()
|
||||
: value(0.f), max(1.f)
|
||||
{}
|
||||
|
||||
// read attributes from html element
|
||||
void readValues(const CHtmlElement &elm);
|
||||
|
||||
// return value ratio to min-max
|
||||
float getValueRatio() const;
|
||||
|
||||
// return meter bar color
|
||||
NLMISC::CRGBA getBarColor(const CHtmlElement &elm, CCssStyle &style) const;
|
||||
|
||||
// return meter value bar color based value and optimum range
|
||||
NLMISC::CRGBA getValueColor(const CHtmlElement &elm, CCssStyle &style) const;
|
||||
|
||||
float value;
|
||||
float max;
|
||||
};
|
||||
|
||||
// A mode
|
||||
std::vector<bool> _A;
|
||||
inline bool getA() const
|
||||
|
@ -941,6 +964,7 @@ namespace NLGUI
|
|||
void htmlPend(const CHtmlElement &elm);
|
||||
void htmlPRE(const CHtmlElement &elm);
|
||||
void htmlPREend(const CHtmlElement &elm);
|
||||
void htmlPROGRESS(const CHtmlElement &elm);
|
||||
void htmlSCRIPT(const CHtmlElement &elm);
|
||||
void htmlSCRIPTend(const CHtmlElement &elm);
|
||||
void htmlSELECT(const CHtmlElement &elm);
|
||||
|
|
|
@ -1108,6 +1108,7 @@ namespace NLGUI
|
|||
case HTML_OPTION: htmlOPTION(elm); break;
|
||||
case HTML_P: htmlP(elm); break;
|
||||
case HTML_PRE: htmlPRE(elm); break;
|
||||
case HTML_PROGRESS: htmlPROGRESS(elm); break;
|
||||
case HTML_SCRIPT: htmlSCRIPT(elm); break;
|
||||
case HTML_SELECT: htmlSELECT(elm); break;
|
||||
case HTML_SMALL: renderPseudoElement(":before", elm); break;
|
||||
|
@ -4889,6 +4890,10 @@ namespace NLGUI
|
|||
css += "meter::-webkit-meter-optimum-value { background-color: rgb(80, 220, 80); }";
|
||||
css += "meter::-webkit-meter-suboptimum-value { background-color: rgb(220, 220, 80); }";
|
||||
css += "meter::-webkit-meter-even-less-good-value { background-color: rgb(220, 80, 80); }";
|
||||
// webkit pseudo elements
|
||||
css += "progress::-webkit-progress-bar, progress::-webkit-progress-value { background: none; }";
|
||||
css += "progress::-webkit-progress-bar { background-color: rgb(230, 230, 230); width: 10em; height: 1em; }";
|
||||
css += "progress::-webkit-progress-value { background-color: rgb(0, 100, 180);}";
|
||||
_Style.parseStylesheet(css);
|
||||
}
|
||||
|
||||
|
@ -5115,6 +5120,54 @@ namespace NLGUI
|
|||
return color;
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
void CGroupHTML::HTMLProgressElement::readValues(const CHtmlElement &elm)
|
||||
{
|
||||
if (!elm.hasAttribute("value") || !fromString(elm.getAttribute("value"), value))
|
||||
value = 0.f;
|
||||
if (!elm.hasAttribute("max") || !fromString(elm.getAttribute("max"), max))
|
||||
max = 1.f;
|
||||
|
||||
if (value > max)
|
||||
value = max;
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
float CGroupHTML::HTMLProgressElement::getValueRatio() const
|
||||
{
|
||||
if (max > 0.f)
|
||||
return value / max;
|
||||
return 0.f;
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
NLMISC::CRGBA CGroupHTML::HTMLProgressElement::getBarColor(const CHtmlElement &elm, CCssStyle &style) const
|
||||
{
|
||||
CRGBA color;
|
||||
|
||||
style.pushStyle();
|
||||
style.applyStyle(elm.getPseudo(":-webkit-progress-bar"));
|
||||
if (style.hasStyle("background-color"))
|
||||
color = style.Current.BackgroundColor;
|
||||
style.popStyle();
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
NLMISC::CRGBA CGroupHTML::HTMLProgressElement::getValueColor(const CHtmlElement &elm, CCssStyle &style) const
|
||||
{
|
||||
CRGBA color;
|
||||
|
||||
style.pushStyle();
|
||||
style.applyStyle(elm.getPseudo(":-webkit-progress-value"));
|
||||
if (style.hasStyle("background-color"))
|
||||
color = style.Current.BackgroundColor;
|
||||
style.popStyle();
|
||||
|
||||
return color;
|
||||
}
|
||||
|
||||
// ****************************************************************************
|
||||
void CGroupHTML::getCellsParameters(const CHtmlElement &elm, bool inherit)
|
||||
{
|
||||
|
@ -6316,6 +6369,50 @@ namespace NLGUI
|
|||
popIfNotEmpty(_PRE);
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CGroupHTML::htmlPROGRESS(const CHtmlElement &elm)
|
||||
{
|
||||
HTMLProgressElement progress;
|
||||
progress.readValues(elm);
|
||||
|
||||
std::string id = "progress";
|
||||
if (elm.hasAttribute("id"))
|
||||
id = elm.getAttribute("id");
|
||||
|
||||
// width: 10em, height: 1em
|
||||
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 border = _Style.Current.BorderWidth > -1 ? _Style.Current.BorderWidth : 0;
|
||||
|
||||
uint barw = (uint) (width * progress.getValueRatio());
|
||||
CRGBA bgColor = progress.getBarColor(elm, _Style);
|
||||
CRGBA valueColor = progress.getValueColor(elm, _Style);
|
||||
|
||||
typedef pair<string, string> TTmplParam;
|
||||
vector<TTmplParam> tmplParams;
|
||||
tmplParams.push_back(TTmplParam("id", id));
|
||||
tmplParams.push_back(TTmplParam("active", "true"));
|
||||
tmplParams.push_back(TTmplParam("w", toString(width)));
|
||||
tmplParams.push_back(TTmplParam("h", toString(height)));
|
||||
tmplParams.push_back(TTmplParam("border_x2", toString(border*2)));
|
||||
tmplParams.push_back(TTmplParam("bgtexture", "blank.tga"));
|
||||
tmplParams.push_back(TTmplParam("bgcolor", bgColor.toString()));
|
||||
tmplParams.push_back(TTmplParam("value_w", toString(barw)));
|
||||
tmplParams.push_back(TTmplParam("value_texture", "blank.tga"));
|
||||
tmplParams.push_back(TTmplParam("value_color", valueColor.toString()));
|
||||
|
||||
CInterfaceGroup *gr = CWidgetManager::getInstance()->getParser()->createGroupInstance("html_progress", getParagraph()->getId(), &tmplParams[0], (uint)tmplParams.size());
|
||||
if (gr)
|
||||
{
|
||||
renderPseudoElement(":before", elm);
|
||||
getParagraph()->addChild(gr);
|
||||
renderPseudoElement(":after", elm);
|
||||
|
||||
// ignore any inner elements
|
||||
_IgnoreChildElements = true;
|
||||
}
|
||||
}
|
||||
|
||||
// ***************************************************************************
|
||||
void CGroupHTML::htmlSCRIPT(const CHtmlElement &elm)
|
||||
{
|
||||
|
|
|
@ -1038,4 +1038,17 @@
|
|||
</group>
|
||||
</template>
|
||||
|
||||
<template name="html_progress" keep="true"
|
||||
id="meter" w="0" h="0" active="true" border_x2="0"
|
||||
bgtexture="blank.tga" bgcolor="0 0 0 255"
|
||||
value_w="0" value_texture="blank.tga" value_color="100 100 100 100"
|
||||
>
|
||||
<group id="#id" w="#w" h="#h" active="#active">
|
||||
<view type="bitmap" id="bg" posref="MM MM" sizeref="wh" scale="true" texture="#bgtexture" color="#bgcolor" />
|
||||
<group id="inner" posref="MM MM" sizeref="wh" w="-#border_x2" h="-#border_x2">
|
||||
<view type="bitmap" id="gauge" posref="ML ML" posparent="bg" sizeref="h" sizeparent="bg" w="#value_w" scale="true" texture="#value_texture" color="#value_color" />
|
||||
</group>
|
||||
</group>
|
||||
</template>
|
||||
|
||||
</interface_config>
|
||||
|
|
|
@ -7265,4 +7265,17 @@
|
|||
</group>
|
||||
</template>
|
||||
|
||||
<template name="html_progress" keep="true"
|
||||
id="meter" w="0" h="0" active="true" border_x2="0"
|
||||
bgtexture="blank.tga" bgcolor="0 0 0 255"
|
||||
value_w="0" value_texture="blank.tga" value_color="100 100 100 100"
|
||||
>
|
||||
<group id="#id" w="#w" h="#h" active="#active">
|
||||
<view type="bitmap" id="bg" posref="MM MM" sizeref="wh" scale="true" texture="#bgtexture" color="#bgcolor" />
|
||||
<group id="inner" posref="MM MM" sizeref="wh" w="-#border_x2" h="-#border_x2">
|
||||
<view type="bitmap" id="gauge" posref="ML ML" posparent="bg" sizeref="h" sizeparent="bg" w="#value_w" scale="true" texture="#value_texture" color="#value_color" />
|
||||
</group>
|
||||
</group>
|
||||
</template>
|
||||
|
||||
</interface_config>
|
||||
|
|
Loading…
Reference in a new issue