mirror of
https://github.com/SFML/SFML.git
synced 2024-11-28 22:31:09 +08:00
Fixed a bug with custom drawables
Fixed wrong default color in sf.Shape git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1040 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
2ec074b12a
commit
bcbb754da9
@ -58,6 +58,11 @@ static int
|
|||||||
PySfDrawable_init(PySfDrawable *self, PyObject *args, PyObject *kwds)
|
PySfDrawable_init(PySfDrawable *self, PyObject *args, PyObject *kwds)
|
||||||
{
|
{
|
||||||
self->obj = new CustomDrawable();
|
self->obj = new CustomDrawable();
|
||||||
|
if (PyObject_HasAttrString((PyObject *)self, "Render"))
|
||||||
|
{
|
||||||
|
self->obj->RenderFunction = PyObject_GetAttrString((PyObject *)self, "Render");
|
||||||
|
}
|
||||||
|
else
|
||||||
self->obj->RenderFunction = NULL;
|
self->obj->RenderFunction = NULL;
|
||||||
self->obj->RenderWindow = NULL;
|
self->obj->RenderWindow = NULL;
|
||||||
return 0;
|
return 0;
|
||||||
@ -226,6 +231,18 @@ PySfDrawable_TransformToGlobal(PySfDrawable* self, PyObject *args)
|
|||||||
return Py_BuildValue("ff", result.x, result.y);
|
return Py_BuildValue("ff", result.x, result.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
int PySfDrawable_SetAttr(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||||
|
{
|
||||||
|
std::string Name(PyString_AsString(attr_name));
|
||||||
|
if (Name == "Render")
|
||||||
|
{
|
||||||
|
Py_CLEAR(((PySfDrawable*)self)->obj->RenderFunction);
|
||||||
|
Py_INCREF(v);
|
||||||
|
((PySfDrawable*)self)->obj->RenderFunction = v;
|
||||||
|
}
|
||||||
|
return PyObject_GenericSetAttr(self, attr_name, v);
|
||||||
|
}
|
||||||
|
|
||||||
static PyMethodDef PySfDrawable_methods[] = {
|
static PyMethodDef PySfDrawable_methods[] = {
|
||||||
{"TransformToLocal", (PyCFunction)PySfDrawable_TransformToLocal, METH_VARARGS, "TransformToLocal(X, Y)\n\
|
{"TransformToLocal", (PyCFunction)PySfDrawable_TransformToLocal, METH_VARARGS, "TransformToLocal(X, Y)\n\
|
||||||
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point). Returns a tuple.\n\
|
Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point). Returns a tuple.\n\
|
||||||
@ -274,7 +291,7 @@ PyTypeObject PySfDrawableType = {
|
|||||||
0, /*tp_call*/
|
0, /*tp_call*/
|
||||||
0, /*tp_str*/
|
0, /*tp_str*/
|
||||||
0, /*tp_getattro*/
|
0, /*tp_getattro*/
|
||||||
0, /*tp_setattro*/
|
PySfDrawable_SetAttr, /*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*/
|
||||||
"Abstract base class for every object that can be drawn into a render window.", /* tp_doc */
|
"Abstract base class for every object that can be drawn into a render window.", /* tp_doc */
|
||||||
|
@ -101,10 +101,9 @@ PySfRenderWindow_DrawObject(PySfRenderWindow *RenderWindow, PySfDrawable *Obj)
|
|||||||
{
|
{
|
||||||
if (PyObject_HasAttrString((PyObject *)Obj, "Render"))
|
if (PyObject_HasAttrString((PyObject *)Obj, "Render"))
|
||||||
{
|
{
|
||||||
Py_XDECREF(Obj->obj->RenderWindow);
|
Py_CLEAR(Obj->obj->RenderWindow);
|
||||||
|
Py_INCREF(RenderWindow);
|
||||||
Obj->obj->RenderWindow = RenderWindow;
|
Obj->obj->RenderWindow = RenderWindow;
|
||||||
Py_XDECREF(Obj->obj->RenderFunction);
|
|
||||||
Obj->obj->RenderFunction = PyObject_GetAttrString((PyObject *)Obj, "Render");
|
|
||||||
}
|
}
|
||||||
RenderWindow->obj->Draw( *(Obj->obj) );
|
RenderWindow->obj->Draw( *(Obj->obj) );
|
||||||
return true;
|
return true;
|
||||||
|
@ -72,7 +72,7 @@ PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
|
|||||||
Col = ColTmp->obj;
|
Col = ColTmp->obj;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
Col = (sf::Color *)&sf::Color::Black;
|
Col = (sf::Color *)&sf::Color::White;
|
||||||
|
|
||||||
if (OutlineColTmp)
|
if (OutlineColTmp)
|
||||||
{
|
{
|
||||||
|
@ -27,7 +27,6 @@
|
|||||||
|
|
||||||
#include <SFML/System.hpp>
|
#include <SFML/System.hpp>
|
||||||
#include <SFML/Window.hpp>
|
#include <SFML/Window.hpp>
|
||||||
#include <iostream>
|
|
||||||
|
|
||||||
#include <Python.h>
|
#include <Python.h>
|
||||||
#include <structmember.h>
|
#include <structmember.h>
|
||||||
|
Loading…
Reference in New Issue
Block a user