1
0
forked from 0ad/0ad

Added support for customized colors.

This was SVN commit r2547.
This commit is contained in:
Gee 2005-07-25 19:06:18 +00:00
parent b94c443037
commit b1ef166bf3
3 changed files with 106 additions and 5 deletions

View File

@ -950,6 +950,19 @@ void CGUI::DrawText(SGUIText &Text, const CColor &DefaultColor,
// -- GL
}
bool CGUI::GetPreDefinedColor(const CStr &name, CColor &Output)
{
if (m_PreDefinedColors.count(name) == 0)
{
return false;
}
else
{
Output = m_PreDefinedColors[name];
return true;
}
}
void CGUI::ReportParseError(const char *str, ...)
{
va_list argp;
@ -1118,6 +1131,11 @@ void CGUI::Xeromyces_ReadRootSetup(XMBElement Element, CXeromyces* pFile)
Xeromyces_ReadTooltip(child, pFile);
}
else
if (name == "color")
{
Xeromyces_ReadColor(child, pFile);
}
else
{
debug_warn("Invalid data - DTD shouldn't allow this");
}
@ -1461,10 +1479,9 @@ void CGUI::Xeromyces_ReadImage(XMBElement Element, CXeromyces* pFile, CGUISprite
// Image object we're adding
SGUIImage image;
// TODO Gee: (2004-08-30) This is not how to set defaults.
CStr DefaultTextureSize ("0 0 100% 100%");
image.m_TextureSize = CClientArea(DefaultTextureSize);
image.m_Size = CClientArea(DefaultTextureSize);
// Set defaults (or maybe do that in DTD?)
image.m_TextureSize = CClientArea("0 0 100% 100%");
image.m_Size = CClientArea("0 0 100% 100%");
// TODO Gee: Setup defaults here (or maybe they are in the SGUIImage ctor)
@ -1811,3 +1828,31 @@ void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile)
AddObject(object);
}
// Reads Custom Color
void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
{
// Read the color and stor in m_PreDefinedColors
XMBAttributeList attributes = Element.getAttributes();
//IGUIObject* object = new CTooltip;
CColor color;
CStr name = attributes.getNamedItem(pFile->getAttributeID("name"));
// Try parsing value
CStr value (Element.getText());
if (value.Length())
{
// Try setting color to value
if (!color.ParseString(value, 255.f))
{
ReportParseError("Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
}
else
{
// input color
m_PreDefinedColors[name] = color;
}
}
}

View File

@ -243,6 +243,12 @@ public:
*/
SGUIIcon GetIcon(const CStr &str) const { return m_Icons.find(str)->second; }
/**
* Get pre-defined color (if it exists)
* Returns false if it fails.
*/
bool GetPreDefinedColor(const CStr &name, CColor &Output);
private:
/**
* Updates the object pointers, needs to be called each
@ -334,6 +340,8 @@ private:
+-<scrollbar> (ReadScrollBar)
|
+-<icon> (ReadIcon)
|
+-<color> (ReadColor)
*/
//@{
@ -482,9 +490,31 @@ private:
* @see LoadXMLFile()
*/
void Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile);
/**
* Reads in the element <tooltip> (the XMBElement) and stores the
* result as an object with the name __tooltip_#.
*
* @param Element The Xeromyces object that represents
* the scrollbar-tag.
* @param pFile The Xeromyces object for the file being read
*
* @see LoadXMLFile()
*/
void Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile);
/**
* Reads in the element <color> (the XMBElement) and stores the
* result in m_PreDefinedColors
*
* @param Element The Xeromyces object that represents
* the scrollbar-tag.
* @param pFile The Xeromyces object for the file being read
*
* @see LoadXMLFile()
*/
void Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile);
//@}
private:
@ -520,8 +550,17 @@ private:
// TODO Gee: Used?
int16_t m_Errors;
// Tooltip
GUITooltip m_Tooltip;
/**
* This is a bank of custom colors, it is simply a look up table that
* will return a color object when someone inputs the name of that
* color. Of course the colors have to be declared in XML, there are
* no hard-coded values.
*/
std::map<CStr, CColor> m_PreDefinedColors;
//@}
//--------------------------------------------------------
/** @name Objects */

View File

@ -80,6 +80,15 @@ bool __ParseString<CClientArea>(const CStr& Value, CClientArea &Output)
template <>
bool GUI<int>::ParseColor(const CStr& Value, CColor &Output, float DefaultAlpha)
{
// First, check our database in g_GUI for pre-defined colors
// If we find anything, we'll ignore DefaultAlpha
#ifdef g_GUI
// If it fails, it won't do anything with Output
if (g_GUI.GetPreDefinedColor(Value, Output))
return true;
#endif // g_GUI
return Output.ParseString(Value, DefaultAlpha);
}
@ -87,6 +96,14 @@ bool GUI<int>::ParseColor(const CStr& Value, CColor &Output, float DefaultAlpha)
template <>
bool __ParseString<CColor>(const CStr& Value, CColor &Output)
{
// First, check our database in g_GUI for pre-defined colors
#ifdef g_GUI
// If it fails, it won't do anything with Output
if (g_GUI.GetPreDefinedColor(Value, Output))
return true;
#endif // g_GUI
return Output.ParseString(Value, 255.f);
}