/*********************************************************\
         __      __           __  __
        / /     / / _____    / / / / ______   __     __
       / /     / / /___  \  / / / / / ___  | / /    / /
      / /_____/ / _____| / / / / / / /__/ / / /    / /
     / ______  / / ___  / / / / / / _____/ / /    / /
    / /     / / / /__/ / / / / / / |____  / |____/ /
   /_/     /_/ |______/ /_/ /_/  \_____/  \_____  /
                                         ______/ /
            High Level Game Framework   /_______/

  ------------------------------------------------------

  Copyright (c) 2009 - Rodrigo Braz Monteiro.
  This file is subject to the terms of license.txt.

\*********************************************************/

#pragma once

#include "utils.h"
#include "input_base.h"
#include <boost/function.hpp>

#ifdef _MSC_VER
#define XINPUT_AVAILABLE
#endif

namespace Halley {

	enum JoystickType {
		JOYSTICK_GENERIC,
		JOYSTICK_360,
		JOYSTICK_PS3
	};



	class InputJoystick : public InputButtonBase {
	public:
		virtual ~InputJoystick() {}

		virtual std::string getName() const = 0;
		virtual JoystickType getType() const = 0;

		size_t getNumberAxes();
		size_t getNumberHats();

		float getAxis(int n);
		shared_ptr<InputBase> getHat(int n);

		void setAxisAdjust(function<float (float)> f);
		static float defaultAxisAdjust(float value);

		int getButtonAtPosition(char c) const;	// c = N, S, E or W

	protected:
		std::vector<float> axes;
		std::vector<spInputButtonBase> hats;
		function<float (float)> axisAdjust;

		virtual void update() {}
		virtual void processEvent(const SDL_Event& event) { (void) event; }

		friend class Input;
	};

	typedef shared_ptr<InputJoystick> spInputJoystick;
}
