Don't crash while in the lobby when receiving an error IQ stanza without an error...
[0ad.git] / source / gui / CGUISprite.cpp
blob8153d30f91c8311029592e17e0867e77abbf32ac
1 /* Copyright (C) 2015 Wildfire Games.
2 * This file is part of 0 A.D.
4 * 0 A.D. is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation, either version 2 of the License, or
7 * (at your option) any later version.
9 * 0 A.D. is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU General Public License for more details.
14 * You should have received a copy of the GNU General Public License
15 * along with 0 A.D. If not, see <http://www.gnu.org/licenses/>.
18 #include "precompiled.h"
20 #include "CGUISprite.h"
22 CGUISprite::~CGUISprite()
24 for (SGUIImage* const& img : m_Images)
25 delete img;
28 void CGUISprite::AddImage(SGUIImage* image)
30 m_Images.push_back(image);
33 void CGUISpriteInstance::Draw(CRect Size, int CellID, std::map<CStr, CGUISprite*>& Sprites, float Z) const
35 if (m_CachedSize != Size || m_CachedCellID != CellID)
37 GUIRenderer::UpdateDrawCallCache(m_DrawCallCache, m_SpriteName, Size, CellID, Sprites);
38 m_CachedSize = Size;
39 m_CachedCellID = CellID;
41 GUIRenderer::Draw(m_DrawCallCache, Z);
44 void CGUISpriteInstance::Invalidate()
46 m_CachedSize = CRect();
47 m_CachedCellID = -1;
50 bool CGUISpriteInstance::IsEmpty() const
52 return m_SpriteName.empty();
55 // Plus a load of constructors / assignment operators, which don't copy the
56 // DrawCall cache (to avoid losing track of who has allocated various bits
57 // of data):
59 CGUISpriteInstance::CGUISpriteInstance()
60 : m_CachedCellID(-1)
64 CGUISpriteInstance::CGUISpriteInstance(const CStr& SpriteName)
65 : m_SpriteName(SpriteName), m_CachedCellID(-1)
69 CGUISpriteInstance::CGUISpriteInstance(const CGUISpriteInstance& Sprite)
70 : m_SpriteName(Sprite.m_SpriteName), m_CachedCellID(-1)
74 CGUISpriteInstance& CGUISpriteInstance::operator=(const CStr& SpriteName)
76 m_SpriteName = SpriteName;
77 m_DrawCallCache.clear();
78 Invalidate();
79 return *this;