Adjusted PySFML to work with the current SFML2 branch.
Note that it's just compatible. A lot of the new functionality is still in the pipeline. git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1308 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
fb7470cbc3
commit
839c80556d
BIN
python/samples/data/cheeseburger.ttf
Normal file
BIN
python/samples/data/cheeseburger.ttf
Normal file
Binary file not shown.
98
python/samples/hellosfml.py
Normal file
98
python/samples/hellosfml.py
Normal file
@ -0,0 +1,98 @@
|
||||
# coding=utf-8
|
||||
from PySFML import sf
|
||||
import random
|
||||
|
||||
# Simple class for an apple.
|
||||
class Apple:
|
||||
sprite = None
|
||||
speed = (2, 2)
|
||||
rotationstep = 1
|
||||
|
||||
def __init__( self, image ):
|
||||
self.sprite = sf.Sprite( image )
|
||||
self.sprite.SetOrigin( image.GetWidth() / 2, image.GetHeight() / 2 )
|
||||
|
||||
# Set resolution and create the window.
|
||||
Resolution = (800, 600)
|
||||
|
||||
wnd = sf.RenderWindow( sf.VideoMode( Resolution[0], Resolution[1], 32 ), "Hello SFML!" )
|
||||
wnd.UseVerticalSync( True )
|
||||
|
||||
# Load a fancy font.
|
||||
cheese = sf.Font()
|
||||
cheese.LoadFromFile( "data/cheeseburger.ttf", 50 )
|
||||
|
||||
# Create a text.
|
||||
text = sf.Text( u"Hello SFML from Python!", cheese, 50 )
|
||||
text.SetOrigin( text.GetRect().GetSize()[0] / 2, text.GetRect().GetSize()[1] / 2 )
|
||||
text.SetPosition( 400, 300 )
|
||||
text.SetColor( sf.Color( 0, 100, 0, 100 ) )
|
||||
|
||||
# Create a text for FPS display.
|
||||
fpstext = sf.Text( u"FPS: --", cheese )
|
||||
fpstext.SetColor( sf.Color( 0, 0, 0 ) )
|
||||
currentfps = 0
|
||||
fpsclock = sf.Clock()
|
||||
|
||||
# Load apple image from file.
|
||||
appleimage = sf.Image()
|
||||
appleimage.LoadFromFile( "data/apple.png" )
|
||||
|
||||
# Create some apples with random position, speed, rotation and color.
|
||||
apples = [Apple( appleimage ) for num in range( 0, 100 )]
|
||||
for apple in apples:
|
||||
apple.sprite.SetOrigin( appleimage.GetWidth() / 2, appleimage.GetHeight() / 2 )
|
||||
apple.sprite.SetPosition(
|
||||
random.randint( apple.sprite.GetOrigin()[0], Resolution[0] - apple.sprite.GetOrigin()[0] ),
|
||||
random.randint( apple.sprite.GetOrigin()[1], Resolution[1] - apple.sprite.GetOrigin()[1] )
|
||||
)
|
||||
apple.sprite.SetColor( sf.Color( random.randint( 100, 255 ), random.randint( 100, 255 ), random.randint( 100, 255 ) ) )
|
||||
|
||||
randx = random.randint( -3, 3 )
|
||||
randy = random.randint( -3, 3 )
|
||||
apple.speed = (1 if randx == 0 else randx, 1 if randy == 0 else randy)
|
||||
|
||||
apple.rotationstep = random.uniform( 1.0, 20.0 ) - 10.0
|
||||
|
||||
event = sf.Event()
|
||||
|
||||
# Main loop.
|
||||
while wnd.IsOpened():
|
||||
# Fetch all pending events and process them.
|
||||
while wnd.GetEvent( event ):
|
||||
# Quit when window has been closed or Escape has been pressed.
|
||||
if event.Type == sf.Event.Closed:
|
||||
wnd.Close()
|
||||
elif event.Type == sf.Event.KeyPressed and event.Key.Code == sf.Key.Escape:
|
||||
wnd.Close()
|
||||
|
||||
# Clear window to white color.
|
||||
wnd.Clear( sf.Color( 255, 255, 255 ) )
|
||||
|
||||
# Draw all apples and texts.
|
||||
for apple in apples:
|
||||
wnd.Draw( apple.sprite )
|
||||
|
||||
wnd.Draw( text )
|
||||
wnd.Draw( fpstext )
|
||||
|
||||
wnd.Display() # Display everything.
|
||||
|
||||
# Count FPS.
|
||||
currentfps += 1
|
||||
if fpsclock.GetElapsedTime() >= 1.0:
|
||||
fpsclock.Reset()
|
||||
fpstext.SetString( u"FPS: " + unicode( currentfps ) )
|
||||
currentfps = 0
|
||||
|
||||
# Update apples (for the "bounce effect").
|
||||
for apple in apples:
|
||||
apple.sprite.Move( apple.speed[0], apple.speed[1] )
|
||||
apple.sprite.Rotate( apple.rotationstep )
|
||||
|
||||
realpos = (apple.sprite.GetPosition()[0] - apple.sprite.GetOrigin()[0], apple.sprite.GetPosition()[1] - apple.sprite.GetOrigin()[1])
|
||||
if (apple.speed[0] > 0 and realpos[0] >= Resolution[0] - appleimage.GetWidth()) or (apple.speed[0] < 0 and realpos[0] <= 0):
|
||||
apple.speed = (apple.speed[0] * -1, apple.speed[1])
|
||||
|
||||
if (apple.speed[1] > 0 and realpos[1] >= Resolution[1] - appleimage.GetWidth()) or (apple.speed[1] < 0 and realpos[1] <= 0):
|
||||
apple.speed = (apple.speed[0], apple.speed[1] * -1)
|
@ -11,7 +11,7 @@ def main():
|
||||
|
||||
# Create main window
|
||||
App = sf.RenderWindow(sf.VideoMode(800, 600), "SFML OpenGL")
|
||||
App.PreserveOpenGLStates(True)
|
||||
App.SetActive()
|
||||
|
||||
# Create a sprite for the background
|
||||
BackgroundImage = sf.Image()
|
||||
@ -73,6 +73,10 @@ def main():
|
||||
|
||||
# Draw background
|
||||
App.Draw(Background)
|
||||
App.Flush()
|
||||
|
||||
# Active window to be able to perform OpenGL commands.
|
||||
App.SetActive()
|
||||
|
||||
# Clear depth buffer
|
||||
glClear(GL_DEPTH_BUFFER_BIT)
|
||||
@ -145,7 +149,7 @@ def main():
|
||||
glEnd()
|
||||
|
||||
# Draw some text on top of our OpenGL object
|
||||
Text = sf.String("This is a rotating cube")
|
||||
Text = sf.Text("This is a rotating cube")
|
||||
Text.SetPosition(230., 300.)
|
||||
Text.SetColor(sf.Color(128, 0, 128))
|
||||
App.Draw(Text)
|
||||
|
@ -3,40 +3,40 @@
|
||||
# You can notice that here we use PySFML.sf instead of just PySFML
|
||||
# Therefore it won't be needed to put sf. in front of SFML classes
|
||||
|
||||
from PySFML.sf import *
|
||||
from PySFML import sf
|
||||
|
||||
|
||||
def Main():
|
||||
Buffer = SoundBuffer()
|
||||
Buffer = sf.SoundBuffer()
|
||||
if not Buffer.LoadFromFile("data/fart.wav"): # Loads the sound
|
||||
return
|
||||
Fart = Sound(Buffer, False)
|
||||
Fart = sf.Sound(Buffer, False)
|
||||
|
||||
WindowWidth, WindowHeight = 640, 480
|
||||
App = RenderWindow(VideoMode(WindowWidth,WindowHeight,32), "Sound with PySFML", Style.Close, WindowSettings(24,8,0))
|
||||
App = sf.RenderWindow(sf.VideoMode(WindowWidth,WindowHeight,32), "Sound with PySFML", sf.Style.Close, sf.ContextSettings(24,8,0))
|
||||
App.SetFramerateLimit(30)
|
||||
|
||||
EventHandler = Event()
|
||||
EventHandler = sf.Event()
|
||||
InputHandler = App.GetInput()
|
||||
|
||||
Text = String("Turn the sound on.\nClick anywhere on the screen.\nMove the mouse. Click again.\nTry clicking in the corners.")
|
||||
Text = sf.Text("Turn the sound on.\nClick anywhere on the screen.\nMove the mouse. Click again.\nTry clicking in the corners.")
|
||||
Text.SetX(30.)
|
||||
Text.SetY(20.)
|
||||
Text.SetColor(Color(150, 100, 10, 255))
|
||||
Text.SetColor(sf.Color(150, 100, 10, 255))
|
||||
|
||||
while App.IsOpened(): # Main loop
|
||||
while App.GetEvent(EventHandler): # Event Handler
|
||||
if EventHandler.Type == Event.Closed:
|
||||
if EventHandler.Type == sf.Event.Closed:
|
||||
App.Close()
|
||||
if EventHandler.Type == Event.KeyPressed and EventHandler.Key.Code == Key.Escape:
|
||||
if EventHandler.Type == sf.Event.KeyPressed and EventHandler.Key.Code == sf.Key.Escape:
|
||||
App.Close()
|
||||
if EventHandler.Type == Event.MouseButtonPressed and EventHandler.MouseButton.Button == Mouse.Left:
|
||||
if EventHandler.Type == sf.Event.MouseButtonPressed and EventHandler.MouseButton.Button == sf.Mouse.Left:
|
||||
Fart.SetPitch(1.5 - 1.*InputHandler.GetMouseY()/WindowHeight)
|
||||
Fart.SetPosition( 1.*(InputHandler.GetMouseX() - WindowWidth/2)/(WindowWidth/20), 2., -2.)
|
||||
Fart.Play()
|
||||
App.Draw(Text)
|
||||
App.Display()
|
||||
App.Clear(Color.Black)
|
||||
App.Clear(sf.Color.Black)
|
||||
|
||||
|
||||
Main()
|
||||
|
@ -4,7 +4,7 @@ from PySFML import sf
|
||||
|
||||
def Main():
|
||||
# Check that the device can capture audio
|
||||
if sf.SoundRecorder.CanCapture() == False:
|
||||
if sf.SoundRecorder.IsAvailable() == False:
|
||||
print "Sorry, audio capture is not supported by your system"
|
||||
return
|
||||
|
||||
|
@ -10,7 +10,7 @@ class Menu:
|
||||
text_color = sf.Color(220, 220, 20, 255)
|
||||
self.spacing = screen_height/7
|
||||
|
||||
self.title = sf.String("PyWorm!")
|
||||
self.title = sf.Text("PyWorm!")
|
||||
self.title.SetColor(text_color)
|
||||
self.title.SetPosition(screen_width/2-80., self.spacing)
|
||||
|
||||
@ -18,7 +18,7 @@ class Menu:
|
||||
x_align = [-80., -50., -70., -50.]
|
||||
self.strings = []
|
||||
for i in range(0, 4):
|
||||
string = sf.String(levels[i])
|
||||
string = sf.Text(levels[i])
|
||||
string.SetColor(text_color)
|
||||
string.SetPosition(screen_width/2+x_align[i], (2+i)*self.spacing+20)
|
||||
self.strings.append(string)
|
||||
@ -47,7 +47,7 @@ class Apple(sf.Sprite):
|
||||
pass
|
||||
# print "Could not load data/apple.png"
|
||||
sf.Sprite.__init__(self, apple_img)
|
||||
self.SetCenter(apple_img.GetWidth()/2, apple_img.GetHeight()/2)
|
||||
self.SetOrigin(apple_img.GetWidth()/2, apple_img.GetHeight()/2)
|
||||
self.size = apple_img.GetWidth()
|
||||
|
||||
def random_move(self, arena):
|
||||
@ -62,10 +62,10 @@ class Arena(dict):
|
||||
def __init__(self, window_width, window_height):
|
||||
self.window_width = window_width
|
||||
self.arena_bottom, self.exit_left, self.exit_right = window_height-80, window_width/2 - 50, window_width/2 + 50
|
||||
self['level_str'] = sf.String()
|
||||
self['level_str'] = sf.Text()
|
||||
self['level_str'].SetColor(sf.Color.White)
|
||||
self['level_str'].SetPosition(60., window_height-60)
|
||||
self['score_str'] = sf.String()
|
||||
self['score_str'] = sf.Text()
|
||||
self['score_str'].SetColor(sf.Color.White)
|
||||
self['score_str'].SetPosition(260., window_height-60)
|
||||
self.exit_rect = sf.Shape.Rectangle(self.exit_left, 0, self.exit_right, self.arena_top, sf.Color.Black)
|
||||
@ -78,16 +78,16 @@ class Arena(dict):
|
||||
def reset(self):
|
||||
self.level, self.score, self.arena_left, self.arena_right = 1, 0, self.shrink_value, self.window_width-self.shrink_value
|
||||
self.update_arena_rect()
|
||||
self['level_str'].SetText("Level: 1")
|
||||
self['score_str'].SetText("Score: 0")
|
||||
self['level_str'].SetString("Level: 1")
|
||||
self['score_str'].SetString("Score: 0")
|
||||
|
||||
def update_score(self):
|
||||
self.score += 1
|
||||
self['score_str'].SetText("Score: " + str(self.score))
|
||||
self['score_str'].SetString("Score: " + str(self.score))
|
||||
|
||||
def next_level(self):
|
||||
self.level += 1
|
||||
self['level_str'].SetText("Level: " + str(self.level))
|
||||
self['level_str'].SetString("Level: " + str(self.level))
|
||||
self.arena_left += self.shrink_value
|
||||
self.arena_right -= self.shrink_value
|
||||
self.update_arena_rect()
|
||||
@ -97,7 +97,7 @@ class Arena(dict):
|
||||
class Part(sf.Sprite):
|
||||
def __init__(self, rond, x, y):
|
||||
sf.Sprite.__init__(self, rond)
|
||||
self.SetCenter(rond.GetWidth()/2, rond.GetHeight()/2)
|
||||
self.SetOrigin(rond.GetWidth()/2, rond.GetHeight()/2)
|
||||
self.SetPosition(x, y)
|
||||
|
||||
class Worm(list):
|
||||
|
@ -13,11 +13,11 @@ 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/RenderWindow.cpp', 'src/Sleep.cpp', \
|
||||
'src/Sprite.cpp', 'src/String.cpp', 'src/VideoMode.cpp', 'src/View.cpp', 'src/Window.cpp', \
|
||||
'src/Shader.cpp', 'src/Rect.cpp', 'src/RenderWindow.cpp', 'src/Sleep.cpp', \
|
||||
'src/Sprite.cpp', 'src/Text.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', \
|
||||
'src/SoundStream.cpp', 'src/Font.cpp', 'src/Glyph.cpp', 'src/Shape.cpp', 'src/WindowSettings.cpp' ], \
|
||||
'src/SoundStream.cpp', 'src/Font.cpp', 'src/Glyph.cpp', 'src/Shape.cpp', 'src/ContextSettings.cpp' ], \
|
||||
libraries=['sfml-graphics', 'sfml-window', 'sfml-audio', 'sfml-system'], \
|
||||
library_dirs=['../lib/mingw'], \
|
||||
include_dirs=['../include']
|
||||
|
@ -22,60 +22,66 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "WindowSettings.hpp"
|
||||
#include "ContextSettings.hpp"
|
||||
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
#include "compat.hpp"
|
||||
|
||||
static PyMemberDef PySfWindowSettings_members[] = {
|
||||
{(char *)"DepthBits", T_UINT, offsetof(PySfWindowSettings, DepthBits), 0, (char *)"Depth buffer bits (24 by default)"},
|
||||
{(char *)"StencilBits", T_UINT, offsetof(PySfWindowSettings, StencilBits), 0, (char *)"Stencil buffer bits (8 by default)"},
|
||||
{(char *)"AntialiasingLevel", T_UINT, offsetof(PySfWindowSettings, AntialiasingLevel), 0, (char *)"Antialiasing level (0 by default)"},
|
||||
static PyMemberDef PySfContextSettings_members[] = {
|
||||
{(char *)"DepthBits", T_UINT, offsetof(PySfContextSettings, DepthBits), 0, (char *)"Depth buffer bits (24 by default)"},
|
||||
{(char *)"StencilBits", T_UINT, offsetof(PySfContextSettings, StencilBits), 0, (char *)"Stencil buffer bits (8 by default)"},
|
||||
{(char *)"AntialiasingLevel", T_UINT, offsetof(PySfContextSettings, AntialiasingLevel), 0, (char *)"Antialiasing level (0 by default)"},
|
||||
{(char *)"MajorVersion", T_UINT, offsetof(PySfContextSettings, MajorVersion), 0, (char *)"Major number of the context version to create. (2 by default)"},
|
||||
{(char *)"MinorVersion", T_UINT, offsetof(PySfContextSettings, MinorVersion), 0, (char *)"Minor number of the context version to create. (0 by default)"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfWindowSettings_dealloc(PySfWindowSettings *self)
|
||||
PySfContextSettings_dealloc(PySfContextSettings *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
void
|
||||
PySfWindowSettingsUpdate(PySfWindowSettings *self)
|
||||
PySfContextSettingsUpdate(PySfContextSettings *self)
|
||||
{
|
||||
self->obj->DepthBits = self->DepthBits;
|
||||
self->obj->StencilBits = self->StencilBits;
|
||||
self->obj->AntialiasingLevel = self->AntialiasingLevel;
|
||||
self->obj->MajorVersion = self->MajorVersion;
|
||||
self->obj->MinorVersion = self->MinorVersion;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindowSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
PySfContextSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", NULL};
|
||||
PySfWindowSettings *self;
|
||||
self = (PySfWindowSettings *)type->tp_alloc(type, 0);
|
||||
const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", "MajorVersion", "MinorVersion", NULL};
|
||||
PySfContextSettings *self;
|
||||
self = (PySfContextSettings *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->DepthBits = 24;
|
||||
self->StencilBits = 8;
|
||||
self->AntialiasingLevel = 0;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|III:WindowSettings.__init__", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel)))
|
||||
self->MajorVersion = 2;
|
||||
self->MinorVersion = 0;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|IIIII:ContextSettings.__init__", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel), &(self->MajorVersion), &(self->MinorVersion)))
|
||||
return NULL;
|
||||
self->obj = new sf::WindowSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel);
|
||||
self->obj = new sf::ContextSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel, self->MajorVersion, self->MinorVersion);
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
PyTypeObject PySfWindowSettingsType = {
|
||||
PyTypeObject PySfContextSettingsType = {
|
||||
head_init
|
||||
"WindowSettings", /*tp_name*/
|
||||
sizeof(PySfWindowSettings), /*tp_basicsize*/
|
||||
"ContextSettings", /*tp_name*/
|
||||
sizeof(PySfContextSettings), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfWindowSettings_dealloc, /*tp_dealloc*/
|
||||
(destructor)PySfContextSettings_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
@ -99,7 +105,7 @@ PyTypeObject PySfWindowSettingsType = {
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfWindowSettings_members, /* tp_members */
|
||||
PySfContextSettings_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
@ -108,12 +114,12 @@ PyTypeObject PySfWindowSettingsType = {
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfWindowSettings_new, /* tp_new */
|
||||
PySfContextSettings_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfWindowSettings *
|
||||
GetNewPySfWindowSettings()
|
||||
PySfContextSettings *
|
||||
GetNewPySfContextSettings()
|
||||
{
|
||||
return PyObject_New(PySfWindowSettings, &PySfWindowSettingsType);
|
||||
return PyObject_New(PySfContextSettings, &PySfContextSettingsType);
|
||||
}
|
||||
|
@ -27,7 +27,7 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Window/WindowSettings.hpp>
|
||||
#include <SFML/Window/ContextSettings.hpp>
|
||||
|
||||
|
||||
typedef struct {
|
||||
@ -35,13 +35,15 @@ typedef struct {
|
||||
unsigned int DepthBits;
|
||||
unsigned int StencilBits;
|
||||
unsigned int AntialiasingLevel;
|
||||
sf::WindowSettings *obj;
|
||||
} PySfWindowSettings;
|
||||
unsigned int MajorVersion;
|
||||
unsigned int MinorVersion;
|
||||
sf::ContextSettings *obj;
|
||||
} PySfContextSettings;
|
||||
|
||||
void
|
||||
PySfWindowSettingsUpdate(PySfWindowSettings *self);
|
||||
PySfContextSettingsUpdate(PySfContextSettings *self);
|
||||
|
||||
PySfWindowSettings *
|
||||
GetNewPySfWindowSettings();
|
||||
PySfContextSettings *
|
||||
GetNewPySfContextSettings();
|
||||
|
||||
#endif
|
@ -31,10 +31,10 @@
|
||||
extern PyTypeObject PySfColorType;
|
||||
|
||||
|
||||
void CustomDrawable::Render(sf::RenderTarget& Target) const
|
||||
void CustomDrawable::Render(sf::RenderTarget& Target, sf::RenderQueue& Queue) const
|
||||
{
|
||||
if (RenderFunction)
|
||||
PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow);
|
||||
PyObject_CallFunction(RenderFunction, (char *)"OO", RenderWindow, Queue);
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_RuntimeError, "Custom drawables must have a render method defined");
|
||||
@ -108,18 +108,18 @@ PySfDrawable_SetRotation(PySfDrawable* self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetCenter(PySfDrawable* self, PyObject *args)
|
||||
PySfDrawable_SetOrigin(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.SetCenter", &x, &y) )
|
||||
if (!PyArg_ParseTuple(args, "ff:Drawable.SetOrigin", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->SetCenter(x, y);
|
||||
self->obj->SetOrigin(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetCenter(PySfDrawable* self)
|
||||
PySfDrawable_GetOrigin(PySfDrawable* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetCenter();
|
||||
sf::Vector2f Vect = self->obj->GetOrigin();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
@ -253,11 +253,11 @@ int PySfDrawable_setattro(PyObject* self, PyObject *attr_name, PyObject *v)
|
||||
|
||||
static PyMethodDef PySfDrawable_methods[] = {
|
||||
{"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 origin, translation, rotation and scale to the point). Returns a tuple.\n\
|
||||
X : X coordinate of the point to transform\n\
|
||||
Y : Y coordinate of the point to transform"},
|
||||
{"TransformToGlobal", (PyCFunction)PySfDrawable_TransformToGlobal, METH_VARARGS, "TransformToGlobal(X, Y)\n\
|
||||
Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point). Returns a tuple.\n\
|
||||
Transform a point from local coordinates into global coordinates (ie it applies the object's origin, translation, rotation and scale to the point). Returns a tuple.\n\
|
||||
X : X coordinate of the point to transform\n\
|
||||
Y : Y coordinate of the point to transform"},
|
||||
{"SetX", (PyCFunction)PySfDrawable_SetX, METH_O, "SetX(X)\nSet the X position of the object.\n X : New X coordinate"},
|
||||
@ -266,8 +266,8 @@ Transform a point from local coordinates into global coordinates (ie it applies
|
||||
{"SetScaleX", (PyCFunction)PySfDrawable_SetScaleX, METH_O, "SetScaleX(ScaleX)\nSet the X scale factor of the object.\n ScaleX : New horizontal scale (must be strictly positive)"},
|
||||
{"SetScaleY", (PyCFunction)PySfDrawable_SetScaleY, METH_O, "SetScaleY(ScaleY)\nSet the Y scale factor of the object.\n ScaleY : New vertical scale (must be strictly positive)"},
|
||||
{"SetRotation", (PyCFunction)PySfDrawable_SetRotation, METH_O, "SetRotation(Rotation)\nSet the orientation of the object.\n Rotation : Angle of rotation, in degrees"},
|
||||
{"SetCenter", (PyCFunction)PySfDrawable_SetCenter, METH_VARARGS, "SetCenter(CenterX, CenterY)\nSet the center of the object, in coordinates relative to the object.\n CenterX : X coordinate of the center\n CenterY : Y coordinate of the center"},
|
||||
{"GetCenter", (PyCFunction)PySfDrawable_GetCenter, METH_NOARGS, "GetCenter()\nGet the center of the object, in coordinates relative to the object."},
|
||||
{"SetOrigin", (PyCFunction)PySfDrawable_SetOrigin, METH_VARARGS, "SetOrigin(OriginX, OriginY)\nSet the origin of the object, in coordinates relative to the object.\n OriginX : X coordinate of the origin\n OriginY : Y coordinate of the origin"},
|
||||
{"GetOrigin", (PyCFunction)PySfDrawable_GetOrigin, METH_NOARGS, "GetOrigin()\nGet the origin of the object, in coordinates relative to the object."},
|
||||
{"SetColor", (PyCFunction)PySfDrawable_SetColor, METH_O, "SetColor(Color)\nSet the color of the object.\n Color : New color"},
|
||||
{"GetPosition", (PyCFunction)PySfDrawable_GetPosition, METH_NOARGS, "GetPosition()\nGet the position of the object."},
|
||||
{"GetScale", (PyCFunction)PySfDrawable_GetScale, METH_NOARGS, "GetScale()\nGet the scale of the object."},
|
||||
|
@ -28,14 +28,15 @@
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/RenderQueue.hpp>
|
||||
|
||||
#include "RenderWindow.hpp"
|
||||
|
||||
#include "RenderQueue.hpp"
|
||||
|
||||
class CustomDrawable : public sf::Drawable
|
||||
{
|
||||
protected :
|
||||
virtual void Render(sf::RenderTarget& Target) const;
|
||||
virtual void Render(sf::RenderTarget& Target, sf::RenderQueue& Queue) const;
|
||||
public :
|
||||
PySfRenderWindow *RenderWindow;
|
||||
PyObject *RenderFunction;
|
||||
|
@ -75,16 +75,16 @@ PySfFont_LoadFromFile(PySfFont* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (EncodingStr == NULL)
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, Charset);
|
||||
else
|
||||
{
|
||||
Encoding.assign(EncodingStr);
|
||||
if (Encoding == "utf8" || Encoding == "")
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, Charset);
|
||||
else if (Encoding == "utf16")
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF16String((sf::Uint16 *)(Charset+2)));
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, Charset+2);
|
||||
else if (Encoding == "utf32")
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF32String((sf::Uint32 *)(Charset+4)));
|
||||
result = self->obj->LoadFromFile(Filename, Charsize, Charset+4);
|
||||
else
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "Font.LoadFromFile() Encoding %s not supported", EncodingStr);
|
||||
@ -125,16 +125,16 @@ PySfFont_LoadFromMemory(PySfFont* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (EncodingStr == NULL)
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, Charset);
|
||||
else
|
||||
{
|
||||
Encoding.assign(EncodingStr);
|
||||
if (Encoding == "utf8")
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, Charset);
|
||||
else if (Encoding == "utf16")
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF16String((sf::Uint16 *)(Charset+2)));
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, Charset+2);
|
||||
else if (Encoding == "utf32")
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF32String((sf::Uint32 *)(Charset+4)));
|
||||
result = self->obj->LoadFromMemory(Data, Size, Charsize, Charset+4);
|
||||
else
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "Font.LoadFromMemory() Encoding %s not supported", EncodingStr);
|
||||
|
@ -223,10 +223,10 @@ PySfImage_GetHeight(PySfImage *self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetValidTextureSize(PySfImage* self, PyObject *args)
|
||||
PySfImage_GetValidSize(PySfImage* self, PyObject *args)
|
||||
{
|
||||
unsigned long S = PyLong_AsUnsignedLong(args);
|
||||
return PyLong_FromUnsignedLong(sf::Image::GetValidTextureSize(S));
|
||||
return PyLong_FromUnsignedLong(sf::Image::GetValidSize(S));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
@ -300,7 +300,7 @@ Create the image from the current contents of the given window. Return True if c
|
||||
{"GetHeight", (PyCFunction)PySfImage_GetHeight, METH_NOARGS, "GetHeight()\nReturn the height of the image."},
|
||||
{"GetTexCoords", (PyCFunction)PySfImage_GetTexCoords, METH_VARARGS, "GetTexCoords(Rect)\nConvert a subrect expressed in pixels, into float texture coordinates. Returns texture coordinates corresponding to the sub-rectangle (sf.FloatRect instance)\n\
|
||||
Rect : Sub-rectangle of image to convert"},
|
||||
{"GetValidTextureSize", (PyCFunction)PySfImage_GetValidTextureSize, METH_STATIC | METH_O, "GetValidTextureSize(Size)\nGet a valid texture size according to hardware support. Returns valid nearest size (greater than or equal to specified size).\n\
|
||||
{"GetValidSize", (PyCFunction)PySfImage_GetValidSize, METH_STATIC | METH_O, "GetValidSize(Size)\nGet a valid texture size according to hardware support. Returns valid nearest size (greater than or equal to specified size).\n\
|
||||
Size : Size to convert"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
@ -58,19 +58,19 @@ PySfListener_GetPosition(PySfListener *self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_SetTarget(PySfListener* self, PyObject *args)
|
||||
PySfListener_SetDirection(PySfListener* self, PyObject *args)
|
||||
{
|
||||
float X, Y, Z;
|
||||
if (!PyArg_ParseTuple(args, "fff:Listener.SetTarget", &X, &Y, &Z))
|
||||
if (!PyArg_ParseTuple(args, "fff:Listener.SetDirection", &X, &Y, &Z))
|
||||
return NULL;
|
||||
sf::Listener::SetTarget(X, Y, Z);
|
||||
sf::Listener::SetDirection(X, Y, Z);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfListener_GetTarget(PySfListener *self)
|
||||
PySfListener_GetDirection(PySfListener *self)
|
||||
{
|
||||
sf::Vector3f Vect = sf::Listener::GetTarget();
|
||||
sf::Vector3f Vect = sf::Listener::GetDirection();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
@ -79,8 +79,8 @@ static PyMethodDef PySfListener_methods[] = {
|
||||
{"GetGlobalVolume", (PyCFunction)PySfListener_GetGlobalVolume, METH_STATIC | METH_NOARGS, "GetGlobalVolume()\nGet the current value of the global volume of all the sounds."},
|
||||
{"SetPosition", (PyCFunction)PySfListener_SetPosition, METH_STATIC | METH_VARARGS, "SetPosition(X, Y, Z)\nChange the position of the listener."},
|
||||
{"GetPosition", (PyCFunction)PySfListener_GetPosition, METH_STATIC | METH_NOARGS, "GetPosition()\nGet the current position of the listener."},
|
||||
{"SetTarget", (PyCFunction)PySfListener_SetTarget, METH_STATIC | METH_VARARGS, "SetTarget(X, Y, Z)\nChange the orientation of the listener (the point he must look at)"},
|
||||
{"GetTarget", (PyCFunction)PySfListener_GetTarget, METH_STATIC | METH_NOARGS, "GetTarget()\nGet the current orientation of the listener (the point he's looking at)"},
|
||||
{"SetDirection", (PyCFunction)PySfListener_SetDirection, METH_STATIC | METH_VARARGS, "SetDirection(X, Y, Z)\nChange the orientation of the listener (the point he must look at)"},
|
||||
{"GetDirection", (PyCFunction)PySfListener_GetDirection, METH_STATIC | METH_NOARGS, "GetDirection()\nGet the current orientation of the listener (the point he's looking at)"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
@ -40,14 +40,11 @@ PySfMusic_dealloc(PySfMusic *self)
|
||||
static PyObject *
|
||||
PySfMusic_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
unsigned int BufferSize=44100;
|
||||
PySfMusic *self;
|
||||
self = (PySfMusic *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
if (!PyArg_ParseTuple(args, "|I:Music.__new__", &BufferSize))
|
||||
return NULL;
|
||||
self->obj = new sf::Music(BufferSize);
|
||||
self->obj = new sf::Music();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
@ -120,8 +117,7 @@ PyTypeObject PySfMusicType = {
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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 */
|
||||
Constructor: sf.Music()", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
|
@ -95,15 +95,10 @@ PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_GetWidth(PySfIntRect *self)
|
||||
PySfIntRect_GetSize(PySfIntRect *self)
|
||||
{
|
||||
return PyLong_FromLong(self->obj->GetWidth());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_GetHeight(PySfIntRect *self)
|
||||
{
|
||||
return PyLong_FromLong(self->obj->GetHeight());
|
||||
sf::Vector2i size( self->obj->GetSize() );
|
||||
return Py_BuildValue( "ii", size.x, size.y );
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
@ -113,15 +108,10 @@ static PyObject *
|
||||
PySfIntRect_Intersects(PySfIntRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_GetWidth(PySfFloatRect *self)
|
||||
PySfFloatRect_GetSize(PySfFloatRect *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetWidth());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_GetHeight(PySfFloatRect *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetHeight());
|
||||
sf::Vector2f size( self->obj->GetSize() );
|
||||
return Py_BuildValue( "ff", size.x, size.y );
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
@ -163,10 +153,7 @@ Move the whole rectangle by the given offset.\n\
|
||||
OffsetX : Horizontal offset\n\
|
||||
OffsetY : Vertical offset\n\
|
||||
"},
|
||||
{"GetWidth", (PyCFunction)PySfIntRect_GetWidth, METH_NOARGS, "GetWidth()\n\
|
||||
Get the width of the rectangle."},
|
||||
{"GetHeight", (PyCFunction)PySfIntRect_GetHeight, METH_NOARGS, "GetHeight()\n\
|
||||
Get the height of the rectangle."},
|
||||
{"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\
|
||||
@ -185,10 +172,7 @@ Move the whole rectangle by the given offset.\n\
|
||||
OffsetX : Horizontal offset\n\
|
||||
OffsetY : Vertical offset\n\
|
||||
"},
|
||||
{"GetWidth", (PyCFunction)PySfFloatRect_GetWidth, METH_NOARGS, "GetWidth()\n\
|
||||
Get the width of the rectangle."},
|
||||
{"GetHeight", (PyCFunction)PySfFloatRect_GetHeight, METH_NOARGS, "GetHeight()\n\
|
||||
Get the height of the rectangle."},
|
||||
{"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\
|
||||
@ -316,14 +300,14 @@ PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args)
|
||||
static PyObject *
|
||||
PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args)
|
||||
{
|
||||
PySfFloatRect *Rect=NULL, *OverlappingRect=NULL;
|
||||
PySfFloatRect *Rect=NULL, *Intersection=NULL;
|
||||
bool result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!|O!:FloatRect.Intersects", &PySfFloatRectType, &Rect, &PySfFloatRectType, &OverlappingRect))
|
||||
if (!PyArg_ParseTuple(args, "O!|O!:FloatRect.Intersects", &PySfFloatRectType, &Rect, &PySfFloatRectType, &Intersection))
|
||||
return NULL;
|
||||
|
||||
if (OverlappingRect)
|
||||
result = self->obj->Intersects(*(Rect->obj), (OverlappingRect->obj));
|
||||
if (Intersection)
|
||||
result = self->obj->Intersects(*(Rect->obj), *(Intersection->obj));
|
||||
else
|
||||
result = self->obj->Intersects(*(Rect->obj));
|
||||
|
||||
@ -345,14 +329,14 @@ PySfIntRect_Contains(PySfIntRect* self, PyObject *args)
|
||||
static PyObject *
|
||||
PySfIntRect_Intersects(PySfIntRect* self, PyObject *args)
|
||||
{
|
||||
PySfIntRect *Rect=NULL, *OverlappingRect=NULL;
|
||||
PySfIntRect *Rect=NULL, *Intersection=NULL;
|
||||
bool result;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "O!|O!:IntRect.Intersects", &PySfIntRectType, &Rect, &PySfIntRectType, &OverlappingRect))
|
||||
if (!PyArg_ParseTuple(args, "O!|O!:IntRect.Intersects", &PySfIntRectType, &Rect, &PySfIntRectType, &Intersection))
|
||||
return NULL;
|
||||
|
||||
if (OverlappingRect)
|
||||
result = self->obj->Intersects(*(Rect->obj), (OverlappingRect->obj));
|
||||
if (Intersection)
|
||||
result = self->obj->Intersects(*(Rect->obj), *(Intersection->obj));
|
||||
else
|
||||
result = self->obj->Intersects(*(Rect->obj));
|
||||
|
||||
|
94
python/src/RenderQueue.cpp
Normal file
94
python/src/RenderQueue.cpp
Normal file
@ -0,0 +1,94 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007-2009 Rémi Koenig (remi.k2620@gmail.com)
|
||||
// Stefan "Tank" Schindler <stefan@boxbox.org>
|
||||
//
|
||||
// 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 "RenderQueue.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
|
||||
static void
|
||||
PySfRenderQueue_dealloc(PySfRenderQueue* self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object( self );
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfRenderQueue_new(PyTypeObject* type, PyObjects* args, PyObject* kwds)
|
||||
{
|
||||
PySfRenderQueue* self(static_cast<PySfRenderQueue*>(type->tp_alloc(type, 0)));
|
||||
|
||||
if(self != 0)
|
||||
{
|
||||
self->obj = new sf::RenderQueue();
|
||||
}
|
||||
|
||||
return static_cast<PyObject*>( self )
|
||||
}
|
||||
|
||||
static PyMethodDef PySfImage_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfImageType = {
|
||||
head_init
|
||||
"RenderQueue", /*tp_name*/
|
||||
sizeof(PySfRenderQueue), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfRenderQueue_dealloc, /*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*/
|
||||
"Implements a queue of rendering commands.\n\
|
||||
Default constructor : sf.RenderQueue()" /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfRenderQueue_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfRenderQueue_new, /* tp_new */
|
||||
};
|
40
python/src/RenderQueue.hpp
Normal file
40
python/src/RenderQueue.hpp
Normal file
@ -0,0 +1,40 @@
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007-2009 Rémi Koenig (remi.k2620@gmail.com)
|
||||
// Stefan "Tank" Schindler <stefan@boxbox.org>
|
||||
//
|
||||
// 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 __PYRENDERQUEUE_H
|
||||
#define __PYRENDERQUEUE_H
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/RenderQueue.hpp>
|
||||
|
||||
struct PySfRenderQueue {
|
||||
PyObject_HEAD
|
||||
sf::RenderQueue* obj;
|
||||
};
|
||||
|
||||
PySfRenderQueue* GetNewPySfRenderQueue();
|
||||
|
||||
#endif
|
@ -61,31 +61,25 @@ PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_Capture(PySfRenderWindow *self)
|
||||
{
|
||||
PySfImage *Image;
|
||||
|
||||
Image = GetNewPySfImage();
|
||||
Image->obj = new sf::Image(self->obj->Capture());
|
||||
return (PyObject *)Image;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_ConvertCoords(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
unsigned int WindowX, WindowY;
|
||||
PySfView *PyTargetView = NULL;
|
||||
sf::View *TargetView = NULL;
|
||||
sf::Vector2f Vect;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "II|O!:RenderWindow.ConvertCoords", &WindowX, &WindowY, &PySfViewType, &PyTargetView))
|
||||
return NULL;
|
||||
|
||||
if (PyTargetView)
|
||||
TargetView = PyTargetView->obj;
|
||||
{
|
||||
Vect = self->obj->ConvertCoords(WindowX, WindowY, *PyTargetView->obj);
|
||||
}
|
||||
else
|
||||
{
|
||||
Vect = self->obj->ConvertCoords(WindowX, WindowY);
|
||||
}
|
||||
|
||||
Vect = self->obj->ConvertCoords(WindowX, WindowY, TargetView);
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
@ -153,6 +147,24 @@ PySfRenderWindow_Clear(PySfRenderWindow *self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_SetActive(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
PyObject* Active( 0 );
|
||||
|
||||
PyArg_ParseTuple( args, "|O", &Active );
|
||||
self->obj->SetActive( Active == 0 ? true : PyBool_AsBool( Active ) );
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_Flush(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->Flush();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_GetView(PySfRenderWindow *self)
|
||||
{
|
||||
@ -174,13 +186,6 @@ PySfRenderWindow_GetView(PySfRenderWindow *self)
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_PreserveOpenGLStates(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->PreserveOpenGLStates(PyBool_AsBool(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args)
|
||||
{
|
||||
@ -210,6 +215,11 @@ PySfRenderWindow_GetDefaultView(PySfRenderWindow *self)
|
||||
}
|
||||
|
||||
static PyMethodDef PySfRenderWindow_methods[] = {
|
||||
{"SetActive", (PyCFunction)PySfRenderWindow_SetActive, METH_VARARGS, "SetActive(Active)\n\
|
||||
Activate or deactivate the window as the current target for OpenGL rendering.\n\
|
||||
Active : True to activate window. (default: True)"},
|
||||
{"Flush", (PyCFunction)PySfRenderWindow_Flush, METH_VARARGS, "Flush()\n\
|
||||
Make sure that what has been drawn so far is rendered."},
|
||||
{"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."},
|
||||
@ -217,18 +227,10 @@ Clear the entire target with a single color.\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"},
|
||||
{"Capture", (PyCFunction)PySfRenderWindow_Capture, METH_NOARGS, "Capture()\n\
|
||||
Save the content of the window to an image. Returns a sf.Image object."},
|
||||
{"ConvertCoords", (PyCFunction)PySfRenderWindow_ConvertCoords, METH_VARARGS, "ConvertCoords(WindowX, WindowY, TargetView)\n\
|
||||
Convert a point in window coordinates into view coordinates. Returns a tuple of two floats.\n\
|
||||
WindowX : X coordinate of the point to convert, relative to the window\n\
|
||||
|
@ -22,7 +22,7 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "PostFX.hpp"
|
||||
#include "Shader.hpp"
|
||||
#include "Drawable.hpp"
|
||||
#include "Image.hpp"
|
||||
|
||||
@ -34,23 +34,23 @@ extern PyTypeObject PySfDrawableType;
|
||||
|
||||
|
||||
static void
|
||||
PySfPostFX_dealloc(PySfPostFX *self)
|
||||
PySfShader_dealloc(PySfShader *self)
|
||||
{
|
||||
delete self->obj;
|
||||
free_object(self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
PySfShader_new(PyTypeObject *type, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_LoadFromFile (PySfPostFX *self, PyObject *args)
|
||||
PySfShader_LoadFromFile (PySfShader *self, PyObject *args)
|
||||
{
|
||||
load_from_file(self, args);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_LoadFromMemory (PySfPostFX *self, PyObject *args)
|
||||
PySfShader_LoadFromMemory (PySfShader *self, PyObject *args)
|
||||
{
|
||||
char *effect;
|
||||
#ifdef IS_PY3K
|
||||
@ -68,7 +68,7 @@ PySfPostFX_LoadFromMemory (PySfPostFX *self, PyObject *args)
|
||||
return PyBool_FromLong(result);
|
||||
}
|
||||
|
||||
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;
|
||||
static PyObject *
PySfShader_SetParameter(PySfShader* self, PyObject *args)
{
char *Name;
float X, Y, Z, W;
int size = PyTuple_Size(args);
if (!PyArg_ParseTuple(args, "sf|fff:Shader.SetParameter", &Name, &X, &Y, &Z, &W))
return NULL;
|
||||
|
||||
switch (size)
|
||||
{
|
||||
@ -92,52 +92,52 @@ static PyObject *
PySfPostFX_SetParameter(PySfPostFX* self, PyObject *args)
{
c
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_SetTexture(PySfPostFX* self, PyObject *args)
|
||||
PySfShader_SetTexture(PySfShader* self, PyObject *args)
|
||||
{
|
||||
PySfImage *Image = NULL;
|
||||
char *Name;
|
||||
if (! PyArg_ParseTuple(args, "s|O", &Name, &Image))
|
||||
return NULL;
|
||||
if (Image == NULL || (PyObject *)Image == Py_None)
|
||||
self->obj->SetTexture(Name, NULL);
|
||||
else
|
||||
if (! PyArg_ParseTuple(args, "sO", &Name, &Image))
|
||||
{
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (!PyObject_TypeCheck(Image, &PySfImageType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "PostFX.SetTexture() Argument 2, if specified, must be a sf.Image instance or None.");
|
||||
PyErr_SetString(PyExc_TypeError, "Shader.SetTexture() Argument 2 must be an sf.Image instance.");
|
||||
return NULL;
|
||||
}
|
||||
self->obj->SetTexture(Name, Image->obj);
|
||||
}
|
||||
|
||||
self->obj->SetTexture(Name, *Image->obj);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_CanUsePostFX(PySfPostFX* self, PyObject *args)
|
||||
PySfShader_IsAvailable(PySfShader* self, PyObject *args)
|
||||
{
|
||||
return PyBool_FromLong(sf::PostFX::CanUsePostFX());
|
||||
return PyBool_FromLong(sf::Shader::IsAvailable());
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfPostFX_methods[] = {
|
||||
{"LoadFromFile", (PyCFunction)PySfPostFX_LoadFromFile, METH_O, "LoadFromFile(Filename)\nLoad the effect from a file."},
|
||||
{"LoadFromMemory", (PyCFunction)PySfPostFX_LoadFromMemory, METH_O, "LoadFromMemory(Effect)\nLoad the effect from a text in memory."},
|
||||
{"SetParameter", (PyCFunction)PySfPostFX_SetParameter, METH_VARARGS, "SetParameter(X), SetParameter(X, Y), SetParameter(X, Y, Z), SetParameter(X, Y, Z, W)\nChange a parameter of the effect.\n\
|
||||
static PyMethodDef PySfShader_methods[] = {
|
||||
{"LoadFromFile", (PyCFunction)PySfShader_LoadFromFile, METH_O, "LoadFromFile(Filename)\nLoad the effect from a file."},
|
||||
{"LoadFromMemory", (PyCFunction)PySfShader_LoadFromMemory, METH_O, "LoadFromMemory(Effect)\nLoad the effect from a text in memory."},
|
||||
{"SetParameter", (PyCFunction)PySfShader_SetParameter, METH_VARARGS, "SetParameter(X), SetParameter(X, Y), SetParameter(X, Y, Z), SetParameter(X, Y, Z, W)\nChange a parameter of the effect.\n\
|
||||
Name : Parameter name in the effect\n\
|
||||
X,Y,Z,W : Values to assign."},
|
||||
{"SetTexture", (PyCFunction)PySfPostFX_SetTexture, METH_VARARGS, "SetTexture(Name, Texture)\nSet a texture parameter.\n\
|
||||
{"SetTexture", (PyCFunction)PySfShader_SetTexture, METH_VARARGS, "SetTexture(Name, Texture)\nSet a texture parameter.\n\
|
||||
Name : Texture name in the effect\n\
|
||||
Texture : Image to set (pass None to use content of current framebuffer)"},
|
||||
{"CanUsePostFX", (PyCFunction)PySfPostFX_CanUsePostFX, METH_STATIC | METH_NOARGS, "CanUsePostFX()\nTell wether or not the system supports post-effects."},
|
||||
Texture : Image to set (pass sf.Shader.CurrentTexture to use content of current framebuffer)"},
|
||||
{"IsAvailable", (PyCFunction)PySfShader_IsAvailable, METH_STATIC | METH_NOARGS, "IsAvailable()\nTell wether or not the system supports post-effects."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfPostFXType = {
|
||||
PyTypeObject PySfShaderType = {
|
||||
head_init
|
||||
"PostFX", /*tp_name*/
|
||||
sizeof(PySfPostFX), /*tp_basicsize*/
|
||||
"Shader", /*tp_name*/
|
||||
sizeof(PySfShader), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfPostFX_dealloc, /*tp_dealloc*/
|
||||
(destructor)PySfShader_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
@ -153,16 +153,16 @@ PyTypeObject PySfPostFXType = {
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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 */
|
||||
"sf.Shader is used to apply a post effect to a window.\n\
|
||||
Default constructor : sf.Shader()\n\
|
||||
Copy constructor : sf.Shader(Copy) where Copy is a sf.Shader instance.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfPostFX_methods, /* tp_methods */
|
||||
PySfShader_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
@ -172,23 +172,23 @@ Copy constructor : sf.PostFX(Copy) where Copy is a sf.PostFX instance.", /* tp_d
|
||||
0, /* tp_dictoffset */
|
||||
0, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfPostFX_new, /* tp_new */
|
||||
PySfShader_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
PySfShader_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfPostFX *self;
|
||||
self = (PySfPostFX *)type->tp_alloc(type, 0);
|
||||
PySfShader *self;
|
||||
self = (PySfShader *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
PySfPostFX *Copy = NULL;
|
||||
PySfShader *Copy = NULL;
|
||||
self->IsCustom = false;
|
||||
if (!PyArg_ParseTuple(args, "|O!", &PySfPostFXType, &Copy))
|
||||
if (!PyArg_ParseTuple(args, "|O!", &PySfShaderType, &Copy))
|
||||
return NULL;
|
||||
if (Copy) self->obj = new sf::PostFX(*(Copy->obj));
|
||||
else self->obj = new sf::PostFX();
|
||||
if (Copy) self->obj = new sf::Shader(*(Copy->obj));
|
||||
else self->obj = new sf::Shader();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
@ -27,12 +27,12 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/PostFX.hpp>
|
||||
#include <SFML/Graphics/Shader.hpp>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool IsCustom;
|
||||
sf::PostFX *obj;
|
||||
} PySfPostFX;
|
||||
sf::Shader *obj;
|
||||
} PySfShader;
|
||||
|
||||
#endif
|
@ -105,9 +105,9 @@ PySfSoundRecorder_GetSampleRate(PySfSoundRecorder* self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_CanCapture(PySfSoundRecorder* self)
|
||||
PySfSoundRecorder_IsAvailable(PySfSoundRecorder* self)
|
||||
{
|
||||
return PyBool_FromLong(sf::SoundRecorder::CanCapture());
|
||||
return PyBool_FromLong(sf::SoundRecorder::IsAvailable());
|
||||
}
|
||||
|
||||
|
||||
@ -115,7 +115,7 @@ static PyMethodDef PySfSoundRecorder_methods[] = {
|
||||
{"Start", (PyCFunction)PySfSoundRecorder_Start, METH_O, "Start(SampleRate=44100)\nStart the capture. Warning : only one capture can happen at the same time.\n SampleRate : Sound frequency (the more samples, the higher the quality) (44100 by default = CD quality)."},
|
||||
{"Stop", (PyCFunction)PySfSoundRecorder_Stop, METH_NOARGS, "Stop()\nStop the capture."},
|
||||
{"GetSampleRate", (PyCFunction)PySfSoundRecorder_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sample rate. Returns the frequency, in samples per second."},
|
||||
{"CanCapture", (PyCFunction)PySfSoundRecorder_CanCapture, METH_STATIC | METH_NOARGS, "CanCapture()\nTell if the system supports sound capture. If not, this class won't be usable. Returns True if audio capture is supported."},
|
||||
{"IsAvailable", (PyCFunction)PySfSoundRecorder_IsAvailable, METH_STATIC | METH_NOARGS, "IsAvailable()\nTell if the system supports sound capture. If not, this class won't be usable. Returns True if audio capture is supported."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
@ -27,32 +27,24 @@
|
||||
#include "compat.hpp"
|
||||
|
||||
|
||||
bool CustomSoundStream::OnStart()
|
||||
void CustomSoundStream::OnSeek(float TimeOffset)
|
||||
{
|
||||
PyGILState_STATE gstate;
|
||||
bool result = false;
|
||||
gstate = PyGILState_Ensure();
|
||||
if (PyObject_HasAttrString(SoundStream, "OnStart"))
|
||||
if (PyObject_HasAttrString(SoundStream, "OnSeek"))
|
||||
{
|
||||
PyObject *OnStart = PyObject_GetAttrString(SoundStream, "OnStart");
|
||||
if (OnStart != NULL)
|
||||
PyObject *OnSeek = PyObject_GetAttrString(SoundStream, "OnSeek");
|
||||
if (OnSeek != NULL)
|
||||
{
|
||||
PyObject *Result = PyObject_CallFunction(OnStart, NULL);
|
||||
if (Result != NULL)
|
||||
{
|
||||
result = PyBool_AsBool(Result);
|
||||
Py_CLEAR(Result);
|
||||
}
|
||||
Py_CLEAR(OnStart);
|
||||
PyObject_CallFunction(OnSeek, const_cast<char*>( "f" ), TimeOffset);
|
||||
Py_CLEAR(OnSeek);
|
||||
}
|
||||
}
|
||||
if (PyErr_Occurred())
|
||||
{
|
||||
PyErr_Print();
|
||||
result = false;
|
||||
}
|
||||
PyGILState_Release(gstate);
|
||||
return result;
|
||||
}
|
||||
|
||||
bool CustomSoundStream::OnGetData(Chunk& Data)
|
||||
|
@ -33,7 +33,7 @@ class CustomSoundStream : public sf::SoundStream
|
||||
{
|
||||
public :
|
||||
PyObject *SoundStream;
|
||||
virtual bool OnStart();
|
||||
virtual void OnSeek(float TimeOffset);
|
||||
virtual bool OnGetData(Chunk& Data);
|
||||
void Init(unsigned int ChannelsCount, unsigned int SampleRate);
|
||||
};
|
||||
|
@ -22,7 +22,7 @@
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "String.hpp"
|
||||
#include "Text.hpp"
|
||||
#include "Font.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Rect.hpp"
|
||||
@ -35,7 +35,7 @@ extern PyTypeObject PySfFontType;
|
||||
|
||||
|
||||
static void
|
||||
PySfString_dealloc(PySfString *self)
|
||||
PySfText_dealloc(PySfText *self)
|
||||
{
|
||||
Py_CLEAR(self->font);
|
||||
delete self->obj;
|
||||
@ -43,50 +43,50 @@ PySfString_dealloc(PySfString *self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
PySfText_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfString *self;
|
||||
self = (PySfString *)type->tp_alloc(type, 0);
|
||||
PySfText *self;
|
||||
self = (PySfText *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->font = NULL;
|
||||
self->IsCustom = false;
|
||||
self->obj = new sf::String();
|
||||
self->obj = new sf::Text();
|
||||
}
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetText(PySfString* self, PyObject *args)
|
||||
PySfText_SetString(PySfText* self, PyObject *args)
|
||||
{
|
||||
char *Text, *EncodingStr=NULL;
|
||||
int Length;
|
||||
std::string Encoding;
|
||||
if (PyArg_ParseTuple(args, "u:String.SetText", &Text))
|
||||
if (PyArg_ParseTuple(args, "u:Text.SetString", &Text))
|
||||
{
|
||||
#if Py_UNICODE_SIZE == 4
|
||||
self->obj->SetText((sf::Uint32 *)Text);
|
||||
self->obj->SetString((sf::Uint32 *)Text);
|
||||
#else
|
||||
self->obj->SetText((sf::Uint16 *)Text);
|
||||
self->obj->SetString((sf::Uint16 *)Text);
|
||||
#endif
|
||||
}
|
||||
else if (PyArg_ParseTuple(args, "s|#s:String.SetText", &Text, &Length, &EncodingStr))
|
||||
else if (PyArg_ParseTuple(args, "s|#s:Text.SetString", &Text, &Length, &EncodingStr))
|
||||
{
|
||||
PyErr_Clear();
|
||||
if (EncodingStr == NULL)
|
||||
self->obj->SetText(sf::Unicode::UTF8String((sf::Uint8 *)Text));
|
||||
self->obj->SetString(Text);
|
||||
else
|
||||
{
|
||||
Encoding.assign(EncodingStr);
|
||||
if (Encoding == "utf8")
|
||||
self->obj->SetText(sf::Unicode::UTF8String((sf::Uint8 *)Text));
|
||||
self->obj->SetString(Text);
|
||||
else if (Encoding == "utf16")
|
||||
self->obj->SetText(sf::Unicode::UTF16String((sf::Uint16 *)(Text+2)));
|
||||
self->obj->SetString(Text+2);
|
||||
else if (Encoding == "utf32")
|
||||
self->obj->SetText(sf::Unicode::UTF32String((sf::Uint32 *)(Text+4)));
|
||||
self->obj->SetString(Text+4);
|
||||
else
|
||||
{
|
||||
PyErr_Format(PyExc_TypeError, "String.SetText() Encoding %s not supported", EncodingStr);
|
||||
PyErr_Format(PyExc_TypeError, "Text.SetString() Encoding %s not supported", EncodingStr);
|
||||
return NULL;
|
||||
}
|
||||
}
|
||||
@ -100,12 +100,12 @@ PySfString_SetText(PySfString* self, PyObject *args)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetFont(PySfString* self, PyObject *args)
|
||||
PySfText_SetFont(PySfText* self, PyObject *args)
|
||||
{
|
||||
PySfFont *Font = (PySfFont *)args;
|
||||
if (!PyObject_TypeCheck(Font, &PySfFontType))
|
||||
{
|
||||
PyErr_SetString(PyExc_ValueError, "String.SetFont() Argument must be a sf.Font");
|
||||
PyErr_SetString(PyExc_ValueError, "Text.SetFont() Argument must be a sf.Font");
|
||||
return NULL;
|
||||
}
|
||||
Py_CLEAR(self->font);
|
||||
@ -116,44 +116,44 @@ PySfString_SetFont(PySfString* self, PyObject *args)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetSize(PySfString* self, PyObject *args)
|
||||
PySfText_SetSize(PySfText* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetSize(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetSize(PySfString* self)
|
||||
PySfText_GetSize(PySfText* self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetSize());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetStyle(PySfString* self, PyObject *args)
|
||||
PySfText_SetStyle(PySfText* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetStyle(PyLong_AsUnsignedLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetStyle(PySfString* self)
|
||||
PySfText_GetStyle(PySfText* self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetStyle());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetText(PySfString* self)
|
||||
PySfText_GetString(PySfText* self)
|
||||
{
|
||||
#if Py_UNICODE_SIZE == 4
|
||||
sf::Unicode::UTF32String Text(self->obj->GetText());
|
||||
const sf::String& Text(self->obj->GetString());
|
||||
#else
|
||||
sf::Unicode::UTF16String Text(self->obj->GetText());
|
||||
const sf::String& Text(self->obj->GetString());
|
||||
#endif
|
||||
return PyUnicode_FromUnicode((const Py_UNICODE*)Text.c_str(), Text.length());
|
||||
return PyUnicode_FromUnicode((const Py_UNICODE*)Text.ToAnsiString().c_str(), Text.GetSize());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetFont(PySfString* self)
|
||||
PySfText_GetFont(PySfText* self)
|
||||
{
|
||||
if (self->font == NULL)
|
||||
{
|
||||
@ -170,7 +170,7 @@ PySfString_GetFont(PySfString* self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetRect(PySfString* self)
|
||||
PySfText_GetRect(PySfText* self)
|
||||
{
|
||||
PySfFloatRect *Rect;
|
||||
|
||||
@ -183,20 +183,20 @@ PySfString_GetRect(PySfString* self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetCharacterPos(PySfString* self, PyObject *args)
|
||||
PySfText_GetCharacterPos(PySfText* self, PyObject *args)
|
||||
{
|
||||
sf::Vector2f Pos = self->obj->GetCharacterPos(PyLong_AsUnsignedLong(args));
|
||||
return Py_BuildValue("ff", Pos.x, Pos.y);
|
||||
}
|
||||
|
||||
static int
|
||||
PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
|
||||
PySfText_init(PySfText *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Text", "Font", "Size", NULL};
|
||||
float Size = 30.f;
|
||||
PyObject *Text=NULL;
|
||||
PySfFont *Font = NULL;
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO!f:String.__new__", (char **)kwlist, &Text, &PySfFontType, &Font, &Size))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO!f:Text.__new__", (char **)kwlist, &Text, &PySfFontType, &Font, &Size))
|
||||
return -1;
|
||||
|
||||
if (Text != NULL)
|
||||
@ -204,52 +204,52 @@ PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
|
||||
if (PyUnicode_Check(Text))
|
||||
{
|
||||
#if Py_UNICODE_SIZE == 4
|
||||
self->obj->SetText((sf::Uint32 *)PyUnicode_AS_UNICODE(Text));
|
||||
self->obj->SetString((sf::Uint32 *)PyUnicode_AS_UNICODE(Text));
|
||||
#else
|
||||
self->obj->SetText((sf::Uint16 *)PyUnicode_AS_UNICODE(Text));
|
||||
self->obj->SetString((sf::Uint16 *)PyUnicode_AS_UNICODE(Text));
|
||||
#endif
|
||||
}
|
||||
#ifdef IS_PY3K
|
||||
else if (PyBytes_Check(Text))
|
||||
self->obj->SetText(sf::Unicode::UTF8String((sf::Uint8 *)PyBytes_AsString(Text)));
|
||||
self->obj->SetString(PyBytes_AsString(Text));
|
||||
#else
|
||||
else if (PyString_Check(Text))
|
||||
self->obj->SetText(sf::Unicode::UTF8String((sf::Uint8 *)PyString_AsString(Text)));
|
||||
self->obj->SetString(PyString_AsString(Text));
|
||||
#endif
|
||||
else
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "String.__init__() first argument must be str");
|
||||
PyErr_SetString(PyExc_TypeError, "Text.__init__() first argument must be str");
|
||||
return -1;
|
||||
}
|
||||
}
|
||||
if (Font) PySfString_SetFont(self, (PyObject *)Font);
|
||||
if (Font) PySfText_SetFont(self, (PyObject *)Font);
|
||||
self->obj->SetSize(Size);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfString_methods[] = {
|
||||
{"GetCharacterPos", (PyCFunction)PySfString_GetCharacterPos, METH_O, "GetCharacterPos(Index)\n\
|
||||
static PyMethodDef PySfText_methods[] = {
|
||||
{"GetCharacterPos", (PyCFunction)PySfText_GetCharacterPos, METH_O, "GetCharacterPos(Index)\n\
|
||||
Return the visual position (a tuple of two floats) of the Index-th character of the string, in coordinates relative to the string (note : translation, center, rotation and scale are not applied)\n\
|
||||
Index : Index of the character"},
|
||||
{"SetText", (PyCFunction)PySfString_SetText, METH_VARARGS, "SetText(UnicodeText) or SetText(Text, Encoding='utf8')\nSet the text. Valid encodings are 'utf8', 'utf16' and 'utf32'.\n Text : New text"},
|
||||
{"GetText", (PyCFunction)PySfString_GetText, METH_NOARGS, "GetText()\nGet the text as an unicode string."},
|
||||
{"SetFont", (PyCFunction)PySfString_SetFont, METH_O, "SetFont(Font)\nSet the font of the string.\n Font : font to use"},
|
||||
{"GetFont", (PyCFunction)PySfString_GetFont, METH_NOARGS, "GetFont()\nGet the font used by the string."},
|
||||
{"SetSize", (PyCFunction)PySfString_SetSize, METH_O, "SetSize(Size)\nSet the size of the string.\n Size : New size, in pixels"},
|
||||
{"GetSize", (PyCFunction)PySfString_GetSize, METH_NOARGS, "GetSize()\nGet the size of the characters."},
|
||||
{"SetStyle", (PyCFunction)PySfString_SetStyle, METH_O, "SetStyle(TextSize)\nSet the style of the text. The default style is Regular.\n TextSize : New text style, (combination of Style values)"},
|
||||
{"GetStyle", (PyCFunction)PySfString_GetStyle, METH_NOARGS, "GetStyle()\nGet the style of the text."},
|
||||
{"GetRect", (PyCFunction)PySfString_GetRect, METH_NOARGS, "GetRect()\nGet the string rectangle on screen."},
|
||||
{"SetString", (PyCFunction)PySfText_SetString, METH_VARARGS, "SetString(UnicodeText) or SetString(Text, Encoding='utf8')\nSet the text. Valid encodings are 'utf8', 'utf16' and 'utf32'.\n Text : New text"},
|
||||
{"GetString", (PyCFunction)PySfText_GetString, METH_NOARGS, "GetString()\nGet the text as an unicode string."},
|
||||
{"SetFont", (PyCFunction)PySfText_SetFont, METH_O, "SetFont(Font)\nSet the font of the string.\n Font : font to use"},
|
||||
{"GetFont", (PyCFunction)PySfText_GetFont, METH_NOARGS, "GetFont()\nGet the font used by the string."},
|
||||
{"SetSize", (PyCFunction)PySfText_SetSize, METH_O, "SetSize(Size)\nSet the size of the string.\n Size : New size, in pixels"},
|
||||
{"GetSize", (PyCFunction)PySfText_GetSize, METH_NOARGS, "GetSize()\nGet the size of the characters."},
|
||||
{"SetStyle", (PyCFunction)PySfText_SetStyle, METH_O, "SetStyle(TextSize)\nSet the style of the text. The default style is Regular.\n TextSize : New text style, (combination of Style values)"},
|
||||
{"GetStyle", (PyCFunction)PySfText_GetStyle, METH_NOARGS, "GetStyle()\nGet the style of the text."},
|
||||
{"GetRect", (PyCFunction)PySfText_GetRect, METH_NOARGS, "GetRect()\nGet the string rectangle on screen."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfStringType = {
|
||||
PyTypeObject PySfTextType = {
|
||||
head_init
|
||||
"String", /*tp_name*/
|
||||
sizeof(PySfString), /*tp_basicsize*/
|
||||
"Text", /*tp_name*/
|
||||
sizeof(PySfText), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfString_dealloc, /*tp_dealloc*/
|
||||
(destructor)PySfText_dealloc, /*tp_dealloc*/
|
||||
0, /*tp_print*/
|
||||
0, /*tp_getattr*/
|
||||
0, /*tp_setattr*/
|
||||
@ -265,15 +265,15 @@ PyTypeObject PySfStringType = {
|
||||
0, /*tp_setattro*/
|
||||
0, /*tp_as_buffer*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.String defines a graphical 2D text, that can be drawn on screen.\n\
|
||||
Default constructor : String ()\nConstruct the string from an unicode or an ascii string : String(Text, Font=sf.Font.GetDefaultFont(), Size=30.)\n Text : Text assigned to the string\n Font : Font used to draw the string (SFML built-in font by default)\n Size : Characters size (30 by default)", /* tp_doc */
|
||||
"sf.Text defines a graphical 2D text, that can be drawn on screen.\n\
|
||||
Default constructor : Text ()\nConstruct the string from an unicode or an ascii string : Text(Text, Font=sf.Font.GetDefaultFont(), Size=30.)\n Text : Text assigned to the string\n Font : Font used to draw the string (SFML built-in font by default)\n Size : Characters size (30 by default)", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfString_methods, /* tp_methods */
|
||||
PySfText_methods, /* tp_methods */
|
||||
0, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
@ -281,27 +281,27 @@ Default constructor : String ()\nConstruct the string from an unicode or an asci
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfString_init, /* tp_init */
|
||||
(initproc)PySfText_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfString_new, /* tp_new */
|
||||
PySfText_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
|
||||
void PySfString_InitConst()
|
||||
void PySfText_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyLong_FromLong(sf::String::Regular);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Regular", obj);
|
||||
obj = PyLong_FromLong(sf::Text::Regular);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Regular", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::String::Bold);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Bold", obj);
|
||||
obj = PyLong_FromLong(sf::Text::Bold);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Bold", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::String::Italic);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Italic", obj);
|
||||
obj = PyLong_FromLong(sf::Text::Italic);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Italic", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyLong_FromLong(sf::String::Underlined);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Underlined", obj);
|
||||
obj = PyLong_FromLong(sf::Text::Underlined);
|
||||
PyDict_SetItemString(PySfTextType.tp_dict, "Underlined", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
@ -27,17 +27,17 @@
|
||||
|
||||
#include <Python.h>
|
||||
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
#include <SFML/Graphics/Text.hpp>
|
||||
|
||||
#include "Font.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool IsCustom;
|
||||
sf::String *obj;
|
||||
sf::Text *obj;
|
||||
PySfFont *font;
|
||||
} PySfString;
|
||||
} PySfText;
|
||||
|
||||
void PySfString_InitConst();
|
||||
void PySfText_InitConst();
|
||||
|
||||
#endif
|
@ -69,32 +69,15 @@ PySfView_GetCenter(PySfView* self)
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_GetHalfSize(PySfView* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetHalfSize();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_GetRect(PySfView* self)
|
||||
{
|
||||
PySfFloatRect *Rect = GetNewPySfFloatRect();
|
||||
Rect->Owner = false;
|
||||
Rect->obj = (sf::FloatRect *) &(self->obj->GetRect());
|
||||
PySfFloatRectUpdateSelf(Rect);
|
||||
return (PyObject *)Rect;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_SetFromRect(PySfView* self, PyObject *args)
|
||||
PySfView_Reset(PySfView* self, PyObject *args)
|
||||
{
|
||||
PySfFloatRect *Rect = (PySfFloatRect *)args;
|
||||
if (!PyObject_TypeCheck(Rect, &PySfFloatRectType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "View.SetFromRect() Argument is not a sf.FloatRect instance");
|
||||
PyErr_SetString(PyExc_TypeError, "View.Reset() Argument is not a sf.FloatRect instance");
|
||||
return NULL;
|
||||
}
|
||||
self->obj->SetFromRect(*(Rect->obj));
|
||||
self->obj->Reset(*(Rect->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
@ -118,16 +101,6 @@ PySfView_SetCenter(PySfView* self, PyObject *args)
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_SetHalfSize(PySfView* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if (!PyArg_ParseTuple(args, "ff:View.SetHalfSize", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->SetHalfSize(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_Zoom(PySfView* self, PyObject *args)
|
||||
{
|
||||
@ -137,14 +110,11 @@ PySfView_Zoom(PySfView* self, PyObject *args)
|
||||
|
||||
static PyMethodDef PySfView_methods[] = {
|
||||
{"GetCenter", (PyCFunction)PySfView_GetCenter, METH_NOARGS, "GetCenter()\nGet the center of the view."},
|
||||
{"GetHalfSize", (PyCFunction)PySfView_GetHalfSize, METH_NOARGS, "GetHalfSize()\nGet the half-size of the view."},
|
||||
{"GetRect", (PyCFunction)PySfView_GetRect, METH_NOARGS, "GetRect()\nGet the bounding rectangle of the view."},
|
||||
{"Move", (PyCFunction)PySfView_Move, METH_VARARGS, "Move(OffsetX, OffsetY)\nMove the view.\n\
|
||||
OffsetX : Offset to move the view, on X axis\n\
|
||||
OffsetY : Offset to move the view, on Y axis"},
|
||||
{"SetFromRect", (PyCFunction)PySfView_SetFromRect, METH_O, "SetFromRect(ViewRect)\nRebuild the view from a rectangle.\n ViewRect : Rectangle defining the position and size of the view."},
|
||||
{"Reset", (PyCFunction)PySfView_Reset, METH_O, "Reset(ViewRect)\nRebuild the view from a rectangle.\n ViewRect : Rectangle defining the position and size of the view."},
|
||||
{"SetCenter", (PyCFunction)PySfView_SetCenter, METH_VARARGS, "SetCenter(X, Y)\nChange the center of the view."},
|
||||
{"SetHalfSize", (PyCFunction)PySfView_SetHalfSize, METH_VARARGS, "SetHalfSize(HalfWidth, HalfHeight)\nChange the half-size of the view."},
|
||||
{"Zoom", (PyCFunction)PySfView_Zoom, METH_O, "Zoom(Factor)\nResize the view rectangle to simulate a zoom / unzoom effect."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
@ -27,7 +27,7 @@
|
||||
#include "Event.hpp"
|
||||
#include "VideoMode.hpp"
|
||||
#include "Input.hpp"
|
||||
#include "WindowSettings.hpp"
|
||||
#include "ContextSettings.hpp"
|
||||
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
|
||||
@ -35,7 +35,7 @@
|
||||
|
||||
|
||||
extern PyTypeObject PySfEventType;
|
||||
extern PyTypeObject PySfWindowSettingsType;
|
||||
extern PyTypeObject PySfContextSettingsType;
|
||||
extern PyTypeObject PySfVideoModeType;
|
||||
|
||||
|
||||
@ -50,16 +50,16 @@ static PyObject *
|
||||
PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
long Handle;
|
||||
PySfWindowSettings *Params=NULL;
|
||||
PySfContextSettings *Params=NULL;
|
||||
PySfWindow *self;
|
||||
self = (PySfWindow *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfWindowSettingsType, &Params))
|
||||
if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfContextSettingsType, &Params))
|
||||
{
|
||||
if (Params)
|
||||
{
|
||||
PySfWindowSettingsUpdate(Params);
|
||||
PySfContextSettingsUpdate(Params);
|
||||
self->obj = new sf::Window((sf::WindowHandle)Handle, *(Params->obj));
|
||||
}
|
||||
else
|
||||
@ -124,18 +124,18 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
|
||||
sf::VideoMode *VideoMode;
|
||||
char *Title=NULL;
|
||||
unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close;
|
||||
PySfWindowSettings *Params=NULL;
|
||||
PySfContextSettings *Params=NULL;
|
||||
|
||||
const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL};
|
||||
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!:Window.Create", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &Params))
|
||||
if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!:Window.Create", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfContextSettingsType, &Params))
|
||||
return NULL;
|
||||
|
||||
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
||||
|
||||
if (Params)
|
||||
{
|
||||
PySfWindowSettingsUpdate(Params);
|
||||
PySfContextSettingsUpdate(Params);
|
||||
self->obj->Create(*VideoMode, Title, WindowStyle, *(Params->obj));
|
||||
}
|
||||
else
|
||||
@ -148,11 +148,11 @@ static int
|
||||
PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
long Handle;
|
||||
PySfWindowSettings *Params;
|
||||
PySfContextSettings *Params;
|
||||
|
||||
if (args != NULL)
|
||||
{
|
||||
if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfWindowSettingsType, &Params))
|
||||
if (PyArg_ParseTuple(args, "l|O!:Window.__new__", &Handle, &PySfContextSettingsType, &Params))
|
||||
return 0;
|
||||
PyErr_Clear();
|
||||
if (PySfWindow_Create(self, args, kwds) == NULL)
|
||||
@ -225,9 +225,9 @@ PySfWindow_GetInput(PySfWindow *self)
|
||||
static PyObject *
|
||||
PySfWindow_GetSettings(PySfWindow *self)
|
||||
{
|
||||
PySfWindowSettings *Settings;
|
||||
Settings = GetNewPySfWindowSettings();
|
||||
Settings->obj = new sf::WindowSettings(self->obj->GetSettings());
|
||||
PySfContextSettings *Settings;
|
||||
Settings = GetNewPySfContextSettings();
|
||||
Settings->obj = new sf::ContextSettings(self->obj->GetSettings());
|
||||
Settings->DepthBits = Settings->obj->DepthBits;
|
||||
Settings->StencilBits = Settings->obj->StencilBits;
|
||||
Settings->AntialiasingLevel = Settings->obj->AntialiasingLevel;
|
||||
@ -307,7 +307,7 @@ PySfWindow_SetIcon(PySfWindow* self, PyObject *args)
|
||||
|
||||
static PyMethodDef PySfWindow_methods[] = {
|
||||
{"Close", (PyCFunction)PySfWindow_Close, METH_NOARGS, "Close()\nClose (destroy) the window. The sf.Window instance remains valid and you can call Create to recreate the window."},
|
||||
{"Create", (PyCFunction)PySfWindow_Create, METH_VARARGS | METH_KEYWORDS, "Create(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.WindowSettings())\n\
|
||||
{"Create", (PyCFunction)PySfWindow_Create, METH_VARARGS | METH_KEYWORDS, "Create(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.ContextSettings())\n\
|
||||
Create a window.\n\
|
||||
Mode : Video mode to use (sf.VideoMode instance)\n\
|
||||
Title : Title of the window\n\
|
||||
@ -363,7 +363,7 @@ PyTypeObject PySfWindowType = {
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Window is a rendering window ; it can create a new window or connect to an existing one.\n\
|
||||
Default constructor : sf.Window()\n\
|
||||
Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.WindowSettings())\n\
|
||||
Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.ContextSettings())\n\
|
||||
Mode : Video mode to use (sf.VideoMode instance)\n\
|
||||
Title : Title of the window\n\
|
||||
WindowStyle : Window style (Resize | Close by default)\n\
|
||||
|
@ -30,9 +30,10 @@
|
||||
#include "Event.hpp"
|
||||
#include "Mouse.hpp"
|
||||
#include "WindowStyle.hpp"
|
||||
#include "ContextSettings.hpp"
|
||||
#include "Blend.hpp"
|
||||
#include "Sound.hpp"
|
||||
#include "String.hpp"
|
||||
#include "Text.hpp"
|
||||
#include "SoundStream.hpp"
|
||||
|
||||
#include "compat.hpp"
|
||||
@ -54,8 +55,8 @@ extern PyTypeObject PySfMouseType;
|
||||
|
||||
extern PyTypeObject PySfVideoModeType;
|
||||
extern PyTypeObject PySfWindowType;
|
||||
extern PyTypeObject PySfWindowSettingsType;
|
||||
extern PyTypeObject PySfStyleType;
|
||||
extern PyTypeObject PySfContextSettingsType;
|
||||
extern PyTypeObject PySfRenderWindowType;
|
||||
extern PyTypeObject PySfViewType;
|
||||
extern PyTypeObject PySfInputType;
|
||||
@ -65,8 +66,8 @@ extern PyTypeObject PySfBlendType;
|
||||
extern PyTypeObject PySfSpriteType;
|
||||
extern PyTypeObject PySfFontType;
|
||||
extern PyTypeObject PySfGlyphType;
|
||||
extern PyTypeObject PySfStringType;
|
||||
extern PyTypeObject PySfPostFXType;
|
||||
extern PyTypeObject PySfTextType;
|
||||
//extern PyTypeObject PySfPostFXType;
|
||||
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfColorType;
|
||||
@ -119,10 +120,10 @@ initsf(void)
|
||||
|
||||
if (PyType_Ready(&PySfWindowType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfWindowSettingsType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfStyleType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfContextSettingsType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfRenderWindowType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfVideoModeType) < 0)
|
||||
@ -167,10 +168,10 @@ initsf(void)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfGlyphType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfStringType) < 0)
|
||||
INITERROR;
|
||||
if (PyType_Ready(&PySfPostFXType) < 0)
|
||||
if (PyType_Ready(&PySfTextType) < 0)
|
||||
INITERROR;
|
||||
/*if (PyType_Ready(&PySfPostFXType) < 0)
|
||||
INITERROR;
*/
|
||||
|
||||
if (PyType_Ready(&PySfImageType) < 0)
|
||||
INITERROR;
|
||||
@ -215,10 +216,10 @@ initsf(void)
|
||||
|
||||
Py_INCREF(&PySfWindowType);
|
||||
PyModule_AddObject(m, "Window", (PyObject *)&PySfWindowType);
|
||||
Py_INCREF(&PySfWindowSettingsType);
|
||||
PyModule_AddObject(m, "WindowSettings", (PyObject *)&PySfWindowSettingsType);
|
||||
Py_INCREF(&PySfStyleType);
|
||||
PyModule_AddObject(m, "Style", (PyObject *)&PySfStyleType);
|
||||
Py_INCREF(&PySfContextSettingsType);
|
||||
PyModule_AddObject(m, "ContextSettings", (PyObject *)&PySfContextSettingsType);
|
||||
Py_INCREF(&PySfRenderWindowType);
|
||||
PyModule_AddObject(m, "RenderWindow", (PyObject *)&PySfRenderWindowType);
|
||||
Py_INCREF(&PySfVideoModeType);
|
||||
@ -238,10 +239,10 @@ initsf(void)
|
||||
PyModule_AddObject(m, "Font", (PyObject *)&PySfFontType);
|
||||
Py_INCREF(&PySfGlyphType);
|
||||
PyModule_AddObject(m, "Glyph", (PyObject *)&PySfGlyphType);
|
||||
Py_INCREF(&PySfStringType);
|
||||
PyModule_AddObject(m, "String", (PyObject *)&PySfStringType);
|
||||
Py_INCREF(&PySfPostFXType);
|
||||
PyModule_AddObject(m, "PostFX", (PyObject *)&PySfPostFXType);
|
||||
Py_INCREF(&PySfTextType);
|
||||
PyModule_AddObject(m, "Text", (PyObject *)&PySfTextType);
|
||||
/*Py_INCREF(&PySfPostFXType);
|
||||
PyModule_AddObject(m, "PostFX", (PyObject *)&PySfPostFXType);
*/
|
||||
|
||||
Py_INCREF(&PySfEventType);
|
||||
PyModule_AddObject(m, "Event", (PyObject *)&PySfEventType);
|
||||
@ -292,7 +293,7 @@ initsf(void)
|
||||
PySfBlend_InitConst();
|
||||
PySfSound_InitConst();
|
||||
PySfSoundStream_InitConst();
|
||||
PySfString_InitConst();
|
||||
PySfText_InitConst();
|
||||
|
||||
PyEval_InitThreads();
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user