1
0
mirror of https://github.com/vcmi/vcmi.git synced 2025-11-27 22:49:25 +02:00

Gui cleanup3 - UI refactoring to use smart pointers (#440)

* Changed most gui classes to use shared pointers
* Store and use IImage as shared_ptr
* CSpellWindow redesign
* AdventureMapClasses cleanup
* CLabel: store background as smart pointer
* Store CObjectList items as smart pointers
* Removed destroy function of list item
* Store toggle buttons as smart pointers
* Use CComponent as smart pointer
* Attempt to fix artifact merchant drawing
This commit is contained in:
Alexander Shishkin
2018-04-07 14:34:11 +03:00
committed by ArseniyShestakov
parent db60983b5a
commit 5c09f751b3
73 changed files with 4793 additions and 4544 deletions

View File

@@ -40,6 +40,23 @@ CIntObject::CIntObject(int used_, Point pos_):
GH.createdObj.front()->addChild(this, true);
}
CIntObject::~CIntObject()
{
if(active_m)
deactivate();
while(!children.empty())
{
if((defActions & DISPOSE) && (children.front()->recActions & DISPOSE))
delete children.front();
else
removeChild(children.front());
}
if(parent_m)
parent_m->removeChild(this);
}
void CIntObject::setTimer(int msToTrigger)
{
if (!(active & TIME))
@@ -125,24 +142,6 @@ void CIntObject::deactivate(ui16 what)
GH.handleElementDeActivate(this, what);
}
CIntObject::~CIntObject()
{
if (active_m)
deactivate();
if(defActions & DISPOSE)
{
while (!children.empty())
if(children.front()->recActions & DISPOSE)
delete children.front();
else
removeChild(children.front());
}
if(parent_m)
parent_m->removeChild(this);
}
void CIntObject::click(EIntObjMouseBtnType btn, tribool down, bool previousState)
{
switch(btn)
@@ -291,8 +290,12 @@ void CIntObject::removeChild(CIntObject * child, bool adjustPosition)
if (!child)
return;
assert(vstd::contains(children, child));
assert(child->parent_m == this);
if(!vstd::contains(children, child))
throw std::runtime_error("Wrong child object");
if(child->parent_m != this)
throw std::runtime_error("Wrong child object");
children -= child;
child->parent_m = nullptr;
if(adjustPosition)