/*****************************************************************************
 * $LastChangedDate: 2009-12-16 21:42:17 -0500 (Wed, 16 Dec 2009) $
 * @file
 * @author  Jim E. Brooks  http://www.palomino3d.org
 * @brief   Joystick event struct (system-neutral).
 *//*
 * LEGAL:   COPYRIGHT (C) 2009 JIM E. BROOKS
 *          THIS SOURCE CODE IS RELEASED UNDER THE TERMS
 *          OF THE GNU GENERAL PUBLIC LICENSE VERSION 2 (GPL 2).
 *****************************************************************************/

#ifndef INPUT_EVENT_JOYSTICK_HH
#define INPUT_EVENT_JOYSTICK_HH 1

namespace input {

////////////////////////////////////////////////////////////////////////////////
/// @brief Joystick event struct (system-neutral).
///
/// Think of JoystickEvent as a union: it should be assigned with
/// either an axis or button event (not both).
///
/// @verbatim
/// 
/// Axis values are returned in range -0x7fff...+0x7fff as:
/// 
///            -0x7fff
///               |
///    -0x7fff  --o--  +0x7fff
///               |
///            -0x7fff
/// 
/// @endverbatim
///
struct JoystickEvent
{
    enum
    {
        eAxis_NONE   = 0xffff,
        eButton_NONE = 0xffff,
    };

    JoystickEvent( void )
    {
        Clear();
    }

    void Clear( void )
    {
        mAxis      = eAxis_NONE;
        mAxisVal   = 0;
        mButton    = eButton_NONE;
        mButtonVal = false;
    }

    bool IfValid( void ) const
    {
        // Either.
        return (mAxis != eAxis_NONE) or (mButton != eButton_NONE);
    }

    bool IfEqualButtons( const JoystickEvent& other ) const
    {
        return (mButton == other.mButton) and (mButtonVal == other.mButtonVal);
    }

// Data members:
    uint    mAxis;          ///< axis (0=X) or eAxis_NONE
    int     mAxisVal;       ///< axis movement
    uint    mButton;        ///< button (0=first) or eButton_NONE
    bool    mButtonVal;     ///< button on/off
};

} // namespace input

#endif // INPUT_EVENT_JOYSTICK_HH
