#ifndef _INPUTHANDLER_H_
#define _INPUTHANDLER_H_

#include "TSingleton.h"
#include "SDL.h"

//#define _GP2X 1 Uncomment for quickly editing in VS.

enum eInputKey
{
	eKeyUp = 0,
	eKeyUpLeft,
	eKeyUpRight,
	eKeyDown,
	eKeyDownLeft,
	eKeyDownRight,
	eKeyLeft,
	eKeyRight,
	eKeyButtonX,
	eKeyButtonY,
	eKeyButtonA,
	eKeyButtonB,
	eKeyButtonL,
	eKeyButtonR,
	eKeyButtonStart,
	eKeyButtonSelect,
	eKeyButtonVolumeUp,
	eKeyButtonVolumeDown,
	eKeyUndefined,
	eNumInputKeys
};

class InputHandler : public TSingleton<InputHandler>
{
	public:
	InputHandler();
	~InputHandler();

	void Update();

	bool IsKeyDown(const eInputKey &key);

	protected:
	void RegisterKeyValue(const eInputKey &key, const bool &bIsDown);
	
#ifdef _GP2X
	eInputKey ConvertGP2XToEnum(const Uint8 &button);
	int ConvertEnumToGP2X(const eInputKey &keyType);

	SDL_Joystick* m_pJoystick;
#endif

	bool m_keyArray[eNumInputKeys];
};


#ifdef _GP2X

// #define GP2X_VK_UP              (1 <<  0)
// #define GP2X_VK_UP_LEFT         (1 <<  1)
// #define GP2X_VK_LEFT            (1 <<  2)
// #define GP2X_VK_DOWN_LEFT       (1 <<  3)
// #define GP2X_VK_DOWN            (1 <<  4)
// #define GP2X_VK_DOWN_RIGHT      (1 <<  5)
// #define GP2X_VK_RIGHT           (1 <<  6)
// #define GP2X_VK_UP_RIGHT        (1 <<  7)
// #define GP2X_VK_START           (1 <<  8)
// #define GP2X_VK_SELECT          (1 <<  9)
// #define GP2X_VK_FL              (1 << 10)
// #define GP2X_VK_FR              (1 << 11)
// #define GP2X_VK_FA              (1 << 12)
// #define GP2X_VK_FB              (1 << 13)
// #define GP2X_VK_FX              (1 << 14)
// #define GP2X_VK_FY              (1 << 15)
// #define GP2X_VK_VOL_UP          (1 << 16)
// #define GP2X_VK_VOL_DOWN        (1 << 17)
// #define GP2X_VK_TAT             (1 << 18)

#define GP2X_BUTTON_UP              (0)
#define GP2X_BUTTON_DOWN            (4)
#define GP2X_BUTTON_LEFT            (2)
#define GP2X_BUTTON_RIGHT           (6)
#define GP2X_BUTTON_UPLEFT          (1)
#define GP2X_BUTTON_UPRIGHT         (7)
#define GP2X_BUTTON_DOWNLEFT        (3)
#define GP2X_BUTTON_DOWNRIGHT       (5)
#define GP2X_BUTTON_CLICK           (18)
#define GP2X_BUTTON_A               (12)
#define GP2X_BUTTON_B               (13)
#define GP2X_BUTTON_Y               (14)
#define GP2X_BUTTON_X               (15)
#define GP2X_BUTTON_L               (10)
#define GP2X_BUTTON_R               (11)
#define GP2X_BUTTON_START           (8)
#define GP2X_BUTTON_SELECT          (9)
#define GP2X_BUTTON_VOLUP           (16)
#define GP2X_BUTTON_VOLDOWN         (17)

#endif

#endif
