Moved all bindings to the "bindings" sub-directory
Renamed the CSFML directory to c Renamed the DSFML directory to d --> bindings must now be updated to match the new organization! git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
0cc5563cac
commit
0e2297af28
417 changed files with 0 additions and 0 deletions
100
bindings/python/src/Blend.cpp
Normal file
100
bindings/python/src/Blend.cpp
Normal file
|
@ -0,0 +1,100 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Blend.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfBlend_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfBlend *self;
|
||||
self = (PySfBlend *)type->tp_alloc(type, 0);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
PyTypeObject PySfBlendType = {
|
||||
head_init
|
||||
"Blend", /*tp_name*/
|
||||
sizeof(PySfBlend), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Enumerate the blending modes for drawable objects.\n\
|
||||
Alpha Pixel = Src * a + Dest * (1 - a).\n\
|
||||
Add Pixel = Src + Dest.\n\
|
||||
Multiply Pixel = Src * Dest.\n\
|
||||
None No blending.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfBlend_new, /* tp_new */
|
||||
};
|
||||
|
||||
void PySfBlend_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Blend::Alpha);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Alpha", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Blend::Add);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Add", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Blend::Multiply);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Multiply", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Blend::None);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "None", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
39
bindings/python/src/Blend.hpp
Normal file
39
bindings/python/src/Blend.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYBLEND_HPP
|
||||
#define __PYBLEND_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfBlend;
|
||||
|
||||
void
|
||||
PySfBlend_InitConst();
|
||||
|
||||
#endif
|
110
bindings/python/src/Clock.cpp
Normal file
110
bindings/python/src/Clock.cpp
Normal file
|
@ -0,0 +1,110 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Clock.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static void
|
||||
PySfClock_dealloc(PySfClock *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfClock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfClock *self;
|
||||
|
||||
self = (PySfClock *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
self->obj = new sf::Clock();
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static PyObject*
|
||||
PySfClock_GetElapsedTime(PySfClock *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetElapsedTime());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfClock_Reset(PySfClock *self)
|
||||
{
|
||||
self->obj->Reset();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfClock_methods[] = {
|
||||
{"GetElapsedTime", (PyCFunction)PySfClock_GetElapsedTime, METH_NOARGS, "GetElapsedTime()\nGet the time elapsed since last reset."},
|
||||
{"Reset", (PyCFunction)PySfClock_Reset, METH_NOARGS, "Reset()\nRestart the timer."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfClockType = {
|
||||
head_init
|
||||
"Clock", /*tp_name*/
|
||||
sizeof(PySfClock), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfClock_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare (tp_reserved in py3k)*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Clock is an utility class for manipulating time.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfClock_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfClock_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
37
bindings/python/src/Clock.hpp
Normal file
37
bindings/python/src/Clock.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYCLOCK_HPP
|
||||
#define __PYCLOCK_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/System/Clock.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Clock *obj;
|
||||
} PySfClock;
|
||||
|
||||
#endif
|
198
bindings/python/src/Color.cpp
Normal file
198
bindings/python/src/Color.cpp
Normal file
|
@ -0,0 +1,198 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Color.hpp"
|
||||
|
||||
#include "offsetof.hpp"
|
||||
#include "compat.hpp"
|
||||
|
||||
static PyMemberDef PySfColor_members[] = {
|
||||
{(char *)"r", T_UBYTE, offsetof(PySfColor, r), 0, (char *)"Red component."},
|
||||
{(char *)"g", T_UBYTE, offsetof(PySfColor, g), 0, (char *)"Green component."},
|
||||
{(char *)"b", T_UBYTE, offsetof(PySfColor, b), 0, (char *)"Blue component."},
|
||||
{(char *)"a", T_UBYTE, offsetof(PySfColor, a), 0, (char *)"Alpha (transparency) component."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfColor_dealloc(PySfColor *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
void
|
||||
PySfColorUpdate(PySfColor *self)
|
||||
{
|
||||
self->obj->r = self->r;
|
||||
self->obj->g = self->g;
|
||||
self->obj->b = self->b;
|
||||
self->obj->a = self->a;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfColor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfColor *self;
|
||||
self = (PySfColor *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->r = 0;
|
||||
self->g = 0;
|
||||
self->b = 0;
|
||||
self->a = 255;
|
||||
self->obj = new sf::Color(0, 0, 0, 255);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfColor_init(PySfColor *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"r", "g", "b", "a", NULL};
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "BBB|B:Color.__init__", (char **)kwlist, &(self->r), &(self->g), &(self->b), &(self->a)))
|
||||
return -1;
|
||||
PySfColorUpdate(self);
|
||||
return 0;
|
||||
}
|
||||
|
||||
PyTypeObject PySfColorType = {
|
||||
head_init
|
||||
"Color", /*tp_name*/
|
||||
sizeof(PySfColor), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfColor_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Color is an utility class for manipulating 32-bits RGBA colors.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfColor_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfColor_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfColor_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfColor *
|
||||
GetNewPySfColor()
|
||||
{
|
||||
return PyObject_New(PySfColor, &PySfColorType);
|
||||
}
|
||||
|
||||
void
|
||||
PySfColor_InitConst()
|
||||
{
|
||||
PySfColor *Black, *White, *Red, *Green, *Blue, *Yellow, *Magenta, *Cyan;
|
||||
Black = GetNewPySfColor();
|
||||
Black->obj = (sf::Color *) &(sf::Color::Black);
|
||||
Black->r = sf::Color::Black.r;
|
||||
Black->g = sf::Color::Black.g;
|
||||
Black->b = sf::Color::Black.b;
|
||||
Black->a = sf::Color::Black.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Black", (PyObject *)Black);
|
||||
Py_DECREF(Black);
|
||||
White = GetNewPySfColor();
|
||||
White->obj = (sf::Color *) &(sf::Color::White);
|
||||
White->r = sf::Color::White.r;
|
||||
White->g = sf::Color::White.g;
|
||||
White->b = sf::Color::White.b;
|
||||
White->a = sf::Color::White.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "White", (PyObject *)White);
|
||||
Py_DECREF(White);
|
||||
Red = GetNewPySfColor();
|
||||
Red->obj = (sf::Color *) &(sf::Color::Red);
|
||||
Red->r = sf::Color::Red.r;
|
||||
Red->g = sf::Color::Red.g;
|
||||
Red->b = sf::Color::Red.b;
|
||||
Red->a = sf::Color::Red.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Red", (PyObject *)Red);
|
||||
Py_DECREF(Red);
|
||||
Green = GetNewPySfColor();
|
||||
Green->obj = (sf::Color *) &(sf::Color::Green);
|
||||
Green->r = sf::Color::Green.r;
|
||||
Green->g = sf::Color::Green.g;
|
||||
Green->b = sf::Color::Green.b;
|
||||
Green->a = sf::Color::Green.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Green", (PyObject *)Green);
|
||||
Py_DECREF(Green);
|
||||
Blue = GetNewPySfColor();
|
||||
Blue->obj = (sf::Color *) &(sf::Color::Blue);
|
||||
Blue->r = sf::Color::Blue.r;
|
||||
Blue->g = sf::Color::Blue.g;
|
||||
Blue->b = sf::Color::Blue.b;
|
||||
Blue->a = sf::Color::Blue.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Blue", (PyObject *)Blue);
|
||||
Py_DECREF(Blue);
|
||||
Yellow = GetNewPySfColor();
|
||||
Yellow->obj = (sf::Color *) &(sf::Color::Yellow);
|
||||
Yellow->r = sf::Color::Yellow.r;
|
||||
Yellow->g = sf::Color::Yellow.g;
|
||||
Yellow->b = sf::Color::Yellow.b;
|
||||
Yellow->a = sf::Color::Yellow.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Yellow", (PyObject *)Yellow);
|
||||
Py_DECREF(Yellow);
|
||||
Magenta = GetNewPySfColor();
|
||||
Magenta->obj = (sf::Color *) &(sf::Color::Magenta);
|
||||
Magenta->r = sf::Color::Magenta.r;
|
||||
Magenta->g = sf::Color::Magenta.g;
|
||||
Magenta->b = sf::Color::Magenta.b;
|
||||
Magenta->a = sf::Color::Magenta.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Magenta", (PyObject *)Magenta);
|
||||
Py_DECREF(Magenta);
|
||||
Cyan = GetNewPySfColor();
|
||||
Cyan->obj = (sf::Color *) &(sf::Color::Cyan);
|
||||
Cyan->r = sf::Color::Cyan.r;
|
||||
Cyan->g = sf::Color::Cyan.g;
|
||||
Cyan->b = sf::Color::Cyan.b;
|
||||
Cyan->a = sf::Color::Cyan.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Cyan", (PyObject *)Cyan);
|
||||
Py_DECREF(Cyan);
|
||||
}
|
||||
|
52
bindings/python/src/Color.hpp
Normal file
52
bindings/python/src/Color.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYCOLOR_HPP
|
||||
#define __PYCOLOR_HPP
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
sf::Color *obj;
|
||||
} PySfColor;
|
||||
|
||||
PySfColor *
|
||||
GetNewPySfColor();
|
||||
|
||||
void
|
||||
PySfColorUpdate(PySfColor *self);
|
||||
|
||||
void
|
||||
PySfColor_InitConst();
|
||||
|
||||
#endif
|
125
bindings/python/src/ContextSettings.cpp
Normal file
125
bindings/python/src/ContextSettings.cpp
Normal file
|
@ -0,0 +1,125 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "ContextSettings.hpp"
|
||||
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
#include "compat.hpp"
|
||||
|
||||
static PyMemberDef PySfContextSettings_members[] = {
|
||||
{(char *)"DepthBits", T_UINT, offsetof(PySfContextSettings, DepthBits), 0, (char *)"Depth buffer bits (24 by default)"},
|
||||
{(char *)"StencilBits", T_UINT, offsetof(PySfContextSettings, StencilBits), 0, (char *)"Stencil buffer bits (8 by default)"},
|
||||
{(char *)"AntialiasingLevel", T_UINT, offsetof(PySfContextSettings, AntialiasingLevel), 0, (char *)"Antialiasing level (0 by default)"},
|
||||
{(char *)"MajorVersion", T_UINT, offsetof(PySfContextSettings, MajorVersion), 0, (char *)"Major number of the context version to create. (2 by default)"},
|
||||
{(char *)"MinorVersion", T_UINT, offsetof(PySfContextSettings, MinorVersion), 0, (char *)"Minor number of the context version to create. (0 by default)"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfContextSettings_dealloc(PySfContextSettings *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
void
|
||||
PySfContextSettingsUpdate(PySfContextSettings *self)
|
||||
{
|
||||
self->obj->DepthBits = self->DepthBits;
|
||||
self->obj->StencilBits = self->StencilBits;
|
||||
self->obj->AntialiasingLevel = self->AntialiasingLevel;
|
||||
self->obj->MajorVersion = self->MajorVersion;
|
||||
self->obj->MinorVersion = self->MinorVersion;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfContextSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", "MajorVersion", "MinorVersion", NULL};
|
||||
PySfContextSettings *self;
|
||||
self = (PySfContextSettings *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->DepthBits = 24;
|
||||
self->StencilBits = 8;
|
||||
self->AntialiasingLevel = 0;
|
||||
self->MajorVersion = 2;
|
||||
self->MinorVersion = 0;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|IIIII:ContextSettings.__init__", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel), &(self->MajorVersion), &(self->MinorVersion)))
|
||||
return NULL;
|
||||
self->obj = new sf::ContextSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel, self->MajorVersion, self->MinorVersion);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
PyTypeObject PySfContextSettingsType = {
|
||||
head_init
|
||||
"ContextSettings", /*tp_name*/
|
||||
sizeof(PySfContextSettings), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfContextSettings_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Structure defining the creation settings of windows.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfContextSettings_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfContextSettings_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfContextSettings *
|
||||
GetNewPySfContextSettings()
|
||||
{
|
||||
return PyObject_New(PySfContextSettings, &PySfContextSettingsType);
|
||||
}
|
||||
|
49
bindings/python/src/ContextSettings.hpp
Normal file
49
bindings/python/src/ContextSettings.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYWINDOWSETTINGS_HPP
|
||||
#define __PYWINDOWSETTINGS_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int DepthBits;
|
||||
unsigned int StencilBits;
|
||||
unsigned int AntialiasingLevel;
|
||||
unsigned int MajorVersion;
|
||||
unsigned int MinorVersion;
|
||||
sf::ContextSettings *obj;
|
||||
} PySfContextSettings;
|
||||
|
||||
void
|
||||
PySfContextSettingsUpdate(PySfContextSettings *self);
|
||||
|
||||
PySfContextSettings *
|
||||
GetNewPySfContextSettings();
|
||||
|
||||
#endif
|
325
bindings/python/src/Drawable.cpp
Normal file
325
bindings/python/src/Drawable.cpp
Normal file
|
@ -0,0 +1,325 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Drawable.hpp"
|
||||
#include "Color.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
|
||||
|
||||
void CustomDrawable::Render(sf::RenderTarget& Target, sf::RenderQueue& Queue) const
|
||||
{
|
||||
if (RenderFunction)
|
||||
PyObject_CallFunction(RenderFunction, (char *)"OO", RenderWindow, Queue);
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Custom drawables must have a render method defined");
|
||||
PyErr_Print();
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
PySfDrawable_dealloc(PySfDrawable *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfDrawable *self;
|
||||
self = (PySfDrawable *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->IsCustom = true;
|
||||
self->obj = new CustomDrawable();
|
||||
if (PyObject_HasAttrString((PyObject *)self, "Render"))
|
||||
self->obj->RenderFunction = PyObject_GetAttrString((PyObject *)self, "Render");
|
||||
else
|
||||
self->obj->RenderFunction = NULL;
|
||||
self->obj->RenderWindow = NULL;
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetX(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetX(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetY(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetY(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetScale(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float ScaleX, ScaleY;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.SetScale", &ScaleX, &ScaleY) )
|
||||
return NULL;
|
||||
self->obj->SetScale(ScaleX, ScaleY);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetScaleX(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetScaleX(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetScaleY(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetScaleY(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetRotation(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetRotation(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetOrigin(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.SetOrigin", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->SetOrigin(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetOrigin(PySfDrawable* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetOrigin();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetColor(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
PySfColor *Color = (PySfColor *)args;
|
||||
if (!PyObject_TypeCheck(args, &PySfColorType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Drawable.SetColor() Argument is not a sf.Color");
|
||||
return NULL;
|
||||
}
|
||||
PySfColorUpdate(Color);
|
||||
self->obj->SetColor(*(Color->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetPosition(PySfDrawable* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetPosition();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetScale(PySfDrawable* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetScale();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetRotation(PySfDrawable* self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetRotation());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_GetColor(PySfDrawable* self)
|
||||
{
|
||||
PySfColor *Color;
|
||||
|
||||
Color = GetNewPySfColor();
|
||||
Color->obj = new sf::Color( self->obj->GetColor() );
|
||||
Color->r = Color->obj->r;
|
||||
Color->g = Color->obj->g;
|
||||
Color->b = Color->obj->b;
|
||||
Color->a = Color->obj->a;
|
||||
|
||||
return (PyObject *)Color;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_Move(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.Move", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->Move(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_Rotate(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->Rotate(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_Scale(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float FactorX, FactorY;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.Scale", &FactorX, &FactorY) )
|
||||
return NULL;
|
||||
self->obj->Scale(FactorX, FactorY);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetBlendMode(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetBlendMode((sf::Blend::Mode)PyLong_AsUnsignedLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetPosition(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float Left, Top;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.SetPosition", &Left, &Top) )
|
||||
return NULL;
|
||||
self->obj->SetPosition(Left, Top);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_TransformToLocal(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float X, Y;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.TransformToLocal", &X, &Y) )
|
||||
return NULL;
|
||||
sf::Vector2f result = self->obj->TransformToLocal(sf::Vector2f(X, Y));
|
||||
return Py_BuildValue("ff", result.x, result.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_TransformToGlobal(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float X, Y;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.TransformToGlobal", &X, &Y) )
|
||||
return NULL;
|
||||
sf::Vector2f result = self->obj->TransformToGlobal(sf::Vector2f(X, Y));
|
||||
return Py_BuildValue("ff", result.x, result.y);
|
||||
}
|
||||
|
||||
int PySfDrawable_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||
{
|
||||
#ifdef IS_PY3K
|
||||
PyObject *string = PyUnicode_AsUTF8String(attr_name);
|
||||
if (string == NULL) return NULL;
|
||||
std::string Name(PyBytes_AsString(string));
|
||||
#else
|
||||
std::string Name(PyString_AsString(attr_name));
|
||||
#endif
|
||||
if (Name == "Render")
|
||||
{
|
||||
Py_CLEAR(((PySfDrawable*)self)->obj->RenderFunction);
|
||||
Py_INCREF(v);
|
||||
((PySfDrawable*)self)->obj->RenderFunction = v;
|
||||
}
|
||||
#ifdef IS_PY3K
|
||||
Py_DECREF(string);
|
||||
#endif
|
||||
return PyObject_GenericSetAttr(self, attr_name, v);
|
||||
}
|
||||
|
||||
static PyMethodDef PySfDrawable_methods[] = {
|
||||
{"TransformToLocal", (PyCFunction)PySfDrawable_TransformToLocal, METH_VARARGS, "TransformToLocal(X, Y)\n\
|
||||
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's origin, translation, rotation and scale to the point). Returns a tuple.\n\
|
||||
X : X coordinate of the point to transform\n\
|
||||
Y : Y coordinate of the point to transform"},
|
||||
{"TransformToGlobal", (PyCFunction)PySfDrawable_TransformToGlobal, METH_VARARGS, "TransformToGlobal(X, Y)\n\
|
||||
Transform a point from local coordinates into global coordinates (ie it applies the object's origin, translation, rotation and scale to the point). Returns a tuple.\n\
|
||||
X : X coordinate of the point to transform\n\
|
||||
Y : Y coordinate of the point to transform"},
|
||||
{"SetX", (PyCFunction)PySfDrawable_SetX, METH_O, "SetX(X)\nSet the X position of the object.\n X : New X coordinate"},
|
||||
{"SetY", (PyCFunction)PySfDrawable_SetY, METH_O, "SetY(Y)\nSet the Y position of the object.\n Y : New Y coordinate"},
|
||||
{"SetScale", (PyCFunction)PySfDrawable_SetScale, METH_VARARGS, "SetScale(ScaleX, ScaleY)\nSet the scale of the object.\n ScaleX : New horizontal scale (must be strictly positive)\n ScaleY : New vertical scale (must be strictly positive)"},
|
||||
{"SetScaleX", (PyCFunction)PySfDrawable_SetScaleX, METH_O, "SetScaleX(ScaleX)\nSet the X scale factor of the object.\n ScaleX : New horizontal scale (must be strictly positive)"},
|
||||
{"SetScaleY", (PyCFunction)PySfDrawable_SetScaleY, METH_O, "SetScaleY(ScaleY)\nSet the Y scale factor of the object.\n ScaleY : New vertical scale (must be strictly positive)"},
|
||||
{"SetRotation", (PyCFunction)PySfDrawable_SetRotation, METH_O, "SetRotation(Rotation)\nSet the orientation of the object.\n Rotation : Angle of rotation, in degrees"},
|
||||
{"SetOrigin", (PyCFunction)PySfDrawable_SetOrigin, METH_VARARGS, "SetOrigin(OriginX, OriginY)\nSet the origin of the object, in coordinates relative to the object.\n OriginX : X coordinate of the origin\n OriginY : Y coordinate of the origin"},
|
||||
{"GetOrigin", (PyCFunction)PySfDrawable_GetOrigin, METH_NOARGS, "GetOrigin()\nGet the origin of the object, in coordinates relative to the object."},
|
||||
{"SetColor", (PyCFunction)PySfDrawable_SetColor, METH_O, "SetColor(Color)\nSet the color of the object.\n Color : New color"},
|
||||
{"GetPosition", (PyCFunction)PySfDrawable_GetPosition, METH_NOARGS, "GetPosition()\nGet the position of the object."},
|
||||
{"GetScale", (PyCFunction)PySfDrawable_GetScale, METH_NOARGS, "GetScale()\nGet the scale of the object."},
|
||||
{"GetRotation", (PyCFunction)PySfDrawable_GetRotation, METH_NOARGS, "GetRotation()\nGet the orientation of the object."},
|
||||
{"GetColor", (PyCFunction)PySfDrawable_GetColor, METH_NOARGS, "GetColor()\nGet the color of the object."},
|
||||
{"Move", (PyCFunction)PySfDrawable_Move, METH_VARARGS, "Move(OffsetX, OffsetY)\nMove the object.\n OffsetX : X offset\n OffsetY : Y offset "},
|
||||
{"Scale", (PyCFunction)PySfDrawable_Scale, METH_VARARGS, "Scale(FactorX, FactorY)\nScale the object.\n FactorX : Scaling factor on X (must be strictly positive)\n FactorY : Scaling factor on Y (must be strictly positive)"},
|
||||
{"Rotate", (PyCFunction)PySfDrawable_Rotate, METH_O, "Rotate(Angle)\nRotate the object.\n Angle : Angle of rotation, in degrees"},
|
||||
{"SetBlendMode", (PyCFunction)PySfDrawable_SetBlendMode, METH_O, "SetBlendMode(Mode)\nSet the blending mode for the object. The default blend mode is sf.Blend.Alpha\n Mode : New blending mode"},
|
||||
{"SetPosition", (PyCFunction)PySfDrawable_SetPosition, METH_VARARGS, "SetPosition(X, Y)\nSet the position of the object.\n X : New X coordinate\n Y : New Y coordinate"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfDrawableType = {
|
||||
head_init
|
||||
"Drawable", /*tp_name*/
|
||||
sizeof(PySfDrawable), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfDrawable_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
PySfDrawable_setattro, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Abstract base class for every object that can be drawn into a render window.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfDrawable_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfDrawable_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
53
bindings/python/src/Drawable.hpp
Normal file
53
bindings/python/src/Drawable.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYDRAWABLE_H
|
||||
#define __PYDRAWABLE_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/RenderQueue.hpp>
|
||||
|
||||
#include "RenderWindow.hpp"
|
||||
#include "RenderQueue.hpp"
|
||||
|
||||
class CustomDrawable : public sf::Drawable
|
||||
{
|
||||
protected :
|
||||
virtual void Render(sf::RenderTarget& Target, sf::RenderQueue& Queue) const;
|
||||
public :
|
||||
PySfRenderWindow *RenderWindow;
|
||||
PyObject *RenderFunction;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool IsCustom;
|
||||
CustomDrawable *obj;
|
||||
} PySfDrawable;
|
||||
|
||||
#endif
|
||||
|
780
bindings/python/src/Event.cpp
Normal file
780
bindings/python/src/Event.cpp
Normal file
|
@ -0,0 +1,780 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Event.hpp"
|
||||
|
||||
#include <structmember.h>
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
////////////////////////////////
|
||||
// Text Events Parameters
|
||||
////////////////////////////////
|
||||
|
||||
PyMemberDef PySfEventText_members[] = {
|
||||
{(char *)"Unicode", T_USHORT, offsetof(PySfEventText, Unicode), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
PySfEventText_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventText *self;
|
||||
|
||||
self = (PySfEventText *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Unicode = 0;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventText_dealloc(PySfEventText* self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
PyTypeObject PySfEventTextType = {
|
||||
head_init
|
||||
"Event.Text", /*tp_name*/
|
||||
sizeof(PySfEventText), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventText_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"Text Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventText_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventText_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// Keyboard Events Parameters
|
||||
/////////////////////////////////////
|
||||
|
||||
static PyObject *
|
||||
PySfEventKey_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventKey *self;
|
||||
|
||||
self = (PySfEventKey *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
Py_INCREF(Py_False);
|
||||
self->Alt = Py_False;
|
||||
Py_INCREF(Py_False);
|
||||
self->Control = Py_False;
|
||||
Py_INCREF(Py_False);
|
||||
self->Shift = Py_False;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventKey_dealloc(PySfEventKey* self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
PyMemberDef PySfEventKey_members[] = {
|
||||
{(char *)"Alt", T_OBJECT, offsetof(PySfEventKey, Alt), READONLY, (char *)""},
|
||||
{(char *)"Control", T_OBJECT, offsetof(PySfEventKey, Control), READONLY, (char *)""},
|
||||
{(char *)"Shift", T_OBJECT, offsetof(PySfEventKey, Shift), READONLY, (char *)""},
|
||||
{(char *)"Code", T_UINT, offsetof(PySfEventKey, Code), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventKeyType = {
|
||||
head_init
|
||||
"Event.Key", /*tp_name*/
|
||||
sizeof(PySfEventKey), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventKey_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"Key Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventKey_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventKey_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// MouseMove Events Parameters
|
||||
////////////////////////////////////
|
||||
|
||||
static PyObject *
|
||||
PySfEventMouseMove_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventMouseMove *self;
|
||||
|
||||
self = (PySfEventMouseMove *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->X = 0;
|
||||
self->Y = 0;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventMouseMove_dealloc(PySfEventMouseMove *self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventMouseMove_members[] = {
|
||||
{(char *)"X", T_INT, offsetof(PySfEventMouseMove, X), READONLY, (char *)""},
|
||||
{(char *)"Y", T_INT, offsetof(PySfEventMouseMove, Y), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventMouseMoveType = {
|
||||
head_init
|
||||
"Event.MouseMove", /*tp_name*/
|
||||
sizeof(PySfEventMouseMove), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventMouseMove_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"MouseMove Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventMouseMove_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventMouseMove_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// MouseButton Events Parameters
|
||||
////////////////////////////////////
|
||||
|
||||
static PyObject *
|
||||
PySfEventMouseButton_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventMouseButton *self;
|
||||
|
||||
self = (PySfEventMouseButton *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Button = 0;
|
||||
self->X = 0;
|
||||
self->Y = 0;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventMouseButton_dealloc(PySfEventMouseButton* self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventMouseButton_members[] = {
|
||||
{(char *)"Button", T_UINT, offsetof(PySfEventMouseButton, Button), READONLY, (char *)""},
|
||||
{(char *)"X", T_INT, offsetof(PySfEventMouseButton, X), READONLY, (char *)""},
|
||||
{(char *)"Y", T_INT, offsetof(PySfEventMouseButton, Y), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventMouseButtonType = {
|
||||
head_init
|
||||
"Event.MouseButton", /*tp_name*/
|
||||
sizeof(PySfEventMouseButton), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventMouseButton_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"MouseButton Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventMouseButton_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventMouseButton_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
// MouseWheel Events Parameters
|
||||
////////////////////////////////
|
||||
|
||||
static PyObject *
|
||||
PySfEventMouseWheel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventMouseWheel *self;
|
||||
|
||||
self = (PySfEventMouseWheel *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Delta = 0;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventMouseWheel_dealloc(PySfEventMouseWheel* self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
PyMemberDef PySfEventMouseWheel_members[] = {
|
||||
{(char *)"Delta", T_INT, offsetof(PySfEventMouseWheel,Delta), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventMouseWheelType = {
|
||||
head_init
|
||||
"Event.MouseWheel", /*tp_name*/
|
||||
sizeof(PySfEventMouseWheel), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventMouseWheel_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"MouseWheel Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventMouseWheel_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventMouseWheel_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// JoyMove Events Parameters
|
||||
////////////////////////////////////
|
||||
|
||||
static PyObject *
|
||||
PySfEventJoyMove_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventJoyMove *self;
|
||||
|
||||
self = (PySfEventJoyMove *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->JoystickId = 0;
|
||||
self->Axis = 0;
|
||||
self->Position = 0.f;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventJoyMove_dealloc(PySfEventJoyMove* self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventJoyMove_members[] = {
|
||||
{(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyMove,JoystickId), READONLY, (char *)""},
|
||||
{(char *)"Axis", T_UINT, offsetof(PySfEventJoyMove,Axis), READONLY, (char *)""},
|
||||
{(char *)"Position", T_FLOAT, offsetof(PySfEventJoyMove,Position), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventJoyMoveType = {
|
||||
head_init
|
||||
"Event.JoyMove", /*tp_name*/
|
||||
sizeof(PySfEventJoyMove), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventJoyMove_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"JoyMove Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventJoyMove_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventJoyMove_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// JoyButton Events Parameters
|
||||
////////////////////////////////////
|
||||
|
||||
static PyObject *
|
||||
PySfEventJoyButton_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventJoyButton *self;
|
||||
|
||||
self = (PySfEventJoyButton *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->JoystickId = 0;
|
||||
self->Button = 0;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventJoyButton_dealloc(PySfEventJoyButton* self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventJoyButton_members[] = {
|
||||
{(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyButton, JoystickId), READONLY, (char *)""},
|
||||
{(char *)"Button", T_UINT, offsetof(PySfEventJoyButton, Button), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventJoyButtonType = {
|
||||
head_init
|
||||
"Event.JoyButton", /*tp_name*/
|
||||
sizeof(PySfEventJoyButton), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventJoyButton_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"JoyButton Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventJoyButton_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventJoyButton_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// Size Events Parameters
|
||||
////////////////////////////////////
|
||||
|
||||
static PyObject *
|
||||
PySfEventSize_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEventSize *self;
|
||||
|
||||
self = (PySfEventSize *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Width = 0;
|
||||
self->Height = 0;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventSize_dealloc(PySfEventSize* self)
|
||||
{
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
PyMemberDef PySfEventSize_members[] = {
|
||||
{(char *)"Width", T_UINT, offsetof(PySfEventSize, Width), READONLY, (char *)""},
|
||||
{(char *)"Height", T_UINT, offsetof(PySfEventSize, Height), READONLY, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventSizeType = {
|
||||
head_init
|
||||
"Event.Size", /*tp_name*/
|
||||
sizeof(PySfEventSize), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventSize_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT, /*tp_flags*/
|
||||
"Size Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventSize_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventSize_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// sf.Event
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfEvent_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEvent *self;
|
||||
|
||||
self = (PySfEvent *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Text = (PySfEventText *)PySfEventText_new(&PySfEventTextType, NULL, NULL);
|
||||
self->Key = (PySfEventKey *)PySfEventKey_new(&PySfEventKeyType, NULL, NULL);
|
||||
self->MouseMove = (PySfEventMouseMove *)PySfEventMouseMove_new(&PySfEventMouseMoveType, NULL, NULL);
|
||||
self->MouseButton = (PySfEventMouseButton *)PySfEventMouseButton_new(&PySfEventMouseButtonType, NULL, NULL);
|
||||
self->MouseWheel = (PySfEventMouseWheel *)PySfEventMouseWheel_new(&PySfEventMouseWheelType, NULL, NULL);
|
||||
self->JoyMove = (PySfEventJoyMove *)PySfEventJoyMove_new(&PySfEventJoyMoveType, NULL, NULL);
|
||||
self->JoyButton = (PySfEventJoyButton *)PySfEventJoyButton_new(&PySfEventJoyButtonType, NULL, NULL);
|
||||
self->Size = (PySfEventSize *)PySfEventSize_new(&PySfEventSizeType, NULL, NULL);
|
||||
self->obj = new sf::Event();
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static void
|
||||
PySfEvent_dealloc(PySfEvent* self)
|
||||
{
|
||||
Py_DECREF(self->Text);
|
||||
Py_DECREF(self->Key);
|
||||
Py_DECREF(self->MouseMove);
|
||||
Py_DECREF(self->MouseButton);
|
||||
Py_DECREF(self->MouseWheel);
|
||||
Py_DECREF(self->JoyMove);
|
||||
Py_DECREF(self->JoyButton);
|
||||
Py_DECREF(self->Size);
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyMemberDef PySfEvent_members[] = {
|
||||
{(char *)"Text", T_OBJECT, offsetof(PySfEvent, Text), READONLY, (char *)"Text Events Parameters"},
|
||||
{(char *)"Key", T_OBJECT, offsetof(PySfEvent, Key), READONLY, (char *)"Keyboard Events Parameters"},
|
||||
{(char *)"MouseMove", T_OBJECT, offsetof(PySfEvent, MouseMove), READONLY, (char *)"MouseMove Events Parameters"},
|
||||
{(char *)"MouseButton", T_OBJECT, offsetof(PySfEvent, MouseButton), READONLY, (char *)"MouseButton Events Parameters"},
|
||||
{(char *)"MouseWheel", T_OBJECT, offsetof(PySfEvent, MouseWheel), READONLY, (char *)"MouseWheel Events Parameters"},
|
||||
{(char *)"JoyMove", T_OBJECT, offsetof(PySfEvent, JoyMove), READONLY, (char *)"JoyMove Events Parameters"},
|
||||
{(char *)"JoyButton", T_OBJECT, offsetof(PySfEvent, JoyButton), READONLY, (char *)"JoyButton Events Parameters"},
|
||||
{(char *)"Size", T_OBJECT, offsetof(PySfEvent, Size), READONLY, (char *)"Size Events Parameters"},
|
||||
{(char *)"Type", T_UINT, offsetof(PySfEvent, Type), READONLY, (char *)"Type Events Parameters"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventType = {
|
||||
head_init
|
||||
"Event", /*tp_name*/
|
||||
sizeof(PySfEvent), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEvent_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Event defines a system event and its parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEvent_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEvent_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
PySfEvent_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Event::KeyReleased);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "KeyReleased", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::LostFocus);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "LostFocus", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::GainedFocus);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "GainedFocus", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::KeyPressed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "KeyPressed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::MouseWheelMoved);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseWheelMoved", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::TextEntered);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "TextEntered", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::MouseMoved);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseMoved", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::JoyButtonPressed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonPressed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::MouseButtonReleased);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonReleased", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::Closed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "Closed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::MouseButtonPressed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonPressed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::JoyMoved);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "JoyMoved", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::JoyButtonReleased);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonReleased", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::Resized);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "Resized", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::MouseEntered);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseEntered", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Event::MouseLeft);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseLeft", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
105
bindings/python/src/Event.hpp
Normal file
105
bindings/python/src/Event.hpp
Normal file
|
@ -0,0 +1,105 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYEVENT_HPP
|
||||
#define __PYEVENT_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
unsigned int short Unicode;
|
||||
} PySfEventText;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
PyObject *Alt;
|
||||
PyObject *Control;
|
||||
PyObject *Shift;
|
||||
unsigned int Code;
|
||||
} PySfEventKey;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
int X;
|
||||
int Y;
|
||||
} PySfEventMouseMove;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
unsigned int Button;
|
||||
int X;
|
||||
int Y;
|
||||
} PySfEventMouseButton;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
int Delta;
|
||||
} PySfEventMouseWheel;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int JoystickId;
|
||||
unsigned int Axis;
|
||||
float Position;
|
||||
} PySfEventJoyMove;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int JoystickId;
|
||||
unsigned int Button;
|
||||
} PySfEventJoyButton;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
} PySfEventSize;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PySfEventText *Text;
|
||||
PySfEventKey *Key;
|
||||
PySfEventMouseMove *MouseMove;
|
||||
PySfEventMouseButton *MouseButton;
|
||||
PySfEventMouseWheel *MouseWheel;
|
||||
PySfEventJoyMove *JoyMove;
|
||||
PySfEventJoyButton *JoyButton;
|
||||
PySfEventSize *Size;
|
||||
unsigned int Type;
|
||||
sf::Event *obj;
|
||||
} PySfEvent;
|
||||
|
||||
void
|
||||
PySfEvent_InitConst();
|
||||
|
||||
#endif
|
200
bindings/python/src/Font.cpp
Normal file
200
bindings/python/src/Font.cpp
Normal file
|
@ -0,0 +1,200 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Font.hpp"
|
||||
#include "Glyph.hpp"
|
||||
#include "Image.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static void
|
||||
PySfFont_dealloc(PySfFont *self)
|
||||
{
|
||||
if (self->Owner)
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfFont *self;
|
||||
self = (PySfFont *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Owner = true;
|
||||
self->obj = new sf::Font();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_LoadFromFile( PySfFont* self, PyObject *args ) {
|
||||
char* Filename;
|
||||
bool result;
|
||||
|
||||
if( PyArg_ParseTuple( args, "s:Font.LoadFromFile", &Filename ) ) {
|
||||
result = self->obj->LoadFromFile(Filename);
|
||||
}
|
||||
else {
|
||||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyBool_FromLong( result );
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_LoadFromMemory( PySfFont* self, PyObject *args ) {
|
||||
unsigned int Size;
|
||||
char* Data;
|
||||
bool result;
|
||||
|
||||
if( PyArg_ParseTuple( args, "s#:Font.LoadFromMemory", &Data, &Size ) ) {
|
||||
result = self->obj->LoadFromMemory( Data, Size );
|
||||
}
|
||||
else {
|
||||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
return PyBool_FromLong( result );
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_GetDefaultFont(PySfFont* self, PyObject *args)
|
||||
{
|
||||
PySfFont *DefaultFont = GetNewPySfFont();
|
||||
DefaultFont->Owner = false;
|
||||
DefaultFont->obj = (sf::Font *)&(sf::Font::GetDefaultFont());
|
||||
return (PyObject *)DefaultFont;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_GetGlyph(PySfFont* self, PyObject *args) {
|
||||
unsigned int codepoint( 0 );
|
||||
unsigned int charsize( 0 );
|
||||
bool bold( false );
|
||||
|
||||
if( !PyArg_ParseTuple( args, "IIb:Font.LoadFromFile", &codepoint, &charsize, &bold ) ) {
|
||||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
|
||||
PySfGlyph* glyph( GetNewPySfGlyph() );
|
||||
|
||||
glyph->Owner = false;
|
||||
glyph->Rectangle = GetNewPySfIntRect();
|
||||
glyph->Rectangle->Owner = false;
|
||||
glyph->TexCoords = GetNewPySfFloatRect();
|
||||
glyph->TexCoords->Owner = false;
|
||||
|
||||
glyph->obj = const_cast<sf::Glyph*>( &( self->obj->GetGlyph( codepoint, charsize, bold ) ) );
|
||||
glyph->Rectangle->obj = &glyph->obj->Rectangle;
|
||||
glyph->TexCoords->obj = &glyph->obj->TexCoords;
|
||||
|
||||
PySfGlyphUpdateSelf( glyph );
|
||||
|
||||
return reinterpret_cast<PyObject*>( glyph );
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_GetImage( PySfFont* self, PyObject* args ) {
|
||||
PySfImage* image( GetNewPySfImage() );
|
||||
|
||||
image->obj = new sf::Image( self->obj->GetImage( PyLong_AsUnsignedLong( args ) ) );
|
||||
|
||||
return reinterpret_cast<PyObject*>( image );
|
||||
}
|
||||
|
||||
static PyMethodDef PySfFont_methods[] = {
|
||||
{"LoadFromFile", (PyCFunction)PySfFont_LoadFromFile, METH_VARARGS, "LoadFromFile(Filename))\n\
|
||||
Load the font from a file. Returns True if loading was successful.\n\
|
||||
Filename : Font file to load"},
|
||||
{"LoadFromMemory", (PyCFunction)PySfFont_LoadFromMemory, METH_VARARGS, "LoadFromMemory(Data)\n\
|
||||
Load the font from a file in memory. Returns True if loading was successful.\n\
|
||||
Data : data to load"},
|
||||
{"GetDefaultFont", (PyCFunction)PySfFont_GetDefaultFont, METH_NOARGS | METH_STATIC, "GetDefaultFont()\n\
|
||||
Get the SFML default built-in font (Arial)."},
|
||||
{"GetImage", (PyCFunction)PySfFont_GetImage, METH_O, "GetImage(characterSize)\n\
|
||||
Get the image containing the rendered characters (glyphs).\n\
|
||||
characterSize: Character size."},
|
||||
{"GetGlyph", (PyCFunction)PySfFont_GetGlyph, METH_VARARGS, "GetGlyph(codePoint, characterSize, bold)\n\
|
||||
Get the description of a glyph (character) given by its code point, character size and boldness. Returns glyph's visual settings, or an invalid glyph if character not found.\n\
|
||||
codePoint : Unicode code point value of the character to get.\n\
|
||||
characterSize: Size of character\n\
|
||||
bold: Bold character"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfFontType = {
|
||||
head_init
|
||||
"Font", /*tp_name*/
|
||||
sizeof(PySfFont), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfFont_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Font is the low-level class for loading and manipulating character fonts. This class is meant to be used by sf.String.\nDefault constructor : sf.Font().", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfFont_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfFont_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfFont *
|
||||
GetNewPySfFont()
|
||||
{
|
||||
return PyObject_New(PySfFont, &PySfFontType);
|
||||
}
|
||||
|
||||
|
42
bindings/python/src/Font.hpp
Normal file
42
bindings/python/src/Font.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYFONT_HPP
|
||||
#define __PYFONT_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool Owner;
|
||||
sf::Font *obj;
|
||||
} PySfFont;
|
||||
|
||||
PySfFont *
|
||||
GetNewPySfFont();
|
||||
|
||||
#endif
|
145
bindings/python/src/Glyph.cpp
Normal file
145
bindings/python/src/Glyph.cpp
Normal file
|
@ -0,0 +1,145 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Glyph.hpp"
|
||||
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyMemberDef PySfGlyph_members[] = {
|
||||
{(char *)"Advance", T_INT, offsetof(PySfGlyph, Advance), 0, (char *)"Offset to move horizontically to the next character."},
|
||||
{(char *)"Rectangle", T_OBJECT, offsetof(PySfGlyph, Rectangle), 0, (char *)"Bounding rectangle of the glyph, in relative coordinates."},
|
||||
{(char *)"TexCoords", T_OBJECT, offsetof(PySfGlyph, TexCoords), 0, (char *)"Texture coordinates of the glyph inside the bitmap font."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfGlyph_dealloc(PySfGlyph *self)
|
||||
{
|
||||
Py_CLEAR(self->Rectangle);
|
||||
Py_CLEAR(self->TexCoords);
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
void
|
||||
PySfGlyphUpdateObj(PySfGlyph *self)
|
||||
{
|
||||
self->obj->Advance = self->Advance;
|
||||
PySfIntRectUpdateSelf(self->Rectangle);
|
||||
PySfFloatRectUpdateSelf(self->TexCoords);
|
||||
}
|
||||
|
||||
void
|
||||
PySfGlyphUpdateSelf(PySfGlyph *self)
|
||||
{
|
||||
self->Advance = self->obj->Advance;
|
||||
PySfIntRectUpdateObj(self->Rectangle);
|
||||
PySfFloatRectUpdateObj(self->TexCoords);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfGlyph_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfGlyph *self;
|
||||
self = (PySfGlyph *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Rectangle = GetNewPySfIntRect();
|
||||
self->Rectangle->Owner = false;
|
||||
self->TexCoords = GetNewPySfFloatRect();
|
||||
self->TexCoords->Owner = false;
|
||||
self->obj = new sf::Glyph();
|
||||
self->Owner = true;
|
||||
self->Advance = self->obj->Advance;
|
||||
self->Rectangle->obj = &(self->obj->Rectangle);
|
||||
self->TexCoords->obj = &(self->obj->TexCoords);
|
||||
PySfIntRectUpdateSelf(self->Rectangle);
|
||||
PySfFloatRectUpdateSelf(self->TexCoords);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
int
|
||||
PySfGlyph_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||
{
|
||||
int result = PyObject_GenericSetAttr(self, attr_name, v);
|
||||
PySfGlyph *Glyph = (PySfGlyph *)self;
|
||||
Glyph->obj->Rectangle = *(Glyph->Rectangle->obj);
|
||||
Glyph->obj->TexCoords = *(Glyph->TexCoords->obj);
|
||||
Glyph->obj->Advance = Glyph->Advance;
|
||||
return result;
|
||||
}
|
||||
|
||||
PyTypeObject PySfGlyphType = {
|
||||
head_init
|
||||
"Glyph", /*tp_name*/
|
||||
sizeof(PySfGlyph), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfGlyph_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Structure describing a glyph (a visual character).", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfGlyph_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfGlyph_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfGlyph *
|
||||
GetNewPySfGlyph()
|
||||
{
|
||||
return PyObject_New(PySfGlyph, &PySfGlyphType);
|
||||
}
|
||||
|
53
bindings/python/src/Glyph.hpp
Normal file
53
bindings/python/src/Glyph.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYGLYPH_HPP
|
||||
#define __PYGLYPH_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Glyph.hpp>
|
||||
|
||||
#include "Rect.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool Owner;
|
||||
int Advance;
|
||||
PySfIntRect *Rectangle;
|
||||
PySfFloatRect *TexCoords;
|
||||
sf::Glyph *obj;
|
||||
} PySfGlyph;
|
||||
|
||||
PySfGlyph *
|
||||
GetNewPySfGlyph();
|
||||
|
||||
void
|
||||
PySfGlyphUpdateObj(PySfGlyph *self);
|
||||
|
||||
void
|
||||
PySfGlyphUpdateSelf(PySfGlyph *self);
|
||||
|
||||
#endif
|
410
bindings/python/src/Image.cpp
Normal file
410
bindings/python/src/Image.cpp
Normal file
|
@ -0,0 +1,410 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Image.hpp"
|
||||
#include "RenderWindow.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Rect.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfIntRectType;
|
||||
extern PyTypeObject PySfRenderWindowType;
|
||||
|
||||
static void
|
||||
PySfImage_dealloc(PySfImage* self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject *
|
||||
PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfColor *ColorTmp=NULL;
|
||||
sf::Color *Color;
|
||||
unsigned int Width=0, Height=0;
|
||||
const char *kwlist[] = {"Width", "Height", "Color", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!:Image.Create", (char **)kwlist, &Width, &Height, &PySfColorType, &ColorTmp))
|
||||
return NULL;
|
||||
|
||||
if (ColorTmp)
|
||||
{
|
||||
Color = ColorTmp->obj;
|
||||
PySfColorUpdate(ColorTmp);
|
||||
self->obj->Create(Width, Height, *Color);
|
||||
}
|
||||
else
|
||||
self->obj->Create(Width, Height);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_CopyScreen(PySfImage* self, PyObject *args)
|
||||
{
|
||||
PySfRenderWindow *RenderWindow;
|
||||
PySfIntRect *SourceRect=NULL;
|
||||
bool Result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!|O!:Image.CopyScreen", &PySfRenderWindowType, &RenderWindow, &PySfIntRectType, &SourceRect))
|
||||
return NULL;
|
||||
|
||||
|
||||
if (SourceRect)
|
||||
Result = self->obj->CopyScreen(*(RenderWindow->obj), *(SourceRect->obj));
|
||||
else
|
||||
Result = self->obj->CopyScreen(*(RenderWindow->obj));
|
||||
if (Result)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_SetPixel(PySfImage* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfColor *ColorTmp=NULL;
|
||||
sf::Color *Color;
|
||||
unsigned int x=0, y=0;
|
||||
const char *kwlist[] = {"x", "y", "Color", NULL};
|
||||
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|O!:Image.SetPixel", (char **)kwlist, &x, &y, &PySfColorType, &ColorTmp))
|
||||
return NULL;
|
||||
|
||||
|
||||
if (ColorTmp)
|
||||
{
|
||||
Color = ColorTmp->obj;
|
||||
PySfColorUpdate(ColorTmp);
|
||||
self->obj->SetPixel(x, y, *Color);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetPixel(PySfImage* self, PyObject *args)
|
||||
{
|
||||
PySfColor *Color;
|
||||
unsigned int x=0, y=0;
|
||||
|
||||
|
||||
if (!PyArg_ParseTuple(args, "II:Image.GetPixel", &x, &y))
|
||||
return NULL;
|
||||
|
||||
|
||||
Color = GetNewPySfColor();
|
||||
Color->obj = new sf::Color(self->obj->GetPixel(x, y));
|
||||
Color->r = Color->obj->r;
|
||||
Color->g = Color->obj->g;
|
||||
Color->b = Color->obj->b;
|
||||
Color->a = Color->obj->a;
|
||||
|
||||
return (PyObject *)Color;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_CreateMaskFromColor(PySfImage* self, PyObject *args)
|
||||
{
|
||||
PySfColor *ColorTmp= (PySfColor *)args;
|
||||
sf::Color *Color;
|
||||
|
||||
if (!PyObject_TypeCheck(ColorTmp, &PySfColorType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Image.CreateMaskFromColor() Argument must be a sf.Color");
|
||||
return NULL;
|
||||
}
|
||||
Color = ColorTmp->obj;
|
||||
PySfColorUpdate(ColorTmp);
|
||||
self->obj->CreateMaskFromColor(*Color);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_LoadFromMemory(PySfImage* self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes;
|
||||
char *Data;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#:Image.LoadFromMemory", &Data, &SizeInBytes))
|
||||
return NULL;
|
||||
|
||||
return PyBool_FromLong(self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_LoadFromPixels(PySfImage* self, PyObject *args)
|
||||
{
|
||||
unsigned int Width, Height, Size;
|
||||
char *Data;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "IIs#:Image.LoadFromPixels", &Width, &Height, &Data, &Size))
|
||||
return NULL;
|
||||
|
||||
self->obj->LoadFromPixels(Width, Height, (sf::Uint8*) Data);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetPixels(PySfImage *self)
|
||||
{
|
||||
#ifdef IS_PY3K
|
||||
return PyBytes_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
|
||||
#else
|
||||
return PyString_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_LoadFromFile (PySfImage *self, PyObject *args)
|
||||
{
|
||||
load_from_file(self, args);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_SaveToFile (PySfImage *self, PyObject *args)
|
||||
{
|
||||
save_to_file(self, args);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_Bind(PySfImage *self)
|
||||
{
|
||||
self->obj->Bind();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_SetSmooth (PySfImage *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetSmooth(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_IsSmooth (PySfImage *self)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->IsSmooth());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetWidth(PySfImage *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetWidth());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetHeight(PySfImage *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetHeight());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetValidSize(PySfImage* self, PyObject *args)
|
||||
{
|
||||
unsigned long S = PyLong_AsUnsignedLong(args);
|
||||
return PyLong_FromUnsignedLong(sf::Image::GetValidSize(S));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetTexCoords(PySfImage* self, PyObject *args)
|
||||
{
|
||||
PySfIntRect *RectArg = NULL;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!:Image.GetTextCoords", &PySfIntRectType, &RectArg))
|
||||
return NULL;
|
||||
|
||||
PySfFloatRect *Rect;
|
||||
|
||||
Rect = GetNewPySfFloatRect();
|
||||
Rect->Owner = true;
|
||||
Rect->obj = new sf::FloatRect(self->obj->GetTexCoords(*(RectArg->obj)));
|
||||
PySfFloatRectUpdateSelf(Rect);
|
||||
|
||||
return (PyObject *)Rect;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
int size = PyTuple_Size(args);
|
||||
if (size > 0)
|
||||
{
|
||||
if (PySfImage_Create(self, args, kwds) == NULL)
|
||||
{
|
||||
if (size != 3)
|
||||
return -1;
|
||||
else if (PySfImage_LoadFromPixels(self, args) == NULL)
|
||||
return -1;
|
||||
else PyErr_Clear();
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_Copy(PySfImage* self, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyMethodDef PySfImage_methods[] = {
|
||||
{"Copy", (PyCFunction)PySfImage_Copy, METH_VARARGS, "Copy(Source, DestX, DestY, SourceRect = sf.IntRect(0,0,0,0))\n\
|
||||
Copy pixels from another image onto this one. This function does a slow pixel copy and should only be used at initialization time.\n\
|
||||
Source : Source image to copy\n\
|
||||
DestX : X coordinate of the destination position\n\
|
||||
DestY : Y coordinate of the destination position\n\
|
||||
SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)\n\
|
||||
ApplyAlpha : Should the copy take in account the source transparency? (false by default)"},
|
||||
{"Create", (PyCFunction)PySfImage_Create, METH_VARARGS, "Create(Width=0, Height=0, Color=sf.Color.Black)\n\
|
||||
Create an empty image.\n\
|
||||
Width : Image width\n\
|
||||
Height : Image height\n\
|
||||
Col : Image color (black by default)"},
|
||||
{"CopyScreen", (PyCFunction)PySfImage_CopyScreen, METH_VARARGS, "CopyScreen(Window, SourceRect)\n\
|
||||
Create the image from the current contents of the given window. Return True if copy was successful.\n\
|
||||
Window : Window to capture\n\
|
||||
SourceRect : Sub-rectangle of the screen to copy (empty by default - entire image)"},
|
||||
{"SetPixel", (PyCFunction)PySfImage_SetPixel, METH_VARARGS | METH_KEYWORDS, "SetPixel(X, Y, Col)\nChange the color of a pixel.\n\
|
||||
X : X coordinate of pixel in the image\n Y : Y coordinate of pixel in the image\n Col : New color for pixel (X, Y)"},
|
||||
{"GetPixel", (PyCFunction)PySfImage_GetPixel, METH_VARARGS, "GetPixel(X, Y)\nGet a pixel from the image."},
|
||||
{"LoadFromFile", (PyCFunction)PySfImage_LoadFromFile, METH_O, "LoadFromFile(Path)\nLoad the surface from a file."},
|
||||
{"SaveToFile", (PyCFunction)PySfImage_SaveToFile, METH_O, "SaveToFile(Path)\nSave the content of the image to a file."},
|
||||
{"LoadFromMemory", (PyCFunction)PySfImage_LoadFromMemory, METH_VARARGS, "LoadFromMemory(Data)\nLoad the image from a file in memory."},
|
||||
{"LoadFromPixels", (PyCFunction)PySfImage_LoadFromPixels, METH_VARARGS, "LoadFromPixels(Width, Height, Data)\nLoad the image directly from a string of pixels."},
|
||||
{"GetPixels", (PyCFunction)PySfImage_GetPixels, METH_NOARGS, "GetPixels()\nGet a string representing the array of pixels (8 bits integers RGBA). String length is GetWidth() x GetHeight() x 4. This string becomes invalid if you reload or resize the image."},
|
||||
{"CreateMaskFromColor", (PyCFunction)PySfImage_CreateMaskFromColor, METH_O, "CreateMaskFromColor(Color)\nCreate transparency mask from a specified colorkey."},
|
||||
{"Bind", (PyCFunction)PySfImage_Bind, METH_NOARGS, "Bind()\nBind the image for rendering."},
|
||||
{"SetSmooth", (PyCFunction)PySfImage_SetSmooth, METH_O, "SetSmooth(Smooth)\nEnable or disable image smooth filter."},
|
||||
{"IsSmooth", (PyCFunction)PySfImage_IsSmooth, METH_NOARGS, "IsOpened(Smooth)\nTells whether the smooth filtering is enabled or not."},
|
||||
{"GetWidth", (PyCFunction)PySfImage_GetWidth, METH_NOARGS, "GetWidth()\nReturn the width of the image."},
|
||||
{"GetHeight", (PyCFunction)PySfImage_GetHeight, METH_NOARGS, "GetHeight()\nReturn the height of the image."},
|
||||
{"GetTexCoords", (PyCFunction)PySfImage_GetTexCoords, METH_VARARGS, "GetTexCoords(Rect)\nConvert a subrect expressed in pixels, into float texture coordinates. Returns texture coordinates corresponding to the sub-rectangle (sf.FloatRect instance)\n\
|
||||
Rect : Sub-rectangle of image to convert"},
|
||||
{"GetValidSize", (PyCFunction)PySfImage_GetValidSize, METH_STATIC | METH_O, "GetValidSize(Size)\nGet a valid texture size according to hardware support. Returns valid nearest size (greater than or equal to specified size).\n\
|
||||
Size : Size to convert"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfImageType = {
|
||||
head_init
|
||||
"Image", /*tp_name*/
|
||||
sizeof(PySfImage), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfImage_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Image is the low-level class for loading and manipulating images.\n\
|
||||
Default constructor : sf.Image()\n\
|
||||
Other constructors : sf.Image(Width=0, Height=0, Color=sf.Color.Black) or sf.Image(Width, Height, Data).\n\
|
||||
Copy constructor : sf.Image(Copy) where Copy is a sf.Image instance.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfImage_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfImage_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfImage_new, /* tp_new */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
PySfImage_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfImage *self;
|
||||
self = (PySfImage *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
if (PyTuple_Size(args) == 1)
|
||||
{
|
||||
PySfImage *Image;
|
||||
if (PyArg_ParseTuple(args, "O!", &PySfImageType, &Image))
|
||||
{
|
||||
self->obj = new sf::Image(*(Image->obj));
|
||||
}
|
||||
else PyErr_Clear();
|
||||
}
|
||||
else self->obj = new sf::Image();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_Copy(PySfImage* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Source", "DestX", "DestY", "SourceRect", "ApplyAlpha", NULL};
|
||||
PySfIntRect *SourceRect = NULL;
|
||||
PySfImage *Source = NULL;
|
||||
unsigned int DestX, DestY;
|
||||
PyObject *PyApplyAlpha = NULL;
|
||||
bool ApplyAlpha = false;
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!II|O!O:Image.Copy", (char **)kwlist, &PySfImageType, &Source, &DestX, &DestY, &PySfIntRectType, &SourceRect, &PyApplyAlpha))
|
||||
return NULL;
|
||||
|
||||
if (PyApplyAlpha)
|
||||
if (PyObject_IsTrue(PyApplyAlpha))
|
||||
ApplyAlpha = true;
|
||||
|
||||
if (SourceRect)
|
||||
self->obj->Copy(*(Source->obj), DestX, DestY, *(SourceRect->obj), ApplyAlpha);
|
||||
else
|
||||
self->obj->Copy(*(Source->obj), DestX, DestY, sf::IntRect(0, 0, 0, 0), ApplyAlpha);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
PySfImage *
|
||||
GetNewPySfImage()
|
||||
{
|
||||
return PyObject_New(PySfImage, &PySfImageType);
|
||||
}
|
||||
|
42
bindings/python/src/Image.hpp
Normal file
42
bindings/python/src/Image.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYIMAGE_HPP
|
||||
#define __PYIMAGE_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Image *obj;
|
||||
} PySfImage;
|
||||
|
||||
PySfImage *
|
||||
GetNewPySfImage();
|
||||
|
||||
#endif
|
||||
|
134
bindings/python/src/Input.cpp
Normal file
134
bindings/python/src/Input.cpp
Normal file
|
@ -0,0 +1,134 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Input.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfInput_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "You can't create an Input object yourself, because an Input object must always be associated to its window.\nThe only way to get an Input is by creating a window and calling : Input = MyWindow.GetInput().");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_IsKeyDown(PySfInput *self, PyObject *args)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->IsKeyDown( (sf::Key::Code) PyLong_AsLong(args) ));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_IsMouseButtonDown(PySfInput *self, PyObject *args)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->IsMouseButtonDown( (sf::Mouse::Button) PyLong_AsLong(args) ));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_IsJoystickButtonDown(PySfInput *self, PyObject *args)
|
||||
{
|
||||
unsigned int JoyId, Button;
|
||||
if (! PyArg_ParseTuple (args, "II:Input.IsJoystickButtonDown", &JoyId, &Button))
|
||||
return NULL;
|
||||
return PyBool_FromLong(self->obj->IsJoystickButtonDown(JoyId, Button));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_GetMouseX(PySfInput *self)
|
||||
{
|
||||
return PyLong_FromLong(self->obj->GetMouseX());
|
||||
}
|
||||
static PyObject*
|
||||
PySfInput_GetMouseY(PySfInput *self)
|
||||
{
|
||||
return PyLong_FromLong(self->obj->GetMouseY());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_GetJoystickAxis(PySfInput *self, PyObject *args)
|
||||
{
|
||||
unsigned int JoyId, Axis;
|
||||
if (! PyArg_ParseTuple (args, "II:Input.GetJoystickAxis", &JoyId, &Axis))
|
||||
return NULL;
|
||||
return PyFloat_FromDouble(self->obj->GetJoystickAxis(JoyId, (sf::Joy::Axis) Axis));
|
||||
}
|
||||
|
||||
static PyMethodDef PySfInput_methods[] = {
|
||||
{"IsKeyDown", (PyCFunction)PySfInput_IsKeyDown, METH_O, "IsKeyDown(KeyCode)\nGet the state of a key. Returns True if key is down, false if key is up.\n KeyCode : Key to check"},
|
||||
{"IsMouseButtonDown", (PyCFunction)PySfInput_IsMouseButtonDown, METH_O, "IsMouseButtonDown(Button)\nGet the state of a mouse button. Returns True if button is down, false if button is up.\n Button : Button to check"},
|
||||
{"IsJoystickButtonDown", (PyCFunction)PySfInput_IsJoystickButtonDown, METH_VARARGS, "IsJoystickButtonDown(JoyId, Button)\nGet the state of a joystick button. Returns True if button is down, false if button is up.\n JoyId : Identifier of the joystick to check (0 or 1)\n Button : Button to check"},
|
||||
{"GetMouseX", (PyCFunction)PySfInput_GetMouseX, METH_NOARGS, "GetMouseX()\nGet the mouse X position."},
|
||||
{"GetMouseY", (PyCFunction)PySfInput_GetMouseY, METH_NOARGS, "GetMouseY()\nGet the mouse Y position."},
|
||||
{"GetJoystickAxis", (PyCFunction)PySfInput_GetJoystickAxis, METH_VARARGS, "GetJoystickAxis(JoyId, Axis)\nGet a joystick axis position. Returns current axis position, in the range [-100, 100] (except for POV, which is [0, 360])\n JoyId : Identifier of the joystick to check (0 or 1)\n Axis : Axis to get"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfInputType = {
|
||||
head_init
|
||||
"Input", /*tp_name*/
|
||||
sizeof(PySfInput), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Input handles real-time input from keyboard and mouse. Use it instead of events to handle continuous moves and more game-friendly inputs.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfInput_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfInput_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfInput *
|
||||
GetNewPySfInput()
|
||||
{
|
||||
return PyObject_New(PySfInput, &PySfInputType);
|
||||
}
|
||||
|
40
bindings/python/src/Input.hpp
Normal file
40
bindings/python/src/Input.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYINPUT_HPP
|
||||
#define __PYINPUT_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/Input.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Input *obj;
|
||||
} PySfInput;
|
||||
|
||||
PySfInput *
|
||||
GetNewPySfInput();
|
||||
|
||||
#endif
|
114
bindings/python/src/Joy.cpp
Normal file
114
bindings/python/src/Joy.cpp
Normal file
|
@ -0,0 +1,114 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Joy.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfJoy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfJoy *self;
|
||||
self = (PySfJoy *)type->tp_alloc(type, 0);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
PyTypeObject PySfJoyType = {
|
||||
head_init
|
||||
"Joy", /*tp_name*/
|
||||
sizeof(PySfJoy), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Definition of joystick axis for joystick events.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfJoy_new, /* tp_new */
|
||||
};
|
||||
|
||||
void PySfJoy_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Joy::AxisX);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisX", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::AxisY);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisY", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::AxisZ);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisZ", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::AxisR);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisR", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::AxisU);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisU", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::AxisV);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisV", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::AxisPOV);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisPOV", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::Count);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "Count", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::AxisCount);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisCount", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Joy::ButtonCount);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "ButtonCount", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
39
bindings/python/src/Joy.hpp
Normal file
39
bindings/python/src/Joy.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYJOY_HPP
|
||||
#define __PYJOY_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfJoy;
|
||||
|
||||
void
|
||||
PySfJoy_InitConst();
|
||||
|
||||
#endif
|
385
bindings/python/src/Key.cpp
Normal file
385
bindings/python/src/Key.cpp
Normal file
|
@ -0,0 +1,385 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Key.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
static PyObject *
|
||||
PySfKey_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfKey *self;
|
||||
self = (PySfKey *)type->tp_alloc(type, 0);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
PyTypeObject PySfKeyType = {
|
||||
head_init
|
||||
"Key", /*tp_name*/
|
||||
sizeof(PySfKey), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Definition of key codes for keyboard events.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfKey_new, /* tp_new */
|
||||
};
|
||||
|
||||
void PySfKey_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Key::Numpad2);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad2", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad3);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad3", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad0);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad0", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad1);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad6);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad6", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad7);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad7", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad4);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad4", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad5);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad5", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad8);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad8", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Numpad9);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad9", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::RAlt);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RAlt", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::PageUp);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "PageUp", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Multiply);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Multiply", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::D);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "D", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::SemiColon);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "SemiColon", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::H);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "H", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::L);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "L", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::P);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "P", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num7);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num7", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::T);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "T", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::X);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "X", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::RSystem);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RSystem", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F5);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F5", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num4);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num4", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num5);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num5", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num6);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num6", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Right);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Right", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num0);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num0", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num1);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num2);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num2", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num3);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num3", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::LControl);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LControl", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num8);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num8", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Num9);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num9", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Tab);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Tab", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::RBracket);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RBracket", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::End);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "End", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::BackSlash);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "BackSlash", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::LShift);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LShift", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::E);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "E", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::C);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "C", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::G);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "G", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::K);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "K", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Up);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Up", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::O);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "O", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::S);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "S", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::W);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "W", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F12);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F12", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F13);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F13", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F10);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F10", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F11);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F11", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F14);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F14", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Delete);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Delete", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Back);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Back", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Tilde);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Tilde", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Home);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Home", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Pause);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Pause", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Add);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Add", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F15);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F15", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Subtract);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Subtract", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::B);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "B", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::J);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "J", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::N);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "N", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::LBracket);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LBracket", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::R);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "R", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::V);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "V", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::LSystem);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LSystem", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Z);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Z", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Left);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Left", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F1);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F2);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F2", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F3);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F3", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F4);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F4", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Divide);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Divide", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F6);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F6", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F7);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F7", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F8);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F8", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::F9);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F9", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Period);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Period", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Down);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Down", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::PageDown);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "PageDown", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Space);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Space", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Menu);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Menu", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::RControl);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RControl", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Slash);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Slash", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Return);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Return", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Quote);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Quote", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::A);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "A", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Insert);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Insert", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::RShift);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RShift", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::I);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "I", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Escape);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Escape", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::M);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "M", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Equal);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Equal", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Q);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Q", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::U);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "U", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Y);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Y", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Dash);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Dash", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::Comma);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Comma", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Key::LAlt);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LAlt", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
39
bindings/python/src/Key.hpp
Normal file
39
bindings/python/src/Key.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYKEY_HPP
|
||||
#define __PYKEY_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfKey;
|
||||
|
||||
void
|
||||
PySfKey_InitConst();
|
||||
|
||||
#endif
|
128
bindings/python/src/Listener.cpp
Normal file
128
bindings/python/src/Listener.cpp
Normal file
|
@ -0,0 +1,128 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Listener.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfListener_SetGlobalVolume(PySfListener* self, PyObject *args)
|
||||
{
|
||||
sf::Listener::SetGlobalVolume(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_GetGlobalVolume(PySfListener* self)
|
||||
{
|
||||
return PyFloat_FromDouble(sf::Listener::GetGlobalVolume());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_SetPosition(PySfListener* self, PyObject *args)
|
||||
{
|
||||
float X, Y, Z;
|
||||
if (!PyArg_ParseTuple(args, "fff:Listener.SetPosition", &X, &Y, &Z))
|
||||
return NULL;
|
||||
sf::Listener::SetPosition(X, Y, Z);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfListener_GetPosition(PySfListener *self)
|
||||
{
|
||||
sf::Vector3f Vect = sf::Listener::GetPosition();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_SetDirection(PySfListener* self, PyObject *args)
|
||||
{
|
||||
float X, Y, Z;
|
||||
if (!PyArg_ParseTuple(args, "fff:Listener.SetDirection", &X, &Y, &Z))
|
||||
return NULL;
|
||||
sf::Listener::SetDirection(X, Y, Z);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfListener_GetDirection(PySfListener *self)
|
||||
{
|
||||
sf::Vector3f Vect = sf::Listener::GetDirection();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
static PyMethodDef PySfListener_methods[] = {
|
||||
{"SetGlobalVolume", (PyCFunction)PySfListener_SetGlobalVolume, METH_STATIC | METH_O, "SetGlobalVolume(Volume)\nChange the global volume of all the sounds."},
|
||||
{"GetGlobalVolume", (PyCFunction)PySfListener_GetGlobalVolume, METH_STATIC | METH_NOARGS, "GetGlobalVolume()\nGet the current value of the global volume of all the sounds."},
|
||||
{"SetPosition", (PyCFunction)PySfListener_SetPosition, METH_STATIC | METH_VARARGS, "SetPosition(X, Y, Z)\nChange the position of the listener."},
|
||||
{"GetPosition", (PyCFunction)PySfListener_GetPosition, METH_STATIC | METH_NOARGS, "GetPosition()\nGet the current position of the listener."},
|
||||
{"SetDirection", (PyCFunction)PySfListener_SetDirection, METH_STATIC | METH_VARARGS, "SetDirection(X, Y, Z)\nChange the orientation of the listener (the point he must look at)"},
|
||||
{"GetDirection", (PyCFunction)PySfListener_GetDirection, METH_STATIC | METH_NOARGS, "GetDirection()\nGet the current orientation of the listener (the point he's looking at)"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfListenerType = {
|
||||
head_init
|
||||
"Listener", /*tp_name*/
|
||||
sizeof(PySfListener), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Listener is a global interface for defining the audio listener properties ; the audio listener is the point in the scene from where all the sounds are heard.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfListener_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
0, /* tp_new */
|
||||
};
|
||||
|
||||
|
37
bindings/python/src/Listener.hpp
Normal file
37
bindings/python/src/Listener.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYLISTENER_HPP
|
||||
#define __PYLISTENER_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Audio/Listener.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfListener;
|
||||
|
||||
#endif
|
102
bindings/python/src/Mouse.cpp
Normal file
102
bindings/python/src/Mouse.cpp
Normal file
|
@ -0,0 +1,102 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Mouse.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfMouse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfMouse *self;
|
||||
self = (PySfMouse *)type->tp_alloc(type, 0);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
PyTypeObject PySfMouseType = {
|
||||
head_init
|
||||
"Mouse", /*tp_name*/
|
||||
sizeof(PySfMouse), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Definition of button codes for mouse events.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfMouse_new, /* tp_new */
|
||||
};
|
||||
|
||||
void PySfMouse_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Mouse::Left);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Left", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Mouse::Right);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Right", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Mouse::Middle);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Middle", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Mouse::XButton1);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Mouse::XButton2);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton2", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Mouse::ButtonCount);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "ButtonCount", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
39
bindings/python/src/Mouse.hpp
Normal file
39
bindings/python/src/Mouse.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYMOUSE_HPP
|
||||
#define __PYMOUSE_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfMouse;
|
||||
|
||||
void
|
||||
PySfMouse_InitConst();
|
||||
|
||||
#endif
|
140
bindings/python/src/Music.cpp
Normal file
140
bindings/python/src/Music.cpp
Normal file
|
@ -0,0 +1,140 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Music.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfSoundStreamType;
|
||||
|
||||
|
||||
static void
|
||||
PySfMusic_dealloc(PySfMusic *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfMusic_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfMusic *self;
|
||||
self = (PySfMusic *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->obj = new sf::Music();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfMusic_OpenFromMemory(PySfMusic *self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes;
|
||||
char *Data;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#:Music.OpenFromMemory", &Data, &SizeInBytes))
|
||||
return NULL;
|
||||
|
||||
return PyBool_FromLong(self->obj->OpenFromMemory(Data, (std::size_t) SizeInBytes));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfMusic_OpenFromFile(PySfMusic *self, PyObject *args)
|
||||
{
|
||||
char *path;
|
||||
#ifdef IS_PY3K
|
||||
PyObject *string = PyUnicode_AsUTF8String(args);
|
||||
if (string == NULL)
|
||||
return NULL;
|
||||
path = PyBytes_AsString(string);
|
||||
#else
|
||||
path = PyString_AsString(args);
|
||||
#endif
|
||||
bool result = self->obj->OpenFromFile(path);
|
||||
#ifdef IS_PY3K
|
||||
Py_DECREF(string);
|
||||
#endif
|
||||
return PyBool_FromLong(result);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfMusic_GetDuration(PySfMusic *self)
|
||||
{
|
||||
return PyFloat_FromDouble((double)(self->obj->GetDuration()));
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfMusic_methods[] = {
|
||||
{"OpenFromFile", (PyCFunction)PySfMusic_OpenFromFile, METH_O, "OpenFromFile(Filename)\nOpen a music file (doesn't play it -- call Play() for that). Returns True if loading has been successful.\n Filename : Path of the music file to open"},
|
||||
{"OpenFromMemory", (PyCFunction)PySfMusic_OpenFromMemory, METH_VARARGS, "OpenFromMemory(Data)\nOpen a music file (doesn't play it -- call Play() for that). Returns True if loading has been successful.\n Data : string representing the file data in memory"},
|
||||
{"GetDuration", (PyCFunction)PySfMusic_GetDuration, METH_NOARGS, "GetDuration()\nGet the sound duration."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfMusicType = {
|
||||
head_init
|
||||
"Music", /*tp_name*/
|
||||
sizeof(PySfMusic), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfMusic_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Music defines a big sound played using streaming, so usually what we call a music :).\n\
|
||||
Constructor: sf.Music()", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfMusic_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfSoundStreamType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfMusic_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
37
bindings/python/src/Music.hpp
Normal file
37
bindings/python/src/Music.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYMUSIC_HPP
|
||||
#define __PYMUSIC_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Audio/Music.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Music *obj;
|
||||
} PySfMusic;
|
||||
|
||||
#endif
|
394
bindings/python/src/Rect.cpp
Normal file
394
bindings/python/src/Rect.cpp
Normal file
|
@ -0,0 +1,394 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Rect.hpp"
|
||||
|
||||
#include <structmember.h>
|
||||
|
||||
#include "compat.hpp"
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
static PyMemberDef PySfIntRect_members[] = {
|
||||
{(char *)"Left", T_INT, offsetof(PySfIntRect, Left), 0, (char *)"Left coordinate of the rectangle."},
|
||||
{(char *)"Top", T_INT, offsetof(PySfIntRect, Top), 0, (char *)"Top coordinate of the rectangle."},
|
||||
{(char *)"Right", T_INT, offsetof(PySfIntRect, Right), 0, (char *)"Right coordinate of the rectangle."},
|
||||
{(char *)"Bottom", T_INT, offsetof(PySfIntRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static PyMemberDef PySfFloatRect_members[] = {
|
||||
{(char *)"Left", T_FLOAT, offsetof(PySfFloatRect, Left), 0, (char *)"Left coordinate of the rectangle."},
|
||||
{(char *)"Top", T_FLOAT, offsetof(PySfFloatRect, Top), 0, (char *)"Top coordinate of the rectangle."},
|
||||
{(char *)"Right", T_FLOAT, offsetof(PySfFloatRect, Right), 0, (char *)"Right coordinate of the rectangle."},
|
||||
{(char *)"Bottom", T_FLOAT, offsetof(PySfFloatRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static void
|
||||
PySfIntRect_dealloc(PySfIntRect* self)
|
||||
{
|
||||
if (self->Owner)
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static void
|
||||
PySfFloatRect_dealloc(PySfFloatRect* self)
|
||||
{
|
||||
if (self->Owner)
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
|
||||
PySfIntRect *self;
|
||||
self = (PySfIntRect *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Owner = true;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiii:IntRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Right), &(self->Bottom)))
|
||||
return NULL;
|
||||
self->obj = new sf::IntRect(self->Left, self->Top, self->Right, self->Bottom);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
|
||||
PySfFloatRect *self;
|
||||
self = (PySfFloatRect *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Owner = true;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffff:FloatRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Right), &(self->Bottom)))
|
||||
return NULL;
|
||||
self->obj = new sf::FloatRect(self->Left, self->Top, self->Right, self->Bottom);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_GetSize(PySfIntRect *self)
|
||||
{
|
||||
sf::Vector2i size( self->obj->GetSize() );
|
||||
return Py_BuildValue( "ii", size.x, size.y );
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Contains(PySfIntRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Intersects(PySfIntRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_GetSize(PySfFloatRect *self)
|
||||
{
|
||||
sf::Vector2f size( self->obj->GetSize() );
|
||||
return Py_BuildValue( "ff", size.x, size.y );
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Offset(PySfIntRect* self, PyObject *args)
|
||||
{
|
||||
int OffsetX, OffsetY;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii:IntRect.Offset", &OffsetX, &OffsetY))
|
||||
return NULL;
|
||||
|
||||
self->obj->Offset(OffsetX, OffsetY);
|
||||
PySfIntRectUpdateSelf(self);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args)
|
||||
{
|
||||
float OffsetX, OffsetY;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ff:FloatRect.Offset", &OffsetX, &OffsetY))
|
||||
return NULL;
|
||||
|
||||
self->obj->Offset(OffsetX, OffsetY);
|
||||
PySfFloatRectUpdateSelf(self);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfIntRect_methods[] = {
|
||||
{"Offset", (PyCFunction)PySfIntRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
|
||||
Move the whole rectangle by the given offset.\n\
|
||||
OffsetX : Horizontal offset\n\
|
||||
OffsetY : Vertical offset\n\
|
||||
"},
|
||||
{"GetSize", (PyCFunction)PySfIntRect_GetSize, METH_NOARGS, "GetSize()\nGet the rectangle's size."},
|
||||
{"Contains", (PyCFunction)PySfIntRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
|
||||
Check if a point is inside the rectangle's area.\n\
|
||||
X : X coordinate of the point to test\n\
|
||||
Y : Y coordinate of the point to test"},
|
||||
{"Intersects", (PyCFunction)PySfIntRect_Intersects, METH_VARARGS, "Intersects(Rectangle, OverlappingRect=None)\n\
|
||||
Check intersection between two rectangles.\n\
|
||||
Rectangle : Rectangle to test\n\
|
||||
OverlappingRect : Rectangle to be filled with overlapping rect (None by default)"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static PyMethodDef PySfFloatRect_methods[] = {
|
||||
{"Offset", (PyCFunction)PySfFloatRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
|
||||
Move the whole rectangle by the given offset.\n\
|
||||
OffsetX : Horizontal offset\n\
|
||||
OffsetY : Vertical offset\n\
|
||||
"},
|
||||
{"GetSize", (PyCFunction)PySfFloatRect_GetSize, METH_NOARGS, "GetSize()\nGet the rectangle's size."},
|
||||
{"Contains", (PyCFunction)PySfFloatRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
|
||||
Check if a point is inside the rectangle's area.\n\
|
||||
X : X coordinate of the point to test\n\
|
||||
Y : Y coordinate of the point to test"},
|
||||
{"Intersects", (PyCFunction)PySfFloatRect_Intersects, METH_VARARGS, "Intersects(Rectangle, OverlappingRect=None)\n\
|
||||
Check intersection between two rectangles.\n\
|
||||
Rectangle : Rectangle to test\n\
|
||||
OverlappingRect : Rectangle to be filled with overlapping rect (None by default)"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
int
|
||||
PySfIntRect_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||
{
|
||||
int result = PyObject_GenericSetAttr(self, attr_name, v);
|
||||
PySfIntRect *Rect = (PySfIntRect *)self;
|
||||
PySfIntRectUpdateObj(Rect);
|
||||
return result;
|
||||
}
|
||||
|
||||
int
|
||||
PySfFloatRect_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||
{
|
||||
int result = PyObject_GenericSetAttr(self, attr_name, v);
|
||||
PySfFloatRect *Rect = (PySfFloatRect *)self;
|
||||
PySfFloatRectUpdateObj(Rect);
|
||||
return result;
|
||||
}
|
||||
|
||||
PyTypeObject PySfIntRectType = {
|
||||
head_init
|
||||
"IntRect", /*tp_name*/
|
||||
sizeof(PySfIntRect), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfIntRect_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
PySfIntRect_setattro, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.IntRect is an utility class for manipulating rectangles.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfIntRect_methods, /* tp_methods */
|
||||
PySfIntRect_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfIntRect_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfFloatRectType = {
|
||||
head_init
|
||||
"FloatRect", /*tp_name*/
|
||||
sizeof(PySfFloatRect), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfFloatRect_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
PySfFloatRect_setattro, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.FloatRect is an utility class for manipulating rectangles.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfFloatRect_methods, /* tp_methods */
|
||||
PySfFloatRect_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfFloatRect_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args)
|
||||
{
|
||||
float x=0, y=0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ff:FloatRect.Contains", &x, &y))
|
||||
return NULL;
|
||||
|
||||
return PyBool_FromLong(self->obj->Contains(x,y));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args)
|
||||
{
|
||||
PySfFloatRect *Rect=NULL, *Intersection=NULL;
|
||||
bool result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!|O!:FloatRect.Intersects", &PySfFloatRectType, &Rect, &PySfFloatRectType, &Intersection))
|
||||
return NULL;
|
||||
|
||||
if (Intersection)
|
||||
result = self->obj->Intersects(*(Rect->obj), *(Intersection->obj));
|
||||
else
|
||||
result = self->obj->Intersects(*(Rect->obj));
|
||||
|
||||
return PyBool_FromLong(result);
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Contains(PySfIntRect* self, PyObject *args)
|
||||
{
|
||||
unsigned int x=0, y=0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "II:IntRect.Contains", &x, &y))
|
||||
return NULL;
|
||||
|
||||
return PyBool_FromLong(self->obj->Contains(x,y));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Intersects(PySfIntRect* self, PyObject *args)
|
||||
{
|
||||
PySfIntRect *Rect=NULL, *Intersection=NULL;
|
||||
bool result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!|O!:IntRect.Intersects", &PySfIntRectType, &Rect, &PySfIntRectType, &Intersection))
|
||||
return NULL;
|
||||
|
||||
if (Intersection)
|
||||
result = self->obj->Intersects(*(Rect->obj), *(Intersection->obj));
|
||||
else
|
||||
result = self->obj->Intersects(*(Rect->obj));
|
||||
|
||||
return PyBool_FromLong(result);
|
||||
}
|
||||
|
||||
void
|
||||
PySfIntRectUpdateObj(PySfIntRect *self)
|
||||
{
|
||||
self->obj->Left = self->Left;
|
||||
self->obj->Right = self->Right;
|
||||
self->obj->Top = self->Top;
|
||||
self->obj->Bottom = self->Bottom;
|
||||
}
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateObj(PySfFloatRect *self)
|
||||
{
|
||||
self->obj->Left = self->Left;
|
||||
self->obj->Right = self->Right;
|
||||
self->obj->Top = self->Top;
|
||||
self->obj->Bottom = self->Bottom;
|
||||
}
|
||||
|
||||
void
|
||||
PySfIntRectUpdateSelf(PySfIntRect *self)
|
||||
{
|
||||
self->Left = self->obj->Left;
|
||||
self->Right = self->obj->Right;
|
||||
self->Top = self->obj->Top;
|
||||
self->Bottom = self->obj->Bottom;
|
||||
}
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateSelf(PySfFloatRect *self)
|
||||
{
|
||||
self->Left = self->obj->Left;
|
||||
self->Right = self->obj->Right;
|
||||
self->Top = self->obj->Top;
|
||||
self->Bottom = self->obj->Bottom;
|
||||
}
|
||||
|
||||
PySfIntRect *
|
||||
GetNewPySfIntRect()
|
||||
{
|
||||
return PyObject_New(PySfIntRect, &PySfIntRectType);
|
||||
}
|
||||
|
||||
PySfFloatRect *
|
||||
GetNewPySfFloatRect()
|
||||
{
|
||||
return PyObject_New(PySfFloatRect, &PySfFloatRectType);
|
||||
}
|
||||
|
||||
|
70
bindings/python/src/Rect.hpp
Normal file
70
bindings/python/src/Rect.hpp
Normal file
|
@ -0,0 +1,70 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYRECT_HPP
|
||||
#define __PYRECT_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool Owner;
|
||||
int Left;
|
||||
int Right;
|
||||
int Top;
|
||||
int Bottom;
|
||||
sf::IntRect *obj;
|
||||
} PySfIntRect;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool Owner;
|
||||
float Left;
|
||||
float Right;
|
||||
float Top;
|
||||
float Bottom;
|
||||
sf::FloatRect *obj;
|
||||
} PySfFloatRect;
|
||||
|
||||
PySfIntRect *
|
||||
GetNewPySfIntRect();
|
||||
|
||||
PySfFloatRect *
|
||||
GetNewPySfFloatRect();
|
||||
|
||||
void
|
||||
PySfIntRectUpdateObj(PySfIntRect *self);
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateObj(PySfFloatRect *self);
|
||||
|
||||
void
|
||||
PySfIntRectUpdateSelf(PySfIntRect *self);
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateSelf(PySfFloatRect *self);
|
||||
|
||||
#endif
|
94
bindings/python/src/RenderQueue.cpp
Normal file
94
bindings/python/src/RenderQueue.cpp
Normal file
|
@ -0,0 +1,94 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007-2009 Rémi Koenig (remi.k2620@gmail.com)
|
||||
// Stefan "Tank" Schindler <stefan@boxbox.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RenderQueue.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
static void
|
||||
PySfRenderQueue_dealloc(PySfRenderQueue* self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object( self );
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfRenderQueue_new(PyTypeObject* type, PyObjects* args, PyObject* kwds)
|
||||
{
|
||||
PySfRenderQueue* self(static_cast<PySfRenderQueue*>(type->tp_alloc(type, 0)));
|
||||
|
||||
if(self != 0)
|
||||
{
|
||||
self->obj = new sf::RenderQueue();
|
||||
}
|
||||
|
||||
return static_cast<PyObject*>( self )
|
||||
}
|
||||
|
||||
static PyMethodDef PySfImage_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfImageType = {
|
||||
head_init
|
||||
"RenderQueue", /*tp_name*/
|
||||
sizeof(PySfRenderQueue), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfRenderQueue_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Implements a queue of rendering commands.\n\
|
||||
Default constructor : sf.RenderQueue()" /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfRenderQueue_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfRenderQueue_new, /* tp_new */
|
||||
};
|
40
bindings/python/src/RenderQueue.hpp
Normal file
40
bindings/python/src/RenderQueue.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007-2009 Rémi Koenig (remi.k2620@gmail.com)
|
||||
// Stefan "Tank" Schindler <stefan@boxbox.org>
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYRENDERQUEUE_H
|
||||
#define __PYRENDERQUEUE_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/RenderQueue.hpp>
|
||||
|
||||
struct PySfRenderQueue {
|
||||
PyObject_HEAD
|
||||
sf::RenderQueue* obj;
|
||||
};
|
||||
|
||||
PySfRenderQueue* GetNewPySfRenderQueue();
|
||||
|
||||
#endif
|
286
bindings/python/src/RenderWindow.cpp
Normal file
286
bindings/python/src/RenderWindow.cpp
Normal file
|
@ -0,0 +1,286 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RenderWindow.hpp"
|
||||
#include "Image.hpp"
|
||||
#include "Window.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Drawable.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
|
||||
|
||||
extern PyTypeObject PySfViewType;
|
||||
extern PyTypeObject PySfWindowType;
|
||||
extern PyTypeObject PySfRenderWindowType;
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
|
||||
static void
|
||||
PySfRenderWindow_dealloc(PySfRenderWindow* self)
|
||||
{
|
||||
Py_CLEAR(self->View);
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfRenderWindow *self;
|
||||
self = (PySfRenderWindow *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->obj = new sf::RenderWindow();
|
||||
self->View = NULL;
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_ConvertCoords(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
unsigned int WindowX, WindowY;
|
||||
PySfView *PyTargetView = NULL;
|
||||
sf::Vector2f Vect;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "II|O!:RenderWindow.ConvertCoords", &WindowX, &WindowY, &PySfViewType, &PyTargetView))
|
||||
return NULL;
|
||||
|
||||
if (PyTargetView)
|
||||
{
|
||||
Vect = self->obj->ConvertCoords(WindowX, WindowY, *PyTargetView->obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vect = self->obj->ConvertCoords(WindowX, WindowY);
|
||||
}
|
||||
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static bool
|
||||
PySfRenderWindow_DrawObject(PySfRenderWindow *RenderWindow, PySfDrawable *Obj)
|
||||
{
|
||||
if (PyObject_TypeCheck((PyObject *)Obj, &PySfDrawableType))
|
||||
{
|
||||
if (Obj->IsCustom)
|
||||
{
|
||||
Py_CLEAR(Obj->obj->RenderWindow);
|
||||
Py_INCREF(RenderWindow);
|
||||
Obj->obj->RenderWindow = RenderWindow;
|
||||
}
|
||||
RenderWindow->obj->Draw(*(Obj->obj));
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_Draw(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
if (args == NULL)
|
||||
return NULL;
|
||||
if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)args))
|
||||
{
|
||||
PyObject *iterator = PyObject_GetIter(args);
|
||||
PyObject *item;
|
||||
PyErr_Clear();
|
||||
if (iterator == NULL)
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Argument to Draw method is neither a Drawable nor an iterable.");
|
||||
return NULL;
|
||||
}
|
||||
while ((item = PyIter_Next(iterator)))
|
||||
{
|
||||
if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)item))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Object in iterable not a Drawable.");
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(item);
|
||||
}
|
||||
Py_DECREF(iterator);
|
||||
}
|
||||
if (PyErr_Occurred())
|
||||
return NULL;
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_Clear(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
PySfColor *Color = NULL;
|
||||
if (!PyArg_ParseTuple(args, "|O!:RenderWindow.Clear", &PySfColorType, &Color))
|
||||
return NULL;
|
||||
if (Color == NULL) self->obj->Clear(sf::Color::Black);
|
||||
else
|
||||
{
|
||||
PySfColorUpdate(Color);
|
||||
self->obj->Clear(*(Color->obj));
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_SetActive(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
PyObject* Active( 0 );
|
||||
|
||||
PyArg_ParseTuple( args, "|O", &Active );
|
||||
self->obj->SetActive( Active == 0 ? true : PyBool_AsBool( Active ) );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_GetView(PySfRenderWindow *self)
|
||||
{
|
||||
if (self->View != NULL)
|
||||
{
|
||||
Py_INCREF(self->View);
|
||||
return (PyObject *)(self->View);
|
||||
}
|
||||
else
|
||||
{
|
||||
PySfView *View;
|
||||
|
||||
View = GetNewPySfView();
|
||||
View->Owner = false;
|
||||
View->obj = (sf::View *)&(self->obj->GetView());
|
||||
Py_INCREF(View);
|
||||
self->View = View;
|
||||
return (PyObject *)View;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args)
|
||||
{
|
||||
PySfView *View = (PySfView *)args;
|
||||
if (!PyObject_TypeCheck(View, &PySfViewType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "RenderWindow.SetView() Argument is not a sf.View");
|
||||
return NULL;
|
||||
}
|
||||
Py_CLEAR(self->View);
|
||||
Py_INCREF(View);
|
||||
self->View = View;
|
||||
self->obj->SetView(*(View->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_GetDefaultView(PySfRenderWindow *self)
|
||||
{
|
||||
PySfView *View;
|
||||
|
||||
View = GetNewPySfView();
|
||||
View->Owner = false;
|
||||
|
||||
// Python doesn't know anything about 'const', so cast away. Be careful with
|
||||
// not changing the default view!
|
||||
View->obj = const_cast<sf::View*>( &( self->obj->GetDefaultView() ) );
|
||||
|
||||
return (PyObject *)View;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfRenderWindow_methods[] = {
|
||||
{"SetActive", (PyCFunction)PySfRenderWindow_SetActive, METH_VARARGS, "SetActive(Active)\n\
|
||||
Activate or deactivate the window as the current target for OpenGL rendering.\n\
|
||||
Active : True to activate window. (default: True)"},
|
||||
{"Clear", (PyCFunction)PySfRenderWindow_Clear, METH_VARARGS, "Clear(FillColor)\n\
|
||||
Clear the entire target with a single color.\n\
|
||||
FillColor : Color to use to clear the render target."},
|
||||
{"GetDefaultView", (PyCFunction)PySfRenderWindow_GetDefaultView, METH_NOARGS, "GetDefaultView()\n\
|
||||
Get the default view of the window for read / write (returns a sf.View instance)."},
|
||||
{"GetView", (PyCFunction)PySfRenderWindow_GetView, METH_NOARGS, "GetView()\n\
|
||||
Get the current view rectangle (returns a sf.View instance)."},
|
||||
{"SetView", (PyCFunction)PySfRenderWindow_SetView, METH_O, "SetView(View)\n\
|
||||
Change the current active view. View must be a sf.View instance."},
|
||||
{"Draw", (PyCFunction)PySfRenderWindow_Draw, METH_O, "Draw(Drawable)\n\
|
||||
Draw something on the window. The argument can be a drawable or any object supporting the iterator protocol and containing drawables (for example a tuple of drawables)."},
|
||||
{"ConvertCoords", (PyCFunction)PySfRenderWindow_ConvertCoords, METH_VARARGS, "ConvertCoords(WindowX, WindowY, TargetView)\n\
|
||||
Convert a point in window coordinates into view coordinates. Returns a tuple of two floats.\n\
|
||||
WindowX : X coordinate of the point to convert, relative to the window\n\
|
||||
WindowY : Y coordinate of the point to convert, relative to the window\n\
|
||||
TargetView : Target view to convert the point to (NULL by default -- uses the current view)."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfRenderWindowType = {
|
||||
head_init
|
||||
"RenderWindow", /*tp_name*/
|
||||
sizeof(PySfRenderWindow), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfRenderWindow_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Simple wrapper for sf.Window that allows easy 2D rendering.\n\
|
||||
Default constructor : sf.RenderWindow()\n\
|
||||
Construct a new window : sf.RenderWindow(Mode, Title, Style::Resize|Style::Close, Params = WindowSettings())\n\
|
||||
Mode : Video mode to use\n\
|
||||
Title : Title of the window\n\
|
||||
WindowStyle : Window style (Resize | Close by default)\n\
|
||||
Params : Creation parameters (see default constructor for default values)\n\
|
||||
Construct the window from an existing control : sf.RenderWindow(Handle, Params)\n\
|
||||
Handle : handle of the control (long integer)\n\
|
||||
Params : Creation parameters (see default constructor for default values)", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfRenderWindow_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfWindowType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfRenderWindow_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
41
bindings/python/src/RenderWindow.hpp
Normal file
41
bindings/python/src/RenderWindow.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYRENDERWINDOW_HPP
|
||||
#define __PYRENDERWINDOW_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
|
||||
#include "View.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::RenderWindow *obj;
|
||||
PySfView *View;
|
||||
} PySfRenderWindow;
|
||||
|
||||
|
||||
#endif
|
194
bindings/python/src/Shader.cpp
Normal file
194
bindings/python/src/Shader.cpp
Normal file
|
@ -0,0 +1,194 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Shader.hpp"
|
||||
#include "Drawable.hpp"
|
||||
#include "Image.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
|
||||
static void
|
||||
PySfShader_dealloc(PySfShader *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShader_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject *
|
||||
PySfShader_LoadFromFile (PySfShader *self, PyObject *args)
|
||||
{
|
||||
load_from_file(self, args);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShader_LoadFromMemory (PySfShader *self, PyObject *args)
|
||||
{
|
||||
char *effect;
|
||||
#ifdef IS_PY3K
|
||||
PyObject *string = PyUnicode_AsUTF8String(args);
|
||||
if (string == NULL)
|
||||
return NULL;
|
||||
effect = PyBytes_AsString(string);
|
||||
#else
|
||||
effect = PyString_AsString(args);
|
||||
#endif
|
||||
bool result = self->obj->LoadFromMemory(effect);
|
||||
#ifdef IS_PY3K
|
||||
Py_DECREF(string);
|
||||
#endif
|
||||
return PyBool_FromLong(result);
|
||||
}
|
||||
|
||||
static PyObject *
PySfShader_SetParameter(PySfShader* self, PyObject *args)
{
char *Name;
float X, Y, Z, W;
int size = PyTuple_Size(args);
if (!PyArg_ParseTuple(args, "sf|fff:Shader.SetParameter", &Name, &X, &Y, &Z, &W))
return NULL;
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case 2:
|
||||
self->obj->SetParameter(Name, X);
|
||||
break;
|
||||
case 3:
|
||||
self->obj->SetParameter(Name, X, Y);
|
||||
break;
|
||||
case 4:
|
||||
self->obj->SetParameter(Name, X, Y, Z);
|
||||
break;
|
||||
case 5:
|
||||
self->obj->SetParameter(Name, X, Y, Z, W);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShader_SetTexture(PySfShader* self, PyObject *args)
|
||||
{
|
||||
PySfImage *Image = NULL;
|
||||
char *Name;
|
||||
if (! PyArg_ParseTuple(args, "sO", &Name, &Image))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyObject_TypeCheck(Image, &PySfImageType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Shader.SetTexture() Argument 2 must be an sf.Image instance.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->obj->SetTexture(Name, *Image->obj);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShader_IsAvailable(PySfShader* self, PyObject *args)
|
||||
{
|
||||
return PyBool_FromLong(sf::Shader::IsAvailable());
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfShader_methods[] = {
|
||||
{"LoadFromFile", (PyCFunction)PySfShader_LoadFromFile, METH_O, "LoadFromFile(Filename)\nLoad the effect from a file."},
|
||||
{"LoadFromMemory", (PyCFunction)PySfShader_LoadFromMemory, METH_O, "LoadFromMemory(Effect)\nLoad the effect from a text in memory."},
|
||||
{"SetParameter", (PyCFunction)PySfShader_SetParameter, METH_VARARGS, "SetParameter(X), SetParameter(X, Y), SetParameter(X, Y, Z), SetParameter(X, Y, Z, W)\nChange a parameter of the effect.\n\
|
||||
Name : Parameter name in the effect\n\
|
||||
X,Y,Z,W : Values to assign."},
|
||||
{"SetTexture", (PyCFunction)PySfShader_SetTexture, METH_VARARGS, "SetTexture(Name, Texture)\nSet a texture parameter.\n\
|
||||
Name : Texture name in the effect\n\
|
||||
Texture : Image to set (pass sf.Shader.CurrentTexture to use content of current framebuffer)"},
|
||||
{"IsAvailable", (PyCFunction)PySfShader_IsAvailable, METH_STATIC | METH_NOARGS, "IsAvailable()\nTell wether or not the system supports post-effects."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfShaderType = {
|
||||
head_init
|
||||
"Shader", /*tp_name*/
|
||||
sizeof(PySfShader), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfShader_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Shader is used to apply a post effect to a window.\n\
|
||||
Default constructor : sf.Shader()\n\
|
||||
Copy constructor : sf.Shader(Copy) where Copy is a sf.Shader instance.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfShader_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfShader_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfShader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfShader *self;
|
||||
self = (PySfShader *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
PySfShader *Copy = NULL;
|
||||
self->IsCustom = false;
|
||||
if (!PyArg_ParseTuple(args, "|O!", &PySfShaderType, &Copy))
|
||||
return NULL;
|
||||
if (Copy) self->obj = new sf::Shader(*(Copy->obj));
|
||||
else self->obj = new sf::Shader();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
38
bindings/python/src/Shader.hpp
Normal file
38
bindings/python/src/Shader.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYPOSTFX_HPP
|
||||
#define __PYPOSTFX_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool IsCustom;
|
||||
sf::Shader *obj;
|
||||
} PySfShader;
|
||||
|
||||
#endif
|
379
bindings/python/src/Shape.cpp
Normal file
379
bindings/python/src/Shape.cpp
Normal file
|
@ -0,0 +1,379 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Shape.hpp"
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include "Color.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
|
||||
static void
|
||||
PySfShape_dealloc(PySfShape* self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfShape *self;
|
||||
self = (PySfShape *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->obj = new sf::Shape();
|
||||
self->IsCustom = false;
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
// void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"X", "Y", "Col", "OutlineCol", NULL};
|
||||
float X, Y;
|
||||
sf::Color *Col, *OutlineCol;
|
||||
PySfColor *ColTmp=NULL, *OutlineColTmp=NULL;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff|O!O!:Shape.AddPoint", (char **)kwlist, &X, &Y, &PySfColorType, &ColTmp, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
|
||||
if (ColTmp)
|
||||
{
|
||||
PySfColorUpdate(ColTmp);
|
||||
Col = ColTmp->obj;
|
||||
}
|
||||
else
|
||||
Col = (sf::Color *)&sf::Color::White;
|
||||
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
self->obj->AddPoint(X, Y, *Col, *OutlineCol);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_SetOutlineWidth(PySfShape* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetOutlineWidth(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_GetOutlineWidth(PySfShape* self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetOutlineWidth());
|
||||
}
|
||||
|
||||
// static Shape Line(float X0, float Y0, float X1, float Y1, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_Line(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"X0", "Y0", "X1", "Y1", "Thickness", "Col", "Outline", "OutlineCol", NULL};
|
||||
PySfShape *Line = GetNewPySfShape();
|
||||
float X0, Y0, X1, Y1, Thickness, Outline = 0.f;
|
||||
sf::Color *OutlineCol;
|
||||
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffffO!|fO!:Shape.Line", (char **)kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
PySfColorUpdate(ColTmp);
|
||||
Line->obj = new sf::Shape(sf::Shape::Line(X0, Y0, X1, Y1, Thickness, *(ColTmp->obj), Outline, *OutlineCol));
|
||||
return (PyObject *)Line;
|
||||
}
|
||||
|
||||
// static Shape Rectangle(float X0, float Y0, float X1, float Y1, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_Rectangle(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"X0", "Y0", "X1", "Y1", "Col", "Outline", "OutlineCol", NULL};
|
||||
PySfShape *Rectangle = GetNewPySfShape();
|
||||
float X0, Y0, X1, Y1, Outline = 0.f;
|
||||
sf::Color *OutlineCol;
|
||||
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffO!|fO!:Shape.Rectangle", (char **)kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
PySfColorUpdate(ColTmp);
|
||||
Rectangle->obj = new sf::Shape(sf::Shape::Rectangle(X0, Y0, X1, Y1, *(ColTmp->obj), Outline, *OutlineCol));
|
||||
return (PyObject *)Rectangle;
|
||||
}
|
||||
|
||||
// static Shape Circle(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_Circle(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"X", "Y", "Radius", "Col", "Outline", "OutlineCol", NULL};
|
||||
PySfShape *Circle = GetNewPySfShape();
|
||||
float X, Y, Radius, Outline = 0.f;
|
||||
sf::Color *OutlineCol;
|
||||
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffO!|fO!:Shape.Circle", (char **)kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
PySfColorUpdate(ColTmp);
|
||||
Circle->obj = new sf::Shape(sf::Shape::Circle(X, Y, Radius, *(ColTmp->obj), Outline, *OutlineCol));
|
||||
return (PyObject *)Circle;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_GetPointPosition(PySfShape* self, PyObject *args)
|
||||
{
|
||||
sf::Vector2f result = self->obj->GetPointPosition(PyLong_AsUnsignedLong(args));
|
||||
return Py_BuildValue("ff", result.x, result.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_GetPointColor(PySfShape* self, PyObject *args)
|
||||
{
|
||||
PySfColor *PyColor = GetNewPySfColor();
|
||||
PyColor->obj = new sf::Color(self->obj->GetPointColor(PyLong_AsUnsignedLong(args)));
|
||||
PyColor->r = PyColor->obj->r;
|
||||
PyColor->g = PyColor->obj->g;
|
||||
PyColor->b = PyColor->obj->b;
|
||||
PyColor->a = PyColor->obj->a;
|
||||
return (PyObject *)PyColor;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_GetPointOutlineColor(PySfShape* self, PyObject *args)
|
||||
{
|
||||
PySfColor *PyColor = GetNewPySfColor();
|
||||
PyColor->obj = new sf::Color(self->obj->GetPointOutlineColor(PyLong_AsUnsignedLong(args)));
|
||||
PyColor->r = PyColor->obj->r;
|
||||
PyColor->g = PyColor->obj->g;
|
||||
PyColor->b = PyColor->obj->b;
|
||||
PyColor->a = PyColor->obj->a;
|
||||
return (PyObject *)PyColor;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_SetPointPosition(PySfShape* self, PyObject *args)
|
||||
{
|
||||
unsigned int Index;
|
||||
float X, Y;
|
||||
if (!PyArg_ParseTuple(args, "Iff:Shape.SetPointPosition", &Index, &X, &Y))
|
||||
return NULL;
|
||||
self->obj->SetPointPosition(Index, X, Y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_SetPointColor(PySfShape* self, PyObject *args)
|
||||
{
|
||||
unsigned int Index;
|
||||
PySfColor *Color;
|
||||
if (!PyArg_ParseTuple(args, "IO!:Shape.SetPointColor", &Index, &PySfColorType, &Color))
|
||||
return NULL;
|
||||
PySfColorUpdate(Color);
|
||||
self->obj->SetPointColor(Index, *(Color->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_SetPointOutlineColor(PySfShape* self, PyObject *args)
|
||||
{
|
||||
unsigned int Index;
|
||||
PySfColor *Color;
|
||||
if (!PyArg_ParseTuple(args, "IO!:Shape.SetPointOutlineColor", &Index, &PySfColorType, &Color))
|
||||
return NULL;
|
||||
PySfColorUpdate(Color);
|
||||
self->obj->SetPointOutlineColor(Index, *(Color->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_GetNbPoints(PySfShape* self, PyObject *args)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetNbPoints());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_EnableFill(PySfShape* self, PyObject *args)
|
||||
{
|
||||
self->obj->EnableFill(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_EnableOutline(PySfShape* self, PyObject *args)
|
||||
{
|
||||
self->obj->EnableOutline(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfShape_methods[] = {
|
||||
{"GetPointPosition", (PyCFunction)PySfShape_GetPointPosition, METH_O, "GetPointPosition(Index)\n\
|
||||
Get the position of a point.\n\
|
||||
Index : Index-th point."},
|
||||
{"GetPointColor", (PyCFunction)PySfShape_GetPointColor, METH_O, "GetPointColor(Index)\n\
|
||||
Get the color of a point.\n Index : Index-th point."},
|
||||
{"GetPointOutlineColor", (PyCFunction)PySfShape_GetPointOutlineColor, METH_O, "GetPointOutlineColor(Index)\n\
|
||||
Get the outline color of a point.\n Index : Index-th point."},
|
||||
{"SetPointPosition", (PyCFunction)PySfShape_SetPointPosition, METH_VARARGS, "SetPointPosition(Index, X, Y).\n\
|
||||
Set the position of a point\n\
|
||||
Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
|
||||
X : New X coordinate of the Index-th point\n\
|
||||
Y : New Y coordinate of the Index-th point."},
|
||||
{"SetPointColor", (PyCFunction)PySfShape_SetPointColor, METH_VARARGS, "SetPointColor(Index, Color).\n\
|
||||
Set the color of a point\n\
|
||||
Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
|
||||
Col : New color of the Index-th point."},
|
||||
{"SetPointOutlineColor", (PyCFunction)PySfShape_SetPointOutlineColor, METH_VARARGS, "SetPointOutlineColor(Index, Color).\n\
|
||||
Set the outline color of a point\n\
|
||||
Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
|
||||
Col : New color of the Index-th point."},
|
||||
{"GetNbPoints", (PyCFunction)PySfShape_GetNbPoints, METH_NOARGS, "GetNbPoints()\n\
|
||||
Get the number of points composing the shape."},
|
||||
{"EnableFill", (PyCFunction)PySfShape_EnableFill, METH_O, "EnableFill(Enable)\n\
|
||||
Enable or disable filling the shape. Fill is enabled by default.\n\
|
||||
Enable : True to enable, false to disable."},
|
||||
{"EnableOutline", (PyCFunction)PySfShape_EnableOutline, METH_O, "EnableOutline(Enable)\n\
|
||||
Enable or disable drawing the shape outline. Outline is enabled by default.\n\
|
||||
Enable : True to enable, false to disable"},
|
||||
{"AddPoint", (PyCFunction)PySfShape_AddPoint, METH_VARARGS | METH_KEYWORDS, "AddPoint(X, Y, Col=sf.Color.White, OutlineCol=sf.Color.Black)\n\
|
||||
Add a point to the shape.\n\
|
||||
X : X coordinate of the point\n\
|
||||
Y : Y coordinate of the point\n\
|
||||
Col : Color of the point (white by default)\n\
|
||||
OutlineCol : Outline color of the point (black by default)."},
|
||||
{"SetOutlineWidth", (PyCFunction)PySfShape_SetOutlineWidth, METH_O, "SetOutlineWidth(Width)\n\
|
||||
Change the width of the shape outline.\n\
|
||||
Width : New width (use 0 to remove the outline)."},
|
||||
{"GetOutlineWidth", (PyCFunction)PySfShape_GetOutlineWidth, METH_NOARGS, "GetOutlineWidth()\n\
|
||||
Get the width of the shape outline."},
|
||||
{"Line", (PyCFunction)PySfShape_Line, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Line(X0, Y0, X1, Y1, Thickness, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\
|
||||
Create a shape made of a single line.\n\
|
||||
X0 : X coordinate of the first point.\n\
|
||||
Y0 : Y coordinate of the first point.\n\
|
||||
X1 : X coordinate of the second point.\n\
|
||||
Y1 : Y coordinate of the second point.\n\
|
||||
Thickness : Line thickness.\n\
|
||||
Col : Color used to draw the line\n\
|
||||
Outline : Outline width (0 by default)\n\
|
||||
OutlineCol : Color used to draw the outline (black by default)."},
|
||||
{"Rectangle", (PyCFunction)PySfShape_Rectangle, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Rectangle(X0, Y0, X1, Y1, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\
|
||||
Create a shape made of a single rectangle.\n\
|
||||
X0 : X coordinate of the first point.\n\
|
||||
Y0 : Y coordinate of the first point.\n\
|
||||
X1 : X coordinate of the second point.\n\
|
||||
Y1 : Y coordinate of the second point.\n\
|
||||
Col : Color used to fill the rectangle.\n\
|
||||
Outline : Outline width (0 by default).\n\
|
||||
OutlineCol : Color used to draw the outline (black by default)."},
|
||||
{"Circle", (PyCFunction)PySfShape_Circle, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Circle(X, Y, Radius, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\
|
||||
Create a shape made of a single circle.\n\
|
||||
X : X coordinate of the center.\n\
|
||||
Y : Y coordinate of the center.\n\
|
||||
Radius : Radius\n\
|
||||
Col : Color used to fill the rectangle.\n\
|
||||
Outline : Outline width (0 by default).\n\
|
||||
OutlineCol : Color used to draw the outline (black by default)."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfShapeType = {
|
||||
head_init
|
||||
"Shape", /*tp_name*/
|
||||
sizeof(PySfShape), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfShape_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc.\nDefault constructor: Shape()", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfShape_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfShape_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
PySfShape *
|
||||
GetNewPySfShape()
|
||||
{
|
||||
PySfShape *Shape = PyObject_New(PySfShape, &PySfShapeType);
|
||||
Shape->IsCustom = false;
|
||||
return Shape;
|
||||
}
|
||||
|
42
bindings/python/src/Shape.hpp
Normal file
42
bindings/python/src/Shape.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSHAPE_HPP
|
||||
#define __PYSHAPE_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool IsCustom;
|
||||
sf::Shape *obj;
|
||||
} PySfShape;
|
||||
|
||||
PySfShape *
|
||||
GetNewPySfShape();
|
||||
|
||||
#endif
|
33
bindings/python/src/Sleep.cpp
Normal file
33
bindings/python/src/Sleep.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Sleep.hpp"
|
||||
|
||||
PyObject *
|
||||
PySFML_Sleep (PyObject *self, PyObject *args)
|
||||
{
|
||||
sf::Sleep(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
35
bindings/python/src/Sleep.hpp
Normal file
35
bindings/python/src/Sleep.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSLEEP_HPP
|
||||
#define __PYSLEEP_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
|
||||
PyObject *
|
||||
PySFML_Sleep (PyObject *self, PyObject *args);
|
||||
|
||||
#endif
|
338
bindings/python/src/Sound.cpp
Normal file
338
bindings/python/src/Sound.cpp
Normal file
|
@ -0,0 +1,338 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Sound.hpp"
|
||||
#include "SoundBuffer.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfSoundBufferType;
|
||||
|
||||
|
||||
static void
|
||||
PySfSound_dealloc(PySfSound *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
|
||||
static int
|
||||
PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Buffer", "Loop", "Pitch", "Volume", "X", "Y", "Z", NULL};
|
||||
PySfSoundBuffer *Buffer=NULL;
|
||||
PyObject *Loop=NULL;
|
||||
float Pitch=1.f, Volume=100.f, X=0.f, Y=0.f, Z=0.f;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|O!Offfff:Sound.__new__", (char **)kwlist, &PySfSoundBufferType, &Buffer, &Loop, &Pitch, &Volume, &X, &Y, &Z))
|
||||
return -1;
|
||||
{
|
||||
if (Loop)
|
||||
self->obj->SetLoop(PyBool_AsBool(Loop));
|
||||
if (Buffer)
|
||||
self->obj->SetBuffer(*(Buffer->obj));
|
||||
self->obj->SetPitch(Pitch);
|
||||
self->obj->SetVolume(Volume);
|
||||
self->obj->SetPosition(X, Y, Z);
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetBuffer(PySfSound *self, PyObject *args)
|
||||
{
|
||||
PySfSoundBuffer *Buffer = (PySfSoundBuffer *)args;
|
||||
if (!PyObject_TypeCheck(args, &PySfSoundBufferType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Sound.SetBuffer() The argument must be a sf.SoundBuffer.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
self->obj->SetBuffer(*(Buffer->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetLoop(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetLoop(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetRelativeToListener(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetRelativeToListener(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_IsRelativeToListener(PySfSound *self)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->IsRelativeToListener());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetPitch(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetPitch(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetMinDistance(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetMinDistance(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetAttenuation(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetAttenuation(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetVolume(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetVolume(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetPitch(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetPitch());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetMinDistance(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetMinDistance());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetAttenuation(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetAttenuation());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetVolume(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetVolume());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetPosition(PySfSound *self)
|
||||
{
|
||||
sf::Vector3f Vect = self->obj->GetPosition();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetPlayingOffset(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetPlayingOffset());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetLoop(PySfSound *self)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->GetLoop());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_Play(PySfSound *self)
|
||||
{
|
||||
self->obj->Play();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_Pause(PySfSound *self)
|
||||
{
|
||||
self->obj->Pause();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_Stop(PySfSound *self)
|
||||
{
|
||||
self->obj->Stop();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetStatus(PySfSound *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetStatus());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetPosition(PySfSound *self, PyObject *args)
|
||||
{
|
||||
float X, Y, Z;
|
||||
if (!PyArg_ParseTuple(args, "fff:Sound.SetPosition", &X, &Y, &Z))
|
||||
return NULL;
|
||||
self->obj->SetPosition(X, Y, Z);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSound_GetBuffer(PySfSound *self)
|
||||
{
|
||||
PySfSoundBuffer *Buffer;
|
||||
|
||||
Buffer = GetNewPySfSoundBuffer();
|
||||
Buffer->obj = new sf::SoundBuffer(*(self->obj->GetBuffer()));
|
||||
|
||||
return (PyObject *)Buffer;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetPlayingOffset(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetPlayingOffset(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfSound_methods[] = {
|
||||
{"SetRelativeToListener", (PyCFunction)PySfSound_SetRelativeToListener, METH_O, "SetRelativeToListener(Relative)\nMake the sound's position relative to the listener's position, or absolute. The default value is false (absolute)\n Relative : True to set the position relative, false to set it absolute"},
|
||||
{"IsRelativeToListener", (PyCFunction)PySfSound_IsRelativeToListener, METH_NOARGS, "IsRelativeToListener()\nTell if the sound's position is relative to the listener's position, or if it's absolute."},
|
||||
{"SetPlayingOffset", (PyCFunction)PySfSound_SetPlayingOffset, METH_O, "SetPlayingOffset(TimeOffset)\nSet the current playing position of the sound.\n TimeOffset : New playing position, expressed in seconds"},
|
||||
{"SetLoop", (PyCFunction)PySfSound_SetLoop, METH_O, "SetLoop(Loop)\nSet the Sound loop state.\n Loop : True to play in loop, false to play once"},
|
||||
{"SetBuffer", (PyCFunction)PySfSound_SetBuffer, METH_O, "SetBuffer(Buffer)\nSet the source buffer.\n Buffer : New sound buffer to bind to the sound "},
|
||||
{"SetPitch", (PyCFunction)PySfSound_SetPitch, METH_O, "SetPitch(Pitch)\nSet the sound pitch. The default pitch is 1.\n Pitch : New pitch"},
|
||||
{"SetMinDistance", (PyCFunction)PySfSound_SetMinDistance, METH_O, "SetMinDistance(MinDistance)\nSet the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume. The default minimum distance is 1.0.\n MinDistance : New minimum distance for the sound"},
|
||||
{"SetAttenuation", (PyCFunction)PySfSound_SetAttenuation, METH_O, "SetAttenuation(Attenuation)\nSet the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener. The default attenuation factor 1.0.\n Attenuation : New attenuation factor for the sound"},
|
||||
{"SetVolume", (PyCFunction)PySfSound_SetVolume, METH_O, "SetVolume(Volume)\nSet the sound volume.\n Volume : Volume (in range [0, 100])"},
|
||||
{"SetPosition", (PyCFunction)PySfSound_SetPosition, METH_VARARGS, "SetPosition(X, Y, Z)\nSet the sound position in the world.\n X,Y,Z : Position of the sound in the world"},
|
||||
{"GetLoop", (PyCFunction)PySfSound_GetLoop, METH_NOARGS, "GetLoop()\nTell whether or not the Sound is looping."},
|
||||
{"GetBuffer", (PyCFunction)PySfSound_GetBuffer, METH_NOARGS, "GetBuffer()\nGet the source buffer. Returns a new sf.SoundBuffer object."},
|
||||
{"GetPitch", (PyCFunction)PySfSound_GetPitch, METH_NOARGS, "GetPitch()\nGet the sound pitch."},
|
||||
{"GetMinDistance", (PyCFunction)PySfSound_GetMinDistance, METH_NOARGS, "GetMinDistance()\nGet the minimum distance."},
|
||||
{"GetAttenuation", (PyCFunction)PySfSound_GetAttenuation, METH_NOARGS, "GetAttenuation()\nGet the attenuation factor."},
|
||||
{"GetVolume", (PyCFunction)PySfSound_GetVolume, METH_NOARGS, "GetVolume()\nGet the sound volume."},
|
||||
{"GetPosition", (PyCFunction)PySfSound_GetPosition, METH_NOARGS, "GetPosition()\nGet the sound position in the world. Returns a tuple."},
|
||||
{"Play", (PyCFunction)PySfSound_Play, METH_NOARGS, "Play()\nPlay the sound."},
|
||||
{"Pause", (PyCFunction)PySfSound_Pause, METH_NOARGS, "Pause()\nPause the sound."},
|
||||
{"Stop", (PyCFunction)PySfSound_Stop, METH_NOARGS, "Stop()\nStop the sound."},
|
||||
{"GetStatus", (PyCFunction)PySfSound_GetStatus, METH_NOARGS, "GetStatus()\nGet the status of the sound (stopped, paused, playing)."},
|
||||
{"GetPlayingOffset", (PyCFunction)PySfSound_GetPlayingOffset, METH_NOARGS, "GetPlayingOffset()\nGet the current playing position of the sound."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfSoundType = {
|
||||
head_init
|
||||
"Sound", /*tp_name*/
|
||||
sizeof(PySfSound), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSound_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Sound defines the properties of a sound such as position, volume, pitch, etc.\n\
|
||||
Default constructor : Sound()\n\
|
||||
Construct the sound from its parameters : Sound(Buffer, Loop = False, Pitch = 1., Volume = 100., X = 0., Y = 0., Z = 0.);\n\
|
||||
Buffer : Sound buffer to play (None by default)\n\
|
||||
Loop : Loop flag (False by default)\n\
|
||||
Pitch : Value of the pitch (1. by default)\n\
|
||||
Volume : Volume (100. by default)\n\
|
||||
X : X position (0. by default)\n\
|
||||
Y : Y position (0. by default)\n\
|
||||
Z : Z position (0. by default)\n\
|
||||
Copy constructor : Sound(Copy) where Copy is a sf.Sound instance.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfSound_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfSound_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfSound_new, /* tp_new */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSound *self;
|
||||
self = (PySfSound *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
if (PyTuple_Size(args) == 1)
|
||||
{
|
||||
PySfSound *Copy;
|
||||
if (PyArg_ParseTuple(args, "O!:Sound.__new__", &PySfSoundType, &Copy))
|
||||
{
|
||||
self->obj = new sf::Sound(*(Copy->obj));
|
||||
return (PyObject *)self;
|
||||
}
|
||||
else PyErr_Clear();
|
||||
}
|
||||
self->obj = new sf::Sound();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
void
|
||||
PySfSound_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Sound::Stopped);
|
||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Stopped", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Sound::Paused);
|
||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Paused", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Sound::Playing);
|
||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Playing", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
40
bindings/python/src/Sound.hpp
Normal file
40
bindings/python/src/Sound.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUND_HPP
|
||||
#define __PYSOUND_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Audio/Sound.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Sound *obj;
|
||||
} PySfSound;
|
||||
|
||||
void
|
||||
PySfSound_InitConst();
|
||||
|
||||
#endif
|
194
bindings/python/src/SoundBuffer.cpp
Normal file
194
bindings/python/src/SoundBuffer.cpp
Normal file
|
@ -0,0 +1,194 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SoundBuffer.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static void
|
||||
PySfSoundBuffer_dealloc(PySfSoundBuffer *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args)
|
||||
{
|
||||
load_from_file(self, args);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBuffer_LoadFromMemory(PySfSoundBuffer* self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes;
|
||||
char *Data;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#:SoundBuffer.LoadFromMemory", &Data, &SizeInBytes))
|
||||
return NULL;
|
||||
|
||||
return PyBool_FromLong(self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBuffer_LoadFromSamples(PySfSoundBuffer* self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes, ChannelsCount, SampleRate;
|
||||
char *Data;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "s#II:SoundBuffer.LoadFromSamples", &Data, &SizeInBytes, &ChannelsCount, &SampleRate))
|
||||
return NULL;
|
||||
|
||||
return PyBool_FromLong(self->obj->LoadFromSamples((const sf::Int16*)Data, (std::size_t) SizeInBytes/2, ChannelsCount, SampleRate));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetSamples(PySfSoundBuffer *self)
|
||||
{
|
||||
#ifdef IS_PY3K
|
||||
return PyBytes_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2);
|
||||
#else
|
||||
return PyString_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2);
|
||||
#endif
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_SaveToFile(PySfSoundBuffer *self, PyObject *args)
|
||||
{
|
||||
save_to_file(self, args);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetDuration(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyFloat_FromDouble((double)(self->obj->GetDuration()));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetChannelsCount(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetChannelsCount());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetSampleRate(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetSampleRate());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetSamplesCount(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetSamplesCount());
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfSoundBuffer_methods[] = {
|
||||
{"LoadFromFile", (PyCFunction)PySfSoundBuffer_LoadFromFile, METH_O, "LoadFromFile(FileName)\nLoad the sound buffer from a file. Returns True if loading has been successful.\n Filename : Path of the sound file to load"},
|
||||
{"SaveToFile", (PyCFunction)PySfSoundBuffer_SaveToFile, METH_O, "SaveToFile(Filename)\nSave the sound buffer to a file. Returns True if saving has been successful.\n Filename : Path of the sound file to write"},
|
||||
{"LoadFromMemory", (PyCFunction)PySfSoundBuffer_LoadFromMemory, METH_O, "LoadFromMemory(Data)\nLoad the sound buffer from a string in memory.\n Data : string representing the file data in memory "},
|
||||
{"LoadFromSamples", (PyCFunction)PySfSoundBuffer_LoadFromSamples, METH_VARARGS, "LoadFromSamples(Samples, ChannelsCount, SampleRate)\nLoad the sound buffer from an array of samples - assumed format for samples is 16 bits signed integer.\n\
|
||||
Samples : Pointer to the samples in memory\n\
|
||||
ChannelsCount : Number of channels (1 = mono, 2 = stereo, ...)\n\
|
||||
SampleRate : Frequency (number of samples to play per second)"},
|
||||
{"GetDuration", (PyCFunction)PySfSoundBuffer_GetDuration, METH_NOARGS, "GetDuration()\nGet the sound duration."},
|
||||
{"GetChannelsCount", (PyCFunction)PySfSoundBuffer_GetChannelsCount, METH_NOARGS, "GetChannelsCount()\nReturn the number of channels (1 = mono, 2 = stereo)."},
|
||||
{"GetSampleRate", (PyCFunction)PySfSoundBuffer_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sound frequency (sample rate)."},
|
||||
{"GetSamplesCount", (PyCFunction)PySfSoundBuffer_GetSamplesCount, METH_NOARGS, "GetSamplesCount()\nReturn the samples count."},
|
||||
{"GetSamples", (PyCFunction)PySfSoundBuffer_GetSamples, METH_NOARGS, "GetSamples()\nReturn the sound samples as a string."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfSoundBufferType = {
|
||||
head_init
|
||||
"SoundBuffer", /*tp_name*/
|
||||
sizeof(PySfSoundBuffer), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSoundBuffer_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.SoundBuffer is the low-level for loading and manipulating sound buffers.\n\
|
||||
Default constructor : SoundBuffer()\n\
|
||||
Copy constructor : SoundBuffer(Copy) where Copy is a sf.SoundBuffer instance.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfSoundBuffer_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfSoundBuffer_new, /* tp_new */
|
||||
};
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSoundBuffer *self;
|
||||
self = (PySfSoundBuffer *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
PySfSoundBuffer *Copy=NULL;
|
||||
if (PyArg_ParseTuple(args, "O!:SoundBuffer.__init__", &PySfSoundBufferType, &Copy))
|
||||
{
|
||||
self->obj = new sf::SoundBuffer(*(Copy->obj));
|
||||
return (PyObject *)self;
|
||||
}
|
||||
PyErr_Clear();
|
||||
self->obj = new sf::SoundBuffer();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
PySfSoundBuffer *
|
||||
GetNewPySfSoundBuffer()
|
||||
{
|
||||
return PyObject_New(PySfSoundBuffer, &PySfSoundBufferType);
|
||||
}
|
||||
|
40
bindings/python/src/SoundBuffer.hpp
Normal file
40
bindings/python/src/SoundBuffer.hpp
Normal file
|
@ -0,0 +1,40 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUNDBUFFER_HPP
|
||||
#define __PYSOUNDBUFFER_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::SoundBuffer *obj;
|
||||
} PySfSoundBuffer;
|
||||
|
||||
PySfSoundBuffer *
|
||||
GetNewPySfSoundBuffer();
|
||||
|
||||
#endif
|
106
bindings/python/src/SoundBufferRecorder.cpp
Normal file
106
bindings/python/src/SoundBufferRecorder.cpp
Normal file
|
@ -0,0 +1,106 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SoundBufferRecorder.hpp"
|
||||
#include "SoundBuffer.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfSoundRecorderType;
|
||||
|
||||
|
||||
static void
|
||||
PySfSoundBufferRecorder_dealloc(PySfSoundBufferRecorder *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBufferRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSoundBufferRecorder *self;
|
||||
self = (PySfSoundBufferRecorder *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
self->obj = new sf::SoundBufferRecorder();
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBufferRecorder_GetBuffer(PySfSoundBufferRecorder* self)
|
||||
{
|
||||
PySfSoundBuffer *SoundBuffer = GetNewPySfSoundBuffer();
|
||||
SoundBuffer->obj = new sf::SoundBuffer(self->obj->GetBuffer());
|
||||
return (PyObject *)SoundBuffer;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfSoundBufferRecorder_methods[] = {
|
||||
{"GetBuffer", (PyCFunction)PySfSoundBufferRecorder_GetBuffer, METH_NOARGS, "GetBuffer()\nGet the sound buffer containing the captured audio data. Returns a SoundBuffer object. Returns a sf.SoundBuffer instance."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfSoundBufferRecorderType = {
|
||||
head_init
|
||||
"SoundBufferRecorder", /*tp_name*/
|
||||
sizeof(PySfSoundBufferRecorder), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSoundBufferRecorder_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Specialized SoundRecorder which saves the captured audio data into a sound buffer.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfSoundBufferRecorder_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfSoundRecorderType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfSoundBufferRecorder_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
37
bindings/python/src/SoundBufferRecorder.hpp
Normal file
37
bindings/python/src/SoundBufferRecorder.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUNDBUFFERRECORDER_HPP
|
||||
#define __PYSOUNDBUFFERRECORDER_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Audio/SoundBufferRecorder.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::SoundBufferRecorder *obj;
|
||||
} PySfSoundBufferRecorder;
|
||||
|
||||
#endif
|
166
bindings/python/src/SoundRecorder.cpp
Normal file
166
bindings/python/src/SoundRecorder.cpp
Normal file
|
@ -0,0 +1,166 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SoundRecorder.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
bool CustomSoundRecorder::OnStart()
|
||||
{
|
||||
bool result = false;
|
||||
if (PyObject_HasAttrString(SoundRecorder, "OnStart"))
|
||||
{
|
||||
PyObject *OnStart = PyObject_GetAttrString(SoundRecorder, "OnStart");
|
||||
PyObject *Result = PyObject_CallFunction(OnStart, NULL);
|
||||
result = PyBool_AsBool(Result);
|
||||
Py_DECREF(OnStart);
|
||||
Py_DECREF(Result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CustomSoundRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount)
|
||||
{
|
||||
bool result = false;
|
||||
if (PyObject_HasAttrString(SoundRecorder, "OnGetData"))
|
||||
{
|
||||
PyObject *OnGetData = PyObject_GetAttrString(SoundRecorder, "OnGetData");
|
||||
PyObject *Result = PyObject_CallFunction(OnGetData, (char *)"#s", (char *)Samples, SamplesCount*2);
|
||||
result = PyBool_AsBool(Result);
|
||||
Py_DECREF(OnGetData);
|
||||
Py_DECREF(Result);
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
void CustomSoundRecorder::OnStop()
|
||||
{
|
||||
if (PyObject_HasAttrString(SoundRecorder, "OnStop"))
|
||||
{
|
||||
PyObject *OnStop = PyObject_GetAttrString(SoundRecorder, "OnStop");
|
||||
PyObject_CallFunction(OnStop, NULL);
|
||||
Py_DECREF(OnStop);
|
||||
}
|
||||
}
|
||||
|
||||
static void
|
||||
PySfSoundRecorder_dealloc(PySfSoundRecorder* self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSoundRecorder *self;
|
||||
self = (PySfSoundRecorder *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->obj = new CustomSoundRecorder();
|
||||
self->obj->SoundRecorder = (PyObject *)self;
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_Start(PySfSoundRecorder* self, PyObject *args)
|
||||
{
|
||||
self->obj->Start(PyLong_AsLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_Stop(PySfSoundRecorder* self)
|
||||
{
|
||||
self->obj->Stop();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_GetSampleRate(PySfSoundRecorder* self)
|
||||
{
|
||||
return PyLong_FromLong(self->obj->GetSampleRate());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_IsAvailable(PySfSoundRecorder* self)
|
||||
{
|
||||
return PyBool_FromLong(sf::SoundRecorder::IsAvailable());
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfSoundRecorder_methods[] = {
|
||||
{"Start", (PyCFunction)PySfSoundRecorder_Start, METH_O, "Start(SampleRate=44100)\nStart the capture. Warning : only one capture can happen at the same time.\n SampleRate : Sound frequency (the more samples, the higher the quality) (44100 by default = CD quality)."},
|
||||
{"Stop", (PyCFunction)PySfSoundRecorder_Stop, METH_NOARGS, "Stop()\nStop the capture."},
|
||||
{"GetSampleRate", (PyCFunction)PySfSoundRecorder_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sample rate. Returns the frequency, in samples per second."},
|
||||
{"IsAvailable", (PyCFunction)PySfSoundRecorder_IsAvailable, METH_STATIC | METH_NOARGS, "IsAvailable()\nTell if the system supports sound capture. If not, this class won't be usable. Returns True if audio capture is supported."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfSoundRecorderType = {
|
||||
head_init
|
||||
"SoundRecorder", /*tp_name*/
|
||||
sizeof(PySfSoundRecorder), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSoundRecorder_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"SoundRecorder is an interface for capturing sound data, it is meant to be used as a base class.\n\
|
||||
Construct the sound recorder with a callback function for processing captured samples : SoundRecorder(Callback, UserData)\n\
|
||||
Callback : Callback function for processing captured samples. This function must take two parameters: the first one is a string containing captured samples, the second one is UserData.\n\
|
||||
UserData : Data to pass to the callback function (None by default).", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfSoundRecorder_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfSoundRecorder_new, /* tp_new */
|
||||
};
|
||||
|
46
bindings/python/src/SoundRecorder.hpp
Normal file
46
bindings/python/src/SoundRecorder.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUNDRECORDER_HPP
|
||||
#define __PYSOUNDRECORDER_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Audio/SoundRecorder.hpp>
|
||||
|
||||
class CustomSoundRecorder : public sf::SoundRecorder
|
||||
{
|
||||
public :
|
||||
PyObject *SoundRecorder;
|
||||
virtual bool OnStart();
|
||||
virtual bool OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount);
|
||||
virtual void OnStop();
|
||||
};
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
CustomSoundRecorder *obj;
|
||||
} PySfSoundRecorder;
|
||||
|
||||
#endif
|
346
bindings/python/src/SoundStream.cpp
Normal file
346
bindings/python/src/SoundStream.cpp
Normal file
|
@ -0,0 +1,346 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SoundStream.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
void CustomSoundStream::OnSeek(float TimeOffset)
|
||||
{
|
||||
PyGILState_STATE gstate;
|
||||
gstate = PyGILState_Ensure();
|
||||
if (PyObject_HasAttrString(SoundStream, "OnSeek"))
|
||||
{
|
||||
PyObject *OnSeek = PyObject_GetAttrString(SoundStream, "OnSeek");
|
||||
if (OnSeek != NULL)
|
||||
{
|
||||
PyObject_CallFunction(OnSeek, const_cast<char*>( "f" ), TimeOffset);
|
||||
Py_CLEAR(OnSeek);
|
||||
}
|
||||
}
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
}
|
||||
PyGILState_Release(gstate);
|
||||
}
|
||||
|
||||
bool CustomSoundStream::OnGetData(Chunk& Data)
|
||||
{
|
||||
PyGILState_STATE gstate;
|
||||
bool result = false;
|
||||
PyObject *Function, *PyData;
|
||||
gstate = PyGILState_Ensure();
|
||||
Function = PyObject_GetAttrString(SoundStream, "OnGetData");
|
||||
if (Function != NULL)
|
||||
{
|
||||
PyData = PyObject_CallFunction(Function, NULL);
|
||||
if (PyData != NULL)
|
||||
{
|
||||
if (PyArg_Parse(PyData, "s#", &(Data.Samples), &(Data.NbSamples)))
|
||||
{
|
||||
Data.NbSamples /= 2;
|
||||
if (Data.NbSamples > 0)
|
||||
result = true;
|
||||
}
|
||||
Py_CLEAR(PyData);
|
||||
}
|
||||
Py_CLEAR(Function);
|
||||
}
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
result = false;
|
||||
}
|
||||
PyGILState_Release(gstate);
|
||||
return result;
|
||||
}
|
||||
|
||||
void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate)
|
||||
{
|
||||
Initialize(ChannelsCount, SampleRate);
|
||||
}
|
||||
|
||||
static void
|
||||
PySfSoundStream_dealloc(PySfSoundStream *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSoundStream *self;
|
||||
self = (PySfSoundStream *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->obj = new CustomSoundStream();
|
||||
self->obj->SoundStream = (PyObject *)self;
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundStream_Initialize(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
unsigned int ChannelsCount, SampleRate;
|
||||
if (!PyArg_ParseTuple(args, "II:SoundStream.Initialize", &ChannelsCount, &SampleRate))
|
||||
return NULL;
|
||||
self->obj->Init(ChannelsCount, SampleRate);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_Play(PySfSoundStream *self)
|
||||
{
|
||||
self->obj->Play();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_Stop(PySfSoundStream *self)
|
||||
{
|
||||
self->obj->Stop();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetChannelsCount(PySfSoundStream *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetChannelsCount());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetSampleRate(PySfSoundStream *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetSampleRate());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_SetPitch(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetPitch(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_SetMinDistance(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetMinDistance(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_SetAttenuation(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetAttenuation(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_SetVolume(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetVolume(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetPitch(PySfSoundStream *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetPitch());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetMinDistance(PySfSoundStream *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetMinDistance());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetAttenuation(PySfSoundStream *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetAttenuation());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetVolume(PySfSoundStream *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetVolume());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetPosition(PySfSoundStream *self)
|
||||
{
|
||||
sf::Vector3f Vect = self->obj->GetPosition();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_Pause(PySfSoundStream *self)
|
||||
{
|
||||
self->obj->Pause();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_SetPosition(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
float X, Y, Z;
|
||||
if (!PyArg_ParseTuple(args, "fff:SoundStream.SetPosition", &X, &Y, &Z))
|
||||
return NULL;
|
||||
self->obj->SetPosition(X, Y, Z);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetStatus(PySfSoundStream *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetStatus());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_SetLoop(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetLoop(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetLoop(PySfSoundStream *self)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->GetLoop());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_GetPlayingOffset(PySfSoundStream *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetPlayingOffset());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_SetRelativeToListener(PySfSoundStream *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetRelativeToListener(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundStream_IsRelativeToListener(PySfSoundStream *self)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->IsRelativeToListener());
|
||||
}
|
||||
|
||||
static PyMethodDef PySfSoundStream_methods[] = {
|
||||
{"SetRelativeToListener", (PyCFunction)PySfSoundStream_SetRelativeToListener, METH_O, "SetRelativeToListener(Relative)\nMake the sound's position relative to the listener's position, or absolute. The default value is false (absolute)\n Relative : True to set the position relative, false to set it absolute"},
|
||||
{"IsRelativeToListener", (PyCFunction)PySfSoundStream_IsRelativeToListener, METH_NOARGS, "IsRelativeToListener()\nTell if the sound's position is relative to the listener's position, or if it's absolute."},
|
||||
{"Initialize", (PyCFunction)PySfSoundStream_Initialize, METH_VARARGS, "Initialize(ChannelsCount, SampleRate)\n\
|
||||
Set the audio stream parameters, you must call it before Play()\n\
|
||||
ChannelsCount : Number of channels\n\
|
||||
SampleRate : Sample rate."},
|
||||
{"Play", (PyCFunction)PySfSoundStream_Play, METH_NOARGS, "Play()\nPlay the sound."},
|
||||
{"Stop", (PyCFunction)PySfSoundStream_Stop, METH_NOARGS, "Stop()\nStop the sound."},
|
||||
{"GetChannelsCount", (PyCFunction)PySfSoundStream_GetChannelsCount, METH_NOARGS, "GetChannelsCount()\nReturn the number of channels (1 = mono, 2 = stereo)."},
|
||||
{"GetSampleRate", (PyCFunction)PySfSoundStream_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sound frequency (sample rate)."},
|
||||
{"GetStatus", (PyCFunction)PySfSoundStream_GetStatus, METH_NOARGS, "GetStatus()\nGet the status of the sound (stopped, paused, playing)."},
|
||||
{"SetLoop", (PyCFunction)PySfSoundStream_SetLoop, METH_O, "SetLoop(Loop)\nSet the music loop state. This parameter is disabled by default\n Loop : True to play in loop, false to play once "},
|
||||
{"GetLoop", (PyCFunction)PySfSoundStream_GetLoop, METH_NOARGS, "GetLoop()\nTell whether or not the music is looping."},
|
||||
{"GetPlayingOffset", (PyCFunction)PySfSoundStream_GetPlayingOffset, METH_NOARGS, "GetPlayingOffset()\nGet the current playing position of the stream."},
|
||||
/* The following methods should be inherited from sf.Sound */
|
||||
{"SetPitch", (PyCFunction)PySfSoundStream_SetPitch, METH_O, "SetPitch(Pitch)\nSet the sound pitch. The default pitch is 1.\n Pitch : New pitch"},
|
||||
{"SetMinDistance", (PyCFunction)PySfSoundStream_SetMinDistance, METH_O, "SetMinDistance(MinDistance)\nSet the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume. The default minimum distance is 1.0.\n MinDistance : New minimum distance for the sound"},
|
||||
{"SetAttenuation", (PyCFunction)PySfSoundStream_SetAttenuation, METH_O, "SetAttenuation(Attenuation)\nSet the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener. The default attenuation factor 1.0.\n Attenuation : New attenuation factor for the sound"},
|
||||
{"SetVolume", (PyCFunction)PySfSoundStream_SetVolume, METH_O, "SetVolume(Volume)\nSet the sound volume.\n Volume : Volume (in range [0, 100])"},
|
||||
{"SetPosition", (PyCFunction)PySfSoundStream_SetPosition, METH_VARARGS, "SetPosition(X, Y, Z)\nSet the sound position in the world.\n X,Y,Z : Position of the sound in the world"},
|
||||
{"GetPitch", (PyCFunction)PySfSoundStream_GetPitch, METH_NOARGS, "GetPitch()\nGet the sound pitch."},
|
||||
{"GetMinDistance", (PyCFunction)PySfSoundStream_GetMinDistance, METH_NOARGS, "GetMinDistance()\nGet the minimum distance."},
|
||||
{"GetAttenuation", (PyCFunction)PySfSoundStream_GetAttenuation, METH_NOARGS, "GetAttenuation()\nGet the attenuation factor."},
|
||||
{"GetVolume", (PyCFunction)PySfSoundStream_GetVolume, METH_NOARGS, "GetVolume()\nGet the sound volume."},
|
||||
{"GetPosition", (PyCFunction)PySfSoundStream_GetPosition, METH_NOARGS, "GetPosition()\nGet the sound position in the world. Returns a tuple."},
|
||||
{"Pause", (PyCFunction)PySfSoundStream_Pause, METH_NOARGS, "Pause()\nPause the sound."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfSoundStreamType = {
|
||||
head_init
|
||||
"SoundStream", /*tp_name*/
|
||||
sizeof(PySfSoundStream), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSoundStream_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"SoundStream is a streamed sound, ie samples are acquired\
|
||||
while the sound is playing. Use it for big sounds that would\
|
||||
require hundreds of MB in memory (see Music),\
|
||||
or for streaming sound from the network", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfSoundStream_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfSoundStream_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
PySfSoundStream_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::SoundStream::Stopped);
|
||||
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Stopped", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::SoundStream::Paused);
|
||||
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Paused", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::SoundStream::Playing);
|
||||
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Playing", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
51
bindings/python/src/SoundStream.hpp
Normal file
51
bindings/python/src/SoundStream.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUNDSTREAM_HPP
|
||||
#define __PYSOUNDSTREAM_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Audio/SoundStream.hpp>
|
||||
|
||||
class CustomSoundStream : public sf::SoundStream
|
||||
{
|
||||
public :
|
||||
PyObject *SoundStream;
|
||||
virtual void OnSeek(float TimeOffset);
|
||||
virtual bool OnGetData(Chunk& Data);
|
||||
void Init(unsigned int ChannelsCount, unsigned int SampleRate);
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
CustomSoundStream *obj;
|
||||
} PySfSoundStream;
|
||||
|
||||
void
|
||||
PySfSoundStream_InitConst();
|
||||
|
||||
#endif
|
||||
|
256
bindings/python/src/Sprite.cpp
Normal file
256
bindings/python/src/Sprite.cpp
Normal file
|
@ -0,0 +1,256 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Sprite.hpp"
|
||||
#include "Drawable.hpp"
|
||||
#include "Color.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfIntRectType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
|
||||
static void
|
||||
PySfSprite_dealloc(PySfSprite *self)
|
||||
{
|
||||
Py_CLEAR(self->Image);
|
||||
Py_CLEAR(self->SubRect);
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSprite *self;
|
||||
|
||||
self = (PySfSprite *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Image = NULL;
|
||||
self->SubRect = NULL;
|
||||
self->IsCustom = false;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfSprite_init(PySfSprite *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Image", "X", "Y", "ScaleX", "ScaleY", "Rotation", "Color", NULL};
|
||||
float X=0, Y=0, ScaleX=1, ScaleY=1, Rotation=0;
|
||||
PySfImage *Image=NULL;
|
||||
PySfColor *Color=NULL;
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!|fffffO!:Sprite.__init__", (char **)kwlist, &PySfImageType, &Image, &X, &Y, &ScaleX, &ScaleY, &Rotation, &PySfColorType, &Color))
|
||||
return -1;
|
||||
|
||||
Py_INCREF(Image);
|
||||
self->Image = Image;
|
||||
if (Color != NULL)
|
||||
self->obj = new sf::Sprite(*(Image->obj), sf::Vector2f(X, Y), sf::Vector2f(ScaleX, ScaleY), Rotation, *(Color->obj));
|
||||
else
|
||||
self->obj = new sf::Sprite(*(Image->obj), sf::Vector2f(X, Y), sf::Vector2f(ScaleX, ScaleY), Rotation);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_SetImage(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
PySfImage *Image = (PySfImage *)args;
|
||||
if (! PyObject_TypeCheck(Image, &PySfImageType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Sprite.SetImage() Argument is not a sf.Image");
|
||||
return NULL;
|
||||
}
|
||||
Py_CLEAR(self->Image);
|
||||
Py_INCREF(Image);
|
||||
self->Image = Image;
|
||||
self->obj->SetImage(*(Image->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetImage(PySfSprite* self)
|
||||
{
|
||||
Py_INCREF(self->Image);
|
||||
return (PyObject *)(self->Image);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetPixel(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
PySfColor *Color;
|
||||
unsigned int x=0, y=0;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "II:Sprite.GetPixel", &x, &y))
|
||||
return NULL;
|
||||
|
||||
Color = GetNewPySfColor();
|
||||
Color->obj = new sf::Color(self->obj->GetPixel(x, y));
|
||||
Color->r = Color->obj->r;
|
||||
Color->g = Color->obj->g;
|
||||
Color->b = Color->obj->b;
|
||||
Color->a = Color->obj->a;
|
||||
|
||||
return (PyObject *)Color;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_Resize(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
float W=0, H=0;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "ff:Sprite.Resize", &W, &H))
|
||||
return NULL;
|
||||
|
||||
self->obj->Resize(W,H);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetSubRect(PySfSprite* self)
|
||||
{
|
||||
if (self->SubRect != NULL)
|
||||
{
|
||||
Py_INCREF(self->SubRect);
|
||||
return (PyObject *)(self->SubRect);
|
||||
}
|
||||
else
|
||||
{
|
||||
PySfIntRect *Rect;
|
||||
Rect = GetNewPySfIntRect();
|
||||
Rect->Owner = false;
|
||||
Rect->obj = (sf::IntRect *) &(self->obj->GetSubRect());
|
||||
PySfIntRectUpdateSelf(Rect);
|
||||
Py_INCREF(Rect);
|
||||
self->SubRect = Rect;
|
||||
return (PyObject *)Rect;
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_SetSubRect(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
PySfIntRect *Rect = (PySfIntRect *)args;
|
||||
if (!PyObject_TypeCheck(Rect, &PySfIntRectType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Sprite.SetSubRect() Argument is not a sf.IntRect instance");
|
||||
return NULL;
|
||||
}
|
||||
Py_CLEAR(self->SubRect);
|
||||
Py_INCREF(Rect);
|
||||
self->SubRect = Rect;
|
||||
self->obj->SetSubRect(*(Rect->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_FlipX(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
self->obj->FlipX(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_FlipY(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
self->obj->FlipY(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetSize(PySfSprite* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetSize();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyMethodDef PySfSprite_methods[] = {
|
||||
{"SetImage", (PyCFunction)PySfSprite_SetImage, METH_O, "SetImage(Image)\nChange the image of the sprite.\n Image : new image (sf.Image instance)"},
|
||||
{"GetImage", (PyCFunction)PySfSprite_GetImage, METH_NOARGS, "GetImage()\nGet the source image of the sprite."},
|
||||
{"GetSize", (PyCFunction)PySfSprite_GetSize, METH_NOARGS, "GetSize()\nGet the sprite's size."},
|
||||
{"GetPixel", (PyCFunction)PySfSprite_GetPixel, METH_VARARGS, "GetPixel()\nGet the color of a given pixel in the sprite."},
|
||||
{"Resize", (PyCFunction)PySfSprite_Resize, METH_VARARGS, "Resize(Width, Height)\nResize the sprite (by changing its scale factors). The default size is defined by the subrect.\n\
|
||||
Width : New width (must be strictly positive)\n\
|
||||
Height : New height (must be strictly positive)"},
|
||||
{"GetSubRect", (PyCFunction)PySfSprite_GetSubRect, METH_NOARGS, "GetSubRect()\nGet the sub-rectangle of the sprite inside the source image."},
|
||||
{"SetSubRect", (PyCFunction)PySfSprite_SetSubRect, METH_O, "SetSubRect(SubRect)\nSet the sub-rectangle of the sprite inside the source image. By default, the subrect covers the entire source image.\n SubRect : New sub-rectangle"},
|
||||
{"FlipX", (PyCFunction)PySfSprite_FlipX, METH_O, "FlipX(Flipped)\nFlip the sprite horizontally.\n Flipped : True to flip the sprite"},
|
||||
{"FlipY", (PyCFunction)PySfSprite_FlipY, METH_O, "FlipY(Flipped)\nFlip the sprite vertically.\n Flipped : True to flip the sprite"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfSpriteType = {
|
||||
head_init
|
||||
"Sprite", /*tp_name*/
|
||||
sizeof(PySfSprite), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSprite_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sfSprite defines a sprite : texture, transformations, color, and draw on screen", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfSprite_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfSprite_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfSprite_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
43
bindings/python/src/Sprite.hpp
Normal file
43
bindings/python/src/Sprite.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSPRITE_HPP
|
||||
#define __PYSPRITE_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
|
||||
#include "Image.hpp"
|
||||
#include "Rect.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool IsCustom;
|
||||
sf::Sprite *obj;
|
||||
PySfImage *Image;
|
||||
PySfIntRect *SubRect;
|
||||
} PySfSprite;
|
||||
|
||||
#endif
|
307
bindings/python/src/Text.cpp
Normal file
307
bindings/python/src/Text.cpp
Normal file
|
@ -0,0 +1,307 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Text.hpp"
|
||||
#include "Font.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Rect.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
extern PyTypeObject PySfFontType;
|
||||
|
||||
|
||||
static void
|
||||
PySfText_dealloc(PySfText *self)
|
||||
{
|
||||
Py_CLEAR(self->font);
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfText *self;
|
||||
self = (PySfText *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->font = NULL;
|
||||
self->IsCustom = false;
|
||||
self->obj = new sf::Text();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_SetString(PySfText* self, PyObject *args)
|
||||
{
|
||||
char *Text, *EncodingStr=NULL;
|
||||
int Length;
|
||||
std::string Encoding;
|
||||
if (PyArg_ParseTuple(args, "u:Text.SetString", &Text))
|
||||
{
|
||||
#if Py_UNICODE_SIZE == 4
|
||||
self->obj->SetString((sf::Uint32 *)Text);
|
||||
#else
|
||||
self->obj->SetString((sf::Uint16 *)Text);
|
||||
#endif
|
||||
}
|
||||
else if (PyArg_ParseTuple(args, "s|#s:Text.SetString", &Text, &Length, &EncodingStr))
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (EncodingStr == NULL)
|
||||
self->obj->SetString(Text);
|
||||
else
|
||||
{
|
||||
Encoding.assign(EncodingStr);
|
||||
if (Encoding == "utf8")
|
||||
self->obj->SetString(Text);
|
||||
else if (Encoding == "utf16")
|
||||
self->obj->SetString(Text+2);
|
||||
else if (Encoding == "utf32")
|
||||
self->obj->SetString(Text+4);
|
||||
else
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "Text.SetString() Encoding %s not supported", EncodingStr);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_BadArgument();
|
||||
return NULL;
|
||||
}
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_SetFont(PySfText* self, PyObject *args)
|
||||
{
|
||||
PySfFont *Font = (PySfFont *)args;
|
||||
if (!PyObject_TypeCheck(Font, &PySfFontType))
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "Text.SetFont() Argument must be a sf.Font");
|
||||
return NULL;
|
||||
}
|
||||
Py_CLEAR(self->font);
|
||||
Py_INCREF(args);
|
||||
self->font = Font;
|
||||
self->obj->SetFont(*(Font->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_SetCharacterSize(PySfText* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetCharacterSize(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_GetCharacterSize(PySfText* self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetCharacterSize());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_SetStyle(PySfText* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetStyle(PyLong_AsUnsignedLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_GetStyle(PySfText* self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetStyle());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_GetString(PySfText* self)
|
||||
{
|
||||
#if Py_UNICODE_SIZE == 4
|
||||
const sf::String& Text(self->obj->GetString());
|
||||
#else
|
||||
const sf::String& Text(self->obj->GetString());
|
||||
#endif
|
||||
return PyUnicode_FromUnicode((const Py_UNICODE*)Text.ToAnsiString().c_str(), Text.GetSize());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_GetFont(PySfText* self)
|
||||
{
|
||||
if (self->font == NULL)
|
||||
{
|
||||
PySfFont *Font = GetNewPySfFont();
|
||||
Font->obj = (sf::Font *)&(sf::Font::GetDefaultFont());
|
||||
Font->Owner = false;
|
||||
return (PyObject *)Font;
|
||||
}
|
||||
else
|
||||
{
|
||||
Py_INCREF(self->font);
|
||||
return (PyObject *)(self->font);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_GetRect(PySfText* self)
|
||||
{
|
||||
PySfFloatRect *Rect;
|
||||
|
||||
Rect = GetNewPySfFloatRect();
|
||||
Rect->Owner = true;
|
||||
Rect->obj = new sf::FloatRect (self->obj->GetRect());
|
||||
PySfFloatRectUpdateSelf(Rect);
|
||||
|
||||
return (PyObject *)Rect;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfText_GetCharacterPos(PySfText* self, PyObject *args)
|
||||
{
|
||||
sf::Vector2f Pos = self->obj->GetCharacterPos(PyLong_AsUnsignedLong(args));
|
||||
return Py_BuildValue("ff", Pos.x, Pos.y);
|
||||
}
|
||||
|
||||
static int
|
||||
PySfText_init(PySfText *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Text", "Font", "Size", NULL};
|
||||
float Size = 30.f;
|
||||
PyObject *Text=NULL;
|
||||
PySfFont *Font = NULL;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO!f:Text.__new__", (char **)kwlist, &Text, &PySfFontType, &Font, &Size))
|
||||
return -1;
|
||||
|
||||
if (Text != NULL)
|
||||
{
|
||||
if (PyUnicode_Check(Text))
|
||||
{
|
||||
#if Py_UNICODE_SIZE == 4
|
||||
self->obj->SetString((sf::Uint32 *)PyUnicode_AS_UNICODE(Text));
|
||||
#else
|
||||
self->obj->SetString((sf::Uint16 *)PyUnicode_AS_UNICODE(Text));
|
||||
#endif
|
||||
}
|
||||
#ifdef IS_PY3K
|
||||
else if (PyBytes_Check(Text))
|
||||
self->obj->SetString(PyBytes_AsString(Text));
|
||||
#else
|
||||
else if (PyString_Check(Text))
|
||||
self->obj->SetString(PyString_AsString(Text));
|
||||
#endif
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Text.__init__() first argument must be str");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (Font) PySfText_SetFont(self, (PyObject *)Font);
|
||||
self->obj->SetCharacterSize(Size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfText_methods[] = {
|
||||
{"GetCharacterPos", (PyCFunction)PySfText_GetCharacterPos, METH_O, "GetCharacterPos(Index)\n\
|
||||
Return the visual position (a tuple of two floats) of the Index-th character of the string, in coordinates relative to the string (note : translation, center, rotation and scale are not applied)\n\
|
||||
Index : Index of the character"},
|
||||
{"SetString", (PyCFunction)PySfText_SetString, METH_VARARGS, "SetString(UnicodeText) or SetString(Text, Encoding='utf8')\nSet the text. Valid encodings are 'utf8', 'utf16' and 'utf32'.\n Text : New text"},
|
||||
{"GetString", (PyCFunction)PySfText_GetString, METH_NOARGS, "GetString()\nGet the text as an unicode string."},
|
||||
{"SetFont", (PyCFunction)PySfText_SetFont, METH_O, "SetFont(Font)\nSet the font of the string.\n Font : font to use"},
|
||||
{"GetFont", (PyCFunction)PySfText_GetFont, METH_NOARGS, "GetFont()\nGet the font used by the string."},
|
||||
{"SetCharacterSize", (PyCFunction)PySfText_SetCharacterSize, METH_O, "SetCharacterSize(Size)\nSet the size of the text.\n Size : New size, in pixels"},
|
||||
{"GetCharacterSize", (PyCFunction)PySfText_GetCharacterSize, METH_NOARGS, "GetCharacterSize()\nGet the size of the characters."},
|
||||
{"SetStyle", (PyCFunction)PySfText_SetStyle, METH_O, "SetStyle(TextSize)\nSet the style of the text. The default style is Regular.\n TextSize : New text style, (combination of Style values)"},
|
||||
{"GetStyle", (PyCFunction)PySfText_GetStyle, METH_NOARGS, "GetStyle()\nGet the style of the text."},
|
||||
{"GetRect", (PyCFunction)PySfText_GetRect, METH_NOARGS, "GetRect()\nGet the string rectangle on screen."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfTextType = {
|
||||
head_init
|
||||
"Text", /*tp_name*/
|
||||
sizeof(PySfText), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfText_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Text defines a graphical 2D text, that can be drawn on screen.\n\
|
||||
Default constructor : Text ()\nConstruct the string from an unicode or an ascii string : Text(Text, Font=sf.Font.GetDefaultFont(), Size=30.)\n Text : Text assigned to the string\n Font : Font used to draw the string (SFML built-in font by default)\n Size : Characters size (30 by default)", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfText_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfText_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfText_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
|
||||
void PySfText_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Text::Regular);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Regular", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Text::Bold);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Bold", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Text::Italic);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Italic", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Text::Underlined);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Underlined", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
43
bindings/python/src/Text.hpp
Normal file
43
bindings/python/src/Text.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSTRING_HPP
|
||||
#define __PYSTRING_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
#include "Font.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool IsCustom;
|
||||
sf::Text *obj;
|
||||
PySfFont *font;
|
||||
} PySfText;
|
||||
|
||||
void PySfText_InitConst();
|
||||
|
||||
#endif
|
197
bindings/python/src/VideoMode.cpp
Normal file
197
bindings/python/src/VideoMode.cpp
Normal file
|
@ -0,0 +1,197 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "VideoMode.hpp"
|
||||
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyMemberDef PySfVideoMode_members[] = {
|
||||
{(char *)"Width", T_UINT, offsetof(PySfVideoMode, Width), 0, (char *)"Video mode width, in pixels."},
|
||||
{(char *)"Height", T_UINT, offsetof(PySfVideoMode, Height), 0, (char *)"Video mode height, in pixels."},
|
||||
{(char *)"BitsPerPixel", T_UINT, offsetof(PySfVideoMode, BitsPerPixel), 0, (char *)"Video mode pixel depth, in bits per pixels."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfVideoMode_dealloc(PySfVideoMode* self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfVideoMode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Width", "Height", "BitsPerPixel", NULL};
|
||||
PySfVideoMode *self;
|
||||
self = (PySfVideoMode *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->BitsPerPixel = 32;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|I:VideoMode.__new__", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
|
||||
return NULL;
|
||||
self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfVideoMode_IsValid(PySfVideoMode* self)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->IsValid());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfVideoMode_GetDesktopMode(PySfVideoMode* self)
|
||||
{
|
||||
PySfVideoMode *VideoMode;
|
||||
|
||||
VideoMode = GetNewPySfVideoMode();
|
||||
VideoMode->obj = new sf::VideoMode(sf::VideoMode::GetDesktopMode());
|
||||
VideoMode->Width = VideoMode->obj->Width;
|
||||
VideoMode->Height = VideoMode->obj->Height;
|
||||
VideoMode->BitsPerPixel = VideoMode->obj->BitsPerPixel;
|
||||
|
||||
return (PyObject *)VideoMode;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfVideoMode_GetMode(PySfVideoMode* self, PyObject *args)
|
||||
{
|
||||
std::size_t index;
|
||||
PySfVideoMode *VideoMode;
|
||||
|
||||
index = (std::size_t)PyLong_AsLong(args);
|
||||
|
||||
VideoMode = GetNewPySfVideoMode();
|
||||
VideoMode->obj = new sf::VideoMode(sf::VideoMode::GetMode(index));
|
||||
VideoMode->Width = VideoMode->obj->Width;
|
||||
VideoMode->Height = VideoMode->obj->Height;
|
||||
VideoMode->BitsPerPixel = VideoMode->obj->BitsPerPixel;
|
||||
|
||||
return (PyObject *)VideoMode;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfVideoMode_GetModesCount(PySfVideoMode* self)
|
||||
{
|
||||
return PyLong_FromLong(sf::VideoMode::GetModesCount());
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfVideoMode_methods[] = {
|
||||
{"IsValid", (PyCFunction)PySfVideoMode_IsValid, METH_NOARGS, "IsValid()\nTell whether or not the video mode is supported."},
|
||||
{"GetDesktopMode", (PyCFunction)PySfVideoMode_GetDesktopMode, METH_STATIC | METH_NOARGS, "GetDesktopMode()\nGet the current desktop video mode."},
|
||||
{"GetMode", (PyCFunction)PySfVideoMode_GetMode, METH_STATIC | METH_O, "GetMode(Index)\nGet a valid video mode. Index must be in range [0, GetModesCount()[ Modes are sorted from best to worst.\n Index : Index of video mode to get"},
|
||||
{"GetModesCount", (PyCFunction)PySfVideoMode_GetModesCount, METH_STATIC | METH_NOARGS, "GetModesCount()\nGet valid video modes count."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyObject *
|
||||
PySfVideoMode_richcompare(PyObject *o1, PyObject *o2, int op)
|
||||
{
|
||||
if (*(((PySfVideoMode *)o1)->obj) == *(((PySfVideoMode *)o2)->obj))
|
||||
{
|
||||
if (op==Py_EQ)
|
||||
Py_RETURN_TRUE;
|
||||
if (op==Py_NE)
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
else
|
||||
{
|
||||
if (op==Py_EQ)
|
||||
Py_RETURN_FALSE;
|
||||
if (op==Py_NE)
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
PyErr_SetString(PyExc_TypeError, "VideoMode comparison : only == and != make sens.");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int
|
||||
PySfVideoMode_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||
{
|
||||
int result = PyObject_GenericSetAttr(self, attr_name, v);
|
||||
PySfVideoMode *Mode = (PySfVideoMode *)self;
|
||||
Mode->obj->Width = Mode->Width;
|
||||
Mode->obj->Height = Mode->Height;
|
||||
Mode->obj->BitsPerPixel = Mode->BitsPerPixel;
|
||||
return result;
|
||||
}
|
||||
|
||||
PyTypeObject PySfVideoModeType = {
|
||||
head_init
|
||||
"VideoMode", /*tp_name*/
|
||||
sizeof(PySfVideoMode), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfVideoMode_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.VideoMode defines a video mode (width, height, bpp, frequency) and provides functions for getting modes supported by the display device\n\
|
||||
Default constructor : VideoMode()\n\
|
||||
Construct the video mode with its attributes : VideoMode(ModeWidth, ModeHeight, ModeBpp = 32)\n ModeWidth : Width in pixels\n ModeHeight : Height in pixels\n ModeBpp : Pixel depths in bits per pixel (32 by default)", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
PySfVideoMode_richcompare, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfVideoMode_methods, /* tp_methods */
|
||||
PySfVideoMode_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfVideoMode_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
PySfVideoMode *
|
||||
GetNewPySfVideoMode()
|
||||
{
|
||||
return PyObject_New(PySfVideoMode, &PySfVideoModeType);
|
||||
}
|
||||
|
43
bindings/python/src/VideoMode.hpp
Normal file
43
bindings/python/src/VideoMode.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYVIDEOMODE_HPP
|
||||
#define __PYVIDEOMODE_HPP
|
||||
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
unsigned int BitsPerPixel;
|
||||
sf::VideoMode *obj;
|
||||
} PySfVideoMode;
|
||||
|
||||
PySfVideoMode *
|
||||
GetNewPySfVideoMode();
|
||||
|
||||
#endif
|
168
bindings/python/src/View.cpp
Normal file
168
bindings/python/src/View.cpp
Normal file
|
@ -0,0 +1,168 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "View.hpp"
|
||||
|
||||
#include "offsetof.hpp"
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfFloatRectType;
|
||||
|
||||
|
||||
static void
|
||||
PySfView_dealloc(PySfView *self)
|
||||
{
|
||||
if (self->Owner)
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfView *self;
|
||||
|
||||
self = (PySfView *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Owner = true;
|
||||
PySfFloatRect *Rect = NULL;
|
||||
if (!PyArg_ParseTuple(args, "|O!:View.__new__", &PySfFloatRectType, &Rect))
|
||||
return NULL;
|
||||
|
||||
if (Rect != NULL)
|
||||
self->obj = new sf::View( (const sf::FloatRect) *(Rect->obj));
|
||||
else
|
||||
self->obj = new sf::View();
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_GetCenter(PySfView* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetCenter();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_Reset(PySfView* self, PyObject *args)
|
||||
{
|
||||
PySfFloatRect *Rect = (PySfFloatRect *)args;
|
||||
if (!PyObject_TypeCheck(Rect, &PySfFloatRectType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "View.Reset() Argument is not a sf.FloatRect instance");
|
||||
return NULL;
|
||||
}
|
||||
self->obj->Reset(*(Rect->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_Move(PySfView* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if (!PyArg_ParseTuple(args, "ff:View.Move", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->Move(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_SetCenter(PySfView* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if (!PyArg_ParseTuple(args, "ff:View.SetCenter", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->SetCenter(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_Zoom(PySfView* self, PyObject *args)
|
||||
{
|
||||
self->obj->Zoom(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfView_methods[] = {
|
||||
{"GetCenter", (PyCFunction)PySfView_GetCenter, METH_NOARGS, "GetCenter()\nGet the center of the view."},
|
||||
{"Move", (PyCFunction)PySfView_Move, METH_VARARGS, "Move(OffsetX, OffsetY)\nMove the view.\n\
|
||||
OffsetX : Offset to move the view, on X axis\n\
|
||||
OffsetY : Offset to move the view, on Y axis"},
|
||||
{"Reset", (PyCFunction)PySfView_Reset, METH_O, "Reset(ViewRect)\nRebuild the view from a rectangle.\n ViewRect : Rectangle defining the position and size of the view."},
|
||||
{"SetCenter", (PyCFunction)PySfView_SetCenter, METH_VARARGS, "SetCenter(X, Y)\nChange the center of the view."},
|
||||
{"Zoom", (PyCFunction)PySfView_Zoom, METH_O, "Zoom(Factor)\nResize the view rectangle to simulate a zoom / unzoom effect."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfViewType = {
|
||||
head_init
|
||||
"View", /*tp_name*/
|
||||
sizeof(PySfView), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfView_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"This class defines a view (position, size, etc.) ; you can consider it as a 2D camera.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfView_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfView_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfView *
|
||||
GetNewPySfView()
|
||||
{
|
||||
return PyObject_New(PySfView, &PySfViewType);
|
||||
}
|
||||
|
43
bindings/python/src/View.hpp
Normal file
43
bindings/python/src/View.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYVIEW_HPP
|
||||
#define __PYVIEW_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/View.hpp>
|
||||
|
||||
#include "Rect.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool Owner;
|
||||
sf::View *obj;
|
||||
} PySfView;
|
||||
|
||||
PySfView *
|
||||
GetNewPySfView();
|
||||
|
||||
#endif
|
395
bindings/python/src/Window.cpp
Normal file
395
bindings/python/src/Window.cpp
Normal file
|
@ -0,0 +1,395 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Window.hpp"
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "VideoMode.hpp"
|
||||
#include "Input.hpp"
|
||||
#include "ContextSettings.hpp"
|
||||
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfEventType;
|
||||
extern PyTypeObject PySfContextSettingsType;
|
||||
extern PyTypeObject PySfVideoModeType;
|
||||
|
||||
|
||||
static void
|
||||
PySfWindow_dealloc(PySfWindow* self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
long Handle;
|
||||
PySfContextSettings *Params=NULL;
|
||||
PySfWindow *self;
|
||||
self = (PySfWindow *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfContextSettingsType, &Params))
|
||||
{
|
||||
if (Params)
|
||||
{
|
||||
PySfContextSettingsUpdate(Params);
|
||||
self->obj = new sf::Window((sf::WindowHandle)Handle, *(Params->obj));
|
||||
}
|
||||
else
|
||||
self->obj = new sf::Window((sf::WindowHandle)Handle);
|
||||
}
|
||||
else
|
||||
{
|
||||
PyErr_Clear();
|
||||
self->obj = new sf::Window();
|
||||
}
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static PyObject*
|
||||
PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
PySfEvent *PyEvent = (PySfEvent *)args;
|
||||
|
||||
if (! PyObject_TypeCheck(PyEvent, &PySfEventType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Window.GetEvent() Argument is not a sfEvent");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->obj->GetEvent(*(PyEvent->obj)))
|
||||
{
|
||||
PyEvent->Type = PyEvent->obj->Type;
|
||||
PyEvent->Text->Unicode = PyEvent->obj->Text.Unicode;
|
||||
PyEvent->Key->Code = PyEvent->obj->Key.Code;
|
||||
Py_DECREF(PyEvent->Key->Alt);
|
||||
PyEvent->Key->Alt = PyBool_FromLong(PyEvent->obj->Key.Alt);
|
||||
Py_DECREF(PyEvent->Key->Control);
|
||||
PyEvent->Key->Control = PyBool_FromLong(PyEvent->obj->Key.Control);
|
||||
Py_DECREF(PyEvent->Key->Shift);
|
||||
PyEvent->Key->Shift = PyBool_FromLong(PyEvent->obj->Key.Shift);
|
||||
PyEvent->MouseButton->Button = PyEvent->obj->MouseButton.Button;
|
||||
PyEvent->MouseButton->X = PyEvent->obj->MouseButton.X;
|
||||
PyEvent->MouseButton->Y = PyEvent->obj->MouseButton.Y;
|
||||
PyEvent->MouseMove->X = PyEvent->obj->MouseMove.X;
|
||||
PyEvent->MouseMove->Y = PyEvent->obj->MouseMove.Y;
|
||||
PyEvent->JoyMove->JoystickId = PyEvent->obj->JoyMove.JoystickId;
|
||||
PyEvent->JoyButton->JoystickId = PyEvent->obj->JoyButton.JoystickId;
|
||||
PyEvent->JoyButton->Button = PyEvent->obj->JoyButton.Button;
|
||||
PyEvent->JoyMove->Axis = PyEvent->obj->JoyMove.Axis;
|
||||
PyEvent->JoyMove->Position = PyEvent->obj->JoyMove.Position;
|
||||
PyEvent->Size->Width = PyEvent->obj->Size.Width;
|
||||
PyEvent->Size->Height = PyEvent->obj->Size.Height;
|
||||
PyEvent->MouseWheel->Delta = PyEvent->obj->MouseWheel.Delta;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
PyObject*
|
||||
PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyObject *VideoModeTmp=NULL;
|
||||
sf::VideoMode *VideoMode;
|
||||
char *Title=NULL;
|
||||
unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close;
|
||||
PySfContextSettings *Params=NULL;
|
||||
|
||||
const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!:Window.Create", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfContextSettingsType, &Params))
|
||||
return NULL;
|
||||
|
||||
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
||||
|
||||
if (Params)
|
||||
{
|
||||
PySfContextSettingsUpdate(Params);
|
||||
self->obj->Create(*VideoMode, Title, WindowStyle, *(Params->obj));
|
||||
}
|
||||
else
|
||||
self->obj->Create(*VideoMode, Title, WindowStyle);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
long Handle;
|
||||
PySfContextSettings *Params;
|
||||
|
||||
if (args != NULL)
|
||||
{
|
||||
if (PyTuple_Size(args) == 0)
|
||||
return 0;
|
||||
if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfContextSettingsType, &Params))
|
||||
return 0;
|
||||
PyErr_Clear();
|
||||
if (PySfWindow_Create(self, args, kwds) == NULL)
|
||||
return -1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_Close(PySfWindow *self)
|
||||
{
|
||||
self->obj->Close();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_IsOpened(PySfWindow *self)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->IsOpened());
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_GetWidth(PySfWindow *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetWidth());
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_GetHeight(PySfWindow *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetHeight());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_UseVerticalSync(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->UseVerticalSync(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_ShowMouseCursor(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->ShowMouseCursor(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetActive(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
return PyBool_FromLong(self->obj->SetActive(PyBool_AsBool(args)));
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_Display(PySfWindow *self)
|
||||
{
|
||||
self->obj->Display();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_GetFrameTime(PySfWindow *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetFrameTime());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_GetInput(PySfWindow *self)
|
||||
{
|
||||
PySfInput *Input;
|
||||
Input = GetNewPySfInput();
|
||||
Input->obj = (sf::Input *)&self->obj->GetInput();
|
||||
return (PyObject *)Input;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_GetSettings(PySfWindow *self)
|
||||
{
|
||||
PySfContextSettings *Settings;
|
||||
Settings = GetNewPySfContextSettings();
|
||||
Settings->obj = new sf::ContextSettings(self->obj->GetSettings());
|
||||
Settings->DepthBits = Settings->obj->DepthBits;
|
||||
Settings->StencilBits = Settings->obj->StencilBits;
|
||||
Settings->AntialiasingLevel = Settings->obj->AntialiasingLevel;
|
||||
return (PyObject *)Settings;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetPosition(PySfWindow* self, PyObject *args)
|
||||
{
|
||||
int Left=0, Top=0;
|
||||
if (!PyArg_ParseTuple(args, "ii:Window.SetPosition", &Left, &Top))
|
||||
return NULL;
|
||||
self->obj->SetPosition(Left,Top);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetFramerateLimit(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetFramerateLimit(PyLong_AsUnsignedLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_Show(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->Show(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_EnableKeyRepeat(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->EnableKeyRepeat(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetCursorPosition(PySfWindow* self, PyObject *args)
|
||||
{
|
||||
unsigned int Left=0, Top=0;
|
||||
if (!PyArg_ParseTuple(args, "II:Window.SetCursorPosition", &Left, &Top))
|
||||
return NULL;
|
||||
self->obj->SetCursorPosition(Left,Top);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetSize(PySfWindow* self, PyObject *args)
|
||||
{
|
||||
unsigned int Width=0, Height=0;
|
||||
if (!PyArg_ParseTuple(args, "II:Window.SetSize", &Width, &Height))
|
||||
return NULL;
|
||||
self->obj->SetSize(Width, Height);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetJoystickThreshold(PySfWindow* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetJoystickThreshold(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetIcon(PySfWindow* self, PyObject *args)
|
||||
{
|
||||
unsigned int Width, Height, Size;
|
||||
char *Data;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "IIs#:Window.SetIcon", &Width, &Height, &Data, &Size))
|
||||
return NULL;
|
||||
|
||||
self->obj->SetIcon(Width, Height, (sf::Uint8*) Data);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfWindow_methods[] = {
|
||||
{"Close", (PyCFunction)PySfWindow_Close, METH_NOARGS, "Close()\nClose (destroy) the window. The sf.Window instance remains valid and you can call Create to recreate the window."},
|
||||
{"Create", (PyCFunction)PySfWindow_Create, METH_VARARGS | METH_KEYWORDS, "Create(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.ContextSettings())\n\
|
||||
Create a window.\n\
|
||||
Mode : Video mode to use (sf.VideoMode instance)\n\
|
||||
Title : Title of the window\n\
|
||||
WindowStyle : Window style (Resize | Close by default)\n\
|
||||
Params : Creation parameters (see default constructor for default values)"},
|
||||
{"Display", (PyCFunction)PySfWindow_Display, METH_NOARGS, "Display()\nDisplay the window on screen."},
|
||||
{"EnableKeyRepeat", (PyCFunction)PySfWindow_EnableKeyRepeat, METH_O, "EnableKeyRepeat(Enable)\nEnable or disable automatic key-repeat. Automatic key-repeat is enabled by default.\n Enabled : True to enable, false to disable"},
|
||||
{"GetEvent", (PyCFunction)PySfWindow_GetEvent, METH_O, "GetEvent(Event)\nGet the event on top of events stack, if any, and pop it. Returns True if an event was returned, False if events stack was empty.\n EventReceived : Event to fill, if any."},
|
||||
{"GetFrameTime", (PyCFunction)PySfWindow_GetFrameTime, METH_NOARGS, "GetFrameTime()\nGet time elapsed since last frame. Returns time elapsed, in seconds"},
|
||||
{"GetHeight", (PyCFunction)PySfWindow_GetHeight, METH_NOARGS, "GetHeight()\nGet the height of the rendering region of the window."},
|
||||
{"GetInput", (PyCFunction)PySfWindow_GetInput, METH_NOARGS, "GetInput()\nGet the input manager of the window."},
|
||||
{"GetSettings", (PyCFunction)PySfWindow_GetSettings, METH_NOARGS, "GetSettings()\nGet the creation settings of the window."},
|
||||
{"GetWidth", (PyCFunction)PySfWindow_GetWidth, METH_NOARGS, "GetWidth()\nGet the width of the rendering region of the window."},
|
||||
{"IsOpened", (PyCFunction)PySfWindow_IsOpened, METH_NOARGS, "IsOpened()\nTell whether or not the window is opened (ie. has been created). Note that a hidden window (Show(False)) will still return True."},
|
||||
{"SetActive", (PyCFunction)PySfWindow_SetActive, METH_O, "SetActive(Active)\nActivate of deactivate the window as the current target for rendering. Returns True if operation was successful, False otherwise.\n Active : True to activate, False to deactivate (True by default)"},
|
||||
{"SetCursorPosition", (PyCFunction)PySfWindow_SetCursorPosition, METH_VARARGS, "SetCursorPosition(Left, Top)\nChange the position of the mouse cursor.\n Left : Left coordinate of the cursor, relative to the window\n Top : Top coordinate of the cursor, relative to the window"},
|
||||
{"SetSize", (PyCFunction)PySfWindow_SetSize, METH_VARARGS, "SetSize(Width, Height)\nChange the size of the rendering region of the window.\n\
|
||||
Width : New width\n Height : New height"},
|
||||
{"SetFramerateLimit", (PyCFunction)PySfWindow_SetFramerateLimit, METH_O, "SetFramerateLimit(Limit)\nSet the framerate at a fixed frequency.\n Limit : Framerate limit, in frames per seconds (use 0 to disable limit)"},
|
||||
{"SetJoystickThreshold", (PyCFunction)PySfWindow_SetJoystickThreshold, METH_O, "SetJoystickThreshold(Threshold)\nChange the joystick threshold, ie. the value below which no move event will be generated.\n Threshold : New threshold, in range [0., 100.]"},
|
||||
{"SetPosition", (PyCFunction)PySfWindow_SetPosition, METH_VARARGS, "SetPosition(X, Y)\nChange the position of the window on screen. Only works for top-level windows\n Left : Left position\n Top : Top position"},
|
||||
{"Show", (PyCFunction)PySfWindow_Show, METH_O, "Show(State)\nShow or hide the window.\n State : True to show, false to hide."},
|
||||
{"ShowMouseCursor", (PyCFunction)PySfWindow_ShowMouseCursor, METH_O, "ShowMouseCursor(Show)\nShow or hide the mouse cursor.\n Show : True to show, false to hide."},
|
||||
{"UseVerticalSync", (PyCFunction)PySfWindow_UseVerticalSync, METH_O, "UseVerticalSync(Enabled)\nEnable / disable vertical synchronization.\n Enabled : True to enable v-sync, False to deactivate"},
|
||||
{"SetIcon", (PyCFunction)PySfWindow_SetIcon, METH_VARARGS, "SetIcon(Width, Height, Pixels)\n\
|
||||
Change the window's icon.\n\
|
||||
Width : Icon's width, in pixels\n\
|
||||
Height : Icon's height, in pixels\n\
|
||||
Pixels : Pointer to the pixels in memory, format must be RGBA 32 bits."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfWindowType = {
|
||||
head_init
|
||||
"Window", /*tp_name*/
|
||||
sizeof(PySfWindow), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfWindow_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Window is a rendering window ; it can create a new window or connect to an existing one.\n\
|
||||
Default constructor : sf.Window()\n\
|
||||
Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.ContextSettings())\n\
|
||||
Mode : Video mode to use (sf.VideoMode instance)\n\
|
||||
Title : Title of the window\n\
|
||||
WindowStyle : Window style (Resize | Close by default)\n\
|
||||
Params : Creation parameters (see default constructor for default values)\n\
|
||||
Construct the window from an existing control : sf.Window(Handle, Params)\n\
|
||||
Handle : Platform-specific handle of the control\n\
|
||||
Params : Creation parameters (see default constructor for default values)", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfWindow_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfWindow_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfWindow_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
41
bindings/python/src/Window.hpp
Normal file
41
bindings/python/src/Window.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYWINDOW_HPP
|
||||
#define __PYWINDOW_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/Window.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Window *obj;
|
||||
} PySfWindow;
|
||||
|
||||
PyObject*
|
||||
PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds);
|
||||
|
||||
#endif
|
103
bindings/python/src/WindowStyle.cpp
Normal file
103
bindings/python/src/WindowStyle.cpp
Normal file
|
@ -0,0 +1,103 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "WindowStyle.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfStyle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfStyle *self;
|
||||
self = (PySfStyle *)type->tp_alloc(type, 0);
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
PyTypeObject PySfStyleType = {
|
||||
head_init
|
||||
"Style", /*tp_name*/
|
||||
sizeof(PySfStyle), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
0, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
0, /*tp_compare*/
|
||||
0, /*tp_repr*/
|
||||
0, /*tp_as_number*/
|
||||
0, /*tp_as_sequence*/
|
||||
0, /*tp_as_mapping*/
|
||||
0, /*tp_hash */
|
||||
0, /*tp_call*/
|
||||
0, /*tp_str*/
|
||||
0, /*tp_getattro*/
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"Enumeration of window creation styles.\n\
|
||||
None No border / title bar (this flag and all others are mutually exclusive).\n\
|
||||
Titlebar Title bar + fixed border.\n\
|
||||
Resize Titlebar + resizable border + maximize button.\n\
|
||||
Close Titlebar + close button.\n\
|
||||
Fullscreen Fullscreen mode (this flag and all others are mutually exclusive).", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfStyle_new, /* tp_new */
|
||||
};
|
||||
|
||||
void PySfStyle_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::Style::None);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "None", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Style::Titlebar);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Titlebar", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Style::Resize);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Resize", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Style::Close);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Close", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::Style::Fullscreen);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Fullscreen", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
39
bindings/python/src/WindowStyle.hpp
Normal file
39
bindings/python/src/WindowStyle.hpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYWINDOWSTYLE_HPP
|
||||
#define __PYWINDOWSTYLE_HPP
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfStyle;
|
||||
|
||||
void
|
||||
PySfStyle_InitConst();
|
||||
|
||||
#endif
|
72
bindings/python/src/compat.hpp
Normal file
72
bindings/python/src/compat.hpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYCOMPAT_HPP
|
||||
#define __PYCOMPAT_HPP
|
||||
|
||||
#if PY_MAJOR_VERSION >= 3
|
||||
|
||||
#define IS_PY3K
|
||||
#define head_init PyVarObject_HEAD_INIT(NULL, 0)
|
||||
|
||||
#define save_to_file(self, args) \
|
||||
PyObject *string = PyUnicode_AsUTF8String(args); \
|
||||
if (string == NULL) return NULL; \
|
||||
char *path = PyBytes_AsString(string); \
|
||||
bool result = self->obj->SaveToFile(path); \
|
||||
Py_DECREF(string); \
|
||||
return PyBool_FromLong(result)
|
||||
|
||||
#define load_from_file(self, args) \
|
||||
PyObject *string = PyUnicode_AsUTF8String(args); \
|
||||
if (string == NULL) return NULL; \
|
||||
char *path = PyBytes_AsString(string); \
|
||||
bool result = self->obj->LoadFromFile(path); \
|
||||
Py_DECREF(string); \
|
||||
return PyBool_FromLong(result)
|
||||
|
||||
#else
|
||||
|
||||
#define save_to_file(self, args) \
|
||||
return PyBool_FromLong(self->obj->SaveToFile(PyString_AsString(args)))
|
||||
#define load_from_file(self, args) \
|
||||
return PyBool_FromLong(self->obj->LoadFromFile(PyString_AsString(args)))
|
||||
|
||||
#define head_init PyObject_HEAD_INIT(NULL) 0,
|
||||
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
||||
|
||||
#endif
|
||||
|
||||
#ifndef Py_TYPE
|
||||
#define Py_TYPE(a) a->ob_type
|
||||
#endif
|
||||
|
||||
#define free_object(a) Py_TYPE(a)->tp_free((PyObject*)a)
|
||||
|
||||
#define PyBool_AsBool(a) ((PyObject_IsTrue(a))?true:false)
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
304
bindings/python/src/main.cpp
Normal file
304
bindings/python/src/main.cpp
Normal file
|
@ -0,0 +1,304 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "main.hpp"
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "Key.hpp"
|
||||
#include "Joy.hpp"
|
||||
#include "Event.hpp"
|
||||
#include "Mouse.hpp"
|
||||
#include "WindowStyle.hpp"
|
||||
#include "ContextSettings.hpp"
|
||||
#include "Blend.hpp"
|
||||
#include "Sound.hpp"
|
||||
#include "Text.hpp"
|
||||
#include "SoundStream.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
extern PyTypeObject PySfClockType;
|
||||
|
||||
extern PyTypeObject PySfEventType;
|
||||
extern PyTypeObject PySfEventTextType;
|
||||
extern PyTypeObject PySfEventKeyType;
|
||||
extern PyTypeObject PySfEventMouseMoveType;
|
||||
extern PyTypeObject PySfEventMouseButtonType;
|
||||
extern PyTypeObject PySfEventMouseWheelType;
|
||||
extern PyTypeObject PySfEventJoyMoveType;
|
||||
extern PyTypeObject PySfEventJoyButtonType;
|
||||
extern PyTypeObject PySfEventSizeType;
|
||||
extern PyTypeObject PySfKeyType;
|
||||
extern PyTypeObject PySfJoyType;
|
||||
extern PyTypeObject PySfMouseType;
|
||||
|
||||
extern PyTypeObject PySfVideoModeType;
|
||||
extern PyTypeObject PySfWindowType;
|
||||
extern PyTypeObject PySfStyleType;
|
||||
extern PyTypeObject PySfContextSettingsType;
|
||||
extern PyTypeObject PySfRenderWindowType;
|
||||
extern PyTypeObject PySfViewType;
|
||||
extern PyTypeObject PySfInputType;
|
||||
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
extern PyTypeObject PySfBlendType;
|
||||
extern PyTypeObject PySfSpriteType;
|
||||
extern PyTypeObject PySfFontType;
|
||||
extern PyTypeObject PySfGlyphType;
|
||||
extern PyTypeObject PySfTextType;
|
||||
//extern PyTypeObject PySfPostFXType;
|
||||
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfColorType;
|
||||
|
||||
extern PyTypeObject PySfShapeType;
|
||||
|
||||
extern PyTypeObject PySfIntRectType;
|
||||
extern PyTypeObject PySfFloatRectType;
|
||||
|
||||
extern PyTypeObject PySfMusicType;
|
||||
extern PyTypeObject PySfSoundType;
|
||||
extern PyTypeObject PySfSoundBufferType;
|
||||
extern PyTypeObject PySfSoundRecorderType;
|
||||
extern PyTypeObject PySfSoundBufferRecorderType;
|
||||
extern PyTypeObject PySfSoundStreamType;
|
||||
extern PyTypeObject PySfListenerType;
|
||||
|
||||
|
||||
static PyMethodDef module_methods[] = {
|
||||
{"Sleep", (PyCFunction)PySFML_Sleep, METH_O, "Sleep(Duration)\nMake the current thread sleep for a given time.\n Duration : Time to sleep, in seconds"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
#ifdef IS_PY3K
|
||||
#define INITERROR return NULL
|
||||
static PyModuleDef module_def = {
|
||||
PyModuleDef_HEAD_INIT,
|
||||
"sf",
|
||||
"Python binding for sfml (Simple Fast Media Library)",
|
||||
-1,
|
||||
module_methods, NULL, NULL, NULL, NULL
|
||||
};
|
||||
|
||||
PyMODINIT_FUNC
|
||||
PyInit_sf(void)
|
||||
#else
|
||||
#define INITERROR return
|
||||
|
||||
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
|
||||
#define PyMODINIT_FUNC void
|
||||
#endif
|
||||
PyMODINIT_FUNC
|
||||
initsf(void)
|
||||
#endif
|
||||
{
|
||||
PyObject *m;
|
||||
|
||||
if (PyType_Ready(&PySfClockType) < 0)
|
||||
INITERROR;
|
||||
|
||||
if (PyType_Ready(&PySfWindowType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfStyleType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfContextSettingsType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfRenderWindowType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfVideoModeType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfViewType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfInputType) < 0)
|
||||
INITERROR;
|
||||
|
||||
if (PyType_Ready(&PySfEventType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventTextType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventKeyType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventMouseMoveType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventMouseButtonType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventMouseWheelType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventJoyMoveType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventJoyButtonType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfEventSizeType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfKeyType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfJoyType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfMouseType) < 0)
|
||||
INITERROR;
|
||||
|
||||
if (PyType_Ready(&PySfDrawableType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfBlendType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfSpriteType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfFontType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfGlyphType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfTextType) < 0)
|
||||
INITERROR;
|
||||
/*if (PyType_Ready(&PySfPostFXType) < 0)
|
||||
INITERROR;
*/
|
||||
|
||||
if (PyType_Ready(&PySfImageType) < 0)
|
||||
INITERROR;
|
||||
|
||||
if (PyType_Ready(&PySfShapeType) < 0)
|
||||
INITERROR;
|
||||
|
||||
if (PyType_Ready(&PySfColorType) < 0)
|
||||
INITERROR;
|
||||
|
||||
if (PyType_Ready(&PySfIntRectType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfFloatRectType) < 0)
|
||||
INITERROR;
|
||||
|
||||
if (PyType_Ready(&PySfMusicType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfSoundType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfSoundBufferType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfSoundBufferRecorderType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfSoundRecorderType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfSoundStreamType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfListenerType) < 0)
|
||||
INITERROR;
|
||||
|
||||
#ifdef IS_PY3K
|
||||
m = PyModule_Create(&module_def);
|
||||
#else
|
||||
m = Py_InitModule3("sf", module_methods, "Python binding for sfml (Simple Fast Media Library)");
|
||||
#endif
|
||||
|
||||
if (m == NULL)
|
||||
INITERROR;
|
||||
|
||||
Py_INCREF(&PySfClockType);
|
||||
PyModule_AddObject(m, "Clock", (PyObject *)&PySfClockType);
|
||||
|
||||
Py_INCREF(&PySfWindowType);
|
||||
PyModule_AddObject(m, "Window", (PyObject *)&PySfWindowType);
|
||||
Py_INCREF(&PySfStyleType);
|
||||
PyModule_AddObject(m, "Style", (PyObject *)&PySfStyleType);
|
||||
Py_INCREF(&PySfContextSettingsType);
|
||||
PyModule_AddObject(m, "ContextSettings", (PyObject *)&PySfContextSettingsType);
|
||||
Py_INCREF(&PySfRenderWindowType);
|
||||
PyModule_AddObject(m, "RenderWindow", (PyObject *)&PySfRenderWindowType);
|
||||
Py_INCREF(&PySfVideoModeType);
|
||||
PyModule_AddObject(m, "VideoMode", (PyObject *)&PySfVideoModeType);
|
||||
Py_INCREF(&PySfViewType);
|
||||
PyModule_AddObject(m, "View", (PyObject *)&PySfViewType);
|
||||
Py_INCREF(&PySfInputType);
|
||||
PyModule_AddObject(m, "Input", (PyObject *)&PySfInputType);
|
||||
|
||||
Py_INCREF(&PySfDrawableType);
|
||||
PyModule_AddObject(m, "Drawable", (PyObject *)&PySfDrawableType);
|
||||
Py_INCREF(&PySfBlendType);
|
||||
PyModule_AddObject(m, "Blend", (PyObject *)&PySfBlendType);
|
||||
Py_INCREF(&PySfSpriteType);
|
||||
PyModule_AddObject(m, "Sprite", (PyObject *)&PySfSpriteType);
|
||||
Py_INCREF(&PySfFontType);
|
||||
PyModule_AddObject(m, "Font", (PyObject *)&PySfFontType);
|
||||
Py_INCREF(&PySfGlyphType);
|
||||
PyModule_AddObject(m, "Glyph", (PyObject *)&PySfGlyphType);
|
||||
Py_INCREF(&PySfTextType);
|
||||
PyModule_AddObject(m, "Text", (PyObject *)&PySfTextType);
|
||||
/*Py_INCREF(&PySfPostFXType);
|
||||
PyModule_AddObject(m, "PostFX", (PyObject *)&PySfPostFXType);
*/
|
||||
|
||||
Py_INCREF(&PySfEventType);
|
||||
PyModule_AddObject(m, "Event", (PyObject *)&PySfEventType);
|
||||
Py_INCREF(&PySfKeyType);
|
||||
PyModule_AddObject(m, "Key", (PyObject *)&PySfKeyType);
|
||||
Py_INCREF(&PySfJoyType);
|
||||
PyModule_AddObject(m, "Joy", (PyObject *)&PySfJoyType);
|
||||
Py_INCREF(&PySfMouseType);
|
||||
PyModule_AddObject(m, "Mouse", (PyObject *)&PySfMouseType);
|
||||
|
||||
Py_INCREF(&PySfImageType);
|
||||
PyModule_AddObject(m, "Image", (PyObject *)&PySfImageType);
|
||||
|
||||
Py_INCREF(&PySfColorType);
|
||||
PyModule_AddObject(m, "Color", (PyObject *)&PySfColorType);
|
||||
|
||||
Py_INCREF(&PySfShapeType);
|
||||
PyModule_AddObject(m, "Shape", (PyObject *)&PySfShapeType);
|
||||
|
||||
Py_INCREF(&PySfIntRectType);
|
||||
PyModule_AddObject(m, "IntRect", (PyObject *)&PySfIntRectType);
|
||||
Py_INCREF(&PySfFloatRectType);
|
||||
PyModule_AddObject(m, "FloatRect", (PyObject *)&PySfFloatRectType);
|
||||
|
||||
Py_INCREF(&PySfMusicType);
|
||||
PyModule_AddObject(m, "Music", (PyObject *)&PySfMusicType);
|
||||
Py_INCREF(&PySfSoundType);
|
||||
PyModule_AddObject(m, "Sound", (PyObject *)&PySfSoundType);
|
||||
Py_INCREF(&PySfSoundBufferType);
|
||||
PyModule_AddObject(m, "SoundBuffer", (PyObject *)&PySfSoundBufferType);
|
||||
Py_INCREF(&PySfSoundRecorderType);
|
||||
PyModule_AddObject(m, "SoundRecorder", (PyObject *)&PySfSoundRecorderType);
|
||||
Py_INCREF(&PySfSoundBufferRecorderType);
|
||||
PyModule_AddObject(m, "SoundBufferRecorder", (PyObject *)&PySfSoundBufferRecorderType);
|
||||
Py_INCREF(&PySfSoundStreamType);
|
||||
PyModule_AddObject(m, "SoundStream", (PyObject *)&PySfSoundStreamType);
|
||||
Py_INCREF(&PySfListenerType);
|
||||
PyModule_AddObject(m, "Listener", (PyObject *)&PySfListenerType);
|
||||
|
||||
PyModule_AddStringConstant(m, "Version", "1.6");
|
||||
|
||||
PySfColor_InitConst();
|
||||
PySfKey_InitConst();
|
||||
PySfJoy_InitConst();
|
||||
PySfEvent_InitConst();
|
||||
PySfMouse_InitConst();
|
||||
PySfStyle_InitConst();
|
||||
PySfBlend_InitConst();
|
||||
PySfSound_InitConst();
|
||||
PySfSoundStream_InitConst();
|
||||
PySfText_InitConst();
|
||||
|
||||
PyEval_InitThreads();
|
||||
|
||||
#ifdef IS_PY3K
|
||||
return m;
|
||||
#endif
|
||||
}
|
||||
|
37
bindings/python/src/main.hpp
Normal file
37
bindings/python/src/main.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYMAIN_HPP
|
||||
#define __PYMAIN_HPP
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "Sleep.hpp"
|
||||
|
||||
#endif
|
32
bindings/python/src/offsetof.hpp
Normal file
32
bindings/python/src/offsetof.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __OFFSETOF_H
|
||||
#define __OFFSETOF_H
|
||||
|
||||
#undef offsetof
|
||||
#define offsetof(TYPE, MEMBER) (reinterpret_cast <size_t> \
|
||||
(&reinterpret_cast <char &>(static_cast <TYPE *> (0)->MEMBER)))
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue