
#include "cEvent.hpp"

using EventEngine::cEvent;

cEvent::cEvent() 
{}

/*virtual*/ cEvent::~cEvent()
{
	//Do nothing
}

/*virtual*/ void cEvent::OnEvent( const SDL_Event& event )
{
	switch (event.type)
	{
	case SDL_WINDOWEVENT:
		OnWindowsEvent(event);
		break;
	case SDL_KEYDOWN:
		OnKeyDown(event.key.keysym.sym, event.key.keysym.mod);// , Event->key.keysym.unicode);
		break;
	case SDL_KEYUP:
		OnKeyUp(event.key.keysym.sym, event.key.keysym.mod);//, Event->key.keysym.unicode);
		break;
	case SDL_MOUSEMOTION:
		OnMouseMove(event.motion.x, event.motion.y, event.motion.xrel, event.motion.yrel, (event.motion.state&SDL_BUTTON(SDL_BUTTON_LEFT)) != 0, (event.motion.state&SDL_BUTTON(SDL_BUTTON_RIGHT)) != 0, (event.motion.state&SDL_BUTTON(SDL_BUTTON_MIDDLE)) != 0);
		break;
	case SDL_MOUSEBUTTONDOWN:
		OnMouseButtonUp(event);
		break;
	case SDL_MOUSEBUTTONUP:
		OnMouseButtonDown(event);
		break;
	case SDL_JOYAXISMOTION:
		OnJoyAxis(event.jaxis.which, event.jaxis.axis, event.jaxis.value);
		break;
	case SDL_JOYBALLMOTION:
		OnJoyBall(event.jball.which, event.jball.ball, event.jball.xrel, event.jball.yrel);
		break;
	case SDL_JOYHATMOTION:
		OnJoyHat(event.jhat.which, event.jhat.hat, event.jhat.value);
		break;
	case SDL_JOYBUTTONDOWN:
		OnJoyButtonDown(event.jbutton.which, event.jbutton.button);
		break;
	case SDL_JOYBUTTONUP:
		OnJoyButtonUp(event.jbutton.which, event.jbutton.button);
		break;
	case SDL_QUIT:
		OnExit();
		break;
	case SDL_SYSWMEVENT:
		//Ignore
		break;
	default:
		OnUser(event.user.type, event.user.code, event.user.data1, event.user.data2);
		break;
	}
}

/*virtual*/ void cEvent::OnInputFocus()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnInputBlur()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnKeyDown(SDL_Keycode sym, Uint16 mod)//, Uint16 unicode)
{
	sym, mod;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnKeyUp(SDL_Keycode sym, Uint16 mod)//, Uint16 unicode)
{
	sym, mod;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnMouseFocus()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnMouseBlur()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnMouseMove(int mX, int mY, int relX, int relY, bool Left, bool Right, bool Middle)
{
	mX, mY, relX, relY, Left, Right, Middle;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnMouseWheel(bool Up, bool Down)
{
	Up, Down;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnLButtonDown(int mX, int mY)
{
	mX, mY;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnLButtonUp(int mX, int mY)
{
	mX, mY;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnRButtonDown(int mX, int mY)
{
	mX, mY;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnRButtonUp(int mX, int mY)
{
	mX, mY;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnMButtonDown(int mX, int mY)
{
	mX, mY;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnMButtonUp(int mX, int mY)
{
	mX, mY;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnJoyAxis(SDL_JoystickID which, Uint8 axis, Sint16 value)
{
	which, axis, value;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnJoyButtonDown(SDL_JoystickID which, Uint8 button)
{
	which, button;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnJoyButtonUp(SDL_JoystickID which, Uint8 button)
{
	which, button;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnJoyHat(SDL_JoystickID which, Uint8 hat, Uint8 value)
{
	which, hat, value;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnJoyBall(SDL_JoystickID which, Uint8 ball, Sint16 xrel, Sint16 yrel)
{
	which, ball, xrel, yrel;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnMinimize()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnRestore()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnResize(int w, int h)
{
	w, h;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnExpose()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnExit()
{
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnUser(Uint32 type, int code, void* data1, void* data2)
{
	type, code, data1, data2;
	//Pure virtual, do nothing
}

/*virtual*/ void cEvent::OnWindowsEvent( const SDL_Event& event )
{
	switch (event.window.event)
	{
	case SDL_WINDOWEVENT_SHOWN:
		SDL_Log("Window %d shown", event.window.windowID);
		break;
	case SDL_WINDOWEVENT_HIDDEN:
		SDL_Log("Window %d hidden", event.window.windowID);
		break;
	case SDL_WINDOWEVENT_EXPOSED:
		SDL_Log("Window %d exposed", event.window.windowID);
		break;
	case SDL_WINDOWEVENT_MOVED:
		SDL_Log("Window %d moved to %d,%d",
			event.window.windowID, event.window.data1,
			event.window.data2);
		break;
	case SDL_WINDOWEVENT_RESIZED:
		SDL_Log("Window %d resized to %dx%d",
			event.window.windowID, event.window.data1,
			event.window.data2);
		break;
	case SDL_WINDOWEVENT_SIZE_CHANGED:
		SDL_Log("Window %d size changed to %dx%d",
			event.window.windowID, event.window.data1,
			event.window.data2);
		break;
	case SDL_WINDOWEVENT_MINIMIZED:
		SDL_Log("Window %d minimized", event.window.windowID);
		break;
	case SDL_WINDOWEVENT_MAXIMIZED:
		SDL_Log("Window %d maximized", event.window.windowID);
		break;
	case SDL_WINDOWEVENT_RESTORED:
		SDL_Log("Window %d restored", event.window.windowID);
		break;
	case SDL_WINDOWEVENT_ENTER:
		SDL_Log("Mouse entered window %d",
			event.window.windowID);
		break;
	case SDL_WINDOWEVENT_LEAVE:
		SDL_Log("Mouse left window %d", event.window.windowID);
		break;
	case SDL_WINDOWEVENT_FOCUS_GAINED:
		SDL_Log("Window %d gained keyboard focus",
			event.window.windowID);
		break;
	case SDL_WINDOWEVENT_FOCUS_LOST:
		SDL_Log("Window %d lost keyboard focus",
			event.window.windowID);
		break;
	case SDL_WINDOWEVENT_CLOSE:
		SDL_Log("Window %d closed", event.window.windowID);
		break;
	default:
		SDL_Log("Window %d got unknown event %d",
			event.window.windowID, event.window.event);
		break;
	}
}

/*virtual*/ void cEvent::OnMouseButtonDown( const SDL_Event& event )
{
	switch (event.button.button) 
	{
	case SDL_BUTTON_LEFT:
		OnLButtonDown(event.button.x, event.button.y);
		break;
	case SDL_BUTTON_RIGHT:
		OnRButtonDown(event.button.x, event.button.y);
		break;
	case SDL_BUTTON_MIDDLE:
		OnMButtonDown(event.button.x, event.button.y);
		break;
	}
}

/*virtual*/ void cEvent::OnMouseButtonUp( const SDL_Event& event )
{
	switch (event.button.button)
	{
	case SDL_BUTTON_LEFT:
		OnLButtonUp(event.button.x, event.button.y);
		break;
	case SDL_BUTTON_RIGHT:
		OnRButtonUp(event.button.x, event.button.y);
		break;
	case SDL_BUTTON_MIDDLE:
		OnMButtonUp(event.button.x, event.button.y);
		break;
	}
}
