
/******************************************************************************
*	File		-	InputManager.h
*	Author		-	Joey Pollack
*	Date		-	2019/11/14 (y/m/d)
*	Mod Date	-	2021/09/08 (y/m/d)
*	Description	-	Handles all input for windows systems
*
******************************************************************************/

#ifndef INPUT_MANAGER_H_
#define INPUT_MANAGER_H_

#include <vector>
#include <string>
#include <glm/glm.hpp>

#include "keyboard.h"

namespace lunarium
{
	class Window;

	class InputManager
	{
	public:

		struct KeyPress
		{
			Keyboard::Key Key;
			
			// Modifiers
			bool ShiftHeld;
			bool ControlHeld;
			bool AltHeld;
		};

		struct MouseButton
		{
			KeyCode code;
			std::string Name;
		};

	private:
		friend class Core;

		struct _KeyEvents
		{
			std::vector<KeyPress> KeysPressed;
			std::vector<Keyboard::Key> KeysReleased;

		} mKeyEvents;

		const int KEY_UP = 0;
		const int KEY_DOWN = 0xFF;


	private:	// ENGINE ONLY METHODS
		InputManager();
		void Initialize(Window* pWindow);
		void Shutdown();

		// Returns an array of keys that were pressed 
		// Keys are only pressed if they were not held on the previous frame
		const _KeyEvents& PollKeys();

		bool IsMouseButton(int keyCode);
		// TODO: Remove these functions 
		// KeyCode TranslateKey(int k);
		// char GetAsciiFromKeyPress(KeyCode k, bool shiftHeld);

	public:

		// Returns true if a key is down and was NOT down last frame
		bool IsKeyPressed(KeyCode key, bool ignoreWantCapture = false);

		// Returns true if a key is down
		bool IsKeyDown(KeyCode key, bool ignoreWantCapture = false);

		// Returns the mouse position in screen coordinates
		glm::vec2 GetMousePosition();
		void SetMousePosition(glm::vec2 p);

	private:
		Window* mpWindow;
		
		unsigned char mKeyboardState[512];
		//unsigned char mKeyboardPreviousState[NUM_KEYS];
		std::vector<KeyCode> mModifiers;
	};
}

#endif	// WIN_INPUT_MANAGER_H_