Changeset View
Changeset View
Standalone View
Standalone View
ps/trunk/source/gui/CGUI.cpp
Show First 20 Lines • Show All 353 Lines • ▼ Show 20 Lines | |||||
void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping)) | void CGUI::DrawSprite(const CGUISpriteInstance& Sprite, int CellID, const float& Z, const CRect& Rect, const CRect& UNUSED(Clipping)) | ||||
{ | { | ||||
// If the sprite doesn't exist (name == ""), don't bother drawing anything | // If the sprite doesn't exist (name == ""), don't bother drawing anything | ||||
if (Sprite.IsEmpty()) | if (Sprite.IsEmpty()) | ||||
return; | return; | ||||
// TODO: Clipping? | // TODO: Clipping? | ||||
Sprite.Draw(Rect, CellID, m_Sprites, Z); | Sprite.Draw(this, Rect, CellID, m_Sprites, Z); | ||||
} | } | ||||
void CGUI::Destroy() | void CGUI::Destroy() | ||||
{ | { | ||||
// We can use the map to delete all | // We can use the map to delete all | ||||
// now we don't want to cancel all if one Destroy fails | // now we don't want to cancel all if one Destroy fails | ||||
for (const std::pair<CStr, IGUIObject*>& p : m_pAllObjects) | for (const std::pair<CStr, IGUIObject*>& p : m_pAllObjects) | ||||
{ | { | ||||
▲ Show 20 Lines • Show All 1,074 Lines • ▼ Show 20 Lines | for (XMBAttribute attr : Element.GetAttributes()) | ||||
if (attr_name == "texture") | if (attr_name == "texture") | ||||
{ | { | ||||
Image->m_TextureName = VfsPath("art/textures/ui") / attr_value; | Image->m_TextureName = VfsPath("art/textures/ui") / attr_value; | ||||
} | } | ||||
else if (attr_name == "size") | else if (attr_name == "size") | ||||
{ | { | ||||
CClientArea ca; | CClientArea ca; | ||||
if (!GUI<CClientArea>::ParseString(attr_value, ca)) | if (!GUI<CClientArea>::ParseString(this, attr_value, ca)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_Size = ca; | Image->m_Size = ca; | ||||
} | } | ||||
else if (attr_name == "texture_size") | else if (attr_name == "texture_size") | ||||
{ | { | ||||
CClientArea ca; | CClientArea ca; | ||||
if (!GUI<CClientArea>::ParseString(attr_value, ca)) | if (!GUI<CClientArea>::ParseString(this, attr_value, ca)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_TextureSize = ca; | Image->m_TextureSize = ca; | ||||
} | } | ||||
else if (attr_name == "real_texture_placement") | else if (attr_name == "real_texture_placement") | ||||
{ | { | ||||
CRect rect; | CRect rect; | ||||
if (!GUI<CRect>::ParseString(attr_value, rect)) | if (!GUI<CRect>::ParseString(this, attr_value, rect)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_TexturePlacementInFile = rect; | Image->m_TexturePlacementInFile = rect; | ||||
} | } | ||||
else if (attr_name == "cell_size") | else if (attr_name == "cell_size") | ||||
{ | { | ||||
CSize size; | CSize size; | ||||
if (!GUI<CSize>::ParseString(attr_value, size)) | if (!GUI<CSize>::ParseString(this, attr_value, size)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_CellSize = size; | Image->m_CellSize = size; | ||||
} | } | ||||
else if (attr_name == "fixed_h_aspect_ratio") | else if (attr_name == "fixed_h_aspect_ratio") | ||||
{ | { | ||||
float val; | float val; | ||||
if (!GUI<float>::ParseString(attr_value, val)) | if (!GUI<float>::ParseString(this, attr_value, val)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_FixedHAspectRatio = val; | Image->m_FixedHAspectRatio = val; | ||||
} | } | ||||
else if (attr_name == "round_coordinates") | else if (attr_name == "round_coordinates") | ||||
{ | { | ||||
bool b; | bool b; | ||||
if (!GUI<bool>::ParseString(attr_value, b)) | if (!GUI<bool>::ParseString(this, attr_value, b)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_RoundCoordinates = b; | Image->m_RoundCoordinates = b; | ||||
} | } | ||||
else if (attr_name == "wrap_mode") | else if (attr_name == "wrap_mode") | ||||
{ | { | ||||
if (attr_value == L"repeat") | if (attr_value == L"repeat") | ||||
Image->m_WrapMode = GL_REPEAT; | Image->m_WrapMode = GL_REPEAT; | ||||
else if (attr_value == L"mirrored_repeat") | else if (attr_value == L"mirrored_repeat") | ||||
Image->m_WrapMode = GL_MIRRORED_REPEAT; | Image->m_WrapMode = GL_MIRRORED_REPEAT; | ||||
else if (attr_value == L"clamp_to_edge") | else if (attr_value == L"clamp_to_edge") | ||||
Image->m_WrapMode = GL_CLAMP_TO_EDGE; | Image->m_WrapMode = GL_CLAMP_TO_EDGE; | ||||
else | else | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
} | } | ||||
else if (attr_name == "z_level") | else if (attr_name == "z_level") | ||||
{ | { | ||||
float z_level; | float z_level; | ||||
if (!GUI<float>::ParseString(attr_value, z_level)) | if (!GUI<float>::ParseString(this, attr_value, z_level)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_DeltaZ = z_level/100.f; | Image->m_DeltaZ = z_level/100.f; | ||||
} | } | ||||
else if (attr_name == "backcolor") | else if (attr_name == "backcolor") | ||||
{ | { | ||||
CGUIColor color; | CGUIColor color; | ||||
if (!GUI<CGUIColor>::ParseString(attr_value, color)) | if (!GUI<CGUIColor>::ParseString(this, attr_value, color)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_BackColor = color; | Image->m_BackColor = color; | ||||
} | } | ||||
else if (attr_name == "bordercolor") | else if (attr_name == "bordercolor") | ||||
{ | { | ||||
CGUIColor color; | CGUIColor color; | ||||
if (!GUI<CGUIColor>::ParseString(attr_value, color)) | if (!GUI<CGUIColor>::ParseString(this, attr_value, color)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_BorderColor = color; | Image->m_BorderColor = color; | ||||
} | } | ||||
else if (attr_name == "border") | else if (attr_name == "border") | ||||
{ | { | ||||
bool b; | bool b; | ||||
if (!GUI<bool>::ParseString(attr_value, b)) | if (!GUI<bool>::ParseString(this, attr_value, b)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value)); | ||||
else | else | ||||
Image->m_Border = b; | Image->m_Border = b; | ||||
} | } | ||||
else | else | ||||
debug_warn(L"Invalid data - DTD shouldn't allow this"); | debug_warn(L"Invalid data - DTD shouldn't allow this"); | ||||
} | } | ||||
Show All 22 Lines | |||||
{ | { | ||||
for (XMBAttribute attr : Element.GetAttributes()) | for (XMBAttribute attr : Element.GetAttributes()) | ||||
{ | { | ||||
CStr attr_name(pFile->GetAttributeString(attr.Name)); | CStr attr_name(pFile->GetAttributeString(attr.Name)); | ||||
if (attr_name == "add_color") | if (attr_name == "add_color") | ||||
{ | { | ||||
CGUIColor color; | CGUIColor color; | ||||
if (!color.ParseString(attr.Value, 0)) | if (!color.ParseString(this, attr.Value, 0)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr.Value); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr.Value); | ||||
else effects.m_AddColor = color; | else effects.m_AddColor = color; | ||||
} | } | ||||
else if (attr_name == "grayscale") | else if (attr_name == "grayscale") | ||||
effects.m_Greyscale = true; | effects.m_Greyscale = true; | ||||
else | else | ||||
debug_warn(L"Invalid data - DTD shouldn't allow this"); | debug_warn(L"Invalid data - DTD shouldn't allow this"); | ||||
} | } | ||||
Show All 39 Lines | for (XMBAttribute attr : Element.GetAttributes()) | ||||
if (attr_value == "null") | if (attr_value == "null") | ||||
continue; | continue; | ||||
if (attr_name == "name") | if (attr_name == "name") | ||||
name = attr_value; | name = attr_value; | ||||
else if (attr_name == "show_edge_buttons") | else if (attr_name == "show_edge_buttons") | ||||
{ | { | ||||
bool b; | bool b; | ||||
if (!GUI<bool>::ParseString(attr_value.FromUTF8(), b)) | if (!GUI<bool>::ParseString(this, attr_value.FromUTF8(), b)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | ||||
else | else | ||||
scrollbar.m_UseEdgeButtons = b; | scrollbar.m_UseEdgeButtons = b; | ||||
} | } | ||||
else if (attr_name == "width") | else if (attr_name == "width") | ||||
{ | { | ||||
float f; | float f; | ||||
if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) | if (!GUI<float>::ParseString(this, attr_value.FromUTF8(), f)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | ||||
else | else | ||||
scrollbar.m_Width = f; | scrollbar.m_Width = f; | ||||
} | } | ||||
else if (attr_name == "minimum_bar_size") | else if (attr_name == "minimum_bar_size") | ||||
{ | { | ||||
float f; | float f; | ||||
if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) | if (!GUI<float>::ParseString(this, attr_value.FromUTF8(), f)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | ||||
else | else | ||||
scrollbar.m_MinimumBarSize = f; | scrollbar.m_MinimumBarSize = f; | ||||
} | } | ||||
else if (attr_name == "maximum_bar_size") | else if (attr_name == "maximum_bar_size") | ||||
{ | { | ||||
float f; | float f; | ||||
if (!GUI<float>::ParseString(attr_value.FromUTF8(), f)) | if (!GUI<float>::ParseString(this, attr_value.FromUTF8(), f)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, attr_value); | ||||
else | else | ||||
scrollbar.m_MaximumBarSize = f; | scrollbar.m_MaximumBarSize = f; | ||||
} | } | ||||
else if (attr_name == "sprite_button_top") | else if (attr_name == "sprite_button_top") | ||||
scrollbar.m_SpriteButtonTop = attr_value; | scrollbar.m_SpriteButtonTop = attr_value; | ||||
else if (attr_name == "sprite_button_top_pressed") | else if (attr_name == "sprite_button_top_pressed") | ||||
scrollbar.m_SpriteButtonTopPressed = attr_value; | scrollbar.m_SpriteButtonTopPressed = attr_value; | ||||
Show All 38 Lines | for (XMBAttribute attr : Element.GetAttributes()) | ||||
if (attr_name == "name") | if (attr_name == "name") | ||||
name = attr_value; | name = attr_value; | ||||
else if (attr_name == "sprite") | else if (attr_name == "sprite") | ||||
icon.m_SpriteName = attr_value; | icon.m_SpriteName = attr_value; | ||||
else if (attr_name == "size") | else if (attr_name == "size") | ||||
{ | { | ||||
CSize size; | CSize size; | ||||
if (!GUI<CSize>::ParseString(attr_value.FromUTF8(), size)) | if (!GUI<CSize>::ParseString(this, attr_value.FromUTF8(), size)) | ||||
LOGERROR("Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value); | LOGERROR("Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value); | ||||
else | else | ||||
icon.m_Size = size; | icon.m_Size = size; | ||||
} | } | ||||
else if (attr_name == "cell_id") | else if (attr_name == "cell_id") | ||||
{ | { | ||||
int cell_id; | int cell_id; | ||||
if (!GUI<int>::ParseString(attr_value.FromUTF8(), cell_id)) | if (!GUI<int>::ParseString(this, attr_value.FromUTF8(), cell_id)) | ||||
LOGERROR("GUI: Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value); | LOGERROR("GUI: Error parsing '%s' (\"%s\") inside <icon>.", attr_name, attr_value); | ||||
else | else | ||||
icon.m_CellID = cell_id; | icon.m_CellID = cell_id; | ||||
} | } | ||||
else | else | ||||
debug_warn(L"Invalid data - DTD shouldn't allow this"); | debug_warn(L"Invalid data - DTD shouldn't allow this"); | ||||
} | } | ||||
Show All 27 Lines | void CGUI::Xeromyces_ReadColor(XMBElement Element, CXeromyces* pFile) | ||||
CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name")); | CStr name = attributes.GetNamedItem(pFile->GetAttributeID("name")); | ||||
// Try parsing value | // Try parsing value | ||||
CStr value(Element.GetText()); | CStr value(Element.GetText()); | ||||
if (value.empty()) | if (value.empty()) | ||||
return; | return; | ||||
// Try setting color to value | // Try setting color to value | ||||
if (!color.ParseString(value)) | if (!color.ParseString(this, value)) | ||||
{ | { | ||||
LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str()); | LOGERROR("GUI: Unable to create custom color '%s'. Invalid color syntax.", name.c_str()); | ||||
return; | return; | ||||
} | } | ||||
m_PreDefinedColors[name] = color; | m_PreDefinedColors[name] = color; | ||||
} | } |
Wildfire Games · Phabricator