mirror of
https://github.com/SFML/SFML.git
synced 2024-11-24 20:31:05 +08:00
More code clean-up and python3 compliance
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1022 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
79bf5c6252
commit
af3dd7c630
@ -22,62 +22,26 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/Graphics/Drawable.hpp>
|
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "Blend.hpp"
|
#include "Blend.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
} PySfBlend;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyMemberDef PySfBlend_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
PySfBlend_dealloc(PySfBlend *self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfBlend_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfBlend_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfBlend *self;
|
PySfBlend *self;
|
||||||
|
|
||||||
self = (PySfBlend *)type->tp_alloc(type, 0);
|
self = (PySfBlend *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
PySfBlend_init(PySfBlend *self, PyObject *args, PyObject *kwds)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef PySfBlend_methods[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
PyTypeObject PySfBlendType = {
|
PyTypeObject PySfBlendType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Blend", /*tp_name*/
|
"Blend", /*tp_name*/
|
||||||
sizeof(PySfBlend), /*tp_basicsize*/
|
sizeof(PySfBlend), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
(destructor)PySfBlend_dealloc, /*tp_dealloc*/
|
0, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@ -104,15 +68,15 @@ None No blending.", /* tp_doc */
|
|||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfBlend_methods, /* tp_methods */
|
0, /* tp_methods */
|
||||||
PySfBlend_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
0, /* tp_descr_get */
|
0, /* tp_descr_get */
|
||||||
0, /* tp_descr_set */
|
0, /* tp_descr_set */
|
||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
(initproc)PySfBlend_init, /* tp_init */
|
0, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
PySfBlend_new, /* tp_new */
|
PySfBlend_new, /* tp_new */
|
||||||
};
|
};
|
||||||
@ -120,16 +84,16 @@ None No blending.", /* tp_doc */
|
|||||||
void PySfBlend_InitConst()
|
void PySfBlend_InitConst()
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = PyInt_FromLong(sf::Blend::Alpha);
|
obj = PyLong_FromLong(sf::Blend::Alpha);
|
||||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Alpha", obj);
|
PyDict_SetItemString(PySfBlendType.tp_dict, "Alpha", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Blend::Add);
|
obj = PyLong_FromLong(sf::Blend::Add);
|
||||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Add", obj);
|
PyDict_SetItemString(PySfBlendType.tp_dict, "Add", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Blend::Multiply);
|
obj = PyLong_FromLong(sf::Blend::Multiply);
|
||||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Multiply", obj);
|
PyDict_SetItemString(PySfBlendType.tp_dict, "Multiply", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Blend::None);
|
obj = PyLong_FromLong(sf::Blend::None);
|
||||||
PyDict_SetItemString(PySfBlendType.tp_dict, "None", obj);
|
PyDict_SetItemString(PySfBlendType.tp_dict, "None", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
#ifndef __PYBLEND_HPP
|
#ifndef __PYBLEND_HPP
|
||||||
#define __PYBLEND_HPP
|
#define __PYBLEND_HPP
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include <SFML/Graphics/Drawable.hpp>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
} PySfBlend;
|
||||||
|
|
||||||
void
|
void
|
||||||
PySfBlend_InitConst();
|
PySfBlend_InitConst();
|
||||||
|
|
||||||
|
@ -25,10 +25,7 @@
|
|||||||
#include "Font.hpp"
|
#include "Font.hpp"
|
||||||
#include "Glyph.hpp"
|
#include "Glyph.hpp"
|
||||||
|
|
||||||
static PyMemberDef PySfFont_members[] = {
|
#include "compat.hpp"
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
@ -36,21 +33,16 @@ PySfFont_dealloc(PySfFont *self)
|
|||||||
{
|
{
|
||||||
if (self->Owner)
|
if (self->Owner)
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfFont_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfFont_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfFont *self;
|
PySfFont *self;
|
||||||
|
|
||||||
self = (PySfFont *)type->tp_alloc(type, 0);
|
self = (PySfFont *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
if (self != NULL)
|
||||||
{
|
|
||||||
self->Owner = true;
|
self->Owner = true;
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,7 +63,7 @@ PySfFont_LoadFromFile(PySfFont* self, PyObject *args, PyObject *kwds)
|
|||||||
int CharsetSize;
|
int CharsetSize;
|
||||||
bool Result;
|
bool Result;
|
||||||
|
|
||||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|Is#", (char **)kwlist, &Filename, &Charsize, &CharsetTmp, &CharsetSize))
|
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|Is#:Font.LoadFromFile", (char **)kwlist, &Filename, &Charsize, &CharsetTmp, &CharsetSize))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (CharsetTmp)
|
if (CharsetTmp)
|
||||||
@ -100,7 +92,7 @@ PySfFont_LoadFromMemory(PySfFont* self, PyObject *args, PyObject *kwds)
|
|||||||
int CharsetSize;
|
int CharsetSize;
|
||||||
bool Result;
|
bool Result;
|
||||||
|
|
||||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s#|Is#", (char **)kwlist, &Data, &Size, &Charsize, &CharsetTmp, &CharsetSize))
|
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s#|Is#:Font.LoadFromMemory", (char **)kwlist, &Data, &Size, &Charsize, &CharsetTmp, &CharsetSize))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (CharsetTmp)
|
if (CharsetTmp)
|
||||||
@ -169,8 +161,7 @@ Get the description of a glyph (character) given by its unicode value. Returns g
|
|||||||
|
|
||||||
|
|
||||||
PyTypeObject PySfFontType = {
|
PyTypeObject PySfFontType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Font", /*tp_name*/
|
"Font", /*tp_name*/
|
||||||
sizeof(PySfFont), /*tp_basicsize*/
|
sizeof(PySfFont), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -198,7 +189,7 @@ PyTypeObject PySfFontType = {
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfFont_methods, /* tp_methods */
|
PySfFont_methods, /* tp_methods */
|
||||||
PySfFont_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
|
@ -25,13 +25,9 @@
|
|||||||
#ifndef __PYFONT_HPP
|
#ifndef __PYFONT_HPP
|
||||||
#define __PYFONT_HPP
|
#define __PYFONT_HPP
|
||||||
|
|
||||||
#include <SFML/Graphics/Font.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Graphics/Font.hpp>
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -24,6 +24,12 @@
|
|||||||
|
|
||||||
#include "Glyph.hpp"
|
#include "Glyph.hpp"
|
||||||
|
|
||||||
|
#include <structmember.h>
|
||||||
|
|
||||||
|
#include "offsetof.hpp"
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
static PyMemberDef PySfGlyph_members[] = {
|
static PyMemberDef PySfGlyph_members[] = {
|
||||||
{(char *)"Advance", T_INT, offsetof(PySfGlyph, Advance), 0, (char *)"Offset to move horizontically to the next character."},
|
{(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 *)"Rectangle", T_OBJECT, offsetof(PySfGlyph, Rectangle), 0, (char *)"Bounding rectangle of the glyph, in relative coordinates."},
|
||||||
@ -32,7 +38,6 @@ static PyMemberDef PySfGlyph_members[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfGlyph_dealloc(PySfGlyph *self)
|
PySfGlyph_dealloc(PySfGlyph *self)
|
||||||
{
|
{
|
||||||
@ -41,7 +46,7 @@ PySfGlyph_dealloc(PySfGlyph *self)
|
|||||||
self->TexCoords->obj = new sf::FloatRect(self->obj->TexCoords);
|
self->TexCoords->obj = new sf::FloatRect(self->obj->TexCoords);
|
||||||
Py_DECREF(self->TexCoords);
|
Py_DECREF(self->TexCoords);
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -80,16 +85,13 @@ static PyObject *
|
|||||||
PySfGlyph_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfGlyph_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfGlyph *self;
|
PySfGlyph *self;
|
||||||
|
|
||||||
self = (PySfGlyph *)type->tp_alloc(type, 0);
|
self = (PySfGlyph *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
if (self != NULL)
|
||||||
{
|
{
|
||||||
self->Advance = 0;
|
self->Advance = 0;
|
||||||
self->Rectangle = GetNewPySfIntRect();
|
self->Rectangle = GetNewPySfIntRect();
|
||||||
self->TexCoords = GetNewPySfFloatRect();
|
self->TexCoords = GetNewPySfFloatRect();
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -103,14 +105,9 @@ PySfGlyph_init(PySfGlyph *self, PyObject *args, PyObject *kwds)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef PySfGlyph_methods[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
PyTypeObject PySfGlyphType = {
|
PyTypeObject PySfGlyphType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Glyph", /*tp_name*/
|
"Glyph", /*tp_name*/
|
||||||
sizeof(PySfGlyph), /*tp_basicsize*/
|
sizeof(PySfGlyph), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -137,7 +134,7 @@ PyTypeObject PySfGlyphType = {
|
|||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfGlyph_methods, /* tp_methods */
|
0, /* tp_methods */
|
||||||
PySfGlyph_members, /* tp_members */
|
PySfGlyph_members, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
|
@ -25,13 +25,9 @@
|
|||||||
#ifndef __PYGLYPH_HPP
|
#ifndef __PYGLYPH_HPP
|
||||||
#define __PYGLYPH_HPP
|
#define __PYGLYPH_HPP
|
||||||
|
|
||||||
#include <SFML/Graphics/Glyph.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Graphics/Glyph.hpp>
|
||||||
|
|
||||||
#include "Rect.hpp"
|
#include "Rect.hpp"
|
||||||
|
|
||||||
|
@ -196,39 +196,13 @@ PySfImage_GetPixels(PySfImage *self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfImage_LoadFromFile (PySfImage *self, PyObject *args)
|
PySfImage_LoadFromFile (PySfImage *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *path;
|
load_from_file(self, args);
|
||||||
#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->LoadFromFile(path);
|
|
||||||
#ifdef IS_PY3K
|
|
||||||
Py_DECREF(string);
|
|
||||||
#endif
|
|
||||||
return PyBool_FromLong(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfImage_SaveToFile (PySfImage *self, PyObject *args)
|
PySfImage_SaveToFile (PySfImage *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *path;
|
save_to_file(self, args);
|
||||||
#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->SaveToFile(path);
|
|
||||||
#ifdef IS_PY3K
|
|
||||||
Py_DECREF(string);
|
|
||||||
#endif
|
|
||||||
return PyBool_FromLong(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
static int
|
||||||
@ -390,6 +364,7 @@ PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
|
|||||||
self->obj = new sf::Image(*(Image->obj));
|
self->obj = new sf::Image(*(Image->obj));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
else PyErr_Clear();
|
||||||
}
|
}
|
||||||
self->obj = new sf::Image();
|
self->obj = new sf::Image();
|
||||||
if (PyTuple_Size(args) > 0)
|
if (PyTuple_Size(args) > 0)
|
||||||
@ -400,6 +375,7 @@ PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
|
|||||||
return -1;
|
return -1;
|
||||||
else if (PySfImage_LoadFromPixels(self, args) == NULL)
|
else if (PySfImage_LoadFromPixels(self, args) == NULL)
|
||||||
return -1;
|
return -1;
|
||||||
|
else PyErr_Clear();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return 0;
|
return 0;
|
||||||
|
@ -22,62 +22,26 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/Window/Event.hpp>
|
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "Joy.hpp"
|
#include "Joy.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
} PySfJoy;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyMemberDef PySfJoy_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
PySfJoy_dealloc(PySfJoy *self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfJoy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfJoy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfJoy *self;
|
PySfJoy *self;
|
||||||
|
|
||||||
self = (PySfJoy *)type->tp_alloc(type, 0);
|
self = (PySfJoy *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
PySfJoy_init(PySfJoy *self, PyObject *args, PyObject *kwds)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef PySfJoy_methods[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
PyTypeObject PySfJoyType = {
|
PyTypeObject PySfJoyType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Joy", /*tp_name*/
|
"Joy", /*tp_name*/
|
||||||
sizeof(PySfJoy), /*tp_basicsize*/
|
sizeof(PySfJoy), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
(destructor)PySfJoy_dealloc, /*tp_dealloc*/
|
0, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@ -100,15 +64,15 @@ PyTypeObject PySfJoyType = {
|
|||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfJoy_methods, /* tp_methods */
|
0, /* tp_methods */
|
||||||
PySfJoy_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
0, /* tp_descr_get */
|
0, /* tp_descr_get */
|
||||||
0, /* tp_descr_set */
|
0, /* tp_descr_set */
|
||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
(initproc)PySfJoy_init, /* tp_init */
|
0, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
PySfJoy_new, /* tp_new */
|
PySfJoy_new, /* tp_new */
|
||||||
};
|
};
|
||||||
@ -116,25 +80,25 @@ PyTypeObject PySfJoyType = {
|
|||||||
void PySfJoy_InitConst()
|
void PySfJoy_InitConst()
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = PyInt_FromLong(sf::Joy::AxisX);
|
obj = PyLong_FromLong(sf::Joy::AxisX);
|
||||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisX", obj);
|
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisX", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Joy::AxisY);
|
obj = PyLong_FromLong(sf::Joy::AxisY);
|
||||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisY", obj);
|
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisY", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Joy::AxisZ);
|
obj = PyLong_FromLong(sf::Joy::AxisZ);
|
||||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisZ", obj);
|
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisZ", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Joy::AxisR);
|
obj = PyLong_FromLong(sf::Joy::AxisR);
|
||||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisR", obj);
|
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisR", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Joy::AxisU);
|
obj = PyLong_FromLong(sf::Joy::AxisU);
|
||||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisU", obj);
|
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisU", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Joy::AxisV);
|
obj = PyLong_FromLong(sf::Joy::AxisV);
|
||||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisV", obj);
|
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisV", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Joy::AxisPOV);
|
obj = PyLong_FromLong(sf::Joy::AxisPOV);
|
||||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisPOV", obj);
|
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisPOV", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
#ifndef __PYJOY_HPP
|
#ifndef __PYJOY_HPP
|
||||||
#define __PYJOY_HPP
|
#define __PYJOY_HPP
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include <SFML/Window/Event.hpp>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
} PySfJoy;
|
||||||
|
|
||||||
void
|
void
|
||||||
PySfJoy_InitConst();
|
PySfJoy_InitConst();
|
||||||
|
|
||||||
|
@ -24,40 +24,17 @@
|
|||||||
|
|
||||||
#include "Listener.hpp"
|
#include "Listener.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
static PyMemberDef PySfListener_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
PySfListener_dealloc(PySfListener* self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfListener_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfListener_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfListener *self;
|
PySfListener *self;
|
||||||
|
|
||||||
self = (PySfListener *)type->tp_alloc(type, 0);
|
self = (PySfListener *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int
|
|
||||||
PySfListener_init(PySfListener *self, PyObject *args, PyObject *kwds)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfListener_SetGlobalVolume(PySfListener* self, PyObject *args)
|
PySfListener_SetGlobalVolume(PySfListener* self, PyObject *args)
|
||||||
{
|
{
|
||||||
@ -75,7 +52,7 @@ static PyObject *
|
|||||||
PySfListener_SetPosition(PySfListener* self, PyObject *args)
|
PySfListener_SetPosition(PySfListener* self, PyObject *args)
|
||||||
{
|
{
|
||||||
float X, Y, Z;
|
float X, Y, Z;
|
||||||
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z))
|
if (!PyArg_ParseTuple(args, "fff:Listener.SetPosition", &X, &Y, &Z))
|
||||||
return NULL;
|
return NULL;
|
||||||
sf::Listener::SetPosition(X, Y, Z);
|
sf::Listener::SetPosition(X, Y, Z);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -92,7 +69,7 @@ static PyObject *
|
|||||||
PySfListener_SetTarget(PySfListener* self, PyObject *args)
|
PySfListener_SetTarget(PySfListener* self, PyObject *args)
|
||||||
{
|
{
|
||||||
float X, Y, Z;
|
float X, Y, Z;
|
||||||
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z))
|
if (!PyArg_ParseTuple(args, "fff:Listener.SetTarget", &X, &Y, &Z))
|
||||||
return NULL;
|
return NULL;
|
||||||
sf::Listener::SetTarget(X, Y, Z);
|
sf::Listener::SetTarget(X, Y, Z);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -116,12 +93,11 @@ static PyMethodDef PySfListener_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PySfListenerType = {
|
PyTypeObject PySfListenerType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Listener", /*tp_name*/
|
"Listener", /*tp_name*/
|
||||||
sizeof(PySfListener), /*tp_basicsize*/
|
sizeof(PySfListener), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
(destructor)PySfListener_dealloc, /*tp_dealloc*/
|
0, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@ -145,14 +121,14 @@ PyTypeObject PySfListenerType = {
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfListener_methods, /* tp_methods */
|
PySfListener_methods, /* tp_methods */
|
||||||
PySfListener_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
0, /* tp_descr_get */
|
0, /* tp_descr_get */
|
||||||
0, /* tp_descr_set */
|
0, /* tp_descr_set */
|
||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
(initproc)PySfListener_init, /* tp_init */
|
0, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
PySfListener_new, /* tp_new */
|
PySfListener_new, /* tp_new */
|
||||||
};
|
};
|
||||||
|
@ -25,13 +25,9 @@
|
|||||||
#ifndef __PYLISTENER_HPP
|
#ifndef __PYLISTENER_HPP
|
||||||
#define __PYLISTENER_HPP
|
#define __PYLISTENER_HPP
|
||||||
|
|
||||||
#include <SFML/Audio/Listener.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Audio/Listener.hpp>
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -22,62 +22,26 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/Window/Event.hpp>
|
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "Mouse.hpp"
|
#include "Mouse.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
} PySfMouse;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyMemberDef PySfMouse_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
PySfMouse_dealloc(PySfMouse *self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfMouse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfMouse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfMouse *self;
|
PySfMouse *self;
|
||||||
|
|
||||||
self = (PySfMouse *)type->tp_alloc(type, 0);
|
self = (PySfMouse *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
PySfMouse_init(PySfMouse *self, PyObject *args, PyObject *kwds)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef PySfMouse_methods[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
PyTypeObject PySfMouseType = {
|
PyTypeObject PySfMouseType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Mouse", /*tp_name*/
|
"Mouse", /*tp_name*/
|
||||||
sizeof(PySfMouse), /*tp_basicsize*/
|
sizeof(PySfMouse), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
(destructor)PySfMouse_dealloc, /*tp_dealloc*/
|
0, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@ -100,15 +64,15 @@ PyTypeObject PySfMouseType = {
|
|||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfMouse_methods, /* tp_methods */
|
0, /* tp_methods */
|
||||||
PySfMouse_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
0, /* tp_descr_get */
|
0, /* tp_descr_get */
|
||||||
0, /* tp_descr_set */
|
0, /* tp_descr_set */
|
||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
(initproc)PySfMouse_init, /* tp_init */
|
0, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
PySfMouse_new, /* tp_new */
|
PySfMouse_new, /* tp_new */
|
||||||
};
|
};
|
||||||
@ -116,19 +80,19 @@ PyTypeObject PySfMouseType = {
|
|||||||
void PySfMouse_InitConst()
|
void PySfMouse_InitConst()
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = PyInt_FromLong(sf::Mouse::Left);
|
obj = PyLong_FromLong(sf::Mouse::Left);
|
||||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Left", obj);
|
PyDict_SetItemString(PySfMouseType.tp_dict, "Left", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Mouse::Right);
|
obj = PyLong_FromLong(sf::Mouse::Right);
|
||||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Right", obj);
|
PyDict_SetItemString(PySfMouseType.tp_dict, "Right", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Mouse::Middle);
|
obj = PyLong_FromLong(sf::Mouse::Middle);
|
||||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Middle", obj);
|
PyDict_SetItemString(PySfMouseType.tp_dict, "Middle", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Mouse::XButton1);
|
obj = PyLong_FromLong(sf::Mouse::XButton1);
|
||||||
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton1", obj);
|
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton1", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Mouse::XButton2);
|
obj = PyLong_FromLong(sf::Mouse::XButton2);
|
||||||
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton2", obj);
|
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton2", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
#ifndef __PYMOUSE_HPP
|
#ifndef __PYMOUSE_HPP
|
||||||
#define __PYMOUSE_HPP
|
#define __PYMOUSE_HPP
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include <SFML/Window/Event.hpp>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
} PySfMouse;
|
||||||
|
|
||||||
void
|
void
|
||||||
PySfMouse_InitConst();
|
PySfMouse_InitConst();
|
||||||
|
|
||||||
|
@ -51,35 +51,22 @@ PySfPostFX_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfPostFX_LoadFromFile (PySfPostFX *self, PyObject *args)
|
PySfPostFX_LoadFromFile (PySfPostFX *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *path;
|
load_from_file(self, args);
|
||||||
#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->LoadFromFile(path);
|
|
||||||
#ifdef IS_PY3K
|
|
||||||
Py_DECREF(string);
|
|
||||||
#endif
|
|
||||||
return PyBool_FromLong(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfPostFX_LoadFromMemory (PySfPostFX *self, PyObject *args)
|
PySfPostFX_LoadFromMemory (PySfPostFX *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *path;
|
char *effect;
|
||||||
#ifdef IS_PY3K
|
#ifdef IS_PY3K
|
||||||
PyObject *string = PyUnicode_AsUTF8String(args);
|
PyObject *string = PyUnicode_AsUTF8String(args);
|
||||||
if (string == NULL)
|
if (string == NULL)
|
||||||
return NULL;
|
return NULL;
|
||||||
path = PyBytes_AsString(string);
|
effect = PyBytes_AsString(string);
|
||||||
#else
|
#else
|
||||||
path = PyString_AsString(args);
|
effect = PyString_AsString(args);
|
||||||
#endif
|
#endif
|
||||||
bool result = self->obj->LoadFromMemory(path);
|
bool result = self->obj->LoadFromMemory(effect);
|
||||||
#ifdef IS_PY3K
|
#ifdef IS_PY3K
|
||||||
Py_DECREF(string);
|
Py_DECREF(string);
|
||||||
#endif
|
#endif
|
||||||
|
@ -27,33 +27,24 @@
|
|||||||
#include <SFML/Graphics/Color.hpp>
|
#include <SFML/Graphics/Color.hpp>
|
||||||
#include "Color.hpp"
|
#include "Color.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
extern PyTypeObject PySfColorType;
|
extern PyTypeObject PySfColorType;
|
||||||
extern PyTypeObject PySfDrawableType;
|
extern PyTypeObject PySfDrawableType;
|
||||||
|
|
||||||
static PyMemberDef PySfShape_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfShape_dealloc(PySfShape* self)
|
PySfShape_dealloc(PySfShape* self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfShape_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfShape_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfShape *self;
|
PySfShape *self;
|
||||||
|
|
||||||
self = (PySfShape *)type->tp_alloc(type, 0);
|
self = (PySfShape *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -64,7 +55,6 @@ PySfShape_init(PySfShape *self, PyObject *args)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
// void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
|
// void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
|
PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||||
@ -73,7 +63,7 @@ PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
|
|||||||
float X, Y;
|
float X, Y;
|
||||||
sf::Color *Col, *OutlineCol;
|
sf::Color *Col, *OutlineCol;
|
||||||
PySfColor *ColTmp=NULL, *OutlineColTmp=NULL;
|
PySfColor *ColTmp=NULL, *OutlineColTmp=NULL;
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff|O!O!", (char **)kwlist, &X, &Y, &PySfColorType, &ColTmp, &PySfColorType, &OutlineColTmp))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff|O!O!:Shape.AddPoint", (char **)kwlist, &X, &Y, &PySfColorType, &ColTmp, &PySfColorType, &OutlineColTmp))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (ColTmp)
|
if (ColTmp)
|
||||||
@ -119,7 +109,7 @@ PySfShape_Line(PySfShape* self, PyObject *args, PyObject *kwds)
|
|||||||
float X0, Y0, X1, Y1, Thickness, Outline = 0.f;
|
float X0, Y0, X1, Y1, Thickness, Outline = 0.f;
|
||||||
sf::Color *OutlineCol;
|
sf::Color *OutlineCol;
|
||||||
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffffO!|fO!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffffO!|fO!:Shape.Line", (char **)kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (OutlineColTmp)
|
if (OutlineColTmp)
|
||||||
{
|
{
|
||||||
@ -143,7 +133,7 @@ PySfShape_Rectangle(PySfShape* self, PyObject *args, PyObject *kwds)
|
|||||||
float X0, Y0, X1, Y1, Outline = 0.f;
|
float X0, Y0, X1, Y1, Outline = 0.f;
|
||||||
sf::Color *OutlineCol;
|
sf::Color *OutlineCol;
|
||||||
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffO!|fO!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffO!|fO!:Shape.Rectangle", (char **)kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (OutlineColTmp)
|
if (OutlineColTmp)
|
||||||
{
|
{
|
||||||
@ -167,7 +157,7 @@ PySfShape_Circle(PySfShape* self, PyObject *args, PyObject *kwds)
|
|||||||
float X, Y, Radius, Outline = 0.f;
|
float X, Y, Radius, Outline = 0.f;
|
||||||
sf::Color *OutlineCol;
|
sf::Color *OutlineCol;
|
||||||
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
PySfColor *ColTmp, *OutlineColTmp=NULL;
|
||||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffO!|fO!", (char **)kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffO!|fO!:Shape.Circle", (char **)kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||||
return NULL;
|
return NULL;
|
||||||
if (OutlineColTmp)
|
if (OutlineColTmp)
|
||||||
{
|
{
|
||||||
@ -218,7 +208,7 @@ PySfShape_SetPointPosition(PySfShape* self, PyObject *args)
|
|||||||
{
|
{
|
||||||
unsigned int Index;
|
unsigned int Index;
|
||||||
float X, Y;
|
float X, Y;
|
||||||
if (!PyArg_ParseTuple(args, "Iff", &Index, &X, &Y))
|
if (!PyArg_ParseTuple(args, "Iff:Shape.SetPointPosition", &Index, &X, &Y))
|
||||||
return NULL;
|
return NULL;
|
||||||
self->obj->SetPointPosition(Index, X, Y);
|
self->obj->SetPointPosition(Index, X, Y);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -229,7 +219,7 @@ PySfShape_SetPointColor(PySfShape* self, PyObject *args)
|
|||||||
{
|
{
|
||||||
unsigned int Index;
|
unsigned int Index;
|
||||||
PySfColor *Color;
|
PySfColor *Color;
|
||||||
if (!PyArg_ParseTuple(args, "IO!", &Index, &PySfColorType, &Color))
|
if (!PyArg_ParseTuple(args, "IO!:Shape.SetPointColor", &Index, &PySfColorType, &Color))
|
||||||
return NULL;
|
return NULL;
|
||||||
PySfColorUpdate(Color);
|
PySfColorUpdate(Color);
|
||||||
self->obj->SetPointColor(Index, *(Color->obj));
|
self->obj->SetPointColor(Index, *(Color->obj));
|
||||||
@ -241,7 +231,7 @@ PySfShape_SetPointOutlineColor(PySfShape* self, PyObject *args)
|
|||||||
{
|
{
|
||||||
unsigned int Index;
|
unsigned int Index;
|
||||||
PySfColor *Color;
|
PySfColor *Color;
|
||||||
if (!PyArg_ParseTuple(args, "IO!", &Index, &PySfColorType, &Color))
|
if (!PyArg_ParseTuple(args, "IO!:Shape:SetPointOutlineColor", &Index, &PySfColorType, &Color))
|
||||||
return NULL;
|
return NULL;
|
||||||
PySfColorUpdate(Color);
|
PySfColorUpdate(Color);
|
||||||
self->obj->SetPointOutlineColor(Index, *(Color->obj));
|
self->obj->SetPointOutlineColor(Index, *(Color->obj));
|
||||||
@ -257,20 +247,14 @@ PySfShape_GetNbPoints(PySfShape* self, PyObject *args)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfShape_EnableFill(PySfShape* self, PyObject *args)
|
PySfShape_EnableFill(PySfShape* self, PyObject *args)
|
||||||
{
|
{
|
||||||
if (PyObject_IsTrue(args))
|
self->obj->EnableFill(PyBool_AsBool(args));
|
||||||
self->obj->EnableFill(true);
|
|
||||||
else
|
|
||||||
self->obj->EnableFill(false);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfShape_EnableOutline(PySfShape* self, PyObject *args)
|
PySfShape_EnableOutline(PySfShape* self, PyObject *args)
|
||||||
{
|
{
|
||||||
if (PyObject_IsTrue(args))
|
self->obj->EnableOutline(PyBool_AsBool(args));
|
||||||
self->obj->EnableOutline(true);
|
|
||||||
else
|
|
||||||
self->obj->EnableOutline(false);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -346,8 +330,7 @@ Create a shape made of a single circle.\n\
|
|||||||
|
|
||||||
|
|
||||||
PyTypeObject PySfShapeType = {
|
PyTypeObject PySfShapeType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Shape", /*tp_name*/
|
"Shape", /*tp_name*/
|
||||||
sizeof(PySfShape), /*tp_basicsize*/
|
sizeof(PySfShape), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -375,7 +358,7 @@ PyTypeObject PySfShapeType = {
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfShape_methods, /* tp_methods */
|
PySfShape_methods, /* tp_methods */
|
||||||
PySfShape_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
&PySfDrawableType, /* tp_base */
|
&PySfDrawableType, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
|
@ -25,13 +25,9 @@
|
|||||||
#ifndef __PYSHAPE_HPP
|
#ifndef __PYSHAPE_HPP
|
||||||
#define __PYSHAPE_HPP
|
#define __PYSHAPE_HPP
|
||||||
|
|
||||||
#include <SFML/Graphics/Shape.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Graphics/Shape.hpp>
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -23,33 +23,26 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Sound.hpp"
|
#include "Sound.hpp"
|
||||||
|
|
||||||
#include "SoundBuffer.hpp"
|
#include "SoundBuffer.hpp"
|
||||||
|
|
||||||
extern PyTypeObject PySfSoundBufferType;
|
#include "compat.hpp"
|
||||||
|
|
||||||
static PyMemberDef PySfSound_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
extern PyTypeObject PySfSoundBufferType;
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfSound_dealloc(PySfSound *self)
|
PySfSound_dealloc(PySfSound *self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfSound *self;
|
PySfSound *self;
|
||||||
|
|
||||||
self = (PySfSound *)type->tp_alloc(type, 0);
|
self = (PySfSound *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -61,21 +54,17 @@ static PyObject*
|
|||||||
PySfSound_SetBuffer(PySfSound *self, PyObject *args)
|
PySfSound_SetBuffer(PySfSound *self, PyObject *args)
|
||||||
{
|
{
|
||||||
PySfSoundBuffer *Buffer = (PySfSoundBuffer *)args;
|
PySfSoundBuffer *Buffer = (PySfSoundBuffer *)args;
|
||||||
if ( ! PyObject_TypeCheck(args, &PySfSoundBufferType))
|
if (!PyObject_TypeCheck(args, &PySfSoundBufferType))
|
||||||
PyErr_SetString(PyExc_TypeError, "The argument must be a sfSoundBuffer.");
|
PyErr_SetString(PyExc_TypeError, "Sound.SetBuffer() The argument must be a sf.SoundBuffer.");
|
||||||
|
|
||||||
self->obj->SetBuffer(*(Buffer->obj));
|
self->obj->SetBuffer(*(Buffer->obj));
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
PySfSound_SetLoop(PySfSound *self, PyObject *args)
|
PySfSound_SetLoop(PySfSound *self, PyObject *args)
|
||||||
{
|
{
|
||||||
if (PyObject_IsTrue(args))
|
self->obj->SetLoop(PyBool_AsBool(args));
|
||||||
self->obj->SetLoop(true);
|
|
||||||
else
|
|
||||||
self->obj->SetLoop(false);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -147,10 +136,7 @@ PySfSound_GetPlayingOffset(PySfSound *self)
|
|||||||
static PyObject*
|
static PyObject*
|
||||||
PySfSound_GetLoop(PySfSound *self)
|
PySfSound_GetLoop(PySfSound *self)
|
||||||
{
|
{
|
||||||
if (self->obj->GetLoop())
|
return PyBool_FromLong(self->obj->GetLoop());
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
@ -184,7 +170,7 @@ static PyObject*
|
|||||||
PySfSound_SetPosition(PySfSound *self, PyObject *args)
|
PySfSound_SetPosition(PySfSound *self, PyObject *args)
|
||||||
{
|
{
|
||||||
float X, Y, Z;
|
float X, Y, Z;
|
||||||
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z))
|
if (!PyArg_ParseTuple(args, "fff:Sound.SetPosition", &X, &Y, &Z))
|
||||||
return NULL;
|
return NULL;
|
||||||
self->obj->SetPosition(X, Y, Z);
|
self->obj->SetPosition(X, Y, Z);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -233,8 +219,7 @@ static PyMethodDef PySfSound_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PySfSoundType = {
|
PyTypeObject PySfSoundType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Sound", /*tp_name*/
|
"Sound", /*tp_name*/
|
||||||
sizeof(PySfSound), /*tp_basicsize*/
|
sizeof(PySfSound), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -272,7 +257,7 @@ Copy constructor : Sound(Copy) where Copy is a sf.Sound instance.", /* tp_doc */
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfSound_methods, /* tp_methods */
|
PySfSound_methods, /* tp_methods */
|
||||||
PySfSound_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
@ -286,9 +271,7 @@ Copy constructor : Sound(Copy) where Copy is a sf.Sound instance.", /* tp_doc */
|
|||||||
|
|
||||||
static int
|
static int
|
||||||
PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds)
|
PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
// Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, float X = 0.f, float Y = 0.f, float Z = 0.f);
|
|
||||||
|
|
||||||
const char *kwlist[] = {"Buffer", "Loop", "Pitch", "Volume", "X", "Y", "Z", NULL};
|
const char *kwlist[] = {"Buffer", "Loop", "Pitch", "Volume", "X", "Y", "Z", NULL};
|
||||||
PySfSoundBuffer *Buffer=NULL;
|
PySfSoundBuffer *Buffer=NULL;
|
||||||
bool Loop=false;
|
bool Loop=false;
|
||||||
@ -298,19 +281,17 @@ PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds)
|
|||||||
if (PyTuple_Size(args) == 1)
|
if (PyTuple_Size(args) == 1)
|
||||||
{
|
{
|
||||||
PySfSound *Copy;
|
PySfSound *Copy;
|
||||||
if (PyArg_ParseTuple(args, "O!", &PySfSoundType, &Copy))
|
if (PyArg_ParseTuple(args, "O!:Sound.__init__", &PySfSoundType, &Copy))
|
||||||
{
|
{
|
||||||
self->obj = new sf::Sound(*(Copy->obj));
|
self->obj = new sf::Sound(*(Copy->obj));
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
else
|
else PyErr_Clear();
|
||||||
PyErr_Clear();
|
|
||||||
}
|
}
|
||||||
if (PyTuple_Size(args) > 0)
|
if (PyTuple_Size(args) > 0)
|
||||||
{
|
{
|
||||||
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "O!|Offfff", (char **)kwlist, &PySfSoundBufferType, &Buffer, &LoopObj, &Pitch, &Volume, &X, &Y, &Z))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Offfff:Sound.__init__", (char **)kwlist, &PySfSoundBufferType, &Buffer, &LoopObj, &Pitch, &Volume, &X, &Y, &Z))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (PyObject_IsTrue(LoopObj))
|
if (PyObject_IsTrue(LoopObj))
|
||||||
Loop = true;
|
Loop = true;
|
||||||
|
|
||||||
@ -326,13 +307,13 @@ void
|
|||||||
PySfSound_InitConst()
|
PySfSound_InitConst()
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = PyInt_FromLong(sf::Sound::Stopped);
|
obj = PyLong_FromLong(sf::Sound::Stopped);
|
||||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Stopped", obj);
|
PyDict_SetItemString(PySfSoundType.tp_dict, "Stopped", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Sound::Paused);
|
obj = PyLong_FromLong(sf::Sound::Paused);
|
||||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Paused", obj);
|
PyDict_SetItemString(PySfSoundType.tp_dict, "Paused", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Sound::Playing);
|
obj = PyLong_FromLong(sf::Sound::Playing);
|
||||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Playing", obj);
|
PyDict_SetItemString(PySfSoundType.tp_dict, "Playing", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,9 @@
|
|||||||
#ifndef __PYSOUND_HPP
|
#ifndef __PYSOUND_HPP
|
||||||
#define __PYSOUND_HPP
|
#define __PYSOUND_HPP
|
||||||
|
|
||||||
#include <SFML/Audio/Sound.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
#include <SFML/Audio/Sound.hpp>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
@ -24,29 +24,21 @@
|
|||||||
|
|
||||||
#include "SoundBuffer.hpp"
|
#include "SoundBuffer.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
static PyMemberDef PySfSoundBuffer_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfSoundBuffer_dealloc(PySfSoundBuffer *self)
|
PySfSoundBuffer_dealloc(PySfSoundBuffer *self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfSoundBuffer *self;
|
PySfSoundBuffer *self;
|
||||||
|
|
||||||
self = (PySfSoundBuffer *)type->tp_alloc(type, 0);
|
self = (PySfSoundBuffer *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -56,11 +48,7 @@ PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds);
|
|||||||
static PyObject*
|
static PyObject*
|
||||||
PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args)
|
PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *path = PyString_AsString(args);
|
load_from_file(self, args);
|
||||||
if (self->obj->LoadFromFile(path))
|
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -69,13 +57,10 @@ PySfSoundBuffer_LoadFromMemory(PySfSoundBuffer* self, PyObject *args)
|
|||||||
unsigned int SizeInBytes;
|
unsigned int SizeInBytes;
|
||||||
char *Data;
|
char *Data;
|
||||||
|
|
||||||
if (! PyArg_ParseTuple(args, "s#", &Data, &SizeInBytes))
|
if (!PyArg_ParseTuple(args, "s#:SoundBuffer.LoadFromMemory", &Data, &SizeInBytes))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes))
|
return PyBool_FromLong(self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes));
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -84,29 +69,26 @@ PySfSoundBuffer_LoadFromSamples(PySfSoundBuffer* self, PyObject *args)
|
|||||||
unsigned int SizeInBytes, ChannelsCount, SampleRate;
|
unsigned int SizeInBytes, ChannelsCount, SampleRate;
|
||||||
char *Data;
|
char *Data;
|
||||||
|
|
||||||
if (! PyArg_ParseTuple(args, "s#II", &Data, &SizeInBytes, &ChannelsCount, &SampleRate))
|
if (!PyArg_ParseTuple(args, "s#II:SoundBuffer.LoadFromSamples", &Data, &SizeInBytes, &ChannelsCount, &SampleRate))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (self->obj->LoadFromSamples((const sf::Int16*)Data, (std::size_t) SizeInBytes/2, ChannelsCount, SampleRate))
|
return PyBool_FromLong(self->obj->LoadFromSamples((const sf::Int16*)Data, (std::size_t) SizeInBytes/2, ChannelsCount, SampleRate));
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
PySfSoundBuffer_GetSamples(PySfSoundBuffer *self)
|
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);
|
return PyString_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
PySfSoundBuffer_SaveToFile(PySfSoundBuffer *self, PyObject *args)
|
PySfSoundBuffer_SaveToFile(PySfSoundBuffer *self, PyObject *args)
|
||||||
{
|
{
|
||||||
char *path = PyString_AsString(args);
|
save_to_file(self, args);
|
||||||
if (self->obj->SaveToFile(path))
|
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
@ -151,8 +133,7 @@ static PyMethodDef PySfSoundBuffer_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PySfSoundBufferType = {
|
PyTypeObject PySfSoundBufferType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"SoundBuffer", /*tp_name*/
|
"SoundBuffer", /*tp_name*/
|
||||||
sizeof(PySfSoundBuffer), /*tp_basicsize*/
|
sizeof(PySfSoundBuffer), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -182,7 +163,7 @@ Copy constructor : SoundBuffer(Copy) where Copy is a sf.SoundBuffer instance.",
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfSoundBuffer_methods, /* tp_methods */
|
PySfSoundBuffer_methods, /* tp_methods */
|
||||||
PySfSoundBuffer_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
@ -197,16 +178,18 @@ Copy constructor : SoundBuffer(Copy) where Copy is a sf.SoundBuffer instance.",
|
|||||||
static int
|
static int
|
||||||
PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds)
|
PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
if (PyTuple_Size(args) == 1)
|
int size = PyTuple_Size(args);
|
||||||
|
if (size == 1)
|
||||||
{
|
{
|
||||||
PySfSoundBuffer *Copy;
|
PySfSoundBuffer *Copy;
|
||||||
if (PyArg_ParseTuple(args, "O!", &PySfSoundBufferType, &Copy))
|
if (!PyArg_ParseTuple(args, "O!:SoundBuffer.__init__", &PySfSoundBufferType, &Copy))
|
||||||
self->obj = new sf::SoundBuffer(*(Copy->obj));
|
|
||||||
else
|
|
||||||
return -1;
|
return -1;
|
||||||
|
self->obj = new sf::SoundBuffer(*(Copy->obj));
|
||||||
}
|
}
|
||||||
else
|
else if (size == 0)
|
||||||
self->obj = new sf::SoundBuffer();
|
self->obj = new sf::SoundBuffer();
|
||||||
|
else
|
||||||
|
PyErr_SetString(PyExc_TypeError, "SoundBuffer.__init__() takes 0 or 1 argument");
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -25,11 +25,9 @@
|
|||||||
#ifndef __PYSOUNDBUFFER_HPP
|
#ifndef __PYSOUNDBUFFER_HPP
|
||||||
#define __PYSOUNDBUFFER_HPP
|
#define __PYSOUNDBUFFER_HPP
|
||||||
|
|
||||||
#include <SFML/Audio/SoundBuffer.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
#include <SFML/Audio/SoundBuffer.hpp>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
@ -23,35 +23,26 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "SoundBufferRecorder.hpp"
|
#include "SoundBufferRecorder.hpp"
|
||||||
|
|
||||||
#include "SoundBuffer.hpp"
|
#include "SoundBuffer.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
extern PyTypeObject PySfSoundRecorderType;
|
extern PyTypeObject PySfSoundRecorderType;
|
||||||
|
|
||||||
static PyMemberDef PySfSoundBufferRecorder_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfSoundBufferRecorder_dealloc(PySfSoundBufferRecorder *self)
|
PySfSoundBufferRecorder_dealloc(PySfSoundBufferRecorder *self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfSoundBufferRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfSoundBufferRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfSoundBufferRecorder *self;
|
PySfSoundBufferRecorder *self;
|
||||||
|
|
||||||
self = (PySfSoundBufferRecorder *)type->tp_alloc(type, 0);
|
self = (PySfSoundBufferRecorder *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -66,7 +57,7 @@ static PyObject *
|
|||||||
PySfSoundBufferRecorder_GetBuffer(PySfSoundBufferRecorder* self)
|
PySfSoundBufferRecorder_GetBuffer(PySfSoundBufferRecorder* self)
|
||||||
{
|
{
|
||||||
PySfSoundBuffer *SoundBuffer = GetNewPySfSoundBuffer();
|
PySfSoundBuffer *SoundBuffer = GetNewPySfSoundBuffer();
|
||||||
SoundBuffer->obj = new sf::SoundBuffer( self->obj->GetBuffer() );
|
SoundBuffer->obj = new sf::SoundBuffer(self->obj->GetBuffer());
|
||||||
return (PyObject *)SoundBuffer;
|
return (PyObject *)SoundBuffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -77,8 +68,7 @@ static PyMethodDef PySfSoundBufferRecorder_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PySfSoundBufferRecorderType = {
|
PyTypeObject PySfSoundBufferRecorderType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"SoundBufferRecorder", /*tp_name*/
|
"SoundBufferRecorder", /*tp_name*/
|
||||||
sizeof(PySfSoundBufferRecorder), /*tp_basicsize*/
|
sizeof(PySfSoundBufferRecorder), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -106,7 +96,7 @@ PyTypeObject PySfSoundBufferRecorderType = {
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfSoundBufferRecorder_methods, /* tp_methods */
|
PySfSoundBufferRecorder_methods, /* tp_methods */
|
||||||
PySfSoundBufferRecorder_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
&PySfSoundRecorderType, /* tp_base */
|
&PySfSoundRecorderType, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
|
@ -25,13 +25,9 @@
|
|||||||
#ifndef __PYSOUNDBUFFERRECORDER_HPP
|
#ifndef __PYSOUNDBUFFERRECORDER_HPP
|
||||||
#define __PYSOUNDBUFFERRECORDER_HPP
|
#define __PYSOUNDBUFFERRECORDER_HPP
|
||||||
|
|
||||||
#include <SFML/Audio/SoundBufferRecorder.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Audio/SoundBufferRecorder.hpp>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
@ -24,57 +24,58 @@
|
|||||||
|
|
||||||
#include "SoundRecorder.hpp"
|
#include "SoundRecorder.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
static PyMemberDef PySfSoundRecorder_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
bool CustomSoundRecorder::OnStart()
|
bool CustomSoundRecorder::OnStart()
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (PyObject_HasAttrString(SoundRecorder, "OnStart"))
|
if (PyObject_HasAttrString(SoundRecorder, "OnStart"))
|
||||||
if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnStart"), NULL)))
|
{
|
||||||
return true;
|
PyObject *OnStart = PyObject_GetAttrString(SoundRecorder, "OnStart");
|
||||||
return false;
|
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 CustomSoundRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount)
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (PyObject_HasAttrString(SoundRecorder, "OnGetData"))
|
if (PyObject_HasAttrString(SoundRecorder, "OnGetData"))
|
||||||
{
|
{
|
||||||
if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnGetData"), (char *)"#s", (char *)Samples, SamplesCount*2)))
|
PyObject *OnGetData = PyObject_GetAttrString(SoundRecorder, "OnGetData");
|
||||||
{
|
PyObject *Result = PyObject_CallFunction(OnGetData, (char *)"#s", (char *)Samples, SamplesCount*2);
|
||||||
return true;
|
result = PyBool_AsBool(Result);
|
||||||
}
|
Py_DECREF(OnGetData);
|
||||||
|
Py_DECREF(Result);
|
||||||
}
|
}
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomSoundRecorder::OnStop()
|
void CustomSoundRecorder::OnStop()
|
||||||
{
|
{
|
||||||
if (PyObject_HasAttrString(SoundRecorder, "OnStop"))
|
if (PyObject_HasAttrString(SoundRecorder, "OnStop"))
|
||||||
PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnStop"), NULL);
|
{
|
||||||
|
PyObject *OnStop = PyObject_GetAttrString(SoundRecorder, "OnStop");
|
||||||
|
PyObject_CallFunction(OnStop, NULL);
|
||||||
|
Py_DECREF(OnStop);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfSoundRecorder_dealloc(PySfSoundRecorder* self)
|
PySfSoundRecorder_dealloc(PySfSoundRecorder* self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfSoundRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfSoundRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfSoundRecorder *self;
|
PySfSoundRecorder *self;
|
||||||
|
|
||||||
self = (PySfSoundRecorder *)type->tp_alloc(type, 0);
|
self = (PySfSoundRecorder *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -86,11 +87,10 @@ PySfSoundRecorder_init(PySfSoundRecorder *self, PyObject *args)
|
|||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfSoundRecorder_Start(PySfSoundRecorder* self, PyObject *args)
|
PySfSoundRecorder_Start(PySfSoundRecorder* self, PyObject *args)
|
||||||
{
|
{
|
||||||
self->obj->Start( PyInt_AsLong(args) );
|
self->obj->Start(PyLong_AsLong(args));
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -104,20 +104,16 @@ PySfSoundRecorder_Stop(PySfSoundRecorder* self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfSoundRecorder_GetSampleRate(PySfSoundRecorder* self)
|
PySfSoundRecorder_GetSampleRate(PySfSoundRecorder* self)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(self->obj->GetSampleRate());
|
return PyLong_FromLong(self->obj->GetSampleRate());
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfSoundRecorder_CanCapture(PySfSoundRecorder* self)
|
PySfSoundRecorder_CanCapture(PySfSoundRecorder* self)
|
||||||
{
|
{
|
||||||
if (sf::SoundRecorder::CanCapture())
|
return PyBool_FromLong(sf::SoundRecorder::CanCapture());
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyMethodDef PySfSoundRecorder_methods[] = {
|
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)."},
|
{"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."},
|
{"Stop", (PyCFunction)PySfSoundRecorder_Stop, METH_NOARGS, "Stop()\nStop the capture."},
|
||||||
@ -128,8 +124,7 @@ static PyMethodDef PySfSoundRecorder_methods[] = {
|
|||||||
|
|
||||||
|
|
||||||
PyTypeObject PySfSoundRecorderType = {
|
PyTypeObject PySfSoundRecorderType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"SoundRecorder", /*tp_name*/
|
"SoundRecorder", /*tp_name*/
|
||||||
sizeof(PySfSoundRecorder), /*tp_basicsize*/
|
sizeof(PySfSoundRecorder), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -160,7 +155,7 @@ Construct the sound recorder with a callback function for processing captured sa
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfSoundRecorder_methods, /* tp_methods */
|
PySfSoundRecorder_methods, /* tp_methods */
|
||||||
PySfSoundRecorder_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
|
@ -25,13 +25,9 @@
|
|||||||
#ifndef __PYSOUNDRECORDER_HPP
|
#ifndef __PYSOUNDRECORDER_HPP
|
||||||
#define __PYSOUNDRECORDER_HPP
|
#define __PYSOUNDRECORDER_HPP
|
||||||
|
|
||||||
#include <SFML/Audio/SoundRecorder.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Audio/SoundRecorder.hpp>
|
||||||
|
|
||||||
class CustomSoundRecorder : public sf::SoundRecorder
|
class CustomSoundRecorder : public sf::SoundRecorder
|
||||||
{
|
{
|
||||||
|
@ -24,32 +24,46 @@
|
|||||||
|
|
||||||
#include "SoundStream.hpp"
|
#include "SoundStream.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
bool CustomSoundStream::OnStart()
|
bool CustomSoundStream::OnStart()
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
if (PyObject_HasAttrString(SoundStream, "OnStart"))
|
if (PyObject_HasAttrString(SoundStream, "OnStart"))
|
||||||
if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundStream, "OnStart"), NULL)))
|
{
|
||||||
return true;
|
PyObject *OnStart = PyObject_GetAttrString(SoundStream, "OnStart");
|
||||||
return false;
|
PyObject *Result = PyObject_CallFunction(OnStart, NULL);
|
||||||
|
result = PyBool_AsBool(Result);
|
||||||
|
Py_DECREF(OnStart);
|
||||||
|
Py_DECREF(Result);
|
||||||
|
}
|
||||||
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool CustomSoundStream::OnGetData(Chunk& Data)
|
bool CustomSoundStream::OnGetData(Chunk& Data)
|
||||||
{
|
{
|
||||||
|
bool result = false;
|
||||||
|
if (PyData != NULL) {
|
||||||
|
Py_DECREF(PyData);
|
||||||
|
}
|
||||||
if (PyObject_HasAttrString(SoundStream, "OnGetData"))
|
if (PyObject_HasAttrString(SoundStream, "OnGetData"))
|
||||||
{
|
{
|
||||||
PyObject *PyData=NULL;
|
PyObject *Function = PyObject_GetAttrString(SoundStream, "OnGetData");
|
||||||
Data.NbSamples = 0;
|
Data.NbSamples = 0;
|
||||||
if ((PyData = PyObject_CallFunction(PyObject_GetAttrString(SoundStream, "OnGetData"), NULL)))
|
PyData = PyObject_CallFunction(Function, NULL);
|
||||||
|
if (PyData != NULL)
|
||||||
{
|
{
|
||||||
if (PyArg_Parse(PyData, "s#", &(Data.Samples), &(Data.NbSamples)))
|
if (PyArg_Parse(PyData, "s#", &(Data.Samples), &(Data.NbSamples)))
|
||||||
{
|
{
|
||||||
Data.NbSamples /= 2;
|
Data.NbSamples /= 2;
|
||||||
if (Data.NbSamples > 0)
|
if (Data.NbSamples > 0)
|
||||||
return true;
|
result = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Py_DECREF(Function);
|
||||||
}
|
}
|
||||||
return false;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate)
|
void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate)
|
||||||
@ -57,16 +71,11 @@ void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate
|
|||||||
Initialize(ChannelsCount, SampleRate);
|
Initialize(ChannelsCount, SampleRate);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static PyMemberDef PySfSoundStream_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static int
|
static int
|
||||||
PySfSoundStream_init(PySfSoundStream *self, PyObject *args, PyObject *kwds)
|
PySfSoundStream_init(PySfSoundStream *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
self->obj = new CustomSoundStream();
|
self->obj = new CustomSoundStream();
|
||||||
|
self->obj->PyData = NULL;
|
||||||
self->obj->SoundStream = (PyObject *)self;
|
self->obj->SoundStream = (PyObject *)self;
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
@ -75,7 +84,7 @@ static void
|
|||||||
PySfSoundStream_dealloc(PySfSoundStream *self)
|
PySfSoundStream_dealloc(PySfSoundStream *self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -90,7 +99,7 @@ static PyObject *
|
|||||||
PySfSoundStream_Initialize(PySfSoundStream *self, PyObject *args)
|
PySfSoundStream_Initialize(PySfSoundStream *self, PyObject *args)
|
||||||
{
|
{
|
||||||
unsigned int ChannelsCount, SampleRate;
|
unsigned int ChannelsCount, SampleRate;
|
||||||
if (!PyArg_ParseTuple(args, "II", &ChannelsCount, &SampleRate))
|
if (!PyArg_ParseTuple(args, "II:SoundStream.Initialize", &ChannelsCount, &SampleRate))
|
||||||
return NULL;
|
return NULL;
|
||||||
self->obj->Init(ChannelsCount, SampleRate);
|
self->obj->Init(ChannelsCount, SampleRate);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -192,7 +201,7 @@ static PyObject*
|
|||||||
PySfSoundStream_SetPosition(PySfSoundStream *self, PyObject *args)
|
PySfSoundStream_SetPosition(PySfSoundStream *self, PyObject *args)
|
||||||
{
|
{
|
||||||
float X, Y, Z;
|
float X, Y, Z;
|
||||||
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z))
|
if (!PyArg_ParseTuple(args, "fff:SoundStream.SetPosition", &X, &Y, &Z))
|
||||||
return NULL;
|
return NULL;
|
||||||
self->obj->SetPosition(X, Y, Z);
|
self->obj->SetPosition(X, Y, Z);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -207,20 +216,14 @@ PySfSoundStream_GetStatus(PySfSoundStream *self)
|
|||||||
static PyObject*
|
static PyObject*
|
||||||
PySfSoundStream_SetLoop(PySfSoundStream *self, PyObject *args)
|
PySfSoundStream_SetLoop(PySfSoundStream *self, PyObject *args)
|
||||||
{
|
{
|
||||||
if (PyObject_IsTrue(args))
|
self->obj->SetLoop(PyBool_AsBool(args));
|
||||||
self->obj->SetLoop(true);
|
|
||||||
else
|
|
||||||
self->obj->SetLoop(false);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
PySfSoundStream_GetLoop(PySfSoundStream *self)
|
PySfSoundStream_GetLoop(PySfSoundStream *self)
|
||||||
{
|
{
|
||||||
if (self->obj->GetLoop())
|
return PyBool_FromLong(self->obj->GetLoop());
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
@ -259,8 +262,7 @@ Set the audio stream parameters, you must call it before Play()\n\
|
|||||||
|
|
||||||
|
|
||||||
PyTypeObject PySfSoundStreamType = {
|
PyTypeObject PySfSoundStreamType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"SoundStream", /*tp_name*/
|
"SoundStream", /*tp_name*/
|
||||||
sizeof(PySfSoundStream), /*tp_basicsize*/
|
sizeof(PySfSoundStream), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -291,7 +293,7 @@ or for streaming sound from the network", /* tp_doc */
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfSoundStream_methods, /* tp_methods */
|
PySfSoundStream_methods, /* tp_methods */
|
||||||
PySfSoundStream_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
@ -308,13 +310,13 @@ void
|
|||||||
PySfSoundStream_InitConst()
|
PySfSoundStream_InitConst()
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = PyInt_FromLong(sf::SoundStream::Stopped);
|
obj = PyLong_FromLong(sf::SoundStream::Stopped);
|
||||||
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Stopped", obj);
|
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Stopped", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::SoundStream::Paused);
|
obj = PyLong_FromLong(sf::SoundStream::Paused);
|
||||||
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Paused", obj);
|
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Paused", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::SoundStream::Playing);
|
obj = PyLong_FromLong(sf::SoundStream::Playing);
|
||||||
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Playing", obj);
|
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Playing", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
}
|
}
|
||||||
|
@ -26,15 +26,14 @@
|
|||||||
#define __PYSOUNDSTREAM_HPP
|
#define __PYSOUNDSTREAM_HPP
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include <SFML/Audio/SoundStream.hpp>
|
#include <SFML/Audio/SoundStream.hpp>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
class CustomSoundStream : public sf::SoundStream
|
class CustomSoundStream : public sf::SoundStream
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
PyObject *SoundStream;
|
PyObject *SoundStream;
|
||||||
|
PyObject *PyData;
|
||||||
virtual bool OnStart();
|
virtual bool OnStart();
|
||||||
virtual bool OnGetData(Chunk& Data);
|
virtual bool OnGetData(Chunk& Data);
|
||||||
void Init(unsigned int ChannelsCount, unsigned int SampleRate);
|
void Init(unsigned int ChannelsCount, unsigned int SampleRate);
|
||||||
|
@ -27,36 +27,27 @@
|
|||||||
#include "Color.hpp"
|
#include "Color.hpp"
|
||||||
#include "Rect.hpp"
|
#include "Rect.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
extern PyTypeObject PySfColorType;
|
extern PyTypeObject PySfColorType;
|
||||||
extern PyTypeObject PySfImageType;
|
extern PyTypeObject PySfImageType;
|
||||||
extern PyTypeObject PySfDrawableType;
|
extern PyTypeObject PySfDrawableType;
|
||||||
extern PyTypeObject PySfFontType;
|
extern PyTypeObject PySfFontType;
|
||||||
|
|
||||||
static PyMemberDef PySfString_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfString_dealloc(PySfString *self)
|
PySfString_dealloc(PySfString *self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfString *self;
|
PySfString *self;
|
||||||
|
|
||||||
self = (PySfString *)type->tp_alloc(type, 0);
|
self = (PySfString *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -121,7 +112,7 @@ PySfString_SetFont(PySfString* self, PyObject *args)
|
|||||||
{
|
{
|
||||||
PySfFont *Font = (PySfFont *)args;
|
PySfFont *Font = (PySfFont *)args;
|
||||||
if (!PyObject_TypeCheck(Font, &PySfFontType))
|
if (!PyObject_TypeCheck(Font, &PySfFontType))
|
||||||
PyErr_SetString(PyExc_ValueError, "Argument must be a sf.Font");
|
PyErr_SetString(PyExc_ValueError, "String.SetFont() Argument must be a sf.Font");
|
||||||
self->obj->SetFont(*(Font->obj));
|
self->obj->SetFont(*(Font->obj));
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@ -155,7 +146,12 @@ PySfString_GetStyle(PySfString* self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfString_GetText(PySfString* self)
|
PySfString_GetText(PySfString* self)
|
||||||
{
|
{
|
||||||
return PyString_FromString((std::string(self->obj->GetText())).c_str());
|
std::string Text = (std::string(self->obj->GetText()));
|
||||||
|
#ifdef IS_PY3K
|
||||||
|
return PyUnicode_DecodeUTF8(Text.c_str(), (Py_ssize_t)Text.length(), "replace");
|
||||||
|
#else
|
||||||
|
return PyString_FromString(Text.c_str());
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -206,8 +202,7 @@ Return the visual position (a tuple of two floats) of the Index-th character of
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PySfStringType = {
|
PyTypeObject PySfStringType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"String", /*tp_name*/
|
"String", /*tp_name*/
|
||||||
sizeof(PySfString), /*tp_basicsize*/
|
sizeof(PySfString), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -236,7 +231,7 @@ Default constructor : String ()\nConstruct the string from a utf-8 or a utf-16 s
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfString_methods, /* tp_methods */
|
PySfString_methods, /* tp_methods */
|
||||||
PySfString_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
&PySfDrawableType, /* tp_base */
|
&PySfDrawableType, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
@ -253,16 +248,16 @@ Default constructor : String ()\nConstruct the string from a utf-8 or a utf-16 s
|
|||||||
void PySfString_InitConst()
|
void PySfString_InitConst()
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = PyInt_FromLong(sf::String::Regular);
|
obj = PyLong_FromLong(sf::String::Regular);
|
||||||
PyDict_SetItemString(PySfStringType.tp_dict, "Regular", obj);
|
PyDict_SetItemString(PySfStringType.tp_dict, "Regular", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::String::Bold);
|
obj = PyLong_FromLong(sf::String::Bold);
|
||||||
PyDict_SetItemString(PySfStringType.tp_dict, "Bold", obj);
|
PyDict_SetItemString(PySfStringType.tp_dict, "Bold", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::String::Italic);
|
obj = PyLong_FromLong(sf::String::Italic);
|
||||||
PyDict_SetItemString(PySfStringType.tp_dict, "Italic", obj);
|
PyDict_SetItemString(PySfStringType.tp_dict, "Italic", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::String::Underlined);
|
obj = PyLong_FromLong(sf::String::Underlined);
|
||||||
PyDict_SetItemString(PySfStringType.tp_dict, "Underlined", obj);
|
PyDict_SetItemString(PySfStringType.tp_dict, "Underlined", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
}
|
}
|
||||||
|
@ -25,11 +25,9 @@
|
|||||||
#ifndef __PYSTRING_HPP
|
#ifndef __PYSTRING_HPP
|
||||||
#define __PYSTRING_HPP
|
#define __PYSTRING_HPP
|
||||||
|
|
||||||
#include <SFML/Graphics/String.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
#include <SFML/Graphics/String.hpp>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
@ -22,8 +22,12 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "VideoMode.hpp"
|
#include "VideoMode.hpp"
|
||||||
|
|
||||||
|
#include <structmember.h>
|
||||||
|
|
||||||
|
#include "offsetof.hpp"
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
static PyMemberDef PySfVideoMode_members[] = {
|
static PyMemberDef PySfVideoMode_members[] = {
|
||||||
@ -34,12 +38,11 @@ static PyMemberDef PySfVideoMode_members[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfVideoMode_dealloc(PySfVideoMode* self)
|
PySfVideoMode_dealloc(PySfVideoMode* self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -72,7 +75,7 @@ PySfVideoMode_init(PySfVideoMode *self, PyObject *args, PyObject *kwds)
|
|||||||
{
|
{
|
||||||
const char *kwlist[] = {"Width", "Height", "BitsPerPixel", NULL};
|
const char *kwlist[] = {"Width", "Height", "BitsPerPixel", NULL};
|
||||||
|
|
||||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|I", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|I:VideoMode.__init__", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
|
self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
|
||||||
@ -111,7 +114,7 @@ PySfVideoMode_GetMode(PySfVideoMode* self, PyObject *args)
|
|||||||
std::size_t index;
|
std::size_t index;
|
||||||
PySfVideoMode *VideoMode;
|
PySfVideoMode *VideoMode;
|
||||||
|
|
||||||
index = (std::size_t)PyInt_AsLong(args);
|
index = (std::size_t)PyLong_AsLong(args);
|
||||||
|
|
||||||
VideoMode = GetNewPySfVideoMode();
|
VideoMode = GetNewPySfVideoMode();
|
||||||
VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetMode(index) );
|
VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetMode(index) );
|
||||||
@ -125,7 +128,7 @@ PySfVideoMode_GetMode(PySfVideoMode* self, PyObject *args)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfVideoMode_GetModesCount(PySfVideoMode* self)
|
PySfVideoMode_GetModesCount(PySfVideoMode* self)
|
||||||
{
|
{
|
||||||
return PyInt_FromLong(sf::VideoMode::GetModesCount());
|
return PyLong_FromLong(sf::VideoMode::GetModesCount());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -150,8 +153,7 @@ int PySfVideoMode_Compare(PyObject *o1, PyObject *o2)
|
|||||||
|
|
||||||
|
|
||||||
PyTypeObject PySfVideoModeType = {
|
PyTypeObject PySfVideoModeType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"VideoMode", /*tp_name*/
|
"VideoMode", /*tp_name*/
|
||||||
sizeof(PySfVideoMode), /*tp_basicsize*/
|
sizeof(PySfVideoMode), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
|
@ -25,15 +25,9 @@
|
|||||||
#ifndef __PYVIDEOMODE_HPP
|
#ifndef __PYVIDEOMODE_HPP
|
||||||
#define __PYVIDEOMODE_HPP
|
#define __PYVIDEOMODE_HPP
|
||||||
|
|
||||||
#include <SFML/System.hpp>
|
#include <SFML/Window/VideoMode.hpp>
|
||||||
#include <SFML/Window.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
@ -23,20 +23,21 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "View.hpp"
|
#include "View.hpp"
|
||||||
|
#include "Rect.hpp"
|
||||||
|
|
||||||
|
#include "offsetof.hpp"
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
extern PyTypeObject PySfFloatRectType;
|
extern PyTypeObject PySfFloatRectType;
|
||||||
|
|
||||||
static PyMemberDef PySfView_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfView_dealloc(PySfView *self)
|
PySfView_dealloc(PySfView *self)
|
||||||
{
|
{
|
||||||
if (self->Owner)
|
if (self->Owner)
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
@ -57,7 +58,7 @@ static int
|
|||||||
PySfView_init(PySfView *self, PyObject *args, PyObject *kwds)
|
PySfView_init(PySfView *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfFloatRect *Rect=NULL;
|
PySfFloatRect *Rect=NULL;
|
||||||
if (! PyArg_ParseTuple(args, "|O!", &PySfFloatRectType, &Rect))
|
if (!PyArg_ParseTuple(args, "|O!:View.__init__", &PySfFloatRectType, &Rect))
|
||||||
return -1;
|
return -1;
|
||||||
|
|
||||||
if (Rect != NULL)
|
if (Rect != NULL)
|
||||||
@ -98,7 +99,7 @@ static PyObject *
|
|||||||
PySfView_Move(PySfView* self, PyObject *args)
|
PySfView_Move(PySfView* self, PyObject *args)
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
if (!PyArg_ParseTuple(args, "ff:View.Move", &x, &y) )
|
||||||
return NULL;
|
return NULL;
|
||||||
self->obj->Move(x, y);
|
self->obj->Move(x, y);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -108,7 +109,7 @@ static PyObject *
|
|||||||
PySfView_SetCenter(PySfView* self, PyObject *args)
|
PySfView_SetCenter(PySfView* self, PyObject *args)
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
if (!PyArg_ParseTuple(args, "ff:View.SetCenter", &x, &y) )
|
||||||
return NULL;
|
return NULL;
|
||||||
self->obj->SetCenter(x, y);
|
self->obj->SetCenter(x, y);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -118,7 +119,7 @@ static PyObject *
|
|||||||
PySfView_SetHalfSize(PySfView* self, PyObject *args)
|
PySfView_SetHalfSize(PySfView* self, PyObject *args)
|
||||||
{
|
{
|
||||||
float x, y;
|
float x, y;
|
||||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
if (!PyArg_ParseTuple(args, "ff:View.SetHalfSize", &x, &y) )
|
||||||
return NULL;
|
return NULL;
|
||||||
self->obj->SetHalfSize(x, y);
|
self->obj->SetHalfSize(x, y);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
@ -145,8 +146,7 @@ static PyMethodDef PySfView_methods[] = {
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PySfViewType = {
|
PyTypeObject PySfViewType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"View", /*tp_name*/
|
"View", /*tp_name*/
|
||||||
sizeof(PySfView), /*tp_basicsize*/
|
sizeof(PySfView), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -174,7 +174,7 @@ PyTypeObject PySfViewType = {
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfView_methods, /* tp_methods */
|
PySfView_methods, /* tp_methods */
|
||||||
PySfView_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
|
@ -25,15 +25,9 @@
|
|||||||
#ifndef __PYVIEW_HPP
|
#ifndef __PYVIEW_HPP
|
||||||
#define __PYVIEW_HPP
|
#define __PYVIEW_HPP
|
||||||
|
|
||||||
#include <SFML/Graphics/View.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include "Rect.hpp"
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Graphics/View.hpp>
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
PyObject_HEAD
|
PyObject_HEAD
|
||||||
|
@ -22,39 +22,38 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include "Window.hpp"
|
#include "Window.hpp"
|
||||||
|
|
||||||
|
#include "Event.hpp"
|
||||||
|
#include "VideoMode.hpp"
|
||||||
|
#include "Input.hpp"
|
||||||
|
#include "WindowSettings.hpp"
|
||||||
|
|
||||||
#include "SFML/Window/WindowStyle.hpp"
|
#include <SFML/Window/WindowStyle.hpp>
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
|
|
||||||
extern PyTypeObject PySfEventType;
|
extern PyTypeObject PySfEventType;
|
||||||
extern PyTypeObject PySfWindowSettingsType;
|
extern PyTypeObject PySfWindowSettingsType;
|
||||||
extern PyTypeObject PySfVideoModeType;
|
extern PyTypeObject PySfVideoModeType;
|
||||||
|
|
||||||
static PyMemberDef PySfWindow_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
static void
|
static void
|
||||||
PySfWindow_dealloc(PySfWindow* self)
|
PySfWindow_dealloc(PySfWindow* self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfWindow *self;
|
PySfWindow *self;
|
||||||
|
|
||||||
self = (PySfWindow *)type->tp_alloc(type, 0);
|
self = (PySfWindow *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyObject*
|
static PyObject*
|
||||||
PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
|
PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
|
||||||
@ -63,7 +62,7 @@ PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
|
|||||||
|
|
||||||
if (! PyObject_TypeCheck(PyEvent, &PySfEventType))
|
if (! PyObject_TypeCheck(PyEvent, &PySfEventType))
|
||||||
{
|
{
|
||||||
PyErr_SetString(PyExc_TypeError, "Argument is not a sfEvent");
|
PyErr_SetString(PyExc_TypeError, "Window.GetEvent() Argument is not a sfEvent");
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -71,43 +70,13 @@ PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
|
|||||||
{
|
{
|
||||||
PyEvent->Type = PyEvent->obj->Type;
|
PyEvent->Type = PyEvent->obj->Type;
|
||||||
PyEvent->Text->Unicode = PyEvent->obj->Text.Unicode;
|
PyEvent->Text->Unicode = PyEvent->obj->Text.Unicode;
|
||||||
PyEvent->Key->Code = PyEvent->obj->Key.Code;
|
PyEvent->Key->Code = PyEvent->obj->Key.Code;
|
||||||
if (PyEvent->obj->Key.Alt && PyEvent->Key->Alt == Py_False)
|
Py_DECREF(PyEvent->Key->Alt);
|
||||||
{
|
PyEvent->Key->Alt = PyBool_FromLong(PyEvent->obj->Key.Alt);
|
||||||
Py_DECREF(Py_False);
|
Py_DECREF(PyEvent->Key->Control);
|
||||||
Py_INCREF(Py_True);
|
PyEvent->Key->Control = PyBool_FromLong(PyEvent->obj->Key.Control);
|
||||||
PyEvent->Key->Alt = Py_True;
|
Py_DECREF(PyEvent->Key->Shift);
|
||||||
}
|
PyEvent->Key->Shift = PyBool_FromLong(PyEvent->obj->Key.Shift);
|
||||||
else if (PyEvent->Key->Alt == Py_True)
|
|
||||||
{
|
|
||||||
Py_DECREF(Py_True);
|
|
||||||
Py_INCREF(Py_False);
|
|
||||||
PyEvent->Key->Alt = Py_False;
|
|
||||||
}
|
|
||||||
if (PyEvent->obj->Key.Control && PyEvent->Key->Control == Py_False)
|
|
||||||
{
|
|
||||||
Py_DECREF(Py_False);
|
|
||||||
Py_INCREF(Py_True);
|
|
||||||
PyEvent->Key->Control = Py_True;
|
|
||||||
}
|
|
||||||
else if (PyEvent->Key->Control == Py_True)
|
|
||||||
{
|
|
||||||
Py_DECREF(Py_True);
|
|
||||||
Py_INCREF(Py_False);
|
|
||||||
PyEvent->Key->Control = Py_False;
|
|
||||||
}
|
|
||||||
if (PyEvent->obj->Key.Shift && PyEvent->Key->Shift == Py_False)
|
|
||||||
{
|
|
||||||
Py_DECREF(Py_False);
|
|
||||||
Py_INCREF(Py_True);
|
|
||||||
PyEvent->Key->Shift = Py_True;
|
|
||||||
}
|
|
||||||
else if (PyEvent->Key->Shift == Py_True)
|
|
||||||
{
|
|
||||||
Py_DECREF(Py_True);
|
|
||||||
Py_INCREF(Py_False);
|
|
||||||
PyEvent->Key->Shift = Py_False;
|
|
||||||
}
|
|
||||||
PyEvent->MouseButton->Button = PyEvent->obj->MouseButton.Button;
|
PyEvent->MouseButton->Button = PyEvent->obj->MouseButton.Button;
|
||||||
PyEvent->MouseButton->X = PyEvent->obj->MouseButton.X;
|
PyEvent->MouseButton->X = PyEvent->obj->MouseButton.X;
|
||||||
PyEvent->MouseButton->Y = PyEvent->obj->MouseButton.Y;
|
PyEvent->MouseButton->Y = PyEvent->obj->MouseButton.Y;
|
||||||
@ -136,30 +105,23 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
|
|||||||
sf::VideoMode *VideoMode;
|
sf::VideoMode *VideoMode;
|
||||||
char *Title=NULL;
|
char *Title=NULL;
|
||||||
unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close;
|
unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close;
|
||||||
PySfWindowSettings *ParamsTmp=NULL;
|
PySfWindowSettings *Params=NULL;
|
||||||
sf::WindowSettings *Params = NULL;
|
|
||||||
|
|
||||||
const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL};
|
const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL};
|
||||||
|
|
||||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &ParamsTmp))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!:Window.Create", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &Params))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
if (VideoModeTmp) {
|
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
||||||
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
|
||||||
PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
|
|
||||||
}
|
|
||||||
else
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
if (ParamsTmp)
|
if (Params)
|
||||||
{
|
{
|
||||||
PySfWindowSettingsUpdate(ParamsTmp);
|
PySfWindowSettingsUpdate(Params);
|
||||||
Params = ParamsTmp->obj;
|
self->obj->Create(*VideoMode, Title, WindowStyle, *(Params->obj));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Params = new sf::WindowSettings();
|
self->obj->Create(*VideoMode, Title, WindowStyle);
|
||||||
|
|
||||||
self->obj->Create(*VideoMode, Title, WindowStyle, *Params);
|
|
||||||
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@ -183,10 +145,7 @@ PySfWindow_Close(PySfWindow *self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_IsOpened(PySfWindow *self)
|
PySfWindow_IsOpened(PySfWindow *self)
|
||||||
{
|
{
|
||||||
if (self->obj->IsOpened())
|
return PyBool_FromLong(self->obj->IsOpened());
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_NONE;
|
|
||||||
}
|
}
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_GetWidth(PySfWindow *self)
|
PySfWindow_GetWidth(PySfWindow *self)
|
||||||
@ -202,32 +161,20 @@ PySfWindow_GetHeight(PySfWindow *self)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_UseVerticalSync(PySfWindow *self, PyObject *args)
|
PySfWindow_UseVerticalSync(PySfWindow *self, PyObject *args)
|
||||||
{
|
{
|
||||||
bool Enabled = false;
|
self->obj->UseVerticalSync(PyBool_AsBool(args));
|
||||||
if (PyObject_IsTrue(args))
|
|
||||||
Enabled = true;
|
|
||||||
self->obj->UseVerticalSync(Enabled);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_ShowMouseCursor(PySfWindow *self, PyObject *args)
|
PySfWindow_ShowMouseCursor(PySfWindow *self, PyObject *args)
|
||||||
{
|
{
|
||||||
bool Show = false;
|
self->obj->ShowMouseCursor(PyBool_AsBool(args));
|
||||||
if (PyObject_IsTrue(args))
|
|
||||||
Show = true;
|
|
||||||
self->obj->ShowMouseCursor(Show);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_SetActive(PySfWindow *self, PyObject *args)
|
PySfWindow_SetActive(PySfWindow *self, PyObject *args)
|
||||||
{
|
{
|
||||||
bool Active = false;
|
return PyBool_FromLong(self->obj->SetActive(PyBool_AsBool(args)));
|
||||||
if (PyObject_IsTrue(args))
|
|
||||||
Active = true;
|
|
||||||
if (self->obj->SetActive(Active))
|
|
||||||
Py_RETURN_TRUE;
|
|
||||||
else
|
|
||||||
Py_RETURN_FALSE;
|
|
||||||
}
|
}
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_Display(PySfWindow *self)
|
PySfWindow_Display(PySfWindow *self)
|
||||||
@ -266,9 +213,8 @@ static PyObject *
|
|||||||
PySfWindow_SetPosition(PySfWindow* self, PyObject *args)
|
PySfWindow_SetPosition(PySfWindow* self, PyObject *args)
|
||||||
{
|
{
|
||||||
int Left=0, Top=0;
|
int Left=0, Top=0;
|
||||||
if (! PyArg_ParseTuple(args, "ii", &Left, &Top))
|
if (!PyArg_ParseTuple(args, "ii:Window.SetPosition", &Left, &Top))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self->obj->SetPosition(Left,Top);
|
self->obj->SetPosition(Left,Top);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@ -283,20 +229,14 @@ PySfWindow_SetFramerateLimit(PySfWindow *self, PyObject *args)
|
|||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_Show(PySfWindow *self, PyObject *args)
|
PySfWindow_Show(PySfWindow *self, PyObject *args)
|
||||||
{
|
{
|
||||||
if (PyObject_IsTrue(args))
|
self->obj->Show(PyBool_AsBool(args));
|
||||||
self->obj->Show(true);
|
|
||||||
else
|
|
||||||
self->obj->Show(false);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfWindow_EnableKeyRepeat(PySfWindow *self, PyObject *args)
|
PySfWindow_EnableKeyRepeat(PySfWindow *self, PyObject *args)
|
||||||
{
|
{
|
||||||
if (PyObject_IsTrue(args))
|
self->obj->EnableKeyRepeat(PyBool_AsBool(args));
|
||||||
self->obj->EnableKeyRepeat(true);
|
|
||||||
else
|
|
||||||
self->obj->EnableKeyRepeat(false);
|
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -304,9 +244,8 @@ static PyObject *
|
|||||||
PySfWindow_SetCursorPosition(PySfWindow* self, PyObject *args)
|
PySfWindow_SetCursorPosition(PySfWindow* self, PyObject *args)
|
||||||
{
|
{
|
||||||
unsigned int Left=0, Top=0;
|
unsigned int Left=0, Top=0;
|
||||||
if (! PyArg_ParseTuple(args, "II", &Left, &Top))
|
if (!PyArg_ParseTuple(args, "II:Window.SetCursorPosition", &Left, &Top))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self->obj->SetCursorPosition(Left,Top);
|
self->obj->SetCursorPosition(Left,Top);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@ -315,9 +254,8 @@ static PyObject *
|
|||||||
PySfWindow_SetSize(PySfWindow* self, PyObject *args)
|
PySfWindow_SetSize(PySfWindow* self, PyObject *args)
|
||||||
{
|
{
|
||||||
unsigned int Width=0, Height=0;
|
unsigned int Width=0, Height=0;
|
||||||
if (! PyArg_ParseTuple(args, "II", &Width, &Height))
|
if (!PyArg_ParseTuple(args, "II:Window.SetSize", &Width, &Height))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self->obj->SetSize(Width, Height);
|
self->obj->SetSize(Width, Height);
|
||||||
Py_RETURN_NONE;
|
Py_RETURN_NONE;
|
||||||
}
|
}
|
||||||
@ -335,7 +273,7 @@ PySfWindow_SetIcon(PySfWindow* self, PyObject *args)
|
|||||||
unsigned int Width, Height, Size;
|
unsigned int Width, Height, Size;
|
||||||
char *Data;
|
char *Data;
|
||||||
|
|
||||||
if (! PyArg_ParseTuple(args, "IIs#", &Width, &Height, &Data, &Size))
|
if (! PyArg_ParseTuple(args, "IIs#:Window.SetIcon", &Width, &Height, &Data, &Size))
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
self->obj->SetIcon(Width, Height, (sf::Uint8*) Data);
|
self->obj->SetIcon(Width, Height, (sf::Uint8*) Data);
|
||||||
@ -378,8 +316,7 @@ Change the window's icon.\n\
|
|||||||
};
|
};
|
||||||
|
|
||||||
PyTypeObject PySfWindowType = {
|
PyTypeObject PySfWindowType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Window", /*tp_name*/
|
"Window", /*tp_name*/
|
||||||
sizeof(PySfWindow), /*tp_basicsize*/
|
sizeof(PySfWindow), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -414,7 +351,7 @@ Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close
|
|||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfWindow_methods, /* tp_methods */
|
PySfWindow_methods, /* tp_methods */
|
||||||
PySfWindow_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
|
@ -25,17 +25,9 @@
|
|||||||
#ifndef __PYWINDOW_HPP
|
#ifndef __PYWINDOW_HPP
|
||||||
#define __PYWINDOW_HPP
|
#define __PYWINDOW_HPP
|
||||||
|
|
||||||
#include <SFML/System.hpp>
|
|
||||||
#include <SFML/Window.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "Event.hpp"
|
#include <SFML/Window/Window.hpp>
|
||||||
#include "VideoMode.hpp"
|
|
||||||
#include "Input.hpp"
|
|
||||||
#include "WindowSettings.hpp"
|
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -24,6 +24,11 @@
|
|||||||
|
|
||||||
#include "WindowSettings.hpp"
|
#include "WindowSettings.hpp"
|
||||||
|
|
||||||
|
#include <structmember.h>
|
||||||
|
|
||||||
|
#include "offsetof.hpp"
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
static PyMemberDef PySfWindowSettings_members[] = {
|
static PyMemberDef PySfWindowSettings_members[] = {
|
||||||
{(char *)"DepthBits", T_UINT, offsetof(PySfWindowSettings, DepthBits), 0, (char *)"Depth buffer bits (24 by default)"},
|
{(char *)"DepthBits", T_UINT, offsetof(PySfWindowSettings, DepthBits), 0, (char *)"Depth buffer bits (24 by default)"},
|
||||||
{(char *)"StencilBits", T_UINT, offsetof(PySfWindowSettings, StencilBits), 0, (char *)"Stencil buffer bits (8 by default)"},
|
{(char *)"StencilBits", T_UINT, offsetof(PySfWindowSettings, StencilBits), 0, (char *)"Stencil buffer bits (8 by default)"},
|
||||||
@ -36,7 +41,7 @@ static void
|
|||||||
PySfWindowSettings_dealloc(PySfWindowSettings *self)
|
PySfWindowSettings_dealloc(PySfWindowSettings *self)
|
||||||
{
|
{
|
||||||
delete self->obj;
|
delete self->obj;
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
free_object(self);
|
||||||
}
|
}
|
||||||
|
|
||||||
void
|
void
|
||||||
@ -51,16 +56,13 @@ static PyObject *
|
|||||||
PySfWindowSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfWindowSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfWindowSettings *self;
|
PySfWindowSettings *self;
|
||||||
|
|
||||||
self = (PySfWindowSettings *)type->tp_alloc(type, 0);
|
self = (PySfWindowSettings *)type->tp_alloc(type, 0);
|
||||||
|
|
||||||
if (self != NULL)
|
if (self != NULL)
|
||||||
{
|
{
|
||||||
self->DepthBits = 24;
|
self->DepthBits = 24;
|
||||||
self->StencilBits = 8;
|
self->StencilBits = 8;
|
||||||
self->AntialiasingLevel = 0;
|
self->AntialiasingLevel = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -69,21 +71,16 @@ static int
|
|||||||
PySfWindowSettings_init(PySfWindowSettings *self, PyObject *args, PyObject *kwds)
|
PySfWindowSettings_init(PySfWindowSettings *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", NULL};
|
const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", NULL};
|
||||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|III", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel)))
|
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|III:WindowSettings.__init__", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel)))
|
||||||
return -1;
|
return -1;
|
||||||
self->obj = new sf::WindowSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel);
|
self->obj = new sf::WindowSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel);
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
static PyMethodDef PySfWindowSettings_methods[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
PyTypeObject PySfWindowSettingsType = {
|
PyTypeObject PySfWindowSettingsType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"WindowSettings", /*tp_name*/
|
"WindowSettings", /*tp_name*/
|
||||||
sizeof(PySfWindowSettings), /*tp_basicsize*/
|
sizeof(PySfWindowSettings), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
@ -110,7 +107,7 @@ PyTypeObject PySfWindowSettingsType = {
|
|||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfWindowSettings_methods, /* tp_methods */
|
0, /* tp_methods */
|
||||||
PySfWindowSettings_members, /* tp_members */
|
PySfWindowSettings_members, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
|
@ -25,13 +25,9 @@
|
|||||||
#ifndef __PYWINDOWSETTINGS_HPP
|
#ifndef __PYWINDOWSETTINGS_HPP
|
||||||
#define __PYWINDOWSETTINGS_HPP
|
#define __PYWINDOWSETTINGS_HPP
|
||||||
|
|
||||||
#include <SFML/Window/WindowSettings.hpp>
|
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "offsetof.hpp"
|
#include <SFML/Window/WindowSettings.hpp>
|
||||||
|
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
@ -22,62 +22,25 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#include <SFML/Window/WindowStyle.hpp>
|
|
||||||
|
|
||||||
#include <Python.h>
|
|
||||||
#include <structmember.h>
|
|
||||||
|
|
||||||
#include "WindowStyle.hpp"
|
#include "WindowStyle.hpp"
|
||||||
|
|
||||||
|
#include "compat.hpp"
|
||||||
|
|
||||||
typedef struct {
|
|
||||||
PyObject_HEAD
|
|
||||||
} PySfStyle;
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
static PyMemberDef PySfStyle_members[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
|
|
||||||
static void
|
|
||||||
PySfStyle_dealloc(PySfStyle *self)
|
|
||||||
{
|
|
||||||
self->ob_type->tp_free((PyObject*)self);
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyObject *
|
static PyObject *
|
||||||
PySfStyle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
PySfStyle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
PySfStyle *self;
|
PySfStyle *self;
|
||||||
|
|
||||||
self = (PySfStyle *)type->tp_alloc(type, 0);
|
self = (PySfStyle *)type->tp_alloc(type, 0);
|
||||||
if (self != NULL)
|
|
||||||
{
|
|
||||||
}
|
|
||||||
|
|
||||||
return (PyObject *)self;
|
return (PyObject *)self;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static int
|
|
||||||
PySfStyle_init(PySfStyle *self, PyObject *args, PyObject *kwds)
|
|
||||||
{
|
|
||||||
return 0;
|
|
||||||
}
|
|
||||||
|
|
||||||
static PyMethodDef PySfStyle_methods[] = {
|
|
||||||
{NULL} /* Sentinel */
|
|
||||||
};
|
|
||||||
|
|
||||||
PyTypeObject PySfStyleType = {
|
PyTypeObject PySfStyleType = {
|
||||||
PyObject_HEAD_INIT(NULL)
|
head_init
|
||||||
0, /*ob_size*/
|
|
||||||
"Style", /*tp_name*/
|
"Style", /*tp_name*/
|
||||||
sizeof(PySfStyle), /*tp_basicsize*/
|
sizeof(PySfStyle), /*tp_basicsize*/
|
||||||
0, /*tp_itemsize*/
|
0, /*tp_itemsize*/
|
||||||
(destructor)PySfStyle_dealloc, /*tp_dealloc*/
|
0, /*tp_dealloc*/
|
||||||
0, /*tp_print*/
|
0, /*tp_print*/
|
||||||
0, /*tp_getattr*/
|
0, /*tp_getattr*/
|
||||||
0, /*tp_setattr*/
|
0, /*tp_setattr*/
|
||||||
@ -105,15 +68,15 @@ Fullscreen Fullscreen mode (this flag and all others are mutually exclusive).",
|
|||||||
0, /* tp_weaklistoffset */
|
0, /* tp_weaklistoffset */
|
||||||
0, /* tp_iter */
|
0, /* tp_iter */
|
||||||
0, /* tp_iternext */
|
0, /* tp_iternext */
|
||||||
PySfStyle_methods, /* tp_methods */
|
0, /* tp_methods */
|
||||||
PySfStyle_members, /* tp_members */
|
0, /* tp_members */
|
||||||
0, /* tp_getset */
|
0, /* tp_getset */
|
||||||
0, /* tp_base */
|
0, /* tp_base */
|
||||||
0, /* tp_dict */
|
0, /* tp_dict */
|
||||||
0, /* tp_descr_get */
|
0, /* tp_descr_get */
|
||||||
0, /* tp_descr_set */
|
0, /* tp_descr_set */
|
||||||
0, /* tp_dictoffset */
|
0, /* tp_dictoffset */
|
||||||
(initproc)PySfStyle_init, /* tp_init */
|
0, /* tp_init */
|
||||||
0, /* tp_alloc */
|
0, /* tp_alloc */
|
||||||
PySfStyle_new, /* tp_new */
|
PySfStyle_new, /* tp_new */
|
||||||
};
|
};
|
||||||
@ -121,19 +84,19 @@ Fullscreen Fullscreen mode (this flag and all others are mutually exclusive).",
|
|||||||
void PySfStyle_InitConst()
|
void PySfStyle_InitConst()
|
||||||
{
|
{
|
||||||
PyObject *obj;
|
PyObject *obj;
|
||||||
obj = PyInt_FromLong(sf::Style::None);
|
obj = PyLong_FromLong(sf::Style::None);
|
||||||
PyDict_SetItemString(PySfStyleType.tp_dict, "None", obj);
|
PyDict_SetItemString(PySfStyleType.tp_dict, "None", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Style::Titlebar);
|
obj = PyLong_FromLong(sf::Style::Titlebar);
|
||||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Titlebar", obj);
|
PyDict_SetItemString(PySfStyleType.tp_dict, "Titlebar", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Style::Resize);
|
obj = PyLong_FromLong(sf::Style::Resize);
|
||||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Resize", obj);
|
PyDict_SetItemString(PySfStyleType.tp_dict, "Resize", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Style::Close);
|
obj = PyLong_FromLong(sf::Style::Close);
|
||||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Close", obj);
|
PyDict_SetItemString(PySfStyleType.tp_dict, "Close", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
obj = PyInt_FromLong(sf::Style::Fullscreen);
|
obj = PyLong_FromLong(sf::Style::Fullscreen);
|
||||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Fullscreen", obj);
|
PyDict_SetItemString(PySfStyleType.tp_dict, "Fullscreen", obj);
|
||||||
Py_DECREF(obj);
|
Py_DECREF(obj);
|
||||||
}
|
}
|
||||||
|
@ -25,6 +25,14 @@
|
|||||||
#ifndef __PYWINDOWSTYLE_HPP
|
#ifndef __PYWINDOWSTYLE_HPP
|
||||||
#define __PYWINDOWSTYLE_HPP
|
#define __PYWINDOWSTYLE_HPP
|
||||||
|
|
||||||
|
#include <Python.h>
|
||||||
|
|
||||||
|
#include <SFML/Window/WindowStyle.hpp>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
PyObject_HEAD
|
||||||
|
} PySfStyle;
|
||||||
|
|
||||||
void
|
void
|
||||||
PySfStyle_InitConst();
|
PySfStyle_InitConst();
|
||||||
|
|
||||||
|
@ -26,17 +26,44 @@
|
|||||||
#define __PYCOMPAT_HPP
|
#define __PYCOMPAT_HPP
|
||||||
|
|
||||||
#if PY_MAJOR_VERSION >= 3
|
#if PY_MAJOR_VERSION >= 3
|
||||||
|
|
||||||
#define IS_PY3K
|
#define IS_PY3K
|
||||||
#define head_init PyVarObject_HEAD_INIT(NULL, 0)
|
#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
|
#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 Py_TYPE(a) a->ob_type
|
#define Py_TYPE(a) a->ob_type
|
||||||
#define head_init PyObject_HEAD_INIT(NULL) 0,
|
#define head_init PyObject_HEAD_INIT(NULL) 0,
|
||||||
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define free_object(a) Py_TYPE(a)->tp_free((PyObject*)a)
|
#define free_object(a) Py_TYPE(a)->tp_free((PyObject*)a)
|
||||||
|
|
||||||
#define PyBool_AsBool(a) ((PyObject_IsTrue(a))?true:false)
|
#define PyBool_AsBool(a) ((PyObject_IsTrue(a))?true:false)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
@ -69,8 +69,7 @@ extern PyTypeObject PySfGlyphType;
|
|||||||
extern PyTypeObject PySfStringType;
|
extern PyTypeObject PySfStringType;
|
||||||
extern PyTypeObject PySfPostFXType;
|
extern PyTypeObject PySfPostFXType;
|
||||||
|
|
||||||
extern PyTypeObject PySfImageType;
|
extern PyTypeObject PySfImageType;
|
||||||
|
|
||||||
extern PyTypeObject PySfColorType;
|
extern PyTypeObject PySfColorType;
|
||||||
|
|
||||||
extern PyTypeObject PySfShapeType;
|
extern PyTypeObject PySfShapeType;
|
||||||
@ -96,8 +95,8 @@ static PyMethodDef module_methods[] = {
|
|||||||
#define INITERROR return NULL
|
#define INITERROR return NULL
|
||||||
static PyModuleDef module_def = {
|
static PyModuleDef module_def = {
|
||||||
PyModuleDef_HEAD_INIT,
|
PyModuleDef_HEAD_INIT,
|
||||||
"noddy",
|
"sf",
|
||||||
"Example module that creates an extension type.",
|
"Python binding for sfml (Simple Fast Media Library)",
|
||||||
-1,
|
-1,
|
||||||
module_methods, NULL, NULL, NULL, NULL
|
module_methods, NULL, NULL, NULL, NULL
|
||||||
};
|
};
|
||||||
|
Loading…
Reference in New Issue
Block a user