Separated OpenGL contexts from Window implementations

Added support for OpenGL 3.0
Replaced WindowSettings with ContextSettings
Synchronized with trunk

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1065 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-03-28 16:22:58 +00:00
commit 9c370e38da
110 changed files with 2758 additions and 2335 deletions

View file

@ -47,7 +47,7 @@
/// \param Params : Creation settings /// \param Params : Creation settings
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfWindowSettings Params); CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfContextSettings Params);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a renderwindow from an existing control /// Construct a renderwindow from an existing control
@ -56,7 +56,7 @@ CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode Mode, const char* Ti
/// \param Params : Creation settings /// \param Params : Creation settings
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle Handle, sfWindowSettings Params); CSFML_API sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle Handle, sfContextSettings Params);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destroy an existing renderwindow /// Destroy an existing renderwindow
@ -110,7 +110,7 @@ CSFML_API unsigned int sfRenderWindow_GetHeight(sfRenderWindow* RenderWindow);
/// \return Settings used to create the window /// \return Settings used to create the window
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfWindowSettings sfRenderWindow_GetSettings(sfRenderWindow* RenderWindow); CSFML_API sfContextSettings sfRenderWindow_GetSettings(sfRenderWindow* RenderWindow);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the event on top of events stack of a window, if any, and pop it /// Get the event on top of events stack of a window, if any, and pop it

View file

@ -57,7 +57,7 @@ typedef struct
unsigned int DepthBits; ///< Bits of the depth buffer unsigned int DepthBits; ///< Bits of the depth buffer
unsigned int StencilBits; ///< Bits of the stencil buffer unsigned int StencilBits; ///< Bits of the stencil buffer
unsigned int AntialiasingLevel; ///< Level of antialiasing unsigned int AntialiasingLevel; ///< Level of antialiasing
} sfWindowSettings; } sfContextSettings;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@ -69,7 +69,7 @@ typedef struct
/// \param Params : Creation settings /// \param Params : Creation settings
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfWindowSettings Params); CSFML_API sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfContextSettings Params);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a window from an existing control /// Construct a window from an existing control
@ -78,7 +78,7 @@ CSFML_API sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigne
/// \param Params : Creation settings /// \param Params : Creation settings
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfWindow* sfWindow_CreateFromHandle(sfWindowHandle Handle, sfWindowSettings Params); CSFML_API sfWindow* sfWindow_CreateFromHandle(sfWindowHandle Handle, sfContextSettings Params);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destroy an existing window /// Destroy an existing window
@ -132,7 +132,7 @@ CSFML_API unsigned int sfWindow_GetHeight(sfWindow* Window);
/// \return Settings used to create the window /// \return Settings used to create the window
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
CSFML_API sfWindowSettings sfWindow_GetSettings(sfWindow* Window); CSFML_API sfContextSettings sfWindow_GetSettings(sfWindow* Window);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the event on top of events stack of a window, if any, and pop it /// Get the event on top of events stack of a window, if any, and pop it

View file

@ -86,14 +86,14 @@ struct sfRenderWindow
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a new renderwindow /// Construct a new renderwindow
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfWindowSettings Params) sfRenderWindow* sfRenderWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfContextSettings Params)
{ {
// Convert video mode // Convert video mode
sf::VideoMode VideoMode(Mode.Width, Mode.Height, Mode.BitsPerPixel); sf::VideoMode VideoMode(Mode.Width, Mode.Height, Mode.BitsPerPixel);
// Create the window // Create the window
sfRenderWindow* RenderWindow = new sfRenderWindow; sfRenderWindow* RenderWindow = new sfRenderWindow;
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel); sf::ContextSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
RenderWindow->This.Create(VideoMode, Title, Style, Settings); RenderWindow->This.Create(VideoMode, Title, Style, Settings);
RenderWindow->Input.This = &RenderWindow->This.GetInput(); RenderWindow->Input.This = &RenderWindow->This.GetInput();
RenderWindow->DefaultView.This = &RenderWindow->This.GetDefaultView(); RenderWindow->DefaultView.This = &RenderWindow->This.GetDefaultView();
@ -106,10 +106,10 @@ sfRenderWindow* sfRenderWindow_Create(sfVideoMode Mode, const char* Title, unsig
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a renderwindow from an existing control /// Construct a renderwindow from an existing control
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle Handle, sfWindowSettings Params) sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle Handle, sfContextSettings Params)
{ {
sfRenderWindow* RenderWindow = new sfRenderWindow; sfRenderWindow* RenderWindow = new sfRenderWindow;
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel); sf::ContextSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
RenderWindow->This.Create(Handle, Settings); RenderWindow->This.Create(Handle, Settings);
RenderWindow->Input.This = &RenderWindow->This.GetInput(); RenderWindow->Input.This = &RenderWindow->This.GetInput();
RenderWindow->DefaultView.This = &RenderWindow->This.GetDefaultView(); RenderWindow->DefaultView.This = &RenderWindow->This.GetDefaultView();
@ -166,12 +166,12 @@ unsigned int sfRenderWindow_GetHeight(sfRenderWindow* RenderWindow)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the creation settings of a window /// Get the creation settings of a window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfWindowSettings sfRenderWindow_GetSettings(sfRenderWindow* RenderWindow) sfContextSettings sfRenderWindow_GetSettings(sfRenderWindow* RenderWindow)
{ {
sfWindowSettings Settings = {0, 0, 0}; sfContextSettings Settings = {0, 0, 0};
CSFML_CHECK_RETURN(RenderWindow, Settings); CSFML_CHECK_RETURN(RenderWindow, Settings);
const sf::WindowSettings& Params = RenderWindow->This.GetSettings(); const sf::ContextSettings& Params = RenderWindow->This.GetSettings();
Settings.DepthBits = Params.DepthBits; Settings.DepthBits = Params.DepthBits;
Settings.StencilBits = Params.StencilBits; Settings.StencilBits = Params.StencilBits;
Settings.AntialiasingLevel = Params.AntialiasingLevel; Settings.AntialiasingLevel = Params.AntialiasingLevel;

View file

@ -3,8 +3,7 @@ export CPP = g++
export CFLAGS = -W -Wall -pedantic -fPIC -Wno-unused -I../.. -I../../../include -DNDEBUG -DCSFML_EXPORTS -O2 export CFLAGS = -W -Wall -pedantic -fPIC -Wno-unused -I../.. -I../../../include -DNDEBUG -DCSFML_EXPORTS -O2
export LDFLAGS = -shared export LDFLAGS = -shared
export LIBPATH = ../../../lib export LIBPATH = ../../../lib
export VERSION = 2.0 export VERSION = 2.0export CP = cp
export CP = cp
export LN = ln export LN = ln
export LNFLAGS = -s -f export LNFLAGS = -s -f
export DESTDIR = /usr export DESTDIR = /usr

View file

@ -32,7 +32,11 @@
struct sfContext struct sfContext
{ {
sf::Context This; sfContext() : This(sf::Context::New()) {}
~sfContext() {delete This;}
sf::Context* This;
}; };
@ -59,5 +63,5 @@ void sfContext_Destroy(sfContext* Context)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfContext_SetActive(sfContext* Context, sfBool Active) void sfContext_SetActive(sfContext* Context, sfBool Active)
{ {
CSFML_CALL(Context, SetActive(Active == sfTrue)) CSFML_CALL_PTR(Context, SetActive(Active == sfTrue))
} }

View file

@ -46,14 +46,14 @@ struct sfWindow
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a new window /// Construct a new window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfWindowSettings Params) sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfContextSettings Params)
{ {
// Convert video mode // Convert video mode
sf::VideoMode VideoMode(Mode.Width, Mode.Height, Mode.BitsPerPixel); sf::VideoMode VideoMode(Mode.Width, Mode.Height, Mode.BitsPerPixel);
// Create the window // Create the window
sfWindow* Window = new sfWindow; sfWindow* Window = new sfWindow;
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel); sf::ContextSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
Window->This.Create(VideoMode, Title, Style, Settings); Window->This.Create(VideoMode, Title, Style, Settings);
Window->Input.This = &Window->This.GetInput(); Window->Input.This = &Window->This.GetInput();
@ -64,10 +64,10 @@ sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Sty
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct a window from an existing control /// Construct a window from an existing control
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfWindow* sfWindow_CreateFromHandle(sfWindowHandle Handle, sfWindowSettings Params) sfWindow* sfWindow_CreateFromHandle(sfWindowHandle Handle, sfContextSettings Params)
{ {
sfWindow* Window = new sfWindow; sfWindow* Window = new sfWindow;
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel); sf::ContextSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
Window->This.Create(Handle, Settings); Window->This.Create(Handle, Settings);
Window->Input.This = &Window->This.GetInput(); Window->Input.This = &Window->This.GetInput();
@ -122,12 +122,12 @@ unsigned int sfWindow_GetHeight(sfWindow* Window)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the creation settings of a window /// Get the creation settings of a window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfWindowSettings sfWindow_GetSettings(sfWindow* Window) sfContextSettings sfWindow_GetSettings(sfWindow* Window)
{ {
sfWindowSettings Settings = {0, 0, 0}; sfContextSettings Settings = {0, 0, 0};
CSFML_CHECK_RETURN(Window, Settings); CSFML_CHECK_RETURN(Window, Settings);
const sf::WindowSettings& Params = Window->This.GetSettings(); const sf::ContextSettings& Params = Window->This.GetSettings();
Settings.DepthBits = Params.DepthBits; Settings.DepthBits = Params.DepthBits;
Settings.StencilBits = Params.StencilBits; Settings.StencilBits = Params.StencilBits;
Settings.AntialiasingLevel = Params.AntialiasingLevel; Settings.AntialiasingLevel = Params.AntialiasingLevel;

View file

@ -109,14 +109,13 @@
<Add library="libgdi32.a" /> <Add library="libgdi32.a" />
</Linker> </Linker>
<Unit filename="..\..\include\SFML\Window\Context.hpp" /> <Unit filename="..\..\include\SFML\Window\Context.hpp" />
<Unit filename="..\..\include\SFML\Window\ContextSettings.hpp" />
<Unit filename="..\..\include\SFML\Window\Event.hpp" /> <Unit filename="..\..\include\SFML\Window\Event.hpp" />
<Unit filename="..\..\include\SFML\Window\Input.hpp" /> <Unit filename="..\..\include\SFML\Window\Input.hpp" />
<Unit filename="..\..\include\SFML\Window\OpenGL.hpp" />
<Unit filename="..\..\include\SFML\Window\VideoMode.hpp" /> <Unit filename="..\..\include\SFML\Window\VideoMode.hpp" />
<Unit filename="..\..\include\SFML\Window\Window.hpp" /> <Unit filename="..\..\include\SFML\Window\Window.hpp" />
<Unit filename="..\..\include\SFML\Window\WindowHandle.hpp" /> <Unit filename="..\..\include\SFML\Window\WindowHandle.hpp" />
<Unit filename="..\..\include\SFML\Window\WindowListener.hpp" /> <Unit filename="..\..\include\SFML\Window\WindowListener.hpp" />
<Unit filename="..\..\include\SFML\Window\WindowSettings.hpp" />
<Unit filename="..\..\include\SFML\Window\WindowStyle.hpp" /> <Unit filename="..\..\include\SFML\Window\WindowStyle.hpp" />
<Unit filename="..\..\include\SFML\Window\glew\glew.h" /> <Unit filename="..\..\include\SFML\Window\glew\glew.h" />
<Unit filename="..\..\src\SFML\Window\Context.cpp" /> <Unit filename="..\..\src\SFML\Window\Context.cpp" />
@ -124,6 +123,8 @@
<Unit filename="..\..\src\SFML\Window\Joystick.hpp" /> <Unit filename="..\..\src\SFML\Window\Joystick.hpp" />
<Unit filename="..\..\src\SFML\Window\VideoMode.cpp" /> <Unit filename="..\..\src\SFML\Window\VideoMode.cpp" />
<Unit filename="..\..\src\SFML\Window\VideoModeSupport.hpp" /> <Unit filename="..\..\src\SFML\Window\VideoModeSupport.hpp" />
<Unit filename="..\..\src\SFML\Window\Win32\ContextWGL.cpp" />
<Unit filename="..\..\src\SFML\Window\Win32\ContextWGL.hpp" />
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.cpp" /> <Unit filename="..\..\src\SFML\Window\Win32\Joystick.cpp" />
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.hpp" /> <Unit filename="..\..\src\SFML\Window\Win32\Joystick.hpp" />
<Unit filename="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp" /> <Unit filename="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp" />

View file

@ -351,6 +351,14 @@
<Filter <Filter
Name="Win32" Name="Win32"
> >
<File
RelativePath="..\..\src\SFML\Window\Win32\ContextWGL.cpp"
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Win32\ContextWGL.hpp"
>
</File>
<File <File
RelativePath="..\..\src\SFML\Window\Win32\Joystick.cpp" RelativePath="..\..\src\SFML\Window\Win32\Joystick.cpp"
> >
@ -396,7 +404,7 @@
> >
</File> </File>
<File <File
RelativePath="..\..\..\src\SFML\Window\Win32\VideoModeSupport.hpp" RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.hpp"
> >
</File> </File>
<File <File
@ -448,6 +456,10 @@
RelativePath="..\..\include\SFML\Window\Context.hpp" RelativePath="..\..\include\SFML\Window\Context.hpp"
> >
</File> </File>
<File
RelativePath="..\..\include\SFML\Window\ContextSettings.hpp"
>
</File>
<File <File
RelativePath="..\..\include\SFML\Window\Event.hpp" RelativePath="..\..\include\SFML\Window\Event.hpp"
> >
@ -504,10 +516,6 @@
RelativePath="..\..\include\SFML\Window\WindowListener.hpp" RelativePath="..\..\include\SFML\Window\WindowListener.hpp"
> >
</File> </File>
<File
RelativePath="..\..\include\SFML\Window\WindowSettings.hpp"
>
</File>
<File <File
RelativePath="..\..\include\SFML\Window\WindowStyle.hpp" RelativePath="..\..\include\SFML\Window\WindowStyle.hpp"
> >

View file

@ -342,6 +342,14 @@
<Filter <Filter
Name="Win32" Name="Win32"
> >
<File
RelativePath="..\..\src\SFML\Window\Win32\ContextWGL.cpp"
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Win32\ContextWGL.hpp"
>
</File>
<File <File
RelativePath="..\..\src\SFML\Window\Win32\Joystick.cpp" RelativePath="..\..\src\SFML\Window\Win32\Joystick.cpp"
> >
@ -407,6 +415,10 @@
RelativePath="..\..\include\SFML\Window\Context.hpp" RelativePath="..\..\include\SFML\Window\Context.hpp"
> >
</File> </File>
<File
RelativePath="..\..\include\SFML\Window\ContextSettings.hpp"
>
</File>
<File <File
RelativePath="..\..\src\SFML\Window\Event.hpp" RelativePath="..\..\src\SFML\Window\Event.hpp"
> >
@ -423,10 +435,6 @@
RelativePath="..\..\src\SFML\Window\Joystick.hpp" RelativePath="..\..\src\SFML\Window\Joystick.hpp"
> >
</File> </File>
<File
RelativePath="..\..\include\SFML\Window\OpenGL.hpp"
>
</File>
<File <File
RelativePath="..\..\src\SFML\Window\VideoMode.cpp" RelativePath="..\..\src\SFML\Window\VideoMode.cpp"
> >
@ -463,10 +471,6 @@
RelativePath="..\..\src\SFML\Window\WindowListener.hpp" RelativePath="..\..\src\SFML\Window\WindowListener.hpp"
> >
</File> </File>
<File
RelativePath="..\..\include\SFML\Window\WindowSettings.hpp"
>
</File>
<File <File
RelativePath="..\..\src\SFML\Window\WindowStyle.hpp" RelativePath="..\..\src\SFML\Window\WindowStyle.hpp"
> >

View file

@ -161,9 +161,10 @@ public :
/// \param DestX : X coordinate of the destination position /// \param DestX : X coordinate of the destination position
/// \param DestY : Y coordinate of the destination position /// \param DestY : Y coordinate of the destination position
/// \param SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image) /// \param SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)
/// \param ApplyAlpha : Should the copy take in account the source transparency? (false by default)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0)); void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0), bool ApplyAlpha = false);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Create the image from the current contents of the /// Create the image from the current contents of the

View file

@ -58,19 +58,19 @@ public :
/// \param Mode : Video mode to use /// \param Mode : Video mode to use
/// \param Title : Title of the window /// \param Title : Title of the window
/// \param WindowStyle : Window style (Resize | Close by default) /// \param WindowStyle : Window style (Resize | Close by default)
/// \param Params : Creation parameters (see default constructor for default values) /// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings()); RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const ContextSettings& Settings = ContextSettings());
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct the window from an existing control /// Construct the window from an existing control
/// ///
/// \param Handle : Platform-specific handle of the control /// \param Handle : Platform-specific handle of the control
/// \param Params : Creation parameters (see default constructor for default values) /// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderWindow(WindowHandle Handle, const WindowSettings& Params = WindowSettings()); RenderWindow(WindowHandle Handle, const ContextSettings& Settings = ContextSettings());
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destructor /// Destructor

View file

@ -30,7 +30,13 @@
/// This file just includes the OpenGL (GL and GLU) headers, /// This file just includes the OpenGL (GL and GLU) headers,
/// which have actually different paths on each system /// which have actually different paths on each system
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#if defined(SFML_SYSTEM_WINDOWS) || defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD) #if defined(SFML_SYSTEM_WINDOWS)
#include <windows.h>
#include <GL/gl.h>
#include <GL/glu.h>
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
#include <GL/gl.h> #include <GL/gl.h>
#include <GL/glu.h> #include <GL/glu.h>

View file

@ -277,7 +277,7 @@ private :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Static member data // Static member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static const char UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence static const int UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence
static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions
static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences
}; };

View file

@ -104,7 +104,7 @@ inline Out Unicode::UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement
while (Begin < End) while (Begin < End)
{ {
Uint32 c = 0; Uint32 c = 0;
int TrailingBytes = UTF8TrailingBytes[*Begin]; int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
if (Begin + TrailingBytes < End) if (Begin + TrailingBytes < End)
{ {
// First decode the UTF-8 character // First decode the UTF-8 character
@ -165,7 +165,7 @@ inline Out Unicode::UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement
while (Begin < End) while (Begin < End)
{ {
Uint32 c = 0; Uint32 c = 0;
int TrailingBytes = UTF8TrailingBytes[*Begin]; int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
if (Begin + TrailingBytes < End) if (Begin + TrailingBytes < End)
{ {
// First decode the UTF-8 character // First decode the UTF-8 character
@ -424,7 +424,7 @@ inline std::size_t Unicode::GetUTF8Length(In Begin, In End)
std::size_t Length = 0; std::size_t Length = 0;
while (Begin < End) while (Begin < End)
{ {
int NbBytes = UTF8TrailingBytes[*Begin]; int NbBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];
if (Begin + NbBytes < End) if (Begin + NbBytes < End)
++Length; ++Length;

View file

@ -37,7 +37,6 @@
#include <SFML/Window/Window.hpp> #include <SFML/Window/Window.hpp>
#include <SFML/Window/WindowListener.hpp> #include <SFML/Window/WindowListener.hpp>
#include <SFML/Window/WindowStyle.hpp> #include <SFML/Window/WindowStyle.hpp>
#include <SFML/Window/OpenGL.hpp>
#endif // SFML_SFML_WINDOW_HPP #endif // SFML_SFML_WINDOW_HPP

View file

@ -29,6 +29,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Config.hpp> #include <SFML/Config.hpp>
#include <SFML/Window/ContextSettings.hpp>
#include <SFML/System/NonCopyable.hpp> #include <SFML/System/NonCopyable.hpp>
@ -36,62 +37,132 @@ namespace sf
{ {
namespace priv namespace priv
{ {
class WindowImpl; class WindowImpl;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Class wrapping an OpenGL context. /// Abstract class representing an OpenGL context
/// All SFML windows already have their own context, so
/// this class is more a helper for specific issues involving
/// OpenGL and multi-threading.
/// It's meant to be used internally.
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
class SFML_API Context : NonCopyable class SFML_API Context : NonCopyable
{ {
public : public :
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Default constructor, create the context /// Create a new context, not associated to a window
///
/// \return Pointer to the created context
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Context(); static Context* New();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destructor, destroy the context /// Create a new context attached to a window
///
/// \param Owner : Pointer to the owner window
/// \param BitsPerPixel : Pixel depth (in bits per pixel)
/// \param Settings : Creation parameters
///
/// \return Pointer to the created context
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
~Context(); static Context* New(const priv::WindowImpl* Owner, unsigned int BitsPerPixel, const ContextSettings& Settings);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Activate or deactivate the context /// Check if a context is active on the current thread
/// ///
/// \param Active : True to activate the context, false to deactivate it /// \return True if there's an active context, false otherwise
///
////////////////////////////////////////////////////////////
void SetActive(bool Active);
////////////////////////////////////////////////////////////
/// Check if there's a context bound to the current thread
///
/// \return True if there's a context bound to the current thread
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static bool IsContextActive(); static bool IsContextActive();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the global context /// Return the default context
/// ///
/// \return Reference to the global context /// \return Reference to the default context
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
static Context& GetGlobal(); static Context& GetDefault();
private : public :
////////////////////////////////////////////////////////////
/// Virtual destructor
///
////////////////////////////////////////////////////////////
virtual ~Context();
////////////////////////////////////////////////////////////
/// Get the settings of the context
///
/// \return Structure containing the settings
///
////////////////////////////////////////////////////////////
const ContextSettings& GetSettings() const;
////////////////////////////////////////////////////////////
/// Activate or deactivate the context as the current target
/// for rendering
///
/// \param Active : True to activate, false to deactivate
///
/// \return True if operation was successful, false otherwise
///
////////////////////////////////////////////////////////////
bool SetActive(bool Active);
////////////////////////////////////////////////////////////
/// Display the contents of the context
///
////////////////////////////////////////////////////////////
virtual void Display() = 0;
////////////////////////////////////////////////////////////
/// Enable / disable vertical synchronization
///
/// \param Enabled : True to enable v-sync, false to deactivate
///
////////////////////////////////////////////////////////////
virtual void UseVerticalSync(bool Enabled) = 0;
protected :
////////////////////////////////////////////////////////////
/// Default constructor
///
////////////////////////////////////////////////////////////
Context();
////////////////////////////////////////////////////////////
/// Make this context the current one
///
/// \param Active : True to activate, false to deactivate
///
/// \return True on success, false if any error happened
///
////////////////////////////////////////////////////////////
virtual bool MakeCurrent(bool Active) = 0;
////////////////////////////////////////////////////////////
/// Evaluate a pixel format configuration.
/// This functions can be used by implementations that have
/// several valid formats and want to get the best one
///
/// \param BitsPerPixel : Requested pixel depth (bits per pixel)
/// \param Settings : Requested additionnal settings
/// \param ColorBits : Color bits of the configuration to evaluate
/// \param DepthBits : Depth bits of the configuration to evaluate
/// \param StencilBits : Stencil bits of the configuration to evaluate
/// \param Antialiasing : Antialiasing level of the configuration to evaluate
///
/// \return Score of the configuration : the lower the better
///
////////////////////////////////////////////////////////////
static int EvaluateFormat(unsigned int BitsPerPixel, const ContextSettings& Settings, int ColorBits, int DepthBits, int StencilBits, int Antialiasing);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::WindowImpl* myDummyWindow; ///< Dummy window holding the context ContextSettings mySettings; ///< Creation settings of the context
}; };
} // namespace sf } // namespace sf

View file

@ -22,16 +22,17 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#ifndef SFML_WINDOWSETTINGS_HPP #ifndef SFML_CONTEXTSETTINGS_HPP
#define SFML_WINDOWSETTINGS_HPP #define SFML_CONTEXTSETTINGS_HPP
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Structure defining the creation settings of windows /// Structure defining the settings of the OpenGL
/// context attached to a window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
struct WindowSettings struct ContextSettings
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Default constructor /// Default constructor
@ -41,7 +42,7 @@ struct WindowSettings
/// \param Antialiasing : Antialiasing level (0 by default) /// \param Antialiasing : Antialiasing level (0 by default)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
explicit WindowSettings(unsigned int Depth = 24, unsigned int Stencil = 8, unsigned int Antialiasing = 0) : explicit ContextSettings(unsigned int Depth = 24, unsigned int Stencil = 8, unsigned int Antialiasing = 0) :
DepthBits (Depth), DepthBits (Depth),
StencilBits (Stencil), StencilBits (Stencil),
AntialiasingLevel(Antialiasing) AntialiasingLevel(Antialiasing)
@ -59,4 +60,4 @@ struct WindowSettings
} // namespace sf } // namespace sf
#endif // SFML_WINDOWSETTINGS_HPP #endif // SFML_CONTEXTSETTINGS_HPP

View file

@ -33,7 +33,7 @@
#include <SFML/Window/VideoMode.hpp> #include <SFML/Window/VideoMode.hpp>
#include <SFML/Window/WindowHandle.hpp> #include <SFML/Window/WindowHandle.hpp>
#include <SFML/Window/WindowListener.hpp> #include <SFML/Window/WindowListener.hpp>
#include <SFML/Window/WindowSettings.hpp> #include <SFML/Window/ContextSettings.hpp>
#include <SFML/Window/WindowStyle.hpp> #include <SFML/Window/WindowStyle.hpp>
#include <SFML/System/Clock.hpp> #include <SFML/System/Clock.hpp>
#include <SFML/System/NonCopyable.hpp> #include <SFML/System/NonCopyable.hpp>
@ -48,6 +48,8 @@ namespace priv
class WindowImpl; class WindowImpl;
} }
class Context;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Window is a rendering window ; it can create a new window /// Window is a rendering window ; it can create a new window
/// or connect to an existing one /// or connect to an existing one
@ -68,19 +70,19 @@ public :
/// \param Mode : Video mode to use /// \param Mode : Video mode to use
/// \param Title : Title of the window /// \param Title : Title of the window
/// \param WindowStyle : Window style (Resize | Close by default) /// \param WindowStyle : Window style (Resize | Close by default)
/// \param Params : Creation parameters (see default constructor for default values) /// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings()); Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const ContextSettings& Settings = ContextSettings());
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct the window from an existing control /// Construct the window from an existing control
/// ///
/// \param Handle : Platform-specific handle of the control /// \param Handle : Platform-specific handle of the control
/// \param Params : Creation parameters (see default constructor for default values) /// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Window(WindowHandle Handle, const WindowSettings& Params = WindowSettings()); Window(WindowHandle Handle, const ContextSettings& Settings = ContextSettings());
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Destructor /// Destructor
@ -94,19 +96,19 @@ public :
/// \param Mode : Video mode to use /// \param Mode : Video mode to use
/// \param Title : Title of the window /// \param Title : Title of the window
/// \param WindowStyle : Window style (Resize | Close by default) /// \param WindowStyle : Window style (Resize | Close by default)
/// \param Params : Creation parameters (see default constructor for default values) /// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings()); void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const ContextSettings& Settings = ContextSettings());
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Create (or recreate) the window from an existing control /// Create (or recreate) the window from an existing control
/// ///
/// \param Handle : Platform-specific handle of the control /// \param Handle : Platform-specific handle of the control
/// \param Params : Creation parameters (see default constructor for default values) /// \param Settings : Additional settings for the underlying OpenGL context (see default constructor for default values)
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Create(WindowHandle Handle, const WindowSettings& Params = WindowSettings()); void Create(WindowHandle Handle, const ContextSettings& Settings = ContextSettings());
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Close (destroy) the window. /// Close (destroy) the window.
@ -143,12 +145,12 @@ public :
unsigned int GetHeight() const; unsigned int GetHeight() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the creation settings of the window /// Get the settinsg of the OpenGL context of the window
/// ///
/// \return Structure containing the creation settings /// \return Structure containing the context settings
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
const WindowSettings& GetSettings() const; const ContextSettings& GetSettings() const;
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Get the event on top of events stack, if any, and pop it /// Get the event on top of events stack, if any, and pop it
@ -232,7 +234,7 @@ public :
void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels); void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Activate of deactivate the window as the current target /// Activate or deactivate the window as the current target
/// for rendering /// for rendering
/// ///
/// \param Active : True to activate, false to deactivate (true by default) /// \param Active : True to activate, false to deactivate (true by default)
@ -298,21 +300,19 @@ private :
virtual void OnEvent(const Event& EventReceived); virtual void OnEvent(const Event& EventReceived);
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Initialize internal window /// Do some common internal initializations
///
/// \param Impl : New internal window implementation
/// ///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Initialize(priv::WindowImpl* Impl); void Initialize();
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Member data // Member data
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
priv::WindowImpl* myWindow; ///< Platform-specific implementation of window priv::WindowImpl* myWindow; ///< Platform-specific implementation of the window
Context* myContext; ///< Platform-specific implementation of the OpenGL context
std::queue<Event> myEvents; ///< Queue of received events std::queue<Event> myEvents; ///< Queue of received events
Input myInput; ///< Input manager connected to window Input myInput; ///< Input manager connected to window
Clock myClock; ///< Clock for measuring the elapsed time between frames Clock myClock; ///< Clock for measuring the elapsed time between frames
WindowSettings mySettings; ///< Creation settings of the window
float myLastFrameTime; ///< Time elapsed since last frame float myLastFrameTime; ///< Time elapsed since last frame
bool myIsExternal; ///< Tell whether the window is internal or external (created by SFML or not) bool myIsExternal; ///< Tell whether the window is internal or external (created by SFML or not)
unsigned int myFramerateLimit; ///< Current framerate limit unsigned int myFramerateLimit; ///< Current framerate limit

View file

@ -1,6 +1,6 @@
Metadata-Version: 1.0 Metadata-Version: 1.0
Name: PySFML Name: PySFML
Version: 1.4 Version: 1.5
Summary: Python binding for SFML (Simple and Fast Multimedia Library) Summary: Python binding for SFML (Simple and Fast Multimedia Library)
Home-page: http://sfml.sourceforge.net/ Home-page: http://sfml.sourceforge.net/
Author: Rémi Koenig Author: Rémi Koenig

View file

@ -1,2 +1 @@
import sf

View file

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

View file

@ -1,6 +1,6 @@
#!/usr/bin/env python #!/usr/bin/env python
from PySFML import * from PySFML import sf
def Main(): def Main():
# Check that the device can capture audio # Check that the device can capture audio

View file

@ -0,0 +1,67 @@
#!/usr/bin/env python
from PySFML import sf
def Main():
# Check that the device can capture audio
if sf.SoundRecorder.CanCapture() == False:
print("Sorry, audio capture is not supported by your system")
return
# Choose the sample rate
SampleRate = int(input("Please choose the sample rate for sound capture (44100 is CD quality) : "))
# Wait for user input...
print("Press enter to start recording audio")
input()
# Here we'll use an integrated custom recorder, which saves the captured data into a sfSoundBuffer
Recorder = sf.SoundBufferRecorder()
# Audio capture is done in a separate thread, so we can block the main thread while it is capturing
Recorder.Start(SampleRate)
print("Recording... press enter to stop")
input()
Recorder.Stop()
# Get the buffer containing the captured data
Buffer = Recorder.GetBuffer()
# Display captured sound informations
print("Sound information :")
print(" " + str(Buffer.GetDuration()) + " seconds")
print(" " + str(Buffer.GetSampleRate()) + " samples / seconds")
print(" " + str(Buffer.GetChannelsCount()) + " channels")
# Choose what to do with the recorded sound data
Choice = str(input("What do you want to do with captured sound (p = play, s = save) ? "))
if Choice == 's':
# Choose the filename
Filename = str(input("Choose the file to create : "))
# Save the buffer
Buffer.SaveToFile(Filename);
else:
# Create a sound instance and play it
Sound = sf.Sound(Buffer)
Sound.Play()
# Wait until finished
while Sound.GetStatus() == sf.Sound.Playing:
# Display the playing position - I don't know how to do this in python
# std::cout << "\rPlaying... " << std::fixed << std::setprecision(2) << Sound.GetPlayingOffset() << " sec";
# Leave some CPU time for other threads
sf.Sleep(0.1)
# Finished !
print("Done !")
# Wait until the user presses 'enter' key
print("Press enter to exit...")
input()
return
Main()

View file

@ -0,0 +1,49 @@
#!/usr/bin/python
from PySFML import sf
class MyCustomStream(sf.SoundStream):
def Open(self, Filename):
# Load the sound data into a sound buffer
self.SoundData = sf.SoundBuffer()
if not self.SoundData.LoadFromFile(Filename):
return False
# Initialize the stream with the sound parameters
self.Initialize(self.SoundData.GetChannelsCount(), self.SoundData.GetSampleRate())
# Copy the audio samples into our internal array
self.myBuffer = self.SoundData.GetSamples()
return True
def OnStart(self):
self.myOffset = 0
self.myBufferSize = 80000
return True
def OnGetData(self):
# Check if there is enough data to stream
if self.myOffset > len(self.myBuffer):
# Returning something else than a string means that we want to stop playing the stream
return False
# Data contains the string of samples we will return
if self.myOffset + self.myBufferSize >= len(self.myBuffer):
print("End of audio data reached")
Data = self.myBuffer[self.myOffset:]
else:
Data = self.myBuffer[self.myOffset:self.myOffset+self.myBufferSize]
# Update the offset
self.myOffset = self.myBufferSize + self.myOffset
return Data
def Main():
Stream = MyCustomStream()
Stream.Open("./data/fart.wav")
Stream.Play()
print("Playing 5 seconds of audio data...")
sf.Sleep(5)
Stream.Stop()
print("Press enter to exit...")
input()
Main()

View file

@ -1,240 +1,277 @@
#!/usr/bin/python #!/usr/bin/python
from PySFML import * from PySFML import sf
import math import math
import random import random
import sys
class Menu:
def __init__(self, screen_width, screen_height):
self.selection = 0
text_color = sf.Color(220, 220, 20, 255)
self.spacing = screen_height/7
self.title = sf.String("PyWorm!")
self.title.SetColor(text_color)
self.title.SetPosition(screen_width/2-80., self.spacing)
levels = ["Very Easy", "Easy", "Medium", "Hard"]
x_align = [-80., -50., -70., -50.]
self.strings = []
for i in range(0, 4):
string = sf.String(levels[i])
string.SetColor(text_color)
string.SetPosition(screen_width/2+x_align[i], (2+i)*self.spacing+20)
self.strings.append(string)
self.rectangle = sf.Shape.Rectangle(0, 0, screen_width, 40, sf.Color(50, 50, 10))
def next_frame(self, win):
self.rectangle.SetY(self.spacing*(2 + self.selection)+20)
win.Draw(self.rectangle)
win.Draw(self.title)
win.Draw(self.strings)
def key_up(self, pressed):
if pressed:
self.selection = (self.selection - 1) % 4
def key_down(self, pressed):
if pressed:
self.selection = (self.selection + 1) % 4
def Game(Difficulty):
PartsPerFrame = 1 + Difficulty # Number of drawn base parts each frame class Apple(sf.Sprite):
PartsSpacing = 3 # Each worm's base part is separated by PartsSpacing pixels def __init__(self):
TurnStep = 0.15 # Turn the worm's head of 0.15 rad apple_img = sf.Image() # Apple's image
if not apple_img.LoadFromFile("./data/apple.png"):
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.size = apple_img.GetWidth()
PartSize = 6.0 # worm's base part size for collision def random_move(self, arena):
PartRealSize = 18.0 # worm's real base part size for drawing self.SetPosition( \
random.randrange(arena.arena_left+arena.border, arena.arena_right-arena.border), \
# Load images random.randrange(arena.arena_top+arena.border, arena.arena_bottom-arena.border) \
Rond = sf.Image() # Image containing the base part of the worm )
if not Rond.LoadFromFile("./data/rond2.png"):
print "Could not load data/rond2.png"
return
WormPart = sf.Sprite(Rond)
WormPart.SetCenter(Rond.GetWidth()/2, Rond.GetHeight()/2)
AppleImg = sf.Image() # Apple's image
if not AppleImg.LoadFromFile("./data/apple.png"):
print "Could not load data/apple.png"
return
Apple = sf.Sprite(AppleImg, 0, 0, 1, 1, 0) # Corresponding sprite
Black = sf.Color(0,0,0,255)
UglyYellow = sf.Color(220, 220, 20, 255)
Stop = False
Event = sf.Event() # Our events manager
Level = 0
ShrinkValue = 20
Border = 30
ArenaTop = 20
ArenaBottom = 520
RequiredLength = 300
ExitLeft = 350
ExitRight = 450
ExitImg = sf.Image(ExitRight-ExitLeft, ArenaTop, Black)
Exit = sf.Sprite(ExitImg, ExitLeft, 0, 1, 1, 0)
Score = 0
HeadX, HeadY = 0, 0
while not Stop:
#Initialize a new game
Level += 1
ArenaLeft = ShrinkValue*Level
ArenaRight = 800-ShrinkValue*Level
ArenaImg = sf.Image(ArenaRight-ArenaLeft, ArenaBottom-ArenaTop, Black)
Arena = sf.Sprite(ArenaImg, ArenaLeft, ArenaTop, 1, 1, 0)
AppleX, AppleY = random.randrange(ArenaLeft+Border, ArenaRight-Border), random.randrange(ArenaTop+Border, ArenaBottom-Border)
Apple.SetX(AppleX - AppleImg.GetWidth()/2) # We move the apple to somewhere else, randomly
Apple.SetY(AppleY - AppleImg.GetHeight()/2)
Crash = False
Running = True
LevelStr = sf.String("Level: " + str(Level))
LevelStr.SetPosition(60., 540.)
LevelStr.SetColor(UglyYellow)
ScoreStr = sf.String("Score: 0")
ScoreStr.SetPosition(260., 540.)
ScoreStr.SetColor(UglyYellow)
Length = 1
TargetedLength = 30
Worm = [[ArenaLeft+50., ArenaTop+50.]]
Angle = 0
i = 0
Dir = 0
while Running: # Game main loop
while App.GetEvent(Event): # Event Handler
if Event.Type == sf.Event.Closed:
App.Close()
return
if Event.Type == sf.Event.KeyPressed:
if Event.Key.Code == sf.Key.Escape:
Running = False
Stop = True
if Event.Key.Code == sf.Key.Left:
Dir = -1
if Event.Key.Code == sf.Key.Right:
Dir = 1
if Crash and Length<=1:
Running = False
if Event.Type == sf.Event.KeyReleased:
if Event.Key.Code == sf.Key.Left and Dir == -1:
Dir = 0
if Event.Key.Code == sf.Key.Right and Dir == 1:
Dir = 0
App.Draw(Arena)
if not Crash: # Create new parts and check collisions if the worm hasn't crashed yet class Arena(dict):
for i in range(0, PartsPerFrame): # We create PartsPerFrame Worm's parts shrink_value, border, arena_top = 20, 30, 20
Angle += Dir*TurnStep def __init__(self, window_width, window_height):
HeadX, HeadY = Worm[Length-1][0]+PartsSpacing*math.cos(Angle), Worm[Length-1][1]+PartsSpacing*math.sin(Angle) self.window_width = window_width
if TargetedLength <= RequiredLength: self.arena_bottom, self.exit_left, self.exit_right = window_height-80, window_width/2 - 50, window_width/2 + 50
if math.sqrt ( (AppleX - HeadX)**2 + (AppleY - HeadY)**2 ) < 14 + PartSize/2: # The Worm ate the apple self['level_str'] = sf.String()
Score += 1 self['level_str'].SetColor(sf.Color.White)
TargetedLength += 20 # The worm gets longer self['level_str'].SetPosition(60., window_height-60)
if TargetedLength <= RequiredLength: self['score_str'] = sf.String()
AppleX, AppleY = random.randrange(ArenaLeft+Border, ArenaRight-Border), random.randrange(ArenaTop+Border, ArenaBottom-Border) self['score_str'].SetColor(sf.Color.White)
Apple.SetX(AppleX - AppleImg.GetWidth()/2) # We move the apple to somewhere else, randomly self['score_str'].SetPosition(260., window_height-60)
Apple.SetY(AppleY - AppleImg.GetHeight()/2) self.exit_rect = sf.Shape.Rectangle(self.exit_left, 0, self.exit_right, self.arena_top, sf.Color.Black)
App.Draw(Apple) self.reset()
self.update_arena_rect()
if HeadX<ArenaLeft+PartSize/2 or HeadX>ArenaRight-PartSize/2 or HeadY<ArenaTop+PartSize/2 or HeadY>ArenaBottom-PartSize/2: # Crash into a wall def update_arena_rect(self):
if Length > RequiredLength: self['arena_rect'] = sf.Shape.Rectangle(self.arena_left, self.arena_top, self.arena_right, self.arena_bottom, sf.Color.Black)
if HeadY<ArenaTop+PartSize/2:
if HeadX<ExitLeft+PartSize/2 or HeadX>ExitRight-PartSize/2:
Crash = True
elif HeadY < 0:
Length = 0
Running = False # Level completed!
else:
Crash = True
elif Running:
Crash = True
if not Crash:
Worm.append([HeadX, HeadY])
Length += 1
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")
if TargetedLength > RequiredLength: def update_score(self):
App.Draw(Exit) self.score += 1
self['score_str'].SetText("Score: " + str(self.score))
if Length >= TargetedLength: def next_level(self):
Worm[0:TargetedLength] = Worm[Length-TargetedLength:Length] self.level += 1
for i in range(Length, TargetedLength): self['level_str'].SetText("Level: " + str(self.level))
del Worm[i] self.arena_left += self.shrink_value
Worm[TargetedLength:Length] = [] self.arena_right -= self.shrink_value
Length = TargetedLength self.update_arena_rect()
self.score += 4
self.update_score()
for i in range(0, Length): class Part(sf.Sprite):
WormPart.SetPosition(Worm[i][0], Worm[i][1]) def __init__(self, rond, x, y):
App.Draw(WormPart) # Draw the part on screen sf.Sprite.__init__(self, rond)
if i < Length - PartSize/PartsSpacing - 1: self.SetCenter(rond.GetWidth()/2, rond.GetHeight()/2)
if math.sqrt( (HeadX-Worm[i][0])**2 + (HeadY-Worm[i][1])**2 ) < PartSize and Running: # Check for collision self.SetPosition(x, y)
Crash = True
if Crash and Length>0: class Worm(list):
TargetedLength -= PartsPerFrame parts_spacing, turn_step, part_size, start_x, start_y, required_length, grow_length = 3, 0.15, 6.0, 50., 50., 300, 20
def __init__(self, difficulty):
self.parts_per_frame = 1 + difficulty
self.angle = 0
self.direction = 0 # 0, 1 or -1 according to the key pressed
self.rond = sf.Image()
self.level_completed = False
if not self.rond.LoadFromFile("./data/rond2.png"):
pass
# print "Could not load data/rond2.png"
ScoreStr.SetText("Score: " + str(Score)) def reset(self, arena):
self.targeted_length, self.angle, self.direction = 30, 0, 0
self[:] = [Part(self.rond, arena.arena_left+self.start_x, arena.arena_top+self.start_y)]
App.Draw(ScoreStr) def left(self, pressed):
App.Draw(LevelStr) if pressed:
App.Display() # Refresh Screen self.direction = -1
App.Clear(BGColor) elif self.direction == -1:
self.direction = 0
def right(self, pressed):
# End of the game if pressed:
if Crash: self.direction = 1
Level = 0 elif self.direction == 1:
Score = 0 self.direction = 0
def restart(self, arena):
if self.targeted_length == 0 and not self.level_completed:
arena.reset()
self.reset(arena)
return True
else: else:
Score += 5 # End level bonus return False
del Worm def crash(self):
del Arena self.targeted_length = 0
del ArenaImg
def Menu(): def move(self, arena, apple):
head_x, head_y = -1, -1
if self.is_running(): # Create new parts and check collisions if the worm hasn't crashed yet
for i in range(self.parts_per_frame): # We create PartsPerFrame Worm's parts
self.angle += self.direction*self.turn_step
head_x, head_y = self[-1].GetPosition()
head_x += self.parts_spacing*math.cos(self.angle)
head_y += self.parts_spacing*math.sin(self.angle)
if self.is_running() and self.targeted_length <= self.required_length: # let's check if the worm ate the apple
if math.hypot(apple.GetPosition()[0] - head_x, apple.GetPosition()[1] - head_y) < apple.size/2 + self.part_size/2: # Yes it did
arena.update_score()
self.targeted_length += self.grow_length # The worm gets longer
apple.random_move(arena)
if head_x<arena.arena_left+self.part_size/2 or head_x>arena.arena_right-self.part_size/2 or head_y<arena.arena_top+self.part_size/2 or head_y>arena.arena_bottom-self.part_size/2: # Crash into a wall
if len(self) > self.required_length:
if head_y<arena.arena_top+self.part_size/2:
if head_x<arena.exit_left+self.part_size/2 or head_x>arena.exit_right-self.part_size/2: # Crash into the exit walls
self.crash()
elif head_y < 0:
self.level_completed = True
self.targeted_length = 0
else:
self.crash()
elif self.is_running():
self.crash()
if self.is_running():
self.append(Part(self.rond, head_x, head_y))
if len(self) > self.targeted_length:
if len(self) - self.targeted_length >= self.parts_per_frame:
del self[0:self.parts_per_frame]
else:
del self[0:len(self) - self.targeted_length]
Selection = 0 if (head_x, head_y) == (-1, -1) and len(self) > 0:
head_x, head_y = self[-1].GetPosition()
TextColor = sf.Color(220, 220, 20, 255) if len(self) > self.part_size/self.parts_spacing + 1:
for i in range(len(self)):
if i < len(self) - self.part_size/self.parts_spacing - 1:
test_x, test_y = self[i].GetPosition()
if math.hypot(head_x-test_x, head_y-test_y) < self.part_size and self.is_running(): # Check for collision
self.crash()
Running = True if len(self) == 0:
Event = sf.Event() if self.level_completed:
self.level_completed = False
arena.next_level()
self.reset(arena)
Title = sf.String("PyWorm!") def is_running(self):
Title.SetX(320.) return (self.targeted_length > 0) and not self.level_completed
Title.SetY(50.) def draw_exit(self):
Title.SetColor(TextColor) return self.targeted_length > self.required_length or self.level_completed
Levels = ["Very Easy", "Easy", "Medium", "Hard"] class Game:
Xs = [320., 350., 330., 350.] def __init__(self, difficulty, window_width, window_height):
Strings = [0,0,0,0] self.arena = Arena(window_width, window_height)
for i in range(0, 4): self.worm = Worm(difficulty)
Strings[i] = sf.String(Levels[i]) self.worm.reset(self.arena)
Strings[i].SetColor(TextColor) self.apple = Apple()
Strings[i].SetPosition(Xs[i], 200. + 80*i) self.apple.random_move(self.arena)
self.pause = False
RectangleImg = sf.Image(ScreenWidth, 40, sf.Color(50,50,10,255)) def enter(self, pressed):
Rectangle = sf.Sprite(RectangleImg, 0, 350, 1, 1, 0) if pressed:
if not self.worm.restart(self.arena):
self.pause = not self.pause
while App.IsOpened(): # Game main loop def next_frame(self, win):
while App.GetEvent(Event): # Event Handler win.Draw(self.arena.values())
if Event.Type == sf.Event.Closed: if not self.pause:
App.Close() self.worm.move(self.arena, self.apple)
if Event.Type == sf.Event.KeyPressed: if self.worm.draw_exit():
if Event.Key.Code == sf.Key.Escape: win.Draw(self.arena.exit_rect)
App.Close() elif self.worm.is_running():
elif Event.Key.Code == sf.Key.Up: win.Draw(self.apple)
Selection = (Selection - 1) % 4 win.Draw(self.worm)
elif Event.Key.Code == sf.Key.Down:
Selection = (Selection + 1) % 4
elif Event.Key.Code == sf.Key.Return:
Game(Selection)
Rectangle.SetY(200 + Selection*80)
App.Draw(Rectangle)
App.Draw(Title)
for i in range(0,4):
App.Draw(Strings[i])
App.Display()
App.Clear(BGColor)
# Initialize the window class Main:
ScreenWidth, ScreenHeight = 800, 600 # Entry Point
App = sf.RenderWindow(sf.VideoMode(ScreenWidth,ScreenHeight,32), "PyWorm", sf.Style.Close) # Creates the window def __init__(self):
BGColor = sf.Color(100,100,0,255) # Initialize the window
App.SetFramerateLimit(30) self.win = sf.RenderWindow(sf.VideoMode(800, 600,32), "PyWorm", sf.Style.Close) # Creates the window
Menu() self.win.EnableKeyRepeat(False)
background_color = sf.Color(100, 100, 0, 255)
self.win.SetFramerateLimit(30)
event = sf.Event()
self.keys = {} # keys to watch
self.menu_begin()
# Boucle principale
while self.win.IsOpened():
while self.win.GetEvent(event): # Event Handler
if event.Type == sf.Event.Closed:
self.win.Close()
elif event.Type == sf.Event.KeyPressed:
for key in self.keys:
if event.Key.Code == key:
self.keys[key](True)
elif event.Type == sf.Event.KeyReleased:
for key in self.keys:
if event.Key.Code == key:
self.keys[key](False)
self.win.Display()
self.win.Clear(background_color)
self.next_frame(self.win)
# Menu
def menu_begin(self):
self.menu = Menu(self.win.GetWidth(), self.win.GetHeight())
self.keys = {sf.Key.Escape:self.close_window, sf.Key.Up:self.menu.key_up, sf.Key.Down:self.menu.key_down, sf.Key.Return:self.menu_end}
self.next_frame = self.menu.next_frame
def close_window(self, pressed):
if pressed:
self.win.Close()
def menu_end(self, pressed):
if pressed:
selection = self.menu.selection
del self.menu
self.game_begin(selection)
# Game
def game_begin(self, selection):
self.game = Game(selection, self.win.GetWidth(), self.win.GetHeight())
self.keys = {sf.Key.Left:self.game.worm.left, sf.Key.Right:self.game.worm.right, sf.Key.Return:self.game.enter, sf.Key.Escape:self.game_end}
self.next_frame = self.game.next_frame
def game_end(self, pressed):
if pressed:
del self.game
self.menu_begin()
Main()

View file

@ -4,7 +4,7 @@
from distutils.core import setup, Extension from distutils.core import setup, Extension
setup(name='PySFML', setup(name='PySFML',
version='1.4', version='1.5',
description='Python binding for SFML (Simple and Fast Multimedia Library)', description='Python binding for SFML (Simple and Fast Multimedia Library)',
author='Rémi Koenig', author='Rémi Koenig',
author_email='remi.k2620@gmail.com', author_email='remi.k2620@gmail.com',
@ -12,8 +12,8 @@ setup(name='PySFML',
license='zlib/png', license='zlib/png',
ext_modules=[ Extension('PySFML.sf', \ ext_modules=[ Extension('PySFML.sf', \
['src/Clock.cpp', 'src/Color.cpp', 'src/Drawable.cpp', \ ['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/Event.cpp', 'src/Image.cpp', 'src/Input.cpp', 'src/Key.cpp', 'src/main.cpp', 'src/Music.cpp', \
'src/Music.cpp', 'src/PostFX.cpp', 'src/Rect.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/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/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/SoundBuffer.cpp', 'src/Listener.cpp', 'src/SoundRecorder.cpp', 'src/SoundBufferRecorder.cpp', \

View file

@ -22,62 +22,26 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics/Drawable.hpp>
#include <Python.h>
#include <structmember.h>
#include "Blend.hpp" #include "Blend.hpp"
#include "compat.hpp"
typedef struct {
PyObject_HEAD
} PySfBlend;
static PyMemberDef PySfBlend_members[] = {
{NULL} /* Sentinel */
};
static void
PySfBlend_dealloc(PySfBlend *self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * static PyObject *
PySfBlend_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfBlend_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfBlend *self; PySfBlend *self;
self = (PySfBlend *)type->tp_alloc(type, 0); self = (PySfBlend *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int
PySfBlend_init(PySfBlend *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyMethodDef PySfBlend_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject PySfBlendType = { PyTypeObject PySfBlendType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Blend", /*tp_name*/ "Blend", /*tp_name*/
sizeof(PySfBlend), /*tp_basicsize*/ sizeof(PySfBlend), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)PySfBlend_dealloc, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
@ -104,15 +68,15 @@ None No blending.", /* tp_doc */
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfBlend_methods, /* tp_methods */ 0, /* tp_methods */
PySfBlend_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)PySfBlend_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PySfBlend_new, /* tp_new */ PySfBlend_new, /* tp_new */
}; };
@ -120,16 +84,16 @@ None No blending.", /* tp_doc */
void PySfBlend_InitConst() void PySfBlend_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::Blend::Alpha); obj = PyLong_FromLong(sf::Blend::Alpha);
PyDict_SetItemString(PySfBlendType.tp_dict, "Alpha", obj); PyDict_SetItemString(PySfBlendType.tp_dict, "Alpha", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Blend::Add); obj = PyLong_FromLong(sf::Blend::Add);
PyDict_SetItemString(PySfBlendType.tp_dict, "Add", obj); PyDict_SetItemString(PySfBlendType.tp_dict, "Add", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Blend::Multiply); obj = PyLong_FromLong(sf::Blend::Multiply);
PyDict_SetItemString(PySfBlendType.tp_dict, "Multiply", obj); PyDict_SetItemString(PySfBlendType.tp_dict, "Multiply", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Blend::None); obj = PyLong_FromLong(sf::Blend::None);
PyDict_SetItemString(PySfBlendType.tp_dict, "None", obj); PyDict_SetItemString(PySfBlendType.tp_dict, "None", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View file

@ -25,6 +25,14 @@
#ifndef __PYBLEND_HPP #ifndef __PYBLEND_HPP
#define __PYBLEND_HPP #define __PYBLEND_HPP
#include <Python.h>
#include <SFML/Graphics/Drawable.hpp>
typedef struct {
PyObject_HEAD
} PySfBlend;
void void
PySfBlend_InitConst(); PySfBlend_InitConst();

View file

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

View file

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

View file

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

View file

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

View file

@ -23,50 +23,46 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "Drawable.hpp" #include "Drawable.hpp"
#include "Color.hpp"
void CustomDrawable::Render (sf::RenderTarget& Target) const #include "compat.hpp"
{
if (RenderFunction)
PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow);
}
extern PyTypeObject PySfColorType; extern PyTypeObject PySfColorType;
static PyMemberDef PySfDrawable_members[] = {
{NULL} /* Sentinel */
};
void CustomDrawable::Render(sf::RenderTarget& Target) const
{
if (RenderFunction)
PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow);
else
PyErr_SetString(PyExc_RuntimeError, "Custom drawables must have a render method defined");
}
static void static void
PySfDrawable_dealloc(PySfDrawable *self) PySfDrawable_dealloc(PySfDrawable *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfDrawable_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfDrawable_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfDrawable *self; PySfDrawable *self;
self = (PySfDrawable *)type->tp_alloc(type, 0); self = (PySfDrawable *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int static int
PySfDrawable_init(PySfDrawable *self, PyObject *args, PyObject *kwds) PySfDrawable_init(PySfDrawable *self, PyObject *args, PyObject *kwds)
{ {
self->obj = new CustomDrawable(); self->obj = new CustomDrawable();
self->obj->RenderFunction = NULL;
self->obj->RenderWindow = NULL;
return 0; return 0;
} }
static PyObject * static PyObject *
PySfDrawable_SetX(PySfDrawable* self, PyObject *args) PySfDrawable_SetX(PySfDrawable* self, PyObject *args)
{ {
@ -83,7 +79,7 @@ static PyObject *
PySfDrawable_SetScale(PySfDrawable* self, PyObject *args) PySfDrawable_SetScale(PySfDrawable* self, PyObject *args)
{ {
float ScaleX, ScaleY; float ScaleX, ScaleY;
if ( !PyArg_ParseTuple(args, "ff", &ScaleX, &ScaleY) ) if (!PyArg_ParseTuple(args, "ff:Drawable.SetScale", &ScaleX, &ScaleY) )
return NULL; return NULL;
self->obj->SetScale(ScaleX, ScaleY); self->obj->SetScale(ScaleX, ScaleY);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -111,7 +107,7 @@ static PyObject *
PySfDrawable_SetCenter(PySfDrawable* self, PyObject *args) PySfDrawable_SetCenter(PySfDrawable* self, PyObject *args)
{ {
float x, y; float x, y;
if ( !PyArg_ParseTuple(args, "ff", &x, &y) ) if (!PyArg_ParseTuple(args, "ff:Drawable.SetCenter", &x, &y) )
return NULL; return NULL;
self->obj->SetCenter(x, y); self->obj->SetCenter(x, y);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -129,7 +125,7 @@ PySfDrawable_SetColor(PySfDrawable* self, PyObject *args)
PySfColor *Color = (PySfColor *)args; PySfColor *Color = (PySfColor *)args;
if (! PyObject_TypeCheck(args, &PySfColorType)) if (! PyObject_TypeCheck(args, &PySfColorType))
{ {
PyErr_SetString(PyExc_TypeError, "Argument is not a sfColor"); PyErr_SetString(PyExc_TypeError, "Drawable.SetColor() Argument is not a sf.Color");
return NULL; return NULL;
} }
PySfColorUpdate(Color); PySfColorUpdate(Color);
@ -172,7 +168,7 @@ static PyObject *
PySfDrawable_Move(PySfDrawable* self, PyObject *args) PySfDrawable_Move(PySfDrawable* self, PyObject *args)
{ {
float x, y; float x, y;
if ( !PyArg_ParseTuple(args, "ff", &x, &y) ) if (!PyArg_ParseTuple(args, "ff:Drawable.Move", &x, &y) )
return NULL; return NULL;
self->obj->Move(x, y); self->obj->Move(x, y);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -187,7 +183,7 @@ static PyObject *
PySfDrawable_Scale(PySfDrawable* self, PyObject *args) PySfDrawable_Scale(PySfDrawable* self, PyObject *args)
{ {
float FactorX, FactorY; float FactorX, FactorY;
if ( !PyArg_ParseTuple(args, "ff", &FactorX, &FactorY) ) if (!PyArg_ParseTuple(args, "ff:Drawable.Scale", &FactorX, &FactorY) )
return NULL; return NULL;
self->obj->Scale(FactorX, FactorY); self->obj->Scale(FactorX, FactorY);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -204,7 +200,7 @@ static PyObject *
PySfDrawable_SetPosition(PySfDrawable* self, PyObject *args) PySfDrawable_SetPosition(PySfDrawable* self, PyObject *args)
{ {
float Left, Top; float Left, Top;
if ( !PyArg_ParseTuple(args, "ff", &Left, &Top) ) if (!PyArg_ParseTuple(args, "ff:Drawable.SetPosition", &Left, &Top) )
return NULL; return NULL;
self->obj->SetPosition(Left, Top); self->obj->SetPosition(Left, Top);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -214,7 +210,7 @@ static PyObject *
PySfDrawable_TransformToLocal(PySfDrawable* self, PyObject *args) PySfDrawable_TransformToLocal(PySfDrawable* self, PyObject *args)
{ {
float X, Y; float X, Y;
if ( !PyArg_ParseTuple(args, "ff", &X, &Y) ) if (!PyArg_ParseTuple(args, "ff:Drawable.TransformToLocal", &X, &Y) )
return NULL; return NULL;
sf::Vector2f result = self->obj->TransformToLocal(sf::Vector2f(X, Y)); sf::Vector2f result = self->obj->TransformToLocal(sf::Vector2f(X, Y));
return Py_BuildValue("ff", result.x, result.y); return Py_BuildValue("ff", result.x, result.y);
@ -224,7 +220,7 @@ static PyObject *
PySfDrawable_TransformToGlobal(PySfDrawable* self, PyObject *args) PySfDrawable_TransformToGlobal(PySfDrawable* self, PyObject *args)
{ {
float X, Y; float X, Y;
if ( !PyArg_ParseTuple(args, "ff", &X, &Y) ) if (!PyArg_ParseTuple(args, "ff:Drawable.TransformToGlobal", &X, &Y) )
return NULL; return NULL;
sf::Vector2f result = self->obj->TransformToGlobal(sf::Vector2f(X, Y)); sf::Vector2f result = self->obj->TransformToGlobal(sf::Vector2f(X, Y));
return Py_BuildValue("ff", result.x, result.y); return Py_BuildValue("ff", result.x, result.y);
@ -261,8 +257,7 @@ Transform a point from local coordinates into global coordinates (ie it applies
}; };
PyTypeObject PySfDrawableType = { PyTypeObject PySfDrawableType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Drawable", /*tp_name*/ "Drawable", /*tp_name*/
sizeof(PySfDrawable), /*tp_basicsize*/ sizeof(PySfDrawable), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -290,7 +285,7 @@ PyTypeObject PySfDrawableType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfDrawable_methods, /* tp_methods */ PySfDrawable_methods, /* tp_methods */
PySfDrawable_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -302,4 +297,10 @@ PyTypeObject PySfDrawableType = {
PySfDrawable_new, /* tp_new */ PySfDrawable_new, /* tp_new */
}; };
PySfDrawable *
GetNewPySfDrawable()
{
return (PySfDrawable *)PySfDrawable_new(&PySfDrawableType, NULL, NULL);
}

View file

@ -25,13 +25,10 @@
#ifndef __PYDRAWABLE_H #ifndef __PYDRAWABLE_H
#define __PYDRAWABLE_H #define __PYDRAWABLE_H
#include <SFML/Graphics/Drawable.hpp>
#include <SFML/Graphics/RenderWindow.hpp>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "Color.hpp" #include <SFML/Graphics/Drawable.hpp>
#include "RenderWindow.hpp" #include "RenderWindow.hpp"
@ -50,5 +47,8 @@ typedef struct {
CustomDrawable *obj; CustomDrawable *obj;
} PySfDrawable; } PySfDrawable;
PySfDrawable *
GetNewPySfDrawable();
#endif #endif

View file

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

View file

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

View file

@ -25,10 +25,7 @@
#include "Font.hpp" #include "Font.hpp"
#include "Glyph.hpp" #include "Glyph.hpp"
static PyMemberDef PySfFont_members[] = { #include "compat.hpp"
{NULL} /* Sentinel */
};
static void static void
@ -36,21 +33,16 @@ PySfFont_dealloc(PySfFont *self)
{ {
if (self->Owner) if (self->Owner)
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfFont_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfFont_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfFont *self; PySfFont *self;
self = (PySfFont *)type->tp_alloc(type, 0); self = (PySfFont *)type->tp_alloc(type, 0);
if (self != NULL) if (self != NULL)
{
self->Owner = true; self->Owner = true;
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -67,27 +59,48 @@ PySfFont_LoadFromFile(PySfFont* self, PyObject *args, PyObject *kwds)
const char *kwlist[] = {"Filename", "Charsize", "Charset", NULL}; const char *kwlist[] = {"Filename", "Charsize", "Charset", NULL};
unsigned int Charsize=30; unsigned int Charsize=30;
char *Filename; char *Filename;
char *CharsetTmp = NULL; char *Charset=NULL, *EncodingStr;
int CharsetSize; int Length;
bool Result; bool result;
std::string Encoding;
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|Is#", (char **)kwlist, &Filename, &Charsize, &CharsetTmp, &CharsetSize)) if (PyArg_ParseTupleAndKeywords(args, kwds, "s|I:Font.LoadFromFile", (char **)kwlist, &Filename, &Charsize))
return NULL; result = self->obj->LoadFromFile(Filename, Charsize);
else if (PyArg_ParseTupleAndKeywords(args, kwds, "s|Iu:Font.LoadFromFile", (char **)kwlist, &Filename, &Charsize, &Charset))
if (CharsetTmp)
{ {
if ((unsigned char)CharsetTmp[0] == 0xff && (unsigned char)CharsetTmp[1] == 0xfe) PyErr_Clear();
Result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::Text((const sf::Uint16 *)(CharsetTmp+2))); #if Py_UNICODE_SIZE == 4
result = self->obj->LoadFromFile(Filename, Charsize, (sf::Uint32 *)Charset);
#else
result = self->obj->LoadFromFile(Filename, Charsize, (sf::Uint16 *)Charset);
#endif
}
else if (PyArg_ParseTupleAndKeywords(args, kwds, "s|Is#s:Font.LoadFromFile", (char **)kwlist, &Filename, &Charsize, &Charset, &Length, &EncodingStr))
{
PyErr_Clear();
if (EncodingStr == NULL)
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
else else
Result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::Text((const sf::Uint8 *)CharsetTmp)); {
Encoding.assign(EncodingStr);
if (Encoding == "utf8" || Encoding == "")
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
else if (Encoding == "utf16")
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF16String((sf::Uint16 *)(Charset+2)));
else if (Encoding == "utf32")
result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::UTF32String((sf::Uint32 *)(Charset+4)));
else
{
PyErr_Format(PyExc_TypeError, "Font.LoadFromFile() Encoding %s not supported", EncodingStr);
return NULL;
}
}
} }
else else
Result = self->obj->LoadFromFile(Filename, Charsize); {
PyErr_BadArgument();
if (Result) return NULL;
Py_RETURN_TRUE; }
else return PyBool_FromLong(result);
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
@ -96,27 +109,48 @@ PySfFont_LoadFromMemory(PySfFont* self, PyObject *args, PyObject *kwds)
const char *kwlist[] = {"Data", "Charsize", "Charset", NULL}; const char *kwlist[] = {"Data", "Charsize", "Charset", NULL};
unsigned int Charsize=30, Size; unsigned int Charsize=30, Size;
char *Data; char *Data;
char *CharsetTmp = NULL; char *Charset=NULL, *EncodingStr;
int CharsetSize; int Length;
bool Result; bool result;
std::string Encoding;
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s#|Is#", (char **)kwlist, &Data, &Size, &Charsize, &CharsetTmp, &CharsetSize)) if (PyArg_ParseTupleAndKeywords(args, kwds, "s#|I:Font.LoadFromMemory", (char **)kwlist, &Data, &Size, &Charsize))
return NULL; result = self->obj->LoadFromMemory(Data, Size, Charsize);
else if (PyArg_ParseTupleAndKeywords(args, kwds, "s#|Iu:Font.LoadFromMemory", (char **)kwlist, &Data, &Size, &Charsize, &Charset))
if (CharsetTmp)
{ {
if ((unsigned char)CharsetTmp[0] == 0xff && (unsigned char)CharsetTmp[1] == 0xfe) PyErr_Clear();
Result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::Text((const sf::Uint16 *)(CharsetTmp+2))); #if Py_UNICODE_SIZE == 4
result = self->obj->LoadFromMemory(Data, Size, Charsize, (sf::Uint32 *)Charset);
#else
result = self->obj->LoadFromMemory(Data, Size, Charsize, (sf::Uint16 *)Charset);
#endif
}
else if (PyArg_ParseTupleAndKeywords(args, kwds, "s#|Is#s:Font.LoadFromMemory", (char **)kwlist, &Data, &Size, &Charsize, &Charset, &Length, &EncodingStr))
{
PyErr_Clear();
if (EncodingStr == NULL)
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
else else
Result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::Text((const sf::Uint8 *)CharsetTmp)); {
Encoding.assign(EncodingStr);
if (Encoding == "utf8")
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF8String((sf::Uint8 *)Charset));
else if (Encoding == "utf16")
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF16String((sf::Uint16 *)(Charset+2)));
else if (Encoding == "utf32")
result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::UTF32String((sf::Uint32 *)(Charset+4)));
else
{
PyErr_Format(PyExc_TypeError, "Font.LoadFromMemory() Encoding %s not supported", EncodingStr);
return NULL;
}
}
} }
else else
Result = self->obj->LoadFromMemory(Data, Size, Charsize); {
PyErr_BadArgument();
if (Result) return NULL;
Py_RETURN_TRUE; }
else return PyBool_FromLong(result);
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
@ -147,16 +181,16 @@ PySfFont_GetGlyph(PySfFont* self, PyObject *args)
} }
static PyMethodDef PySfFont_methods[] = { static PyMethodDef PySfFont_methods[] = {
{"LoadFromFile", (PyCFunction)PySfFont_LoadFromFile, METH_VARARGS | METH_KEYWORDS, "LoadFromFile(Filename, CharSize, Charset)\n\ {"LoadFromFile", (PyCFunction)PySfFont_LoadFromFile, METH_VARARGS | METH_KEYWORDS, "LoadFromFile(Filename, CharSize, UnicodeCharset) or LoadFromFile(Filename, CharSize, Charset, Encoding='utf8')\n\
Load the font from a file. Returns True if loading was successful.\n\ Load the font from a file. Returns True if loading was successful.\n\
Filename : Font file to load\n\ Filename : Font file to load\n\
CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\n\ CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\n\
Charset : Characters set to generate (empty by default - takes the ASCII range [31, 255])"}, Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters)"},
{"LoadFromMemory", (PyCFunction)PySfFont_LoadFromMemory, METH_VARARGS | METH_KEYWORDS, "LoadFromMemory(Data, CharSize, Charset)\n\ {"LoadFromMemory", (PyCFunction)PySfFont_LoadFromMemory, METH_VARARGS | METH_KEYWORDS, "LoadFromMemory(Data, CharSize, UnicodeCharset) or LoadFromMemory(Data, CharSize, Charset, Encoding='utf8')\n\
Load the font from a file in memory. Returns True if loading was successful.\n\ Load the font from a file in memory. Returns True if loading was successful.\n\
Data : data to load\n\ Data : data to load\n\
CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\n\ CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\n\
Charset : Characters set to generate (empty by default - takes the ASCII range [31, 255])"}, Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters)"},
{"GetDefaultFont", (PyCFunction)PySfFont_GetDefaultFont, METH_NOARGS | METH_STATIC, "GetDefaultFont()\n\ {"GetDefaultFont", (PyCFunction)PySfFont_GetDefaultFont, METH_NOARGS | METH_STATIC, "GetDefaultFont()\n\
Get the SFML default built-in font (Arial)."}, Get the SFML default built-in font (Arial)."},
{"GetCharacterSize", (PyCFunction)PySfFont_GetCharacterSize, METH_NOARGS, "GetCharacterSize()\n\ {"GetCharacterSize", (PyCFunction)PySfFont_GetCharacterSize, METH_NOARGS, "GetCharacterSize()\n\
@ -169,8 +203,7 @@ Get the description of a glyph (character) given by its unicode value. Returns g
PyTypeObject PySfFontType = { PyTypeObject PySfFontType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Font", /*tp_name*/ "Font", /*tp_name*/
sizeof(PySfFont), /*tp_basicsize*/ sizeof(PySfFont), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -198,7 +231,7 @@ PyTypeObject PySfFontType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfFont_methods, /* tp_methods */ PySfFont_methods, /* tp_methods */
PySfFont_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View file

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

View file

@ -24,6 +24,12 @@
#include "Glyph.hpp" #include "Glyph.hpp"
#include <structmember.h>
#include "offsetof.hpp"
#include "compat.hpp"
static PyMemberDef PySfGlyph_members[] = { static PyMemberDef PySfGlyph_members[] = {
{(char *)"Advance", T_INT, offsetof(PySfGlyph, Advance), 0, (char *)"Offset to move horizontically to the next character."}, {(char *)"Advance", T_INT, offsetof(PySfGlyph, Advance), 0, (char *)"Offset to move horizontically to the next character."},
{(char *)"Rectangle", T_OBJECT, offsetof(PySfGlyph, Rectangle), 0, (char *)"Bounding rectangle of the glyph, in relative coordinates."}, {(char *)"Rectangle", T_OBJECT, offsetof(PySfGlyph, Rectangle), 0, (char *)"Bounding rectangle of the glyph, in relative coordinates."},
@ -32,7 +38,6 @@ static PyMemberDef PySfGlyph_members[] = {
}; };
static void static void
PySfGlyph_dealloc(PySfGlyph *self) PySfGlyph_dealloc(PySfGlyph *self)
{ {
@ -41,7 +46,7 @@ PySfGlyph_dealloc(PySfGlyph *self)
self->TexCoords->obj = new sf::FloatRect(self->obj->TexCoords); self->TexCoords->obj = new sf::FloatRect(self->obj->TexCoords);
Py_DECREF(self->TexCoords); Py_DECREF(self->TexCoords);
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
void void
@ -80,16 +85,13 @@ static PyObject *
PySfGlyph_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfGlyph_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfGlyph *self; PySfGlyph *self;
self = (PySfGlyph *)type->tp_alloc(type, 0); self = (PySfGlyph *)type->tp_alloc(type, 0);
if (self != NULL) if (self != NULL)
{ {
self->Advance = 0; self->Advance = 0;
self->Rectangle = GetNewPySfIntRect(); self->Rectangle = GetNewPySfIntRect();
self->TexCoords = GetNewPySfFloatRect(); self->TexCoords = GetNewPySfFloatRect();
} }
return (PyObject *)self; return (PyObject *)self;
} }
@ -103,14 +105,9 @@ PySfGlyph_init(PySfGlyph *self, PyObject *args, PyObject *kwds)
return 0; return 0;
} }
static PyMethodDef PySfGlyph_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject PySfGlyphType = { PyTypeObject PySfGlyphType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Glyph", /*tp_name*/ "Glyph", /*tp_name*/
sizeof(PySfGlyph), /*tp_basicsize*/ sizeof(PySfGlyph), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -137,7 +134,7 @@ PyTypeObject PySfGlyphType = {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfGlyph_methods, /* tp_methods */ 0, /* tp_methods */
PySfGlyph_members, /* tp_members */ PySfGlyph_members, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */

View file

@ -25,13 +25,9 @@
#ifndef __PYGLYPH_HPP #ifndef __PYGLYPH_HPP
#define __PYGLYPH_HPP #define __PYGLYPH_HPP
#include <SFML/Graphics/Glyph.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "offsetof.hpp" #include <SFML/Graphics/Glyph.hpp>
#include "Rect.hpp" #include "Rect.hpp"

View file

@ -24,34 +24,27 @@
#include "Image.hpp" #include "Image.hpp"
#include "RenderWindow.hpp" #include "RenderWindow.hpp"
#include "Color.hpp"
#include "Rect.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType; extern PyTypeObject PySfColorType;
extern PyTypeObject PySfIntRectType; extern PyTypeObject PySfIntRectType;
extern PyTypeObject PySfRenderWindowType; extern PyTypeObject PySfRenderWindowType;
static PyMemberDef PySfImage_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfImage_dealloc(PySfImage* self) PySfImage_dealloc(PySfImage* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfImage_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfImage_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfImage *self; PySfImage *self;
self = (PySfImage *)type->tp_alloc(type, 0); self = (PySfImage *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -64,7 +57,7 @@ PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
unsigned int Width=0, Height=0; unsigned int Width=0, Height=0;
const char *kwlist[] = {"Width", "Height", "Color", NULL}; const char *kwlist[] = {"Width", "Height", "Color", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!", (char **)kwlist, &Width, &Height, &PySfColorType, &ColorTmp)) if (! PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!:Image.Create", (char **)kwlist, &Width, &Height, &PySfColorType, &ColorTmp))
return NULL; return NULL;
if (ColorTmp) if (ColorTmp)
@ -82,12 +75,11 @@ PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
static PyObject * static PyObject *
PySfImage_CopyScreen(PySfImage* self, PyObject *args) PySfImage_CopyScreen(PySfImage* self, PyObject *args)
{ {
// bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
PySfRenderWindow *RenderWindow; PySfRenderWindow *RenderWindow;
PySfIntRect *SourceRect=NULL; PySfIntRect *SourceRect=NULL;
bool Result; bool Result;
if (! PyArg_ParseTuple(args, "O!|O!", &PySfRenderWindowType, &RenderWindow, &PySfIntRectType, &SourceRect)) if (! PyArg_ParseTuple(args, "O!|O!:Image.CopyScreen", &PySfRenderWindowType, &RenderWindow, &PySfIntRectType, &SourceRect))
return NULL; return NULL;
@ -113,7 +105,7 @@ PySfImage_SetPixel(PySfImage* self, PyObject *args, PyObject *kwds)
const char *kwlist[] = {"x", "y", "Color", NULL}; const char *kwlist[] = {"x", "y", "Color", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|O!", (char **)kwlist, &x, &y, &PySfColorType, &ColorTmp)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|O!:Image.SetPixel", (char **)kwlist, &x, &y, &PySfColorType, &ColorTmp))
return NULL; return NULL;
@ -134,7 +126,7 @@ PySfImage_GetPixel(PySfImage* self, PyObject *args)
unsigned int x=0, y=0; unsigned int x=0, y=0;
if (! PyArg_ParseTuple(args, "II", &x, &y)) if (!PyArg_ParseTuple(args, "II:Image.GetPixel", &x, &y))
return NULL; return NULL;
@ -154,8 +146,11 @@ PySfImage_CreateMaskFromColor(PySfImage* self, PyObject *args)
PySfColor *ColorTmp= (PySfColor *)args; PySfColor *ColorTmp= (PySfColor *)args;
sf::Color *Color; sf::Color *Color;
if ( ! PyObject_TypeCheck(ColorTmp, &PySfColorType)) if (!PyObject_TypeCheck(ColorTmp, &PySfColorType))
PyErr_SetString(PyExc_ValueError, "Argument must be a sf.Color"); {
PyErr_SetString(PyExc_TypeError, "Image.CreateMaskFromColor() Argument must be a sf.Color");
return NULL;
}
Color = ColorTmp->obj; Color = ColorTmp->obj;
PySfColorUpdate(ColorTmp); PySfColorUpdate(ColorTmp);
self->obj->CreateMaskFromColor(*Color); self->obj->CreateMaskFromColor(*Color);
@ -169,14 +164,10 @@ PySfImage_LoadFromMemory(PySfImage* self, PyObject *args)
unsigned int SizeInBytes; unsigned int SizeInBytes;
char *Data; char *Data;
if (! PyArg_ParseTuple(args, "s#", &Data, &SizeInBytes)) if (! PyArg_ParseTuple(args, "s#:Image.LoadFromMemory", &Data, &SizeInBytes))
return NULL; return NULL;
if (self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes)) return PyBool_FromLong(self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
@ -185,7 +176,7 @@ PySfImage_LoadFromPixels(PySfImage* self, PyObject *args)
unsigned int Width, Height, Size; unsigned int Width, Height, Size;
char *Data; char *Data;
if (! PyArg_ParseTuple(args, "IIs#", &Width, &Height, &Data, &Size)) if (! PyArg_ParseTuple(args, "IIs#:Image.LoadFromPixels", &Width, &Height, &Data, &Size))
return NULL; return NULL;
self->obj->LoadFromPixels(Width, Height, (sf::Uint8*) Data); self->obj->LoadFromPixels(Width, Height, (sf::Uint8*) Data);
@ -195,29 +186,23 @@ PySfImage_LoadFromPixels(PySfImage* self, PyObject *args)
static PyObject * static PyObject *
PySfImage_GetPixels(PySfImage *self) PySfImage_GetPixels(PySfImage *self)
{ {
#ifdef IS_PY3K
return PyBytes_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
#else
return PyString_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4); return PyString_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
#endif
} }
static PyObject * static PyObject *
PySfImage_LoadFromFile (PySfImage *self, PyObject *args) PySfImage_LoadFromFile (PySfImage *self, PyObject *args)
{ {
char *path = PyString_AsString(args); load_from_file(self, args);
if (self->obj->LoadFromFile(path))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
PySfImage_SaveToFile (PySfImage *self, PyObject *args) PySfImage_SaveToFile (PySfImage *self, PyObject *args)
{ {
char *path = PyString_AsString(args); save_to_file(self, args);
if (self->obj->SaveToFile(path))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static int static int
@ -233,10 +218,7 @@ PySfImage_Bind(PySfImage *self)
static PyObject * static PyObject *
PySfImage_SetSmooth (PySfImage *self, PyObject *args) PySfImage_SetSmooth (PySfImage *self, PyObject *args)
{ {
bool arg=false; self->obj->SetSmooth(PyBool_AsBool(args));
if (PyObject_IsTrue(args))
arg = true;
self->obj->SetSmooth(arg);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -269,8 +251,9 @@ PySfImage_GetTexCoords(PySfImage* self, PyObject *args)
if (! PyArg_ParseTuple(args, "O!|O", &PySfIntRectType, &RectArg, &AdjustObj)) if (! PyArg_ParseTuple(args, "O!|O", &PySfIntRectType, &RectArg, &AdjustObj))
return NULL; return NULL;
if (PyObject_IsTrue(AdjustObj)) if (AdjustObj)
Adjust = true; if (PyObject_IsTrue(AdjustObj))
Adjust = true;
PySfFloatRect *Rect; PySfFloatRect *Rect;
@ -293,7 +276,8 @@ Copy pixels from another image onto this one. This function does a slow pixel co
Source : Source image to copy\n\ Source : Source image to copy\n\
DestX : X coordinate of the destination position\n\ DestX : X coordinate of the destination position\n\
DestY : Y coordinate of the destination position\n\ DestY : Y coordinate of the destination position\n\
SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)"}, SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)\n\
ApplyAlpha : Should the copy take in account the source transparency? (false by default)"},
{"Create", (PyCFunction)PySfImage_Create, METH_VARARGS, "Create(Width=0, Height=0, Color=sf.Color.Black)\n\ {"Create", (PyCFunction)PySfImage_Create, METH_VARARGS, "Create(Width=0, Height=0, Color=sf.Color.Black)\n\
Create an empty image.\n\ Create an empty image.\n\
Width : Image width\n\ Width : Image width\n\
@ -325,8 +309,7 @@ Create the image from the current contents of the given window. Return True if c
}; };
PyTypeObject PySfImageType = { PyTypeObject PySfImageType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Image", /*tp_name*/ "Image", /*tp_name*/
sizeof(PySfImage), /*tp_basicsize*/ sizeof(PySfImage), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -357,7 +340,7 @@ Copy constructor : sf.Image(Copy) where Copy is a sf.Image instance.", /* tp_doc
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfImage_methods, /* tp_methods */ PySfImage_methods, /* tp_methods */
PySfImage_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -372,7 +355,8 @@ Copy constructor : sf.Image(Copy) where Copy is a sf.Image instance.", /* tp_doc
static int static int
PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds) PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
{ {
if (PyTuple_Size(args) == 1) int size = PyTuple_Size(args);
if (size == 1)
{ {
PySfImage *Image; PySfImage *Image;
if (PyArg_ParseTuple(args, "O!", &PySfImageType, &Image)) if (PyArg_ParseTuple(args, "O!", &PySfImageType, &Image))
@ -380,13 +364,19 @@ PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
self->obj = new sf::Image(*(Image->obj)); self->obj = new sf::Image(*(Image->obj));
return 0; return 0;
} }
else PyErr_Clear();
} }
self->obj = new sf::Image(); self->obj = new sf::Image();
if (PyTuple_Size(args) > 0) if (PyTuple_Size(args) > 0)
{ {
if (PySfImage_Create(self, args, kwds) == NULL) if (PySfImage_Create(self, args, kwds) == NULL)
if (PySfImage_LoadFromPixels(self, args) == NULL) {
if (size != 3)
return -1; return -1;
else if (PySfImage_LoadFromPixels(self, args) == NULL)
return -1;
else PyErr_Clear();
}
} }
return 0; return 0;
} }
@ -396,17 +386,23 @@ PySfImage_Copy(PySfImage* self, PyObject *args)
{ {
PySfIntRect *SourceRect = NULL; PySfIntRect *SourceRect = NULL;
PySfImage *Source = NULL; PySfImage *Source = NULL;
unsigned int DestX, DestY; unsigned int DestX, DestY;
if (! PyArg_ParseTuple(args, "O!II|O!", &PySfImageType, &Source, &DestX, &DestY, &PySfIntRectType, &SourceRect)) PyObject *PyApplyAlpha;
bool ApplyAlpha = false;
if (! PyArg_ParseTuple(args, "O!II|O!O:Image.Copy", &PySfImageType, &Source, &DestX, &DestY, &PySfIntRectType, &SourceRect, &PyApplyAlpha))
return NULL; return NULL;
if (PyApplyAlpha)
if (PyObject_IsTrue(PyApplyAlpha))
ApplyAlpha = true;
if (SourceRect) if (SourceRect)
{ {
PySfIntRectUpdateObj(SourceRect); PySfIntRectUpdateObj(SourceRect);
self->obj->Copy(*(Source->obj), DestX, DestY, *(SourceRect->obj)); self->obj->Copy(*(Source->obj), DestX, DestY, *(SourceRect->obj), ApplyAlpha);
} }
else else
self->obj->Copy(*(Source->obj), DestX, DestY); self->obj->Copy(*(Source->obj), DestX, DestY, sf::IntRect(0, 0, 0, 0), ApplyAlpha);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -414,6 +410,6 @@ PySfImage_Copy(PySfImage* self, PyObject *args)
PySfImage * PySfImage *
GetNewPySfImage() GetNewPySfImage()
{ {
return PyObject_New(PySfImage, &PySfImageType); return (PySfImage *)PySfImage_new(&PySfImageType, NULL, NULL);
} }

View file

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

View file

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

View file

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

View file

@ -22,62 +22,26 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <Python.h>
#include <structmember.h>
#include "Joy.hpp" #include "Joy.hpp"
#include "compat.hpp"
typedef struct {
PyObject_HEAD
} PySfJoy;
static PyMemberDef PySfJoy_members[] = {
{NULL} /* Sentinel */
};
static void
PySfJoy_dealloc(PySfJoy *self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * static PyObject *
PySfJoy_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfJoy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfJoy *self; PySfJoy *self;
self = (PySfJoy *)type->tp_alloc(type, 0); self = (PySfJoy *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int
PySfJoy_init(PySfJoy *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyMethodDef PySfJoy_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject PySfJoyType = { PyTypeObject PySfJoyType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Joy", /*tp_name*/ "Joy", /*tp_name*/
sizeof(PySfJoy), /*tp_basicsize*/ sizeof(PySfJoy), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)PySfJoy_dealloc, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
@ -100,15 +64,15 @@ PyTypeObject PySfJoyType = {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfJoy_methods, /* tp_methods */ 0, /* tp_methods */
PySfJoy_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)PySfJoy_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PySfJoy_new, /* tp_new */ PySfJoy_new, /* tp_new */
}; };
@ -116,25 +80,25 @@ PyTypeObject PySfJoyType = {
void PySfJoy_InitConst() void PySfJoy_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::Joy::AxisX); obj = PyLong_FromLong(sf::Joy::AxisX);
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisX", obj); PyDict_SetItemString(PySfJoyType.tp_dict, "AxisX", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Joy::AxisY); obj = PyLong_FromLong(sf::Joy::AxisY);
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisY", obj); PyDict_SetItemString(PySfJoyType.tp_dict, "AxisY", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Joy::AxisZ); obj = PyLong_FromLong(sf::Joy::AxisZ);
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisZ", obj); PyDict_SetItemString(PySfJoyType.tp_dict, "AxisZ", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Joy::AxisR); obj = PyLong_FromLong(sf::Joy::AxisR);
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisR", obj); PyDict_SetItemString(PySfJoyType.tp_dict, "AxisR", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Joy::AxisU); obj = PyLong_FromLong(sf::Joy::AxisU);
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisU", obj); PyDict_SetItemString(PySfJoyType.tp_dict, "AxisU", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Joy::AxisV); obj = PyLong_FromLong(sf::Joy::AxisV);
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisV", obj); PyDict_SetItemString(PySfJoyType.tp_dict, "AxisV", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Joy::AxisPOV); obj = PyLong_FromLong(sf::Joy::AxisPOV);
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisPOV", obj); PyDict_SetItemString(PySfJoyType.tp_dict, "AxisPOV", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View file

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

View file

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

View file

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

View file

@ -24,40 +24,17 @@
#include "Listener.hpp" #include "Listener.hpp"
#include "compat.hpp"
static PyMemberDef PySfListener_members[] = {
{NULL} /* Sentinel */
};
static void
PySfListener_dealloc(PySfListener* self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * static PyObject *
PySfListener_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfListener_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfListener *self; PySfListener *self;
self = (PySfListener *)type->tp_alloc(type, 0); self = (PySfListener *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int
PySfListener_init(PySfListener *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyObject * static PyObject *
PySfListener_SetGlobalVolume(PySfListener* self, PyObject *args) PySfListener_SetGlobalVolume(PySfListener* self, PyObject *args)
{ {
@ -75,7 +52,7 @@ static PyObject *
PySfListener_SetPosition(PySfListener* self, PyObject *args) PySfListener_SetPosition(PySfListener* self, PyObject *args)
{ {
float X, Y, Z; float X, Y, Z;
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z)) if (!PyArg_ParseTuple(args, "fff:Listener.SetPosition", &X, &Y, &Z))
return NULL; return NULL;
sf::Listener::SetPosition(X, Y, Z); sf::Listener::SetPosition(X, Y, Z);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -92,7 +69,7 @@ static PyObject *
PySfListener_SetTarget(PySfListener* self, PyObject *args) PySfListener_SetTarget(PySfListener* self, PyObject *args)
{ {
float X, Y, Z; float X, Y, Z;
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z)) if (!PyArg_ParseTuple(args, "fff:Listener.SetTarget", &X, &Y, &Z))
return NULL; return NULL;
sf::Listener::SetTarget(X, Y, Z); sf::Listener::SetTarget(X, Y, Z);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -116,12 +93,11 @@ static PyMethodDef PySfListener_methods[] = {
}; };
PyTypeObject PySfListenerType = { PyTypeObject PySfListenerType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Listener", /*tp_name*/ "Listener", /*tp_name*/
sizeof(PySfListener), /*tp_basicsize*/ sizeof(PySfListener), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)PySfListener_dealloc, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
@ -145,14 +121,14 @@ PyTypeObject PySfListenerType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfListener_methods, /* tp_methods */ PySfListener_methods, /* tp_methods */
PySfListener_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)PySfListener_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PySfListener_new, /* tp_new */ PySfListener_new, /* tp_new */
}; };

View file

@ -25,13 +25,9 @@
#ifndef __PYLISTENER_HPP #ifndef __PYLISTENER_HPP
#define __PYLISTENER_HPP #define __PYLISTENER_HPP
#include <SFML/Audio/Listener.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "offsetof.hpp" #include <SFML/Audio/Listener.hpp>
typedef struct { typedef struct {

View file

@ -22,62 +22,26 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <Python.h>
#include <structmember.h>
#include "Mouse.hpp" #include "Mouse.hpp"
#include "compat.hpp"
typedef struct {
PyObject_HEAD
} PySfMouse;
static PyMemberDef PySfMouse_members[] = {
{NULL} /* Sentinel */
};
static void
PySfMouse_dealloc(PySfMouse *self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * static PyObject *
PySfMouse_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfMouse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfMouse *self; PySfMouse *self;
self = (PySfMouse *)type->tp_alloc(type, 0); self = (PySfMouse *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int
PySfMouse_init(PySfMouse *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyMethodDef PySfMouse_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject PySfMouseType = { PyTypeObject PySfMouseType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Mouse", /*tp_name*/ "Mouse", /*tp_name*/
sizeof(PySfMouse), /*tp_basicsize*/ sizeof(PySfMouse), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)PySfMouse_dealloc, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
@ -100,15 +64,15 @@ PyTypeObject PySfMouseType = {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfMouse_methods, /* tp_methods */ 0, /* tp_methods */
PySfMouse_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)PySfMouse_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PySfMouse_new, /* tp_new */ PySfMouse_new, /* tp_new */
}; };
@ -116,19 +80,19 @@ PyTypeObject PySfMouseType = {
void PySfMouse_InitConst() void PySfMouse_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::Mouse::Left); obj = PyLong_FromLong(sf::Mouse::Left);
PyDict_SetItemString(PySfMouseType.tp_dict, "Left", obj); PyDict_SetItemString(PySfMouseType.tp_dict, "Left", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Mouse::Right); obj = PyLong_FromLong(sf::Mouse::Right);
PyDict_SetItemString(PySfMouseType.tp_dict, "Right", obj); PyDict_SetItemString(PySfMouseType.tp_dict, "Right", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Mouse::Middle); obj = PyLong_FromLong(sf::Mouse::Middle);
PyDict_SetItemString(PySfMouseType.tp_dict, "Middle", obj); PyDict_SetItemString(PySfMouseType.tp_dict, "Middle", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Mouse::XButton1); obj = PyLong_FromLong(sf::Mouse::XButton1);
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton1", obj); PyDict_SetItemString(PySfMouseType.tp_dict, "XButton1", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Mouse::XButton2); obj = PyLong_FromLong(sf::Mouse::XButton2);
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton2", obj); PyDict_SetItemString(PySfMouseType.tp_dict, "XButton2", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -23,49 +23,36 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "RenderWindow.hpp" #include "RenderWindow.hpp"
#include "Event.hpp"
#include "VideoMode.hpp"
#include "Drawable.hpp"
#include "Color.hpp"
#include "Rect.hpp"
#include "View.hpp" #include "View.hpp"
#include "Image.hpp" #include "Image.hpp"
#include "Window.hpp" #include "Window.hpp"
#include "Color.hpp"
#include "Drawable.hpp"
#include "compat.hpp"
#include "SFML/Window/WindowStyle.hpp" #include <SFML/Window/WindowStyle.hpp>
extern PyTypeObject PySfEventType;
extern PyTypeObject PySfViewType; extern PyTypeObject PySfViewType;
extern PyTypeObject PySfColorType;
extern PyTypeObject PySfWindowType; extern PyTypeObject PySfWindowType;
extern PyTypeObject PySfWindowSettingsType; extern PyTypeObject PySfRenderWindowType;
extern PyTypeObject PySfVideoModeType; extern PyTypeObject PySfColorType;
extern PyTypeObject PySfDrawableType; extern PyTypeObject PySfDrawableType;
static PyMemberDef PySfRenderWindow_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfRenderWindow_dealloc(PySfRenderWindow* self) PySfRenderWindow_dealloc(PySfRenderWindow* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfRenderWindow *self; PySfRenderWindow *self;
self = (PySfRenderWindow *)type->tp_alloc(type, 0); self = (PySfRenderWindow *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -74,7 +61,8 @@ PySfRenderWindow_init(PySfRenderWindow *self, PyObject *args, PyObject *kwds)
{ {
self->obj = new sf::RenderWindow(); self->obj = new sf::RenderWindow();
if (PyTuple_Size(args) > 0) if (PyTuple_Size(args) > 0)
PySfWindow_Create((PySfWindow *)self, args, kwds); if (PySfWindow_Create((PySfWindow *)self, args, kwds) == NULL)
return -1;
return 0; return 0;
} }
@ -96,7 +84,7 @@ PySfRenderWindow_ConvertCoords(PySfRenderWindow *self, PyObject *args)
sf::View *TargetView = NULL; sf::View *TargetView = NULL;
sf::Vector2f Vect; sf::Vector2f Vect;
if (! PyArg_ParseTuple(args, "II|O!", &WindowX, &WindowY, &PySfViewType, &PyTargetView)) if (!PyArg_ParseTuple(args, "II|O!:RenderWindow.ConvertCoords", &WindowX, &WindowY, &PySfViewType, &PyTargetView))
return NULL; return NULL;
if (PyTargetView) if (PyTargetView)
@ -113,7 +101,9 @@ PySfRenderWindow_DrawObject(PySfRenderWindow *RenderWindow, PySfDrawable *Obj)
{ {
if (PyObject_HasAttrString((PyObject *)Obj, "Render")) if (PyObject_HasAttrString((PyObject *)Obj, "Render"))
{ {
Py_XDECREF(Obj->obj->RenderWindow);
Obj->obj->RenderWindow = RenderWindow; Obj->obj->RenderWindow = RenderWindow;
Py_XDECREF(Obj->obj->RenderFunction);
Obj->obj->RenderFunction = PyObject_GetAttrString((PyObject *)Obj, "Render"); Obj->obj->RenderFunction = PyObject_GetAttrString((PyObject *)Obj, "Render");
} }
RenderWindow->obj->Draw( *(Obj->obj) ); RenderWindow->obj->Draw( *(Obj->obj) );
@ -125,21 +115,18 @@ PySfRenderWindow_DrawObject(PySfRenderWindow *RenderWindow, PySfDrawable *Obj)
static PyObject * static PyObject *
PySfRenderWindow_Draw(PySfRenderWindow *self, PyObject *args) PySfRenderWindow_Draw(PySfRenderWindow *self, PyObject *args)
{ {
if (!args) if (args == NULL)
return NULL; return NULL;
if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)args)) if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)args))
{ {
PyObject *iterator = PyObject_GetIter(args); PyObject *iterator = PyObject_GetIter(args);
PyObject *item; PyObject *item;
PyErr_Clear();
if (iterator == NULL) if (iterator == NULL)
{ {
PyErr_SetString(PyExc_TypeError, "Argument to Draw method is neither a Drawable nor an iterable."); PyErr_SetString(PyExc_TypeError, "Argument to Draw method is neither a Drawable nor an iterable.");
return NULL; return NULL;
} }
while ((item = PyIter_Next(iterator))) while ((item = PyIter_Next(iterator)))
{ {
if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)item)) if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)item))
@ -149,26 +136,36 @@ PySfRenderWindow_Draw(PySfRenderWindow *self, PyObject *args)
} }
Py_DECREF(item); Py_DECREF(item);
} }
Py_DECREF(iterator); Py_DECREF(iterator);
}
if (PyErr_Occurred()) { if (PyErr_Occurred())
return NULL; return NULL;
}
}
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject *
PySfRenderWindow_GetDefaultView(PySfRenderWindow *self) static PyObject *
{ PySfRenderWindow_Clear(PySfRenderWindow *self, PyObject *args)
PySfView *View; {
PySfColor *Color;
View = GetNewPySfView(); int size = PyTuple_Size(args);
View->Owner = false; if (size == 1)
View->obj = &(self->obj->GetDefaultView()); {
if (!PyArg_ParseTuple(args, "O!:RenderWindow.Clear", &PySfColorType, &Color))
return (PyObject *)View; 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 * static PyObject *
@ -185,10 +182,7 @@ PySfRenderWindow_GetView(PySfRenderWindow *self)
static PyObject * static PyObject *
PySfRenderWindow_PreserveOpenGLStates(PySfRenderWindow *self, PyObject *args) PySfRenderWindow_PreserveOpenGLStates(PySfRenderWindow *self, PyObject *args)
{ {
bool Optimize = false; self->obj->PreserveOpenGLStates(PyBool_AsBool(args));
if (PyObject_IsTrue(args))
Optimize = true;
self->obj->PreserveOpenGLStates(Optimize);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -196,42 +190,31 @@ static PyObject *
PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args) PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args)
{ {
PySfView *View = (PySfView *)args; PySfView *View = (PySfView *)args;
if (! PyObject_TypeCheck(View, &PySfViewType)) if (!PyObject_TypeCheck(View, &PySfViewType))
{ {
PyErr_SetString(PyExc_TypeError, "Argument is not a sfView"); PyErr_SetString(PyExc_TypeError, "RenderWindow.SetView() Argument is not a sf.View");
return NULL; return NULL;
} }
self->obj->SetView( *(View->obj)); self->obj->SetView( *(View->obj));
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
PySfRenderWindow_Clear(PySfRenderWindow* self, PyObject *args) PySfRenderWindow_GetDefaultView(PySfRenderWindow *self)
{ {
PySfColor *Color = (PySfColor *)args; PySfView *View;
if (! PyObject_TypeCheck(Color, &PySfColorType))
{ View = GetNewPySfView();
PyErr_SetString(PyExc_TypeError, "Argument is not a sfColor"); View->Owner = false;
return NULL; View->obj = &(self->obj->GetDefaultView());
}
PySfColorUpdate(Color); return (PyObject *)View;
self->obj->Clear(*(Color->obj));
Py_RETURN_NONE;
} }
static PyMethodDef PySfRenderWindow_methods[] = { static PyMethodDef PySfRenderWindow_methods[] = {
{"Clear", (PyCFunction)PySfRenderWindow_Clear, METH_O, "Clear(FillColor)\n\ {"Clear", (PyCFunction)PySfRenderWindow_Clear, METH_VARARGS, "Clear(FillColor)\n\
Clear the entire target with a single color.\n\ Clear the entire target with a single color.\n\
FillColor : Color to use to clear the render target."}, FillColor : Color to use to clear the render target."},
{"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\
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)."},
{"GetDefaultView", (PyCFunction)PySfRenderWindow_GetDefaultView, METH_NOARGS, "GetDefaultView()\n\ {"GetDefaultView", (PyCFunction)PySfRenderWindow_GetDefaultView, METH_NOARGS, "GetDefaultView()\n\
Get the default view of the window for read / write (returns a sf.View instance)."}, Get the default view of the window for read / write (returns a sf.View instance)."},
{"GetView", (PyCFunction)PySfRenderWindow_GetView, METH_NOARGS, "GetView()\n\ {"GetView", (PyCFunction)PySfRenderWindow_GetView, METH_NOARGS, "GetView()\n\
@ -241,12 +224,23 @@ Tell SFML to preserve external OpenGL states, at the expense of more CPU charge.
Preserve : True to preserve OpenGL states, false to let SFML optimize"}, Preserve : True to preserve OpenGL states, false to let SFML optimize"},
{"SetView", (PyCFunction)PySfRenderWindow_SetView, METH_O, "SetView(View)\n\ {"SetView", (PyCFunction)PySfRenderWindow_SetView, METH_O, "SetView(View)\n\
Change the current active view. View must be a sf.View instance."}, 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\
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)."},
{NULL} /* Sentinel */ {NULL} /* Sentinel */
}; };
PyTypeObject PySfRenderWindowType = { PyTypeObject PySfRenderWindowType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"RenderWindow", /*tp_name*/ "RenderWindow", /*tp_name*/
sizeof(PySfRenderWindow), /*tp_basicsize*/ sizeof(PySfRenderWindow), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -266,7 +260,14 @@ PyTypeObject PySfRenderWindowType = {
0, /*tp_setattro*/ 0, /*tp_setattro*/
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"Simple wrapper for sf.Window that allows easy 2D rendering.", /* tp_doc */ "Simple wrapper for sf.Window that allows easy 2D rendering.\n\
Default constructor : sf.RenderWindow()\n\
Other constructor : sf.RenderWindow(Mode, Title, Style::Resize|Style::Close, Params = WindowSettings())\n\
Parameters:\n\
Mode : Video mode to use\n\
Title : Title of the window\n\
WindowStyle : Window style (Resize | Close by default)\n\
Params : Creation parameters (see default constructor for default values)", /* tp_doc */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
@ -274,7 +275,7 @@ PyTypeObject PySfRenderWindowType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfRenderWindow_methods, /* tp_methods */ PySfRenderWindow_methods, /* tp_methods */
PySfRenderWindow_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PySfWindowType, /* tp_base */ &PySfWindowType, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View file

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

View file

@ -27,33 +27,24 @@
#include <SFML/Graphics/Color.hpp> #include <SFML/Graphics/Color.hpp>
#include "Color.hpp" #include "Color.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType; extern PyTypeObject PySfColorType;
extern PyTypeObject PySfDrawableType; extern PyTypeObject PySfDrawableType;
static PyMemberDef PySfShape_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfShape_dealloc(PySfShape* self) PySfShape_dealloc(PySfShape* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfShape_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfShape_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfShape *self; PySfShape *self;
self = (PySfShape *)type->tp_alloc(type, 0); self = (PySfShape *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -64,7 +55,6 @@ PySfShape_init(PySfShape *self, PyObject *args)
return 0; return 0;
} }
// void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0)); // void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
static PyObject * static PyObject *
PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds) PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
@ -73,7 +63,7 @@ PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
float X, Y; float X, Y;
sf::Color *Col, *OutlineCol; sf::Color *Col, *OutlineCol;
PySfColor *ColTmp=NULL, *OutlineColTmp=NULL; PySfColor *ColTmp=NULL, *OutlineColTmp=NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff|O!O!", (char **)kwlist, &X, &Y, &PySfColorType, &ColTmp, &PySfColorType, &OutlineColTmp)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff|O!O!:Shape.AddPoint", (char **)kwlist, &X, &Y, &PySfColorType, &ColTmp, &PySfColorType, &OutlineColTmp))
return NULL; return NULL;
if (ColTmp) if (ColTmp)
@ -119,7 +109,7 @@ PySfShape_Line(PySfShape* self, PyObject *args, PyObject *kwds)
float X0, Y0, X1, Y1, Thickness, Outline = 0.f; float X0, Y0, X1, Y1, Thickness, Outline = 0.f;
sf::Color *OutlineCol; sf::Color *OutlineCol;
PySfColor *ColTmp, *OutlineColTmp=NULL; PySfColor *ColTmp, *OutlineColTmp=NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffffO!|fO!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffffO!|fO!:Shape.Line", (char **)kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
return NULL; return NULL;
if (OutlineColTmp) if (OutlineColTmp)
{ {
@ -143,7 +133,7 @@ PySfShape_Rectangle(PySfShape* self, PyObject *args, PyObject *kwds)
float X0, Y0, X1, Y1, Outline = 0.f; float X0, Y0, X1, Y1, Outline = 0.f;
sf::Color *OutlineCol; sf::Color *OutlineCol;
PySfColor *ColTmp, *OutlineColTmp=NULL; PySfColor *ColTmp, *OutlineColTmp=NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffO!|fO!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffO!|fO!:Shape.Rectangle", (char **)kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
return NULL; return NULL;
if (OutlineColTmp) if (OutlineColTmp)
{ {
@ -167,7 +157,7 @@ PySfShape_Circle(PySfShape* self, PyObject *args, PyObject *kwds)
float X, Y, Radius, Outline = 0.f; float X, Y, Radius, Outline = 0.f;
sf::Color *OutlineCol; sf::Color *OutlineCol;
PySfColor *ColTmp, *OutlineColTmp=NULL; PySfColor *ColTmp, *OutlineColTmp=NULL;
if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffO!|fO!", (char **)kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffO!|fO!:Shape.Circle", (char **)kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
return NULL; return NULL;
if (OutlineColTmp) if (OutlineColTmp)
{ {
@ -218,7 +208,7 @@ PySfShape_SetPointPosition(PySfShape* self, PyObject *args)
{ {
unsigned int Index; unsigned int Index;
float X, Y; float X, Y;
if (!PyArg_ParseTuple(args, "Iff", &Index, &X, &Y)) if (!PyArg_ParseTuple(args, "Iff:Shape.SetPointPosition", &Index, &X, &Y))
return NULL; return NULL;
self->obj->SetPointPosition(Index, X, Y); self->obj->SetPointPosition(Index, X, Y);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -229,7 +219,7 @@ PySfShape_SetPointColor(PySfShape* self, PyObject *args)
{ {
unsigned int Index; unsigned int Index;
PySfColor *Color; PySfColor *Color;
if (!PyArg_ParseTuple(args, "IO!", &Index, &PySfColorType, &Color)) if (!PyArg_ParseTuple(args, "IO!:Shape.SetPointColor", &Index, &PySfColorType, &Color))
return NULL; return NULL;
PySfColorUpdate(Color); PySfColorUpdate(Color);
self->obj->SetPointColor(Index, *(Color->obj)); self->obj->SetPointColor(Index, *(Color->obj));
@ -241,7 +231,7 @@ PySfShape_SetPointOutlineColor(PySfShape* self, PyObject *args)
{ {
unsigned int Index; unsigned int Index;
PySfColor *Color; PySfColor *Color;
if (!PyArg_ParseTuple(args, "IO!", &Index, &PySfColorType, &Color)) if (!PyArg_ParseTuple(args, "IO!:Shape:SetPointOutlineColor", &Index, &PySfColorType, &Color))
return NULL; return NULL;
PySfColorUpdate(Color); PySfColorUpdate(Color);
self->obj->SetPointOutlineColor(Index, *(Color->obj)); self->obj->SetPointOutlineColor(Index, *(Color->obj));
@ -257,20 +247,14 @@ PySfShape_GetNbPoints(PySfShape* self, PyObject *args)
static PyObject * static PyObject *
PySfShape_EnableFill(PySfShape* self, PyObject *args) PySfShape_EnableFill(PySfShape* self, PyObject *args)
{ {
if (PyObject_IsTrue(args)) self->obj->EnableFill(PyBool_AsBool(args));
self->obj->EnableFill(true);
else
self->obj->EnableFill(false);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
PySfShape_EnableOutline(PySfShape* self, PyObject *args) PySfShape_EnableOutline(PySfShape* self, PyObject *args)
{ {
if (PyObject_IsTrue(args)) self->obj->EnableOutline(PyBool_AsBool(args));
self->obj->EnableOutline(true);
else
self->obj->EnableOutline(false);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -346,8 +330,7 @@ Create a shape made of a single circle.\n\
PyTypeObject PySfShapeType = { PyTypeObject PySfShapeType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Shape", /*tp_name*/ "Shape", /*tp_name*/
sizeof(PySfShape), /*tp_basicsize*/ sizeof(PySfShape), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -375,7 +358,7 @@ PyTypeObject PySfShapeType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfShape_methods, /* tp_methods */ PySfShape_methods, /* tp_methods */
PySfShape_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PySfDrawableType, /* tp_base */ &PySfDrawableType, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -391,6 +374,6 @@ PyTypeObject PySfShapeType = {
PySfShape * PySfShape *
GetNewPySfShape() GetNewPySfShape()
{ {
return PyObject_New(PySfShape, &PySfShapeType); return (PySfShape *)PySfShape_new(&PySfShapeType, NULL, NULL);
} }

View file

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

View file

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

View file

@ -23,33 +23,26 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "Sound.hpp" #include "Sound.hpp"
#include "SoundBuffer.hpp" #include "SoundBuffer.hpp"
extern PyTypeObject PySfSoundBufferType; #include "compat.hpp"
static PyMemberDef PySfSound_members[] = {
{NULL} /* Sentinel */ extern PyTypeObject PySfSoundBufferType;
};
static void static void
PySfSound_dealloc(PySfSound *self) PySfSound_dealloc(PySfSound *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfSound *self; PySfSound *self;
self = (PySfSound *)type->tp_alloc(type, 0); self = (PySfSound *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -61,21 +54,17 @@ static PyObject*
PySfSound_SetBuffer(PySfSound *self, PyObject *args) PySfSound_SetBuffer(PySfSound *self, PyObject *args)
{ {
PySfSoundBuffer *Buffer = (PySfSoundBuffer *)args; PySfSoundBuffer *Buffer = (PySfSoundBuffer *)args;
if ( ! PyObject_TypeCheck(args, &PySfSoundBufferType)) if (!PyObject_TypeCheck(args, &PySfSoundBufferType))
PyErr_SetString(PyExc_TypeError, "The argument must be a sfSoundBuffer."); PyErr_SetString(PyExc_TypeError, "Sound.SetBuffer() The argument must be a sf.SoundBuffer.");
self->obj->SetBuffer(*(Buffer->obj)); self->obj->SetBuffer(*(Buffer->obj));
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject* static PyObject*
PySfSound_SetLoop(PySfSound *self, PyObject *args) PySfSound_SetLoop(PySfSound *self, PyObject *args)
{ {
if (PyObject_IsTrue(args)) self->obj->SetLoop(PyBool_AsBool(args));
self->obj->SetLoop(true);
else
self->obj->SetLoop(false);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -147,10 +136,7 @@ PySfSound_GetPlayingOffset(PySfSound *self)
static PyObject* static PyObject*
PySfSound_GetLoop(PySfSound *self) PySfSound_GetLoop(PySfSound *self)
{ {
if (self->obj->GetLoop()) return PyBool_FromLong(self->obj->GetLoop());
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
@ -184,7 +170,7 @@ static PyObject*
PySfSound_SetPosition(PySfSound *self, PyObject *args) PySfSound_SetPosition(PySfSound *self, PyObject *args)
{ {
float X, Y, Z; float X, Y, Z;
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z)) if (!PyArg_ParseTuple(args, "fff:Sound.SetPosition", &X, &Y, &Z))
return NULL; return NULL;
self->obj->SetPosition(X, Y, Z); self->obj->SetPosition(X, Y, Z);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -233,8 +219,7 @@ static PyMethodDef PySfSound_methods[] = {
}; };
PyTypeObject PySfSoundType = { PyTypeObject PySfSoundType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Sound", /*tp_name*/ "Sound", /*tp_name*/
sizeof(PySfSound), /*tp_basicsize*/ sizeof(PySfSound), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -272,7 +257,7 @@ Copy constructor : Sound(Copy) where Copy is a sf.Sound instance.", /* tp_doc */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfSound_methods, /* tp_methods */ PySfSound_methods, /* tp_methods */
PySfSound_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -286,9 +271,7 @@ Copy constructor : Sound(Copy) where Copy is a sf.Sound instance.", /* tp_doc */
static int static int
PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds) PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds)
{ {
// Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, float X = 0.f, float Y = 0.f, float Z = 0.f);
const char *kwlist[] = {"Buffer", "Loop", "Pitch", "Volume", "X", "Y", "Z", NULL}; const char *kwlist[] = {"Buffer", "Loop", "Pitch", "Volume", "X", "Y", "Z", NULL};
PySfSoundBuffer *Buffer=NULL; PySfSoundBuffer *Buffer=NULL;
bool Loop=false; bool Loop=false;
@ -298,19 +281,17 @@ PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds)
if (PyTuple_Size(args) == 1) if (PyTuple_Size(args) == 1)
{ {
PySfSound *Copy; PySfSound *Copy;
if (PyArg_ParseTuple(args, "O!", &PySfSoundType, &Copy)) if (PyArg_ParseTuple(args, "O!:Sound.__init__", &PySfSoundType, &Copy))
{ {
self->obj = new sf::Sound(*(Copy->obj)); self->obj = new sf::Sound(*(Copy->obj));
return 0; return 0;
} }
else else PyErr_Clear();
PyErr_Clear();
} }
if (PyTuple_Size(args) > 0) if (PyTuple_Size(args) > 0)
{ {
if ( !PyArg_ParseTupleAndKeywords(args, kwds, "O!|Offfff", (char **)kwlist, &PySfSoundBufferType, &Buffer, &LoopObj, &Pitch, &Volume, &X, &Y, &Z)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!|Offfff:Sound.__init__", (char **)kwlist, &PySfSoundBufferType, &Buffer, &LoopObj, &Pitch, &Volume, &X, &Y, &Z))
return -1; return -1;
if (PyObject_IsTrue(LoopObj)) if (PyObject_IsTrue(LoopObj))
Loop = true; Loop = true;
@ -326,13 +307,13 @@ void
PySfSound_InitConst() PySfSound_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::Sound::Stopped); obj = PyLong_FromLong(sf::Sound::Stopped);
PyDict_SetItemString(PySfSoundType.tp_dict, "Stopped", obj); PyDict_SetItemString(PySfSoundType.tp_dict, "Stopped", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Sound::Paused); obj = PyLong_FromLong(sf::Sound::Paused);
PyDict_SetItemString(PySfSoundType.tp_dict, "Paused", obj); PyDict_SetItemString(PySfSoundType.tp_dict, "Paused", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Sound::Playing); obj = PyLong_FromLong(sf::Sound::Playing);
PyDict_SetItemString(PySfSoundType.tp_dict, "Playing", obj); PyDict_SetItemString(PySfSoundType.tp_dict, "Playing", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View file

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

View file

@ -24,29 +24,21 @@
#include "SoundBuffer.hpp" #include "SoundBuffer.hpp"
#include "compat.hpp"
static PyMemberDef PySfSoundBuffer_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfSoundBuffer_dealloc(PySfSoundBuffer *self) PySfSoundBuffer_dealloc(PySfSoundBuffer *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfSoundBuffer *self; PySfSoundBuffer *self;
self = (PySfSoundBuffer *)type->tp_alloc(type, 0); self = (PySfSoundBuffer *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -56,11 +48,7 @@ PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds);
static PyObject* static PyObject*
PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args) PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args)
{ {
char *path = PyString_AsString(args); load_from_file(self, args);
if (self->obj->LoadFromFile(path))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
@ -69,13 +57,10 @@ PySfSoundBuffer_LoadFromMemory(PySfSoundBuffer* self, PyObject *args)
unsigned int SizeInBytes; unsigned int SizeInBytes;
char *Data; char *Data;
if (! PyArg_ParseTuple(args, "s#", &Data, &SizeInBytes)) if (!PyArg_ParseTuple(args, "s#:SoundBuffer.LoadFromMemory", &Data, &SizeInBytes))
return NULL; return NULL;
if (self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes)) return PyBool_FromLong(self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
@ -84,29 +69,26 @@ PySfSoundBuffer_LoadFromSamples(PySfSoundBuffer* self, PyObject *args)
unsigned int SizeInBytes, ChannelsCount, SampleRate; unsigned int SizeInBytes, ChannelsCount, SampleRate;
char *Data; char *Data;
if (! PyArg_ParseTuple(args, "s#II", &Data, &SizeInBytes, &ChannelsCount, &SampleRate)) if (!PyArg_ParseTuple(args, "s#II:SoundBuffer.LoadFromSamples", &Data, &SizeInBytes, &ChannelsCount, &SampleRate))
return NULL; return NULL;
if (self->obj->LoadFromSamples((const sf::Int16*)Data, (std::size_t) SizeInBytes/2, ChannelsCount, SampleRate)) return PyBool_FromLong(self->obj->LoadFromSamples((const sf::Int16*)Data, (std::size_t) SizeInBytes/2, ChannelsCount, SampleRate));
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
PySfSoundBuffer_GetSamples(PySfSoundBuffer *self) PySfSoundBuffer_GetSamples(PySfSoundBuffer *self)
{ {
#ifdef IS_PY3K
return PyBytes_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2);
#else
return PyString_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2); return PyString_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2);
#endif
} }
static PyObject* static PyObject*
PySfSoundBuffer_SaveToFile(PySfSoundBuffer *self, PyObject *args) PySfSoundBuffer_SaveToFile(PySfSoundBuffer *self, PyObject *args)
{ {
char *path = PyString_AsString(args); save_to_file(self, args);
if (self->obj->SaveToFile(path))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
@ -151,8 +133,7 @@ static PyMethodDef PySfSoundBuffer_methods[] = {
}; };
PyTypeObject PySfSoundBufferType = { PyTypeObject PySfSoundBufferType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"SoundBuffer", /*tp_name*/ "SoundBuffer", /*tp_name*/
sizeof(PySfSoundBuffer), /*tp_basicsize*/ sizeof(PySfSoundBuffer), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -182,7 +163,7 @@ Copy constructor : SoundBuffer(Copy) where Copy is a sf.SoundBuffer instance.",
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfSoundBuffer_methods, /* tp_methods */ PySfSoundBuffer_methods, /* tp_methods */
PySfSoundBuffer_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -197,22 +178,24 @@ Copy constructor : SoundBuffer(Copy) where Copy is a sf.SoundBuffer instance.",
static int static int
PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds) PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds)
{ {
if (PyTuple_Size(args) == 1) int size = PyTuple_Size(args);
if (size == 1)
{ {
PySfSoundBuffer *Copy; PySfSoundBuffer *Copy;
if (PyArg_ParseTuple(args, "O!", &PySfSoundBufferType, &Copy)) if (!PyArg_ParseTuple(args, "O!:SoundBuffer.__init__", &PySfSoundBufferType, &Copy))
self->obj = new sf::SoundBuffer(*(Copy->obj));
else
return -1; return -1;
self->obj = new sf::SoundBuffer(*(Copy->obj));
} }
else else if (size == 0)
self->obj = new sf::SoundBuffer(); self->obj = new sf::SoundBuffer();
else
PyErr_SetString(PyExc_TypeError, "SoundBuffer.__init__() takes 0 or 1 argument");
return 0; return 0;
} }
PySfSoundBuffer * PySfSoundBuffer *
GetNewPySfSoundBuffer() GetNewPySfSoundBuffer()
{ {
return PyObject_New(PySfSoundBuffer, &PySfSoundBufferType); return (PySfSoundBuffer *)PySfSoundBuffer_new(&PySfSoundBufferType, NULL, NULL);
} }

View file

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

View file

@ -23,35 +23,26 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "SoundBufferRecorder.hpp" #include "SoundBufferRecorder.hpp"
#include "SoundBuffer.hpp" #include "SoundBuffer.hpp"
#include "compat.hpp"
extern PyTypeObject PySfSoundRecorderType; extern PyTypeObject PySfSoundRecorderType;
static PyMemberDef PySfSoundBufferRecorder_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfSoundBufferRecorder_dealloc(PySfSoundBufferRecorder *self) PySfSoundBufferRecorder_dealloc(PySfSoundBufferRecorder *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfSoundBufferRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfSoundBufferRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfSoundBufferRecorder *self; PySfSoundBufferRecorder *self;
self = (PySfSoundBufferRecorder *)type->tp_alloc(type, 0); self = (PySfSoundBufferRecorder *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -66,7 +57,7 @@ static PyObject *
PySfSoundBufferRecorder_GetBuffer(PySfSoundBufferRecorder* self) PySfSoundBufferRecorder_GetBuffer(PySfSoundBufferRecorder* self)
{ {
PySfSoundBuffer *SoundBuffer = GetNewPySfSoundBuffer(); PySfSoundBuffer *SoundBuffer = GetNewPySfSoundBuffer();
SoundBuffer->obj = new sf::SoundBuffer( self->obj->GetBuffer() ); SoundBuffer->obj = new sf::SoundBuffer(self->obj->GetBuffer());
return (PyObject *)SoundBuffer; return (PyObject *)SoundBuffer;
} }
@ -77,8 +68,7 @@ static PyMethodDef PySfSoundBufferRecorder_methods[] = {
}; };
PyTypeObject PySfSoundBufferRecorderType = { PyTypeObject PySfSoundBufferRecorderType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"SoundBufferRecorder", /*tp_name*/ "SoundBufferRecorder", /*tp_name*/
sizeof(PySfSoundBufferRecorder), /*tp_basicsize*/ sizeof(PySfSoundBufferRecorder), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -106,7 +96,7 @@ PyTypeObject PySfSoundBufferRecorderType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfSoundBufferRecorder_methods, /* tp_methods */ PySfSoundBufferRecorder_methods, /* tp_methods */
PySfSoundBufferRecorder_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PySfSoundRecorderType, /* tp_base */ &PySfSoundRecorderType, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View file

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

View file

@ -24,57 +24,58 @@
#include "SoundRecorder.hpp" #include "SoundRecorder.hpp"
#include "compat.hpp"
static PyMemberDef PySfSoundRecorder_members[] = {
{NULL} /* Sentinel */
};
bool CustomSoundRecorder::OnStart() bool CustomSoundRecorder::OnStart()
{ {
bool result = false;
if (PyObject_HasAttrString(SoundRecorder, "OnStart")) if (PyObject_HasAttrString(SoundRecorder, "OnStart"))
if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnStart"), NULL))) {
return true; PyObject *OnStart = PyObject_GetAttrString(SoundRecorder, "OnStart");
return false; PyObject *Result = PyObject_CallFunction(OnStart, NULL);
result = PyBool_AsBool(Result);
Py_DECREF(OnStart);
Py_DECREF(Result);
}
return result;
} }
bool CustomSoundRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount) bool CustomSoundRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount)
{ {
bool result = false;
if (PyObject_HasAttrString(SoundRecorder, "OnGetData")) if (PyObject_HasAttrString(SoundRecorder, "OnGetData"))
{ {
if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnGetData"), (char *)"#s", (char *)Samples, SamplesCount*2))) PyObject *OnGetData = PyObject_GetAttrString(SoundRecorder, "OnGetData");
{ PyObject *Result = PyObject_CallFunction(OnGetData, (char *)"#s", (char *)Samples, SamplesCount*2);
return true; result = PyBool_AsBool(Result);
} Py_DECREF(OnGetData);
Py_DECREF(Result);
} }
return false; return result;
} }
void CustomSoundRecorder::OnStop() void CustomSoundRecorder::OnStop()
{ {
if (PyObject_HasAttrString(SoundRecorder, "OnStop")) if (PyObject_HasAttrString(SoundRecorder, "OnStop"))
PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnStop"), NULL); {
PyObject *OnStop = PyObject_GetAttrString(SoundRecorder, "OnStop");
PyObject_CallFunction(OnStop, NULL);
Py_DECREF(OnStop);
}
} }
static void static void
PySfSoundRecorder_dealloc(PySfSoundRecorder* self) PySfSoundRecorder_dealloc(PySfSoundRecorder* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfSoundRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfSoundRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfSoundRecorder *self; PySfSoundRecorder *self;
self = (PySfSoundRecorder *)type->tp_alloc(type, 0); self = (PySfSoundRecorder *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
@ -86,11 +87,10 @@ PySfSoundRecorder_init(PySfSoundRecorder *self, PyObject *args)
return 0; return 0;
} }
static PyObject * static PyObject *
PySfSoundRecorder_Start(PySfSoundRecorder* self, PyObject *args) PySfSoundRecorder_Start(PySfSoundRecorder* self, PyObject *args)
{ {
self->obj->Start( PyInt_AsLong(args) ); self->obj->Start(PyLong_AsLong(args));
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -104,20 +104,16 @@ PySfSoundRecorder_Stop(PySfSoundRecorder* self)
static PyObject * static PyObject *
PySfSoundRecorder_GetSampleRate(PySfSoundRecorder* self) PySfSoundRecorder_GetSampleRate(PySfSoundRecorder* self)
{ {
return PyInt_FromLong(self->obj->GetSampleRate()); return PyLong_FromLong(self->obj->GetSampleRate());
} }
static PyObject * static PyObject *
PySfSoundRecorder_CanCapture(PySfSoundRecorder* self) PySfSoundRecorder_CanCapture(PySfSoundRecorder* self)
{ {
if (sf::SoundRecorder::CanCapture()) return PyBool_FromLong(sf::SoundRecorder::CanCapture());
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyMethodDef PySfSoundRecorder_methods[] = { 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)."}, {"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."}, {"Stop", (PyCFunction)PySfSoundRecorder_Stop, METH_NOARGS, "Stop()\nStop the capture."},
@ -128,8 +124,7 @@ static PyMethodDef PySfSoundRecorder_methods[] = {
PyTypeObject PySfSoundRecorderType = { PyTypeObject PySfSoundRecorderType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"SoundRecorder", /*tp_name*/ "SoundRecorder", /*tp_name*/
sizeof(PySfSoundRecorder), /*tp_basicsize*/ sizeof(PySfSoundRecorder), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -160,7 +155,7 @@ Construct the sound recorder with a callback function for processing captured sa
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfSoundRecorder_methods, /* tp_methods */ PySfSoundRecorder_methods, /* tp_methods */
PySfSoundRecorder_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View file

@ -25,13 +25,9 @@
#ifndef __PYSOUNDRECORDER_HPP #ifndef __PYSOUNDRECORDER_HPP
#define __PYSOUNDRECORDER_HPP #define __PYSOUNDRECORDER_HPP
#include <SFML/Audio/SoundRecorder.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "offsetof.hpp" #include <SFML/Audio/SoundRecorder.hpp>
class CustomSoundRecorder : public sf::SoundRecorder class CustomSoundRecorder : public sf::SoundRecorder
{ {

View file

@ -24,31 +24,46 @@
#include "SoundStream.hpp" #include "SoundStream.hpp"
#include "compat.hpp"
bool CustomSoundStream::OnStart() bool CustomSoundStream::OnStart()
{ {
bool result = false;
if (PyObject_HasAttrString(SoundStream, "OnStart")) if (PyObject_HasAttrString(SoundStream, "OnStart"))
if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundStream, "OnStart"), NULL))) {
return true; PyObject *OnStart = PyObject_GetAttrString(SoundStream, "OnStart");
return false; PyObject *Result = PyObject_CallFunction(OnStart, NULL);
result = PyBool_AsBool(Result);
Py_DECREF(OnStart);
Py_DECREF(Result);
}
return result;
} }
bool CustomSoundStream::OnGetData(Chunk& Data) bool CustomSoundStream::OnGetData(Chunk& Data)
{ {
bool result = false;
if (PyData != NULL) {
Py_DECREF(PyData);
}
if (PyObject_HasAttrString(SoundStream, "OnGetData")) if (PyObject_HasAttrString(SoundStream, "OnGetData"))
{ {
PyObject *PyData=NULL; PyObject *Function = PyObject_GetAttrString(SoundStream, "OnGetData");
if ((PyData = PyObject_CallFunction(PyObject_GetAttrString(SoundStream, "OnGetData"), NULL))) Data.NbSamples = 0;
PyData = PyObject_CallFunction(Function, NULL);
if (PyData != NULL)
{ {
if (PyArg_Parse(PyData, "s#", &(Data.Samples), &(Data.NbSamples))) if (PyArg_Parse(PyData, "s#", &(Data.Samples), &(Data.NbSamples)))
{ {
Data.NbSamples /= 2; Data.NbSamples /= 2;
if (Data.NbSamples > 0) if (Data.NbSamples > 0)
return true; result = true;
} }
} }
Py_DECREF(Function);
} }
return false; return result;
} }
void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate) void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate)
@ -56,16 +71,11 @@ void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate
Initialize(ChannelsCount, SampleRate); Initialize(ChannelsCount, SampleRate);
} }
static PyMemberDef PySfSoundStream_members[] = {
{NULL} /* Sentinel */
};
static int static int
PySfSoundStream_init(PySfSoundStream *self, PyObject *args, PyObject *kwds) PySfSoundStream_init(PySfSoundStream *self, PyObject *args, PyObject *kwds)
{ {
self->obj = new CustomSoundStream(); self->obj = new CustomSoundStream();
self->obj->PyData = NULL;
self->obj->SoundStream = (PyObject *)self; self->obj->SoundStream = (PyObject *)self;
return 0; return 0;
} }
@ -74,7 +84,7 @@ static void
PySfSoundStream_dealloc(PySfSoundStream *self) PySfSoundStream_dealloc(PySfSoundStream *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
@ -89,7 +99,7 @@ static PyObject *
PySfSoundStream_Initialize(PySfSoundStream *self, PyObject *args) PySfSoundStream_Initialize(PySfSoundStream *self, PyObject *args)
{ {
unsigned int ChannelsCount, SampleRate; unsigned int ChannelsCount, SampleRate;
if (!PyArg_ParseTuple(args, "II", &ChannelsCount, &SampleRate)) if (!PyArg_ParseTuple(args, "II:SoundStream.Initialize", &ChannelsCount, &SampleRate))
return NULL; return NULL;
self->obj->Init(ChannelsCount, SampleRate); self->obj->Init(ChannelsCount, SampleRate);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -191,7 +201,7 @@ static PyObject*
PySfSoundStream_SetPosition(PySfSoundStream *self, PyObject *args) PySfSoundStream_SetPosition(PySfSoundStream *self, PyObject *args)
{ {
float X, Y, Z; float X, Y, Z;
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z)) if (!PyArg_ParseTuple(args, "fff:SoundStream.SetPosition", &X, &Y, &Z))
return NULL; return NULL;
self->obj->SetPosition(X, Y, Z); self->obj->SetPosition(X, Y, Z);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -206,20 +216,14 @@ PySfSoundStream_GetStatus(PySfSoundStream *self)
static PyObject* static PyObject*
PySfSoundStream_SetLoop(PySfSoundStream *self, PyObject *args) PySfSoundStream_SetLoop(PySfSoundStream *self, PyObject *args)
{ {
if (PyObject_IsTrue(args)) self->obj->SetLoop(PyBool_AsBool(args));
self->obj->SetLoop(true);
else
self->obj->SetLoop(false);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject* static PyObject*
PySfSoundStream_GetLoop(PySfSoundStream *self) PySfSoundStream_GetLoop(PySfSoundStream *self)
{ {
if (self->obj->GetLoop()) return PyBool_FromLong(self->obj->GetLoop());
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject* static PyObject*
@ -258,8 +262,7 @@ Set the audio stream parameters, you must call it before Play()\n\
PyTypeObject PySfSoundStreamType = { PyTypeObject PySfSoundStreamType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"SoundStream", /*tp_name*/ "SoundStream", /*tp_name*/
sizeof(PySfSoundStream), /*tp_basicsize*/ sizeof(PySfSoundStream), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -290,7 +293,7 @@ or for streaming sound from the network", /* tp_doc */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfSoundStream_methods, /* tp_methods */ PySfSoundStream_methods, /* tp_methods */
PySfSoundStream_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -307,13 +310,13 @@ void
PySfSoundStream_InitConst() PySfSoundStream_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::SoundStream::Stopped); obj = PyLong_FromLong(sf::SoundStream::Stopped);
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Stopped", obj); PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Stopped", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::SoundStream::Paused); obj = PyLong_FromLong(sf::SoundStream::Paused);
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Paused", obj); PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Paused", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::SoundStream::Playing); obj = PyLong_FromLong(sf::SoundStream::Playing);
PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Playing", obj); PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Playing", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View file

@ -25,16 +25,15 @@
#ifndef __PYSOUNDSTREAM_HPP #ifndef __PYSOUNDSTREAM_HPP
#define __PYSOUNDSTREAM_HPP #define __PYSOUNDSTREAM_HPP
#include <SFML/Audio/SoundStream.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include <SFML/Audio/SoundStream.hpp>
class CustomSoundStream : public sf::SoundStream class CustomSoundStream : public sf::SoundStream
{ {
public : public :
PyObject *SoundStream; PyObject *SoundStream;
PyObject *PyData;
virtual bool OnStart(); virtual bool OnStart();
virtual bool OnGetData(Chunk& Data); virtual bool OnGetData(Chunk& Data);
void Init(unsigned int ChannelsCount, unsigned int SampleRate); void Init(unsigned int ChannelsCount, unsigned int SampleRate);

View file

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

View file

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

View file

@ -27,52 +27,40 @@
#include "Color.hpp" #include "Color.hpp"
#include "Rect.hpp" #include "Rect.hpp"
#include "compat.hpp"
extern PyTypeObject PySfColorType; extern PyTypeObject PySfColorType;
extern PyTypeObject PySfImageType; extern PyTypeObject PySfImageType;
extern PyTypeObject PySfDrawableType; extern PyTypeObject PySfDrawableType;
extern PyTypeObject PySfFontType; extern PyTypeObject PySfFontType;
static PyMemberDef PySfString_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfString_dealloc(PySfString *self) PySfString_dealloc(PySfString *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfString *self; PySfString *self;
self = (PySfString *)type->tp_alloc(type, 0); self = (PySfString *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int static int
PySfString_init(PySfString *self, PyObject *args, PyObject *kwds) PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
{ {
const char *kwlist[] = {"Text", "Font", "Size", NULL}; const char *kwlist[] = {"Text", "Font", "Size", NULL};
float Size = 30.f; float Size = 30.f;
std::string Text = ""; PyObject *Text=NULL;
char *TextTmp = NULL;
unsigned int TextSize;
PySfFont *FontTmp = NULL; PySfFont *FontTmp = NULL;
sf::Font *Font; sf::Font *Font;
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|s#O!f", (char **)kwlist, &TextTmp, &TextSize, &PySfFontType, &FontTmp, &Size)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "|OO!f:String.__init__", (char **)kwlist, &Text, &PySfFontType, &FontTmp, &Size))
return -1; return -1;
if (FontTmp) if (FontTmp)
@ -80,39 +68,74 @@ PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
else else
Font = (sf::Font *)&(sf::Font::GetDefaultFont()); Font = (sf::Font *)&(sf::Font::GetDefaultFont());
if (TextSize >= 2 && TextTmp) if (Text != NULL)
if ((unsigned char)TextTmp[0] == 0xff && (unsigned char)TextTmp[1] == 0xfe) {
if (PyUnicode_Check(Text))
{ {
self->obj = new sf::String(sf::Unicode::Text((const sf::Uint16 *)(TextTmp+2)), *Font, Size); #if Py_UNICODE_SIZE == 4
return 0; self->obj = new sf::String((sf::Uint32 *)PyUnicode_AS_UNICODE(Text), *Font, Size);
#else
self->obj = new sf::String((sf::Uint16 *)PyUnicode_AS_UNICODE(Text), *Font, Size);
#endif
} }
#ifdef IS_PY3K
if (TextTmp != NULL) else if (PyBytes_Check(Text))
self->obj = new sf::String(sf::Unicode::Text((const sf::Uint8 *)(TextTmp)), *Font, Size); self->obj = new sf::String(sf::Unicode::UTF8String((sf::Uint8 *)PyBytes_AsString(Text)), *Font, Size);
#else
else if (PyString_Check(Text))
self->obj = new sf::String(sf::Unicode::UTF8String((sf::Uint8 *)PyString_AsString(Text)), *Font, Size);
#endif
else
{
PyErr_SetString(PyExc_TypeError, "String.__init__() first argument must be str");
return -1;
}
}
else else
self->obj = new sf::String(); self->obj = new sf::String("", *Font, Size);
return 0; return 0;
} }
static PyObject * static PyObject *
PySfString_SetText(PySfString* self, PyObject *args) PySfString_SetText(PySfString* self, PyObject *args)
{ {
char *TextTmp = NULL; char *Text, *EncodingStr=NULL;
int Size; int Length;
if (!PyArg_Parse(args, "s#", &TextTmp, &Size)) std::string Encoding;
return NULL; if (PyArg_ParseTuple(args, "u:String.SetText", &Text))
if (Size >= 2)
{ {
if ((unsigned char)TextTmp[0] == 0xff && (unsigned char)TextTmp[1] == 0xfe) #if Py_UNICODE_SIZE == 4
self->obj->SetText((sf::Uint32 *)Text);
#else
self->obj->SetText((sf::Uint16 *)Text);
#endif
}
else if (PyArg_ParseTuple(args, "s|#s:String.SetText", &Text, &Length, &EncodingStr))
{
PyErr_Clear();
if (EncodingStr == NULL)
self->obj->SetText(sf::Unicode::UTF8String((sf::Uint8 *)Text));
else
{ {
self->obj->SetText(sf::Unicode::Text((const sf::Uint16 *)(TextTmp+2))); Encoding.assign(EncodingStr);
Py_RETURN_NONE; if (Encoding == "utf8")
self->obj->SetText(sf::Unicode::UTF8String((sf::Uint8 *)Text));
else if (Encoding == "utf16")
self->obj->SetText(sf::Unicode::UTF16String((sf::Uint16 *)(Text+2)));
else if (Encoding == "utf32")
self->obj->SetText(sf::Unicode::UTF32String((sf::Uint32 *)(Text+4)));
else
{
PyErr_Format(PyExc_TypeError, "String.SetText() Encoding %s not supported", EncodingStr);
return NULL;
}
} }
} }
self->obj->SetText(sf::Unicode::Text((const sf::Uint8 *)(TextTmp))); else
{
PyErr_BadArgument();
return NULL;
}
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -121,7 +144,7 @@ PySfString_SetFont(PySfString* self, PyObject *args)
{ {
PySfFont *Font = (PySfFont *)args; PySfFont *Font = (PySfFont *)args;
if (!PyObject_TypeCheck(Font, &PySfFontType)) if (!PyObject_TypeCheck(Font, &PySfFontType))
PyErr_SetString(PyExc_ValueError, "Argument must be a sf.Font"); PyErr_SetString(PyExc_ValueError, "String.SetFont() Argument must be a sf.Font");
self->obj->SetFont(*(Font->obj)); self->obj->SetFont(*(Font->obj));
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -155,7 +178,12 @@ PySfString_GetStyle(PySfString* self)
static PyObject * static PyObject *
PySfString_GetText(PySfString* self) PySfString_GetText(PySfString* self)
{ {
return PyString_FromString((std::string(self->obj->GetText())).c_str()); #if Py_UNICODE_SIZE == 4
sf::Unicode::UTF32String Text(self->obj->GetText());
#else
sf::Unicode::UTF16String Text(self->obj->GetText());
#endif
return PyUnicode_FromUnicode((const Py_UNICODE*)Text.c_str(), Text.length());
} }
static PyObject * static PyObject *
@ -193,8 +221,8 @@ static PyMethodDef PySfString_methods[] = {
{"GetCharacterPos", (PyCFunction)PySfString_GetCharacterPos, METH_O, "GetCharacterPos(Index)\n\ {"GetCharacterPos", (PyCFunction)PySfString_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\ 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"}, Index : Index of the character"},
{"SetText", (PyCFunction)PySfString_SetText, METH_O, "SetText(Text)\nSet the text (an utf-8 or utf-16 string).\n Text : New text"}, {"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."}, {"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"}, {"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."}, {"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"}, {"SetSize", (PyCFunction)PySfString_SetSize, METH_O, "SetSize(Size)\nSet the size of the string.\n Size : New size, in pixels"},
@ -206,8 +234,7 @@ Return the visual position (a tuple of two floats) of the Index-th character of
}; };
PyTypeObject PySfStringType = { PyTypeObject PySfStringType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"String", /*tp_name*/ "String", /*tp_name*/
sizeof(PySfString), /*tp_basicsize*/ sizeof(PySfString), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -228,7 +255,7 @@ PyTypeObject PySfStringType = {
0, /*tp_as_buffer*/ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
"sf.String defines a graphical 2D text, that can be drawn on screen.\n\ "sf.String defines a graphical 2D text, that can be drawn on screen.\n\
Default constructor : String ()\nConstruct the string from a utf-8 or a utf-16 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 */ 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 */
0, /* tp_traverse */ 0, /* tp_traverse */
0, /* tp_clear */ 0, /* tp_clear */
0, /* tp_richcompare */ 0, /* tp_richcompare */
@ -236,7 +263,7 @@ Default constructor : String ()\nConstruct the string from a utf-8 or a utf-16 s
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfString_methods, /* tp_methods */ PySfString_methods, /* tp_methods */
PySfString_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
&PySfDrawableType, /* tp_base */ &PySfDrawableType, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
@ -253,16 +280,16 @@ Default constructor : String ()\nConstruct the string from a utf-8 or a utf-16 s
void PySfString_InitConst() void PySfString_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::String::Regular); obj = PyLong_FromLong(sf::String::Regular);
PyDict_SetItemString(PySfStringType.tp_dict, "Regular", obj); PyDict_SetItemString(PySfStringType.tp_dict, "Regular", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::String::Bold); obj = PyLong_FromLong(sf::String::Bold);
PyDict_SetItemString(PySfStringType.tp_dict, "Bold", obj); PyDict_SetItemString(PySfStringType.tp_dict, "Bold", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::String::Italic); obj = PyLong_FromLong(sf::String::Italic);
PyDict_SetItemString(PySfStringType.tp_dict, "Italic", obj); PyDict_SetItemString(PySfStringType.tp_dict, "Italic", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::String::Underlined); obj = PyLong_FromLong(sf::String::Underlined);
PyDict_SetItemString(PySfStringType.tp_dict, "Underlined", obj); PyDict_SetItemString(PySfStringType.tp_dict, "Underlined", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View file

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

View file

@ -22,8 +22,12 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "VideoMode.hpp" #include "VideoMode.hpp"
#include <structmember.h>
#include "offsetof.hpp"
#include "compat.hpp"
static PyMemberDef PySfVideoMode_members[] = { static PyMemberDef PySfVideoMode_members[] = {
@ -34,12 +38,11 @@ static PyMemberDef PySfVideoMode_members[] = {
}; };
static void static void
PySfVideoMode_dealloc(PySfVideoMode* self) PySfVideoMode_dealloc(PySfVideoMode* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
@ -72,7 +75,7 @@ PySfVideoMode_init(PySfVideoMode *self, PyObject *args, PyObject *kwds)
{ {
const char *kwlist[] = {"Width", "Height", "BitsPerPixel", NULL}; const char *kwlist[] = {"Width", "Height", "BitsPerPixel", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|I", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "II|I:VideoMode.__init__", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
return -1; return -1;
self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel); self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
@ -111,7 +114,7 @@ PySfVideoMode_GetMode(PySfVideoMode* self, PyObject *args)
std::size_t index; std::size_t index;
PySfVideoMode *VideoMode; PySfVideoMode *VideoMode;
index = (std::size_t)PyInt_AsLong(args); index = (std::size_t)PyLong_AsLong(args);
VideoMode = GetNewPySfVideoMode(); VideoMode = GetNewPySfVideoMode();
VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetMode(index) ); VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetMode(index) );
@ -125,7 +128,7 @@ PySfVideoMode_GetMode(PySfVideoMode* self, PyObject *args)
static PyObject * static PyObject *
PySfVideoMode_GetModesCount(PySfVideoMode* self) PySfVideoMode_GetModesCount(PySfVideoMode* self)
{ {
return PyInt_FromLong(sf::VideoMode::GetModesCount()); return PyLong_FromLong(sf::VideoMode::GetModesCount());
} }
@ -150,8 +153,7 @@ int PySfVideoMode_Compare(PyObject *o1, PyObject *o2)
PyTypeObject PySfVideoModeType = { PyTypeObject PySfVideoModeType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"VideoMode", /*tp_name*/ "VideoMode", /*tp_name*/
sizeof(PySfVideoMode), /*tp_basicsize*/ sizeof(PySfVideoMode), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/

View file

@ -25,15 +25,9 @@
#ifndef __PYVIDEOMODE_HPP #ifndef __PYVIDEOMODE_HPP
#define __PYVIDEOMODE_HPP #define __PYVIDEOMODE_HPP
#include <SFML/System.hpp> #include <SFML/Window/VideoMode.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "offsetof.hpp"
typedef struct { typedef struct {
PyObject_HEAD PyObject_HEAD

View file

@ -23,20 +23,21 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "View.hpp" #include "View.hpp"
#include "Rect.hpp"
#include "offsetof.hpp"
#include "compat.hpp"
extern PyTypeObject PySfFloatRectType; extern PyTypeObject PySfFloatRectType;
static PyMemberDef PySfView_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfView_dealloc(PySfView *self) PySfView_dealloc(PySfView *self)
{ {
if (self->Owner) if (self->Owner)
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
@ -57,7 +58,7 @@ static int
PySfView_init(PySfView *self, PyObject *args, PyObject *kwds) PySfView_init(PySfView *self, PyObject *args, PyObject *kwds)
{ {
PySfFloatRect *Rect=NULL; PySfFloatRect *Rect=NULL;
if (! PyArg_ParseTuple(args, "|O!", &PySfFloatRectType, &Rect)) if (!PyArg_ParseTuple(args, "|O!:View.__init__", &PySfFloatRectType, &Rect))
return -1; return -1;
if (Rect != NULL) if (Rect != NULL)
@ -98,7 +99,7 @@ static PyObject *
PySfView_Move(PySfView* self, PyObject *args) PySfView_Move(PySfView* self, PyObject *args)
{ {
float x, y; float x, y;
if ( !PyArg_ParseTuple(args, "ff", &x, &y) ) if (!PyArg_ParseTuple(args, "ff:View.Move", &x, &y) )
return NULL; return NULL;
self->obj->Move(x, y); self->obj->Move(x, y);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -108,7 +109,7 @@ static PyObject *
PySfView_SetCenter(PySfView* self, PyObject *args) PySfView_SetCenter(PySfView* self, PyObject *args)
{ {
float x, y; float x, y;
if ( !PyArg_ParseTuple(args, "ff", &x, &y) ) if (!PyArg_ParseTuple(args, "ff:View.SetCenter", &x, &y) )
return NULL; return NULL;
self->obj->SetCenter(x, y); self->obj->SetCenter(x, y);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -118,7 +119,7 @@ static PyObject *
PySfView_SetHalfSize(PySfView* self, PyObject *args) PySfView_SetHalfSize(PySfView* self, PyObject *args)
{ {
float x, y; float x, y;
if ( !PyArg_ParseTuple(args, "ff", &x, &y) ) if (!PyArg_ParseTuple(args, "ff:View.SetHalfSize", &x, &y) )
return NULL; return NULL;
self->obj->SetHalfSize(x, y); self->obj->SetHalfSize(x, y);
Py_RETURN_NONE; Py_RETURN_NONE;
@ -145,8 +146,7 @@ static PyMethodDef PySfView_methods[] = {
}; };
PyTypeObject PySfViewType = { PyTypeObject PySfViewType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"View", /*tp_name*/ "View", /*tp_name*/
sizeof(PySfView), /*tp_basicsize*/ sizeof(PySfView), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -174,7 +174,7 @@ PyTypeObject PySfViewType = {
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfView_methods, /* tp_methods */ PySfView_methods, /* tp_methods */
PySfView_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View file

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

View file

@ -22,39 +22,38 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include "Window.hpp" #include "Window.hpp"
#include "Event.hpp"
#include "VideoMode.hpp"
#include "Input.hpp"
#include "WindowSettings.hpp"
#include "SFML/Window/WindowStyle.hpp" #include <SFML/Window/WindowStyle.hpp>
#include "compat.hpp"
extern PyTypeObject PySfEventType; extern PyTypeObject PySfEventType;
extern PyTypeObject PySfWindowSettingsType; extern PyTypeObject PySfWindowSettingsType;
extern PyTypeObject PySfVideoModeType; extern PyTypeObject PySfVideoModeType;
static PyMemberDef PySfWindow_members[] = {
{NULL} /* Sentinel */
};
static void static void
PySfWindow_dealloc(PySfWindow* self) PySfWindow_dealloc(PySfWindow* self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
static PyObject * static PyObject *
PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfWindow *self; PySfWindow *self;
self = (PySfWindow *)type->tp_alloc(type, 0); self = (PySfWindow *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static PyObject* static PyObject*
PySfWindow_GetEvent(PySfWindow *self, PyObject *args) PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
@ -63,7 +62,7 @@ PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
if (! PyObject_TypeCheck(PyEvent, &PySfEventType)) if (! PyObject_TypeCheck(PyEvent, &PySfEventType))
{ {
PyErr_SetString(PyExc_TypeError, "Argument is not a sfEvent"); PyErr_SetString(PyExc_TypeError, "Window.GetEvent() Argument is not a sfEvent");
return NULL; return NULL;
} }
@ -71,43 +70,13 @@ PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
{ {
PyEvent->Type = PyEvent->obj->Type; PyEvent->Type = PyEvent->obj->Type;
PyEvent->Text->Unicode = PyEvent->obj->Text.Unicode; PyEvent->Text->Unicode = PyEvent->obj->Text.Unicode;
PyEvent->Key->Code = PyEvent->obj->Key.Code; PyEvent->Key->Code = PyEvent->obj->Key.Code;
if (PyEvent->obj->Key.Alt && PyEvent->Key->Alt == Py_False) Py_DECREF(PyEvent->Key->Alt);
{ PyEvent->Key->Alt = PyBool_FromLong(PyEvent->obj->Key.Alt);
Py_DECREF(Py_False); Py_DECREF(PyEvent->Key->Control);
Py_INCREF(Py_True); PyEvent->Key->Control = PyBool_FromLong(PyEvent->obj->Key.Control);
PyEvent->Key->Alt = Py_True; Py_DECREF(PyEvent->Key->Shift);
} PyEvent->Key->Shift = PyBool_FromLong(PyEvent->obj->Key.Shift);
else if (PyEvent->Key->Alt == Py_True)
{
Py_DECREF(Py_True);
Py_INCREF(Py_False);
PyEvent->Key->Alt = Py_False;
}
if (PyEvent->obj->Key.Control && PyEvent->Key->Control == Py_False)
{
Py_DECREF(Py_False);
Py_INCREF(Py_True);
PyEvent->Key->Control = Py_True;
}
else if (PyEvent->Key->Control == Py_True)
{
Py_DECREF(Py_True);
Py_INCREF(Py_False);
PyEvent->Key->Control = Py_False;
}
if (PyEvent->obj->Key.Shift && PyEvent->Key->Shift == Py_False)
{
Py_DECREF(Py_False);
Py_INCREF(Py_True);
PyEvent->Key->Shift = Py_True;
}
else if (PyEvent->Key->Shift == Py_True)
{
Py_DECREF(Py_True);
Py_INCREF(Py_False);
PyEvent->Key->Shift = Py_False;
}
PyEvent->MouseButton->Button = PyEvent->obj->MouseButton.Button; PyEvent->MouseButton->Button = PyEvent->obj->MouseButton.Button;
PyEvent->MouseButton->X = PyEvent->obj->MouseButton.X; PyEvent->MouseButton->X = PyEvent->obj->MouseButton.X;
PyEvent->MouseButton->Y = PyEvent->obj->MouseButton.Y; PyEvent->MouseButton->Y = PyEvent->obj->MouseButton.Y;
@ -136,30 +105,23 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
sf::VideoMode *VideoMode; sf::VideoMode *VideoMode;
char *Title=NULL; char *Title=NULL;
unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close; unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close;
PySfWindowSettings *ParamsTmp=NULL; PySfWindowSettings *Params=NULL;
sf::WindowSettings *Params = NULL;
const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL}; const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &ParamsTmp)) if (!PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!:Window.Create", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &Params))
return NULL; return NULL;
if (VideoModeTmp) { VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj; PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
}
else
return NULL;
if (ParamsTmp) if (Params)
{ {
PySfWindowSettingsUpdate(ParamsTmp); PySfWindowSettingsUpdate(Params);
Params = ParamsTmp->obj; self->obj->Create(*VideoMode, Title, WindowStyle, *(Params->obj));
} }
else else
Params = new sf::WindowSettings(); self->obj->Create(*VideoMode, Title, WindowStyle);
self->obj->Create(*VideoMode, Title, WindowStyle, *Params);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -169,7 +131,8 @@ PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds)
{ {
self->obj = new sf::Window(); self->obj = new sf::Window();
if (PyTuple_Size(args) > 0) if (PyTuple_Size(args) > 0)
PySfWindow_Create(self, args, kwds); if (PySfWindow_Create(self, args, kwds) == NULL)
return -1;
return 0; return 0;
} }
@ -182,10 +145,7 @@ PySfWindow_Close(PySfWindow *self)
static PyObject * static PyObject *
PySfWindow_IsOpened(PySfWindow *self) PySfWindow_IsOpened(PySfWindow *self)
{ {
if (self->obj->IsOpened()) return PyBool_FromLong(self->obj->IsOpened());
Py_RETURN_TRUE;
else
Py_RETURN_NONE;
} }
static PyObject * static PyObject *
PySfWindow_GetWidth(PySfWindow *self) PySfWindow_GetWidth(PySfWindow *self)
@ -201,32 +161,20 @@ PySfWindow_GetHeight(PySfWindow *self)
static PyObject * static PyObject *
PySfWindow_UseVerticalSync(PySfWindow *self, PyObject *args) PySfWindow_UseVerticalSync(PySfWindow *self, PyObject *args)
{ {
bool Enabled = false; self->obj->UseVerticalSync(PyBool_AsBool(args));
if (PyObject_IsTrue(args))
Enabled = true;
self->obj->UseVerticalSync(Enabled);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
PySfWindow_ShowMouseCursor(PySfWindow *self, PyObject *args) PySfWindow_ShowMouseCursor(PySfWindow *self, PyObject *args)
{ {
bool Show = false; self->obj->ShowMouseCursor(PyBool_AsBool(args));
if (PyObject_IsTrue(args))
Show = true;
self->obj->ShowMouseCursor(Show);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
PySfWindow_SetActive(PySfWindow *self, PyObject *args) PySfWindow_SetActive(PySfWindow *self, PyObject *args)
{ {
bool Active = false; return PyBool_FromLong(self->obj->SetActive(PyBool_AsBool(args)));
if (PyObject_IsTrue(args))
Active = true;
if (self->obj->SetActive(Active))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
} }
static PyObject * static PyObject *
PySfWindow_Display(PySfWindow *self) PySfWindow_Display(PySfWindow *self)
@ -265,9 +213,8 @@ static PyObject *
PySfWindow_SetPosition(PySfWindow* self, PyObject *args) PySfWindow_SetPosition(PySfWindow* self, PyObject *args)
{ {
int Left=0, Top=0; int Left=0, Top=0;
if (! PyArg_ParseTuple(args, "ii", &Left, &Top)) if (!PyArg_ParseTuple(args, "ii:Window.SetPosition", &Left, &Top))
return NULL; return NULL;
self->obj->SetPosition(Left,Top); self->obj->SetPosition(Left,Top);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -282,20 +229,14 @@ PySfWindow_SetFramerateLimit(PySfWindow *self, PyObject *args)
static PyObject * static PyObject *
PySfWindow_Show(PySfWindow *self, PyObject *args) PySfWindow_Show(PySfWindow *self, PyObject *args)
{ {
if (PyObject_IsTrue(args)) self->obj->Show(PyBool_AsBool(args));
self->obj->Show(true);
else
self->obj->Show(false);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
static PyObject * static PyObject *
PySfWindow_EnableKeyRepeat(PySfWindow *self, PyObject *args) PySfWindow_EnableKeyRepeat(PySfWindow *self, PyObject *args)
{ {
if (PyObject_IsTrue(args)) self->obj->EnableKeyRepeat(PyBool_AsBool(args));
self->obj->EnableKeyRepeat(true);
else
self->obj->EnableKeyRepeat(false);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -303,9 +244,8 @@ static PyObject *
PySfWindow_SetCursorPosition(PySfWindow* self, PyObject *args) PySfWindow_SetCursorPosition(PySfWindow* self, PyObject *args)
{ {
unsigned int Left=0, Top=0; unsigned int Left=0, Top=0;
if (! PyArg_ParseTuple(args, "II", &Left, &Top)) if (!PyArg_ParseTuple(args, "II:Window.SetCursorPosition", &Left, &Top))
return NULL; return NULL;
self->obj->SetCursorPosition(Left,Top); self->obj->SetCursorPosition(Left,Top);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -314,9 +254,8 @@ static PyObject *
PySfWindow_SetSize(PySfWindow* self, PyObject *args) PySfWindow_SetSize(PySfWindow* self, PyObject *args)
{ {
unsigned int Width=0, Height=0; unsigned int Width=0, Height=0;
if (! PyArg_ParseTuple(args, "II", &Width, &Height)) if (!PyArg_ParseTuple(args, "II:Window.SetSize", &Width, &Height))
return NULL; return NULL;
self->obj->SetSize(Width, Height); self->obj->SetSize(Width, Height);
Py_RETURN_NONE; Py_RETURN_NONE;
} }
@ -334,7 +273,7 @@ PySfWindow_SetIcon(PySfWindow* self, PyObject *args)
unsigned int Width, Height, Size; unsigned int Width, Height, Size;
char *Data; char *Data;
if (! PyArg_ParseTuple(args, "IIs#", &Width, &Height, &Data, &Size)) if (! PyArg_ParseTuple(args, "IIs#:Window.SetIcon", &Width, &Height, &Data, &Size))
return NULL; return NULL;
self->obj->SetIcon(Width, Height, (sf::Uint8*) Data); self->obj->SetIcon(Width, Height, (sf::Uint8*) Data);
@ -348,7 +287,7 @@ Create a window.\n\
Mode : Video mode to use (sf.VideoMode instance)\n\ Mode : Video mode to use (sf.VideoMode instance)\n\
Title : Title of the window\n\ Title : Title of the window\n\
WindowStyle : Window style (Resize | Close by default)\n\ WindowStyle : Window style (Resize | Close by default)\n\
Params : Creation parameters (see default constructor for default values)\n"}, Params : Creation parameters (see default constructor for default values)"},
{"Display", (PyCFunction)PySfWindow_Display, METH_NOARGS, "Display()\nDisplay the window on screen."}, {"Display", (PyCFunction)PySfWindow_Display, METH_NOARGS, "Display()\nDisplay the window on screen."},
{"EnableKeyRepeat", (PyCFunction)PySfWindow_EnableKeyRepeat, METH_O, "EnableKeyRepeat(Enable)\nEnable or disable automatic key-repeat. Automatic key-repeat is enabled by default.\n Enabled : True to enable, false to disable"}, {"EnableKeyRepeat", (PyCFunction)PySfWindow_EnableKeyRepeat, METH_O, "EnableKeyRepeat(Enable)\nEnable or disable automatic key-repeat. Automatic key-repeat is enabled by default.\n Enabled : True to enable, false to disable"},
{"GetEvent", (PyCFunction)PySfWindow_GetEvent, METH_O, "GetEvent(Event)\nGet the event on top of events stack, if any, and pop it. Returns True if an event was returned, False if events stack was empty.\n EventReceived : Event to fill, if any."}, {"GetEvent", (PyCFunction)PySfWindow_GetEvent, METH_O, "GetEvent(Event)\nGet the event on top of events stack, if any, and pop it. Returns True if an event was returned, False if events stack was empty.\n EventReceived : Event to fill, if any."},
@ -377,8 +316,7 @@ Change the window's icon.\n\
}; };
PyTypeObject PySfWindowType = { PyTypeObject PySfWindowType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Window", /*tp_name*/ "Window", /*tp_name*/
sizeof(PySfWindow), /*tp_basicsize*/ sizeof(PySfWindow), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -413,7 +351,7 @@ Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfWindow_methods, /* tp_methods */ PySfWindow_methods, /* tp_methods */
PySfWindow_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */

View file

@ -25,17 +25,9 @@
#ifndef __PYWINDOW_HPP #ifndef __PYWINDOW_HPP
#define __PYWINDOW_HPP #define __PYWINDOW_HPP
#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <iostream>
#include <Python.h> #include <Python.h>
#include <structmember.h>
#include "Event.hpp" #include <SFML/Window/Window.hpp>
#include "VideoMode.hpp"
#include "Input.hpp"
#include "WindowSettings.hpp"
typedef struct { typedef struct {

View file

@ -24,6 +24,11 @@
#include "WindowSettings.hpp" #include "WindowSettings.hpp"
#include <structmember.h>
#include "offsetof.hpp"
#include "compat.hpp"
static PyMemberDef PySfWindowSettings_members[] = { static PyMemberDef PySfWindowSettings_members[] = {
{(char *)"DepthBits", T_UINT, offsetof(PySfWindowSettings, DepthBits), 0, (char *)"Depth buffer bits (24 by default)"}, {(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 *)"StencilBits", T_UINT, offsetof(PySfWindowSettings, StencilBits), 0, (char *)"Stencil buffer bits (8 by default)"},
@ -36,7 +41,7 @@ static void
PySfWindowSettings_dealloc(PySfWindowSettings *self) PySfWindowSettings_dealloc(PySfWindowSettings *self)
{ {
delete self->obj; delete self->obj;
self->ob_type->tp_free((PyObject*)self); free_object(self);
} }
void void
@ -51,16 +56,13 @@ static PyObject *
PySfWindowSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfWindowSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfWindowSettings *self; PySfWindowSettings *self;
self = (PySfWindowSettings *)type->tp_alloc(type, 0); self = (PySfWindowSettings *)type->tp_alloc(type, 0);
if (self != NULL) if (self != NULL)
{ {
self->DepthBits = 24; self->DepthBits = 24;
self->StencilBits = 8; self->StencilBits = 8;
self->AntialiasingLevel = 0; self->AntialiasingLevel = 0;
} }
return (PyObject *)self; return (PyObject *)self;
} }
@ -69,21 +71,16 @@ static int
PySfWindowSettings_init(PySfWindowSettings *self, PyObject *args, PyObject *kwds) PySfWindowSettings_init(PySfWindowSettings *self, PyObject *args, PyObject *kwds)
{ {
const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", NULL}; const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", NULL};
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|III", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel))) if (!PyArg_ParseTupleAndKeywords(args, kwds, "|III:WindowSettings.__init__", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel)))
return -1; return -1;
self->obj = new sf::WindowSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel); self->obj = new sf::WindowSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel);
return 0; return 0;
} }
static PyMethodDef PySfWindowSettings_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject PySfWindowSettingsType = { PyTypeObject PySfWindowSettingsType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"WindowSettings", /*tp_name*/ "WindowSettings", /*tp_name*/
sizeof(PySfWindowSettings), /*tp_basicsize*/ sizeof(PySfWindowSettings), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
@ -110,7 +107,7 @@ PyTypeObject PySfWindowSettingsType = {
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfWindowSettings_methods, /* tp_methods */ 0, /* tp_methods */
PySfWindowSettings_members, /* tp_members */ PySfWindowSettings_members, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
@ -126,6 +123,6 @@ PyTypeObject PySfWindowSettingsType = {
PySfWindowSettings * PySfWindowSettings *
GetNewPySfWindowSettings() GetNewPySfWindowSettings()
{ {
return PyObject_New(PySfWindowSettings, &PySfWindowSettingsType); return (PySfWindowSettings *)PySfWindowSettings_new(&PySfWindowSettingsType, NULL, NULL);
} }

View file

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

View file

@ -22,62 +22,25 @@
// //
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window/WindowStyle.hpp>
#include <Python.h>
#include <structmember.h>
#include "WindowStyle.hpp" #include "WindowStyle.hpp"
#include "compat.hpp"
typedef struct {
PyObject_HEAD
} PySfStyle;
static PyMemberDef PySfStyle_members[] = {
{NULL} /* Sentinel */
};
static void
PySfStyle_dealloc(PySfStyle *self)
{
self->ob_type->tp_free((PyObject*)self);
}
static PyObject * static PyObject *
PySfStyle_new(PyTypeObject *type, PyObject *args, PyObject *kwds) PySfStyle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
{ {
PySfStyle *self; PySfStyle *self;
self = (PySfStyle *)type->tp_alloc(type, 0); self = (PySfStyle *)type->tp_alloc(type, 0);
if (self != NULL)
{
}
return (PyObject *)self; return (PyObject *)self;
} }
static int
PySfStyle_init(PySfStyle *self, PyObject *args, PyObject *kwds)
{
return 0;
}
static PyMethodDef PySfStyle_methods[] = {
{NULL} /* Sentinel */
};
PyTypeObject PySfStyleType = { PyTypeObject PySfStyleType = {
PyObject_HEAD_INIT(NULL) head_init
0, /*ob_size*/
"Style", /*tp_name*/ "Style", /*tp_name*/
sizeof(PySfStyle), /*tp_basicsize*/ sizeof(PySfStyle), /*tp_basicsize*/
0, /*tp_itemsize*/ 0, /*tp_itemsize*/
(destructor)PySfStyle_dealloc, /*tp_dealloc*/ 0, /*tp_dealloc*/
0, /*tp_print*/ 0, /*tp_print*/
0, /*tp_getattr*/ 0, /*tp_getattr*/
0, /*tp_setattr*/ 0, /*tp_setattr*/
@ -105,15 +68,15 @@ Fullscreen Fullscreen mode (this flag and all others are mutually exclusive).",
0, /* tp_weaklistoffset */ 0, /* tp_weaklistoffset */
0, /* tp_iter */ 0, /* tp_iter */
0, /* tp_iternext */ 0, /* tp_iternext */
PySfStyle_methods, /* tp_methods */ 0, /* tp_methods */
PySfStyle_members, /* tp_members */ 0, /* tp_members */
0, /* tp_getset */ 0, /* tp_getset */
0, /* tp_base */ 0, /* tp_base */
0, /* tp_dict */ 0, /* tp_dict */
0, /* tp_descr_get */ 0, /* tp_descr_get */
0, /* tp_descr_set */ 0, /* tp_descr_set */
0, /* tp_dictoffset */ 0, /* tp_dictoffset */
(initproc)PySfStyle_init, /* tp_init */ 0, /* tp_init */
0, /* tp_alloc */ 0, /* tp_alloc */
PySfStyle_new, /* tp_new */ PySfStyle_new, /* tp_new */
}; };
@ -121,19 +84,19 @@ Fullscreen Fullscreen mode (this flag and all others are mutually exclusive).",
void PySfStyle_InitConst() void PySfStyle_InitConst()
{ {
PyObject *obj; PyObject *obj;
obj = PyInt_FromLong(sf::Style::None); obj = PyLong_FromLong(sf::Style::None);
PyDict_SetItemString(PySfStyleType.tp_dict, "None", obj); PyDict_SetItemString(PySfStyleType.tp_dict, "None", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Style::Titlebar); obj = PyLong_FromLong(sf::Style::Titlebar);
PyDict_SetItemString(PySfStyleType.tp_dict, "Titlebar", obj); PyDict_SetItemString(PySfStyleType.tp_dict, "Titlebar", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Style::Resize); obj = PyLong_FromLong(sf::Style::Resize);
PyDict_SetItemString(PySfStyleType.tp_dict, "Resize", obj); PyDict_SetItemString(PySfStyleType.tp_dict, "Resize", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Style::Close); obj = PyLong_FromLong(sf::Style::Close);
PyDict_SetItemString(PySfStyleType.tp_dict, "Close", obj); PyDict_SetItemString(PySfStyleType.tp_dict, "Close", obj);
Py_DECREF(obj); Py_DECREF(obj);
obj = PyInt_FromLong(sf::Style::Fullscreen); obj = PyLong_FromLong(sf::Style::Fullscreen);
PyDict_SetItemString(PySfStyleType.tp_dict, "Fullscreen", obj); PyDict_SetItemString(PySfStyleType.tp_dict, "Fullscreen", obj);
Py_DECREF(obj); Py_DECREF(obj);
} }

View file

@ -25,6 +25,14 @@
#ifndef __PYWINDOWSTYLE_HPP #ifndef __PYWINDOWSTYLE_HPP
#define __PYWINDOWSTYLE_HPP #define __PYWINDOWSTYLE_HPP
#include <Python.h>
#include <SFML/Window/WindowStyle.hpp>
typedef struct {
PyObject_HEAD
} PySfStyle;
void void
PySfStyle_InitConst(); PySfStyle_InitConst();

69
python/src/compat.hpp Normal file
View file

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

View file

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

View file

@ -67,7 +67,7 @@
LinkIncremental="2" LinkIncremental="2"
GenerateDebugInformation="true" GenerateDebugInformation="true"
ProgramDatabaseFile="$(IntDir)$(TargetName).pdb" ProgramDatabaseFile="$(IntDir)$(TargetName).pdb"
SubSystem="2" SubSystem="1"
TargetMachine="1" TargetMachine="1"
/> />
<Tool <Tool

View file

@ -3,6 +3,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <SFML/OpenGL.hpp>
#include <iostream> #include <iostream>

View file

@ -3,6 +3,7 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Graphics.hpp> #include <SFML/Graphics.hpp>
#include <windows.h>
#include <cmath> #include <cmath>
HWND Button; HWND Button;

View file

@ -1,11 +1,44 @@
/*
#include <SFML/Window.hpp>
void f(void*)
{
sf::Context context;
}
int main()
{
{
sf::Thread t(&f);
t.Launch();
}
{
sf::Window window(sf::VideoMode(640, 480), "Test");
{
sf::Thread t(&f);
t.Launch();
}
}
{
sf::Thread t(&f);
t.Launch();
}
return 0;
}
*/
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Window.hpp> #include <SFML/Window.hpp>
#include <fstream> #include <SFML/OpenGL.hpp>
#include <iostream>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Entry point of application /// Entry point of application
@ -117,3 +150,4 @@ int main()
return EXIT_SUCCESS; return EXIT_SUCCESS;
} }

View file

@ -51,6 +51,9 @@ mySamples (BufferSize)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Music::~Music() Music::~Music()
{ {
// We must stop before destroying the file :)
Stop();
delete myFile; delete myFile;
} }
@ -60,6 +63,9 @@ Music::~Music()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Music::OpenFromFile(const std::string& Filename) bool Music::OpenFromFile(const std::string& Filename)
{ {
// First stop the music if it was already running
Stop();
// Create the sound file implementation, and open it in read mode // Create the sound file implementation, and open it in read mode
delete myFile; delete myFile;
myFile = priv::SoundFile::CreateRead(Filename); myFile = priv::SoundFile::CreateRead(Filename);
@ -84,6 +90,9 @@ bool Music::OpenFromFile(const std::string& Filename)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Music::OpenFromMemory(const char* Data, std::size_t SizeInBytes) bool Music::OpenFromMemory(const char* Data, std::size_t SizeInBytes)
{ {
// First stop the music if it was already running
Stop();
// Create the sound file implementation, and open it in read mode // Create the sound file implementation, and open it in read mode
delete myFile; delete myFile;
myFile = priv::SoundFile::CreateRead(Data, SizeInBytes); myFile = priv::SoundFile::CreateRead(Data, SizeInBytes);
@ -108,7 +117,7 @@ bool Music::OpenFromMemory(const char* Data, std::size_t SizeInBytes)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Music::OnStart() bool Music::OnStart()
{ {
return myFile->Restart(); return myFile && myFile->Restart();
} }
@ -117,12 +126,19 @@ bool Music::OnStart()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool Music::OnGetData(SoundStream::Chunk& Data) bool Music::OnGetData(SoundStream::Chunk& Data)
{ {
// Fill the chunk parameters if (myFile)
Data.Samples = &mySamples[0]; {
Data.NbSamples = myFile->Read(&mySamples[0], mySamples.size()); // Fill the chunk parameters
Data.Samples = &mySamples[0];
Data.NbSamples = myFile->Read(&mySamples[0], mySamples.size());
// Check if we have reached the end of the audio file // Check if we have reached the end of the audio file
return Data.NbSamples == mySamples.size(); return Data.NbSamples == mySamples.size();
}
else
{
return false;
}
} }

View file

@ -26,7 +26,6 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundStream.hpp> #include <SFML/Audio/SoundStream.hpp>
#include <SFML/Audio/SoundBuffer.hpp>
#include <SFML/Audio/AudioDevice.hpp> #include <SFML/Audio/AudioDevice.hpp>
#include <SFML/Audio/OpenAL.hpp> #include <SFML/Audio/OpenAL.hpp>
#include <SFML/System/Sleep.hpp> #include <SFML/System/Sleep.hpp>
@ -191,6 +190,7 @@ void SoundStream::Run()
{ {
// Create buffers // Create buffers
ALCheck(alGenBuffers(BuffersCount, myBuffers)); ALCheck(alGenBuffers(BuffersCount, myBuffers));
unsigned int EndBuffer = 0xFFFF;
// Fill the queue // Fill the queue
bool RequestStop = FillQueue(); bool RequestStop = FillQueue();
@ -203,37 +203,15 @@ void SoundStream::Run()
// The stream has been interrupted ! // The stream has been interrupted !
if (Sound::GetStatus() == Stopped) if (Sound::GetStatus() == Stopped)
{ {
// User requested to stop if (!RequestStop)
if (RequestStop)
{ {
if (myLoop) // Just continue
{ Sound::Play();
// The stream is in loop mode : restart it
if (OnStart())
{
mySamplesProcessed = 0;
ClearQueue();
RequestStop = FillQueue();
Sound::Play();
}
else
{
// Restart failed : finish the streaming loop
myIsStreaming = false;
break;
}
}
else
{
// The stream is not in loop mode : finish the streaming loop
myIsStreaming = false;
break;
}
} }
else else
{ {
// Streaming is not completed : restart the sound // End streaming
Sound::Play(); myIsStreaming = false;
} }
} }
@ -241,20 +219,45 @@ void SoundStream::Run()
ALint NbProcessed; ALint NbProcessed;
ALCheck(alGetSourcei(Sound::mySource, AL_BUFFERS_PROCESSED, &NbProcessed)); ALCheck(alGetSourcei(Sound::mySource, AL_BUFFERS_PROCESSED, &NbProcessed));
while (NbProcessed-- && !RequestStop) while (NbProcessed--)
{ {
// Pop the first unused buffer from the queue // Pop the first unused buffer from the queue
ALuint Buffer; ALuint Buffer;
ALCheck(alSourceUnqueueBuffers(Sound::mySource, 1, &Buffer)); ALCheck(alSourceUnqueueBuffers(Sound::mySource, 1, &Buffer));
// Retrieve its size and add it to the samples count // Retrieve its size and add it to the samples count
ALint Size; if (Buffer == EndBuffer)
ALCheck(alGetBufferi(Buffer, AL_SIZE, &Size)); {
mySamplesProcessed += Size / sizeof(Int16); // This was the last buffer: reset the sample count
mySamplesProcessed = 0;
EndBuffer = 0xFFFF;
}
else
{
ALint Size;
ALCheck(alGetBufferi(Buffer, AL_SIZE, &Size));
mySamplesProcessed += Size / sizeof(Int16);
}
// Fill it and push it back into the playing queue // Fill it and push it back into the playing queue
if (FillAndPushBuffer(Buffer)) if (!RequestStop)
RequestStop = true; {
if (FillAndPushBuffer(Buffer))
{
// User requested to stop: check if we must loop or really stop
if (myLoop && OnStart())
{
// Looping: mark the current buffer as the last one
// (to know when to reset the sample count)
EndBuffer = Buffer;
}
else
{
// Not looping or restart failed: request stop
RequestStop = true;
}
}
}
} }
// Leave some time for the other threads if the stream is still playing // Leave some time for the other threads if the stream is still playing
@ -269,6 +272,7 @@ void SoundStream::Run()
ClearQueue(); ClearQueue();
// Delete the buffers // Delete the buffers
ALCheck(alSourcei(Sound::mySource, AL_BUFFER, 0));
ALCheck(alDeleteBuffers(BuffersCount, myBuffers)); ALCheck(alDeleteBuffers(BuffersCount, myBuffers));
} }
@ -324,7 +328,7 @@ bool SoundStream::FillQueue()
void SoundStream::ClearQueue() void SoundStream::ClearQueue()
{ {
// Get the number of buffers still in the queue // Get the number of buffers still in the queue
ALint NbQueued; ALint NbQueued;
ALCheck(alGetSourcei(Sound::mySource, AL_BUFFERS_QUEUED, &NbQueued)); ALCheck(alGetSourcei(Sound::mySource, AL_BUFFERS_QUEUED, &NbQueued));
// Unqueue them all // Unqueue them all

View file

@ -382,7 +382,7 @@ void Drawable::Draw(RenderTarget& Target) const
switch (myBlendMode) switch (myBlendMode)
{ {
case Blend::Alpha : GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); break; case Blend::Alpha : GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE_MINUS_SRC_ALPHA)); break;
case Blend::Add : GLCheck(glBlendFunc(GL_ONE, GL_ONE)); break; case Blend::Add : GLCheck(glBlendFunc(GL_SRC_ALPHA, GL_ONE)); break;
case Blend::Multiply : GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO)); break; case Blend::Multiply : GLCheck(glBlendFunc(GL_DST_COLOR, GL_ZERO)); break;
default : break; default : break;
} }

View file

@ -65,7 +65,7 @@ GraphicsContext::GraphicsContext()
// Activate the global context // Activate the global context
if (!Context::IsContextActive()) if (!Context::IsContextActive())
{ {
Context::GetGlobal().SetActive(true); Context::GetDefault().SetActive(true);
myActivated = true; myActivated = true;
} }
else else
@ -86,7 +86,7 @@ GraphicsContext::~GraphicsContext()
{ {
// Deactivate the global context // Deactivate the global context
if (myActivated) if (myActivated)
Context::GetGlobal().SetActive(false); Context::GetDefault().SetActive(false);
} }
} // namespace priv } // namespace priv

View file

@ -267,7 +267,7 @@ void Image::CreateMaskFromColor(Color ColorKey, Uint8 Alpha)
/// This function does a slow pixel copy and should only /// This function does a slow pixel copy and should only
/// be used at initialization time /// be used at initialization time
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Image::Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect) void Image::Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect, bool ApplyAlpha)
{ {
// Make sure both images are valid // Make sure both images are valid
if ((Source.myWidth == 0) || (Source.myHeight == 0) || (myWidth == 0) || (myHeight == 0)) if ((Source.myWidth == 0) || (Source.myHeight == 0) || (myWidth == 0) || (myHeight == 0))
@ -313,11 +313,37 @@ void Image::Copy(const Image& Source, unsigned int DestX, unsigned int DestY, co
Uint8* DstPixels = reinterpret_cast<Uint8*>(&myPixels[0]) + (DestX + DestY * myWidth) * 4; Uint8* DstPixels = reinterpret_cast<Uint8*>(&myPixels[0]) + (DestX + DestY * myWidth) * 4;
// Copy the pixels // Copy the pixels
for (int i = 0; i < Rows; ++i) if (ApplyAlpha)
{ {
memcpy(DstPixels, SrcPixels, Pitch); // Interpolation using alpha values, pixel by pixel (slower)
SrcPixels += SrcStride; for (int i = 0; i < Rows; ++i)
DstPixels += DstStride; {
for (int j = 0; j < Width; ++j)
{
// Get a direct pointer to the components of the current pixel
const Uint8* Src = SrcPixels + j * 4;
Uint8* Dst = DstPixels + j * 4;
// Interpolate RGB components using the alpha value of the source pixel
Uint8 Alpha = Src[3];
Dst[0] = (Src[0] * Alpha + Dst[0] * (255 - Alpha)) / 255;
Dst[1] = (Src[1] * Alpha + Dst[1] * (255 - Alpha)) / 255;
Dst[2] = (Src[2] * Alpha + Dst[2] * (255 - Alpha)) / 255;
}
SrcPixels += SrcStride;
DstPixels += DstStride;
}
}
else
{
// Optimized copy ignoring alpha values, row by row (faster)
for (int i = 0; i < Rows; ++i)
{
memcpy(DstPixels, SrcPixels, Pitch);
SrcPixels += SrcStride;
DstPixels += DstStride;
}
} }
// The texture will need an update // The texture will need an update

View file

@ -46,18 +46,18 @@ RenderWindow::RenderWindow()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct the window /// Construct the window
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderWindow::RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, const WindowSettings& Params) RenderWindow::RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, const ContextSettings& Settings)
{ {
Create(Mode, Title, WindowStyle, Params); Create(Mode, Title, WindowStyle, Settings);
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Construct the window from an existing control /// Construct the window from an existing control
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
RenderWindow::RenderWindow(WindowHandle Handle, const WindowSettings& Params) RenderWindow::RenderWindow(WindowHandle Handle, const ContextSettings& Settings)
{ {
Create(Handle, Params); Create(Handle, Settings);
} }

View file

@ -0,0 +1,86 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Lucas Soltic (elmerod@gmail.com) and Laurent Gomila (laurent.gom@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.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#ifdef SFML_SYSTEM_MACOS
#include <CoreFoundation/CoreFoundation.h>
#include <iostream>
#include <cstdio>
namespace sf
{
namespace priv
{
////////////////////////////////////////////////////////////
/// Under Mac OS X, when launching an application from the Finder,
/// the default working directory is the user home directory ;
/// when launching from Xcode, the default one is the directory
/// containing the application. In order to produce a uniform behaviour
/// and simplify the use of resources, SFML sets the working directory to
/// the Resources folder of the application bundle.
/// The "constructor" attribute forces the function to be called
/// at library loading time.
////////////////////////////////////////////////////////////
void InitializeWorkingDirectory(void) __attribute__ ((constructor));
void InitializeWorkingDirectory(void)
{
char PathBuffer[4096];
bool Encoded = false;
// Get the application bundle
CFBundleRef MainBundle = CFBundleGetMainBundle();
assert(MainBundle != NULL);
// Get the resource directory URL
CFURLRef ResourceDirectory = CFBundleCopyResourcesDirectoryURL(MainBundle);
assert(ResourceDirectory != NULL);
// Convert it as absolute URL
CFURLRef AbsoluteURL = CFURLCopyAbsoluteURL(ResourceDirectory);
assert(AbsoluteURL != NULL);
// Get the path as C string
Encoded = CFURLGetFileSystemRepresentation(AbsoluteURL, true, (UInt8 *)PathBuffer, 4096);
assert(Encoded);
// Set the working directory
chdir(PathBuffer);
CFRelease(AbsoluteURL);
CFRelease(ResourceDirectory);
}
} // namespace priv
} // namespace sf
#endif // SFML_SYSTEM_MACOS

Some files were not shown because too many files have changed in this diff Show more