// ---------------------------------------------------------------------------
// 
//   Lily Engine alpha
// 
//   Copyright (c) 2010 Clifford Jolly
//     http://cliffjolly.com
//     cliff@cliffjolly.com
// 
// ---------------------------------------------------------------------------
// 
//   This program is free software; you can redistribute it and/or modify
//   it under the terms of the GNU General Public License as published by
//   the Free Software Foundation; either version 2 of the License, or
//   (at your option) any later version.
//  
//   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., 59 Temple Place, Suite 330, Boston, MA 02111-1307
//   USA
// -------------------------- END HEADER -------------------------------------

#ifndef INPUT_H
#define INPUT_H

#include <string>

namespace LilyParser {
    class ParserNode;
}

// For the most part, the game probably only has to worry about these.

/// Get the keybind as a boolean (on or off).
bool inputGetKeybindState(int keybindNum);

/// Get the keybind state as an axis (mapped to a real joystick axis,
/// will have a range of 0 to INPUT_AXIS_MAX).
int  inputGetAxisState(int axisNum);

/// Read in values from the actual devices and parse them into
/// something easily pulled in from inputGet???State().
void inputPumpState(void);


// For defining binds and the binds setup screen.

/// Keybind definition.
struct InputBindDef {

    /// This maps to an SDL keysym, or -1 for no keyboard control.
    int sdlKey;

    /// Joystick number or -1 for no joystick control.
    int joyNum;

    /// Joystick axis number, or -1 for no axis control.
    int joyAxis;

    /// Joystick axis direction: 0 for negative, 1 for positive.
    int joyAxisDirection;

    /// Joystick button, or -1 for no button.
    int joyButton;
};

// Max value from an axis. Also value returned for a button mapped to
// an axis when active.
#define INPUT_AXIS_MAX 32767

/// Clear an InputBindDef. (Set everything to -1.)
void inputClearBindDef(InputBindDef *def);

/// Set a keybind in the global keybind list.
void inputSetKeybind(int keybindNum, bool secondary,  InputBindDef *def);

/// Get a keybind from the global list.
void inputGetKeybind(int keybindNum, bool secondary, InputBindDef *def);

/// Get a string description of the button mapping. (For example,
/// "Joystick 0, Button 1".) For control names, see
/// engineUISetControlActionName().
std::string inputGetNameForBind(InputBindDef *def);

/// Clear all binds.
void inputClearBinds(void);

/// Initialize, open up the joystick devices, count everything, etc.
void inputInit(bool disableJoysticks);

/// Just closes joystick devices.
void inputShutdown(void);

/// Set an InputBindDef based on the current state of any
/// joystick. For the input setup screen to easily set stuff up.
void inputSetDefBasedOnWhateverJoysticksAreDoing(InputBindDef *def);

class TiXmlElement;

// Load/save junk.

/// Save binds as XML.
TiXmlElement *inputSaveBindsToXML(void);

/// Load binds from XML that inputSaveBindsToXML saved.
void inputLoadBindsFromXML(TiXmlElement *xml);


/// Save binds to a ParserNode.
LilyParser::ParserNode *inputSaveBindsToParserNode(void);

/// Load binds from a ParserNode that inputSaveBindsToParserNode saved.
void inputLoadBindsFromParserNode(LilyParser::ParserNode *node);


/// Get the number of joysticks that were opened in inputInit().
int inputGetNumJoysticks(void);

/// Get an SDL_Joystick directly.
void *inputGetRawJoystick(int joyNum);

#endif

