Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: PySFML2  (Read 16094 times)

0 Members and 1 Guest are viewing this topic.

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
PySFML2
« Reply #15 on: April 13, 2010, 08:53:10 am »
I've recently hadn't got the time to keep PySFML synchronized to trunk, so there's probably (a lot of ;)) wrong/missing code in the Python port. Anyways, I'll try to synchronize it ASAP.

Kaoron

  • Full Member
  • ***
  • Posts: 156
    • View Profile
PySFML2
« Reply #16 on: April 13, 2010, 03:31:03 pm »
I didn't work on sf::Renderer, but here is another patch which covers a few renamings since my last post, plus a fix in Window.cpp presented here.

Code: [Select]
Index: src/Shape.cpp
===================================================================
--- src/Shape.cpp (révision 1509)
+++ src/Shape.cpp (copie de travail)
@@ -237,9 +237,9 @@
 }
 
 static PyObject *
-PySfShape_GetNbPoints(PySfShape* self, PyObject *args)
+PySfShape_GetPointsCount(PySfShape* self, PyObject *args)
 {
- return PyLong_FromUnsignedLong(self->obj->GetNbPoints());
+ return PyLong_FromUnsignedLong(self->obj->GetPointsCount());
 }
 
 static PyObject *
@@ -266,18 +266,18 @@
 Get the outline color of a point.\n Index : Index-th point."},
  {"SetPointPosition", (PyCFunction)PySfShape_SetPointPosition, METH_VARARGS, "SetPointPosition(Index, X, Y).\n\
 Set the position of a point\n\
- Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Index : Index of the point, in range [0, GetPointscount() - 1]\n\
  X :     New X coordinate of the Index-th point\n\
  Y :     New Y coordinate of the Index-th point."},
  {"SetPointColor", (PyCFunction)PySfShape_SetPointColor, METH_VARARGS, "SetPointColor(Index, Color).\n\
 Set the color of a point\n\

- Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Index : Index of the point, in range [0, GetPointscount() - 1]\n\
  Col :   New color of the Index-th point."},
  {"SetPointOutlineColor", (PyCFunction)PySfShape_SetPointOutlineColor, METH_VARARGS, "SetPointOutlineColor(Index, Color).\n\
 Set the outline color of a point\n\

- Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Index : Index of the point, in range [0, GetPointscount() - 1]\n\
  Col :   New color of the Index-th point."},
- {"GetNbPoints", (PyCFunction)PySfShape_GetNbPoints, METH_NOARGS, "GetNbPoints()\n\
+ {"GetPointsCount", (PyCFunction)PySfShape_GetPointsCount, METH_NOARGS, "GetPointscount()\n\
 Get the number of points composing the shape."},
  {"EnableFill", (PyCFunction)PySfShape_EnableFill, METH_O, "EnableFill(Enable)\n\
 Enable or disable filling the shape. Fill is enabled by default.\n\Index: src/Glyph.hpp
===================================================================
--- src/Glyph.hpp (révision 1509)
+++ src/Glyph.hpp (copie de travail)
@@ -36,8 +36,8 @@
  PyObject_HEAD
  bool Owner;
  int Advance;
- PySfIntRect *Rectangle;
- PySfFloatRect *TexCoords;
+ PySfIntRect *Bounds;
+ PySfIntRect *SubRect;
  sf::Glyph *obj;
 } PySfGlyph;
 
Index: src/Glyph.cpp
===================================================================
--- src/Glyph.cpp (révision 1509)
+++ src/Glyph.cpp (copie de travail)
@@ -32,8 +32,8 @@
 
 static PyMemberDef PySfGlyph_members[] = {
  {(char *)"Advance", T_INT, offsetof(PySfGlyph, Advance), 0, (char *)"Offset to move horizontically to the next character."},
- {(char *)"Rectangle", T_OBJECT, offsetof(PySfGlyph, Rectangle), 0, (char *)"Bounding rectangle of the glyph, in relative coordinates."},
- {(char *)"TexCoords", T_OBJECT, offsetof(PySfGlyph, TexCoords), 0, (char *)"Texture coordinates of the glyph inside the bitmap font."},
+ {(char *)"Bounds", T_OBJECT, offsetof(PySfGlyph, Bounds), 0, (char *)"Bounding rectangle of the glyph, in coordinates relative to the baseline."},
+ {(char *)"SubRect", T_OBJECT, offsetof(PySfGlyph, SubRect), 0, (char *)"Texture coordinates of the glyph inside the font's image."},
  {NULL}  /* Sentinel */
 };
 
@@ -41,8 +41,8 @@
 static void
 PySfGlyph_dealloc(PySfGlyph *self)
 {
- Py_CLEAR(self->Rectangle);
- Py_CLEAR(self->TexCoords);
+ Py_CLEAR(self->Bounds);
+ Py_CLEAR(self->SubRect);
  delete self->obj;
  free_object(self);
 }
@@ -51,16 +51,16 @@
 PySfGlyphUpdateObj(PySfGlyph *self)
 {
  self->obj->Advance = self->Advance;
- PySfIntRectUpdateSelf(self->Rectangle);
- PySfFloatRectUpdateSelf(self->TexCoords);
+ PySfIntRectUpdateSelf(self->Bounds);
+ PySfIntRectUpdateSelf(self->SubRect);
 }
 
 void
 PySfGlyphUpdateSelf(PySfGlyph *self)
 {
  self->Advance = self->obj->Advance;
- PySfIntRectUpdateObj(self->Rectangle);
- PySfFloatRectUpdateObj(self->TexCoords);
+ PySfIntRectUpdateObj(self->Bounds);
+ PySfIntRectUpdateObj(self->SubRect);
 }
 
 static PyObject *
@@ -70,17 +70,17 @@
  self = (PySfGlyph *)type->tp_alloc(type, 0);
  if (self != NULL)
  {
- self->Rectangle = GetNewPySfIntRect();
- self->Rectangle->Owner = false;
- self->TexCoords = GetNewPySfFloatRect();
- self->TexCoords->Owner = false;
+ self->Bounds = GetNewPySfIntRect();
+ self->Bounds->Owner = false;
+ self->SubRect = GetNewPySfIntRect();
+ self->SubRect->Owner = false;
  self->obj = new sf::Glyph();
  self->Owner = true;
  self->Advance = self->obj->Advance;
- self->Rectangle->obj = &(self->obj->Rectangle);
- self->TexCoords->obj = &(self->obj->TexCoords);
- PySfIntRectUpdateSelf(self->Rectangle);
- PySfFloatRectUpdateSelf(self->TexCoords);
+ self->Bounds->obj = &(self->obj->Bounds);
+ self->SubRect->obj = &(self->obj->SubRect);
+ PySfIntRectUpdateSelf(self->Bounds);
+ PySfIntRectUpdateSelf(self->SubRect);
  }
  return (PyObject *)self;
 }
@@ -90,8 +90,8 @@
 {
  int result = PyObject_GenericSetAttr(self, attr_name, v);
  PySfGlyph *Glyph = (PySfGlyph *)self;
- Glyph->obj->Rectangle = *(Glyph->Rectangle->obj);
- Glyph->obj->TexCoords = *(Glyph->TexCoords->obj);
+ Glyph->obj->Bounds = *(Glyph->Bounds->obj);
+ Glyph->obj->SubRect = *(Glyph->SubRect->obj);
  Glyph->obj->Advance = Glyph->Advance;
  return result;
 }
Index: src/Font.cpp
===================================================================
--- src/Font.cpp (révision 1509)
+++ src/Font.cpp (copie de travail)
@@ -106,14 +106,14 @@
  PySfGlyph*  glyph( GetNewPySfGlyph() );
 
  glyph->Owner = false;
- glyph->Rectangle = GetNewPySfIntRect();
- glyph->Rectangle->Owner = false;
- glyph->TexCoords = GetNewPySfFloatRect();
- glyph->TexCoords->Owner = false;
+ glyph->Bounds = GetNewPySfIntRect();
+ glyph->Bounds->Owner = false;
+ glyph->SubRect = GetNewPySfIntRect();
+ glyph->SubRect->Owner = false;
 
  glyph->obj = const_cast<sf::Glyph*>( &( self->obj->GetGlyph( codepoint, charsize, bold ) ) );
- glyph->Rectangle->obj = &glyph->obj->Rectangle;
- glyph->TexCoords->obj = &glyph->obj->TexCoords;
+ glyph->Bounds->obj = &glyph->obj->Bounds;
+ glyph->SubRect->obj = &glyph->obj->SubRect;
 
  PySfGlyphUpdateSelf( glyph );
 
Index: src/Rect.hpp
===================================================================
--- src/Rect.hpp (révision 1509)
+++ src/Rect.hpp (copie de travail)
@@ -33,9 +33,9 @@
  PyObject_HEAD
  bool Owner;
  int Left;
- int Right;
  int Top;
- int Bottom;
+ int Width;
+ int Height;
  sf::IntRect *obj;
 } PySfIntRect;
 
@@ -43,9 +43,9 @@
  PyObject_HEAD
  bool Owner;
  float Left;
- float Right;
  float Top;
- float Bottom;
+ float Width;
+ float Height;
  sf::FloatRect *obj;
 } PySfFloatRect;

Index: src/Rect.cpp
===================================================================
--- src/Rect.cpp (révision 1509)
+++ src/Rect.cpp (copie de travail)
@@ -33,16 +33,16 @@
 static PyMemberDef PySfIntRect_members[] = {
  {(char *)"Left", T_INT, offsetof(PySfIntRect, Left), 0, (char *)"Left coordinate of the rectangle."},
  {(char *)"Top", T_INT, offsetof(PySfIntRect, Top), 0, (char *)"Top coordinate of the rectangle."},
- {(char *)"Right", T_INT, offsetof(PySfIntRect, Right), 0, (char *)"Right coordinate of the rectangle."},
- {(char *)"Bottom", T_INT, offsetof(PySfIntRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
+ {(char *)"Width", T_INT, offsetof(PySfIntRect, Width), 0, (char *)"Width of the rectangle."},
+ {(char *)"Height", T_INT, offsetof(PySfIntRect, Height), 0, (char *)"Height of the rectangle."},
  {NULL}  /* Sentinel */
 };
 
 static PyMemberDef PySfFloatRect_members[] = {
  {(char *)"Left", T_FLOAT, offsetof(PySfFloatRect, Left), 0, (char *)"Left coordinate of the rectangle."},
  {(char *)"Top", T_FLOAT, offsetof(PySfFloatRect, Top), 0, (char *)"Top coordinate of the rectangle."},
- {(char *)"Right", T_FLOAT, offsetof(PySfFloatRect, Right), 0, (char *)"Right coordinate of the rectangle."},
- {(char *)"Bottom", T_FLOAT, offsetof(PySfFloatRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
+ {(char *)"Width", T_FLOAT, offsetof(PySfFloatRect, Width), 0, (char *)"Width of the rectangle."},
+ {(char *)"Height", T_FLOAT, offsetof(PySfFloatRect, Height), 0, (char *)"Height of the rectangle."},
  {NULL}  /* Sentinel */
 };
 
@@ -65,15 +65,15 @@
 static PyObject *
 PySfIntRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
- const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
+ const char *kwlist[] = {"Left", "Top", "Width", "Height", NULL};
  PySfIntRect *self;
  self = (PySfIntRect *)type->tp_alloc(type, 0);
  if (self != NULL)
  {
  self->Owner = true;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiii:IntRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Right), &(self->Bottom)))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "iiii:IntRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Width), &(self->Height)))
  return NULL;
- self->obj = new sf::IntRect(self->Left, self->Top, self->Right, self->Bottom);
+ self->obj = new sf::IntRect(self->Left, self->Top, self->Width, self->Height);
  }
  return (PyObject *)self;
 }
@@ -81,79 +81,32 @@
 static PyObject *
 PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
 {
- const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
+ const char *kwlist[] = {"Left", "Top", "Width", "Height", NULL};
  PySfFloatRect *self;
  self = (PySfFloatRect *)type->tp_alloc(type, 0);
  if (self != NULL)
  {
  self->Owner = true;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffff:FloatRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Right), &(self->Bottom)))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffff:FloatRect.__new__", (char **)kwlist, &(self->Left), &(self->Top), &(self->Width), &(self->Height)))
  return NULL;
- self->obj = new sf::FloatRect(self->Left, self->Top, self->Right, self->Bottom);
+ self->obj = new sf::FloatRect(self->Left, self->Top, self->Width, self->Height);
  }
  return (PyObject *)self;
 }
 
 static PyObject *
-PySfIntRect_GetSize(PySfIntRect *self)
-{
- sf::Vector2i  size( self->obj->GetSize() );
- return Py_BuildValue( "ii", size.x, size.y );
-}
-
-static PyObject *
 PySfIntRect_Contains(PySfIntRect* self, PyObject *args);
 
 static PyObject *
 PySfIntRect_Intersects(PySfIntRect* self, PyObject *args);
 
 static PyObject *
-PySfFloatRect_GetSize(PySfFloatRect *self)
-{
- sf::Vector2f  size( self->obj->GetSize() );
- return Py_BuildValue( "ff", size.x, size.y );
-}
-
-static PyObject *
 PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args);
 
 static PyObject *
 PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args);
 
-static PyObject *
-PySfIntRect_Offset(PySfIntRect* self, PyObject *args)
-{
- int OffsetX, OffsetY;
-
- if (!PyArg_ParseTuple(args, "ii:IntRect.Offset", &OffsetX, &OffsetY))
- return NULL;
-
- self->obj->Offset(OffsetX, OffsetY);
- PySfIntRectUpdateSelf(self);
- Py_RETURN_NONE;
-}
-
-static PyObject *
-PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args)
-{
- float OffsetX, OffsetY;
-
- if (!PyArg_ParseTuple(args, "ff:FloatRect.Offset", &OffsetX, &OffsetY))
- return NULL;
-
- self->obj->Offset(OffsetX, OffsetY);
- PySfFloatRectUpdateSelf(self);
- Py_RETURN_NONE;
-}
-
-
 static PyMethodDef PySfIntRect_methods[] = {
- {"Offset", (PyCFunction)PySfIntRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
-Move the whole rectangle by the given offset.\n\
- OffsetX : Horizontal offset\n\
- OffsetY : Vertical offset\n\
-"},
- {"GetSize", (PyCFunction)PySfIntRect_GetSize, METH_NOARGS, "GetSize()\nGet the rectangle's size."},
  {"Contains", (PyCFunction)PySfIntRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
 Check if a point is inside the rectangle's area.\n\
  X : X coordinate of the point to test\n\
@@ -167,12 +120,6 @@
 
 
 static PyMethodDef PySfFloatRect_methods[] = {
- {"Offset", (PyCFunction)PySfFloatRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
-Move the whole rectangle by the given offset.\n\
- OffsetX : Horizontal offset\n\
- OffsetY : Vertical offset\n\
-"},
- {"GetSize", (PyCFunction)PySfFloatRect_GetSize, METH_NOARGS, "GetSize()\nGet the rectangle's size."},
  {"Contains", (PyCFunction)PySfFloatRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
 Check if a point is inside the rectangle's area.\n\
  X : X coordinate of the point to test\n\
@@ -347,36 +294,36 @@
 PySfIntRectUpdateObj(PySfIntRect *self)
 {
  self->obj->Left = self->Left;
- self->obj->Right = self->Right;
  self->obj->Top = self->Top;
- self->obj->Bottom = self->Bottom;
+ self->obj->Width = self->Width;
+ self->obj->Height = self->Height;
 }
 
 void
 PySfFloatRectUpdateObj(PySfFloatRect *self)
 {
  self->obj->Left = self->Left;
- self->obj->Right = self->Right;
  self->obj->Top = self->Top;
- self->obj->Bottom = self->Bottom;
+ self->obj->Width = self->Width;
+ self->obj->Height = self->Height;
 }
 
 void
 PySfIntRectUpdateSelf(PySfIntRect *self)
 {
  self->Left = self->obj->Left;
- self->Right = self->obj->Right;
  self->Top = self->obj->Top;
- self->Bottom = self->obj->Bottom;
+ self->Width = self->obj->Width;
+ self->Height = self->obj->Height;
 }
 
 void
 PySfFloatRectUpdateSelf(PySfFloatRect *self)
 {
  self->Left = self->obj->Left;
- self->Right = self->obj->Right;
  self->Top = self->obj->Top;
- self->Bottom = self->obj->Bottom;
+ self->Width = self->obj->Width;
+ self->Height = self->obj->Height;
 }
 
 PySfIntRect *
 


TODO :
- Complete my previous patch with a proper Renderer wrapper
- Fix changes in VideoMode (-GetMode, -GetModesCount, +GetFullscreenModes)
- maybe some other changes I didn't notice

It would also be nice to fix fileformats inconsistencies : some files are unix, some are dos. Newlines are often messed up in patches.

Svenstaro

  • Full Member
  • ***
  • Posts: 222
    • View Profile
PySFML2
« Reply #17 on: July 04, 2010, 09:17:58 pm »
Tank, can you give us an update?

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
PySFML2
« Reply #18 on: July 09, 2010, 08:45:30 am »
Working on it, like said in the other thread. However there're plenty of changes that need to be done, so don't expect it in the next few days. ;)

Pompei2

  • Newbie
  • *
  • Posts: 2
    • View Profile
PySFML2
« Reply #19 on: November 29, 2010, 09:53:46 am »
Any updates on this?

xarxer

  • Newbie
  • *
  • Posts: 35
    • View Profile
PySFML2
« Reply #20 on: December 22, 2010, 01:52:20 am »
I'm also wondering if it'll work soon :)

Tank

  • SFML Team
  • Hero Member
  • *****
  • Posts: 1486
    • View Profile
    • Blog
    • Email
PySFML2
« Reply #21 on: January 04, 2011, 09:02:41 am »
There won't be any updates on the current PySFML implementation (that one programmed against the raw Python C API) as far as I am concerned.

There's a thread in here in which at least one user was fiddling around with Cython, but I don't know if that guy's still at work.

If not, I will continue my work on PySFML 2, because currently it's rather chaotic and not really maintained -- time to change that. :)