
#include <Platform/PlatformInput.h>
#include <Spectre/Input/Keyboard.h>
#include <Spectre/Input/Mouse.h>
#include <Spectre/Input/InputDevice.h>
#include <Spectre/Input/InputModule.h>

namespace sp {

InputModule::InputModule(PlatformInput *platform) :
m_platform	(platform)
{
	// Let user "install" devices?
	m_mouse = m_platform->createMouse();
	m_keyboard = m_platform->createKeyboard();

	addInputDevice(m_mouse);
	addInputDevice(m_keyboard);
}

InputModule::~InputModule()
{
	InputDeviceVec::iterator it;

	for(it = m_devices.begin(); it != m_devices.end(); it++) {
		delete (*it);
	}
}

void InputModule::addInputDevice(InputDevice *device)
{
	device->init();

	m_devices.push_back(device);
}

Mouse* InputModule::getMouse()
{
	return m_mouse;
}

Keyboard* InputModule::getKeyboard()
{
	return m_keyboard;
}

void InputModule::update()
{
	InputDeviceVec::iterator it;

	// Update all devices.
	for(it = m_devices.begin(); it != m_devices.end(); it++) {
		(*it)->update(this);
	}
}

} // namespace sp
