2#include <core/SGradient.h>
19static int GradientItemCmp(
const void *_p1,
const void *_p2)
21 const GradientItem *p1 = (
const GradientItem *)_p1;
22 const GradientItem *p2 = (
const GradientItem *)_p2;
23 float diff = p1->pos - p2->pos;
32static BOOL ParseGradientColors(
const SStringW &value, SArray<GradientItem> &output)
35 SplitString(value,
',', lstInfo);
37 for (UINT i = 0; i < lstInfo.GetCount(); i++)
39 SStringWList lstColorInfo;
40 SplitString(lstInfo[i],
'|', lstColorInfo);
41 GradientItem gradient;
42 if (lstColorInfo.GetCount() == 2)
44 gradient.cr = GETCOLOR(lstColorInfo[0]);
45 gradient.pos = (float)_wtof(lstColorInfo[1]);
49 gradient.cr = GETCOLOR(lstColorInfo[0]);
50 gradient.pos = 1.0f * i / (lstInfo.GetCount() - 1);
54 qsort(output.GetData(), output.GetCount(),
sizeof(GradientItem), GradientItemCmp);
55 if (output.GetCount() < 2)
58 output[output.GetCount() - 1].pos = 1.0f;
65 return ParseGradientColors(value,
m_arrGradient) ? S_FALSE : E_INVALIDARG;
86 GradientItem gradient;
89 if (gradient.pos < pos || gradient.pos < 0.f || gradient.pos > 1.0f)
91 SSLOGW() <<
"invalid gradient item pos. pos must between 0 and 1";
104 SSLOGW() <<
"gradient color table is empty";
const GradientItem * GetGradientData() SCONST OVERRIDE
Gets the gradient data.
int GetGradientLength() SCONST OVERRIDE
Gets the length of the gradient.
SArray< GradientItem > m_arrGradient
HRESULT OnAttrColors(const SStringW &value, BOOL bLoading)
Handles the "colors" attribute.
int LoadColorTable(IXmlNode *xmlNode)
Loads the color table from an XML node.
void OnInitFinished(IXmlNode *pNode) OVERRIDE
Initializes the object after loading from XML.
A class representing an ASCII string.
float as_float(float def=0) const
Converts the attribute value to a float.
const wchar_t * as_string(const wchar_t *def=L"") const
Gets the attribute value as a string.
Class representing an XML node.
SXmlNode next_sibling() const
Gets the next sibling node in the children list of the parent node.
SXmlAttr attribute(const wchar_t *name, bool bCaseSensitive=false) const
Gets the attribute with the specified name.
IXmlNode * Child(const wchar_t *name, BOOL bCaseSensitive) SCONST PURE
Gets a child node by name.