view LightClone/Source/InputManager.h @ 15:ee1c2510096d

Work on GUI system
author koryspansel <koryspansel@bendbroadband.com>
date Wed, 14 Sep 2011 11:04:18 -0700
parents 7081e8e6008c
children 51718795f019
line wrap: on
line source

/*
 * InputManager
 */

#ifndef __INPUTMANAGER_H__
#define __INPUTMANAGER_H__

#define DIRECTINPUT_VERSION 0x0800
#include <dinput.h>
#include "Core.h"
#include "Event.h"
#include "EventSource.h"

//TODO: Remove the need to pass InputManager to world objects during
//		initialization by sending input events instead

/*
 * InputEventType
 */
enum
{
	InputEventType_KeyDown,
	InputEventType_KeyUp,

	InputEventType_MouseDown,
	InputEventType_MouseUp,
	InputEventType_MouseMove,
};

/*
 * InputEvent
 */
struct InputEvent : public Event
{
	union
	{
		struct
		{
			/*
			 * nKey
			 */
			uint32 nKey;

			/*
			 * nDuration
			 */
			uint32 nDuration;
		};

		struct
		{
			/*
			 * nButton
			 */
			uint32 nButton;

			/*
			 * nDuration
			 */
			uint32 nDuration;
		};

		struct
		{
			/*
			 * fX
			 */
			float fX;

			/*
			 * fY
			 */
			float fY;
		};
	};
};

/*
 * InputManager
 */
class InputManager : public EventSource
{
	/*
	 * pDirectInput
	 */
	IDirectInput8* pDirectInput;

	/*
	 * pKeyboard
	 */
	IDirectInputDevice8* pKeyboard;

	/*
	 * pMouse
	 */
	IDirectInputDevice8* pMouse;

	/*
	 * kCurrentKeyboardState
	 */
	char kCurrentKeyboardState[256];

	/*
	 * kPreviousKeyboardState
	 */
	char kPreviousKeyboardState[256];

	/*
	 * kCurrentMouseState
	 */
	DIMOUSESTATE kCurrentMouseState;

	/*
	 * kPreviousMouseState
	 */
	DIMOUSESTATE kPreviousMouseState;

	/*
	 * fMouseX
	 */
	float fMouseX;

	/*
	 * fMouseY
	 */
	float fMouseY;

	/*
	 * kMouseBounds
	 */
	Rectangle2 kMouseBounds;

public:

	/*
	 * InputManager
	 */
	InputManager();

	/*
	 * Initialze
	 */
	ErrorCode Initialize(HWND kWindow);

	/*
	 * Terminate
	 */
	void Terminate();

	/*
	 * Update
	 */
	virtual void Update(EventSystem* pEventSystem, float fElapsed);

	/*
	 * SetBounds
	 */
	void SetBounds(float fMinimumX, float fMinimumY, float fMaximumX, float fMaximumY);

	/*
	 * SetMouse
	 */
	void SetMouse(float fX, float fY);

	/*
	 * IsKeyDown
	 */
	bool IsKeyDown(uint32 nKey) const;

	/*
	 * WasKeyDown
	 */
	bool WasKeyDown(uint32 nKey) const;

	/*
	 * IsButtonDown
	 */
	bool IsButtonDown(uint32 nButton) const;

	/*
	 * WasButtonDown
	 */
	bool WasButtonDown(uint32 nButton) const;

	/*
	 * GetMouseX
	 */
	float GetMouseX() const;

	/*
	 * GetMouseY
	 */
	float GetMouseY() const;
};

#endif //__INPUTMANAGER_H__