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

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

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

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

#pragma once

#include "utils.h"
#include "SDL.h"
#include <vector>

namespace Halley {

	class InputBase {
	public:
		virtual ~InputBase() {}

		virtual bool isEnabled() const { return true; }

		virtual size_t getNumberButtons() { return 0; }
		virtual size_t getNumberAxes() { return 0; }
		virtual size_t getNumberHats() { return 0; }

		virtual bool isButtonPressed(int code) { (void)code; return false; }
		virtual bool isButtonReleased(int code) { (void)code; return false; }
		virtual bool isButtonDown(int code) { (void)code; return false; }

		virtual float getAxis(int n) { (void)n; return 0; }
		virtual shared_ptr<InputBase> getHat(int n) { (void)n; return shared_ptr<InputBase>(); }

		virtual void setVibration(float high, float low) { (void) high; (void) low; }
	};

	typedef shared_ptr<InputBase> spInputBase;



	class InputButtonBase : public InputBase {
	public:
		InputButtonBase(int nButtons=-1);

		size_t getNumberButtons() { return buttonDown.size(); }

		bool isButtonPressed(int code);
		bool isButtonReleased(int code);
		bool isButtonDown(int code);

	protected:
		std::vector<char> buttonPressed;
		std::vector<char> buttonReleased;
		std::vector<char> buttonDown;

		void init(int nButtons);

		void onButtonPressed(int code);
		void onButtonReleased(int code);
		void onButtonStatus(int code, bool down);
		void clearPresses();

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

		friend class InputJoystickXInput;
	};

	typedef shared_ptr<InputButtonBase> spInputButtonBase;

}
