
#include <Spectre/Display/Display.h>
#include <Spectre/System/MessageHandler.h>

namespace sp {

void MessageHandler::registerListener(EventListener *listener)
{
	for(auto it = m_listeners.begin(); it != m_listeners.end(); it++) {

		if (listener == *it) {
			// Already in vector. nothing to do.
			return;
		}
	}

	m_listeners.push_back(listener);
}

void MessageHandler::unregisterListener(EventListener *listener)
{
	for(auto it = m_listeners.begin(); it != m_listeners.end(); it++) {

		if (listener == *it) {
			m_listeners.erase(it);
			break;
		}
	}
}

void MessageHandler::onSizeChanged(Display* display, int width, int height)
{
	for(EventListener* listener : m_listeners) {
		listener->onSizeChanged(display, width, height);
	}
}

void MessageHandler::onEvent(const Event& event)
{
	for(EventListener* listener : m_listeners) {
		listener->onEvent(event);
	}
}

} // namespace sp
