//-----------------------------------------------------------------------------------------------
// SystemEvent.hpp
//
#pragma once
#ifndef include_SystemEvent
#define include_SystemEvent


/////////////////////////////////////////////////////////////////////////////////////////////////
enum EventType
{
	EVENT_TYPE_APP_CLOSE			= 0x0004, // 4
	EVENT_TYPE_APP_GAINED_FOCUS		= 0x0007, // 7
	EVENT_TYPE_APP_LOST_FOCUS		= 0x0008, // 8
	EVENT_TYPE_BUTTON_PRESSED		= 0x0100, // 256
	EVENT_TYPE_BUTTON_RELEASED		= 0x0101, // 257
	EVENT_TYPE_TEXT_CHARACTER_TYPED	= 0x0102, // 258
	EVENT_TYPE_BUTTON_REPEATED		= 0x010A, // 266
	EVENT_TYPE_MOUSE_WHEEL_MOVED	= 0x020a, // 522
	EVENT_TYPE_UNRECOGNIZED			= 0xe000, // 57344, for OS events we don't recognize (default)
	EVENT_TYPE_IGNORE_AND_PERMIT	= 0xe001, // 57345, for OS events we explicitly want to ignore but allow (WM_PAINT, etc.)	
	EVENT_TYPE_IGNORE_AND_CONSUME	= 0xe002, // 57346, for OS events we explicitly want to capture and destroy
	EVENT_TYPE_NONE
};


/////////////////////////////////////////////////////////////////////////////////////////////////
enum KeyButton
{
	BUTTON_NONE						= 0,	// 0
	BUTTON_KEYBOARD_ENTER			= '\r', // 13
	BUTTON_KEYBOARD_ESCAPE			= 0x1b, // 27
	BUTTON_KEYBOARD_SPACE			= ' ',  // 32
	BUTTON_KEYBOARD_PLUS			= '+',	// 43 (0x2b)
	BUTTON_KEYBOARD_COMMA			= ',',	// 44 (0x2c)
	BUTTON_KEYBOARD_MINUS			= '-',	// 45 (0x2d)
	BUTTON_KEYBOARD_PERIOD			= '.',	// 46
	BUTTON_KEYBOARD_SLASH			= '/',	// 47 (0x2f)
	BUTTON_KEYBOARD_0				= '0',	// 48
	BUTTON_KEYBOARD_1				= '1',	// 49
	BUTTON_KEYBOARD_2				= '2',	// 50
	BUTTON_KEYBOARD_3				= '3',	// 51
	BUTTON_KEYBOARD_4				= '4',	// 52
	BUTTON_KEYBOARD_5				= '5',	// 53
	BUTTON_KEYBOARD_6				= '6',	// 54
	BUTTON_KEYBOARD_7				= '7',	// 55
	BUTTON_KEYBOARD_8				= '8',	// 56
	BUTTON_KEYBOARD_9				= '9',	// 57
	BUTTON_KEYBOARD_SEMICOLON		= ';',	// 59
	BUTTON_KEYBOARD_A				= 'A',  // 65
	BUTTON_KEYBOARD_B				= 'B',  // 66
	BUTTON_KEYBOARD_C				= 'C',  // 67
	BUTTON_KEYBOARD_D				= 'D',  // 68
	BUTTON_KEYBOARD_E				= 'E',  // 69
	BUTTON_KEYBOARD_F				= 'F',  // 70
	BUTTON_KEYBOARD_G				= 'G',  // 71
	BUTTON_KEYBOARD_H				= 'H',  // 72
	BUTTON_KEYBOARD_I				= 'I',  // 73
	BUTTON_KEYBOARD_J				= 'J',  // 74
	BUTTON_KEYBOARD_K				= 'K',  // 75
	BUTTON_KEYBOARD_L				= 'L',  // 76
	BUTTON_KEYBOARD_M				= 'M',  // 77
	BUTTON_KEYBOARD_N				= 'N',  // 78
	BUTTON_KEYBOARD_O				= 'O',  // 79
	BUTTON_KEYBOARD_P				= 'P',  // 80
	BUTTON_KEYBOARD_Q				= 'Q',  // 81
	BUTTON_KEYBOARD_R				= 'R',  // 82
	BUTTON_KEYBOARD_S				= 'S',  // 83
	BUTTON_KEYBOARD_T				= 'T',  // 84
	BUTTON_KEYBOARD_U				= 'U',  // 85
	BUTTON_KEYBOARD_V				= 'V',  // 86
	BUTTON_KEYBOARD_W				= 'W',  // 87
	BUTTON_KEYBOARD_X				= 'X',  // 88
	BUTTON_KEYBOARD_Y				= 'Y',  // 89
	BUTTON_KEYBOARD_Z				= 'Z',  // 90
	BUTTON_KEYBOARD_LEFTBRACKET		= '[',	// 91
	BUTTON_KEYBOARD_BACKSLASH		= '\\',	// 92
	BUTTON_KEYBOARD_RIGHTBRACKET	= ']',	// 93
	BUTTON_KEYBOARD_NUMPAD0			= 0x60, // 96
	BUTTON_KEYBOARD_NUMPAD1			= 0x61, // 97
	BUTTON_KEYBOARD_NUMPAD2			= 0x62, // 98
	BUTTON_KEYBOARD_NUMPAD3			= 0x63, // 99
	BUTTON_KEYBOARD_NUMPAD4			= 0x64, // 100
	BUTTON_KEYBOARD_NUMPAD5			= 0x65, // 101
	BUTTON_KEYBOARD_NUMPAD6			= 0x66, // 102
	BUTTON_KEYBOARD_NUMPAD7			= 0x67, // 103
	BUTTON_KEYBOARD_NUMPAD8			= 0x68, // 104
	BUTTON_KEYBOARD_NUMPAD9			= 0x69, // 105
	BUTTON_KEYBOARD_F1				= 0x70, // 112
	BUTTON_KEYBOARD_F2				= 0x71, // 113
	BUTTON_KEYBOARD_F3				= 0x72, // 114
	BUTTON_KEYBOARD_F4				= 0x73, // 115
	BUTTON_KEYBOARD_F5				= 0x74, // 116
	BUTTON_KEYBOARD_F6				= 0x75, // 117
	BUTTON_KEYBOARD_F7				= 0x76, // 118
	BUTTON_KEYBOARD_F8				= 0x77, // 119
	BUTTON_KEYBOARD_F9				= 0x78, // 120
	BUTTON_KEYBOARD_F10				= 0x79, // 121
	BUTTON_KEYBOARD_F11				= 0x7a, // 122
	BUTTON_KEYBOARD_F12				= 0x7b, // 123
	BUTTON_KEYBOARD_F13				= 0x7c, // 124
	BUTTON_KEYBOARD_F14				= 0x7d, // 125
	BUTTON_KEYBOARD_F15				= 0x7e, // 126
	BUTTON_KEYBOARD_F16				= 0x7f, // 127
	BUTTON_KEYBOARD_F17				= 0x80, // 128
	BUTTON_KEYBOARD_F18				= 0x81, // 129
	BUTTON_KEYBOARD_F19				= 0x82, // 130
	BUTTON_KEYBOARD_F20				= 0x83, // 131
	BUTTON_KEYBOARD_F21				= 0x84, // 132
	BUTTON_KEYBOARD_F22				= 0x85, // 133
	BUTTON_KEYBOARD_F23				= 0x86, // 134
	BUTTON_KEYBOARD_F24				= 0x87, // 135
	BUTTON_KEYBOARD_LEFT_SHIFT		= 0xA0, // 160
	BUTTON_KEYBOARD_RIGHT_SHIFT		= 0xA1, // 161
	BUTTON_KEYBOARD_LEFT_CTRL		= 0xA2, // 162
	BUTTON_KEYBOARD_RIGHT_CTRL		= 0xA3, // 163
	BUTTON_KEYBOARD_LEFT_ALT		= 0xA4, // 164
	BUTTON_KEYBOARD_RIGHT_ALT		= 0xA5, // 165
	BUTTON_KEYBOARD_TILDE			= 0xc0,	// 192
	BUTTON_MOUSE_LEFT_BUTTON		= 0x1ab0, // 6832 (unused/reserved in unicode)
	BUTTON_MOUSE_MIDDLE_BUTTON		= 0x1ab1, // 6833 (unused/reserved in unicode)
	BUTTON_MOUSE_RIGHT_BUTTON		= 0x1ab2, // 6834 (unused/reserved in unicode)
//	BUTTON_MOUSE_WHEEL_DOWN			= 0x1ab3, // 6835 (unused/reserved in unicode)
//	BUTTON_MOUSE_WHEEL_UP			= 0x1ab4, // 6836 (unused/reserved in unicode)
	BUTTON_KEYBOARD_LEFTARROW		= 0x2190, // 8592 (unicode for left arrow)
	BUTTON_KEYBOARD_UPARROW			= 0x2191, // 8593 (unicode for up arrow)
	BUTTON_KEYBOARD_RIGHTARROW		= 0x2192, // 8594 (unicode for right arrow)
	BUTTON_KEYBOARD_DOWNARROW		= 0x2193, // 8595 (unicode for down arrow)
	BUTTON_KEYBOARD_HOME			= 0x2196, // 8598 (unicode for home / northwest arrow)
	BUTTON_KEYBOARD_PGUP			= 0x2197, // 8599 (unicode for page-up / northeast arrow)
	BUTTON_KEYBOARD_PGDN			= 0x2198, // 8600 (unicode for page-down / southeast arrow)
	BUTTON_KEYBOARD_END				= 0x2199, // 8601 (unicode for end / southwest arrow)
//	BUTTON_KEYBOARD_SHIFT			= 0x21e7, // 8679 (unicode for "upward white arrow" or "level 2 select key")
//	BUTTON_KEYBOARD_CONTROL			= 0x2303, // 8963 (unicode for "up arrowhead", which looks kinda like '^' but isn't)
	BUTTON_KEYBOARD_DELETE			= 0x2326, // 8998 (unicode for "erase to the right", which looks kinda like [X]>
	BUTTON_KEYBOARD_BACKSPACE		= 0x232b, // 9003 (unicode for "erase to the left", which looks kinda like <[X]
	BUTTON_MAX_NUM_BUTTONS
};


//-----------------------------------------------------------------------------------------------
const char* GetKeyButtonName( KeyButton keyButtonCode );


/////////////////////////////////////////////////////////////////////////////////////////////////
struct ButtonState
{
	ButtonState();

	bool	m_isPressed;
};


/////////////////////////////////////////////////////////////////////////////////////////////////
struct SystemEvent
{
	SystemEvent();
	bool WasButtonPressed( KeyButton keyButtonCode ) const { return (m_eventType == EVENT_TYPE_BUTTON_PRESSED) && (m_keyButtonCode == keyButtonCode); }
	bool WasButtonReleased( KeyButton keyButtonCode ) const { return (m_eventType == EVENT_TYPE_BUTTON_RELEASED) && (m_keyButtonCode == keyButtonCode); }

	EventType		m_eventType;
	KeyButton		m_keyButtonCode;
	unsigned int	m_utf32TextCharacter;
	int				m_miscData;
};


//-----------------------------------------------------------------------------------------------
inline SystemEvent::SystemEvent()
	: m_eventType( EVENT_TYPE_NONE )
	, m_keyButtonCode( BUTTON_NONE )
	, m_utf32TextCharacter( 0 )
	, m_miscData( 0 )
{
}


//-----------------------------------------------------------------------------------------------
inline ButtonState::ButtonState()
	: m_isPressed( false )
{
}



/////////////////////////////////////////////////////////////////////////////////////////////////
//unsigned char GetLatinCharForKey( KeyButton keyButtonCode, bool isCapsShifted );



/////////////////////////////////////////////////////////////////////////////////////////////////
/*
//-----------------------------------------------------------------------------------------------
inline bool IsAlpha( KeyButton keyButtonCode )
{
	return (keyButtonCode >= BUTTON_KEYBOARD_A) && (keyButtonCode <= BUTTON_KEYBOARD_Z);
}


//-----------------------------------------------------------------------------------------------
inline bool IsNumeric( KeyButton keyButtonCode )
{
	return  ((keyButtonCode >= BUTTON_KEYBOARD_0) && (keyButtonCode <= BUTTON_KEYBOARD_9)) ||
			((keyButtonCode >= BUTTON_KEYBOARD_NUMPAD0) && (keyButtonCode <= BUTTON_KEYBOARD_NUMPAD9));
}


//-----------------------------------------------------------------------------------------------
inline bool IsSymbol( KeyButton keyButtonCode )
{
	switch( keyButtonCode )
	{
		case BUTTON_KEYBOARD_COMMA:
		case BUTTON_KEYBOARD_PERIOD:
		case BUTTON_KEYBOARD_SEMICOLON:
		case BUTTON_KEYBOARD_LEFTBRACKET:
		case BUTTON_KEYBOARD_RIGHTBRACKET:
		case BUTTON_KEYBOARD_TILDE:
			return true;

		default:
			return false;
	}
}


//-----------------------------------------------------------------------------------------------
inline bool IsAlphaNumeric( KeyButton keyButtonCode )
{
	return IsAlpha( keyButtonCode ) || IsNumeric( keyButtonCode );
}


//-----------------------------------------------------------------------------------------------
inline bool IsAlphaNumericOrSymbol( KeyButton keyButtonCode )
{
	return IsAlpha( keyButtonCode ) || IsNumeric( keyButtonCode ) || IsSymbol( keyButtonCode );
}
*/


#endif // include_SystemEvent
