Core: Added Listenable class (Made class Listener system generic)
Former-commit-id: 3baed32d6720c6455f50af51f262292ece9943fa
This commit is contained in:
@@ -5,63 +5,11 @@
|
||||
#include <Nazara/Utility/AbstractAtlas.hpp>
|
||||
#include <Nazara/Utility/Debug.hpp>
|
||||
|
||||
NzAbstractAtlas::NzAbstractAtlas() :
|
||||
m_listenersLocked(false)
|
||||
{
|
||||
}
|
||||
|
||||
NzAbstractAtlas::~NzAbstractAtlas()
|
||||
{
|
||||
m_listenersLocked = true;
|
||||
for (auto& pair : m_listeners)
|
||||
pair.first->OnAtlasReleased(this, pair.second);
|
||||
NotifyRelease(Listener::OnAtlasReleased);
|
||||
}
|
||||
|
||||
void NzAbstractAtlas::AddListener(Listener* listener, void* userdata) const
|
||||
{
|
||||
if (!m_listenersLocked)
|
||||
m_listeners.insert(std::make_pair(listener, userdata));
|
||||
}
|
||||
|
||||
void NzAbstractAtlas::RemoveListener(Listener* listener) const
|
||||
{
|
||||
if (!m_listenersLocked)
|
||||
m_listeners.erase(listener);
|
||||
}
|
||||
|
||||
void NzAbstractAtlas::NotifyCleared()
|
||||
{
|
||||
m_listenersLocked = true;
|
||||
|
||||
auto it = m_listeners.begin();
|
||||
while (it != m_listeners.end())
|
||||
{
|
||||
if (!it->first->OnAtlasCleared(this, it->second))
|
||||
m_listeners.erase(it++);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
m_listenersLocked = false;
|
||||
}
|
||||
|
||||
void NzAbstractAtlas::NotifyLayerChange(NzAbstractImage* oldLayer, NzAbstractImage* newLayer)
|
||||
{
|
||||
m_listenersLocked = true;
|
||||
|
||||
auto it = m_listeners.begin();
|
||||
while (it != m_listeners.end())
|
||||
{
|
||||
if (!it->first->OnAtlasLayerChange(this, oldLayer, newLayer, it->second))
|
||||
m_listeners.erase(it++);
|
||||
else
|
||||
++it;
|
||||
}
|
||||
|
||||
m_listenersLocked = false;
|
||||
}
|
||||
|
||||
|
||||
NzAbstractAtlas::Listener::~Listener() = default;
|
||||
|
||||
bool NzAbstractAtlas::Listener::OnAtlasCleared(const NzAbstractAtlas* atlas, void* userdata)
|
||||
|
||||
Reference in New Issue
Block a user