
#include <Spectre/System/Event.h>
#include <Spectre/Core/String.h>

namespace sp {

Event::Event(Type type) :
type	(type)
{
}

std::string Event::toString() const
{
	switch(type) {
	case Type::Quit :
		return "Quit";
	case Type::Size :
		return "Size (" + core::to_string(size.width) + ", " + core::to_string(size.height) + ")";
	case Type::Key :
		return "Key '" + key.getKeyName() + "' " + (key.pressed ? "pressed" : "released");
	case Type::MouseButton :
		return "MouseButton '" + mouseButton.getName() + "' " + (mouseButton.pressed ? "pressed" : "released");
	case Type::MouseMove :
		return "MouseMove (" + core::to_string(mouseMove.x) + ", " + core::to_string(mouseMove.y) + ")";
	}
	return "Unknown";
}

std::string Event::KeyEvent::getKeyName() const
{
	return Keyboard::getKeyName(code);
}

std::string Event::MouseButtonEvent::getName() const
{
	return Mouse::getButtonName(button);
}

// Helper methods

Event Event::createSize(Display *display, int width, int height)
{
	Event event(Size);
	event.size.display 	= display;
	event.size.width 	= width;
	event.size.height 	= height;
	return event;
}

Event Event::createKey(Keyboard::Key code, bool pressed)
{
	Event event(Key);
	event.key.code = code;
	event.key.pressed = pressed;
	return event;
}

Event Event::createMouseButton(Mouse::Button button, bool pressed)
{
	Event event(MouseButton);
	event.mouseButton.button = button;
	event.mouseButton.pressed = pressed;
	return event;
}

Event Event::createMouseMove(unsigned int x, unsigned int y)
{
	Event event(MouseMove);
	event.mouseMove.x = x;
	event.mouseMove.y = y;
	return event;
}

} // namespace sp
