// This file is part of ThriceBall.
//
// Author: Kai Hillenbrand (AnTeevY)
// © Copyright, 2009 by Kai Hillenbrand, http://www.anteevy.de

// --------------------------------------------------

#pragma once
#ifndef FRAMELISTENER_H
#define FRAMELISTENER_H

// extern includes
#include "CEGUI/CEGUISystem.h"
#include "CEGUI/CEGUISchemeManager.h"
#include "OgreCEGUIRenderer.h"
#include <NxOgre.h>
#include <NxOgreOGRE3D.h>
#include <OgreWindowEventUtilities.h>

// intern includes
#include "renderer.h"
#include "baseframelistener.h"
#include "player.h"
#include "level.h"

// --------------------------------------------------

class CRenderer;
class CPlayer;
class CLevel;

class CFrameListener : public CBaseFrameListener, public OIS::MouseListener, public OIS::KeyListener
{
public:
    CFrameListener(RenderWindow* win, SceneManager *sceneMgr, CRenderer *renderer, CPlayer *player);
	~CFrameListener(){}

	CEGUI::MouseButton convertButton(OIS::MouseButtonID buttonID);	// OIS -> CEGUI	
	bool frameStarted(const FrameEvent &evt);						// called each frame

	// get functions
	CRenderer* getRenderer(){return m_pRenderer;}

protected:
	bool windowClosing(RenderWindow *rw);	// window close event (called when clicking the X)

	// mosue listener
	bool mouseMoved(const OIS::MouseEvent &e);
	bool mousePressed(const OIS::MouseEvent &e, OIS::MouseButtonID id);
	bool mouseReleased(const OIS::MouseEvent &e, OIS::MouseButtonID id);

	// key listener
	bool keyPressed(const OIS::KeyEvent &e);
	bool keyReleased(const OIS::KeyEvent &e);

	// OGRE variables
	SceneManager *m_pSceneMgr;
	Camera *m_pCamera;
	NxOgre::TimeController *m_pTimeController;

	// pointers to instances
	CRenderer *m_pRenderer;			// pointer to renderer instance
	CPlayer *m_pPlayer;				// pointer to player instance
	CLevel *m_pLevel;				// pointer to level instance

	// general variables
	float fWinWidth, fWinHeight;	// window width and height
	bool isMMBdown;					// is middle mouse button currently hold down?
	float fMouseSens;				// mouse sensitivity
	bool m_bIngame;					// currently ingame and NOT in main menu?
	bool m_bContinue;				// whether to continue rendering or not
};

#endif
