Removed RenderTarget

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1025 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
remi-k 2009-02-27 23:50:02 +00:00
parent 39f4805a98
commit 7e7489b34a
7 changed files with 91 additions and 216 deletions

View File

@ -13,7 +13,7 @@ setup(name='PySFML',
ext_modules=[ Extension('PySFML.sf', \
['src/Clock.cpp', 'src/Color.cpp', 'src/Drawable.cpp', \
'src/Event.cpp', 'src/Image.cpp', 'src/Input.cpp', 'src/Key.cpp', 'src/main.cpp', 'src/Music.cpp', \
'src/PostFX.cpp', 'src/Rect.cpp', 'src/RenderTarget.cpp', 'src/RenderWindow.cpp', 'src/Sleep.cpp', \
'src/PostFX.cpp', 'src/Rect.cpp', 'src/RenderWindow.cpp', 'src/Sleep.cpp', \
'src/Sprite.cpp', 'src/String.cpp', 'src/VideoMode.cpp', 'src/View.cpp', 'src/Window.cpp', \
'src/Joy.cpp', 'src/Mouse.cpp', 'src/WindowStyle.cpp', 'src/Blend.cpp', 'src/Sound.cpp', \
'src/SoundBuffer.cpp', 'src/Listener.cpp', 'src/SoundRecorder.cpp', 'src/SoundBufferRecorder.cpp', \

View File

@ -31,10 +31,10 @@
extern PyTypeObject PySfColorType;
void CustomDrawable::Render (sf::RenderTarget& Target) const
void CustomDrawable::Render(sf::RenderTarget& Target) const
{
if (RenderFunction)
PyObject_CallFunction(RenderFunction, (char *)"O", RenderTarget);
PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow);
else
PyErr_SetString(PyExc_RuntimeError, "Custom drawables must have a render method defined");
}
@ -59,7 +59,7 @@ PySfDrawable_init(PySfDrawable *self, PyObject *args, PyObject *kwds)
{
self->obj = new CustomDrawable();
self->obj->RenderFunction = NULL;
self->obj->RenderTarget = NULL;
self->obj->RenderWindow = NULL;
return 0;
}

View File

@ -29,7 +29,7 @@
#include <SFML/Graphics/Drawable.hpp>
#include "RenderTarget.hpp"
#include "RenderWindow.hpp"
class CustomDrawable : public sf::Drawable
@ -37,7 +37,7 @@ class CustomDrawable : public sf::Drawable
protected :
virtual void Render(sf::RenderTarget& Target) const;
public :
PySfRenderTarget *RenderTarget;
PySfRenderWindow *RenderWindow;
PyObject *RenderFunction;
};

View File

@ -1,151 +0,0 @@
////////////////////////////////////////////////////////////
//
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#include "RenderTarget.hpp"
#include "Color.hpp"
#include "View.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType;
extern PyTypeObject PySfViewType;
static PyObject *
PySfRenderTarget_Clear(PySfRenderTarget *self, PyObject *args)
{
PySfColor *Color;
int size = PyTuple_Size(args);
if (size == 1)
{
if (!PyArg_ParseTuple(args, "O!:RenderTarget.Clear", &PySfColorType, &Color))
return NULL;
PySfColorUpdate(Color);
self->obj->Clear(*(Color->obj));
}
else if (size == 0)
{
self->obj->Clear(sf::Color::Black);
}
else
{
PyErr_SetString(PyExc_TypeError, "sf.RenderTarget.Clear takes one or zero argument");
return NULL;
}
Py_RETURN_NONE;
}
static PyObject *
PySfRenderTarget_GetView(PySfRenderTarget *self)
{
PySfView *View;
View = GetNewPySfView();
View->obj = new sf::View(self->obj->GetView());
return (PyObject *)View;
}
static PyObject *
PySfRenderTarget_PreserveOpenGLStates(PySfRenderTarget *self, PyObject *args)
{
self->obj->PreserveOpenGLStates(PyBool_AsBool(args));
Py_RETURN_NONE;
}
static PyObject *
PySfRenderTarget_SetView(PySfRenderTarget* self, PyObject *args)
{
PySfView *View = (PySfView *)args;
if (!PyObject_TypeCheck(View, &PySfViewType))
{
PyErr_SetString(PyExc_TypeError, "RenderTarget.SetView() Argument is not a sf.View");
return NULL;
}
self->obj->SetView( *(View->obj));
Py_RETURN_NONE;
}
static PyObject *
PySfRenderTarget_GetDefaultView(PySfRenderTarget *self)
{
PySfView *View;
View = GetNewPySfView();
View->Owner = false;
View->obj = &(self->obj->GetDefaultView());
return (PyObject *)View;
}
static PyMethodDef PySfRenderTarget_methods[] = {
{"Clear", (PyCFunction)PySfRenderTarget_Clear, METH_VARARGS, "Clear(FillColor)\n\
Clear the entire target with a single color.\n\
FillColor : Color to use to clear the render target."},
{"GetDefaultView", (PyCFunction)PySfRenderTarget_GetDefaultView, METH_NOARGS, "GetDefaultView()\n\
Get the default view of the window for read / write (returns a sf.View instance)."},
{"GetView", (PyCFunction)PySfRenderTarget_GetView, METH_NOARGS, "GetView()\n\
Get the current view rectangle (returns a sf.View instance)."},
{"PreserveOpenGLStates", (PyCFunction)PySfRenderTarget_PreserveOpenGLStates, METH_O, "PreserveOpenGLStates(Preserve)\n\
Tell SFML to preserve external OpenGL states, at the expense of more CPU charge. Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default\n\
Preserve : True to preserve OpenGL states, false to let SFML optimize"},
{"SetView", (PyCFunction)PySfRenderTarget_SetView, METH_O, "SetView(View)\n\
Change the current active view. View must be a sf.View instance."},
{NULL} /* Sentinel */
};
PyTypeObject PySfRenderTargetType = {
head_init
"RenderTarget", /*tp_name*/
sizeof(PySfRenderTarget), /*tp_basicsize*/
0, /*tp_itemsize*/
0, /*tp_dealloc*/
0, /*tp_print*/
0, /*tp_getattr*/
0, /*tp_setattr*/
0, /*tp_compare*/
0, /*tp_repr*/
0, /*tp_as_number*/
0, /*tp_as_sequence*/
0, /*tp_as_mapping*/
0, /*tp_hash */
0, /*tp_call*/
0, /*tp_str*/
0, /*tp_getattro*/
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Base class for all render targets (window, image, ...).", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
PySfRenderTarget_methods, /* tp_methods */
};

View File

@ -1,38 +0,0 @@
////////////////////////////////////////////////////////////
//
// 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 __PYRENDERTARGET_H
#define __PYRENDERTARGET_H
#include <Python.h>
#include <SFML/Graphics/RenderTarget.hpp>
typedef struct {
PyObject_HEAD
sf::RenderTarget *obj;
} PySfRenderTarget;
#endif

View File

@ -23,15 +23,11 @@
////////////////////////////////////////////////////////////
#include "RenderWindow.hpp"
#include "Event.hpp"
#include "VideoMode.hpp"
#include "Drawable.hpp"
#include "Color.hpp"
#include "Rect.hpp"
#include "View.hpp"
#include "Image.hpp"
#include "Window.hpp"
#include "WindowSettings.hpp"
#include "Color.hpp"
#include "Drawable.hpp"
#include "compat.hpp"
@ -40,8 +36,9 @@
extern PyTypeObject PySfViewType;
extern PyTypeObject PySfWindowType;
extern PyTypeObject PySfRenderWindowType;
extern PyTypeObject PySfColorType;
extern PyTypeObject PySfDrawableType;
extern PyTypeObject PySfRenderTargetType;
static void
@ -104,9 +101,9 @@ PySfRenderWindow_DrawObject(PySfRenderWindow *RenderWindow, PySfDrawable *Obj)
{
if (PyObject_HasAttrString((PyObject *)Obj, "Render"))
{
Py_DECREF(Obj->obj->RenderTarget);
Obj->obj->RenderTarget = (PySfRenderTarget *)RenderWindow;
Py_DECREF(Obj->obj->RenderFunction);
Py_XDECREF(Obj->obj->RenderWindow);
Obj->obj->RenderWindow = RenderWindow;
Py_XDECREF(Obj->obj->RenderFunction);
Obj->obj->RenderFunction = PyObject_GetAttrString((PyObject *)Obj, "Render");
}
RenderWindow->obj->Draw( *(Obj->obj) );
@ -146,6 +143,42 @@ PySfRenderWindow_Draw(PySfRenderWindow *self, PyObject *args)
Py_RETURN_NONE;
}
static PyObject *
PySfRenderWindow_Clear(PySfRenderWindow *self, PyObject *args)
{
PySfColor *Color;
int size = PyTuple_Size(args);
if (size == 1)
{
if (!PyArg_ParseTuple(args, "O!:RenderWindow.Clear", &PySfColorType, &Color))
return NULL;
PySfColorUpdate(Color);
self->obj->Clear(*(Color->obj));
}
else if (size == 0)
{
self->obj->Clear(sf::Color::Black);
}
else
{
PyErr_SetString(PyExc_TypeError, "RenderWindow.Clear() takes one or zero argument");
return NULL;
}
Py_RETURN_NONE;
}
static PyObject *
PySfRenderWindow_GetView(PySfRenderWindow *self)
{
PySfView *View;
View = GetNewPySfView();
View->obj = new sf::View(self->obj->GetView());
return (PyObject *)View;
}
static PyObject *
PySfRenderWindow_PreserveOpenGLStates(PySfRenderWindow *self, PyObject *args)
{
@ -153,7 +186,46 @@ PySfRenderWindow_PreserveOpenGLStates(PySfRenderWindow *self, PyObject *args)
Py_RETURN_NONE;
}
static PyObject *
PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args)
{
PySfView *View = (PySfView *)args;
if (!PyObject_TypeCheck(View, &PySfViewType))
{
PyErr_SetString(PyExc_TypeError, "RenderWindow.SetView() Argument is not a sf.View");
return NULL;
}
self->obj->SetView( *(View->obj));
Py_RETURN_NONE;
}
static PyObject *
PySfRenderWindow_GetDefaultView(PySfRenderWindow *self)
{
PySfView *View;
View = GetNewPySfView();
View->Owner = false;
View->obj = &(self->obj->GetDefaultView());
return (PyObject *)View;
}
static PyMethodDef PySfRenderWindow_methods[] = {
{"Clear", (PyCFunction)PySfRenderWindow_Clear, METH_VARARGS, "Clear(FillColor)\n\
Clear the entire target with a single color.\n\
FillColor : Color to use to clear the render target."},
{"GetDefaultView", (PyCFunction)PySfRenderWindow_GetDefaultView, METH_NOARGS, "GetDefaultView()\n\
Get the default view of the window for read / write (returns a sf.View instance)."},
{"GetView", (PyCFunction)PySfRenderWindow_GetView, METH_NOARGS, "GetView()\n\
Get the current view rectangle (returns a sf.View instance)."},
{"PreserveOpenGLStates", (PyCFunction)PySfRenderWindow_PreserveOpenGLStates, METH_O, "PreserveOpenGLStates(Preserve)\n\
Tell SFML to preserve external OpenGL states, at the expense of more CPU charge. Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default\n\
Preserve : True to preserve OpenGL states, false to let SFML optimize"},
{"SetView", (PyCFunction)PySfRenderWindow_SetView, METH_O, "SetView(View)\n\
Change the current active view. View must be a sf.View instance."},
{"Draw", (PyCFunction)PySfRenderWindow_Draw, METH_O, "Draw(Drawable)\n\
Draw something on the window. The argument can be a drawable or any object supporting the iterator protocol and containing drawables (for example a tuple of drawables)."},
{"PreserveOpenGLStates", (PyCFunction)PySfRenderWindow_PreserveOpenGLStates, METH_O, "PreserveOpenGLStates(Preserve)\n\
Tell SFML to preserve external OpenGL states, at the expense of more CPU charge. Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default\n\
Preserve : True to preserve OpenGL states, false to let SFML optimize"},
@ -164,8 +236,6 @@ Convert a point in window coordinates into view coordinates. Returns a tuple of
WindowX : X coordinate of the point to convert, relative to the window\n\
WindowY : Y coordinate of the point to convert, relative to the window\n\
TargetView : Target view to convert the point to (NULL by default -- uses the current view)."},
{"Draw", (PyCFunction)PySfRenderWindow_Draw, METH_O, "Draw(Drawable)\n\
Draw something on the window. The argument can be a drawable or any object supporting the iterator protocol and containing drawables (for example a tuple of drawables)."},
{NULL} /* Sentinel */
};
@ -207,7 +277,7 @@ Parameters:\n\
PySfRenderWindow_methods, /* tp_methods */
0, /* tp_members */
0, /* tp_getset */
0, /* tp_base */
&PySfWindowType, /* tp_base */
0, /* tp_dict */
0, /* tp_descr_get */
0, /* tp_descr_set */
@ -215,9 +285,6 @@ Parameters:\n\
(initproc)PySfRenderWindow_init, /* tp_init */
0, /* tp_alloc */
PySfRenderWindow_new, /* tp_new */
0, /* tp_free */
0, /* tp_is_gc */
Py_BuildValue("(OO)", &PySfWindowType, &PySfRenderTargetType) /* tp_bases */
};

View File

@ -57,7 +57,6 @@ extern PyTypeObject PySfWindowType;
extern PyTypeObject PySfWindowSettingsType;
extern PyTypeObject PySfStyleType;
extern PyTypeObject PySfRenderWindowType;
extern PyTypeObject PySfRenderTargetType;
extern PyTypeObject PySfViewType;
extern PyTypeObject PySfInputType;
@ -124,8 +123,6 @@ initsf(void)
INITERROR;
if (PyType_Ready(&PySfStyleType) < 0)
INITERROR;
if (PyType_Ready(&PySfRenderTargetType) < 0)
INITERROR;
if (PyType_Ready(&PySfRenderWindowType) < 0)
INITERROR;
if (PyType_Ready(&PySfVideoModeType) < 0)