* Began supporting python3

* Code clean-up


git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1021 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
remi-k 2009-02-25 10:40:38 +00:00
parent 60ebaa84d1
commit 79bf5c6252
31 changed files with 572 additions and 644 deletions

View File

@ -30,11 +30,7 @@ def main():
Texture = glGenTextures(1) # instead of glGenTextures(1, &Texture); Texture = glGenTextures(1) # instead of glGenTextures(1, &Texture);
glBindTexture(GL_TEXTURE_2D, Texture) glBindTexture(GL_TEXTURE_2D, Texture)
# It is almost the same line there, except in C++, the last argument was Image.GetPixelsPtr(). # It is almost the same line there, except in C++, the last argument was Image.GetPixelsPtr().
# With GetPixelsPtr, PySFML returns a PyCObject: "an opaque value, useful for C extension # In python, GetPixels simply returns a string.
# modules who need to pass an opaque value (as a void* pointer) through Python code to other C code".
# However, gluBuild2DMipmaps' python version takes a string as last argument (which is normally a
# pointer to pixels data). This is why Image.GetPixelsPtr is replaced by Image.GetPixelsString.
# This function (that doesn't exist in C++ SFML) returns a string that contains the pixels data.
gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.GetWidth(), Image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, Image.GetPixels()) gluBuild2DMipmaps(GL_TEXTURE_2D, GL_RGBA, Image.GetWidth(), Image.GetHeight(), GL_RGBA, GL_UNSIGNED_BYTE, Image.GetPixels())
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR) glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
@ -73,7 +69,7 @@ def main():
# Adjust the viewport when the window is resized # Adjust the viewport when the window is resized
if Event.Type == sf.Event.Resized: if Event.Type == sf.Event.Resized:
glViewport(0, 0, Event.Size.Width, Event.Size.Height); glViewport(0, 0, Event.Size.Width, Event.Size.Height)
# Draw background # Draw background
App.Draw(Background) App.Draw(Background)
@ -81,7 +77,7 @@ def main():
# Clear depth buffer # Clear depth buffer
glClear(GL_DEPTH_BUFFER_BIT) glClear(GL_DEPTH_BUFFER_BIT)
# Apply some transf.ormations # Apply some transformations
glMatrixMode(GL_MODELVIEW) glMatrixMode(GL_MODELVIEW)
glLoadIdentity() glLoadIdentity()
glTranslatef(0, 0, -200) glTranslatef(0, 0, -200)

View File

@ -24,24 +24,14 @@
#include "Clock.hpp" #include "Clock.hpp"
#include "compat.hpp"
typedef struct {
PyObject_HEAD
sf::Clock *obj;
} PySfClock;
static PyMemberDef PySfClock_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfClock_dealloc(PySfClock *self) PySfClock_dealloc(PySfClock *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
@ -86,8 +76,7 @@ static PyMethodDef PySfClock_methods[] = {
}; };
PyTypeObject PySfClockType = { PyTypeObject PySfClockType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Clock", /*tp_name*/ "Clock", /*tp_name*/
sizeof(PySfClock), /*tp_basicsize*/ sizeof(PySfClock), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -95,7 +84,7 @@ PyTypeObject PySfClockType = {
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
0, /*tp_compare*/ 0, /*tp_compare (tp_reserved in py3k)*/
0, /*tp_repr*/ 0, /*tp_repr*/
0, /*tp_as_number*/ 0, /*tp_as_number*/
0, /*tp_as_sequence*/ 0, /*tp_as_sequence*/
@ -115,7 +104,7 @@ PyTypeObject PySfClockType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfClock_methods, /* tp_methods */ PySfClock_methods, /* tp_methods */
PySfClock_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View File

@ -25,11 +25,13 @@
#ifndef __PYCLOCK_HPP #ifndef __PYCLOCK_HPP
#define __PYCLOCK_HPP #define __PYCLOCK_HPP
#include <Python.h>
#include <SFML/System/Clock.hpp> #include <SFML/System/Clock.hpp>
#include <iostream>
#include <Python.h> typedef struct {
#include <structmember.h> PyObject_HEAD
sf::Clock *obj;
} PySfClock;
#endif #endif

View File

@ -24,6 +24,9 @@
#include "Color.hpp" #include "Color.hpp"
#include "offsetof.hpp"
#include "compat.hpp"
static PyMemberDef PySfColor_members[] = { static PyMemberDef PySfColor_members[] = {
{(char *)"r", T_UBYTE, offsetof(PySfColor, r), 0, (char *)"Red component."}, {(char *)"r", T_UBYTE, offsetof(PySfColor, r), 0, (char *)"Red component."},
{(char *)"g", T_UBYTE, offsetof(PySfColor, g), 0, (char *)"Green component."}, {(char *)"g", T_UBYTE, offsetof(PySfColor, g), 0, (char *)"Green component."},
@ -38,7 +41,7 @@ static void
PySfColor_dealloc(PySfColor *self) PySfColor_dealloc(PySfColor *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
void void
@ -101,8 +104,7 @@ static PyMethodDef PySfColor_methods[] = {
PyTypeObject PySfColorType = { PyTypeObject PySfColorType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Color", /*tp_name*/ "Color", /*tp_name*/
sizeof(PySfColor), /*tp_basicsize*/ sizeof(PySfColor), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/

View File

@ -25,13 +25,10 @@
#ifndef __PYCOLOR_HPP #ifndef __PYCOLOR_HPP
#define __PYCOLOR_HPP #define __PYCOLOR_HPP
#include <SFML/Graphics/Color.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h> #include <structmember.h>
#include "offsetof.hpp" #include <SFML/Graphics/Color.hpp>
typedef struct { typedef struct {

View File

@ -23,6 +23,13 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "Drawable.hpp" #include "Drawable.hpp"
#include "Color.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType;
void CustomDrawable::Render (sf::RenderTarget& Target) const void CustomDrawable::Render (sf::RenderTarget& Target) const
{ {
@ -30,20 +37,11 @@ void CustomDrawable::Render (sf::RenderTarget& Target) const
PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow); PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow);
} }
extern PyTypeObject PySfColorType;
static PyMemberDef PySfDrawable_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfDrawable_dealloc(PySfDrawable *self) PySfDrawable_dealloc(PySfDrawable *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
@ -261,8 +259,7 @@ Transform a point from local coordinates into global coordinates (ie it applies
}; };
PyTypeObject PySfDrawableType = { PyTypeObject PySfDrawableType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Drawable", /*tp_name*/ "Drawable", /*tp_name*/
sizeof(PySfDrawable), /*tp_basicsize*/ sizeof(PySfDrawable), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -290,7 +287,7 @@ PyTypeObject PySfDrawableType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfDrawable_methods, /* tp_methods */ PySfDrawable_methods, /* tp_methods */
PySfDrawable_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View File

@ -25,13 +25,10 @@
#ifndef __PYDRAWABLE_H #ifndef __PYDRAWABLE_H
#define __PYDRAWABLE_H #define __PYDRAWABLE_H
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "Color.hpp" #include <SFML/Graphics/Drawable.hpp>
#include "RenderWindow.hpp" #include "RenderWindow.hpp"

View File

@ -24,13 +24,16 @@
#include "Event.hpp" #include "Event.hpp"
#include <structmember.h>
#include "compat.hpp"
//////////////////////////////// ////////////////////////////////
// Text Events Parameters // Text Events Parameters
//////////////////////////////// ////////////////////////////////
PyMemberDef PySfEventText_members[] = { PyMemberDef PySfEventText_members[] = {
{(char *)"Unicode", T_USHORT, offsetof(PySfEventText, Unicode), RO, (char *)""}, {(char *)"Unicode", T_USHORT, offsetof(PySfEventText, Unicode), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
@ -57,12 +60,11 @@ PySfEventText_init(PySfEventText *self, PyObject *args, PyObject *kwds)
void void
PySfEventText_dealloc(PySfEventText* self) PySfEventText_dealloc(PySfEventText* self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyTypeObject PySfEventTextType = { PyTypeObject PySfEventTextType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.Text", /*tp_name*/ "Event.Text", /*tp_name*/
sizeof(PySfEventText), /*tp_basicsize*/ sizeof(PySfEventText), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -136,20 +138,19 @@ PySfEventKey_init(PySfEventKey *self, PyObject *args, PyObject *kwds)
void void
PySfEventKey_dealloc(PySfEventKey* self) PySfEventKey_dealloc(PySfEventKey* self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyMemberDef PySfEventKey_members[] = { PyMemberDef PySfEventKey_members[] = {
{(char *)"Alt", T_OBJECT, offsetof(PySfEventKey, Alt), RO, (char *)""}, {(char *)"Alt", T_OBJECT, offsetof(PySfEventKey, Alt), READONLY, (char *)""},
{(char *)"Control", T_OBJECT, offsetof(PySfEventKey, Control), RO, (char *)""}, {(char *)"Control", T_OBJECT, offsetof(PySfEventKey, Control), READONLY, (char *)""},
{(char *)"Shift", T_OBJECT, offsetof(PySfEventKey, Shift), RO, (char *)""}, {(char *)"Shift", T_OBJECT, offsetof(PySfEventKey, Shift), READONLY, (char *)""},
{(char *)"Code", T_UINT, offsetof(PySfEventKey, Code), RO, (char *)""}, {(char *)"Code", T_UINT, offsetof(PySfEventKey, Code), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfEventKeyType = { PyTypeObject PySfEventKeyType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.Key", /*tp_name*/ "Event.Key", /*tp_name*/
sizeof(PySfEventKey), /*tp_basicsize*/ sizeof(PySfEventKey), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -218,19 +219,18 @@ PySfEventMouseMove_init(PySfEventMouseMove *self, PyObject *args, PyObject *kwds
void void
PySfEventMouseMove_dealloc(PySfEventMouseMove *self) PySfEventMouseMove_dealloc(PySfEventMouseMove *self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyMemberDef PySfEventMouseMove_members[] = { PyMemberDef PySfEventMouseMove_members[] = {
{(char *)"X", T_INT, offsetof(PySfEventMouseMove, X), RO, (char *)""}, {(char *)"X", T_INT, offsetof(PySfEventMouseMove, X), READONLY, (char *)""},
{(char *)"Y", T_INT, offsetof(PySfEventMouseMove, Y), RO, (char *)""}, {(char *)"Y", T_INT, offsetof(PySfEventMouseMove, Y), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfEventMouseMoveType = { PyTypeObject PySfEventMouseMoveType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.MouseMove", /*tp_name*/ "Event.MouseMove", /*tp_name*/
sizeof(PySfEventMouseMove), /*tp_basicsize*/ sizeof(PySfEventMouseMove), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -300,20 +300,19 @@ PySfEventMouseButton_init(PySfEventMouseButton *self, PyObject *args, PyObject *
void void
PySfEventMouseButton_dealloc(PySfEventMouseButton* self) PySfEventMouseButton_dealloc(PySfEventMouseButton* self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyMemberDef PySfEventMouseButton_members[] = { PyMemberDef PySfEventMouseButton_members[] = {
{(char *)"Button", T_UINT, offsetof(PySfEventMouseButton, Button), RO, (char *)""}, {(char *)"Button", T_UINT, offsetof(PySfEventMouseButton, Button), READONLY, (char *)""},
{(char *)"X", T_INT, offsetof(PySfEventMouseButton, X), RO, (char *)""}, {(char *)"X", T_INT, offsetof(PySfEventMouseButton, X), READONLY, (char *)""},
{(char *)"Y", T_INT, offsetof(PySfEventMouseButton, Y), RO, (char *)""}, {(char *)"Y", T_INT, offsetof(PySfEventMouseButton, Y), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfEventMouseButtonType = { PyTypeObject PySfEventMouseButtonType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.MouseButton", /*tp_name*/ "Event.MouseButton", /*tp_name*/
sizeof(PySfEventMouseButton), /*tp_basicsize*/ sizeof(PySfEventMouseButton), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -381,17 +380,16 @@ PySfEventMouseWheel_init(PySfEventMouseWheel *self, PyObject *args, PyObject *kw
void void
PySfEventMouseWheel_dealloc(PySfEventMouseWheel* self) PySfEventMouseWheel_dealloc(PySfEventMouseWheel* self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyMemberDef PySfEventMouseWheel_members[] = { PyMemberDef PySfEventMouseWheel_members[] = {
{(char *)"Delta", T_INT, offsetof(PySfEventMouseWheel,Delta), RO, (char *)""}, {(char *)"Delta", T_INT, offsetof(PySfEventMouseWheel,Delta), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfEventMouseWheelType = { PyTypeObject PySfEventMouseWheelType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.MouseWheel", /*tp_name*/ "Event.MouseWheel", /*tp_name*/
sizeof(PySfEventMouseWheel), /*tp_basicsize*/ sizeof(PySfEventMouseWheel), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -461,20 +459,19 @@ PySfEventJoyMove_init(PySfEventJoyMove *self, PyObject *args, PyObject *kwds)
void void
PySfEventJoyMove_dealloc(PySfEventJoyMove* self) PySfEventJoyMove_dealloc(PySfEventJoyMove* self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyMemberDef PySfEventJoyMove_members[] = { PyMemberDef PySfEventJoyMove_members[] = {
{(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyMove,JoystickId), RO, (char *)""}, {(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyMove,JoystickId), READONLY, (char *)""},
{(char *)"Axis", T_UINT, offsetof(PySfEventJoyMove,Axis), RO, (char *)""}, {(char *)"Axis", T_UINT, offsetof(PySfEventJoyMove,Axis), READONLY, (char *)""},
{(char *)"Position", T_FLOAT, offsetof(PySfEventJoyMove,Position), RO, (char *)""}, {(char *)"Position", T_FLOAT, offsetof(PySfEventJoyMove,Position), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfEventJoyMoveType = { PyTypeObject PySfEventJoyMoveType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.JoyMove", /*tp_name*/ "Event.JoyMove", /*tp_name*/
sizeof(PySfEventJoyMove), /*tp_basicsize*/ sizeof(PySfEventJoyMove), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -543,19 +540,18 @@ PySfEventJoyButton_init(PySfEventJoyButton *self, PyObject *args, PyObject *kwds
void void
PySfEventJoyButton_dealloc(PySfEventJoyButton* self) PySfEventJoyButton_dealloc(PySfEventJoyButton* self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyMemberDef PySfEventJoyButton_members[] = { PyMemberDef PySfEventJoyButton_members[] = {
{(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyButton, JoystickId), RO, (char *)""}, {(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyButton, JoystickId), READONLY, (char *)""},
{(char *)"Button", T_UINT, offsetof(PySfEventJoyButton, Button), RO, (char *)""}, {(char *)"Button", T_UINT, offsetof(PySfEventJoyButton, Button), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfEventJoyButtonType = { PyTypeObject PySfEventJoyButtonType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.JoyButton", /*tp_name*/ "Event.JoyButton", /*tp_name*/
sizeof(PySfEventJoyButton), /*tp_basicsize*/ sizeof(PySfEventJoyButton), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -624,18 +620,17 @@ PySfEventSize_init(PySfEventSize *self, PyObject *args, PyObject *kwds)
void void
PySfEventSize_dealloc(PySfEventSize* self) PySfEventSize_dealloc(PySfEventSize* self)
{ {
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
PyMemberDef PySfEventSize_members[] = { PyMemberDef PySfEventSize_members[] = {
{(char *)"Width", T_UINT, offsetof(PySfEventSize, Width), RO, (char *)""}, {(char *)"Width", T_UINT, offsetof(PySfEventSize, Width), READONLY, (char *)""},
{(char *)"Height", T_UINT, offsetof(PySfEventSize, Height), RO, (char *)""}, {(char *)"Height", T_UINT, offsetof(PySfEventSize, Height), READONLY, (char *)""},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfEventSizeType = { PyTypeObject PySfEventSizeType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event.Size", /*tp_name*/ "Event.Size", /*tp_name*/
sizeof(PySfEventSize), /*tp_basicsize*/ sizeof(PySfEventSize), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -725,19 +720,19 @@ PySfEvent_dealloc(PySfEvent* self)
Py_DECREF(self->JoyButton); Py_DECREF(self->JoyButton);
Py_DECREF(self->Size); Py_DECREF(self->Size);
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyMemberDef PySfEvent_members[] = { static PyMemberDef PySfEvent_members[] = {
{(char *)"Text", T_OBJECT, offsetof(PySfEvent, Text), RO, (char *)"Text Events Parameters"}, {(char *)"Text", T_OBJECT, offsetof(PySfEvent, Text), READONLY, (char *)"Text Events Parameters"},
{(char *)"Key", T_OBJECT, offsetof(PySfEvent, Key), RO, (char *)"Keyboard Events Parameters"}, {(char *)"Key", T_OBJECT, offsetof(PySfEvent, Key), READONLY, (char *)"Keyboard Events Parameters"},
{(char *)"MouseMove", T_OBJECT, offsetof(PySfEvent, MouseMove), RO, (char *)"MouseMove Events Parameters"}, {(char *)"MouseMove", T_OBJECT, offsetof(PySfEvent, MouseMove), READONLY, (char *)"MouseMove Events Parameters"},
{(char *)"MouseButton", T_OBJECT, offsetof(PySfEvent, MouseButton), RO, (char *)"MouseButton Events Parameters"}, {(char *)"MouseButton", T_OBJECT, offsetof(PySfEvent, MouseButton), READONLY, (char *)"MouseButton Events Parameters"},
{(char *)"MouseWheel", T_OBJECT, offsetof(PySfEvent, MouseWheel), RO, (char *)"MouseWheel Events Parameters"}, {(char *)"MouseWheel", T_OBJECT, offsetof(PySfEvent, MouseWheel), READONLY, (char *)"MouseWheel Events Parameters"},
{(char *)"JoyMove", T_OBJECT, offsetof(PySfEvent, JoyMove), RO, (char *)"JoyMove Events Parameters"}, {(char *)"JoyMove", T_OBJECT, offsetof(PySfEvent, JoyMove), READONLY, (char *)"JoyMove Events Parameters"},
{(char *)"JoyButton", T_OBJECT, offsetof(PySfEvent, JoyButton), RO, (char *)"JoyButton Events Parameters"}, {(char *)"JoyButton", T_OBJECT, offsetof(PySfEvent, JoyButton), READONLY, (char *)"JoyButton Events Parameters"},
{(char *)"Size", T_OBJECT, offsetof(PySfEvent, Size), RO, (char *)"Size Events Parameters"}, {(char *)"Size", T_OBJECT, offsetof(PySfEvent, Size), READONLY, (char *)"Size Events Parameters"},
{(char *)"Type", T_UINT, offsetof(PySfEvent, Type), RO, (char *)"Type Events Parameters"}, {(char *)"Type", T_UINT, offsetof(PySfEvent, Type), READONLY, (char *)"Type Events Parameters"},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
@ -746,8 +741,7 @@ static PyMethodDef PySfEvent_methods[] = {
}; };
PyTypeObject PySfEventType = { PyTypeObject PySfEventType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Event", /*tp_name*/ "Event", /*tp_name*/
sizeof(PySfEvent), /*tp_basicsize*/ sizeof(PySfEvent), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -792,52 +786,52 @@ void
PySfEvent_InitConst() PySfEvent_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::Event::KeyReleased); obj = PyLong_FromLong(sf::Event::KeyReleased);
PyDict_SetItemString(PySfEventType.tp_dict, "KeyReleased", obj); PyDict_SetItemString(PySfEventType.tp_dict, "KeyReleased", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::LostFocus); obj = PyLong_FromLong(sf::Event::LostFocus);
PyDict_SetItemString(PySfEventType.tp_dict, "LostFocus", obj); PyDict_SetItemString(PySfEventType.tp_dict, "LostFocus", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::GainedFocus); obj = PyLong_FromLong(sf::Event::GainedFocus);
PyDict_SetItemString(PySfEventType.tp_dict, "GainedFocus", obj); PyDict_SetItemString(PySfEventType.tp_dict, "GainedFocus", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::KeyPressed); obj = PyLong_FromLong(sf::Event::KeyPressed);
PyDict_SetItemString(PySfEventType.tp_dict, "KeyPressed", obj); PyDict_SetItemString(PySfEventType.tp_dict, "KeyPressed", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::MouseWheelMoved); obj = PyLong_FromLong(sf::Event::MouseWheelMoved);
PyDict_SetItemString(PySfEventType.tp_dict, "MouseWheelMoved", obj); PyDict_SetItemString(PySfEventType.tp_dict, "MouseWheelMoved", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::TextEntered); obj = PyLong_FromLong(sf::Event::TextEntered);
PyDict_SetItemString(PySfEventType.tp_dict, "TextEntered", obj); PyDict_SetItemString(PySfEventType.tp_dict, "TextEntered", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::MouseMoved); obj = PyLong_FromLong(sf::Event::MouseMoved);
PyDict_SetItemString(PySfEventType.tp_dict, "MouseMoved", obj); PyDict_SetItemString(PySfEventType.tp_dict, "MouseMoved", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::JoyButtonPressed); obj = PyLong_FromLong(sf::Event::JoyButtonPressed);
PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonPressed", obj); PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonPressed", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::MouseButtonReleased); obj = PyLong_FromLong(sf::Event::MouseButtonReleased);
PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonReleased", obj); PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonReleased", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::Closed); obj = PyLong_FromLong(sf::Event::Closed);
PyDict_SetItemString(PySfEventType.tp_dict, "Closed", obj); PyDict_SetItemString(PySfEventType.tp_dict, "Closed", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::MouseButtonPressed); obj = PyLong_FromLong(sf::Event::MouseButtonPressed);
PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonPressed", obj); PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonPressed", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::JoyMoved); obj = PyLong_FromLong(sf::Event::JoyMoved);
PyDict_SetItemString(PySfEventType.tp_dict, "JoyMoved", obj); PyDict_SetItemString(PySfEventType.tp_dict, "JoyMoved", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::JoyButtonReleased); obj = PyLong_FromLong(sf::Event::JoyButtonReleased);
PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonReleased", obj); PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonReleased", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::Resized); obj = PyLong_FromLong(sf::Event::Resized);
PyDict_SetItemString(PySfEventType.tp_dict, "Resized", obj); PyDict_SetItemString(PySfEventType.tp_dict, "Resized", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::MouseEntered); obj = PyLong_FromLong(sf::Event::MouseEntered);
PyDict_SetItemString(PySfEventType.tp_dict, "MouseEntered", obj); PyDict_SetItemString(PySfEventType.tp_dict, "MouseEntered", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Event::MouseLeft); obj = PyLong_FromLong(sf::Event::MouseLeft);
PyDict_SetItemString(PySfEventType.tp_dict, "MouseLeft", obj); PyDict_SetItemString(PySfEventType.tp_dict, "MouseLeft", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View File

@ -25,12 +25,9 @@
#ifndef __PYEVENT_HPP #ifndef __PYEVENT_HPP
#define __PYEVENT_HPP #define __PYEVENT_HPP
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include <SFML/Window/Event.hpp>
typedef struct typedef struct
{ {

View File

@ -24,34 +24,27 @@
#include "Image.hpp" #include "Image.hpp"
#include "RenderWindow.hpp" #include "RenderWindow.hpp"
#include "Color.hpp"
#include "Rect.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType; extern PyTypeObject PySfColorType;
extern PyTypeObject PySfIntRectType; extern PyTypeObject PySfIntRectType;
extern PyTypeObject PySfRenderWindowType; extern PyTypeObject PySfRenderWindowType;
static PyMemberDef PySfImage_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfImage_dealloc(PySfImage* self) PySfImage_dealloc(PySfImage* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfImage_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfImage_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfImage *self; PySfImage *self;
self = (PySfImage *)type->tp_alloc(type, 0); self = (PySfImage *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -64,7 +57,7 @@ PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
unsigned int Width=0, Height=0; unsigned int Width=0, Height=0;
const char *kwlist[] = {"Width", "Height", "Color", NULL}; const char *kwlist[] = {"Width", "Height", "Color", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!", (char **)kwlist, &Width, &Height, &PySfColorType, &ColorTmp)) if (! PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!:Image.Create", (char **)kwlist, &Width, &Height, &PySfColorType, &ColorTmp))
return NULL; return NULL;
if (ColorTmp) if (ColorTmp)
@ -82,12 +75,11 @@ PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
static PyObject * static PyObject *
PySfImage_CopyScreen(PySfImage* self, PyObject *args) PySfImage_CopyScreen(PySfImage* self, PyObject *args)
{ {
// bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
PySfRenderWindow *RenderWindow; PySfRenderWindow *RenderWindow;
PySfIntRect *SourceRect=NULL; PySfIntRect *SourceRect=NULL;
bool Result; bool Result;
if (! PyArg_ParseTuple(args, "O!|O!", &PySfRenderWindowType, &RenderWindow, &PySfIntRectType, &SourceRect)) if (! PyArg_ParseTuple(args, "O!|O!:Image.CopyScreen", &PySfRenderWindowType, &RenderWindow, &PySfIntRectType, &SourceRect))
return NULL; return NULL;
@ -113,7 +105,7 @@ PySfImage_SetPixel(PySfImage* self, PyObject *args, PyObject *kwds)
const char *kwlist[] = {"x", "y", "Color", NULL}; const char *kwlist[] = {"x", "y", "Color", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|O!", (char **)kwlist, &x, &y, &PySfColorType, &ColorTmp)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|O!:Image.SetPixel", (char **)kwlist, &x, &y, &PySfColorType, &ColorTmp))
return NULL; return NULL;
@ -134,7 +126,7 @@ PySfImage_GetPixel(PySfImage* self, PyObject *args)
unsigned int x=0, y=0; unsigned int x=0, y=0;
if (! PyArg_ParseTuple(args, "II", &x, &y)) if (!PyArg_ParseTuple(args, "II:Image.GetPixel", &x, &y))
return NULL; return NULL;
@ -154,8 +146,11 @@ PySfImage_CreateMaskFromColor(PySfImage* self, PyObject *args)
PySfColor *ColorTmp= (PySfColor *)args; PySfColor *ColorTmp= (PySfColor *)args;
sf::Color *Color; sf::Color *Color;
if ( ! PyObject_TypeCheck(ColorTmp, &PySfColorType)) if (!PyObject_TypeCheck(ColorTmp, &PySfColorType))
PyErr_SetString(PyExc_ValueError, "Argument must be a sf.Color"); {
PyErr_SetString(PyExc_TypeError, "Image.CreateMaskFromColor() Argument must be a sf.Color");
return NULL;
}
Color = ColorTmp->obj; Color = ColorTmp->obj;
PySfColorUpdate(ColorTmp); PySfColorUpdate(ColorTmp);
self->obj->CreateMaskFromColor(*Color); self->obj->CreateMaskFromColor(*Color);
@ -169,14 +164,10 @@ PySfImage_LoadFromMemory(PySfImage* 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#:Image.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 *
@ -185,7 +176,7 @@ PySfImage_LoadFromPixels(PySfImage* 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#:Image.LoadFromPixels", &Width, &Height, &Data, &Size))
return NULL; return NULL;
self->obj->LoadFromPixels(Width, Height, (sf::Uint8*) Data); self->obj->LoadFromPixels(Width, Height, (sf::Uint8*) Data);
@ -195,29 +186,49 @@ PySfImage_LoadFromPixels(PySfImage* self, PyObject *args)
static PyObject * static PyObject *
PySfImage_GetPixels(PySfImage *self) PySfImage_GetPixels(PySfImage *self)
{ {
#ifdef IS_PY3K
return PyBytes_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
#else
return PyString_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4); return PyString_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
#endif
} }
static PyObject * static PyObject *
PySfImage_LoadFromFile (PySfImage *self, PyObject *args) PySfImage_LoadFromFile (PySfImage *self, PyObject *args)
{ {
char *path = PyString_AsString(args); char *path;
#ifdef IS_PY3K
if (self->obj->LoadFromFile(path)) PyObject *string = PyUnicode_AsUTF8String(args);
Py_RETURN_TRUE; if (string == NULL)
else return NULL;
Py_RETURN_FALSE; 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 = PyString_AsString(args); char *path;
#ifdef IS_PY3K
if (self->obj->SaveToFile(path)) PyObject *string = PyUnicode_AsUTF8String(args);
Py_RETURN_TRUE; if (string == NULL)
else return NULL;
Py_RETURN_FALSE; 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
@ -233,10 +244,7 @@ PySfImage_Bind(PySfImage *self)
static PyObject * static PyObject *
PySfImage_SetSmooth (PySfImage *self, PyObject *args) PySfImage_SetSmooth (PySfImage *self, PyObject *args)
{ {
bool arg=false; self->obj->SetSmooth(PyBool_AsBool(args));
if (PyObject_IsTrue(args))
arg = true;
self->obj->SetSmooth(arg);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -269,8 +277,9 @@ PySfImage_GetTexCoords(PySfImage* self, PyObject *args)
if (! PyArg_ParseTuple(args, "O!|O", &PySfIntRectType, &RectArg, &AdjustObj)) if (! PyArg_ParseTuple(args, "O!|O", &PySfIntRectType, &RectArg, &AdjustObj))
return NULL; return NULL;
if (PyObject_IsTrue(AdjustObj)) if (AdjustObj)
Adjust = true; if (PyObject_IsTrue(AdjustObj))
Adjust = true;
PySfFloatRect *Rect; PySfFloatRect *Rect;
@ -326,8 +335,7 @@ Create the image from the current contents of the given window. Return True if c
}; };
PyTypeObject PySfImageType = { PyTypeObject PySfImageType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Image", /*tp_name*/ "Image", /*tp_name*/
sizeof(PySfImage), /*tp_basicsize*/ sizeof(PySfImage), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -358,7 +366,7 @@ Copy constructor : sf.Image(Copy) where Copy is a sf.Image instance.", /* tp_doc
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfImage_methods, /* tp_methods */ PySfImage_methods, /* tp_methods */
PySfImage_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -373,7 +381,8 @@ Copy constructor : sf.Image(Copy) where Copy is a sf.Image instance.", /* tp_doc
static int static int
PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds) PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
{ {
if (PyTuple_Size(args) == 1) int size = PyTuple_Size(args);
if (size == 1)
{ {
PySfImage *Image; PySfImage *Image;
if (PyArg_ParseTuple(args, "O!", &PySfImageType, &Image)) if (PyArg_ParseTuple(args, "O!", &PySfImageType, &Image))
@ -386,8 +395,12 @@ PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
if (PyTuple_Size(args) > 0) if (PyTuple_Size(args) > 0)
{ {
if (PySfImage_Create(self, args, kwds) == NULL) if (PySfImage_Create(self, args, kwds) == NULL)
if (PySfImage_LoadFromPixels(self, args) == NULL) {
if (size != 3)
return -1; return -1;
else if (PySfImage_LoadFromPixels(self, args) == NULL)
return -1;
}
} }
return 0; return 0;
} }
@ -400,11 +413,12 @@ PySfImage_Copy(PySfImage* self, PyObject *args)
unsigned int DestX, DestY; unsigned int DestX, DestY;
PyObject *PyApplyAlpha; PyObject *PyApplyAlpha;
bool ApplyAlpha = false; bool ApplyAlpha = false;
if (! PyArg_ParseTuple(args, "O!II|O!O", &PySfImageType, &Source, &DestX, &DestY, &PySfIntRectType, &SourceRect, &PyApplyAlpha)) if (! PyArg_ParseTuple(args, "O!II|O!O:Image.Copy", &PySfImageType, &Source, &DestX, &DestY, &PySfIntRectType, &SourceRect, &PyApplyAlpha))
return NULL; return NULL;
if (PyObject_IsTrue(PyApplyAlpha)) if (PyApplyAlpha)
ApplyAlpha = true; if (PyObject_IsTrue(PyApplyAlpha))
ApplyAlpha = true;
if (SourceRect) if (SourceRect)
{ {

View File

@ -25,16 +25,9 @@
#ifndef __PYIMAGE_HPP #ifndef __PYIMAGE_HPP
#define __PYIMAGE_HPP #define __PYIMAGE_HPP
#include <SFML/Graphics/Image.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "Color.hpp" #include <SFML/Graphics/Image.hpp>
#include "Rect.hpp"
#include "offsetof.hpp"
typedef struct { typedef struct {

View File

@ -24,85 +24,61 @@
#include "Input.hpp" #include "Input.hpp"
#include "compat.hpp"
static PyMemberDef PySfInput_members[] = {
{NULL} /* Sentinel */
};
static void
PySfInput_dealloc(PySfInput *self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * static PyObject *
PySfInput_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfInput_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfInput *self; PySfInput *self;
self = (PySfInput *)type->tp_alloc(type, 0); self = (PySfInput *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int static int
PySfInput_init(PySfInput *self, PyObject *args, PyObject *kwds) PySfInput_init(PySfInput *self, PyObject *args, PyObject *kwds)
{ {
PyErr_SetString(PyExc_StandardError, "You can't create an Input object yourself, because an Input object must always be associated to its window.\nThe only way to get an Input is by creating a window and calling : Input = MyWindow.GetInput()."); PyErr_SetString(PyExc_RuntimeError, "You can't create an Input object yourself, because an Input object must always be associated to its window.\nThe only way to get an Input is by creating a window and calling : Input = MyWindow.GetInput().");
return -1; return -1;
} }
static PyObject* static PyObject*
PySfInput_IsKeyDown(PySfInput *self, PyObject *args) PySfInput_IsKeyDown(PySfInput *self, PyObject *args)
{ {
if (self->obj->IsKeyDown( (sf::Key::Code) PyInt_AsLong(args) )) return PyBool_FromLong(self->obj->IsKeyDown( (sf::Key::Code) PyLong_AsLong(args) ));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
PySfInput_IsMouseButtonDown(PySfInput *self, PyObject *args) PySfInput_IsMouseButtonDown(PySfInput *self, PyObject *args)
{ {
if (self->obj->IsMouseButtonDown( (sf::Mouse::Button) PyInt_AsLong(args) )) return PyBool_FromLong(self->obj->IsMouseButtonDown( (sf::Mouse::Button) PyLong_AsLong(args) ));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
PySfInput_IsJoystickButtonDown(PySfInput *self, PyObject *args) PySfInput_IsJoystickButtonDown(PySfInput *self, PyObject *args)
{ {
unsigned int JoyId, Button; unsigned int JoyId, Button;
if (! PyArg_ParseTuple (args, "II", &JoyId, &Button)) if (! PyArg_ParseTuple (args, "II:Input.IsJoystickButtonDown", &JoyId, &Button))
return NULL; return NULL;
if (self->obj->IsJoystickButtonDown(JoyId, Button)) return PyBool_FromLong(self->obj->IsJoystickButtonDown(JoyId, Button));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
PySfInput_GetMouseX(PySfInput *self) PySfInput_GetMouseX(PySfInput *self)
{ {
return PyInt_FromLong(self->obj->GetMouseX()); return PyLong_FromLong(self->obj->GetMouseX());
} }
static PyObject* static PyObject*
PySfInput_GetMouseY(PySfInput *self) PySfInput_GetMouseY(PySfInput *self)
{ {
return PyInt_FromLong(self->obj->GetMouseY()); return PyLong_FromLong(self->obj->GetMouseY());
} }
static PyObject* static PyObject*
PySfInput_GetJoystickAxis(PySfInput *self, PyObject *args) PySfInput_GetJoystickAxis(PySfInput *self, PyObject *args)
{ {
unsigned int JoyId, Axis; unsigned int JoyId, Axis;
if (! PyArg_ParseTuple (args, "II", &JoyId, &Axis)) if (! PyArg_ParseTuple (args, "II:Input.GetJoystickAxis", &JoyId, &Axis))
return NULL; return NULL;
return PyFloat_FromDouble(self->obj->GetJoystickAxis(JoyId, (sf::Joy::Axis) Axis)); return PyFloat_FromDouble(self->obj->GetJoystickAxis(JoyId, (sf::Joy::Axis) Axis));
} }
@ -118,12 +94,11 @@ static PyMethodDef PySfInput_methods[] = {
}; };
PyTypeObject PySfInputType = { PyTypeObject PySfInputType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Input", /*tp_name*/ "Input", /*tp_name*/
sizeof(PySfInput), /*tp_basicsize*/ sizeof(PySfInput), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)PySfInput_dealloc, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
@ -147,7 +122,7 @@ PyTypeObject PySfInputType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfInput_methods, /* tp_methods */ PySfInput_methods, /* tp_methods */
PySfInput_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View File

@ -25,12 +25,9 @@
#ifndef __PYINPUT_HPP #ifndef __PYINPUT_HPP
#define __PYINPUT_HPP #define __PYINPUT_HPP
#include <SFML/Window/Input.hpp>
#include <SFML/Window/Event.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include <SFML/Window/Input.hpp>
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View File

@ -22,62 +22,24 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <Python.h>
#include <structmember.h>
#include "Key.hpp" #include "Key.hpp"
#include "compat.hpp"
typedef struct {
PyObject_HEAD
} PySfKey;
static PyMemberDef PySfKey_members[] = {
{NULL} /* Sentinel */
};
static void
PySfKey_dealloc(PySfKey *self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * static PyObject *
PySfKey_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfKey_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfKey *self; PySfKey *self;
self = (PySfKey *)type->tp_alloc(type, 0); self = (PySfKey *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int
PySfKey_init(PySfKey *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyMethodDef PySfKey_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject PySfKeyType = { PyTypeObject PySfKeyType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Key", /*tp_name*/ "Key", /*tp_name*/
sizeof(PySfKey), /*tp_basicsize*/ sizeof(PySfKey), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)PySfKey_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 +62,15 @@ PyTypeObject PySfKeyType = {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfKey_methods, /* tp_methods */ 0, /* tp_methods */
PySfKey_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)PySfKey_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PySfKey_new, /* tp_new */ PySfKey_new, /* tp_new */
}; };
@ -116,307 +78,307 @@ PyTypeObject PySfKeyType = {
void PySfKey_InitConst() void PySfKey_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::Key::Numpad2); obj = PyLong_FromLong(sf::Key::Numpad2);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad2", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad2", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad3); obj = PyLong_FromLong(sf::Key::Numpad3);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad3", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad3", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad0); obj = PyLong_FromLong(sf::Key::Numpad0);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad0", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad0", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad1); obj = PyLong_FromLong(sf::Key::Numpad1);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad1", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad1", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad6); obj = PyLong_FromLong(sf::Key::Numpad6);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad6", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad6", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad7); obj = PyLong_FromLong(sf::Key::Numpad7);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad7", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad7", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad4); obj = PyLong_FromLong(sf::Key::Numpad4);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad4", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad4", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad5); obj = PyLong_FromLong(sf::Key::Numpad5);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad5", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad5", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad8); obj = PyLong_FromLong(sf::Key::Numpad8);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad8", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad8", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Numpad9); obj = PyLong_FromLong(sf::Key::Numpad9);
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad9", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad9", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::RAlt); obj = PyLong_FromLong(sf::Key::RAlt);
PyDict_SetItemString(PySfKeyType.tp_dict, "RAlt", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "RAlt", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::PageUp); obj = PyLong_FromLong(sf::Key::PageUp);
PyDict_SetItemString(PySfKeyType.tp_dict, "PageUp", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "PageUp", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Multiply); obj = PyLong_FromLong(sf::Key::Multiply);
PyDict_SetItemString(PySfKeyType.tp_dict, "Multiply", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Multiply", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::D); obj = PyLong_FromLong(sf::Key::D);
PyDict_SetItemString(PySfKeyType.tp_dict, "D", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "D", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::SemiColon); obj = PyLong_FromLong(sf::Key::SemiColon);
PyDict_SetItemString(PySfKeyType.tp_dict, "SemiColon", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "SemiColon", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::H); obj = PyLong_FromLong(sf::Key::H);
PyDict_SetItemString(PySfKeyType.tp_dict, "H", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "H", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::L); obj = PyLong_FromLong(sf::Key::L);
PyDict_SetItemString(PySfKeyType.tp_dict, "L", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "L", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::P); obj = PyLong_FromLong(sf::Key::P);
PyDict_SetItemString(PySfKeyType.tp_dict, "P", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "P", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num7); obj = PyLong_FromLong(sf::Key::Num7);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num7", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num7", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::T); obj = PyLong_FromLong(sf::Key::T);
PyDict_SetItemString(PySfKeyType.tp_dict, "T", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "T", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::X); obj = PyLong_FromLong(sf::Key::X);
PyDict_SetItemString(PySfKeyType.tp_dict, "X", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "X", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::RSystem); obj = PyLong_FromLong(sf::Key::RSystem);
PyDict_SetItemString(PySfKeyType.tp_dict, "RSystem", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "RSystem", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F5); obj = PyLong_FromLong(sf::Key::F5);
PyDict_SetItemString(PySfKeyType.tp_dict, "F5", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F5", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num4); obj = PyLong_FromLong(sf::Key::Num4);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num4", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num4", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num5); obj = PyLong_FromLong(sf::Key::Num5);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num5", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num5", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num6); obj = PyLong_FromLong(sf::Key::Num6);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num6", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num6", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Right); obj = PyLong_FromLong(sf::Key::Right);
PyDict_SetItemString(PySfKeyType.tp_dict, "Right", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Right", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num0); obj = PyLong_FromLong(sf::Key::Num0);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num0", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num0", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num1); obj = PyLong_FromLong(sf::Key::Num1);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num1", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num1", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num2); obj = PyLong_FromLong(sf::Key::Num2);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num2", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num2", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num3); obj = PyLong_FromLong(sf::Key::Num3);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num3", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num3", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::LControl); obj = PyLong_FromLong(sf::Key::LControl);
PyDict_SetItemString(PySfKeyType.tp_dict, "LControl", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "LControl", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num8); obj = PyLong_FromLong(sf::Key::Num8);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num8", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num8", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Num9); obj = PyLong_FromLong(sf::Key::Num9);
PyDict_SetItemString(PySfKeyType.tp_dict, "Num9", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Num9", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Tab); obj = PyLong_FromLong(sf::Key::Tab);
PyDict_SetItemString(PySfKeyType.tp_dict, "Tab", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Tab", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::RBracket); obj = PyLong_FromLong(sf::Key::RBracket);
PyDict_SetItemString(PySfKeyType.tp_dict, "RBracket", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "RBracket", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::End); obj = PyLong_FromLong(sf::Key::End);
PyDict_SetItemString(PySfKeyType.tp_dict, "End", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "End", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::BackSlash); obj = PyLong_FromLong(sf::Key::BackSlash);
PyDict_SetItemString(PySfKeyType.tp_dict, "BackSlash", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "BackSlash", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::LShift); obj = PyLong_FromLong(sf::Key::LShift);
PyDict_SetItemString(PySfKeyType.tp_dict, "LShift", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "LShift", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::E); obj = PyLong_FromLong(sf::Key::E);
PyDict_SetItemString(PySfKeyType.tp_dict, "E", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "E", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::C); obj = PyLong_FromLong(sf::Key::C);
PyDict_SetItemString(PySfKeyType.tp_dict, "C", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "C", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::G); obj = PyLong_FromLong(sf::Key::G);
PyDict_SetItemString(PySfKeyType.tp_dict, "G", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "G", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::K); obj = PyLong_FromLong(sf::Key::K);
PyDict_SetItemString(PySfKeyType.tp_dict, "K", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "K", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Up); obj = PyLong_FromLong(sf::Key::Up);
PyDict_SetItemString(PySfKeyType.tp_dict, "Up", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Up", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::O); obj = PyLong_FromLong(sf::Key::O);
PyDict_SetItemString(PySfKeyType.tp_dict, "O", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "O", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::S); obj = PyLong_FromLong(sf::Key::S);
PyDict_SetItemString(PySfKeyType.tp_dict, "S", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "S", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::W); obj = PyLong_FromLong(sf::Key::W);
PyDict_SetItemString(PySfKeyType.tp_dict, "W", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "W", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F12); obj = PyLong_FromLong(sf::Key::F12);
PyDict_SetItemString(PySfKeyType.tp_dict, "F12", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F12", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F13); obj = PyLong_FromLong(sf::Key::F13);
PyDict_SetItemString(PySfKeyType.tp_dict, "F13", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F13", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F10); obj = PyLong_FromLong(sf::Key::F10);
PyDict_SetItemString(PySfKeyType.tp_dict, "F10", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F10", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F11); obj = PyLong_FromLong(sf::Key::F11);
PyDict_SetItemString(PySfKeyType.tp_dict, "F11", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F11", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F14); obj = PyLong_FromLong(sf::Key::F14);
PyDict_SetItemString(PySfKeyType.tp_dict, "F14", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F14", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Delete); obj = PyLong_FromLong(sf::Key::Delete);
PyDict_SetItemString(PySfKeyType.tp_dict, "Delete", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Delete", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Back); obj = PyLong_FromLong(sf::Key::Back);
PyDict_SetItemString(PySfKeyType.tp_dict, "Back", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Back", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Tilde); obj = PyLong_FromLong(sf::Key::Tilde);
PyDict_SetItemString(PySfKeyType.tp_dict, "Tilde", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Tilde", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Home); obj = PyLong_FromLong(sf::Key::Home);
PyDict_SetItemString(PySfKeyType.tp_dict, "Home", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Home", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Pause); obj = PyLong_FromLong(sf::Key::Pause);
PyDict_SetItemString(PySfKeyType.tp_dict, "Pause", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Pause", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Add); obj = PyLong_FromLong(sf::Key::Add);
PyDict_SetItemString(PySfKeyType.tp_dict, "Add", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Add", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F15); obj = PyLong_FromLong(sf::Key::F15);
PyDict_SetItemString(PySfKeyType.tp_dict, "F15", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F15", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Subtract); obj = PyLong_FromLong(sf::Key::Subtract);
PyDict_SetItemString(PySfKeyType.tp_dict, "Subtract", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Subtract", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::B); obj = PyLong_FromLong(sf::Key::B);
PyDict_SetItemString(PySfKeyType.tp_dict, "B", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "B", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F); obj = PyLong_FromLong(sf::Key::F);
PyDict_SetItemString(PySfKeyType.tp_dict, "F", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::J); obj = PyLong_FromLong(sf::Key::J);
PyDict_SetItemString(PySfKeyType.tp_dict, "J", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "J", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::N); obj = PyLong_FromLong(sf::Key::N);
PyDict_SetItemString(PySfKeyType.tp_dict, "N", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "N", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::LBracket); obj = PyLong_FromLong(sf::Key::LBracket);
PyDict_SetItemString(PySfKeyType.tp_dict, "LBracket", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "LBracket", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::R); obj = PyLong_FromLong(sf::Key::R);
PyDict_SetItemString(PySfKeyType.tp_dict, "R", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "R", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::V); obj = PyLong_FromLong(sf::Key::V);
PyDict_SetItemString(PySfKeyType.tp_dict, "V", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "V", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::LSystem); obj = PyLong_FromLong(sf::Key::LSystem);
PyDict_SetItemString(PySfKeyType.tp_dict, "LSystem", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "LSystem", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Z); obj = PyLong_FromLong(sf::Key::Z);
PyDict_SetItemString(PySfKeyType.tp_dict, "Z", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Z", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Left); obj = PyLong_FromLong(sf::Key::Left);
PyDict_SetItemString(PySfKeyType.tp_dict, "Left", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Left", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F1); obj = PyLong_FromLong(sf::Key::F1);
PyDict_SetItemString(PySfKeyType.tp_dict, "F1", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F1", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F2); obj = PyLong_FromLong(sf::Key::F2);
PyDict_SetItemString(PySfKeyType.tp_dict, "F2", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F2", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F3); obj = PyLong_FromLong(sf::Key::F3);
PyDict_SetItemString(PySfKeyType.tp_dict, "F3", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F3", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F4); obj = PyLong_FromLong(sf::Key::F4);
PyDict_SetItemString(PySfKeyType.tp_dict, "F4", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F4", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Divide); obj = PyLong_FromLong(sf::Key::Divide);
PyDict_SetItemString(PySfKeyType.tp_dict, "Divide", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Divide", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F6); obj = PyLong_FromLong(sf::Key::F6);
PyDict_SetItemString(PySfKeyType.tp_dict, "F6", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F6", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F7); obj = PyLong_FromLong(sf::Key::F7);
PyDict_SetItemString(PySfKeyType.tp_dict, "F7", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F7", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F8); obj = PyLong_FromLong(sf::Key::F8);
PyDict_SetItemString(PySfKeyType.tp_dict, "F8", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F8", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::F9); obj = PyLong_FromLong(sf::Key::F9);
PyDict_SetItemString(PySfKeyType.tp_dict, "F9", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "F9", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Period); obj = PyLong_FromLong(sf::Key::Period);
PyDict_SetItemString(PySfKeyType.tp_dict, "Period", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Period", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Down); obj = PyLong_FromLong(sf::Key::Down);
PyDict_SetItemString(PySfKeyType.tp_dict, "Down", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Down", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::PageDown); obj = PyLong_FromLong(sf::Key::PageDown);
PyDict_SetItemString(PySfKeyType.tp_dict, "PageDown", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "PageDown", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Space); obj = PyLong_FromLong(sf::Key::Space);
PyDict_SetItemString(PySfKeyType.tp_dict, "Space", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Space", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Menu); obj = PyLong_FromLong(sf::Key::Menu);
PyDict_SetItemString(PySfKeyType.tp_dict, "Menu", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Menu", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::RControl); obj = PyLong_FromLong(sf::Key::RControl);
PyDict_SetItemString(PySfKeyType.tp_dict, "RControl", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "RControl", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Slash); obj = PyLong_FromLong(sf::Key::Slash);
PyDict_SetItemString(PySfKeyType.tp_dict, "Slash", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Slash", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Return); obj = PyLong_FromLong(sf::Key::Return);
PyDict_SetItemString(PySfKeyType.tp_dict, "Return", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Return", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Quote); obj = PyLong_FromLong(sf::Key::Quote);
PyDict_SetItemString(PySfKeyType.tp_dict, "Quote", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Quote", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::A); obj = PyLong_FromLong(sf::Key::A);
PyDict_SetItemString(PySfKeyType.tp_dict, "A", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "A", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Insert); obj = PyLong_FromLong(sf::Key::Insert);
PyDict_SetItemString(PySfKeyType.tp_dict, "Insert", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Insert", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::RShift); obj = PyLong_FromLong(sf::Key::RShift);
PyDict_SetItemString(PySfKeyType.tp_dict, "RShift", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "RShift", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::I); obj = PyLong_FromLong(sf::Key::I);
PyDict_SetItemString(PySfKeyType.tp_dict, "I", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "I", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Escape); obj = PyLong_FromLong(sf::Key::Escape);
PyDict_SetItemString(PySfKeyType.tp_dict, "Escape", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Escape", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::M); obj = PyLong_FromLong(sf::Key::M);
PyDict_SetItemString(PySfKeyType.tp_dict, "M", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "M", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Equal); obj = PyLong_FromLong(sf::Key::Equal);
PyDict_SetItemString(PySfKeyType.tp_dict, "Equal", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Equal", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Q); obj = PyLong_FromLong(sf::Key::Q);
PyDict_SetItemString(PySfKeyType.tp_dict, "Q", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Q", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::U); obj = PyLong_FromLong(sf::Key::U);
PyDict_SetItemString(PySfKeyType.tp_dict, "U", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "U", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Y); obj = PyLong_FromLong(sf::Key::Y);
PyDict_SetItemString(PySfKeyType.tp_dict, "Y", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Y", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Dash); obj = PyLong_FromLong(sf::Key::Dash);
PyDict_SetItemString(PySfKeyType.tp_dict, "Dash", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Dash", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::Comma); obj = PyLong_FromLong(sf::Key::Comma);
PyDict_SetItemString(PySfKeyType.tp_dict, "Comma", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "Comma", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Key::LAlt); obj = PyLong_FromLong(sf::Key::LAlt);
PyDict_SetItemString(PySfKeyType.tp_dict, "LAlt", obj); PyDict_SetItemString(PySfKeyType.tp_dict, "LAlt", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View File

@ -25,6 +25,14 @@
#ifndef __PYKEY_HPP #ifndef __PYKEY_HPP
#define __PYKEY_HPP #define __PYKEY_HPP
#include <Python.h>
#include <SFML/Window/Event.hpp>
typedef struct {
PyObject_HEAD
} PySfKey;
void void
PySfKey_InitConst(); PySfKey_InitConst();

View File

@ -24,32 +24,24 @@
#include "Music.hpp" #include "Music.hpp"
#include "compat.hpp"
extern PyTypeObject PySfSoundStreamType; extern PyTypeObject PySfSoundStreamType;
static PyMemberDef PySfMusic_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfMusic_dealloc(PySfMusic *self) PySfMusic_dealloc(PySfMusic *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfMusic_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfMusic_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfMusic *self; PySfMusic *self;
self = (PySfMusic *)type->tp_alloc(type, 0); self = (PySfMusic *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -58,11 +50,16 @@ static int
PySfMusic_init(PySfMusic *self, PyObject *args, PyObject *kwds) PySfMusic_init(PySfMusic *self, PyObject *args, PyObject *kwds)
{ {
unsigned int BufferSize=44100; unsigned int BufferSize=44100;
if (PyTuple_Size(args) == 1) int size = PyTuple_Size(args);
if (size == 1)
{ {
if ( !PyArg_ParseTuple(args, "I", &BufferSize)) if ( !PyArg_ParseTuple(args, "I:Music.Init", &BufferSize))
return -1; return -1;
} }
else if (size > 1)
{
PyErr_SetString(PyExc_TypeError, "Music.__init__() takes at most one argument");
}
self->obj = new sf::Music(BufferSize); self->obj = new sf::Music(BufferSize);
return 0; return 0;
} }
@ -73,23 +70,29 @@ PySfMusic_OpenFromMemory(PySfMusic *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#:Music.OpenFromMemory", &Data, &SizeInBytes))
return NULL; return NULL;
if (self->obj->OpenFromMemory(Data, (std::size_t) SizeInBytes)) return PyBool_FromLong(self->obj->OpenFromMemory(Data, (std::size_t) SizeInBytes));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
PySfMusic_OpenFromFile(PySfMusic *self, PyObject *args) PySfMusic_OpenFromFile(PySfMusic *self, PyObject *args)
{ {
char *path = PyString_AsString(args); char *path;
if (self->obj->OpenFromFile(path)) #ifdef IS_PY3K
Py_RETURN_TRUE; PyObject *string = PyUnicode_AsUTF8String(args);
else if (string == NULL)
Py_RETURN_FALSE; return NULL;
path = PyBytes_AsString(string);
#else
path = PyString_AsString(args);
#endif
bool result = self->obj->OpenFromFile(path);
#ifdef IS_PY3K
Py_DECREF(string);
#endif
return PyBool_FromLong(result);
} }
static PyObject* static PyObject*
@ -108,8 +111,7 @@ static PyMethodDef PySfMusic_methods[] = {
PyTypeObject PySfMusicType = { PyTypeObject PySfMusicType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Music", /*tp_name*/ "Music", /*tp_name*/
sizeof(PySfMusic), /*tp_basicsize*/ sizeof(PySfMusic), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -129,7 +131,9 @@ PyTypeObject PySfMusicType = {
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"sf.Music defines a big sound played using streaming, so usually what we call a music :)", /* tp_doc */ "sf.Music defines a big sound played using streaming, so usually what we call a music :).\n\
Constructor: sf.Music(BufferSize=44100)\n\
BufferSize : Size of the internal buffer, expressed in number of samples (ie. size taken by the music in memory) (44100 by default)", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
@ -137,7 +141,7 @@ PyTypeObject PySfMusicType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfMusic_methods, /* tp_methods */ PySfMusic_methods, /* tp_methods */
PySfMusic_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PySfSoundStreamType, /* tp_base */ &PySfSoundStreamType, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View File

@ -25,13 +25,9 @@
#ifndef __PYMUSIC_HPP #ifndef __PYMUSIC_HPP
#define __PYMUSIC_HPP #define __PYMUSIC_HPP
#include <SFML/Audio/Music.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include <SFML/Audio/Music.hpp>
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View File

@ -22,69 +22,75 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "PostFX.hpp" #include "PostFX.hpp"
#include "Drawable.hpp"
#include "Image.hpp"
#include "compat.hpp"
extern PyTypeObject PySfImageType; extern PyTypeObject PySfImageType;
extern PyTypeObject PySfDrawableType; extern PyTypeObject PySfDrawableType;
static PyMemberDef PySfPostFX_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfPostFX_dealloc(PySfPostFX *self) PySfPostFX_dealloc(PySfPostFX *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfPostFX_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfPostFX_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfPostFX *self; PySfPostFX *self;
self = (PySfPostFX *)type->tp_alloc(type, 0); self = (PySfPostFX *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static PyObject * static PyObject *
PySfPostFX_LoadFromFile (PySfPostFX *self, PyObject *args) PySfPostFX_LoadFromFile (PySfPostFX *self, PyObject *args)
{ {
if (self->obj->LoadFromFile(PyString_AsString(args))) char *path;
Py_RETURN_TRUE; #ifdef IS_PY3K
else PyObject *string = PyUnicode_AsUTF8String(args);
Py_RETURN_FALSE; 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)
{ {
if (self->obj->LoadFromMemory(PyString_AsString(args))) char *path;
Py_RETURN_TRUE; #ifdef IS_PY3K
else PyObject *string = PyUnicode_AsUTF8String(args);
Py_RETURN_FALSE; if (string == NULL)
return NULL;
path = PyBytes_AsString(string);
#else
path = PyString_AsString(args);
#endif
bool result = self->obj->LoadFromMemory(path);
#ifdef IS_PY3K
Py_DECREF(string);
#endif
return PyBool_FromLong(result);
} }
static int static int
PySfPostFX_init(PySfPostFX *self, PyObject *args); PySfPostFX_init(PySfPostFX *self, PyObject *args);
static PyObject * static PyObject * PySfPostFX_SetParameter(PySfPostFX* self, PyObject *args) { char *Name; float X, Y, Z, W; int size = PyTuple_Size(args); if (!PyArg_ParseTuple(args, "sf|fff:PostFX.SetParameter", &Name, &X, &Y, &Z, &W)) return NULL;
PySfPostFX_SetParameter(PySfPostFX* self, PyObject *args)
{
char *Name;
float X, Y, Z, W;
int size = PyTuple_Size(args);
if (! PyArg_ParseTuple(args, "sf|fff", &Name, &X, &Y, &Z, &W))
return NULL;
switch (size) switch (size)
{ {
@ -120,7 +126,7 @@ PySfPostFX_SetTexture(PySfPostFX* self, PyObject *args)
{ {
if (!PyObject_TypeCheck(Image, &PySfImageType)) if (!PyObject_TypeCheck(Image, &PySfImageType))
{ {
PyErr_SetString(PyExc_TypeError, "Argument 2, if specified, must be a sf.Image instance or None."); PyErr_SetString(PyExc_TypeError, "PostFX.SetTexture() Argument 2, if specified, must be a sf.Image instance or None.");
return NULL; return NULL;
} }
self->obj->SetTexture(Name, Image->obj); self->obj->SetTexture(Name, Image->obj);
@ -131,10 +137,7 @@ PySfPostFX_SetTexture(PySfPostFX* self, PyObject *args)
static PyObject * static PyObject *
PySfPostFX_CanUsePostFX(PySfPostFX* self, PyObject *args) PySfPostFX_CanUsePostFX(PySfPostFX* self, PyObject *args)
{ {
if (sf::PostFX::CanUsePostFX()) return PyBool_FromLong(sf::PostFX::CanUsePostFX());
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
@ -152,8 +155,7 @@ static PyMethodDef PySfPostFX_methods[] = {
}; };
PyTypeObject PySfPostFXType = { PyTypeObject PySfPostFXType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"PostFX", /*tp_name*/ "PostFX", /*tp_name*/
sizeof(PySfPostFX), /*tp_basicsize*/ sizeof(PySfPostFX), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -173,7 +175,9 @@ PyTypeObject PySfPostFXType = {
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"sf.PostFX is used to apply a post effect to a window. ", /* tp_doc */ "sf.PostFX is used to apply a post effect to a window.\n\
Default constructor : sf.PostFX()\n\
Copy constructor : sf.PostFX(Copy) where Copy is a sf.PostFX instance.", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
@ -181,7 +185,7 @@ PyTypeObject PySfPostFXType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfPostFX_methods, /* tp_methods */ PySfPostFX_methods, /* tp_methods */
PySfPostFX_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PySfDrawableType, /* tp_base */ &PySfDrawableType, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View File

@ -25,14 +25,9 @@
#ifndef __PYPOSTFX_HPP #ifndef __PYPOSTFX_HPP
#define __PYPOSTFX_HPP #define __PYPOSTFX_HPP
#include <SFML/Graphics/PostFX.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "Drawable.hpp" #include <SFML/Graphics/PostFX.hpp>
#include "Image.hpp"
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View File

@ -24,6 +24,12 @@
#include "Rect.hpp" #include "Rect.hpp"
#include <structmember.h>
#include "compat.hpp"
#include "offsetof.hpp"
static PyMemberDef PySfIntRect_members[] = { static PyMemberDef PySfIntRect_members[] = {
{(char *)"Left", T_INT, offsetof(PySfIntRect, Left), 0, (char *)"Left coordinate of the rectangle."}, {(char *)"Left", T_INT, offsetof(PySfIntRect, Left), 0, (char *)"Left coordinate of the rectangle."},
{(char *)"Top", T_INT, offsetof(PySfIntRect, Top), 0, (char *)"Top coordinate of the rectangle."}, {(char *)"Top", T_INT, offsetof(PySfIntRect, Top), 0, (char *)"Top coordinate of the rectangle."},
@ -44,26 +50,21 @@ static void
PySfIntRect_dealloc(PySfIntRect* self) PySfIntRect_dealloc(PySfIntRect* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static void static void
PySfFloatRect_dealloc(PySfFloatRect* self) PySfFloatRect_dealloc(PySfFloatRect* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfIntRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfIntRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfIntRect *self; PySfIntRect *self;
self = (PySfIntRect *)type->tp_alloc(type, 0); self = (PySfIntRect *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -71,12 +72,7 @@ static PyObject *
PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfFloatRect *self; PySfFloatRect *self;
self = (PySfFloatRect *)type->tp_alloc(type, 0); self = (PySfFloatRect *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -86,7 +82,7 @@ PySfIntRect_init(PySfIntRect *self, PyObject *args, PyObject *kwds)
const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL}; const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
int Left, Top, Right, Bottom; int Left, Top, Right, Bottom;
if (! PyArg_ParseTupleAndKeywords(args, kwds, "iiii", (char **)kwlist, &Left, &Top, &Right, &Bottom)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiii:IntRect.__init__", (char **)kwlist, &Left, &Top, &Right, &Bottom))
return -1; return -1;
self->Left = Left; self->Left = Left;
@ -101,14 +97,14 @@ static PyObject *
PySfIntRect_GetWidth(PySfIntRect *self) PySfIntRect_GetWidth(PySfIntRect *self)
{ {
PySfIntRectUpdateObj(self); PySfIntRectUpdateObj(self);
return PyInt_FromLong(self->obj->GetWidth()); return PyLong_FromLong(self->obj->GetWidth());
} }
static PyObject * static PyObject *
PySfIntRect_GetHeight(PySfIntRect *self) PySfIntRect_GetHeight(PySfIntRect *self)
{ {
PySfIntRectUpdateObj(self); PySfIntRectUpdateObj(self);
return PyInt_FromLong(self->obj->GetHeight()); return PyLong_FromLong(self->obj->GetHeight());
} }
static PyObject * static PyObject *
@ -143,7 +139,7 @@ PySfFloatRect_init(PySfFloatRect *self, PyObject *args, PyObject *kwds)
const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL}; const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
float Left, Top, Right, Bottom; float Left, Top, Right, Bottom;
if (! PyArg_ParseTupleAndKeywords(args, kwds, "ffff", (char **)kwlist, &Left, &Top, &Right, &Bottom)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffff:FloatRect.__init__", (char **)kwlist, &Left, &Top, &Right, &Bottom))
return -1; return -1;
self->Left = Left; self->Left = Left;
@ -160,7 +156,7 @@ PySfIntRect_Offset(PySfIntRect* self, PyObject *args)
{ {
int OffsetX, OffsetY; int OffsetX, OffsetY;
if (!PyArg_ParseTuple(args, "ii", &OffsetX, &OffsetY)) if (!PyArg_ParseTuple(args, "ii:IntRect.Offset", &OffsetX, &OffsetY))
return NULL; return NULL;
PySfIntRectUpdateObj(self); PySfIntRectUpdateObj(self);
@ -174,7 +170,7 @@ PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args)
{ {
float OffsetX, OffsetY; float OffsetX, OffsetY;
if (!PyArg_ParseTuple(args, "ff", &OffsetX, &OffsetY)) if (!PyArg_ParseTuple(args, "ff:FloatRect.Offset", &OffsetX, &OffsetY))
return NULL; return NULL;
PySfFloatRectUpdateObj(self); PySfFloatRectUpdateObj(self);
@ -228,8 +224,7 @@ Check intersection between two rectangles.\n\
}; };
PyTypeObject PySfIntRectType = { PyTypeObject PySfIntRectType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"IntRect", /*tp_name*/ "IntRect", /*tp_name*/
sizeof(PySfIntRect), /*tp_basicsize*/ sizeof(PySfIntRect), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -271,8 +266,7 @@ PyTypeObject PySfIntRectType = {
PyTypeObject PySfFloatRectType = { PyTypeObject PySfFloatRectType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"FloatRect", /*tp_name*/ "FloatRect", /*tp_name*/
sizeof(PySfFloatRect), /*tp_basicsize*/ sizeof(PySfFloatRect), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -318,14 +312,11 @@ PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args)
{ {
float x=0, y=0; float x=0, y=0;
if (! PyArg_ParseTuple(args, "ff", &x, &y)) if (!PyArg_ParseTuple(args, "ff:FloatRect.Contains", &x, &y))
return NULL; return NULL;
PySfFloatRectUpdateObj(self); PySfFloatRectUpdateObj(self);
if (self->obj->Contains(x,y)) return PyBool_FromLong(self->obj->Contains(x,y));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
@ -334,8 +325,7 @@ PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args)
PySfFloatRect *Rect=NULL, *OverlappingRect=NULL; PySfFloatRect *Rect=NULL, *OverlappingRect=NULL;
bool result; bool result;
if (!PyArg_ParseTuple(args, "O!|O!:FloatRect.Intersects", &PySfFloatRectType, &Rect, &PySfFloatRectType, &OverlappingRect))
if (! PyArg_ParseTuple(args, "O!|O!", &PySfFloatRectType, &Rect, &PySfFloatRectType, &OverlappingRect))
return NULL; return NULL;
PySfFloatRectUpdateObj(self); PySfFloatRectUpdateObj(self);
@ -344,10 +334,7 @@ PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args)
else else
result = self->obj->Intersects(*(Rect->obj)); result = self->obj->Intersects(*(Rect->obj));
if (result) return PyBool_FromLong(result);
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
@ -357,13 +344,10 @@ PySfIntRect_Contains(PySfIntRect* self, PyObject *args)
unsigned int x=0, y=0; unsigned int x=0, y=0;
PySfIntRectUpdateObj(self); PySfIntRectUpdateObj(self);
if (! PyArg_ParseTuple(args, "II", &x, &y)) if (!PyArg_ParseTuple(args, "II:IntRect.Contains", &x, &y))
return NULL; return NULL;
if (self->obj->Contains(x,y)) return PyBool_FromLong(self->obj->Contains(x,y));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
@ -373,7 +357,7 @@ PySfIntRect_Intersects(PySfIntRect* self, PyObject *args)
bool result; bool result;
PySfIntRectUpdateObj(self); PySfIntRectUpdateObj(self);
if (! PyArg_ParseTuple(args, "O!|O!", &PySfIntRectType, &Rect, &PySfIntRectType, &OverlappingRect)) if (!PyArg_ParseTuple(args, "O!|O!:IntRect.Intersects", &PySfIntRectType, &Rect, &PySfIntRectType, &OverlappingRect))
return NULL; return NULL;
if (OverlappingRect) if (OverlappingRect)
@ -381,10 +365,7 @@ PySfIntRect_Intersects(PySfIntRect* self, PyObject *args)
else else
result = self->obj->Intersects(*(Rect->obj)); result = self->obj->Intersects(*(Rect->obj));
if (result) return PyBool_FromLong(result);
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
void void

View File

@ -25,14 +25,9 @@
#ifndef __PYRECT_HPP #ifndef __PYRECT_HPP
#define __PYRECT_HPP #define __PYRECT_HPP
#include <Python.h>
#include <SFML/Graphics/Rect.hpp> #include <SFML/Graphics/Rect.hpp>
#include <iostream>
#include <Python.h>
#include <structmember.h>
#include "offsetof.hpp"
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View File

@ -25,33 +25,26 @@
#include "RenderTarget.hpp" #include "RenderTarget.hpp"
#include "Color.hpp" #include "Color.hpp"
#include "View.hpp" #include "View.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType; extern PyTypeObject PySfColorType;
extern PyTypeObject PySfViewType; extern PyTypeObject PySfViewType;
static PyMemberDef PySfRenderTarget_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfRenderTarget_dealloc(PySfRenderTarget *self) PySfRenderTarget_dealloc(PySfRenderTarget *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfRenderTarget_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfRenderTarget_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfRenderTarget *self; PySfRenderTarget *self;
self = (PySfRenderTarget *)type->tp_alloc(type, 0); self = (PySfRenderTarget *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -62,11 +55,8 @@ PySfRenderTarget_Clear(PySfRenderTarget *self, PyObject *args)
int size = PyTuple_Size(args); int size = PyTuple_Size(args);
if (size == 1) if (size == 1)
{ {
if (! PyArg_ParseTuple(args, "O!", &PySfColorType, &Color)) if (!PyArg_ParseTuple(args, "O!:RenderTarget.Clear", &PySfColorType, &Color))
{
PyErr_SetString(PyExc_TypeError, "Argument is not a sf.Color");
return NULL; return NULL;
}
PySfColorUpdate(Color); PySfColorUpdate(Color);
self->obj->Clear(*(Color->obj)); self->obj->Clear(*(Color->obj));
} }
@ -97,9 +87,7 @@ PySfRenderTarget_GetView(PySfRenderTarget *self)
static PyObject * static PyObject *
PySfRenderTarget_PreserveOpenGLStates(PySfRenderTarget *self, PyObject *args) PySfRenderTarget_PreserveOpenGLStates(PySfRenderTarget *self, PyObject *args)
{ {
bool Optimize = false; bool Optimize = PyBool_AsBool(args);
if (PyObject_IsTrue(args))
Optimize = true;
self->obj->PreserveOpenGLStates(Optimize); self->obj->PreserveOpenGLStates(Optimize);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -108,9 +96,9 @@ static PyObject *
PySfRenderTarget_SetView(PySfRenderTarget* self, PyObject *args) PySfRenderTarget_SetView(PySfRenderTarget* self, PyObject *args)
{ {
PySfView *View = (PySfView *)args; PySfView *View = (PySfView *)args;
if (! PyObject_TypeCheck(View, &PySfViewType)) if (!PyObject_TypeCheck(View, &PySfViewType))
{ {
PyErr_SetString(PyExc_TypeError, "Argument is not a sf.View"); PyErr_SetString(PyExc_TypeError, "RenderTarget.SetView() Argument is not a sf.View");
return NULL; return NULL;
} }
self->obj->SetView( *(View->obj)); self->obj->SetView( *(View->obj));
@ -146,8 +134,7 @@ Change the current active view. View must be a sf.View instance."},
}; };
PyTypeObject PySfRenderTargetType = { PyTypeObject PySfRenderTargetType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"RenderTarget", /*tp_name*/ "RenderTarget", /*tp_name*/
sizeof(PySfRenderTarget), /*tp_basicsize*/ sizeof(PySfRenderTarget), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -175,14 +162,14 @@ PyTypeObject PySfRenderTargetType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfRenderTarget_methods, /* tp_methods */ PySfRenderTarget_methods, /* tp_methods */
PySfRenderTarget_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 */
0, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PySfRenderTarget_new, /* tp_new */ PySfRenderTarget_new, /* tp_new */
}; };

View File

@ -25,12 +25,9 @@
#ifndef __PYRENDERTARGET_H #ifndef __PYRENDERTARGET_H
#define __PYRENDERTARGET_H #define __PYRENDERTARGET_H
#include <SFML/Graphics/RenderTarget.hpp>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include <iostream> #include <SFML/Graphics/RenderTarget.hpp>
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View File

@ -23,7 +23,6 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "RenderWindow.hpp" #include "RenderWindow.hpp"
#include "Event.hpp" #include "Event.hpp"
#include "VideoMode.hpp" #include "VideoMode.hpp"
#include "Drawable.hpp" #include "Drawable.hpp"
@ -31,9 +30,12 @@
#include "Rect.hpp" #include "Rect.hpp"
#include "View.hpp" #include "View.hpp"
#include "Image.hpp" #include "Image.hpp"
#include "Window.hpp" #include "Window.hpp"
#include "WindowSettings.hpp"
#include "compat.hpp"
#include "SFML/Window/WindowStyle.hpp" #include <SFML/Window/WindowStyle.hpp>
extern PyTypeObject PySfEventType; extern PyTypeObject PySfEventType;
@ -43,31 +45,21 @@ extern PyTypeObject PySfWindowType;
extern PyTypeObject PySfWindowSettingsType; extern PyTypeObject PySfWindowSettingsType;
extern PyTypeObject PySfVideoModeType; extern PyTypeObject PySfVideoModeType;
extern PyTypeObject PySfDrawableType; extern PyTypeObject PySfDrawableType;
extern PyTypeObject PySfRenderTargetType; extern PyTypeObject PySfRenderTargetType;
static PyMemberDef PySfRenderWindow_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfRenderWindow_dealloc(PySfRenderWindow* self) PySfRenderWindow_dealloc(PySfRenderWindow* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfRenderWindow *self; PySfRenderWindow *self;
self = (PySfRenderWindow *)type->tp_alloc(type, 0); self = (PySfRenderWindow *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -76,7 +68,8 @@ PySfRenderWindow_init(PySfRenderWindow *self, PyObject *args, PyObject *kwds)
{ {
self->obj = new sf::RenderWindow(); self->obj = new sf::RenderWindow();
if (PyTuple_Size(args) > 0) if (PyTuple_Size(args) > 0)
PySfWindow_Create((PySfWindow *)self, args, kwds); if (PySfWindow_Create((PySfWindow *)self, args, kwds) == NULL)
return -1;
return 0; return 0;
} }
@ -98,7 +91,7 @@ PySfRenderWindow_ConvertCoords(PySfRenderWindow *self, PyObject *args)
sf::View *TargetView = NULL; sf::View *TargetView = NULL;
sf::Vector2f Vect; sf::Vector2f Vect;
if (! PyArg_ParseTuple(args, "II|O!", &WindowX, &WindowY, &PySfViewType, &PyTargetView)) if (!PyArg_ParseTuple(args, "II|O!:RenderWindow.ConvertCoords", &WindowX, &WindowY, &PySfViewType, &PyTargetView))
return NULL; return NULL;
if (PyTargetView) if (PyTargetView)
@ -154,9 +147,8 @@ PySfRenderWindow_Draw(PySfRenderWindow *self, PyObject *args)
Py_DECREF(iterator); Py_DECREF(iterator);
if (PyErr_Occurred()) { if (PyErr_Occurred())
return NULL; return NULL;
}
} }
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -175,8 +167,7 @@ Draw something on the window. The argument can be a drawable or any object suppo
}; };
PyTypeObject PySfRenderWindowType = { PyTypeObject PySfRenderWindowType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"RenderWindow", /*tp_name*/ "RenderWindow", /*tp_name*/
sizeof(PySfRenderWindow), /*tp_basicsize*/ sizeof(PySfRenderWindow), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -196,7 +187,14 @@ PyTypeObject PySfRenderWindowType = {
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Simple wrapper for sf.Window that allows easy 2D rendering.", /* tp_doc */ "Simple wrapper for sf.Window that allows easy 2D rendering.\n\
Default constructor : sf.RenderWindow()\n\
Other constructor : sf.RenderWindow(Mode, Title, Style::Resize|Style::Close, Params = WindowSettings())\n\
Parameters:\n\
Mode : Video mode to use\n\
Title : Title of the window\n\
WindowStyle : Window style (Resize | Close by default)\n\
Params : Creation parameters (see default constructor for default values)", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
@ -204,7 +202,7 @@ PyTypeObject PySfRenderWindowType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfRenderWindow_methods, /* tp_methods */ PySfRenderWindow_methods, /* tp_methods */
PySfRenderWindow_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View File

@ -25,13 +25,9 @@
#ifndef __PYRENDERWINDOW_HPP #ifndef __PYRENDERWINDOW_HPP
#define __PYRENDERWINDOW_HPP #define __PYRENDERWINDOW_HPP
#include <SFML/Graphics.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "WindowSettings.hpp" #include <SFML/Graphics.hpp>
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View File

@ -25,11 +25,9 @@
#ifndef __PYSLEEP_HPP #ifndef __PYSLEEP_HPP
#define __PYSLEEP_HPP #define __PYSLEEP_HPP
#include <SFML/System/Sleep.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include <SFML/System/Sleep.hpp>
PyObject * PyObject *
PySFML_Sleep (PyObject *self, PyObject *args); PySFML_Sleep (PyObject *self, PyObject *args);

View File

@ -22,7 +22,12 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "Sprite.hpp" #include "Sprite.hpp"
#include "Drawable.hpp"
#include "Rect.hpp"
#include "Color.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType; extern PyTypeObject PySfColorType;
@ -30,19 +35,16 @@ extern PyTypeObject PySfImageType;
extern PyTypeObject PySfIntRectType; extern PyTypeObject PySfIntRectType;
extern PyTypeObject PySfDrawableType; extern PyTypeObject PySfDrawableType;
static PyMemberDef PySfSprite_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfSprite_dealloc(PySfSprite *self) PySfSprite_dealloc(PySfSprite *self)
{ {
if (self->Image != NULL) if (self->Image != NULL)
Py_DECREF(self->Image); {
Py_DECREF(self->Image);
}
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
@ -69,7 +71,7 @@ PySfSprite_init(PySfSprite *self, PyObject *args, PyObject *kwds)
PySfImage *Image=NULL; PySfImage *Image=NULL;
PySfColor *Color=NULL; PySfColor *Color=NULL;
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!|fffffO!", (char **)kwlist, &PySfImageType, &Image, &X, &Y, &ScaleX, &ScaleY, &Rotation, &PySfColorType, &Color)) if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!|fffffO!:Sprite.__init__", (char **)kwlist, &PySfImageType, &Image, &X, &Y, &ScaleX, &ScaleY, &Rotation, &PySfColorType, &Color))
return -1; return -1;
Py_INCREF(Image); Py_INCREF(Image);
@ -79,7 +81,6 @@ PySfSprite_init(PySfSprite *self, PyObject *args, PyObject *kwds)
else else
self->obj = new sf::Sprite(*(Image->obj), sf::Vector2f(X, Y), sf::Vector2f(ScaleX, ScaleY), Rotation); self->obj = new sf::Sprite(*(Image->obj), sf::Vector2f(X, Y), sf::Vector2f(ScaleX, ScaleY), Rotation);
return 0; return 0;
} }
@ -91,7 +92,7 @@ PySfSprite_SetImage(PySfSprite* self, PyObject *args)
PySfImage *Image = (PySfImage *)args; PySfImage *Image = (PySfImage *)args;
if (! PyObject_TypeCheck(Image, &PySfImageType)) if (! PyObject_TypeCheck(Image, &PySfImageType))
{ {
PyErr_SetString(PyExc_TypeError, "Argument is not a sfImage"); PyErr_SetString(PyExc_TypeError, "Sprite.SetImage() Argument is not a sf.Image");
return NULL; return NULL;
} }
Py_DECREF(self->Image); Py_DECREF(self->Image);
@ -114,8 +115,7 @@ PySfSprite_GetPixel(PySfSprite* self, PyObject *args)
PySfColor *Color; PySfColor *Color;
unsigned int x=0, y=0; unsigned int x=0, y=0;
if (!PyArg_ParseTuple(args, "II:Sprite.GetPixel", &x, &y))
if (! PyArg_ParseTuple(args, "II", &x, &y))
return NULL; return NULL;
Color = GetNewPySfColor(); Color = GetNewPySfColor();
@ -133,7 +133,7 @@ PySfSprite_Resize(PySfSprite* self, PyObject *args)
{ {
float W=0, H=0; float W=0, H=0;
if (! PyArg_ParseTuple(args, "ff", &W, &H)) if (! PyArg_ParseTuple(args, "ff:Sprite.Resize", &W, &H))
return NULL; return NULL;
self->obj->Resize(W,H); self->obj->Resize(W,H);
@ -161,7 +161,7 @@ PySfSprite_SetSubRect(PySfSprite* self, PyObject *args)
PySfIntRect *Rect = (PySfIntRect *)args; PySfIntRect *Rect = (PySfIntRect *)args;
if (! PyObject_TypeCheck(Rect, &PySfIntRectType)) if (! PyObject_TypeCheck(Rect, &PySfIntRectType))
{ {
PyErr_SetString(PyExc_TypeError, "Argument is not a sf.IntRect instance"); PyErr_SetString(PyExc_TypeError, "Sprite.SetSubRect() Argument is not a sf.IntRect instance");
return NULL; return NULL;
} }
self->obj->SetSubRect(*(Rect->obj)); self->obj->SetSubRect(*(Rect->obj));
@ -171,20 +171,14 @@ PySfSprite_SetSubRect(PySfSprite* self, PyObject *args)
static PyObject * static PyObject *
PySfSprite_FlipX(PySfSprite* self, PyObject *args) PySfSprite_FlipX(PySfSprite* self, PyObject *args)
{ {
bool Flip = false; self->obj->FlipX(PyBool_AsBool(args));
if (PyObject_IsTrue(args))
Flip = true;
self->obj->FlipX(Flip);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
PySfSprite_FlipY(PySfSprite* self, PyObject *args) PySfSprite_FlipY(PySfSprite* self, PyObject *args)
{ {
bool Flip = false; self->obj->FlipY(PyBool_AsBool(args));
if (PyObject_IsTrue(args))
Flip = true;
self->obj->FlipY(Flip);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -211,8 +205,7 @@ static PyMethodDef PySfSprite_methods[] = {
}; };
PyTypeObject PySfSpriteType = { PyTypeObject PySfSpriteType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Sprite", /*tp_name*/ "Sprite", /*tp_name*/
sizeof(PySfSprite), /*tp_basicsize*/ sizeof(PySfSprite), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -240,7 +233,7 @@ PyTypeObject PySfSpriteType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfSprite_methods, /* tp_methods */ PySfSprite_methods, /* tp_methods */
PySfSprite_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PySfDrawableType, /* tp_base */ &PySfDrawableType, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View File

@ -25,16 +25,11 @@
#ifndef __PYSPRITE_HPP #ifndef __PYSPRITE_HPP
#define __PYSPRITE_HPP #define __PYSPRITE_HPP
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/Image.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "Drawable.hpp" #include <SFML/Graphics/Sprite.hpp>
#include "Image.hpp" #include "Image.hpp"
#include "Rect.hpp"
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View File

@ -169,7 +169,8 @@ PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds)
{ {
self->obj = new sf::Window(); self->obj = new sf::Window();
if (PyTuple_Size(args) > 0) if (PyTuple_Size(args) > 0)
PySfWindow_Create(self, args, kwds); if (PySfWindow_Create(self, args, kwds) == NULL)
return -1;
return 0; return 0;
} }

42
python/src/compat.hpp Normal file
View File

@ -0,0 +1,42 @@
////////////////////////////////////////////////////////////
//
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef __PYCOMPAT_HPP
#define __PYCOMPAT_HPP
#if PY_MAJOR_VERSION >= 3
#define IS_PY3K
#define head_init PyVarObject_HEAD_INIT(NULL, 0)
#else
#define Py_TYPE(a) a->ob_type
#define head_init PyObject_HEAD_INIT(NULL) 0,
#define PyBytes_FromStringAndSize PyString_FromStringAndSize
#endif
#define free_object(a) Py_TYPE(a)->tp_free((PyObject*)a)
#define PyBool_AsBool(a) ((PyObject_IsTrue(a))?true:false)
#endif

View File

@ -33,7 +33,9 @@
#include "Blend.hpp" #include "Blend.hpp"
#include "Sound.hpp" #include "Sound.hpp"
#include "String.hpp" #include "String.hpp"
#include "SoundStream.hpp" #include "SoundStream.hpp"
#include "compat.hpp"
extern PyTypeObject PySfClockType; extern PyTypeObject PySfClockType;
@ -88,109 +90,129 @@ extern PyTypeObject PySfListenerType;
static PyMethodDef module_methods[] = { static PyMethodDef module_methods[] = {
{"Sleep", (PyCFunction)PySFML_Sleep, METH_O, "Sleep(Duration)\nMake the current thread sleep for a given time.\n Duration : Time to sleep, in seconds"}, {"Sleep", (PyCFunction)PySFML_Sleep, METH_O, "Sleep(Duration)\nMake the current thread sleep for a given time.\n Duration : Time to sleep, in seconds"},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
#ifdef IS_PY3K
#define INITERROR return NULL
static PyModuleDef module_def = {
PyModuleDef_HEAD_INIT,
"noddy",
"Example module that creates an extension type.",
-1,
module_methods, NULL, NULL, NULL, NULL
};
PyObject *
PyInit_sf(void)
#else
#define INITERROR return
#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */ #ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
#define PyMODINIT_FUNC void #define PyMODINIT_FUNC void
#endif #endif
PyMODINIT_FUNC PyMODINIT_FUNC
initsf(void) initsf(void)
#endif
{ {
PyObject *m; PyObject *m;
if (PyType_Ready(&PySfClockType) < 0) if (PyType_Ready(&PySfClockType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfWindowType) < 0) if (PyType_Ready(&PySfWindowType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfWindowSettingsType) < 0) if (PyType_Ready(&PySfWindowSettingsType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfStyleType) < 0) if (PyType_Ready(&PySfStyleType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfRenderTargetType) < 0) if (PyType_Ready(&PySfRenderTargetType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfRenderWindowType) < 0) if (PyType_Ready(&PySfRenderWindowType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfVideoModeType) < 0) if (PyType_Ready(&PySfVideoModeType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfViewType) < 0) if (PyType_Ready(&PySfViewType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfInputType) < 0) if (PyType_Ready(&PySfInputType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventType) < 0) if (PyType_Ready(&PySfEventType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventTextType) < 0) if (PyType_Ready(&PySfEventTextType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventKeyType) < 0) if (PyType_Ready(&PySfEventKeyType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventMouseMoveType) < 0) if (PyType_Ready(&PySfEventMouseMoveType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventMouseButtonType) < 0) if (PyType_Ready(&PySfEventMouseButtonType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventMouseWheelType) < 0) if (PyType_Ready(&PySfEventMouseWheelType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventJoyMoveType) < 0) if (PyType_Ready(&PySfEventJoyMoveType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventJoyButtonType) < 0) if (PyType_Ready(&PySfEventJoyButtonType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfEventSizeType) < 0) if (PyType_Ready(&PySfEventSizeType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfKeyType) < 0) if (PyType_Ready(&PySfKeyType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfJoyType) < 0) if (PyType_Ready(&PySfJoyType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfMouseType) < 0) if (PyType_Ready(&PySfMouseType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfDrawableType) < 0) if (PyType_Ready(&PySfDrawableType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfBlendType) < 0) if (PyType_Ready(&PySfBlendType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfSpriteType) < 0) if (PyType_Ready(&PySfSpriteType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfFontType) < 0) if (PyType_Ready(&PySfFontType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfGlyphType) < 0) if (PyType_Ready(&PySfGlyphType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfStringType) < 0) if (PyType_Ready(&PySfStringType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfPostFXType) < 0) if (PyType_Ready(&PySfPostFXType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfImageType) < 0) if (PyType_Ready(&PySfImageType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfShapeType) < 0) if (PyType_Ready(&PySfShapeType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfColorType) < 0) if (PyType_Ready(&PySfColorType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfIntRectType) < 0) if (PyType_Ready(&PySfIntRectType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfFloatRectType) < 0) if (PyType_Ready(&PySfFloatRectType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfMusicType) < 0) if (PyType_Ready(&PySfMusicType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfSoundType) < 0) if (PyType_Ready(&PySfSoundType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfSoundBufferType) < 0) if (PyType_Ready(&PySfSoundBufferType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfSoundBufferRecorderType) < 0) if (PyType_Ready(&PySfSoundBufferRecorderType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfSoundRecorderType) < 0) if (PyType_Ready(&PySfSoundRecorderType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfSoundStreamType) < 0) if (PyType_Ready(&PySfSoundStreamType) < 0)
return; INITERROR;
if (PyType_Ready(&PySfListenerType) < 0) if (PyType_Ready(&PySfListenerType) < 0)
return; INITERROR;
m = Py_InitModule3("sf", module_methods, "Python binding for sfml (Simple Fast Media Library)"); #ifdef IS_PY3K
m = PyModule_Create(&module_def);
#else
m = Py_InitModule3("sf", module_methods, "Python binding for sfml (Simple Fast Media Library)");
#endif
if (m == NULL) if (m == NULL)
return; INITERROR;
Py_INCREF(&PySfClockType); Py_INCREF(&PySfClockType);
PyModule_AddObject(m, "Clock", (PyObject *)&PySfClockType); PyModule_AddObject(m, "Clock", (PyObject *)&PySfClockType);
@ -274,6 +296,10 @@ initsf(void)
PySfBlend_InitConst(); PySfBlend_InitConst();
PySfSound_InitConst(); PySfSound_InitConst();
PySfSoundStream_InitConst(); PySfSoundStream_InitConst();
PySfString_InitConst(); PySfString_InitConst();
#ifdef IS_PY3K
return m;
#endif
} }