/*
    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 "mouse.h"

static PyObject* pysMouseGetPosPrev(PyObject* self)
{
    SGint x, y;
    sgMouseGetPosPrev(&x, &y);

    return Py_BuildValue("(ii)", x, y);
}
static PyObject* pysMouseGetPosPrevX(PyObject* self)
{
    return Py_BuildValue("i", sgMouseGetPosPrevX());
}
static PyObject* pysMouseGetPosPrevY(PyObject* self)
{
    return Py_BuildValue("i", sgMouseGetPosPrevY());
}

static PyObject* pysMouseGetPos(PyObject* self)
{
    SGint x, y;
    sgMouseGetPos(&x, &y);

    return Py_BuildValue("(ii)", x, y);
}
static PyObject* pysMouseGetPosX(PyObject* self)
{
    return Py_BuildValue("i", sgMouseGetPosX());
}
static PyObject* pysMouseGetPosY(PyObject* self)
{
    return Py_BuildValue("i", sgMouseGetPosY());
}

static PyObject* pysMouseGetWheelPrev(PyObject* self)
{
    return Py_BuildValue("i", sgMouseGetWheelPrev());
}
static PyObject* pysMouseGetWheel(PyObject* self)
{
    return Py_BuildValue("i", sgMouseGetWheel());
}

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

    if(sgMouseGetButtonPrev(button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButton(PyObject* self, PyObject* args)
{
    SGuint button;
    if(!PyArg_ParseTuple(args, "I", &button))
        return NULL;

    if(sgMouseGetButton(button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonPress(PyObject* self, PyObject* args)
{
    SGuint button;
    if(!PyArg_ParseTuple(args, "I", &button))
        return NULL;

    if(sgMouseGetButtonPress(button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonRelease(PyObject* self, PyObject* args)
{
    SGuint button;
    if(!PyArg_ParseTuple(args, "I", &button))
        return NULL;

    if(sgMouseGetButtonRelease(button))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}

static PyObject* pysMouseGetButtonLeftPrev(PyObject* self)
{
    if(sgMouseGetButtonLeftPrev())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonLeft(PyObject* self)
{
    if(sgMouseGetButtonLeft())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonLeftPress(PyObject* self)
{
    if(sgMouseGetButtonLeftPress())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonLeftRelease(PyObject* self)
{
    if(sgMouseGetButtonLeftRelease())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}

static PyObject* pysMouseGetButtonRightPrev(PyObject* self)
{
    if(sgMouseGetButtonRightPrev())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonRight(PyObject* self)
{
    if(sgMouseGetButtonRight())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonRightPress(PyObject* self)
{
    if(sgMouseGetButtonRightPress())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonRightRelease(PyObject* self)
{
    if(sgMouseGetButtonRightRelease())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}

static PyObject* pysMouseGetButtonMiddlePrev(PyObject* self)
{
    if(sgMouseGetButtonMiddlePrev())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonMiddle(PyObject* self)
{
    if(sgMouseGetButtonMiddle())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonMiddlePress(PyObject* self)
{
    if(sgMouseGetButtonMiddlePress())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
static PyObject* pysMouseGetButtonMiddleRelease(PyObject* self)
{
    if(sgMouseGetButtonMiddleRelease())
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}

static PyMethodDef InputMouseMethods[] = {
    {"getPosPrev", (PyCFunction)pysMouseGetPosPrev, METH_NOARGS, ""},
    {"getPosPrevX", (PyCFunction)pysMouseGetPosPrevX, METH_NOARGS, ""},
    {"getPosPrevY", (PyCFunction)pysMouseGetPosPrevY, METH_NOARGS, ""},

    {"getPos", (PyCFunction)pysMouseGetPos, METH_NOARGS, ""},
    {"getPosX", (PyCFunction)pysMouseGetPosX, METH_NOARGS, ""},
    {"getPosY", (PyCFunction)pysMouseGetPosY, METH_NOARGS, ""},

    {"getWheelPrev", (PyCFunction)pysMouseGetWheelPrev, METH_NOARGS, ""},
    {"getWheel", (PyCFunction)pysMouseGetWheel, METH_NOARGS, ""},

    {"getButtonPrev", (PyCFunction)pysMouseGetButtonPrev, METH_VARARGS, ""},
    {"getButton", (PyCFunction)pysMouseGetButton, METH_VARARGS, ""},
    {"getButtonPress", (PyCFunction)pysMouseGetButtonPress, METH_VARARGS, ""},
    {"getButtonRelease", (PyCFunction)pysMouseGetButtonRelease, METH_VARARGS, ""},

    {"getButtonLeftPrev", (PyCFunction)pysMouseGetButtonLeftPrev, METH_NOARGS, ""},
    {"getButtonLeft", (PyCFunction)pysMouseGetButtonLeft, METH_NOARGS, ""},
    {"getButtonLeftPress", (PyCFunction)pysMouseGetButtonLeftPress, METH_NOARGS, ""},
    {"getButtonLeftRelease", (PyCFunction)pysMouseGetButtonLeftRelease, METH_NOARGS, ""},

    {"getButtonRightPrev", (PyCFunction)pysMouseGetButtonRightPrev, METH_NOARGS, ""},
    {"getButtonRight", (PyCFunction)pysMouseGetButtonRight, METH_NOARGS, ""},
    {"getButtonRightPress", (PyCFunction)pysMouseGetButtonRightPress, METH_NOARGS, ""},
    {"getButtonRightRelease", (PyCFunction)pysMouseGetButtonRightRelease, METH_NOARGS, ""},

    {"getButtonMiddlePrev", (PyCFunction)pysMouseGetButtonMiddlePrev, METH_NOARGS, ""},
    {"getButtonMiddle", (PyCFunction)pysMouseGetButtonMiddle, METH_NOARGS, ""},
    {"getButtonMiddlePress", (PyCFunction)pysMouseGetButtonMiddlePress, METH_NOARGS, ""},
    {"getButtonMiddleRelease", (PyCFunction)pysMouseGetButtonMiddleRelease, METH_NOARGS, ""},
    {NULL, NULL, 0, NULL}
};

void sgpyInitInputMouse(PyObject* parent)
{
    PyObject* mouse = Py_InitModule("siege.input.mouse", InputMouseMethods);
    if(parent != NULL)
        PyModule_AddObject(parent, "mouse", mouse);
}
