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

static PyObject* pysWindowOpen(PyObject* self, PyObject* args)
{
    unsigned int width, height, bpp, flags;
    PyArg_ParseTuple(args, "IIII", &width, &height, &bpp, &flags);

    PyObject* ret = sgWindowOpen(width, height, bpp, flags) ? Py_True : Py_False;
    Py_INCREF(ret);
    return ret;
}

static PyObject* pysWindowIsOpened(PyObject* self)
{
    PyObject* ret = sgWindowIsOpened() ? Py_True : Py_False;
    Py_INCREF(ret);
    return ret;
}

static PyObject* pysWindowClose(PyObject* self)
{
    sgWindowClose();

    Py_INCREF(Py_None);
    return Py_None;
}

static PyObject* pysWindowSetTitle(PyObject* self, PyObject* args)
{
    char* title;
    PyArg_ParseTuple(args, "s", &title);

    sgWindowSetTitle(title);

    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject* pysWindowGetTitle(PyObject* self)
{
    return Py_BuildValue("s", sgWindowGetTitle());
}

static PyObject* pysWindowSetSize(PyObject* self, PyObject* args)
{
    unsigned int width, height;
    PyArg_ParseTuple(args, "II", &width, &height);

    sgWindowSetSize(width, height);

    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject* pysWindowGetSize(PyObject* self)
{
    SGuint width, height;
    sgWindowGetSize(&width, &height);

    return Py_BuildValue("(ii)", width, height);
}

static PyObject* pysWindowSetWidth(PyObject* self, PyObject* args)
{
    unsigned int width;
    PyArg_ParseTuple(args, "I", &width);

    sgWindowSetWidth(width);

    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject* pysWindowGetWidth(PyObject* self)
{
    return Py_BuildValue("i", sgWindowGetWidth());
}

static PyObject* pysWindowSetHeight(PyObject* self, PyObject* args)
{
    unsigned int height;
    PyArg_ParseTuple(args, "I", &height);

    sgWindowSetHeight(height);

    Py_INCREF(Py_None);
    return Py_None;
}
static PyObject* pysWindowGetHeight(PyObject* self)
{
    return Py_BuildValue("i", sgWindowGetHeight());
}

static PyObject* pysWindowSwapBuffers(PyObject* self)
{
    sgWindowSwapBuffers();

    Py_INCREF(Py_None);
    return Py_None;
}

static PyMethodDef CoreWindowMethods[] = {
    {"open"       , (PyCFunction)pysWindowOpen       , METH_VARARGS, ""},
    {"isOpened"   , (PyCFunction)pysWindowIsOpened   , METH_NOARGS , ""},
    {"close"      , (PyCFunction)pysWindowClose      , METH_NOARGS , ""},
    {"setTitle"   , (PyCFunction)pysWindowSetTitle   , METH_VARARGS, ""},
    {"getTitle"   , (PyCFunction)pysWindowGetTitle   , METH_NOARGS , ""},
    {"setSize"    , (PyCFunction)pysWindowSetSize    , METH_VARARGS, ""},
    {"getSize"    , (PyCFunction)pysWindowGetSize    , METH_NOARGS , ""},
    {"setWidth"   , (PyCFunction)pysWindowSetWidth   , METH_VARARGS, ""},
    {"getWidth"   , (PyCFunction)pysWindowGetWidth   , METH_NOARGS , ""},
    {"setHeight"  , (PyCFunction)pysWindowSetHeight  , METH_VARARGS, ""},
    {"getHeight"  , (PyCFunction)pysWindowGetHeight  , METH_NOARGS , ""},
    {"swapBuffers", (PyCFunction)pysWindowSwapBuffers, METH_NOARGS , ""},
    {NULL, NULL, 0, NULL}
};

void sgpyInitCoreWindow(PyObject* parent)
{
    PyObject* window = Py_InitModule("siege.core.window", CoreWindowMethods);
    if(parent != NULL)
        PyModule_AddObject(parent, "window", window);
}
