////////////////////////////////////////////////////////////////////////////////
//
// Copyright 2016 RWS Inc, All Rights Reserved
//
// This program is free software; you can redistribute it and/or modify
// it under the terms of version 2 of the GNU General Public License as published by
// the Free Software Foundation
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License along
// with this program; if not, write to the Free Software Foundation, Inc.,
// 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
//
//////////////////////////////////////////////////////////////////////////////
//
// InputEvent.H
// 
// History:
//		01/16/96 JMI	Started.
//
//////////////////////////////////////////////////////////////////////////////
//
// API to handle input events as one entity.  Merely an interface to the
// separate Blue APIs fro input events.
//
//////////////////////////////////////////////////////////////////////////////

#ifndef INPUT_EVENT_H
#define INPUT_EVENT_H

//////////////////////////////////////////////////////////////////////////////
// C Headers -- Must be included before RSPiX.h b/c RSPiX utilizes SHMalloc.
//////////////////////////////////////////////////////////////////////////////

///////////////////////////////////////////////////////////////////////////////
// RSPiX Headers.
// If PATHS_IN_INCLUDES macro is defined, we can utilize relative
// paths to a header file.  In this case we generally go off of our
// RSPiX root directory.  System.h MUST be included before this macro
// is evaluated.  System.h is the header that, based on the current
// platform (or more so in this case on the compiler), defines 
// PATHS_IN_INCLUDES.  Blue.h includes system.h so you can include that
// instead.
///////////////////////////////////////////////////////////////////////////////
#include "System.h"

#ifdef PATHS_IN_INCLUDES

#else

#endif

//////////////////////////////////////////////////////////////////////////////
// Macros.
//////////////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////////////
// Typedefs.
//////////////////////////////////////////////////////////////////////////////

// Input event structure for rsp*InputEvent[s]() functions.
typedef struct
	{
	typedef enum
		{
		None,		// No event.  Use this value to indicate no event.	
		Key,		// Keyboard event.
		Joy		// Joystick event (NYI) ???
		} Type;

	Type	type;		// Type of event { Mouse, Key, Joy }.
	int32_t	lTime;	// Time at which event occurred.
	int16_t	sUsed;	// Indicates that this event has been used.
						// Set this if your API utilizes this event so that others
						// know that it's already been absorbed.
	int32_t	lUser;	// User value.  Use as you please.

	union
		{				
		struct	// Keyboard event.
			{
			int32_t	lKey;			// Key value and modifiers (ala rspGetKey).
			};
		};
	} RInputEvent;

// Input event structure for Maple input events. (Used only for menu navigation)
const int MapleInputButtons = 18;
const int MapleInputAxes = 12;
#define MAPLEINPUT_BUTTON_MENUUP pInputSettings->m_sJoyMenuUpButton
#define MAPLEINPUT_BUTTON_MENUDOWN pInputSettings->m_sJoyMenuDownButton
#define MAPLEINPUT_BUTTON_MENULEFT pInputSettings->m_sJoyMenuLeftButton
#define MAPLEINPUT_BUTTON_MENURIGHT pInputSettings->m_sJoyMenuRightButton
#define MAPLEINPUT_AXIS_MENUUP pInputSettings->m_sJoyMenuUpAxis
#define MAPLEINPUT_AXIS_MENUDOWN pInputSettings->m_sJoyMenuDownAxis
#define MAPLEINPUT_AXIS_MENULEFT pInputSettings->m_sJoyMenuLeftAxis
#define MAPLEINPUT_AXIS_MENURIGHT pInputSettings->m_sJoyMenuRightAxis
#define MAPLEINPUT_BUTTON_CONFIRM pInputSettings->m_sJoyMenuConfirmButton
#define MAPLEINPUT_BUTTON_START pInputSettings->m_sJoyStartButton
#define MAPLEINPUT_BUTTON_BACK pInputSettings->m_sJoyMenuBackButton
#define MAPLEINPUT_BUTTON_BACK2 pInputSettings->m_sJoyMenuBackButton2

// Twinstick stuff
#define MAPLEINPUT_AXIS_MENUUP2 pInputSettings->m_sJoyMenuUpAxis2
#define MAPLEINPUT_AXIS_MENUDOWN2 pInputSettings->m_sJoyMenuDownAxis2
#define MAPLEINPUT_AXIS_MENULEFT2 pInputSettings->m_sJoyMenuLeftAxis2
#define MAPLEINPUT_AXIS_MENURIGHT2 pInputSettings->m_sJoyMenuRightAxis2
#define MAPLEINPUT_BUTTON_CONFIRM2 pInputSettings->m_sJoyMenuConfirmButton2
#define MAPLEINPUT_BUTTON_BACK3 pInputSettings->m_sJoyMenuBackButton3


typedef struct
{
	typedef enum
	{
		None,		// Nothing to report on this button.
		Press,		// This button was pressed.
		Release		// This button was released.
	} EButtonState;	// State of button (pushed, released, or None)

	EButtonState ButtonState[MapleInputButtons];	// States of all 16 buttons
	EButtonState AxisState[MapleInputAxes];			// States of all 6 axes
} MapleInputState;

//////////////////////////////////////////////////////////////////////////////
// Protos.
//////////////////////////////////////////////////////////////////////////////

// Clears any pending input events.  Calls rspClearMouseEvents() and
// rspClearKeyEvents().
//void rspClearAllInputEvents(void);	// Returns nothing.

// Clears any pending key input events.  Calls rspClearKeyEvents().
void rspClearKeyInputEvents(void);	// Returns nothing.

// Clears any pending mouse input events.  Calls rspClearMouseEvents().
void rspClearMouseInputEvents(void);	// Returns nothing.

// Gets the next input event.
int16_t rspGetNextInputEvent(	// Returns 1 if there is an event, 0 if none.
	RInputEvent*	pie);			// Out: Filled with input event type and details.


// MapleInput menu controls.

// Clears the MapleInput state. Returns nothing.
void ClearMapleInputState(int8_t controllerId = 0);

// Gets the next MapleInput state.
int16_t GetMapleInputState(MapleInputState* mis, int8_t controllerId = 0); // Returns 1 on success, 0 if failure or controller not present.
int16_t GetMapleInputStateNoUpdate(MapleInputState* mis, int8_t controllerId = 0);
int16_t GetLastMapleInputState(MapleInputState* mis, int8_t controllerId = 0);	// Returns the last known MapleInputState

// Returns 1 if any button on the controller is pressed.
int16_t IsMapleInputButtonPressed(int8_t controllerId = 0);

#endif	// INPUT_EVENT_H
//////////////////////////////////////////////////////////////////////////////
// EOF
//////////////////////////////////////////////////////////////////////////////
