/*
-----------------------------------------------------------------------------
Filename:    TutorialApplication.h
-----------------------------------------------------------------------------

This source file is part of the
   ___                 __    __ _ _    _ 
  /___\__ _ _ __ ___  / / /\ \ (_) | _(_)
 //  // _` | '__/ _ \ \ \/  \/ / | |/ / |
/ \_// (_| | | |  __/  \  /\  /| |   <| |
\___/ \__, |_|  \___|   \/  \/ |_|_|\_\_|
      |___/                              
      Tutorial Framework
      http://www.ogre3d.org/tikiwiki/
-----------------------------------------------------------------------------
*/
#ifndef __TutorialApplication_h_
#define __TutorialApplication_h_

#include "BaseApplication.h"
#include "OpenSaveFileDialog.h"
#include "fglove.h"

class TutorialApplication : public BaseApplication
{

public:
    TutorialApplication(void);
    virtual ~TutorialApplication(void);

protected:
	void ConnectGlove(void);

    virtual void createScene(void);
	virtual void createCamera(void);
	//virtual void createViewports(void);

	//virtual void createFrameListener(void);
	virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt);
	
	// OIS::KeyListener
    virtual bool keyPressed( const OIS::KeyEvent& evt );
    virtual bool keyReleased( const OIS::KeyEvent& evt );
    //OIS::MouseListener
    virtual bool mouseMoved( const OIS::MouseEvent& evt );
    virtual bool mousePressed( const OIS::MouseEvent& evt, OIS::MouseButtonID id );
    virtual bool mouseReleased( const OIS::MouseEvent& evt, OIS::MouseButtonID id );
	// Called when a any button of the GUI is clicked
	//virtual void buttonHit(OgreBites::Button* b);

	Ogre::Real m_fRotateSpeed;			// The rotate constant
	Ogre::Real m_fRotateDecel;			// The rotate deceleration constant
	Ogre::Real m_fZoomSpeed;			// The zoom constant
	Ogre::Real m_fZoomDecel;			// The zoom deceleration
	Ogre::Real m_fMaxZoom;				// Max zoom distance	
	Ogre::Real m_fMinZoom;				// Min zoom distance
	Ogre::Real m_fPivotPitch;			// Current pitch of the camera   
 	
	Ogre::SceneNode* m_pCameraNode;		// Current position of cam
	Ogre::SceneNode* m_pCameraGoal;		// Where the camera should be (for smoother movement)
	Ogre::SceneNode* m_pCameraPivot;	// Pivot around which cam will rotate
	
	

private:
	common::OpenSaveFileDialog* mOpenSaveFileDialog;

	void Update5SensorGlove();
	void Update14SensorGlove();
	void UpdateCam(Ogre::Real fdT);
	void setupCamera();
	void updateCameraGoal(Ogre::Real deltaYaw, Ogre::Real deltaPitch, Ogre::Real deltaZoom);

	fdGlove* m_pGlove;					// our one and only glove

	// MyGUI variables and methods
	virtual void setup_finished(void);
	void setupMyGUI(void);
	void btnAbout_Click(MyGUI::WidgetPtr _sender);
	void wndAboutButtonPressed(MyGUI::WidgetPtr _widget, const std::string& _name);
	void btnExit_Click(MyGUI::WidgetPtr _sender);
	void loadCalibrationGui(bool b5SensorGlove);
	void btnCalibrate_Click(MyGUI::WidgetPtr _sender);
	void btnAdvCalib_Click(MyGUI::WidgetPtr _sender);
	void CalibCheckBox_Click(MyGUI::WidgetPtr _sender);
	void btnCalSetMin_Click(MyGUI::WidgetPtr _sender);
	void btnCalSetMax_Click(MyGUI::WidgetPtr _sender);
	void btnSaveCalib_Click(MyGUI::WidgetPtr _sender);
	void btnFistCalib_Click(MyGUI::WidgetPtr _sender);
	void btnOpenHandCalib_Click(MyGUI::WidgetPtr _sender);
	void btnSpreadFingersCalib_Click(MyGUI::WidgetPtr _sender);
	void btnFlatHandCalib_Click(MyGUI::WidgetPtr _sender);
	void btnCalibReset_Click(MyGUI::WidgetPtr _sender);
	void btnGraphicsSettings_Click(MyGUI::WidgetPtr _sender);
	void ApplyGraphicsSettings_Click(MyGUI::WidgetPtr _sender);
	void notifyOpenSaveEndDialog(bool _result);
	void btnSaveCal_Click(MyGUI::WidgetPtr _sender);

	int m_iCurrentSensor;	// currently selected sensor in calibration menu
	MyGUI::OgrePlatform* m_pPlatform;
	MyGUI::Gui* m_pGUI;
	MyGUI::StaticTextPtr m_ptxtFPS;
	MyGUI::StaticTextPtr m_ptxtRawVal;
	MyGUI::StaticTextPtr m_ptxtScaledVal;
	MyGUI::StaticTextPtr m_ptxtMaxCal;
	MyGUI::StaticTextPtr m_ptxtMinCal;

};

#endif // #ifndef __TutorialApplication_h_
