本文整理汇总了C++中XMBElement::GetAttributes方法的典型用法代码示例。如果您正苦于以下问题:C++ XMBElement::GetAttributes方法的具体用法?C++ XMBElement::GetAttributes怎么用?C++ XMBElement::GetAttributes使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类XMBElement
的用法示例。
在下文中一共展示了XMBElement::GetAttributes方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: Xeromyces_ReadScript
void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths)
{
// Check for a 'file' parameter
CStrW file(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("file")).FromUTF8());
// If there is a file specified, open and execute it
if (!file.empty())
{
Paths.insert(file);
try
{
m_ScriptInterface->LoadGlobalScriptFile(file);
}
catch (PSERROR_Scripting& e)
{
LOGERROR("GUI: Error executing script %s: %s", utf8_from_wstring(file), e.what());
}
}
// If it has a directory attribute, read all JS files in that directory
CStrW directory(Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("directory")).FromUTF8());
if (!directory.empty())
{
VfsPaths pathnames;
vfs::GetPathnames(g_VFS, directory, L"*.js", pathnames);
for (const VfsPath& path : pathnames)
{
// Only load new files (so when the insert succeeds)
if (Paths.insert(path).second)
try
{
m_ScriptInterface->LoadGlobalScriptFile(path);
}
catch (PSERROR_Scripting& e)
{
LOGERROR("GUI: Error executing script %s: %s", path.string8(), e.what());
}
}
}
// Execute inline scripts
try
{
CStr code(Element.GetText());
if (!code.empty())
m_ScriptInterface->LoadGlobalScript(L"Some XML file", code.FromUTF8());
}
catch (PSERROR_Scripting& e)
{
LOGERROR("GUI: Error executing inline script: %s", e.what());
}
}
示例2: Xeromyces_ReadTooltip
void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile)
{
// Read the tooltip, and store it as a specially-named object
IGUIObject* object = new CTooltip;
XMBAttributeList attributes = Element.GetAttributes();
for (int i=0; i<attributes.Count; ++i)
{
XMBAttribute attr = attributes.Item(i);
CStr attr_name (pFile->GetAttributeString(attr.Name));
CStr attr_value (attr.Value);
if (attr_name == "name")
{
object->SetName("__tooltip_" + attr_value);
}
else
{
object->SetSetting(attr_name, attr_value.FromUTF8());
}
}
AddObject(object);
}
示例3: Xeromyces_ReadRepeat
void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject* pParent, std::vector<std::pair<CStr, CStr> >& NameSubst, boost::unordered_set<VfsPath>& Paths, u32 nesting_depth)
{
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
ELMT(object);
ATTR(count);
ATTR(var);
XMBAttributeList attributes = Element.GetAttributes();
int count = CStr(attributes.GetNamedItem(attr_count)).ToInt();
CStr var("["+attributes.GetNamedItem(attr_var)+"]");
if (var.size() < 3)
var = "[n]";
for (int n = 0; n < count; ++n)
{
NameSubst.emplace_back(var, "[" + CStr::FromInt(n) + "]");
XERO_ITER_EL(Element, child)
{
if (child.GetNodeName() == elmt_object)
Xeromyces_ReadObject(child, pFile, pParent, NameSubst, Paths, nesting_depth);
}
NameSubst.pop_back();
}
}
示例4: Xeromyces_ReadRepeat
void CGUI::Xeromyces_ReadRepeat(XMBElement Element, CXeromyces* pFile, IGUIObject *pParent, boost::unordered_set<VfsPath>& Paths)
{
#define ELMT(x) int elmt_##x = pFile->GetElementID(#x)
#define ATTR(x) int attr_##x = pFile->GetAttributeID(#x)
ELMT(object);
ATTR(count);
XMBAttributeList attributes = Element.GetAttributes();
int count = CStr(attributes.GetNamedItem(attr_count)).ToInt();
for (int n = 0; n < count; ++n)
{
std::vector<std::pair<CStr, CStr> > subst;
subst.push_back(std::make_pair(CStr("[n]"), "[" + CStr::FromInt(n) + "]"));
XERO_ITER_EL(Element, child)
{
if (child.GetNodeName() == elmt_object)
{
Xeromyces_ReadObject(child, pFile, pParent, subst, Paths);
}
}
}
}
示例5: Xeromyces_ReadColor
// 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.empty())
{
// Try setting color to value
if (!color.ParseString(value, 255.f))
{
LOGERROR(L"GUI: Unable to create custom color '%hs'. Invalid color syntax.", name.c_str());
}
else
{
// input color
m_PreDefinedColors[name] = color;
}
}
}
示例6: Xeromyces_ReadEffects
void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects &effects)
{
XMBAttributeList attributes = Element.GetAttributes();
for (int i=0; i<attributes.Count; ++i)
{
XMBAttribute attr = attributes.Item(i);
CStr attr_name (pFile->GetAttributeString(attr.Name));
CStrW attr_value (attr.Value.FromUTF8());
if (attr_name == "add_color")
{
CColor color;
if (!GUI<int>::ParseColor(attr_value, color, 0.f))
LOGERROR(L"GUI: Error parsing '%hs' (\"%ls\")", attr_name.c_str(), attr_value.c_str());
else effects.m_AddColor = color;
}
else if (attr_name == "grayscale")
{
effects.m_Greyscale = true;
}
else
{
debug_warn(L"Invalid data - DTD shouldn't allow this");
}
}
}
示例7: Xeromyces_ReadScript
void CGUI::Xeromyces_ReadScript(XMBElement Element, CXeromyces* pFile, boost::unordered_set<VfsPath>& Paths)
{
// Check for a 'file' parameter
CStrW file (Element.GetAttributes().GetNamedItem( pFile->GetAttributeID("file") ).FromUTF8());
// If there is a file specified, open and execute it
if (! file.empty())
{
Paths.insert(file);
try
{
m_ScriptInterface->LoadGlobalScriptFile(file);
}
catch (PSERROR_Scripting& e)
{
LOGERROR(L"GUI: Error executing script %ls: %hs", file.c_str(), e.what());
}
}
// Execute inline scripts
try
{
CStr code (Element.GetText());
if (! code.empty())
m_ScriptInterface->LoadGlobalScript(L"Some XML file", code.FromUTF8());
}
catch (PSERROR_Scripting& e)
{
LOGERROR(L"GUI: Error executing inline script: %hs", e.what());
}
}
示例8: Xeromyces_ReadStyle
void CGUI::Xeromyces_ReadStyle(XMBElement Element, CXeromyces* pFile)
{
// style object we're adding
SGUIStyle style;
CStr name;
//
// Read Attributes
//
// Now we can iterate all attributes and store
XMBAttributeList attributes = Element.GetAttributes();
for (int i=0; i<attributes.Count; ++i)
{
XMBAttribute attr = attributes.Item(i);
CStr attr_name (pFile->GetAttributeString(attr.Name));
// The "name" setting is actually the name of the style
// and not a new default
if (attr_name == "name")
name = attr.Value;
else
style.m_SettingsDefaults[attr_name] = attr.Value.FromUTF8();
}
//
// Add to CGUI
//
m_Styles[name] = style;
}
示例9: Xeromyces_ReadIcon
void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile)
{
// Icon we're adding
SGUIIcon icon;
CStr name;
XMBAttributeList attributes = Element.GetAttributes();
for (int i=0; i<attributes.Count; ++i)
{
XMBAttribute attr = attributes.Item(i);
CStr attr_name (pFile->GetAttributeString(attr.Name));
CStr attr_value (attr.Value);
if (attr_value == "null")
continue;
if (attr_name == "name")
name = attr_value;
else
if (attr_name == "sprite")
icon.m_SpriteName = attr_value;
else
if (attr_name == "size")
{
CSize size;
if (!GUI<CSize>::ParseString(attr_value.FromUTF8(), size))
LOGERROR(L"Error parsing '%hs' (\"%hs\") inside <icon>.", attr_name.c_str(), attr_value.c_str());
else
icon.m_Size = size;
}
else
if (attr_name == "cell_id")
{
int cell_id;
if (!GUI<int>::ParseString(attr_value.FromUTF8(), cell_id))
LOGERROR(L"GUI: Error parsing '%hs' (\"%hs\") inside <icon>.", attr_name.c_str(), attr_value.c_str());
else
icon.m_CellID = cell_id;
}
else
{
debug_warn(L"Invalid data - DTD shouldn't allow this");
}
}
m_Icons[name] = icon;
}
示例10: Xeromyces_ReadTooltip
void CGUI::Xeromyces_ReadTooltip(XMBElement Element, CXeromyces* pFile)
{
IGUIObject* object = new CTooltip;
for (XMBAttribute attr : Element.GetAttributes())
{
CStr attr_name(pFile->GetAttributeString(attr.Name));
CStr attr_value(attr.Value);
if (attr_name == "name")
object->SetName("__tooltip_" + attr_value);
else
object->SetSetting(attr_name, attr_value.FromUTF8());
}
AddObject(object);
}
示例11: Xeromyces_ReadStyle
void CGUI::Xeromyces_ReadStyle(XMBElement Element, CXeromyces* pFile)
{
SGUIStyle style;
CStr name;
for (XMBAttribute attr : Element.GetAttributes())
{
CStr attr_name(pFile->GetAttributeString(attr.Name));
// The "name" setting is actually the name of the style
// and not a new default
if (attr_name == "name")
name = attr.Value;
else
style.m_SettingsDefaults[attr_name] = attr.Value.FromUTF8();
}
m_Styles[name] = style;
}
示例12: Xeromyces_ReadSprite
void CGUI::Xeromyces_ReadSprite(XMBElement Element, CXeromyces* pFile)
{
CGUISprite* Sprite = new CGUISprite;
// Get name, we know it exists because of DTD requirements
CStr name = Element.GetAttributes().GetNamedItem(pFile->GetAttributeID("name"));
if (m_Sprites.find(name) != m_Sprites.end())
LOGWARNING("GUI sprite name '%s' used more than once; first definition will be discarded", name.c_str());
SGUIImageEffects* effects = NULL;
for (XMBElement child : Element.GetChildNodes())
{
CStr ElementName(pFile->GetElementString(child.GetNodeName()));
if (ElementName == "image")
Xeromyces_ReadImage(child, pFile, *Sprite);
else if (ElementName == "effect")
{
if (effects)
LOGERROR("GUI <sprite> must not have more than one <effect>");
else
{
effects = new SGUIImageEffects;
Xeromyces_ReadEffects(child, pFile, *effects);
}
}
else
debug_warn(L"Invalid data - DTD shouldn't allow this");
}
// Apply the effects to every image (unless the image overrides it with
// different effects)
if (effects)
for (SGUIImage* const& img : Sprite->m_Images)
if (!img->m_Effects)
img->m_Effects = new SGUIImageEffects(*effects); // do a copy just so it can be deleted correctly later
delete effects;
m_Sprites[name] = Sprite;
}
示例13: Xeromyces_ReadEffects
void CGUI::Xeromyces_ReadEffects(XMBElement Element, CXeromyces* pFile, SGUIImageEffects& effects)
{
for (XMBAttribute attr : Element.GetAttributes())
{
CStr attr_name(pFile->GetAttributeString(attr.Name));
CStrW attr_value(attr.Value.FromUTF8());
if (attr_name == "add_color")
{
CColor color;
if (!GUI<int>::ParseColor(attr_value, color, 0))
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
else effects.m_AddColor = color;
}
else if (attr_name == "grayscale")
effects.m_Greyscale = true;
else
debug_warn(L"Invalid data - DTD shouldn't allow this");
}
}
示例14: Xeromyces_ReadColor
void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile)
{
XMBAttributeList attributes = Element.GetAttributes();
CColor color;
CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name"));
// Try parsing value
CStr value(Element.GetText());
if (value.empty())
return;
// Try setting color to value
if (!color.ParseString(value))
{
LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str());
return;
}
m_PreDefinedColors[name] = color;
}
示例15: Xeromyces_ReadIcon
void CGUI::Xeromyces_ReadIcon(XMBElement Element, CXeromyces* pFile)
{
SGUIIcon icon;
CStr name;
for (XMBAttribute attr : Element.GetAttributes())
{
CStr attr_name(pFile->GetAttributeString(attr.Name));
CStr attr_value(attr.Value);
if (attr_value == "null")
continue;
if (attr_name == "name")
name = attr_value;
else if (attr_name == "sprite")
icon.m_SpriteName = attr_value;
else if (attr_name == "size")
{
CSize size;
if (!GUI<CSize>::ParseString(attr_value.FromUTF8(), size))
LOGERROR("Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value);
else
icon.m_Size = size;
}
else if (attr_name == "cell_id")
{
int cell_id;
if (!GUI<int>::ParseString(attr_value.FromUTF8(), cell_id))
LOGERROR("GUI: Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value);
else
icon.m_CellID = cell_id;
}
else
debug_warn(L"Invalid data - DTD shouldn't allow this");
}
m_Icons[name] = icon;
}