
///////////////////////////////////////////////////////////////////////////////
//
// File   : AVP_Platform_MenuInputDevices.cpp
// Author : Andy Tate
// Date   : 2-Mar-2005
//
// Copyright (C) 2005 Rebellion, All Rights Reserved.
//
///////////////////////////////////////////////////////////////////////////////

////////////////////////////////////////////////////////////////////////////////
// Include files...
////////////////////////////////////////////////////////////////////////////////

#include "Core/Asura.h"

#if !defined(ASURA_USE_GUI_MENU_SYSTEM)

#include "Menus/Asura_MenuControllerInput.h"
#include "Menus/Asura_MenuInputDevice.h"
#include "Menus/Asura_MenuKeyboardInput.h"
#include "Menus/Asura_MenuSystem.h"
#include "Input/Asura_PlatformInput.h"


////////////////////////////////////////////////////////////////////////////////
// Constant declarations...
////////////////////////////////////////////////////////////////////////////////

static const int	iPROJECT_NUMBER_OF_SUPPORTED_CONTROLLERS	= 1;

static const float	fCURSOR_SCROLL_DELAY						= 0.300f;
static const float	fCURSOR_SCROLL_REPEAT_PERIOD				= 0.100f;
static const float	fAXIS_REST_THRESHOLD						= 0.100f;
static const float	fKEY_REPEAT_DELAY							= 0.300f;
static const float	fKEY_REPEAT_PERIOD							= 0.100f;


////////////////////////////////////////////////////////////////////////////////
// Static variable declarations...
////////////////////////////////////////////////////////////////////////////////



class AVP_MenuControllerKeyboardInput : public Asura_MenuInputDevice
{
public:

	virtual bool Update()
	{
		m_xController.Update();
		m_xKeyboard.Update();
		return true;
	}

	virtual bool IsPrimaryKeyDepressed(PressType ePressedType = PT_DEBOUNCED_PRESSED) const
	{
		return m_xKeyboard.IsPrimaryKeyDepressed(ePressedType) || m_xController.IsPrimaryKeyDepressed(ePressedType);
	}

	virtual bool IsBackKeyDepressed(PressType ePressedType = PT_DEBOUNCED_PRESSED) const
	{
		return m_xKeyboard.IsBackKeyDepressed(ePressedType) || m_xController.IsBackKeyDepressed(ePressedType);
	}

	virtual bool IsStartKeyDepressed(PressType ePressedType = PT_DEBOUNCED_PRESSED) const
	{
		return m_xKeyboard.IsStartKeyDepressed(ePressedType) || m_xController.IsStartKeyDepressed(ePressedType);
	}


	Asura_Vector_2 GetCurrentVector(PressType ePressedType = PT_DEBOUNCED_PRESSED) const
	{
		//return whichever is non zero
		if (m_xKeyboard.GetCurrentVector(ePressedType).MagnitudeSquared() > 0.0f)
		{
			return m_xKeyboard.GetCurrentVector(ePressedType);
		}
		else
		{
			return m_xController.GetCurrentVector(ePressedType);
		}
	}

	AVP_MenuControllerKeyboardInput(const Asura_MenuKeyboardInput::KeyDefn* pxKeyDefn,
		const Asura_MenuControllerInput::ControllerDefn* pxController) :
	m_xController(pxController),
		m_xKeyboard(pxKeyDefn){}

private:
	Asura_MenuControllerInput m_xController;
	Asura_MenuKeyboardInput m_xKeyboard;


};

// Menu specific input devices...

static Asura_MenuKeyboardInput::KeyDefn g_xKeyDefn = 
{
	ASURA_KEYID_ENTER, 
	ASURA_KEYID_SPACE, 
	ASURA_KEYID_ESCAPE, 
	ASURA_KEYID_UP, 
	ASURA_KEYID_DOWN, 
	ASURA_KEYID_LEFT, 
	ASURA_KEYID_RIGHT,
	fCURSOR_SCROLL_DELAY, 
	fCURSOR_SCROLL_REPEAT_PERIOD
};

static Asura_MenuControllerInput::ControllerDefn g_xControllerDefn = 
{
	ASURA_XBOX360_KEYID_PAD1_LEFT,		// m_iLeft
	ASURA_XBOX360_KEYID_PAD1_RIGHT,		// m_iRight
	ASURA_XBOX360_KEYID_PAD1_UP,			// m_iUp
	ASURA_XBOX360_KEYID_PAD1_DOWN,		// m_iDown
	ASURA_XBOX360_AXISID_PAD1_LSTICK_H,		// m_iHorizAxis
	ASURA_XBOX360_AXISID_PAD1_LSTICK_V,		// m_iVertAxis
	ASURA_XBOX360_KEYID_PAD1_A,		// m_iPrimaryKey
	ASURA_XBOX360_KEYID_PAD1_BACK,		// m_iBackKey
	fAXIS_REST_THRESHOLD,			// m_fRestThreshold
	fKEY_REPEAT_DELAY,				// m_fRepeatDelay
	fKEY_REPEAT_PERIOD,				// m_fRepeatPeriod
	ASURA_XBOX360_KEYID_PAD1_B,		// m_iPrimaryKey2
	ASURA_XBOX360_KEYID_PAD1_START,	// m_iStartKey
};


static Asura_MenuKeyboardInput	g_xMenuKeyboardInput (&g_xKeyDefn);
AVP_MenuControllerKeyboardInput g_xMenuControllerKeyboardInput(&g_xKeyDefn, &g_xControllerDefn);

// Needed for Asura to link...

int Asura_MenuSystem::s_iNumInputDevices	= iPROJECT_NUMBER_OF_SUPPORTED_CONTROLLERS;

Asura_MenuInputDevice*	Asura_MenuSystem::s_apxInputDevices [iPROJECT_NUMBER_OF_SUPPORTED_CONTROLLERS] =
{
	&g_xMenuControllerKeyboardInput
};


////////////////////////////////////////////////////////////////////////////////
// Functions...
////////////////////////////////////////////////////////////////////////////////

#endif

/// End of file. ///
