/*
    Copyright (c) 2007 SIEGE Development Team
    All rights reserved.
    
    This file is part of libSIEGE.
    
    This software is copyrighted work licensed under the terms of the
    2-clause BSD license. Please consult the file "license.txt" for
    details.
    
    If you did not recieve the file with this program, please email
    Tim Chas <darkuranium@gmail.com>.
*/

#include "joystick.h"

static PyObject* pysJoystickGetButtonPrev(PyObject* self, PyObject* args)
{
    SGuint joy;
    SGuint button;
    if(!PyArg_ParseTuple(args, "II", &joy, &button))
        return NULL;

    if(sgJoystickGetButtonPrev(joy, button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysJoystickGetButton(PyObject* self, PyObject* args)
{
    SGuint joy;
    SGuint button;
    if(!PyArg_ParseTuple(args, "II", &joy, &button))
        return NULL;

    if(sgJoystickGetButton(joy, button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysJoystickGetButtonPress(PyObject* self, PyObject* args)
{
    SGuint joy;
    SGuint button;
    if(!PyArg_ParseTuple(args, "II", &joy, &button))
        return NULL;

    if(sgJoystickGetButtonPress(joy, button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysJoystickGetButtonRelease(PyObject* self, PyObject* args)
{
    SGuint joy;
    SGuint button;
    if(!PyArg_ParseTuple(args, "II", &joy, &button))
        return NULL;

    if(sgJoystickGetButtonRelease(joy, button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}

static PyObject* pysJoystickGetAxisPrev(PyObject* self, PyObject* args)
{
    SGuint joy;
    if(!PyArg_ParseTuple(args, "I", &joy))
        return NULL;

    //float* axis = sgJoystickGetAxisPrev(joy);
    /// \todo TODO
    return NULL;
}
static PyObject* pysJoystickGetAxisIndexPrev(PyObject* self, PyObject* args)
{
    SGuint joy;
    SGuint axis;
    if(!PyArg_ParseTuple(args, "II", &joy, &axis))
        return NULL;

    return Py_BuildValue("f", sgJoystickGetAxisIndexPrev(joy, axis));
}
static PyObject* pysJoystickGetAxis(PyObject* self, PyObject* args)
{
    SGuint joy;
    if(!PyArg_ParseTuple(args, "I", &joy))
        return NULL;

    //float* axis = sgJoystickGetAxis(joy);
    /// \todo TODO
    return NULL;
}
static PyObject* pysJoystickGetAxisIndex(PyObject* self, PyObject* args)
{
    SGuint joy;
    SGuint axis;
    if(!PyArg_ParseTuple(args, "II", &joy, &axis))
        return NULL;

    return Py_BuildValue("f", sgJoystickGetAxisIndex(joy, axis));
}
static PyObject* pysJoystickGetAxisDelta(PyObject* self, PyObject* args)
{
    SGuint joy;
    if(!PyArg_ParseTuple(args, "I", &joy))
        return NULL;

    //float* axis = sgJoystickGetAxisDelta(joy);
    /// \todo TODO
    return NULL;
}
static PyObject* pysJoystickGetAxisIndexDelta(PyObject* self, PyObject* args)
{
    SGuint joy;
    SGuint axis;
    if(!PyArg_ParseTuple(args, "II", &joy, &axis))
        return NULL;

    return Py_BuildValue("f", sgJoystickGetAxisIndexDelta(joy, axis));
}

static PyMethodDef InputJoystickMethods[] = {
    {"getButtonPrev", (PyCFunction)pysJoystickGetButtonPrev, METH_VARARGS, ""},
    {"getButton", (PyCFunction)pysJoystickGetButton, METH_VARARGS, ""},
    {"getButtonPress", (PyCFunction)pysJoystickGetButtonPress, METH_VARARGS, ""},
    {"getButtonRelease", (PyCFunction)pysJoystickGetButtonRelease, METH_VARARGS, ""},

    {"getAxisPrev", (PyCFunction)pysJoystickGetAxisPrev, METH_VARARGS, ""},
    {"getAxisIndexPrev", (PyCFunction)pysJoystickGetAxisIndexPrev, METH_VARARGS, ""},
    {"getAxis", (PyCFunction)pysJoystickGetAxis, METH_VARARGS, ""},
    {"getAxisIndex", (PyCFunction)pysJoystickGetAxisIndex, METH_VARARGS, ""},
    {"getAxisDelta", (PyCFunction)pysJoystickGetAxisDelta, METH_VARARGS, ""},
    {"getAxisIndexDelta", (PyCFunction)pysJoystickGetAxisIndexDelta, METH_VARARGS, ""},
    {NULL, NULL, 0, NULL}
};

void sgpyInitInputJoystick(PyObject* parent)
{
    PyObject* joystick = Py_InitModule("siege.input.joystick", InputJoystickMethods);
    if(parent != NULL)
        PyModule_AddObject(parent, "joystick", joystick);
}
