/*
	Trig Wars.
	Copyright (c) 2008, Darragh Coy.
	All rights reserved.
	Original work(s), source code & author(s) details available at: http://www.darraghcoy.com

	Redistribution and use in source and binary forms, with or without modification, are permitted 
	provided that the following conditions are met:

		* 	Redistributions of source code must retain the above copyright notice, this list of 
			conditions and the following disclaimer.
		* 	Redistributions in binary form must reproduce the above copyright notice, this list of 
			conditions and the following disclaimer in the documentation.
		* 	Neither the name of the author nor the names of contributors may be used to endorse or 
			promote products derived from this software without specific prior written permission.
		* 	The use of any third party libraries, modules or data files provided with the source 
			form of the program must follow and respect the individual licensing terms of these 
			components. You do not have permission to modify or circumvent the licensing terms for 
			provided third party components unless the third party licenses specifically allow this. 
			If you do not agree to the terms of provided third party components then you do not have 
			permission to use them in your derived work(s).
		* 	The terms of this license do not apply to separate (but related) distributions if supplied 
			by the author(s), only to the contents of this source distribution, derived works, and the 
			binaries produced by either modified or unmodified versions of the source code. The terms 
			of this license do not also apply to any third party libraries or components provided with 
			the source distribution. Such third party elements are licensed under their own separate 
			agreements.

	THIS SOFTWARE IS PROVIDED BY DARRAGH COY ''AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
	BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 
	ARE DISCLAIMED. IN NO EVENT SHALL DARRAGH COY BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
	EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 
	OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY 
	OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING 
	IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/

#ifndef GAMEPAD_H
#define GAMEPAD_H

//=====================================================================================================================
//=====================================================================================================================

namespace Game
{
	//=================================================================================================================
	/// @brief		Allows for gamepad input using the XINPUT library
	//=================================================================================================================
	
	class Gamepad
	{
		public:

			//=========================================================================================================
			// Enums
			//=========================================================================================================

				/// Which player we are getting

				enum PlayerIndex
				{
					// The first player
				
					PLAYER_ONE = 0 ,
					
					// The second player
					
					PLAYER_TWO = 1 ,
					
					// The third player
					
					PLAYER_THREE = 2 ,
					
					// The fourth player
					
					PLAYER_FOUR	= 3
				};

			//=========================================================================================================
			// Structures
			//=========================================================================================================

				/// Structure which encapsulates the state of the gamepad

				struct GamepadState
				{
					/// Is the gamepad connected ?
				
					bool m_connected;
					
					/// The state of this digital button. True if pressed.
					
					bool m_a;
					
					/// The state of this digital button. True if pressed.
					
					bool m_b;
					
					/// The state of this digital button. True if pressed.
					
					bool m_x;
					
					/// The state of this digital button. True if pressed.
					
					bool m_y;
					
					/// The state of this digital button. True if pressed.
					
					bool m_up;
					
					/// The state of this digital button. True if pressed.
					
					bool m_down;
					
					/// The state of this digital button. True if pressed.
					
					bool m_left;
					
					/// The state of this digital button. True if pressed.
					
					bool m_right;
					
					/// The state of this digital button. True if pressed.
					
					bool m_lstick;
					
					/// The state of this digital button. True if pressed.
					
					bool m_rstick;
					
					/// The state of this digital button. True if pressed.
					
					bool m_lshoulder;
					
					/// The state of this digital button. True if pressed.
					
					bool m_rshoulder;
					
					/// The state of this digital button. True if pressed.
					
					bool m_start;
					
					/// The state of this digital button. True if pressed.
					
					bool m_back;
					
					/// The state of this analogue trigger. 1 if fully pressed. 0 is not pressed at all.
					
					float m_ltrigger;
					
					/// The state of this analogue trigger. 1 if fully pressed. 0 is not pressed at all.
					
					float m_rtrigger;
					
					/// The x value of this analogue stick. -1 if fully left. 1 if fully right. 0 if centered.
					
					float m_lstick_x;
					
					/// The y value of this analogue stick. -1 if fully up. 1 if fully down. 0 if centered.
					
					float m_lstick_y;
					
					/// The x value of this analogue stick. -1 if fully left. 1 if fully right. 0 if centered.
					
					float m_rstick_x;
					
					/// The y value of this analogue stick. -1 if fully up. 1 if fully down. 0 if centered.
					
					float m_rstick_y;
				};

			//=========================================================================================================
			// Functions
			//=========================================================================================================

				/// Initialises the gamepad interface:

				static void Initialize();

				/// Gets the state of the gamepad for the given player

				static GamepadState GetState( PlayerIndex player_index , bool use_dead_zones = true );
		
		private:

			//=========================================================================================================
			// Structures
			//=========================================================================================================
			
				/// Last known state of gamepad 1
				
				static GamepadState s_state1;
				
				/// Last known state of gamepad 2
				
				static GamepadState s_state2;
				
				/// Last known state of gamepad 3
				
				static GamepadState s_state3;
				
				/// Last known state of gamepad 4
				
				static GamepadState s_state4;
	};

};

#endif
