mirror of
https://gitea.wildfiregames.com/0ad/0ad.git
synced 2026-06-21 01:29:50 +00:00
Removes raw pointers management from CGUISprite.
This was SVN commit r25694.
This commit is contained in:
+20
-18
@@ -1024,9 +1024,11 @@ void CGUI::Xeromyces_ReadSprite(const XMBData& xmb, XMBElement element)
|
||||
// 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 = effects;
|
||||
{
|
||||
for (const std::unique_ptr<SGUIImage>& image : Sprite->m_Images)
|
||||
if (!image->m_Effects)
|
||||
image->m_Effects = effects;
|
||||
}
|
||||
|
||||
m_Sprites.erase(name);
|
||||
m_Sprites.emplace(name, Sprite);
|
||||
@@ -1034,7 +1036,7 @@ void CGUI::Xeromyces_ReadSprite(const XMBData& xmb, XMBElement element)
|
||||
|
||||
void CGUI::Xeromyces_ReadImage(const XMBData& xmb, XMBElement element, CGUISprite& parent)
|
||||
{
|
||||
SGUIImage* Image = new SGUIImage();
|
||||
auto image = std::make_unique<SGUIImage>();
|
||||
|
||||
// TODO Gee: Setup defaults here (or maybe they are in the SGUIImage ctor)
|
||||
|
||||
@@ -1045,15 +1047,15 @@ void CGUI::Xeromyces_ReadImage(const XMBData& xmb, XMBElement element, CGUISprit
|
||||
|
||||
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")
|
||||
{
|
||||
Image->m_Size.FromString(attr.Value);
|
||||
image->m_Size.FromString(attr.Value);
|
||||
}
|
||||
else if (attr_name == "texture_size")
|
||||
{
|
||||
Image->m_TextureSize.FromString(attr.Value);
|
||||
image->m_TextureSize.FromString(attr.Value);
|
||||
}
|
||||
else if (attr_name == "real_texture_placement")
|
||||
{
|
||||
@@ -1061,7 +1063,7 @@ void CGUI::Xeromyces_ReadImage(const XMBData& xmb, XMBElement element, CGUISprit
|
||||
if (!ParseString<CRect>(this, attr_value, rect))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else
|
||||
Image->m_TexturePlacementInFile = rect;
|
||||
image->m_TexturePlacementInFile = rect;
|
||||
}
|
||||
else if (attr_name == "fixed_h_aspect_ratio")
|
||||
{
|
||||
@@ -1069,7 +1071,7 @@ void CGUI::Xeromyces_ReadImage(const XMBData& xmb, XMBElement element, CGUISprit
|
||||
if (!ParseString<float>(this, attr_value, val))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else
|
||||
Image->m_FixedHAspectRatio = val;
|
||||
image->m_FixedHAspectRatio = val;
|
||||
}
|
||||
else if (attr_name == "round_coordinates")
|
||||
{
|
||||
@@ -1077,22 +1079,22 @@ void CGUI::Xeromyces_ReadImage(const XMBData& xmb, XMBElement element, CGUISprit
|
||||
if (!ParseString<bool>(this, attr_value, b))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
else
|
||||
Image->m_RoundCoordinates = b;
|
||||
image->m_RoundCoordinates = b;
|
||||
}
|
||||
else if (attr_name == "wrap_mode")
|
||||
{
|
||||
if (attr_value == L"repeat")
|
||||
Image->m_WrapMode = GL_REPEAT;
|
||||
image->m_WrapMode = GL_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")
|
||||
Image->m_WrapMode = GL_CLAMP_TO_EDGE;
|
||||
image->m_WrapMode = GL_CLAMP_TO_EDGE;
|
||||
else
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
}
|
||||
else if (attr_name == "backcolor")
|
||||
{
|
||||
if (!ParseString<CGUIColor>(this, attr_value, Image->m_BackColor))
|
||||
if (!ParseString<CGUIColor>(this, attr_value, image->m_BackColor))
|
||||
LOGERROR("GUI: Error parsing '%s' (\"%s\")", attr_name, utf8_from_wstring(attr_value));
|
||||
}
|
||||
else
|
||||
@@ -1105,19 +1107,19 @@ void CGUI::Xeromyces_ReadImage(const XMBData& xmb, XMBElement element, CGUISprit
|
||||
std::string_view ElementName(xmb.GetElementStringView(child.GetNodeName()));
|
||||
if (ElementName == "effect")
|
||||
{
|
||||
if (Image->m_Effects)
|
||||
if (image->m_Effects)
|
||||
LOGERROR("GUI <image> must not have more than one <effect>");
|
||||
else
|
||||
{
|
||||
Image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
Xeromyces_ReadEffects(xmb, child, *Image->m_Effects);
|
||||
image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
Xeromyces_ReadEffects(xmb, child, *image->m_Effects);
|
||||
}
|
||||
}
|
||||
else
|
||||
debug_warn(L"Invalid data - DTD shouldn't allow this");
|
||||
}
|
||||
|
||||
parent.AddImage(Image);
|
||||
parent.AddImage(std::move(image));
|
||||
}
|
||||
|
||||
void CGUI::Xeromyces_ReadEffects(const XMBData& xmb, XMBElement element, SGUIImageEffects& effects)
|
||||
|
||||
@@ -19,15 +19,11 @@
|
||||
|
||||
#include "CGUISprite.h"
|
||||
|
||||
CGUISprite::~CGUISprite()
|
||||
{
|
||||
for (SGUIImage* const& img : m_Images)
|
||||
delete img;
|
||||
}
|
||||
CGUISprite::~CGUISprite() = default;
|
||||
|
||||
void CGUISprite::AddImage(SGUIImage* image)
|
||||
void CGUISprite::AddImage(std::unique_ptr<SGUIImage> image)
|
||||
{
|
||||
m_Images.push_back(image);
|
||||
m_Images.emplace_back(std::move(image));
|
||||
}
|
||||
|
||||
void CGUISpriteInstance::Draw(CGUI& pGUI, CCanvas2D& canvas, const CRect& Size, std::map<CStr, const CGUISprite*>& Sprites) const
|
||||
|
||||
@@ -121,10 +121,10 @@ public:
|
||||
*
|
||||
* @param image Adds this image to the sprite collage.
|
||||
*/
|
||||
void AddImage(SGUIImage*);
|
||||
void AddImage(std::unique_ptr<SGUIImage> image);
|
||||
|
||||
/// List of images
|
||||
std::vector<SGUIImage*> m_Images;
|
||||
std::vector<std::unique_ptr<SGUIImage>> m_Images;
|
||||
};
|
||||
|
||||
// An instance of a sprite, usually stored in IGUIObjects - basically a string
|
||||
|
||||
+19
-19
@@ -101,22 +101,22 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const
|
||||
if (SpriteName.Find("stretched:") != -1)
|
||||
{
|
||||
// TODO: Should check (nicely) that this is a valid file?
|
||||
SGUIImage* Image = new SGUIImage();
|
||||
auto image = std::make_unique<SGUIImage>();
|
||||
|
||||
Image->m_TextureName = TextureName;
|
||||
image->m_TextureName = TextureName;
|
||||
if (SpriteName.Find("grayscale:") != -1)
|
||||
{
|
||||
Image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
Image->m_Effects->m_Greyscale = true;
|
||||
image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
image->m_Effects->m_Greyscale = true;
|
||||
}
|
||||
|
||||
Sprite->AddImage(Image);
|
||||
Sprite->AddImage(std::move(image));
|
||||
Sprites[SpriteName] = Sprite;
|
||||
}
|
||||
else if (SpriteName.Find("cropped:") != -1)
|
||||
{
|
||||
// TODO: Should check (nicely) that this is a valid file?
|
||||
SGUIImage* Image = new SGUIImage();
|
||||
auto image = std::make_unique<SGUIImage>();
|
||||
|
||||
const bool centered = SpriteName.Find("center:") != -1;
|
||||
|
||||
@@ -126,23 +126,23 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const
|
||||
const CRect percentSize = centered
|
||||
? CRect(50 - 50 / xRatio, 50 - 50 / yRatio, 50 + 50 / xRatio, 50 + 50 / yRatio)
|
||||
: CRect(0, 0, 100 / xRatio, 100 / yRatio);
|
||||
Image->m_TextureSize = CGUISize(CRect(0, 0, 0, 0), percentSize);
|
||||
Image->m_TextureName = TextureName;
|
||||
image->m_TextureSize = CGUISize(CRect(0, 0, 0, 0), percentSize);
|
||||
image->m_TextureName = TextureName;
|
||||
|
||||
if (SpriteName.Find("grayscale:") != -1)
|
||||
{
|
||||
Image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
Image->m_Effects->m_Greyscale = true;
|
||||
image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
image->m_Effects->m_Greyscale = true;
|
||||
}
|
||||
|
||||
Sprite->AddImage(Image);
|
||||
Sprite->AddImage(std::move(image));
|
||||
Sprites[SpriteName] = Sprite;
|
||||
}
|
||||
if (SpriteName.Find("color:") != -1)
|
||||
{
|
||||
CStrW value = wstring_from_utf8(SpriteName.AfterLast("color:").BeforeFirst(":"));
|
||||
|
||||
SGUIImage* Image = new SGUIImage();
|
||||
auto image = std::make_unique<SGUIImage>();
|
||||
CGUIColor* color;
|
||||
|
||||
// If we are using a mask, this is an effect.
|
||||
@@ -150,12 +150,12 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const
|
||||
// TODO: we are assuming there is a filename here.
|
||||
if (SpriteName.Find("textureAsMask:") != -1)
|
||||
{
|
||||
Image->m_TextureName = TextureName;
|
||||
Image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
color = &Image->m_Effects->m_SolidColor;
|
||||
image->m_TextureName = TextureName;
|
||||
image->m_Effects = std::make_shared<SGUIImageEffects>();
|
||||
color = &image->m_Effects->m_SolidColor;
|
||||
}
|
||||
else
|
||||
color = &Image->m_BackColor;
|
||||
color = &image->m_BackColor;
|
||||
|
||||
// Check color is valid
|
||||
if (!CGUI::ParseString<CGUIColor>(&pGUI, value, *color))
|
||||
@@ -164,7 +164,7 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const
|
||||
return;
|
||||
}
|
||||
|
||||
Sprite->AddImage(Image);
|
||||
Sprite->AddImage(std::move(image));
|
||||
Sprites[SpriteName] = Sprite;
|
||||
}
|
||||
it = Sprites.find(SpriteName);
|
||||
@@ -182,10 +182,10 @@ void GUIRenderer::UpdateDrawCallCache(const CGUI& pGUI, DrawCalls& Calls, const
|
||||
|
||||
// Iterate through all the sprite's images, loading the texture and
|
||||
// calculating the texture coordinates
|
||||
std::vector<SGUIImage*>::const_iterator cit;
|
||||
std::vector<std::unique_ptr<SGUIImage>>::const_iterator cit;
|
||||
for (cit = it->second->m_Images.begin(); cit != it->second->m_Images.end(); ++cit)
|
||||
{
|
||||
SDrawCall Call(*cit); // pointers are safe since we never modify sprites/images after startup
|
||||
SDrawCall Call(cit->get()); // pointers are safe since we never modify sprites/images after startup
|
||||
|
||||
CRect ObjectSize = (*cit)->m_Size.GetSize(Size);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user