[SCM] Python bindings for the SFML Library branch, upstream, updated. upstream/1.2-2-g4e61c09
Christoph Egger
Christoph.Egger at gmx.de
Mon Dec 15 16:19:58 UTC 2008
The following commit has been merged in the upstream branch:
commit 4e61c091e012922cd0a29e3269f5101ac624aa60
Author: Christoph Egger <Christoph.Egger at gmx.de>
Date: Sat Dec 13 14:00:13 2008 +0100
Imported Upstream version 1.4~svn956
diff --git a/python/MANIFEST.in b/python/MANIFEST.in
new file mode 100644
index 0000000..a0c972c
--- /dev/null
+++ b/python/MANIFEST.in
@@ -0,0 +1,69 @@
+setup.py
+include src/Blend.cpp
+include src/Clock.cpp
+include src/Color.cpp
+include src/Drawable.cpp
+include src/Event.cpp
+include src/Image.cpp
+include src/Input.cpp
+include src/Joy.cpp
+include src/Key.cpp
+include src/Mouse.cpp
+include src/Music.cpp
+include src/PostFX.cpp
+include src/Rect.cpp
+include src/RenderWindow.cpp
+include src/Sleep.cpp
+include src/Sprite.cpp
+include src/String.cpp
+include src/VideoMode.cpp
+include src/View.cpp
+include src/Window.cpp
+include src/WindowStyle.cpp
+include src/main.cpp
+include src/Font.cpp
+include src/Shape.cpp
+include src/WindowSettings.cpp
+
+include src/Listener.cpp
+include src/Sound.cpp
+include src/SoundBuffer.cpp
+include src/SoundBufferRecorder.cpp
+include src/SoundRecorder.cpp
+include src/SoundStream.cpp
+
+
+include src/Blend.hpp
+include src/Clock.hpp
+include src/Color.hpp
+include src/Drawable.hpp
+include src/Event.hpp
+include src/Image.hpp
+include src/Input.hpp
+include src/Joy.hpp
+include src/Key.hpp
+include src/Mouse.hpp
+include src/Music.hpp
+include src/PostFX.hpp
+include src/Rect.hpp
+include src/RenderWindow.hpp
+include src/Sleep.hpp
+include src/Sprite.hpp
+include src/String.hpp
+include src/VideoMode.hpp
+include src/View.hpp
+include src/Window.hpp
+include src/WindowStyle.hpp
+include src/main.hpp
+include src/Font.hpp
+include src/Shape.hpp
+include src/WindowSettings.hpp
+include src/offsetof.hpp
+
+include src/Listener.hpp
+include src/Sound.hpp
+include src/SoundBuffer.hpp
+include src/SoundBufferRecorder.hpp
+include src/SoundRecorder.hpp
+include src/SoundStream.hpp
+
diff --git a/python/PKG-INFO b/python/PKG-INFO
index 5351247..c786a96 100644
--- a/python/PKG-INFO
+++ b/python/PKG-INFO
@@ -1,8 +1,8 @@
Metadata-Version: 1.0
Name: PySFML
-Version: 1.3
+Version: 1.2
Summary: Python binding for SFML (Simple and Fast Multimedia Library)
-Home-page: http://www.sfml-dev.org/
+Home-page: http://sfml.sourceforge.net/
Author: Rémi Koenig
Author-email: remi.k2620 at gmail.com
License: zlib/png
diff --git a/python/doc/style.css b/python/doc/style.css
new file mode 100644
index 0000000..0a59e69
--- /dev/null
+++ b/python/doc/style.css
@@ -0,0 +1,96 @@
+div#logo
+{
+ margin-bottom : 1em;
+ background : url("http://www.sfml-dev.org/images/logo-bg.jpg") repeat-x;
+}
+
+div#logo a
+{
+ display : block;
+}
+
+div.class_desc
+{
+ margin-left:10px;
+ font-weight: bolder;
+ color:#168;
+}
+
+div.base_class
+{
+ margin-top:8px;
+ margin-left:10px;
+ font-weight: bold;
+ color:#168;
+}
+
+div.attr_name
+{
+ margin-top:20px;
+ margin-left:10px;
+ font-weight: bolder;
+}
+
+div.inherited
+{
+ margin-left:20px;
+ font-size: smaller;
+}
+
+div.desc
+{
+ margin-left:20px;
+}
+
+div.event_member
+{
+ margin-left:30px;
+ font-weight: lighter;
+}
+
+p#footer
+{
+ text-decoration : overline;
+ color : #606060;
+ padding-top : 1em;
+ text-align : center;
+ font-size : smaller;
+}
+
+p#footer a
+{
+ color : #007298;
+ text-decoration : none;
+}
+
+H1 {
+ text-align : center;
+ margin-top : 0px;
+ color : #2090B0;
+ font-size : 160%;
+}
+H2 {
+ font-size: 120%;
+}
+H3 {
+ font-size: 100%;
+}
+
+a {
+ color: #2090B0;
+}
+a:visited {
+ color: #2090B0;
+}
+HR { height: 1px;
+ border: none;
+ border-top: 1px solid black;
+}
+
+BODY,H1,H2,H3,H4,H5,H6,P,CENTER,TD,TH,UL,DL,DIV {
+ font-family: Geneva, Arial, Helvetica, sans-serif;
+}
+BODY,TD {
+ font-size: 90%;
+}
+
diff --git a/python/samples/data/apple.png b/python/samples/data/apple.png
new file mode 100644
index 0000000..0cfb031
Binary files /dev/null and b/python/samples/data/apple.png differ
diff --git a/python/samples/data/fart.wav b/python/samples/data/fart.wav
new file mode 100644
index 0000000..b265837
Binary files /dev/null and b/python/samples/data/fart.wav differ
diff --git a/python/samples/data/rond2.png b/python/samples/data/rond2.png
new file mode 100644
index 0000000..8d36b1d
Binary files /dev/null and b/python/samples/data/rond2.png differ
diff --git a/python/samples/libsndfile-1.dll b/python/samples/libsndfile-1.dll
new file mode 100644
index 0000000..f112de2
Binary files /dev/null and b/python/samples/libsndfile-1.dll differ
diff --git a/python/samples/opengl.py b/python/samples/opengl.py
new file mode 100644
index 0000000..6442b83
--- /dev/null
+++ b/python/samples/opengl.py
@@ -0,0 +1,166 @@
+#!/usr/bin/python
+
+from PySFML import *
+
+from OpenGL.GL import *
+from OpenGL.GLUT import *
+from OpenGL.GLU import *
+
+
+def main():
+
+ # Create main window
+ App = sf.RenderWindow(sf.VideoMode(800, 600), "SFML OpenGL")
+ App.PreserveOpenGLStates(True)
+
+ # Create a sprite for the background
+ BackgroundImage = sf.Image()
+ if not BackgroundImage.LoadFromFile("../../samples/bin/datas/opengl/background.jpg"):
+ return
+ Background = sf.Sprite(BackgroundImage)
+
+ # Load an OpenGL texture.
+ # We could directly use a sf.Image as an OpenGL texture (with its Bind() member function),
+ # but here we want more control on it (generate mipmaps, ...) so we create a new one
+
+ Image = sf.Image()
+ if not Image.LoadFromFile("../../samples/bin/datas/opengl/texture.jpg"):
+ return
+ # The next line is a bit different from the C++ version
+ Texture = glGenTextures(1) # instead of glGenTextures(1, &Texture);
+ glBindTexture(GL_TEXTURE_2D, Texture)
+ # 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
+ # 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())
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_LINEAR)
+ glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_LINEAR_MIPMAP_LINEAR)
+
+
+ # Enable Z-buffer read and write
+ glEnable(GL_DEPTH_TEST)
+ glDepthMask(GL_TRUE)
+ glClearDepth(1.)
+
+ # Setup a perspective projection
+ glMatrixMode(GL_PROJECTION)
+ glLoadIdentity()
+ gluPerspective(90., 1., 1., 500.)
+
+ # Bind our texture
+ glEnable(GL_TEXTURE_2D)
+ glBindTexture(GL_TEXTURE_2D, Texture)
+ glColor4f(1., 1., 1., 1.)
+
+ # Create a clock for measuring the time elapsed
+ Clock = sf.Clock()
+
+ # Start game loop
+ while App.IsOpened():
+ # Process events
+ Event = sf.Event()
+ while App.GetEvent(Event):
+ # Close window : exit
+ if Event.Type == sf.Event.Closed:
+ App.Close()
+
+ # Escape key : exit
+ if (Event.Type == sf.Event.KeyPressed) and (Event.Key.Code == sf.Key.Escape):
+ App.Close()
+
+ # Adjust the viewport when the window is resized
+ if Event.Type == sf.Event.Resized:
+ glViewport(0, 0, Event.Size.Width, Event.Size.Height);
+
+ # Draw background
+ App.Draw(Background)
+
+ # Clear depth buffer
+ glClear(GL_DEPTH_BUFFER_BIT)
+
+ # Apply some transf.ormations
+ glMatrixMode(GL_MODELVIEW)
+ glLoadIdentity()
+ glTranslatef(0, 0, -200)
+ glRotatef(Clock.GetElapsedTime() * 50, 1, 0, 0)
+ glRotatef(Clock.GetElapsedTime() * 30, 0, 1, 0)
+ glRotatef(Clock.GetElapsedTime() * 90, 0, 0, 1)
+
+ # Draw a cube
+ glBegin(GL_QUADS)
+
+ glTexCoord2f(0, 0)
+ glVertex3f(-50., -50., -50.)
+ glTexCoord2f(0, 1)
+ glVertex3f(-50., 50., -50.)
+ glTexCoord2f(1, 1)
+ glVertex3f( 50., 50., -50.)
+ glTexCoord2f(1, 0)
+ glVertex3f( 50., -50., -50.)
+
+ glTexCoord2f(0, 0)
+ glVertex3f(-50., -50., 50.)
+ glTexCoord2f(0, 1)
+ glVertex3f(-50., 50., 50.)
+ glTexCoord2f(1, 1)
+ glVertex3f( 50., 50., 50.)
+ glTexCoord2f(1, 0)
+ glVertex3f( 50., -50., 50.)
+
+ glTexCoord2f(0, 0)
+ glVertex3f(-50., -50., -50.)
+ glTexCoord2f(0, 1)
+ glVertex3f(-50., 50., -50.)
+ glTexCoord2f(1, 1)
+ glVertex3f(-50., 50., 50.)
+ glTexCoord2f(1, 0)
+ glVertex3f(-50., -50., 50.)
+
+ glTexCoord2f(0, 0)
+ glVertex3f(50., -50., -50.)
+ glTexCoord2f(0, 1)
+ glVertex3f(50., 50., -50.)
+ glTexCoord2f(1, 1)
+ glVertex3f(50., 50., 50.)
+ glTexCoord2f(1, 0)
+ glVertex3f(50., -50., 50.)
+
+ glTexCoord2f(0, 1)
+ glVertex3f(-50., -50., 50.)
+ glTexCoord2f(0, 0)
+ glVertex3f(-50., -50., -50.)
+ glTexCoord2f(1, 0)
+ glVertex3f( 50., -50., -50.)
+ glTexCoord2f(1, 1)
+ glVertex3f( 50., -50., 50.)
+
+ glTexCoord2f(0, 1)
+ glVertex3f(-50., 50., 50.)
+ glTexCoord2f(0, 0)
+ glVertex3f(-50., 50., -50.)
+ glTexCoord2f(1, 0)
+ glVertex3f( 50., 50., -50.)
+ glTexCoord2f(1, 1)
+ glVertex3f( 50., 50., 50.)
+
+ glEnd()
+
+ # Draw some text on top of our OpenGL object
+ Text = sf.String("This is a rotating cube")
+ Text.SetPosition(230., 300.)
+ Text.SetColor(sf.Color(128, 0, 128))
+ App.Draw(Text)
+
+ # Finally, display the rendered frame on screen
+ App.Display()
+
+ # Don't forget to destroy our texture
+ # In C++, the call to this function was a bit different
+ glDeleteTextures(Texture) # instead of glDeleteTextures(1, &Texture);
+
+ return
+main()
+
diff --git a/python/samples/sound.py b/python/samples/sound.py
new file mode 100644
index 0000000..6487406
--- /dev/null
+++ b/python/samples/sound.py
@@ -0,0 +1,43 @@
+#!/usr/bin/python
+
+# You can notice that here we use PySFML.sf instead of just PySFML
+# Therefore it won't be needed to put sf. in front of SFML classes
+
+from PySFML.sf import *
+
+
+def Main():
+ Buffer = SoundBuffer()
+ if not Buffer.LoadFromFile("data/fart.wav"): # Loads the sound
+ return
+ Fart = Sound(Buffer, False)
+
+ WindowWidth, WindowHeight = 640, 480
+ App = RenderWindow(VideoMode(WindowWidth,WindowHeight,32), "Sound with PySFML", Style.Close, WindowSettings(24,8,0))
+ App.SetFramerateLimit(30)
+
+ EventHandler = Event()
+ InputHandler = App.GetInput()
+
+ Text = String("Turn the sound on.\nClick anywhere on the screen.\nMove the mouse. Click again.\nTry clicking in the corners.")
+ Text.SetX(30.)
+ Text.SetY(20.)
+ Text.SetColor(Color(150, 100, 10, 255))
+
+ while App.IsOpened(): # Main loop
+ while App.GetEvent(EventHandler): # Event Handler
+ if EventHandler.Type == Event.Closed:
+ App.Close()
+ if EventHandler.Type == Event.KeyPressed and EventHandler.Key.Code == Key.Escape:
+ App.Close()
+ if EventHandler.Type == Event.MouseButtonPressed and EventHandler.MouseButton.Button == Mouse.Left:
+ Fart.SetPitch(1.5 - 1.*InputHandler.GetMouseY()/WindowHeight)
+ Fart.SetPosition( 1.*(InputHandler.GetMouseX() - WindowWidth/2)/(WindowWidth/20), 2., -2.)
+ Fart.Play()
+ App.Draw(Text)
+ App.Display()
+ App.Clear(Color.Black)
+
+
+Main()
+
diff --git a/python/samples/sound_capture.py b/python/samples/sound_capture.py
new file mode 100644
index 0000000..bfb24d0
--- /dev/null
+++ b/python/samples/sound_capture.py
@@ -0,0 +1,68 @@
+#!/usr/bin/env python
+
+from PySFML import *
+
+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 = 0
+ SampleRate = int(raw_input("Please choose the sample rate for sound capture (44100 is CD quality) : "))
+
+ # Wait for user input...
+ print "Press enter to start recording audio"
+ raw_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"
+ raw_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(raw_input("What do you want to do with captured sound (p = play, s = save) ? "))
+
+ if Choice == 's':
+ # Choose the filename
+ Filename = str(raw_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..."
+ raw_input()
+
+ return
+
+Main()
diff --git a/python/samples/sound_stream.py b/python/samples/sound_stream.py
new file mode 100755
index 0000000..e3d588b
--- /dev/null
+++ b/python/samples/sound_stream.py
@@ -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..."
+ raw_input()
+
+Main()
+
diff --git a/python/samples/worm.py b/python/samples/worm.py
new file mode 100644
index 0000000..25a1c6c
--- /dev/null
+++ b/python/samples/worm.py
@@ -0,0 +1,240 @@
+#!/usr/bin/python
+
+from PySFML import *
+import math
+import random
+import sys
+
+
+def Game(Difficulty):
+
+ PartsPerFrame = 1 + Difficulty # Number of drawn base parts each frame
+ PartsSpacing = 3 # Each worm's base part is separated by PartsSpacing pixels
+ TurnStep = 0.15 # Turn the worm's head of 0.15 rad
+
+ PartSize = 6.0 # worm's base part size for collision
+ PartRealSize = 18.0 # worm's real base part size for drawing
+
+ # Load images
+ 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
+ for i in range(0, PartsPerFrame): # We create PartsPerFrame Worm's parts
+ Angle += Dir*TurnStep
+ HeadX, HeadY = Worm[Length-1][0]+PartsSpacing*math.cos(Angle), Worm[Length-1][1]+PartsSpacing*math.sin(Angle)
+ if TargetedLength <= RequiredLength:
+ if math.sqrt ( (AppleX - HeadX)**2 + (AppleY - HeadY)**2 ) < 14 + PartSize/2: # The Worm ate the apple
+ Score += 1
+ TargetedLength += 20 # The worm gets longer
+ if TargetedLength <= RequiredLength:
+ 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)
+ App.Draw(Apple)
+
+ if HeadX<ArenaLeft+PartSize/2 or HeadX>ArenaRight-PartSize/2 or HeadY<ArenaTop+PartSize/2 or HeadY>ArenaBottom-PartSize/2: # Crash into a wall
+ if Length > RequiredLength:
+ 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
+
+
+ if TargetedLength > RequiredLength:
+ App.Draw(Exit)
+
+ if Length >= TargetedLength:
+ Worm[0:TargetedLength] = Worm[Length-TargetedLength:Length]
+ for i in range(Length, TargetedLength):
+ del Worm[i]
+ Worm[TargetedLength:Length] = []
+ Length = TargetedLength
+
+ for i in range(0, Length):
+ WormPart.SetPosition(Worm[i][0], Worm[i][1])
+ App.Draw(WormPart) # Draw the part on screen
+ if i < Length - PartSize/PartsSpacing - 1:
+ if math.sqrt( (HeadX-Worm[i][0])**2 + (HeadY-Worm[i][1])**2 ) < PartSize and Running: # Check for collision
+ Crash = True
+
+ if Crash and Length>0:
+ TargetedLength -= PartsPerFrame
+
+
+ ScoreStr.SetText("Score: " + str(Score))
+
+ App.Draw(ScoreStr)
+ App.Draw(LevelStr)
+ App.Display() # Refresh Screen
+ App.Clear(BGColor)
+
+
+ # End of the game
+ if Crash:
+ Level = 0
+ Score = 0
+ else:
+ Score += 5 # End level bonus
+
+ del Worm
+ del Arena
+ del ArenaImg
+
+def Menu():
+
+ Selection = 0
+
+ TextColor = sf.Color(220, 220, 20, 255)
+
+ Running = True
+ Event = sf.Event()
+
+ Title = sf.String("PyWorm!")
+ Title.SetX(320.)
+ Title.SetY(50.)
+ Title.SetColor(TextColor)
+
+ Levels = ["Very Easy", "Easy", "Medium", "Hard"]
+ Xs = [320., 350., 330., 350.]
+ Strings = [0,0,0,0]
+ for i in range(0, 4):
+ Strings[i] = sf.String(Levels[i])
+ Strings[i].SetColor(TextColor)
+ Strings[i].SetPosition(Xs[i], 200. + 80*i)
+
+ RectangleImg = sf.Image(ScreenWidth, 40, sf.Color(50,50,10,255))
+ Rectangle = sf.Sprite(RectangleImg, 0, 350, 1, 1, 0)
+
+ while App.IsOpened(): # Game main loop
+ while App.GetEvent(Event): # Event Handler
+ if Event.Type == sf.Event.Closed:
+ App.Close()
+ if Event.Type == sf.Event.KeyPressed:
+ if Event.Key.Code == sf.Key.Escape:
+ App.Close()
+ elif Event.Key.Code == sf.Key.Up:
+ Selection = (Selection - 1) % 4
+ 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
+ScreenWidth, ScreenHeight = 800, 600
+App = sf.RenderWindow(sf.VideoMode(ScreenWidth,ScreenHeight,32), "PyWorm", sf.Style.Close) # Creates the window
+BGColor = sf.Color(100,100,0,255)
+App.SetFramerateLimit(30)
+Menu()
+
diff --git a/python/scripts/footer.htm b/python/scripts/footer.htm
new file mode 100644
index 0000000..77030f7
--- /dev/null
+++ b/python/scripts/footer.htm
@@ -0,0 +1,7 @@
+
+ <p id="footer">
+ :: Copyright © 2007-2008 Rémi Koenig ::
+ </p>
+
+ </body>
+</html>
diff --git a/python/scripts/gen_doc.py b/python/scripts/gen_doc.py
new file mode 100755
index 0000000..99e4721
--- /dev/null
+++ b/python/scripts/gen_doc.py
@@ -0,0 +1,118 @@
+#!/usr/bin/python
+# coding=UTF-8
+
+from PySFML import sf
+
+# Amélioration à faire : trouver les méthodes héritées, et de quelle classe
+
+def function_str(function, class_name=None):
+ string = ''
+ name = function.__name__
+ doc = function.__doc__
+ if not doc.startswith(name+'('):
+ string += name+"(...)"+'\n'
+ string += doc+'\n'
+ strings = string.split('\n')
+ strings[0] = '<div class="attr_name">'+strings[0]+'</div>\n<div class="desc">'
+ string = strings[0]
+ for s in strings[1:-1]:
+ string += s + '<br />'
+ string += strings[-1]
+ inherited = ''
+ if class_name != None:
+ try:
+ base_class_name = function.__objclass__.__name__
+ if base_class_name != class_name:
+ inherited = '<div class="inherited">Inherited</div>\n'
+ except AttributeError:
+ pass
+ return string.replace('\t', ' ')+'</div>\n'+inherited
+
+class FilesManager:
+ def __init__(self):
+ self.files = {}
+ f = open("header.htm")
+ self.header = f.read()
+ f.close()
+ f = open("footer.htm")
+ self.footer = f.read()
+ f.close()
+
+ def add(self, filename, string):
+ if not self.files.has_key(filename):
+ self.files[filename] = open('../doc/' + filename + '.html', 'w')
+ self.files[filename].write(self.header.replace('TITLE', filename))
+ self.files[filename].write(string)
+
+ def __del__(self):
+ for filename in self.files:
+ self.files[filename].write(self.footer)
+ self.files[filename].close()
+
+
+def Main():
+
+ fm = FilesManager()
+
+ fm.add('index', '<h1>PySFML index</h1>\n')
+
+ fm.add('index', '<h2>Classes</h2>\n')
+
+ module_methods = ""
+ module_constants = ""
+
+ for m in dir(sf):
+ if not m.startswith('__'):
+ if m == 'Event':
+ attr = sf.Event()
+ else:
+ attr = getattr(sf, m)
+ if type(attr) == str:
+ module_constants += '<div class="attr_name">'+m+'</div>\n<div class="desc">"'+attr+'"</div>\n'
+ elif str(type(attr)) == "<type 'builtin_function_or_method'>" or str(type(attr)) == "<type 'method_descriptor'>":
+ module_methods += function_str(attr)
+ else:
+ fm.add('index', '<a href="'+m+'.html">'+m+'</a><br />\n')
+ info = {'Attributes':'', 'Constants':'', 'Methods':'', 'Static methods':''}
+ members = ""
+ constants = ""
+ static_methods = ""
+ methods = ""
+ for n in dir(attr):
+ if not n.startswith('__'):
+ attr2 = getattr(attr, n)
+ if str(type(attr2)) == "<type 'member_descriptor'>": # member
+ info['Attributes'] += '<div class="attr_name">'+n+'</div>\n<div class="desc">'+attr2.__doc__+'</div>\n'
+ elif type(attr2) == long:
+ info['Attributes'] += '<div class="attr_name">'+n+'</div>\n'
+ elif type(attr2) == int or type(attr2) == sf.Color: # int or color (constant)
+ info['Constants'] += '<div class="attr_name">'+n+'</div>\n'
+ elif str(type(attr2)) == "<type 'builtin_function_or_method'>": # static method
+ info['Static methods'] += function_str(attr2, m)
+ elif str(type(attr2)) == "<type 'method_descriptor'>": # method
+ info['Methods'] += function_str(attr2, m)
+ elif str(type(attr2)).startswith("<type 'Event."):
+ info['Attributes'] += '<div class="attr_name">'+n+'</div>\n<div class="desc">' + attr2.__doc__+'</div>\n'
+ for o in dir(attr2):
+ if not o.startswith('__'):
+ attr3 = getattr(attr2, o)
+ info['Attributes'] += '<div class="event_member"> > ' + o + '</div>\n'
+ else:
+ print "Warning : unknown type for " + n + " " + str(type(attr2))
+ fm.add(m, '<h1>sf.'+m+' Class Reference</h1>\n')
+ fm.add(m, '<div class="class_desc">'+attr.__doc__.replace('\n', '<br />\n').replace('\t', ' ')+'</div>\n')
+ if m != 'Event':
+ base = attr.__base__.__name__
+ if base != 'object':
+ fm.add(m, '<div class="base_class">Base class: <a href="'+base+'.html">sf.'+base+'</a>.</div>\n')
+ for t in info:
+ if info[t] != '':
+ fm.add(m, '<h2>'+t+'</h2>\n'+info[t]+'<br />\n')
+ fm.add(m, '<br />\n<br />\n')
+
+ fm.add('index', '<h2>Module methods</h2>\n' + module_methods)
+
+ fm.add('index', '<h2>Module constants</h2>\n' + module_constants)
+
+Main()
+
diff --git a/python/scripts/header.htm b/python/scripts/header.htm
new file mode 100644
index 0000000..f335b42
--- /dev/null
+++ b/python/scripts/header.htm
@@ -0,0 +1,11 @@
+<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
+<html>
+ <head>
+ <title>PySFML - Python binding for SFML (Simple and Fast Multimedia Library) - TITLE</title>
+ <meta http-equiv="Content-Type" content="text/html;charset=UTF-8" />
+ <link href="style.css" rel="stylesheet" type="text/css" />
+ </head>
+ <body>
+ <div id="logo">
+ <img src="http://www.sfml-dev.org/images/logo.jpg" width="770" height="200" title="SFML home" alt="SFML logo" />
+ </div>
diff --git a/python/setup.py b/python/setup.py
index 4956023..125ed27 100644
--- a/python/setup.py
+++ b/python/setup.py
@@ -4,7 +4,7 @@
from distutils.core import setup, Extension
setup(name='PySFML',
- version='1.3',
+ version='1.4',
description='Python binding for SFML (Simple and Fast Multimedia Library)',
author='Rémi Koenig',
author_email='remi.k2620 at gmail.com',
@@ -16,8 +16,8 @@ setup(name='PySFML',
'src/Music.cpp', 'src/PostFX.cpp', 'src/Rect.cpp', 'src/RenderWindow.cpp', 'src/Sleep.cpp', \
'src/Sprite.cpp', 'src/String.cpp', 'src/VideoMode.cpp', 'src/View.cpp', 'src/Window.cpp', \
'src/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/Font.cpp', 'src/Shape.cpp', 'src/WindowSettings.cpp' ], \
+ 'src/SoundBuffer.cpp', 'src/Listener.cpp', 'src/SoundRecorder.cpp', 'src/SoundBufferRecorder.cpp', \
+ 'src/SoundStream.cpp', 'src/Font.cpp', 'src/Glyph.cpp', 'src/Shape.cpp', 'src/WindowSettings.cpp' ], \
libraries=['sfml-graphics', 'sfml-window', 'sfml-audio', 'sfml-system'], \
library_dirs=['../lib/mingw'], \
include_dirs=['../include']
diff --git a/python/src/Blend.cpp b/python/src/Blend.cpp
index a4029f3..7398e46 100644
--- a/python/src/Blend.cpp
+++ b/python/src/Blend.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include <SFML/Graphics/Drawable.hpp>
#include <Python.h>
@@ -49,44 +73,48 @@ static PyMethodDef PySfBlend_methods[] = {
PyTypeObject PySfBlendType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Blend", /*tp_name*/
- sizeof(PySfBlend), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Blend", /*tp_name*/
+ sizeof(PySfBlend), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfBlend_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfBlend doc", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfBlend_methods, /* tp_methods */
- PySfBlend_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfBlend_init, /* tp_init */
- 0, /* tp_alloc */
- PySfBlend_new, /* tp_new */
+ "Enumerate the blending modes for drawable objects.\n\
+Alpha Pixel = Src * a + Dest * (1 - a).\n\
+Add Pixel = Src + Dest.\n\
+Multiply Pixel = Src * Dest.\n\
+None No blending.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfBlend_methods, /* tp_methods */
+ PySfBlend_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfBlend_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfBlend_new, /* tp_new */
};
void PySfBlend_InitConst()
diff --git a/python/src/Blend.hpp b/python/src/Blend.hpp
index 174682e..e47ed9c 100644
--- a/python/src/Blend.hpp
+++ b/python/src/Blend.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYBLEND_HPP
#define __PYBLEND_HPP
diff --git a/python/src/Clock.cpp b/python/src/Clock.cpp
index 99a2b76..7c28c31 100644
--- a/python/src/Clock.cpp
+++ b/python/src/Clock.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Clock.hpp"
@@ -56,51 +80,51 @@ PySfClock_Reset(PySfClock *self)
}
static PyMethodDef PySfClock_methods[] = {
- {"GetElapsedTime", (PyCFunction)PySfClock_GetElapsedTime, METH_NOARGS, "Get the time elapsed since last reset."},
- {"Reset", (PyCFunction)PySfClock_Reset, METH_NOARGS, "Restart the timer."},
+ {"GetElapsedTime", (PyCFunction)PySfClock_GetElapsedTime, METH_NOARGS, "GetElapsedTime()\nGet the time elapsed since last reset."},
+ {"Reset", (PyCFunction)PySfClock_Reset, METH_NOARGS, "Reset()\nRestart the timer."},
{NULL} /* Sentinel */
};
PyTypeObject PySfClockType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Clock", /*tp_name*/
- sizeof(PySfClock), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Clock", /*tp_name*/
+ sizeof(PySfClock), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfClock_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfClock is an utility class for manipulating time.", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfClock_methods, /* tp_methods */
- PySfClock_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfClock_init, /* tp_init */
- 0, /* tp_alloc */
- PySfClock_new, /* tp_new */
+ "sf.Clock is an utility class for manipulating time.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfClock_methods, /* tp_methods */
+ PySfClock_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfClock_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfClock_new, /* tp_new */
};
diff --git a/python/src/Clock.hpp b/python/src/Clock.hpp
index f35ac8a..4b2c9d8 100644
--- a/python/src/Clock.hpp
+++ b/python/src/Clock.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYCLOCK_HPP
#define __PYCLOCK_HPP
diff --git a/python/src/Color.cpp b/python/src/Color.cpp
index be47056..30e428e 100644
--- a/python/src/Color.cpp
+++ b/python/src/Color.cpp
@@ -1,10 +1,34 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Color.hpp"
static PyMemberDef PySfColor_members[] = {
- {(char *)"r", T_UBYTE, offsetof(PySfColor, r), 0, (char *)""},
- {(char *)"g", T_UBYTE, offsetof(PySfColor, g), 0, (char *)""},
- {(char *)"b", T_UBYTE, offsetof(PySfColor, b), 0, (char *)""},
- {(char *)"a", T_UBYTE, offsetof(PySfColor, a), 0, (char *)""},
+ {(char *)"r", T_UBYTE, offsetof(PySfColor, r), 0, (char *)"Red component."},
+ {(char *)"g", T_UBYTE, offsetof(PySfColor, g), 0, (char *)"Green component."},
+ {(char *)"b", T_UBYTE, offsetof(PySfColor, b), 0, (char *)"Blue component."},
+ {(char *)"a", T_UBYTE, offsetof(PySfColor, a), 0, (char *)"Alpha (transparency) component."},
{NULL} /* Sentinel */
};
@@ -13,6 +37,7 @@ static PyMemberDef PySfColor_members[] = {
static void
PySfColor_dealloc(PySfColor *self)
{
+ delete self->obj;
self->ob_type->tp_free((PyObject*)self);
}
@@ -97,7 +122,7 @@ PyTypeObject PySfColorType = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfColor is an utility class for manipulating colors", /* tp_doc */
+ "sf.Color is an utility class for manipulating 32-bits RGBA colors.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
diff --git a/python/src/Color.hpp b/python/src/Color.hpp
index f48536c..19379e3 100644
--- a/python/src/Color.hpp
+++ b/python/src/Color.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYCOLOR_HPP
#define __PYCOLOR_HPP
diff --git a/python/src/Drawable.cpp b/python/src/Drawable.cpp
index 545e00c..347e7f7 100644
--- a/python/src/Drawable.cpp
+++ b/python/src/Drawable.cpp
@@ -1,9 +1,33 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Drawable.hpp"
-void CustomDrawable::Render (const sf::RenderWindow& Window) const
+void CustomDrawable::Render (sf::RenderTarget& Target) const
{
if (RenderFunction)
- PyObject_CallFunction(RenderFunction, "O", RenderWindow);
+ PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow);
}
@@ -108,6 +132,7 @@ PySfDrawable_SetColor(PySfDrawable* self, PyObject *args)
PyErr_SetString(PyExc_TypeError, "Argument is not a sfColor");
return NULL;
}
+ PySfColorUpdate(Color);
self->obj->SetColor(*(Color->obj));
Py_RETURN_NONE;
}
@@ -185,25 +210,53 @@ PySfDrawable_SetPosition(PySfDrawable* self, PyObject *args)
Py_RETURN_NONE;
}
+static PyObject *
+PySfDrawable_TransformToLocal(PySfDrawable* self, PyObject *args)
+{
+ float X, Y;
+ if ( !PyArg_ParseTuple(args, "ff", &X, &Y) )
+ return NULL;
+ sf::Vector2f result = self->obj->TransformToLocal(sf::Vector2f(X, Y));
+ return Py_BuildValue("ff", result.x, result.y);
+}
+
+static PyObject *
+PySfDrawable_TransformToGlobal(PySfDrawable* self, PyObject *args)
+{
+ float X, Y;
+ if ( !PyArg_ParseTuple(args, "ff", &X, &Y) )
+ return NULL;
+ sf::Vector2f result = self->obj->TransformToGlobal(sf::Vector2f(X, Y));
+ return Py_BuildValue("ff", result.x, result.y);
+}
+
static PyMethodDef PySfDrawable_methods[] = {
- {"SetX", (PyCFunction)PySfDrawable_SetX, METH_O, "Set the X position of the object."},
- {"SetY", (PyCFunction)PySfDrawable_SetY, METH_O, "Set the Y position of the object."},
- {"SetScale", (PyCFunction)PySfDrawable_SetScale, METH_VARARGS, "Set the uniform scale of the object."},
- {"SetScaleX", (PyCFunction)PySfDrawable_SetScaleX, METH_O, "Set the scale of the object."},
- {"SetScaleY", (PyCFunction)PySfDrawable_SetScaleY, METH_O, "Set the scale of the object."},
- {"SetRotation", (PyCFunction)PySfDrawable_SetRotation, METH_O, "Set the orientation of the object."},
- {"SetCenter", (PyCFunction)PySfDrawable_SetCenter, METH_VARARGS, "Set the center of the object, in coordinates relative to the object."},
- {"GetCenter", (PyCFunction)PySfDrawable_GetCenter, METH_NOARGS, "Get the center of the object, in coordinates relative to the object."},
- {"SetColor", (PyCFunction)PySfDrawable_SetColor, METH_O, "Set the color of the object."},
- {"GetPosition", (PyCFunction)PySfDrawable_GetPosition, METH_NOARGS, "Get the position of the object."},
- {"GetScale", (PyCFunction)PySfDrawable_GetScale, METH_NOARGS, "Get the scale of the object."},
- {"GetRotation", (PyCFunction)PySfDrawable_GetRotation, METH_NOARGS, "Get the orientation of the object."},
- {"GetColor", (PyCFunction)PySfDrawable_GetColor, METH_NOARGS, "Get the color of the object."},
- {"Move", (PyCFunction)PySfDrawable_Move, METH_VARARGS, "Move the object."},
- {"Scale", (PyCFunction)PySfDrawable_Scale, METH_VARARGS, "Scale the object."},
- {"Rotate", (PyCFunction)PySfDrawable_Rotate, METH_O, "Rotate the object."},
- {"SetBlendMode", (PyCFunction)PySfDrawable_SetBlendMode, METH_O, "Set the blending mode for the object."},
- {"SetPosition", (PyCFunction)PySfDrawable_SetPosition, METH_VARARGS, "Set the position of the object."},
+ {"TransformToLocal", (PyCFunction)PySfDrawable_TransformToLocal, METH_VARARGS, "TransformToLocal(X, Y)\n\
+Transform a point from global coordinates into local coordinates (ie it applies the inverse of object's center, translation, rotation and scale to the point). Returns a tuple.\n\
+ X : X coordinate of the point to transform\n\
+ Y : Y coordinate of the point to transform"},
+ {"TransformToGlobal", (PyCFunction)PySfDrawable_TransformToGlobal, METH_VARARGS, "TransformToGlobal(X, Y)\n\
+Transform a point from local coordinates into global coordinates (ie it applies the object's center, translation, rotation and scale to the point). Returns a tuple.\n\
+ X : X coordinate of the point to transform\n\
+ Y : Y coordinate of the point to transform"},
+ {"SetX", (PyCFunction)PySfDrawable_SetX, METH_O, "SetX(X)\nSet the X position of the object.\n X : New X coordinate"},
+ {"SetY", (PyCFunction)PySfDrawable_SetY, METH_O, "SetY(Y)\nSet the Y position of the object.\n Y : New Y coordinate"},
+ {"SetScale", (PyCFunction)PySfDrawable_SetScale, METH_VARARGS, "SetScale(ScaleX, ScaleY)\nSet the scale of the object.\n ScaleX : New horizontal scale (must be strictly positive)\n ScaleY : New vertical scale (must be strictly positive)"},
+ {"SetScaleX", (PyCFunction)PySfDrawable_SetScaleX, METH_O, "SetScaleX(ScaleX)\nSet the X scale factor of the object.\n ScaleX : New horizontal scale (must be strictly positive)"},
+ {"SetScaleY", (PyCFunction)PySfDrawable_SetScaleY, METH_O, "SetScaleY(ScaleY)\nSet the Y scale factor of the object.\n ScaleY : New vertical scale (must be strictly positive)"},
+ {"SetRotation", (PyCFunction)PySfDrawable_SetRotation, METH_O, "SetRotation(Rotation)\nSet the orientation of the object.\n Rotation : Angle of rotation, in degrees"},
+ {"SetCenter", (PyCFunction)PySfDrawable_SetCenter, METH_VARARGS, "SetCenter(CenterX, CenterY)\nSet the center of the object, in coordinates relative to the object.\n CenterX : X coordinate of the center\n CenterY : Y coordinate of the center"},
+ {"GetCenter", (PyCFunction)PySfDrawable_GetCenter, METH_NOARGS, "GetCenter()\nGet the center of the object, in coordinates relative to the object."},
+ {"SetColor", (PyCFunction)PySfDrawable_SetColor, METH_O, "SetColor(Color)\nSet the color of the object.\n Color : New color"},
+ {"GetPosition", (PyCFunction)PySfDrawable_GetPosition, METH_NOARGS, "GetPosition()\nGet the position of the object."},
+ {"GetScale", (PyCFunction)PySfDrawable_GetScale, METH_NOARGS, "GetScale()\nGet the scale of the object."},
+ {"GetRotation", (PyCFunction)PySfDrawable_GetRotation, METH_NOARGS, "GetRotation()\nGet the orientation of the object."},
+ {"GetColor", (PyCFunction)PySfDrawable_GetColor, METH_NOARGS, "GetColor()\nGet the color of the object."},
+ {"Move", (PyCFunction)PySfDrawable_Move, METH_VARARGS, "Move(OffsetX, OffsetY)\nMove the object.\n OffsetX : X offset\n OffsetY : Y offset "},
+ {"Scale", (PyCFunction)PySfDrawable_Scale, METH_VARARGS, "Scale(FactorX, FactorY)\nScale the object.\n FactorX : Scaling factor on X (must be strictly positive)\n FactorY : Scaling factor on Y (must be strictly positive)"},
+ {"Rotate", (PyCFunction)PySfDrawable_Rotate, METH_O, "Rotate(Angle)\nRotate the object.\n Angle : Angle of rotation, in degrees"},
+ {"SetBlendMode", (PyCFunction)PySfDrawable_SetBlendMode, METH_O, "SetBlendMode(Mode)\nSet the blending mode for the object. The default blend mode is sf.Blend.Alpha\n Mode : New blending mode"},
+ {"SetPosition", (PyCFunction)PySfDrawable_SetPosition, METH_VARARGS, "SetPosition(X, Y)\nSet the position of the object.\n X : New X coordinate\n Y : New Y coordinate"},
{NULL} /* Sentinel */
};
@@ -229,7 +282,7 @@ PyTypeObject PySfDrawableType = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfDrawable defines a sprite : texture, transformations, color, and draw on screen", /* tp_doc */
+ "Abstract base class for every object that can be drawn into a render window.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
diff --git a/python/src/Drawable.hpp b/python/src/Drawable.hpp
index 369d41a..8676d9d 100644
--- a/python/src/Drawable.hpp
+++ b/python/src/Drawable.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYDRAWABLE_H
#define __PYDRAWABLE_H
@@ -14,7 +38,7 @@
class CustomDrawable : public sf::Drawable
{
protected :
- virtual void Render(const sf::RenderWindow& Window) const;
+ virtual void Render(sf::RenderTarget& Target) const;
public :
PySfRenderWindow *RenderWindow;
PyObject *RenderFunction;
diff --git a/python/src/Event.cpp b/python/src/Event.cpp
index c38dc52..9549169 100644
--- a/python/src/Event.cpp
+++ b/python/src/Event.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Event.hpp"
@@ -6,10 +30,24 @@
////////////////////////////////
PyMemberDef PySfEventText_members[] = {
- {"Unicode", T_USHORT, offsetof(PySfEventText, Unicode), 0, ""},
+ {(char *)"Unicode", T_USHORT, offsetof(PySfEventText, Unicode), RO, (char *)""},
{NULL} /* Sentinel */
};
+static PyObject *
+PySfEventText_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventText *self;
+
+ self = (PySfEventText *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ self->Unicode = 0;
+ }
+
+ return (PyObject *)self;
+}
+
int
PySfEventText_init(PySfEventText *self, PyObject *args, PyObject *kwds)
{
@@ -61,6 +99,7 @@ PyTypeObject PySfEventTextType = {
0, /* tp_dictoffset */
(initproc)PySfEventText_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventText_new, /* tp_new */
};
@@ -69,6 +108,25 @@ PyTypeObject PySfEventTextType = {
// Keyboard Events Parameters
/////////////////////////////////////
+static PyObject *
+PySfEventKey_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventKey *self;
+
+ self = (PySfEventKey *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ Py_INCREF(Py_False);
+ self->Alt = Py_False;
+ Py_INCREF(Py_False);
+ self->Control = Py_False;
+ Py_INCREF(Py_False);
+ self->Shift = Py_False;
+ }
+
+ return (PyObject *)self;
+}
+
int
PySfEventKey_init(PySfEventKey *self, PyObject *args, PyObject *kwds)
{
@@ -82,10 +140,10 @@ PySfEventKey_dealloc(PySfEventKey* self)
}
PyMemberDef PySfEventKey_members[] = {
- {"Alt", T_OBJECT, offsetof(PySfEventKey, Alt), 0, ""},
- {"Control", T_OBJECT, offsetof(PySfEventKey, Control), 0, ""},
- {"Shift", T_OBJECT, offsetof(PySfEventKey, Shift), 0, ""},
- {"Code", T_UINT, offsetof(PySfEventKey, Code), 0, ""},
+ {(char *)"Alt", T_OBJECT, offsetof(PySfEventKey, Alt), RO, (char *)""},
+ {(char *)"Control", T_OBJECT, offsetof(PySfEventKey, Control), RO, (char *)""},
+ {(char *)"Shift", T_OBJECT, offsetof(PySfEventKey, Shift), RO, (char *)""},
+ {(char *)"Code", T_UINT, offsetof(PySfEventKey, Code), RO, (char *)""},
{NULL} /* Sentinel */
};
@@ -128,6 +186,7 @@ PyTypeObject PySfEventKeyType = {
0, /* tp_dictoffset */
(initproc)PySfEventKey_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventKey_new, /* tp_new */
};
@@ -135,6 +194,21 @@ PyTypeObject PySfEventKeyType = {
// MouseMove Events Parameters
////////////////////////////////////
+static PyObject *
+PySfEventMouseMove_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventMouseMove *self;
+
+ self = (PySfEventMouseMove *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ self->X = 0;
+ self->Y = 0;
+ }
+
+ return (PyObject *)self;
+}
+
int
PySfEventMouseMove_init(PySfEventMouseMove *self, PyObject *args, PyObject *kwds)
{
@@ -149,8 +223,8 @@ PySfEventMouseMove_dealloc(PySfEventMouseMove *self)
PyMemberDef PySfEventMouseMove_members[] = {
- {"X", T_UINT, offsetof(PySfEventMouseMove, X), 0, ""},
- {"Y", T_UINT, offsetof(PySfEventMouseMove, Y), 0, ""},
+ {(char *)"X", T_INT, offsetof(PySfEventMouseMove, X), RO, (char *)""},
+ {(char *)"Y", T_INT, offsetof(PySfEventMouseMove, Y), RO, (char *)""},
{NULL} /* Sentinel */
};
@@ -193,6 +267,7 @@ PyTypeObject PySfEventMouseMoveType = {
0, /* tp_dictoffset */
(initproc)PySfEventMouseMove_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventMouseMove_new, /* tp_new */
};
@@ -200,6 +275,22 @@ PyTypeObject PySfEventMouseMoveType = {
// MouseButton Events Parameters
////////////////////////////////////
+static PyObject *
+PySfEventMouseButton_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventMouseButton *self;
+
+ self = (PySfEventMouseButton *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ self->Button = 0;
+ self->X = 0;
+ self->Y = 0;
+ }
+
+ return (PyObject *)self;
+}
+
int
PySfEventMouseButton_init(PySfEventMouseButton *self, PyObject *args, PyObject *kwds)
{
@@ -214,7 +305,9 @@ PySfEventMouseButton_dealloc(PySfEventMouseButton* self)
PyMemberDef PySfEventMouseButton_members[] = {
- {"Button", T_UINT, offsetof(PySfEventMouseButton, Button), 0, ""},
+ {(char *)"Button", T_UINT, offsetof(PySfEventMouseButton, Button), RO, (char *)""},
+ {(char *)"X", T_INT, offsetof(PySfEventMouseButton, X), RO, (char *)""},
+ {(char *)"Y", T_INT, offsetof(PySfEventMouseButton, Y), RO, (char *)""},
{NULL} /* Sentinel */
};
@@ -257,6 +350,7 @@ PyTypeObject PySfEventMouseButtonType = {
0, /* tp_dictoffset */
(initproc)PySfEventMouseButton_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventMouseButton_new, /* tp_new */
};
@@ -264,10 +358,19 @@ PyTypeObject PySfEventMouseButtonType = {
// MouseWheel Events Parameters
////////////////////////////////
-PyMemberDef PySfEventMouseWheel_members[] = {
- {"Delta", T_INT, offsetof(PySfEventMouseWheel,Delta), 0, ""},
- {NULL} /* Sentinel */
-};
+static PyObject *
+PySfEventMouseWheel_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventMouseWheel *self;
+
+ self = (PySfEventMouseWheel *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ self->Delta = 0;
+ }
+
+ return (PyObject *)self;
+}
int
PySfEventMouseWheel_init(PySfEventMouseWheel *self, PyObject *args, PyObject *kwds)
@@ -281,6 +384,11 @@ PySfEventMouseWheel_dealloc(PySfEventMouseWheel* self)
self->ob_type->tp_free((PyObject*)self);
}
+PyMemberDef PySfEventMouseWheel_members[] = {
+ {(char *)"Delta", T_INT, offsetof(PySfEventMouseWheel,Delta), RO, (char *)""},
+ {NULL} /* Sentinel */
+};
+
PyTypeObject PySfEventMouseWheelType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
@@ -320,6 +428,7 @@ PyTypeObject PySfEventMouseWheelType = {
0, /* tp_dictoffset */
(initproc)PySfEventMouseWheel_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventMouseWheel_new, /* tp_new */
};
@@ -327,6 +436,22 @@ PyTypeObject PySfEventMouseWheelType = {
// JoyMove Events Parameters
////////////////////////////////////
+static PyObject *
+PySfEventJoyMove_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventJoyMove *self;
+
+ self = (PySfEventJoyMove *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ self->JoystickId = 0;
+ self->Axis = 0;
+ self->Position = 0.f;
+ }
+
+ return (PyObject *)self;
+}
+
int
PySfEventJoyMove_init(PySfEventJoyMove *self, PyObject *args, PyObject *kwds)
{
@@ -341,9 +466,9 @@ PySfEventJoyMove_dealloc(PySfEventJoyMove* self)
PyMemberDef PySfEventJoyMove_members[] = {
- {"JoystickId", T_UINT, offsetof(PySfEventJoyMove,JoystickId), 0, ""},
- {"Axis", T_UINT, offsetof(PySfEventJoyMove,Axis), 0, ""},
- {"Position", T_FLOAT, offsetof(PySfEventJoyMove,Position), 0, ""},
+ {(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyMove,JoystickId), RO, (char *)""},
+ {(char *)"Axis", T_UINT, offsetof(PySfEventJoyMove,Axis), RO, (char *)""},
+ {(char *)"Position", T_FLOAT, offsetof(PySfEventJoyMove,Position), RO, (char *)""},
{NULL} /* Sentinel */
};
@@ -386,6 +511,7 @@ PyTypeObject PySfEventJoyMoveType = {
0, /* tp_dictoffset */
(initproc)PySfEventJoyMove_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventJoyMove_new, /* tp_new */
};
@@ -393,6 +519,21 @@ PyTypeObject PySfEventJoyMoveType = {
// JoyButton Events Parameters
////////////////////////////////////
+static PyObject *
+PySfEventJoyButton_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventJoyButton *self;
+
+ self = (PySfEventJoyButton *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ self->JoystickId = 0;
+ self->Button = 0;
+ }
+
+ return (PyObject *)self;
+}
+
int
PySfEventJoyButton_init(PySfEventJoyButton *self, PyObject *args, PyObject *kwds)
{
@@ -407,8 +548,8 @@ PySfEventJoyButton_dealloc(PySfEventJoyButton* self)
PyMemberDef PySfEventJoyButton_members[] = {
- {"JoystickId", T_UINT, offsetof(PySfEventJoyButton, JoystickId), 0, ""},
- {"Button", T_UINT, offsetof(PySfEventJoyButton, Button), 0, ""},
+ {(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyButton, JoystickId), RO, (char *)""},
+ {(char *)"Button", T_UINT, offsetof(PySfEventJoyButton, Button), RO, (char *)""},
{NULL} /* Sentinel */
};
@@ -451,6 +592,7 @@ PyTypeObject PySfEventJoyButtonType = {
0, /* tp_dictoffset */
(initproc)PySfEventJoyButton_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventJoyButton_new, /* tp_new */
};
@@ -458,6 +600,21 @@ PyTypeObject PySfEventJoyButtonType = {
// Size Events Parameters
////////////////////////////////////
+static PyObject *
+PySfEventSize_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfEventSize *self;
+
+ self = (PySfEventSize *)type->tp_alloc(type, 0);
+ if (self != NULL)
+ {
+ self->Width = 0;
+ self->Height = 0;
+ }
+
+ return (PyObject *)self;
+}
+
int
PySfEventSize_init(PySfEventSize *self, PyObject *args, PyObject *kwds)
{
@@ -471,8 +628,8 @@ PySfEventSize_dealloc(PySfEventSize* self)
}
PyMemberDef PySfEventSize_members[] = {
- {"Width", T_UINT, offsetof(PySfEventSize, Width), 0, ""},
- {"Height", T_UINT, offsetof(PySfEventSize, Height), 0, ""},
+ {(char *)"Width", T_UINT, offsetof(PySfEventSize, Width), RO, (char *)""},
+ {(char *)"Height", T_UINT, offsetof(PySfEventSize, Height), RO, (char *)""},
{NULL} /* Sentinel */
};
@@ -515,6 +672,7 @@ PyTypeObject PySfEventSizeType = {
0, /* tp_dictoffset */
(initproc)PySfEventSize_init, /* tp_init */
0, /* tp_alloc */
+ PySfEventSize_new, /* tp_new */
};
@@ -523,7 +681,7 @@ PyTypeObject PySfEventSizeType = {
////////////////////////////////////
-// sfEvent
+// sf.Event
////////////////////////////////////
@@ -542,15 +700,14 @@ PySfEvent_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (PySfEvent *)type->tp_alloc(type, 0);
if (self != NULL)
{
- self->Text = PyObject_New(PySfEventText, &PySfEventTextType);
- self->Key = PyObject_New(PySfEventKey, &PySfEventKeyType);
- // self->Key = (PySfEventKey*) PyType_GenericNew(&PySfEventKeyType, Py_None, Py_None);
- self->MouseMove = PyObject_New(PySfEventMouseMove, &PySfEventMouseMoveType);
- self->MouseButton = PyObject_New(PySfEventMouseButton, &PySfEventMouseButtonType);
- self->MouseWheel = PyObject_New(PySfEventMouseWheel, &PySfEventMouseWheelType);
- self->JoyMove = PyObject_New(PySfEventJoyMove, &PySfEventJoyMoveType);
- self->JoyButton = PyObject_New(PySfEventJoyButton, &PySfEventJoyButtonType);
- self->Size = PyObject_New(PySfEventSize, &PySfEventSizeType);
+ self->Text = (PySfEventText *)PySfEventText_new(&PySfEventTextType, NULL, NULL);
+ self->Key = (PySfEventKey *)PySfEventKey_new(&PySfEventKeyType, NULL, NULL);
+ self->MouseMove = (PySfEventMouseMove *)PySfEventMouseMove_new(&PySfEventMouseMoveType, NULL, NULL);
+ self->MouseButton = (PySfEventMouseButton *)PySfEventMouseButton_new(&PySfEventMouseButtonType, NULL, NULL);
+ self->MouseWheel = (PySfEventMouseWheel *)PySfEventMouseWheel_new(&PySfEventMouseWheelType, NULL, NULL);
+ self->JoyMove = (PySfEventJoyMove *)PySfEventJoyMove_new(&PySfEventJoyMoveType, NULL, NULL);
+ self->JoyButton = (PySfEventJoyButton *)PySfEventJoyButton_new(&PySfEventJoyButtonType, NULL, NULL);
+ self->Size = (PySfEventSize *)PySfEventSize_new(&PySfEventSizeType, NULL, NULL);
}
return (PyObject *)self;
@@ -572,15 +729,15 @@ PySfEvent_dealloc(PySfEvent* self)
}
static PyMemberDef PySfEvent_members[] = {
- {"Text", T_OBJECT, offsetof(PySfEvent, Text), RO, "Text Events Parameters"},
- {"Key", T_OBJECT, offsetof(PySfEvent, Key), RO, "Keyboard Events Parameters"},
- {"MouseMove", T_OBJECT, offsetof(PySfEvent, MouseMove), RO, "MouseMove Events Parameters"},
- {"MouseButton", T_OBJECT, offsetof(PySfEvent, MouseButton), RO, "MouseButton Events Parameters"},
- {"MouseWheel", T_OBJECT, offsetof(PySfEvent, MouseWheel), RO, "MouseWheel Events Parameters"},
- {"JoyMove", T_OBJECT, offsetof(PySfEvent, JoyMove), RO, "JoyMove Events Parameters"},
- {"JoyButton", T_OBJECT, offsetof(PySfEvent, JoyButton), RO, "JoyButton Events Parameters"},
- {"Size", T_OBJECT, offsetof(PySfEvent, Size), RO, "Size Events Parameters"},
- {"Type", T_UINT, offsetof(PySfEvent, Type), RO, "Type Events Parameters"},
+ {(char *)"Text", T_OBJECT, offsetof(PySfEvent, Text), RO, (char *)"Text Events Parameters"},
+ {(char *)"Key", T_OBJECT, offsetof(PySfEvent, Key), RO, (char *)"Keyboard Events Parameters"},
+ {(char *)"MouseMove", T_OBJECT, offsetof(PySfEvent, MouseMove), RO, (char *)"MouseMove Events Parameters"},
+ {(char *)"MouseButton", T_OBJECT, offsetof(PySfEvent, MouseButton), RO, (char *)"MouseButton Events Parameters"},
+ {(char *)"MouseWheel", T_OBJECT, offsetof(PySfEvent, MouseWheel), RO, (char *)"MouseWheel Events Parameters"},
+ {(char *)"JoyMove", T_OBJECT, offsetof(PySfEvent, JoyMove), RO, (char *)"JoyMove Events Parameters"},
+ {(char *)"JoyButton", T_OBJECT, offsetof(PySfEvent, JoyButton), RO, (char *)"JoyButton Events Parameters"},
+ {(char *)"Size", T_OBJECT, offsetof(PySfEvent, Size), RO, (char *)"Size Events Parameters"},
+ {(char *)"Type", T_UINT, offsetof(PySfEvent, Type), RO, (char *)"Type Events Parameters"},
{NULL} /* Sentinel */
};
@@ -610,7 +767,7 @@ PyTypeObject PySfEventType = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfEvent defines a system event and its parameters", /* tp_doc */
+ "sf.Event defines a system event and its parameters", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
@@ -631,22 +788,6 @@ PyTypeObject PySfEventType = {
};
-
-
-void
-initEvents(void)
-{
- PySfEventTextType.tp_new = PyType_GenericNew;
- PySfEventKeyType.tp_new = PyType_GenericNew;
- PySfEventMouseMoveType.tp_new = PyType_GenericNew;
- PySfEventMouseButtonType.tp_new = PyType_GenericNew;
- PySfEventMouseWheelType.tp_new = PyType_GenericNew;
- PySfEventJoyMoveType.tp_new = PyType_GenericNew;
- PySfEventJoyButtonType.tp_new = PyType_GenericNew;
- PySfEventSizeType.tp_new = PyType_GenericNew;
-}
-
-
void
PySfEvent_InitConst()
{
@@ -693,5 +834,11 @@ PySfEvent_InitConst()
obj = PyInt_FromLong(sf::Event::Resized);
PyDict_SetItemString(PySfEventType.tp_dict, "Resized", obj);
Py_DECREF(obj);
+ obj = PyInt_FromLong(sf::Event::MouseEntered);
+ PyDict_SetItemString(PySfEventType.tp_dict, "MouseEntered", obj);
+ Py_DECREF(obj);
+ obj = PyInt_FromLong(sf::Event::MouseLeft);
+ PyDict_SetItemString(PySfEventType.tp_dict, "MouseLeft", obj);
+ Py_DECREF(obj);
}
diff --git a/python/src/Event.hpp b/python/src/Event.hpp
index 53a67ac..c0f4ad8 100644
--- a/python/src/Event.hpp
+++ b/python/src/Event.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYEVENT_HPP
#define __PYEVENT_HPP
@@ -26,14 +50,16 @@ typedef struct
typedef struct
{
PyObject_HEAD
- unsigned int X;
- unsigned int Y;
+ int X;
+ int Y;
} PySfEventMouseMove;
typedef struct
{
PyObject_HEAD
unsigned int Button;
+ int X;
+ int Y;
} PySfEventMouseButton;
typedef struct
@@ -77,9 +103,6 @@ typedef struct {
} PySfEvent;
void
-initEvents(void);
-
-void
PySfEvent_InitConst();
#endif
diff --git a/python/src/Font.cpp b/python/src/Font.cpp
index 31bcdfd..c6c04f1 100644
--- a/python/src/Font.cpp
+++ b/python/src/Font.cpp
@@ -1,4 +1,29 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Font.hpp"
+#include "Glyph.hpp"
static PyMemberDef PySfFont_members[] = {
{NULL} /* Sentinel */
@@ -9,6 +34,7 @@ static PyMemberDef PySfFont_members[] = {
static void
PySfFont_dealloc(PySfFont *self)
{
+ delete self->obj;
self->ob_type->tp_free((PyObject*)self);
}
@@ -34,38 +60,58 @@ PySfFont_init(PySfFont *self, PyObject *args, PyObject *kwds)
}
static PyObject *
-PySfFont_LoadFromFile(PySfFont* self, PyObject *args)
+PySfFont_LoadFromFile(PySfFont* self, PyObject *args, PyObject *kwds)
{
+ const char *kwlist[] = {"Filename", "Charsize", "Charset", NULL};
unsigned int Charsize=30;
char *Filename;
- std::wstring Charset = L"";
- wchar_t *CharsetTmp=NULL;
+ char *CharsetTmp = NULL;
+ int CharsetSize;
+ bool Result;
- if (! PyArg_ParseTuple(args, "s|Iu", &Filename, &Charsize, &CharsetTmp))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|Is#", (char **)kwlist, &Filename, &Charsize, &CharsetTmp, &CharsetSize))
return NULL;
if (CharsetTmp)
- Charset.assign(CharsetTmp);
- if (self->obj->LoadFromFile(Filename, Charsize, Charset))
+ {
+ if ((unsigned char)CharsetTmp[0] == 0xff && (unsigned char)CharsetTmp[1] == 0xfe)
+ Result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::Text((const sf::Uint16 *)(CharsetTmp+2)));
+ else
+ Result = self->obj->LoadFromFile(Filename, Charsize, sf::Unicode::Text((const sf::Uint8 *)CharsetTmp));
+ }
+ else
+ Result = self->obj->LoadFromFile(Filename, Charsize);
+
+ if (Result)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
static PyObject *
-PySfFont_LoadFromMemory(PySfFont* self, PyObject *args)
+PySfFont_LoadFromMemory(PySfFont* self, PyObject *args, PyObject *kwds)
{
+ const char *kwlist[] = {"Data", "Charsize", "Charset", NULL};
unsigned int Charsize=30, Size;
char *Data;
- std::wstring Charset = L"";
- wchar_t *CharsetTmp=NULL;
+ char *CharsetTmp = NULL;
+ int CharsetSize;
+ bool Result;
- if (! PyArg_ParseTuple(args, "s#|Iu", &Data, &Size, &Charsize, &CharsetTmp))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "s#|Is#", (char **)kwlist, &Data, &Size, &Charsize, &CharsetTmp, &CharsetSize))
return NULL;
if (CharsetTmp)
- Charset.assign(CharsetTmp);
- if (self->obj->LoadFromMemory(Data, Size, Charsize, Charset))
+ {
+ if ((unsigned char)CharsetTmp[0] == 0xff && (unsigned char)CharsetTmp[1] == 0xfe)
+ Result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::Text((const sf::Uint16 *)(CharsetTmp+2)));
+ else
+ Result = self->obj->LoadFromMemory(Data, Size, Charsize, sf::Unicode::Text((const sf::Uint8 *)CharsetTmp));
+ }
+ else
+ Result = self->obj->LoadFromMemory(Data, Size, Charsize);
+
+ if (Result)
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
@@ -79,54 +125,86 @@ PySfFont_GetDefaultFont(PySfFont* self, PyObject *args)
return (PyObject *)Font;
}
+static PyObject *
+PySfFont_GetCharacterSize(PySfFont* self)
+{
+ return PyLong_FromUnsignedLong(self->obj->GetCharacterSize());
+}
+
+static PyObject *
+PySfFont_GetGlyph(PySfFont* self, PyObject *args)
+{
+ PySfGlyph *PyGlyph = GetNewPySfGlyph();
+ sf::Glyph *Glyph = new sf::Glyph(self->obj->GetGlyph(PyLong_AsUnsignedLong(args)));
+ PyGlyph->obj = Glyph;
+ PyGlyph->Rectangle->obj = &(PyGlyph->obj->Rectangle);
+ PyGlyph->TexCoords->obj = &(PyGlyph->obj->TexCoords);
+ PySfGlyphUpdateSelf(PyGlyph);
+ return (PyObject *)PyGlyph;
+}
+
static PyMethodDef PySfFont_methods[] = {
- {"LoadFromFile", (PyCFunction)PySfFont_LoadFromFile, METH_VARARGS, "Load the font from a file.\nparam Filename : Font file to load\nparam CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\nparam Charset : Characters set to generate (empty by default - takes the ASCII range [31, 255])\nreturn True if loading was successful."},
- {"LoadFromMemory", (PyCFunction)PySfFont_LoadFromMemory, METH_VARARGS, "Load the font from a file in memory.\nparam Data : data to load\nparam SizeInBytes : Size of the data, in bytes\nparam CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\nparam Charset : Characters set to generate (empty by default - takes the ASCII range [31, 255])\nreturn True if loading was successful."},
- {"GetDefaultFont", (PyCFunction)PySfFont_GetDefaultFont, METH_NOARGS | METH_STATIC, "Get the SFML default built-in font (Arial)."},
+ {"LoadFromFile", (PyCFunction)PySfFont_LoadFromFile, METH_VARARGS | METH_KEYWORDS, "LoadFromFile(Filename, CharSize, Charset)\n\
+Load the font from a file. Returns True if loading was successful.\n\
+ Filename : Font file to load\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])"},
+ {"LoadFromMemory", (PyCFunction)PySfFont_LoadFromMemory, METH_VARARGS | METH_KEYWORDS, "LoadFromMemory(Data, CharSize, Charset)\n\
+Load the font from a file in memory. Returns True if loading was successful.\n\
+ Data : data to load\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])"},
+ {"GetDefaultFont", (PyCFunction)PySfFont_GetDefaultFont, METH_NOARGS | METH_STATIC, "GetDefaultFont()\n\
+Get the SFML default built-in font (Arial)."},
+ {"GetCharacterSize", (PyCFunction)PySfFont_GetCharacterSize, METH_NOARGS, "GetCharacterSize()\n\
+Get the base size of characters in the font; All glyphs dimensions are based on this value"},
+ {"GetGlyph", (PyCFunction)PySfFont_GetGlyph, METH_O, "GetGlyph(CodePoint)\n\
+Get the description of a glyph (character) given by its unicode value. Returns glyph's visual settings, or an invalid glyph if character not found.\n\
+ CodePoint : Unicode value of the character to get."},
{NULL} /* Sentinel */
};
PyTypeObject PySfFontType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Font", /*tp_name*/
- sizeof(PySfFont), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Font", /*tp_name*/
+ sizeof(PySfFont), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfFont_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sf.Font is the low-level class for loading and manipulating character fonts. This class is meant to be used by sf.Font.", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfFont_methods, /* tp_methods */
- PySfFont_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfFont_init, /* tp_init */
- 0, /* tp_alloc */
- PySfFont_new, /* tp_new */
+ "sf.Font is the low-level class for loading and manipulating character fonts. This class is meant to be used by sf.String.\nDefault constructor : sf.Font().", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfFont_methods, /* tp_methods */
+ PySfFont_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfFont_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfFont_new, /* tp_new */
};
PySfFont *
diff --git a/python/src/Font.hpp b/python/src/Font.hpp
index 05913c5..6d202e5 100644
--- a/python/src/Font.hpp
+++ b/python/src/Font.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYFONT_HPP
#define __PYFONT_HPP
diff --git a/python/src/Glyph.cpp b/python/src/Glyph.cpp
new file mode 100644
index 0000000..21c93a3
--- /dev/null
+++ b/python/src/Glyph.cpp
@@ -0,0 +1,158 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#include "Glyph.hpp"
+
+static PyMemberDef PySfGlyph_members[] = {
+ {(char *)"Advance", T_INT, offsetof(PySfGlyph, Advance), 0, (char *)"Offset to move horizontically to the next character."},
+ {(char *)"Rectangle", T_OBJECT, offsetof(PySfGlyph, Rectangle), 0, (char *)"Bounding rectangle of the glyph, in relative coordinates."},
+ {(char *)"TexCoords", T_OBJECT, offsetof(PySfGlyph, TexCoords), 0, (char *)"Texture coordinates of the glyph inside the bitmap font."},
+ {NULL} /* Sentinel */
+};
+
+
+
+static void
+PySfGlyph_dealloc(PySfGlyph *self)
+{
+ self->Rectangle->obj = new sf::IntRect(self->obj->Rectangle);
+ Py_DECREF(self->Rectangle);
+ self->TexCoords->obj = new sf::FloatRect(self->obj->TexCoords);
+ Py_DECREF(self->TexCoords);
+ delete self->obj;
+ self->ob_type->tp_free((PyObject*)self);
+}
+
+void
+PySfGlyphUpdateObj(PySfGlyph *self)
+{
+ self->obj->Advance = self->Advance;
+ PySfIntRectUpdateObj(self->Rectangle);
+ PySfFloatRectUpdateObj(self->TexCoords);
+ self->obj->Rectangle.Left = self->Rectangle->Left;
+ self->obj->Rectangle.Top = self->Rectangle->Top;
+ self->obj->Rectangle.Right = self->Rectangle->Right;
+ self->obj->Rectangle.Bottom = self->Rectangle->Bottom;
+ self->obj->TexCoords.Left = self->TexCoords->Left;
+ self->obj->TexCoords.Top = self->TexCoords->Top;
+ self->obj->TexCoords.Right = self->TexCoords->Right;
+ self->obj->TexCoords.Bottom = self->TexCoords->Bottom;
+}
+
+void
+PySfGlyphUpdateSelf(PySfGlyph *self)
+{
+ self->Advance = self->obj->Advance;
+ self->Rectangle->Left = self->obj->Rectangle.Left;
+ self->Rectangle->Top = self->obj->Rectangle.Top;
+ self->Rectangle->Right = self->obj->Rectangle.Right;
+ self->Rectangle->Bottom = self->obj->Rectangle.Bottom;
+ self->TexCoords->Left = self->obj->TexCoords.Left;
+ self->TexCoords->Top = self->obj->TexCoords.Top;
+ self->TexCoords->Right = self->obj->TexCoords.Right;
+ self->TexCoords->Bottom = self->obj->TexCoords.Bottom;
+ PySfIntRectUpdateObj(self->Rectangle);
+ PySfFloatRectUpdateObj(self->TexCoords);
+}
+
+static PyObject *
+PySfGlyph_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfGlyph *self;
+
+ self = (PySfGlyph *)type->tp_alloc(type, 0);
+
+ if (self != NULL)
+ {
+ self->Advance = 0;
+ self->Rectangle = GetNewPySfIntRect();
+ self->TexCoords = GetNewPySfFloatRect();
+ }
+
+ return (PyObject *)self;
+}
+
+
+static int
+PySfGlyph_init(PySfGlyph *self, PyObject *args, PyObject *kwds)
+{
+ self->obj = new sf::Glyph();
+ self->Rectangle->obj = &(self->obj->Rectangle);
+ self->TexCoords->obj = &(self->obj->TexCoords);
+ return 0;
+}
+
+static PyMethodDef PySfGlyph_methods[] = {
+ {NULL} /* Sentinel */
+};
+
+
+PyTypeObject PySfGlyphType = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "Glyph", /*tp_name*/
+ sizeof(PySfGlyph), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ (destructor)PySfGlyph_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "Structure describing a glyph (a visual character).", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfGlyph_methods, /* tp_methods */
+ PySfGlyph_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfGlyph_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfGlyph_new, /* tp_new */
+};
+
+PySfGlyph *
+GetNewPySfGlyph()
+{
+ return (PySfGlyph *)PySfGlyph_new(&PySfGlyphType, NULL, NULL);
+}
+
diff --git a/python/src/Glyph.hpp b/python/src/Glyph.hpp
new file mode 100644
index 0000000..0b35a88
--- /dev/null
+++ b/python/src/Glyph.hpp
@@ -0,0 +1,56 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYGLYPH_HPP
+#define __PYGLYPH_HPP
+
+#include <SFML/Graphics/Glyph.hpp>
+#include <iostream>
+
+#include <Python.h>
+#include <structmember.h>
+
+#include "offsetof.hpp"
+
+#include "Rect.hpp"
+
+
+typedef struct {
+ PyObject_HEAD
+ int Advance;
+ PySfIntRect *Rectangle;
+ PySfFloatRect *TexCoords;
+ sf::Glyph *obj;
+} PySfGlyph;
+
+PySfGlyph *
+GetNewPySfGlyph();
+
+void
+PySfGlyphUpdateObj(PySfGlyph *self);
+
+void
+PySfGlyphUpdateSelf(PySfGlyph *self);
+
+#endif
diff --git a/python/src/Image.cpp b/python/src/Image.cpp
index af2aa30..9991135 100644
--- a/python/src/Image.cpp
+++ b/python/src/Image.cpp
@@ -1,7 +1,33 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Image.hpp"
+#include "RenderWindow.hpp"
extern PyTypeObject PySfColorType;
extern PyTypeObject PySfIntRectType;
+extern PyTypeObject PySfRenderWindowType;
static PyMemberDef PySfImage_members[] = {
{NULL} /* Sentinel */
@@ -36,13 +62,11 @@ PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
PySfColor *ColorTmp=NULL;
sf::Color *Color;
unsigned int Width=0, Height=0;
- char *kwlist[] = {"Width", "Height", "Color", NULL};
-
+ const char *kwlist[] = {"Width", "Height", "Color", NULL};
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!", kwlist, &Width, &Height, &PySfColorType, &ColorTmp))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!", (char **)kwlist, &Width, &Height, &PySfColorType, &ColorTmp))
return NULL;
-
if (ColorTmp)
{
Color = ColorTmp->obj;
@@ -56,28 +80,28 @@ PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
}
static PyObject *
-PySfImage_Resize(PySfImage* self, PyObject *args, PyObject *kwds)
+PySfImage_CopyScreen(PySfImage* self, PyObject *args)
{
- PySfColor *ColorTmp=NULL;
- sf::Color *Color;
- unsigned int Width=0, Height=0;
- char *kwlist[] = {"Width", "Height", "Color", NULL};
-
+// bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
+ PySfRenderWindow *RenderWindow;
+ PySfIntRect *SourceRect=NULL;
+ bool Result;
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|O!", kwlist, &Width, &Height, &PySfColorType, &ColorTmp))
+ if (! PyArg_ParseTuple(args, "O!|O!", &PySfRenderWindowType, &RenderWindow, &PySfIntRectType, &SourceRect))
return NULL;
- if (ColorTmp)
+ if (SourceRect)
{
- Color = ColorTmp->obj;
- PySfColorUpdate(ColorTmp);
- self->obj->Resize(Width, Height, *Color);
+ PySfIntRectUpdateObj(SourceRect);
+ Result = self->obj->CopyScreen(*(RenderWindow->obj), *(SourceRect->obj));
}
else
- self->obj->Resize(Width, Height);
-
- Py_RETURN_NONE;
+ Result = self->obj->CopyScreen(*(RenderWindow->obj));
+ if (Result)
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
}
static PyObject *
@@ -86,10 +110,10 @@ PySfImage_SetPixel(PySfImage* self, PyObject *args, PyObject *kwds)
PySfColor *ColorTmp=NULL;
sf::Color *Color;
unsigned int x=0, y=0;
- char *kwlist[] = {"x", "y", "Color", NULL};
+ const char *kwlist[] = {"x", "y", "Color", NULL};
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|O!", kwlist, &x, &y, &PySfColorType, &ColorTmp))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|O!", (char **)kwlist, &x, &y, &PySfColorType, &ColorTmp))
return NULL;
@@ -104,14 +128,13 @@ PySfImage_SetPixel(PySfImage* self, PyObject *args, PyObject *kwds)
}
static PyObject *
-PySfImage_GetPixel(PySfImage* self, PyObject *args, PyObject *kwds)
+PySfImage_GetPixel(PySfImage* self, PyObject *args)
{
PySfColor *Color;
unsigned int x=0, y=0;
- char *kwlist[] = {"x", "y", NULL};
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "II", kwlist, &x, &y))
+ if (! PyArg_ParseTuple(args, "II", &x, &y))
return NULL;
@@ -170,19 +193,7 @@ PySfImage_LoadFromPixels(PySfImage* self, PyObject *args)
}
static PyObject *
-PySfImage_GetPixelsBuffer(PySfImage *self)
-{
- return PyBuffer_FromMemory((void *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
-}
-
-static PyObject *
-PySfImage_GetPixelsPtr(PySfImage *self)
-{
- return PyCObject_FromVoidPtr((void *)(self->obj->GetPixelsPtr()), NULL);
-}
-
-static PyObject *
-PySfImage_GetPixelsString(PySfImage *self)
+PySfImage_GetPixels(PySfImage *self)
{
return PyString_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
}
@@ -210,12 +221,7 @@ PySfImage_SaveToFile (PySfImage *self, PyObject *args)
}
static int
-PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
-{
- self->obj = new sf::Image();
- PySfImage_Create(self, args, kwds);
- return 0;
-}
+PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds);
static PyObject *
PySfImage_Bind(PySfImage *self)
@@ -228,7 +234,7 @@ static PyObject *
PySfImage_SetSmooth (PySfImage *self, PyObject *args)
{
bool arg=false;
- if (args == Py_True)
+ if (PyObject_IsTrue(args))
arg = true;
self->obj->SetSmooth(arg);
Py_RETURN_NONE;
@@ -257,13 +263,14 @@ static PyObject *
PySfImage_GetTexCoords(PySfImage* self, PyObject *args)
{
PySfIntRect *RectArg = NULL;
- bool Adjust = true;
+ bool Adjust = false;
PyObject *AdjustObj = NULL;
if (! PyArg_ParseTuple(args, "O!|O", &PySfIntRectType, &RectArg, &AdjustObj))
+ return NULL;
- if (AdjustObj == Py_False)
- Adjust = false;
+ if (PyObject_IsTrue(AdjustObj))
+ Adjust = true;
PySfFloatRect *Rect;
@@ -277,70 +284,133 @@ PySfImage_GetTexCoords(PySfImage* self, PyObject *args)
return (PyObject *)Rect;
}
+static PyObject *
+PySfImage_Copy(PySfImage* self, PyObject *args);
+
static PyMethodDef PySfImage_methods[] = {
- {"Create", (PyCFunction)PySfImage_Create, METH_VARARGS | METH_KEYWORDS, "Create an empty image."},
- {"Resize", (PyCFunction)PySfImage_Resize, METH_VARARGS | METH_KEYWORDS, "Resize the image - warning : this function does not scale the image, it just ajdusts size (add padding or remove pixels)."},
- {"SetPixel", (PyCFunction)PySfImage_SetPixel, METH_VARARGS | METH_KEYWORDS, "Change the color of a pixel Don't forget to call Update when you end modifying pixels."},
- {"GetPixel", (PyCFunction)PySfImage_GetPixel, METH_VARARGS | METH_KEYWORDS, "Get a pixel from the image."},
- {"LoadFromFile", (PyCFunction)PySfImage_LoadFromFile, METH_O, "Load the surface from a file."},
- {"SaveToFile", (PyCFunction)PySfImage_SaveToFile, METH_O, "Save the content of the image to a file."},
- {"LoadFromMemory", (PyCFunction)PySfImage_LoadFromMemory, METH_VARARGS, "Load the image from pixels in memory."},
- {"LoadFromPixels", (PyCFunction)PySfImage_LoadFromPixels, METH_VARARGS, "Load the image directly from an array of pixels."},
- {"GetPixelsPtr", (PyCFunction)PySfImage_GetPixelsPtr, METH_NOARGS, "Get a read-only pointer to the array of pixels (8 bits integers RGBA) Array size is GetWidth() x GetHeight() x 4. This pointer becomes invalid if you reload or resize the image. Returns a CType pointer."},
- {"GetPixelsBuffer", (PyCFunction)PySfImage_GetPixelsBuffer, METH_NOARGS, "Same as GetPixelsPtr, but creates a buffer out of pixels data."},
- {"GetPixelsString", (PyCFunction)PySfImage_GetPixelsString, METH_NOARGS, "Same as GetPixelsPtr, but creates a string out of pixels data."},
- {"CreateMaskFromColor", (PyCFunction)PySfImage_CreateMaskFromColor, METH_O, "Create transparency mask from a specified colorkey."},
- {"Bind", (PyCFunction)PySfImage_Bind, METH_NOARGS, "Bind the image for rendering."},
- {"SetSmooth", (PyCFunction)PySfImage_SetSmooth, METH_VARARGS, "Enable or disable image smooth filter."},
- {"GetWidth", (PyCFunction)PySfImage_GetWidth, METH_NOARGS, "Return the width of the image."},
- {"GetHeight", (PyCFunction)PySfImage_GetHeight, METH_NOARGS, "Return the height of the image."},
- {"GetTexCoords", (PyCFunction)PySfImage_GetTexCoords, METH_VARARGS, "Convert a subrect expressed in pixels, into float texture coordinates."},
- {"GetValidTextureSize", (PyCFunction)PySfImage_GetValidTextureSize, METH_STATIC | METH_O, "Get a valid texture size according to hardware support."},
+ {"Copy", (PyCFunction)PySfImage_Copy, METH_VARARGS, "Copy(Source, DestX, DestY, SourceRect = sf.IntRect(0,0,0,0))\n\
+Copy pixels from another image onto this one. This function does a slow pixel copy and should only be used at initialization time.\n\
+ Source : Source image to copy\n\
+ DestX : X 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)"},
+ {"Create", (PyCFunction)PySfImage_Create, METH_VARARGS, "Create(Width=0, Height=0, Color=sf.Color.Black)\n\
+Create an empty image.\n\
+ Width : Image width\n\
+ Height : Image height\n\
+ Col : Image color (black by default)"},
+ {"CopyScreen", (PyCFunction)PySfImage_CopyScreen, METH_VARARGS, "CopyScreen(Window, SourceRect)\n\
+Create the image from the current contents of the given window. Return True if copy was successful.\n\
+ Window : Window to capture\n\
+ SourceRect : Sub-rectangle of the screen to copy (empty by default - entire image)"},
+ {"SetPixel", (PyCFunction)PySfImage_SetPixel, METH_VARARGS | METH_KEYWORDS, "SetPixel(X, Y, Col)\nChange the color of a pixel.\n\
+ X : X coordinate of pixel in the image\n Y : Y coordinate of pixel in the image\n Col : New color for pixel (X, Y)"},
+ {"GetPixel", (PyCFunction)PySfImage_GetPixel, METH_VARARGS, "GetPixel(X, Y)\nGet a pixel from the image."},
+ {"LoadFromFile", (PyCFunction)PySfImage_LoadFromFile, METH_O, "LoadFromFile(Path)\nLoad the surface from a file."},
+ {"SaveToFile", (PyCFunction)PySfImage_SaveToFile, METH_O, "SaveToFile(Path)\nSave the content of the image to a file."},
+ {"LoadFromMemory", (PyCFunction)PySfImage_LoadFromMemory, METH_VARARGS, "LoadFromMemory(Data)\nLoad the image from a file in memory."},
+ {"LoadFromPixels", (PyCFunction)PySfImage_LoadFromPixels, METH_VARARGS, "LoadFromPixels(Width, Height, Data)\nLoad the image directly from a string of pixels."},
+ {"GetPixels", (PyCFunction)PySfImage_GetPixels, METH_NOARGS, "GetPixels()\nGet a string representing the array of pixels (8 bits integers RGBA). String length is GetWidth() x GetHeight() x 4. This string becomes invalid if you reload or resize the image."},
+ {"CreateMaskFromColor", (PyCFunction)PySfImage_CreateMaskFromColor, METH_O, "CreateMaskFromColor(Color)\nCreate transparency mask from a specified colorkey."},
+ {"Bind", (PyCFunction)PySfImage_Bind, METH_NOARGS, "Bind()\nBind the image for rendering."},
+ {"SetSmooth", (PyCFunction)PySfImage_SetSmooth, METH_VARARGS, "SetSmooth(Smooth)\nEnable or disable image smooth filter."},
+ {"GetWidth", (PyCFunction)PySfImage_GetWidth, METH_NOARGS, "GetWidth()\nReturn the width of the image."},
+ {"GetHeight", (PyCFunction)PySfImage_GetHeight, METH_NOARGS, "GetHeight()\nReturn the height of the image."},
+ {"GetTexCoords", (PyCFunction)PySfImage_GetTexCoords, METH_VARARGS, "GetTexCoords(Rect, Adjust=True)\nConvert a subrect expressed in pixels, into float texture coordinates. Returns texture coordinates corresponding to the sub-rectangle (sf.FloatRect instance)\n\
+ Rect : Sub-rectangle of image to convert\n\
+ Adjust : Pass true to apply the half-texel adjustment"},
+ {"GetValidTextureSize", (PyCFunction)PySfImage_GetValidTextureSize, METH_STATIC | METH_O, "GetValidTextureSize(Size)\nGet a valid texture size according to hardware support. Returns valid nearest size (greater than or equal to specified size).\n\
+ Size : Size to convert"},
{NULL} /* Sentinel */
};
PyTypeObject PySfImageType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Image", /*tp_name*/
- sizeof(PySfImage), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Image", /*tp_name*/
+ sizeof(PySfImage), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfImage_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfImage is the low-level class for loading and manipulating images", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfImage_methods, /* tp_methods */
- PySfImage_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfImage_init, /* tp_init */
- 0, /* tp_alloc */
- PySfImage_new, /* tp_new */
+ "sf.Image is the low-level class for loading and manipulating images.\n\
+Default constructor : sf.Image()\n\
+Other constructors : sf.Image(Width=0, Height=0, Color=sf.Color.Black) or sf.Image(Width, Height, Data).\n\
+Copy constructor : sf.Image(Copy) where Copy is a sf.Image instance.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfImage_methods, /* tp_methods */
+ PySfImage_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfImage_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfImage_new, /* tp_new */
};
+static int
+PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds)
+{
+ if (PyTuple_Size(args) == 1)
+ {
+ PySfImage *Image;
+ if (PyArg_ParseTuple(args, "O!", &PySfImageType, &Image))
+ {
+ self->obj = new sf::Image(*(Image->obj));
+ return 0;
+ }
+ }
+ self->obj = new sf::Image();
+ if (PyTuple_Size(args) > 0)
+ {
+ if (PySfImage_Create(self, args, kwds) == NULL)
+ if (PySfImage_LoadFromPixels(self, args) == NULL)
+ return -1;
+ }
+ return 0;
+}
+
+static PyObject *
+PySfImage_Copy(PySfImage* self, PyObject *args)
+{
+ PySfIntRect *SourceRect = NULL;
+ PySfImage *Source = NULL;
+ unsigned int DestX, DestY;
+ if (! PyArg_ParseTuple(args, "O!II|O!", &PySfImageType, &Source, &DestX, &DestY, &PySfIntRectType, &SourceRect))
+ return NULL;
+
+ if (SourceRect)
+ {
+ PySfIntRectUpdateObj(SourceRect);
+ self->obj->Copy(*(Source->obj), DestX, DestY, *(SourceRect->obj));
+ }
+ else
+ self->obj->Copy(*(Source->obj), DestX, DestY);
+
+ Py_RETURN_NONE;
+}
+
PySfImage *
GetNewPySfImage()
{
diff --git a/python/src/Image.hpp b/python/src/Image.hpp
index 6ce6160..84713e0 100644
--- a/python/src/Image.hpp
+++ b/python/src/Image.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYIMAGE_HPP
#define __PYIMAGE_HPP
diff --git a/python/src/Input.cpp b/python/src/Input.cpp
index 104dab3..e0162fb 100644
--- a/python/src/Input.cpp
+++ b/python/src/Input.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Input.hpp"
@@ -9,7 +33,6 @@ static PyMemberDef PySfInput_members[] = {
static void
PySfInput_dealloc(PySfInput *self)
{
- // delete self->obj;
self->ob_type->tp_free((PyObject*)self);
}
@@ -30,7 +53,7 @@ PySfInput_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
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_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().");
return -1;
}
@@ -85,55 +108,55 @@ PySfInput_GetJoystickAxis(PySfInput *self, PyObject *args)
}
static PyMethodDef PySfInput_methods[] = {
- {"IsKeyDown", (PyCFunction)PySfInput_IsKeyDown, METH_O, "Get the state of a key."},
- {"IsMouseButtonDown", (PyCFunction)PySfInput_IsMouseButtonDown, METH_O, "Get the state of a mouse button."},
- {"IsJoystickButtonDown", (PyCFunction)PySfInput_IsJoystickButtonDown, METH_VARARGS, "Get the state of a joystick button."},
- {"GetMouseX", (PyCFunction)PySfInput_GetMouseX, METH_NOARGS, "Get the mouse X position."},
- {"GetMouseY", (PyCFunction)PySfInput_GetMouseY, METH_NOARGS, "Get the mouse Y position."},
- {"GetJoystickAxis", (PyCFunction)PySfInput_GetJoystickAxis, METH_O | METH_VARARGS, "Get a joystick axis position."},
+ {"IsKeyDown", (PyCFunction)PySfInput_IsKeyDown, METH_O, "IsKeyDown(KeyCode)\nGet the state of a key. Returns True if key is down, false if key is up.\n KeyCode : Key to check"},
+ {"IsMouseButtonDown", (PyCFunction)PySfInput_IsMouseButtonDown, METH_O, "IsMouseButtonDown(Button)\nGet the state of a mouse button. Returns True if button is down, false if button is up.\n Button : Button to check"},
+ {"IsJoystickButtonDown", (PyCFunction)PySfInput_IsJoystickButtonDown, METH_VARARGS, "IsJoystickButtonDown(JoyId, Button)\nGet the state of a joystick button. Returns True if button is down, false if button is up.\n JoyId : Identifier of the joystick to check (0 or 1)\n Button : Button to check"},
+ {"GetMouseX", (PyCFunction)PySfInput_GetMouseX, METH_NOARGS, "GetMouseX()\nGet the mouse X position."},
+ {"GetMouseY", (PyCFunction)PySfInput_GetMouseY, METH_NOARGS, "GetMouseY()\nGet the mouse Y position."},
+ {"GetJoystickAxis", (PyCFunction)PySfInput_GetJoystickAxis, METH_VARARGS, "GetJoystickAxis(JoyId, Axis)\nGet a joystick axis position. Returns current axis position, in the range [-100, 100] (except for POV, which is [0, 360])\n JoyId : Identifier of the joystick to check (0 or 1)\n Axis : Axis to get"},
{NULL} /* Sentinel */
};
PyTypeObject PySfInputType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Input", /*tp_name*/
- sizeof(PySfInput), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Input", /*tp_name*/
+ sizeof(PySfInput), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfInput_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfInput handles real-time input from keyboard and mouse.", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfInput_methods, /* tp_methods */
- PySfInput_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfInput_init, /* tp_init */
- 0, /* tp_alloc */
- PySfInput_new, /* tp_new */
+ "sf.Input handles real-time input from keyboard and mouse. Use it instead of events to handle continuous moves and more game-friendly inputs.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfInput_methods, /* tp_methods */
+ PySfInput_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfInput_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfInput_new, /* tp_new */
};
PySfInput *
diff --git a/python/src/Input.hpp b/python/src/Input.hpp
index 59a025d..ad5209e 100644
--- a/python/src/Input.hpp
+++ b/python/src/Input.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYINPUT_HPP
#define __PYINPUT_HPP
diff --git a/python/src/Joy.cpp b/python/src/Joy.cpp
index 268f9cf..b43b29d 100644
--- a/python/src/Joy.cpp
+++ b/python/src/Joy.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include <SFML/Window/Event.hpp>
#include <Python.h>
@@ -49,44 +73,44 @@ static PyMethodDef PySfJoy_methods[] = {
PyTypeObject PySfJoyType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Joy", /*tp_name*/
- sizeof(PySfJoy), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Joy", /*tp_name*/
+ sizeof(PySfJoy), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfJoy_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfJoy doc", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfJoy_methods, /* tp_methods */
- PySfJoy_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfJoy_init, /* tp_init */
- 0, /* tp_alloc */
- PySfJoy_new, /* tp_new */
+ "Definition of joystick axis for joystick events.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfJoy_methods, /* tp_methods */
+ PySfJoy_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfJoy_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfJoy_new, /* tp_new */
};
void PySfJoy_InitConst()
diff --git a/python/src/Joy.hpp b/python/src/Joy.hpp
index 3124f2e..14805ad 100644
--- a/python/src/Joy.hpp
+++ b/python/src/Joy.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYJOY_HPP
#define __PYJOY_HPP
diff --git a/python/src/Key.cpp b/python/src/Key.cpp
index 80ec892..f209c37 100644
--- a/python/src/Key.cpp
+++ b/python/src/Key.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include <SFML/Window/Event.hpp>
#include <Python.h>
@@ -49,44 +73,44 @@ static PyMethodDef PySfKey_methods[] = {
PyTypeObject PySfKeyType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Key", /*tp_name*/
- sizeof(PySfKey), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Key", /*tp_name*/
+ sizeof(PySfKey), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfKey_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfKey doc", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfKey_methods, /* tp_methods */
- PySfKey_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfKey_init, /* tp_init */
- 0, /* tp_alloc */
- PySfKey_new, /* tp_new */
+ "Definition of key codes for keyboard events.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfKey_methods, /* tp_methods */
+ PySfKey_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfKey_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfKey_new, /* tp_new */
};
void PySfKey_InitConst()
diff --git a/python/src/Key.hpp b/python/src/Key.hpp
index 707d9f2..2126ee2 100644
--- a/python/src/Key.hpp
+++ b/python/src/Key.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYKEY_HPP
#define __PYKEY_HPP
diff --git a/python/src/Listener.cpp b/python/src/Listener.cpp
index 474a09d..5a56143 100644
--- a/python/src/Listener.cpp
+++ b/python/src/Listener.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Listener.hpp"
@@ -82,55 +106,55 @@ PySfListener_GetTarget(PySfListener *self)
}
static PyMethodDef PySfListener_methods[] = {
- {"SetGlobalVolume", (PyCFunction)PySfListener_SetGlobalVolume, METH_STATIC | METH_O, "Change the global volume of all the sounds."},
- {"GetGlobalVolume", (PyCFunction)PySfListener_GetGlobalVolume, METH_STATIC | METH_NOARGS, "Get the current value of the global volume of all the sounds."},
- {"SetPosition", (PyCFunction)PySfListener_SetPosition, METH_STATIC | METH_VARARGS, "Change the position of the listener."},
- {"GetPosition", (PyCFunction)PySfListener_GetPosition, METH_STATIC | METH_NOARGS, "Get the current position of the listener."},
- {"SetTarget", (PyCFunction)PySfListener_SetTarget, METH_STATIC | METH_VARARGS, "Change the orientation of the listener (the point he must look at)"},
- {"GetTarget", (PyCFunction)PySfListener_GetTarget, METH_STATIC | METH_NOARGS, "Get the current orientation of the listener (the point he's looking at)"},
+ {"SetGlobalVolume", (PyCFunction)PySfListener_SetGlobalVolume, METH_STATIC | METH_O, "SetGlobalVolume(Volume)\nChange the global volume of all the sounds."},
+ {"GetGlobalVolume", (PyCFunction)PySfListener_GetGlobalVolume, METH_STATIC | METH_NOARGS, "GetGlobalVolume()\nGet the current value of the global volume of all the sounds."},
+ {"SetPosition", (PyCFunction)PySfListener_SetPosition, METH_STATIC | METH_VARARGS, "SetPosition(X, Y, Z)\nChange the position of the listener."},
+ {"GetPosition", (PyCFunction)PySfListener_GetPosition, METH_STATIC | METH_NOARGS, "GetPosition()\nGet the current position of the listener."},
+ {"SetTarget", (PyCFunction)PySfListener_SetTarget, METH_STATIC | METH_VARARGS, "SetTarget(X, Y, Z)\nChange the orientation of the listener (the point he must look at)"},
+ {"GetTarget", (PyCFunction)PySfListener_GetTarget, METH_STATIC | METH_NOARGS, "GetTarget()\nGet the current orientation of the listener (the point he's looking at)"},
{NULL} /* Sentinel */
};
PyTypeObject PySfListenerType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
+ 0, /*ob_size*/
"Listener", /*tp_name*/
- sizeof(PySfListener), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ sizeof(PySfListener), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfListener_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfListener doc", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfListener_methods, /* tp_methods */
- PySfListener_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfListener_init, /* tp_init */
- 0, /* tp_alloc */
- PySfListener_new, /* tp_new */
+ "Listener is a global interface for defining the audio listener properties ; the audio listener is the point in the scene from where all the sounds are heard.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfListener_methods, /* tp_methods */
+ PySfListener_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfListener_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfListener_new, /* tp_new */
};
diff --git a/python/src/Listener.hpp b/python/src/Listener.hpp
index e743cf0..6cd7250 100644
--- a/python/src/Listener.hpp
+++ b/python/src/Listener.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYLISTENER_HPP
#define __PYLISTENER_HPP
diff --git a/python/src/Mouse.cpp b/python/src/Mouse.cpp
index 903cabf..490e7e3 100644
--- a/python/src/Mouse.cpp
+++ b/python/src/Mouse.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include <SFML/Window/Event.hpp>
#include <Python.h>
@@ -49,44 +73,44 @@ static PyMethodDef PySfMouse_methods[] = {
PyTypeObject PySfMouseType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Mouse", /*tp_name*/
- sizeof(PySfMouse), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Mouse", /*tp_name*/
+ sizeof(PySfMouse), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfMouse_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfMouse doc", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfMouse_methods, /* tp_methods */
- PySfMouse_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfMouse_init, /* tp_init */
- 0, /* tp_alloc */
- PySfMouse_new, /* tp_new */
+ "Definition of button codes for mouse events.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfMouse_methods, /* tp_methods */
+ PySfMouse_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfMouse_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfMouse_new, /* tp_new */
};
void PySfMouse_InitConst()
diff --git a/python/src/Mouse.hpp b/python/src/Mouse.hpp
index 90949de..0876840 100644
--- a/python/src/Mouse.hpp
+++ b/python/src/Mouse.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYMOUSE_HPP
#define __PYMOUSE_HPP
diff --git a/python/src/Music.cpp b/python/src/Music.cpp
index d1dee8e..9801262 100644
--- a/python/src/Music.cpp
+++ b/python/src/Music.cpp
@@ -1,5 +1,32 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Music.hpp"
+
+extern PyTypeObject PySfSoundStreamType;
+
static PyMemberDef PySfMusic_members[] = {
{NULL} /* Sentinel */
@@ -66,127 +93,60 @@ PySfMusic_OpenFromFile(PySfMusic *self, PyObject *args)
}
static PyObject*
-PySfMusic_SetLoop(PySfMusic *self, PyObject *args)
-{
- if (args == Py_True)
- self->obj->SetLoop(true);
- else
- self->obj->SetLoop(false);
- Py_RETURN_NONE;
-}
-
-static PyObject*
-PySfMusic_GetLoop(PySfMusic *self)
-{
- if (self->obj->GetLoop())
- Py_RETURN_TRUE;
- else
- Py_RETURN_FALSE;
-}
-
-static PyObject*
PySfMusic_GetDuration(PySfMusic *self)
{
return PyFloat_FromDouble((double)(self->obj->GetDuration()));
}
-static PyObject*
-PySfMusic_Play(PySfMusic *self)
-{
- self->obj->Play();
- Py_RETURN_NONE;
-}
-
-static PyObject*
-PySfMusic_Stop(PySfMusic *self)
-{
- self->obj->Stop();
- Py_RETURN_NONE;
-}
-
-static PyObject*
-PySfMusic_GetChannelsCount(PySfMusic *self)
-{
- return PyLong_FromUnsignedLong(self->obj->GetChannelsCount());
-}
-
-static PyObject*
-PySfMusic_GetSampleRate(PySfMusic *self)
-{
- return PyLong_FromUnsignedLong(self->obj->GetSampleRate());
-}
-
-static PyObject*
-PySfMusic_GetStatus(PySfMusic *self)
-{
- return PyLong_FromUnsignedLong(self->obj->GetStatus());
-}
-
-static PyObject*
-PySfMusic_Initialize(PySfMusic *self, PyObject *args)
-{
- unsigned int ChannelsCount, SampleRate;
- if (! PyArg_ParseTuple(args, "II", &ChannelsCount, &SampleRate))
- return NULL;
- // self->obj->Initialize(ChannelsCount, SampleRate);
- Py_RETURN_NONE;
-}
static PyMethodDef PySfMusic_methods[] = {
- {"OpenFromFile", (PyCFunction)PySfMusic_OpenFromFile, METH_O, "Open a music file (doesn't play it -- call Play() for that)."},
- {"OpenFromMemory", (PyCFunction)PySfMusic_OpenFromMemory, METH_VARARGS, "Open a music file (doesn't play it -- call Play() for that)."},
- {"SetLoop", (PyCFunction)PySfMusic_SetLoop, METH_O, "Set the music loop state."},
- {"GetLoop", (PyCFunction)PySfMusic_GetLoop, METH_NOARGS, "Tell whether or not the music is looping."},
- {"GetDuration", (PyCFunction)PySfMusic_GetDuration, METH_NOARGS, "Get the sound duration."},
- {"Play", (PyCFunction)PySfMusic_Play, METH_NOARGS, "Start playing the audio stream."},
- {"Stop", (PyCFunction)PySfMusic_Stop, METH_NOARGS, "Stop playing the audio stream."},
- {"GetChannelsCount", (PyCFunction)PySfMusic_GetChannelsCount, METH_NOARGS, "Return the number of channels (1 = mono, 2 = stereo)"},
- {"GetSampleRate", (PyCFunction)PySfMusic_GetSampleRate, METH_NOARGS, "Get the sound frequency (sample rate)."},
- {"GetStatus", (PyCFunction)PySfMusic_GetStatus, METH_NOARGS, "Get the status of the sound (stopped, paused, playing)."},
- {"Initialize", (PyCFunction)PySfMusic_Initialize, METH_VARARGS, "Set the audio stream parameters, you must call it before Play()."},
+ {"OpenFromFile", (PyCFunction)PySfMusic_OpenFromFile, METH_O, "OpenFromFile(Filename)\nOpen a music file (doesn't play it -- call Play() for that). Returns True if loading has been successful.\n Filename : Path of the music file to open"},
+ {"OpenFromMemory", (PyCFunction)PySfMusic_OpenFromMemory, METH_VARARGS, "OpenFromMemory(Data)\nOpen a music file (doesn't play it -- call Play() for that). Returns True if loading has been successful.\n Data : string representing the file data in memory"},
+ {"GetDuration", (PyCFunction)PySfMusic_GetDuration, METH_NOARGS, "GetDuration()\nGet the sound duration."},
{NULL} /* Sentinel */
};
+
PyTypeObject PySfMusicType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Music", /*tp_name*/
- sizeof(PySfMusic), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Music", /*tp_name*/
+ sizeof(PySfMusic), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfMusic_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfMusic defines a big sound played using streaming, so usually what we call a music :)", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfMusic_methods, /* tp_methods */
- PySfMusic_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfMusic_init, /* tp_init */
- 0, /* tp_alloc */
- PySfMusic_new, /* tp_new */
+ "sf.Music defines a big sound played using streaming, so usually what we call a music :)", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfMusic_methods, /* tp_methods */
+ PySfMusic_members, /* tp_members */
+ 0, /* tp_getset */
+ &PySfSoundStreamType, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfMusic_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfMusic_new, /* tp_new */
};
diff --git a/python/src/Music.hpp b/python/src/Music.hpp
index 5904d3f..9d2fba4 100644
--- a/python/src/Music.hpp
+++ b/python/src/Music.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYMUSIC_HPP
#define __PYMUSIC_HPP
diff --git a/python/src/PostFX.cpp b/python/src/PostFX.cpp
index 2d0b956..fb2f343 100644
--- a/python/src/PostFX.cpp
+++ b/python/src/PostFX.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "PostFX.hpp"
@@ -35,28 +59,22 @@ static PyObject *
PySfPostFX_LoadFromFile (PySfPostFX *self, PyObject *args)
{
if (self->obj->LoadFromFile(PyString_AsString(args)))
- return Py_True;
+ Py_RETURN_TRUE;
else
- return Py_False;
+ Py_RETURN_FALSE;
}
static PyObject *
PySfPostFX_LoadFromMemory (PySfPostFX *self, PyObject *args)
{
if (self->obj->LoadFromMemory(PyString_AsString(args)))
- return Py_True;
+ Py_RETURN_TRUE;
else
- return Py_False;
+ Py_RETURN_FALSE;
}
static int
-PySfPostFX_init(PySfPostFX *self, PyObject *args)
-{
-
- self->obj = new sf::PostFX();
-
- return 0;
-}
+PySfPostFX_init(PySfPostFX *self, PyObject *args);
static PyObject *
@@ -94,9 +112,19 @@ PySfPostFX_SetTexture(PySfPostFX* self, PyObject *args)
{
PySfImage *Image = NULL;
char *Name;
- if (! PyArg_ParseTuple(args, "s|O!", &Name, &PySfImageType, &Image))
- return NULL;
- self->obj->SetTexture(Name, (Image ? Image->obj : NULL));
+ if (! PyArg_ParseTuple(args, "s|O", &Name, &Image))
+ return NULL;
+ if (Image == NULL || (PyObject *)Image == Py_None)
+ self->obj->SetTexture(Name, NULL);
+ else
+ {
+ if (!PyObject_TypeCheck(Image, &PySfImageType))
+ {
+ PyErr_SetString(PyExc_TypeError, "Argument 2, if specified, must be a sf.Image instance or None.");
+ return NULL;
+ }
+ self->obj->SetTexture(Name, Image->obj);
+ }
Py_RETURN_NONE;
}
@@ -111,54 +139,73 @@ PySfPostFX_CanUsePostFX(PySfPostFX* self, PyObject *args)
static PyMethodDef PySfPostFX_methods[] = {
- {"LoadFromFile", (PyCFunction)PySfPostFX_LoadFromFile, METH_O, "Load the effect from a file."},
- {"LoadFromMemory", (PyCFunction)PySfPostFX_LoadFromMemory, METH_O, "Load the effect from a text in memory."},
- {"SetParameter", (PyCFunction)PySfPostFX_SetParameter, METH_VARARGS, "Change a parameter of the effect."},
- {"SetTexture", (PyCFunction)PySfPostFX_SetTexture, METH_VARARGS, "Set a texture parameter."},
- {"CanUsePostFX", (PyCFunction)PySfPostFX_CanUsePostFX, METH_STATIC | METH_NOARGS, "Tell wether or not the system supports post-effects."},
+ {"LoadFromFile", (PyCFunction)PySfPostFX_LoadFromFile, METH_O, "LoadFromFile(Filename)\nLoad the effect from a file."},
+ {"LoadFromMemory", (PyCFunction)PySfPostFX_LoadFromMemory, METH_O, "LoadFromMemory(Effect)\nLoad the effect from a text in memory."},
+ {"SetParameter", (PyCFunction)PySfPostFX_SetParameter, METH_VARARGS, "SetParameter(X), SetParameter(X, Y), SetParameter(X, Y, Z), SetParameter(X, Y, Z, W)\nChange a parameter of the effect.\n\
+ Name : Parameter name in the effect\n\
+ X,Y,Z,W : Values to assign."},
+ {"SetTexture", (PyCFunction)PySfPostFX_SetTexture, METH_VARARGS, "SetTexture(Name, Texture)\nSet a texture parameter.\n\
+ Name : Texture name in the effect\n\
+ Texture : Image to set (pass None to use content of current framebuffer)"},
+ {"CanUsePostFX", (PyCFunction)PySfPostFX_CanUsePostFX, METH_STATIC | METH_NOARGS, "CanUsePostFX()\nTell wether or not the system supports post-effects."},
{NULL} /* Sentinel */
};
PyTypeObject PySfPostFXType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "PostFX", /*tp_name*/
- sizeof(PySfPostFX), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "PostFX", /*tp_name*/
+ sizeof(PySfPostFX), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfPostFX_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfPostFX defines a string : texture, transformations, color, and draw on screen", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfPostFX_methods, /* tp_methods */
- PySfPostFX_members, /* tp_members */
- 0, /* tp_getset */
- &PySfDrawableType, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfPostFX_init, /* tp_init */
- 0, /* tp_alloc */
- PySfPostFX_new, /* tp_new */
+ "sf.PostFX is used to apply a post effect to a window. ", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfPostFX_methods, /* tp_methods */
+ PySfPostFX_members, /* tp_members */
+ 0, /* tp_getset */
+ &PySfDrawableType, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfPostFX_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfPostFX_new, /* tp_new */
};
+static int
+PySfPostFX_init(PySfPostFX *self, PyObject *args)
+{
+ if (PyTuple_Size(args) == 1)
+ {
+ PySfPostFX *Copy;
+ if (PyArg_ParseTuple(args, "O!", &PySfPostFXType, &Copy))
+ self->obj = new sf::PostFX(*(Copy->obj));
+ else
+ return -1;
+ }
+ else
+ self->obj = new sf::PostFX();
+ return 0;
+}
diff --git a/python/src/PostFX.hpp b/python/src/PostFX.hpp
index a51ef8a..20541ac 100644
--- a/python/src/PostFX.hpp
+++ b/python/src/PostFX.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYPOSTFX_HPP
#define __PYPOSTFX_HPP
diff --git a/python/src/Rect.cpp b/python/src/Rect.cpp
index d49c830..abd938a 100644
--- a/python/src/Rect.cpp
+++ b/python/src/Rect.cpp
@@ -1,18 +1,42 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Rect.hpp"
static PyMemberDef PySfIntRect_members[] = {
- {"Left", T_INT, offsetof(PySfIntRect, Left), 0, ""},
- {"Top", T_INT, offsetof(PySfIntRect, Top), 0, ""},
- {"Right", T_INT, offsetof(PySfIntRect, Right), 0, ""},
- {"Bottom", T_INT, offsetof(PySfIntRect, Bottom), 0, ""},
+ {(char *)"Left", T_INT, offsetof(PySfIntRect, Left), 0, (char *)"Left coordinate of the rectangle."},
+ {(char *)"Top", T_INT, offsetof(PySfIntRect, Top), 0, (char *)"Top coordinate of the rectangle."},
+ {(char *)"Right", T_INT, offsetof(PySfIntRect, Right), 0, (char *)"Right coordinate of the rectangle."},
+ {(char *)"Bottom", T_INT, offsetof(PySfIntRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
{NULL} /* Sentinel */
};
static PyMemberDef PySfFloatRect_members[] = {
- {"Left", T_FLOAT, offsetof(PySfFloatRect, Left), 0, ""},
- {"Top", T_FLOAT, offsetof(PySfFloatRect, Top), 0, ""},
- {"Right", T_FLOAT, offsetof(PySfFloatRect, Right), 0, ""},
- {"Bottom", T_FLOAT, offsetof(PySfFloatRect, Bottom), 0, ""},
+ {(char *)"Left", T_FLOAT, offsetof(PySfFloatRect, Left), 0, (char *)"Left coordinate of the rectangle."},
+ {(char *)"Top", T_FLOAT, offsetof(PySfFloatRect, Top), 0, (char *)"Top coordinate of the rectangle."},
+ {(char *)"Right", T_FLOAT, offsetof(PySfFloatRect, Right), 0, (char *)"Right coordinate of the rectangle."},
+ {(char *)"Bottom", T_FLOAT, offsetof(PySfFloatRect, Bottom), 0, (char *)"Bottom coordinate of the rectangle."},
{NULL} /* Sentinel */
};
@@ -59,10 +83,10 @@ PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
PySfIntRect_init(PySfIntRect *self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
+ const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
int Left, Top, Right, Bottom;
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "iiii", kwlist, &Left, &Top, &Right, &Bottom))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "iiii", (char **)kwlist, &Left, &Top, &Right, &Bottom))
return -1;
self->Left = Left;
@@ -88,10 +112,10 @@ PySfIntRect_GetHeight(PySfIntRect *self)
}
static PyObject *
-PySfIntRect_Contains(PySfIntRect* self, PyObject *args, PyObject *kwds);
+PySfIntRect_Contains(PySfIntRect* self, PyObject *args);
static PyObject *
-PySfIntRect_Intersects(PySfIntRect* self, PyObject *args, PyObject *kwds);
+PySfIntRect_Intersects(PySfIntRect* self, PyObject *args);
static PyObject *
PySfFloatRect_GetWidth(PySfFloatRect *self)
@@ -108,18 +132,18 @@ PySfFloatRect_GetHeight(PySfFloatRect *self)
}
static PyObject *
-PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args, PyObject *kwds);
+PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args);
static PyObject *
-PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args, PyObject *kwds);
+PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args);
static int
PySfFloatRect_init(PySfFloatRect *self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
+ const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
float Left, Top, Right, Bottom;
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "ffff", kwlist, &Left, &Top, &Right, &Bottom))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "ffff", (char **)kwlist, &Left, &Top, &Right, &Bottom))
return -1;
self->Left = Left;
@@ -132,7 +156,7 @@ PySfFloatRect_init(PySfFloatRect *self, PyObject *args, PyObject *kwds)
static PyObject *
-PySfIntRect_Offset(PySfIntRect* self, PyObject *args, PyObject *kwds)
+PySfIntRect_Offset(PySfIntRect* self, PyObject *args)
{
int OffsetX, OffsetY;
@@ -146,7 +170,7 @@ PySfIntRect_Offset(PySfIntRect* self, PyObject *args, PyObject *kwds)
}
static PyObject *
-PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args, PyObject *kwds)
+PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args)
{
float OffsetX, OffsetY;
@@ -161,118 +185,140 @@ PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args, PyObject *kwds)
static PyMethodDef PySfIntRect_methods[] = {
- {"Offset", (PyCFunction)PySfIntRect_Offset, METH_VARARGS, "Move the whole rectangle by the given offset."},
- {"GetWidth", (PyCFunction)PySfIntRect_GetWidth, METH_NOARGS, "Get the width of the rectangle."},
- {"GetHeight", (PyCFunction)PySfIntRect_GetHeight, METH_NOARGS, "Get the height of the rectangle."},
- {"Contains", (PyCFunction)PySfIntRect_Contains, METH_VARARGS | METH_KEYWORDS, "Check if a point is inside the rectangle's area."},
- {"Intersects", (PyCFunction)PySfIntRect_Intersects, METH_VARARGS | METH_KEYWORDS, "Check intersection between two rectangles."},
+ {"Offset", (PyCFunction)PySfIntRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
+Move the whole rectangle by the given offset.\n\
+ OffsetX : Horizontal offset\n\
+ OffsetY : Vertical offset\n\
+"},
+ {"GetWidth", (PyCFunction)PySfIntRect_GetWidth, METH_NOARGS, "GetWidth()\n\
+Get the width of the rectangle."},
+ {"GetHeight", (PyCFunction)PySfIntRect_GetHeight, METH_NOARGS, "GetHeight()\n\
+Get the height of the rectangle."},
+ {"Contains", (PyCFunction)PySfIntRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
+Check if a point is inside the rectangle's area.\n\
+ X : X coordinate of the point to test\n\
+ Y : Y coordinate of the point to test"},
+ {"Intersects", (PyCFunction)PySfIntRect_Intersects, METH_VARARGS, "Intersects(Rectangle, OverlappingRect=None)\n\
+Check intersection between two rectangles.\n\
+ Rectangle : Rectangle to test\n\
+ OverlappingRect : Rectangle to be filled with overlapping rect (None by default)"},
{NULL} /* Sentinel */
};
static PyMethodDef PySfFloatRect_methods[] = {
- {"Offset", (PyCFunction)PySfFloatRect_Offset, METH_VARARGS, "Move the whole rectangle by the given offset."},
- {"GetWidth", (PyCFunction)PySfFloatRect_GetWidth, METH_NOARGS, "Get the width of the rectangle."},
- {"GetHeight", (PyCFunction)PySfFloatRect_GetHeight, METH_NOARGS, "Get the height of the rectangle."},
- {"Contains", (PyCFunction)PySfFloatRect_Contains, METH_VARARGS | METH_KEYWORDS, "Check if a point is inside the rectangle's area."},
- {"Intersects", (PyCFunction)PySfFloatRect_Intersects, METH_VARARGS | METH_KEYWORDS, "Check intersection between two rectangles."},
+ {"Offset", (PyCFunction)PySfFloatRect_Offset, METH_VARARGS, "Offset(OffsetX, OffsetY)\n\
+Move the whole rectangle by the given offset.\n\
+ OffsetX : Horizontal offset\n\
+ OffsetY : Vertical offset\n\
+"},
+ {"GetWidth", (PyCFunction)PySfFloatRect_GetWidth, METH_NOARGS, "GetWidth()\n\
+Get the width of the rectangle."},
+ {"GetHeight", (PyCFunction)PySfFloatRect_GetHeight, METH_NOARGS, "GetHeight()\n\
+Get the height of the rectangle."},
+ {"Contains", (PyCFunction)PySfFloatRect_Contains, METH_VARARGS, "Contains(X, Y)\n\
+Check if a point is inside the rectangle's area.\n\
+ X : X coordinate of the point to test\n\
+ Y : Y coordinate of the point to test"},
+ {"Intersects", (PyCFunction)PySfFloatRect_Intersects, METH_VARARGS, "Intersects(Rectangle, OverlappingRect=None)\n\
+Check intersection between two rectangles.\n\
+ Rectangle : Rectangle to test\n\
+ OverlappingRect : Rectangle to be filled with overlapping rect (None by default)"},
{NULL} /* Sentinel */
};
PyTypeObject PySfIntRectType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "IntRect", /*tp_name*/
- sizeof(PySfIntRect), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "IntRect", /*tp_name*/
+ sizeof(PySfIntRect), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfIntRect_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfRect is an utility class for manipulating rectangles.", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfIntRect_methods, /* tp_methods */
- PySfIntRect_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfIntRect_init, /* tp_init */
- 0, /* tp_alloc */
- PySfIntRect_new, /* tp_new */
+ "sf.IntRect is an utility class for manipulating rectangles.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfIntRect_methods, /* tp_methods */
+ PySfIntRect_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfIntRect_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfIntRect_new, /* tp_new */
};
PyTypeObject PySfFloatRectType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "FloatRect", /*tp_name*/
- sizeof(PySfFloatRect), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "FloatRect", /*tp_name*/
+ sizeof(PySfFloatRect), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfFloatRect_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfRect is an utility class for manipulating rectangles.", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfFloatRect_methods, /* tp_methods */
- PySfFloatRect_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfFloatRect_init, /* tp_init */
- 0, /* tp_alloc */
- PySfFloatRect_new, /* tp_new */
+ "sf.FloatRect is an utility class for manipulating rectangles.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfFloatRect_methods, /* tp_methods */
+ PySfFloatRect_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfFloatRect_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfFloatRect_new, /* tp_new */
};
static PyObject *
-PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args, PyObject *kwds)
+PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args)
{
float x=0, y=0;
- char *kwlist[] = {"x", "y", NULL};
-
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "ff", kwlist, &x, &y))
+ if (! PyArg_ParseTuple(args, "ff", &x, &y))
return NULL;
PySfFloatRectUpdateObj(self);
@@ -283,14 +329,13 @@ PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args, PyObject *kwds)
}
static PyObject *
-PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args, PyObject *kwds)
+PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args)
{
PySfFloatRect *Rect=NULL, *OverlappingRect=NULL;
- char *kwlist[] = {"Rect", "OverlappingRect", NULL};
bool result;
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!", kwlist, &PySfFloatRectType, &Rect, &PySfFloatRectType, &OverlappingRect))
+ if (! PyArg_ParseTuple(args, "O!|O!", &PySfFloatRectType, &Rect, &PySfFloatRectType, &OverlappingRect))
return NULL;
PySfFloatRectUpdateObj(self);
@@ -307,14 +352,12 @@ PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args, PyObject *kwds)
static PyObject *
-PySfIntRect_Contains(PySfIntRect* self, PyObject *args, PyObject *kwds)
+PySfIntRect_Contains(PySfIntRect* self, PyObject *args)
{
unsigned int x=0, y=0;
- char *kwlist[] = {"X", "Y", NULL};
-
PySfIntRectUpdateObj(self);
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "II", kwlist, &x, &y))
+ if (! PyArg_ParseTuple(args, "II", &x, &y))
return NULL;
if (self->obj->Contains(x,y))
@@ -324,15 +367,13 @@ PySfIntRect_Contains(PySfIntRect* self, PyObject *args, PyObject *kwds)
}
static PyObject *
-PySfIntRect_Intersects(PySfIntRect* self, PyObject *args, PyObject *kwds)
+PySfIntRect_Intersects(PySfIntRect* self, PyObject *args)
{
PySfIntRect *Rect=NULL, *OverlappingRect=NULL;
- char *kwlist[] = {"Rect", "OverlappingRect", NULL};
bool result;
-
PySfIntRectUpdateObj(self);
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!|O!", kwlist, &PySfIntRectType, &Rect, &PySfIntRectType, &OverlappingRect))
+ if (! PyArg_ParseTuple(args, "O!|O!", &PySfIntRectType, &Rect, &PySfIntRectType, &OverlappingRect))
return NULL;
if (OverlappingRect)
diff --git a/python/src/Rect.hpp b/python/src/Rect.hpp
index 9636f16..59856f9 100644
--- a/python/src/Rect.hpp
+++ b/python/src/Rect.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYRECT_HPP
#define __PYRECT_HPP
diff --git a/python/src/RenderWindow.cpp b/python/src/RenderWindow.cpp
index 4a87fe0..a251bd8 100644
--- a/python/src/RenderWindow.cpp
+++ b/python/src/RenderWindow.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "RenderWindow.hpp"
#include "Event.hpp"
@@ -6,7 +30,8 @@
#include "Color.hpp"
#include "Rect.hpp"
#include "View.hpp"
-#include "Image.hpp"
+#include "Image.hpp"
+#include "Window.hpp"
#include "SFML/Window/WindowStyle.hpp"
@@ -16,7 +41,8 @@ extern PyTypeObject PySfViewType;
extern PyTypeObject PySfColorType;
extern PyTypeObject PySfWindowType;
extern PyTypeObject PySfWindowSettingsType;
-extern PyTypeObject PySfVideoModeType;
+extern PyTypeObject PySfVideoModeType;
+extern PyTypeObject PySfDrawableType;
static PyMemberDef PySfRenderWindow_members[] = {
{NULL} /* Sentinel */
@@ -43,47 +69,14 @@ PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return (PyObject *)self;
}
-
-static PyObject*
-PySfRenderWindow_Create(PySfRenderWindow* self, PyObject *args, PyObject *kwds)
-{
- PyObject *VideoModeTmp=NULL;
- sf::VideoMode *VideoMode;
- char *Title=NULL;
- unsigned long WindowStyle = sf::Style::Resize | sf::Style::Close;
- PySfWindowSettings *ParamsTmp=NULL;
- sf::WindowSettings *Params;
-
- char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL};
-
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!", kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &ParamsTmp))
- return NULL;
-
- if (VideoModeTmp) {
- VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
- PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
- }
- else
- return NULL;
-
- if (ParamsTmp)
- Params = ParamsTmp->obj;
- else
- Params = new sf::WindowSettings();
-
- self->obj->Create(*VideoMode, Title, WindowStyle, *Params);
-
- Py_RETURN_NONE;
-}
-
static int
PySfRenderWindow_init(PySfRenderWindow *self, PyObject *args, PyObject *kwds)
{
- self->obj = new sf::RenderWindow();
- PySfRenderWindow_Create(self, args, kwds);
+ self->obj = new sf::RenderWindow();
+ if (PyTuple_Size(args) > 0)
+ PySfWindow_Create((PySfWindow *)self, args, kwds);
return 0;
-}
-
+}
static PyObject *
PySfRenderWindow_Capture(PySfRenderWindow *self)
@@ -112,22 +105,57 @@ PySfRenderWindow_ConvertCoords(PySfRenderWindow *self, PyObject *args)
Vect = self->obj->ConvertCoords(WindowX, WindowY, TargetView);
return Py_BuildValue("ff", Vect.x, Vect.y);
}
+
+static bool
+PySfRenderWindow_DrawObject(PySfRenderWindow *RenderWindow, PySfDrawable *Obj)
+{
+ if (PyObject_TypeCheck((PyObject *)Obj, &PySfDrawableType))
+ {
+ if (PyObject_HasAttrString((PyObject *)Obj, "Render"))
+ {
+ Obj->obj->RenderWindow = RenderWindow;
+ Obj->obj->RenderFunction = PyObject_GetAttrString((PyObject *)Obj, "Render");
+ }
+ RenderWindow->obj->Draw( *(Obj->obj) );
+ return true;
+ }
+ return false;
+}
static PyObject *
PySfRenderWindow_Draw(PySfRenderWindow *self, PyObject *args)
{
- PySfDrawable *Drawable = (PySfDrawable *)args;
-
if (!args)
return NULL;
- if (PyObject_HasAttrString(args, "Render"))
- {
- Drawable->obj->RenderWindow = self;
- Drawable->obj->RenderFunction = PyObject_GetAttrString(args, "Render");
- }
- self->obj->Draw( *(Drawable->obj) );
+ if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)args))
+ {
+ PyObject *iterator = PyObject_GetIter(args);
+ PyObject *item;
+
+ if (iterator == NULL)
+ {
+ PyErr_SetString(PyExc_TypeError, "Argument to Draw method is neither a Drawable nor an iterable.");
+ return NULL;
+ }
+
+ while ((item = PyIter_Next(iterator)))
+ {
+ if (!PySfRenderWindow_DrawObject(self, (PySfDrawable *)item))
+ {
+ PyErr_SetString(PyExc_TypeError, "Object in iterable not a Drawable.");
+ return NULL;
+ }
+ Py_DECREF(item);
+ }
+
+ Py_DECREF(iterator);
+
+ if (PyErr_Occurred()) {
+ return NULL;
+ }
+ }
Py_RETURN_NONE;
}
@@ -157,28 +185,14 @@ PySfRenderWindow_GetView(PySfRenderWindow *self)
static PyObject *
PySfRenderWindow_PreserveOpenGLStates(PySfRenderWindow *self, PyObject *args)
{
- bool Optimize = true;
- if (args == Py_False)
- Optimize = false;
+ bool Optimize = false;
+ if (PyObject_IsTrue(args))
+ Optimize = true;
self->obj->PreserveOpenGLStates(Optimize);
Py_RETURN_NONE;
}
static PyObject *
-PySfRenderWindow_SetBackgroundColor(PySfRenderWindow* self, PyObject *args)
-{
- PySfColor *Color = (PySfColor *)args;
- if (! PyObject_TypeCheck(Color, &PySfColorType))
- {
- PyErr_SetString(PyExc_TypeError, "Argument is not a sfColor");
- return NULL;
- }
- PySfColorUpdate(Color);
- self->obj->SetBackgroundColor(*(Color->obj));
- Py_RETURN_NONE;
-}
-
-static PyObject *
PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args)
{
PySfView *View = (PySfView *)args;
@@ -190,69 +204,86 @@ PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args)
self->obj->SetView( *(View->obj));
Py_RETURN_NONE;
}
+
+static PyObject *
+PySfRenderWindow_Clear(PySfRenderWindow* self, PyObject *args)
+{
+ PySfColor *Color = (PySfColor *)args;
+ if (! PyObject_TypeCheck(Color, &PySfColorType))
+ {
+ PyErr_SetString(PyExc_TypeError, "Argument is not a sfColor");
+ return NULL;
+ }
+ PySfColorUpdate(Color);
+ self->obj->Clear(*(Color->obj));
+ Py_RETURN_NONE;
+}
static PyMethodDef PySfRenderWindow_methods[] = {
- {"Capture", (PyCFunction)PySfRenderWindow_Capture, METH_NOARGS, "Save the content of the window to an image."},
- {"ConvertCoords", (PyCFunction)PySfRenderWindow_ConvertCoords, METH_VARARGS, "Convert a point in window coordinates into view coordinates\n\
-param WindowX : X coordinate of the point to convert, relative to the window\n\
-param WindowY : Y coordinate of the point to convert, relative to the window\n\
-param TargetView : Target view to convert the point to (NULL by default -- uses the current view)."},
- {"Draw", (PyCFunction)PySfRenderWindow_Draw, METH_O, "Draw something on the window."},
- {"GetDefaultView", (PyCFunction)PySfRenderWindow_GetDefaultView, METH_NOARGS, "Get the default view of the window for read / write."},
- {"GetView", (PyCFunction)PySfRenderWindow_GetView, METH_NOARGS, "Get the current view rectangle."},
- {"PreserveOpenGLStates", (PyCFunction)PySfRenderWindow_PreserveOpenGLStates, METH_O, "\
-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\
-param Preserve : True to preserve OpenGL states, false to let SFML optimize"},
- {"SetBackgroundColor", (PyCFunction)PySfRenderWindow_SetBackgroundColor, METH_O, "Change the background color of the window."},
- {"SetView", (PyCFunction)PySfRenderWindow_SetView, METH_O, "Change the current active view."},
+ {"Clear", (PyCFunction)PySfRenderWindow_Clear, METH_O, "Clear(FillColor)\n\
+Clear the entire target with a single color.\n\
+ 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\
+Get the default view of the window for read / write (returns a sf.View instance)."},
+ {"GetView", (PyCFunction)PySfRenderWindow_GetView, METH_NOARGS, "GetView()\n\
+Get the current view rectangle (returns a sf.View instance)."},
+ {"PreserveOpenGLStates", (PyCFunction)PySfRenderWindow_PreserveOpenGLStates, METH_O, "PreserveOpenGLStates(Preserve)\n\
+Tell SFML to preserve external OpenGL states, at the expense of more CPU charge. Use this function if you don't want SFML to mess up your own OpenGL states (if any). Don't enable state preservation if not needed, as it will allow SFML to do internal optimizations and improve performances. This parameter is false by default\n\
+ Preserve : True to preserve OpenGL states, false to let SFML optimize"},
+ {"SetView", (PyCFunction)PySfRenderWindow_SetView, METH_O, "SetView(View)\n\
+Change the current active view. View must be a sf.View instance."},
{NULL} /* Sentinel */
};
PyTypeObject PySfRenderWindowType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "RenderWindow", /*tp_name*/
- sizeof(PySfRenderWindow), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "RenderWindow", /*tp_name*/
+ sizeof(PySfRenderWindow), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfRenderWindow_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT, /*tp_flags*/
- "Simple wrapper for sfWindow that allows easy 2D rendering.", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfRenderWindow_methods, /* tp_methods */
- PySfRenderWindow_members, /* tp_members */
- 0, /* tp_getset */
- &PySfWindowType, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfRenderWindow_init, /* tp_init */
- 0, /* tp_alloc */
- PySfRenderWindow_new, /* tp_new */
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "Simple wrapper for sf.Window that allows easy 2D rendering.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfRenderWindow_methods, /* tp_methods */
+ PySfRenderWindow_members, /* tp_members */
+ 0, /* tp_getset */
+ &PySfWindowType, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfRenderWindow_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfRenderWindow_new, /* tp_new */
};
diff --git a/python/src/RenderWindow.hpp b/python/src/RenderWindow.hpp
index f8852f7..c484b89 100644
--- a/python/src/RenderWindow.hpp
+++ b/python/src/RenderWindow.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYRENDERWINDOW_HPP
#define __PYRENDERWINDOW_HPP
@@ -11,7 +35,6 @@
typedef struct {
PyObject_HEAD
- PySfWindowSettings *Settings;
sf::RenderWindow *obj;
} PySfRenderWindow;
diff --git a/python/src/Shape.cpp b/python/src/Shape.cpp
index 7881fa4..ad2bd52 100644
--- a/python/src/Shape.cpp
+++ b/python/src/Shape.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Shape.hpp"
#include <SFML/Graphics/Color.hpp>
@@ -45,11 +69,11 @@ PySfShape_init(PySfShape *self, PyObject *args)
static PyObject *
PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"X", "Y", "Col", "OutlineCol", NULL};
+ const char *kwlist[] = {"X", "Y", "Col", "OutlineCol", NULL};
float X, Y;
sf::Color *Col, *OutlineCol;
PySfColor *ColTmp=NULL, *OutlineColTmp=NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff|O!O!", kwlist, &X, &Y, &PySfColorType, &Col, &PySfColorType, &OutlineCol))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "ff|O!O!", (char **)kwlist, &X, &Y, &PySfColorType, &ColTmp, &PySfColorType, &OutlineColTmp))
return NULL;
if (ColTmp)
@@ -90,12 +114,12 @@ PySfShape_GetOutlineWidth(PySfShape* self)
static PyObject *
PySfShape_Line(PySfShape* self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"X0", "Y0", "X1", "Y1", "Thickness", "Col", "Outline", "OutlineCol", NULL};
+ const char *kwlist[] = {"X0", "Y0", "X1", "Y1", "Thickness", "Col", "Outline", "OutlineCol", NULL};
PySfShape *Line = GetNewPySfShape();
float X0, Y0, X1, Y1, Thickness, Outline = 0.f;
sf::Color *OutlineCol;
PySfColor *ColTmp, *OutlineColTmp=NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffffO!|fO!", kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffffO!|fO!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
return NULL;
if (OutlineColTmp)
{
@@ -114,12 +138,12 @@ PySfShape_Line(PySfShape* self, PyObject *args, PyObject *kwds)
static PyObject *
PySfShape_Rectangle(PySfShape* self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"X0", "Y0", "X1", "Y1", "Col", "Outline", "OutlineCol", NULL};
+ const char *kwlist[] = {"X0", "Y0", "X1", "Y1", "Col", "Outline", "OutlineCol", NULL};
PySfShape *Rectangle = GetNewPySfShape();
float X0, Y0, X1, Y1, Outline = 0.f;
sf::Color *OutlineCol;
PySfColor *ColTmp, *OutlineColTmp=NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffO!|fO!", kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "ffffO!|fO!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
return NULL;
if (OutlineColTmp)
{
@@ -138,12 +162,12 @@ PySfShape_Rectangle(PySfShape* self, PyObject *args, PyObject *kwds)
static PyObject *
PySfShape_Circle(PySfShape* self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"X", "Y", "Radius", "Col", "Outline", "OutlineCol", NULL};
+ const char *kwlist[] = {"X", "Y", "Radius", "Col", "Outline", "OutlineCol", NULL};
PySfShape *Circle = GetNewPySfShape();
float X, Y, Radius, Outline = 0.f;
sf::Color *OutlineCol;
PySfColor *ColTmp, *OutlineColTmp=NULL;
- if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffO!|fO!", kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
+ if (!PyArg_ParseTupleAndKeywords(args, kwds, "fffO!|fO!", (char **)kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
return NULL;
if (OutlineColTmp)
{
@@ -159,13 +183,72 @@ PySfShape_Circle(PySfShape* self, PyObject *args, PyObject *kwds)
}
static PyObject *
-PySfShape_GetPoint(PySfShape* self, PyObject *args)
+PySfShape_GetPointPosition(PySfShape* self, PyObject *args)
{
- sf::Vector2f result = self->obj->GetPoint(PyLong_AsUnsignedLong(args));
+ sf::Vector2f result = self->obj->GetPointPosition(PyLong_AsUnsignedLong(args));
return Py_BuildValue("ff", result.x, result.y);
}
static PyObject *
+PySfShape_GetPointColor(PySfShape* self, PyObject *args)
+{
+ PySfColor *PyColor = GetNewPySfColor();
+ PyColor->obj = new sf::Color(self->obj->GetPointColor(PyLong_AsUnsignedLong(args)));
+ PyColor->r = PyColor->obj->r;
+ PyColor->g = PyColor->obj->g;
+ PyColor->b = PyColor->obj->b;
+ PyColor->a = PyColor->obj->a;
+ return (PyObject *)PyColor;
+}
+
+static PyObject *
+PySfShape_GetPointOutlineColor(PySfShape* self, PyObject *args)
+{
+ PySfColor *PyColor = GetNewPySfColor();
+ PyColor->obj = new sf::Color(self->obj->GetPointOutlineColor(PyLong_AsUnsignedLong(args)));
+ PyColor->r = PyColor->obj->r;
+ PyColor->g = PyColor->obj->g;
+ PyColor->b = PyColor->obj->b;
+ PyColor->a = PyColor->obj->a;
+ return (PyObject *)PyColor;
+}
+
+static PyObject *
+PySfShape_SetPointPosition(PySfShape* self, PyObject *args)
+{
+ unsigned int Index;
+ float X, Y;
+ if (!PyArg_ParseTuple(args, "Iff", &Index, &X, &Y))
+ return NULL;
+ self->obj->SetPointPosition(Index, X, Y);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+PySfShape_SetPointColor(PySfShape* self, PyObject *args)
+{
+ unsigned int Index;
+ PySfColor *Color;
+ if (!PyArg_ParseTuple(args, "IO!", &Index, &PySfColorType, &Color))
+ return NULL;
+ PySfColorUpdate(Color);
+ self->obj->SetPointColor(Index, *(Color->obj));
+ Py_RETURN_NONE;
+}
+
+static PyObject *
+PySfShape_SetPointOutlineColor(PySfShape* self, PyObject *args)
+{
+ unsigned int Index;
+ PySfColor *Color;
+ if (!PyArg_ParseTuple(args, "IO!", &Index, &PySfColorType, &Color))
+ return NULL;
+ PySfColorUpdate(Color);
+ self->obj->SetPointOutlineColor(Index, *(Color->obj));
+ Py_RETURN_NONE;
+}
+
+static PyObject *
PySfShape_GetNbPoints(PySfShape* self, PyObject *args)
{
return PyLong_FromUnsignedLong(self->obj->GetNbPoints());
@@ -174,48 +257,90 @@ PySfShape_GetNbPoints(PySfShape* self, PyObject *args)
static PyObject *
PySfShape_EnableFill(PySfShape* self, PyObject *args)
{
- if (args == Py_False)
- self->obj->EnableFill(false);
- else
+ if (PyObject_IsTrue(args))
self->obj->EnableFill(true);
+ else
+ self->obj->EnableFill(false);
Py_RETURN_NONE;
}
static PyObject *
PySfShape_EnableOutline(PySfShape* self, PyObject *args)
{
- if (args == Py_False)
- self->obj->EnableOutline(false);
- else
+ if (PyObject_IsTrue(args))
self->obj->EnableOutline(true);
+ else
+ self->obj->EnableOutline(false);
Py_RETURN_NONE;
}
static PyMethodDef PySfShape_methods[] = {
- {"GetPoint", (PyCFunction)PySfShape_GetPoint, METH_O, "Get a point of the shape.\n param Index-th point."},
- {"GetNbPoints", (PyCFunction)PySfShape_GetNbPoints, METH_NOARGS, "Get the number of points composing the shape.\n param Total number of points."},
- {"EnableFill", (PyCFunction)PySfShape_EnableFill, METH_O, "Enable or disable filling the shape. Fill is enabled by default.\n param Enable : True to enable, false to disable."},
- {"EnableOutline", (PyCFunction)PySfShape_EnableOutline, METH_O, "Enable or disable drawing the shape outline. Outline is enabled by default.\n param Enable : True to enable, false to disable"},
- {"AddPoint", (PyCFunction)PySfShape_AddPoint, METH_VARARGS | METH_KEYWORDS, "Add a point to the shape.\n param X : X coordinate of the point\n param Y : Y coordinate of the point\n param Col : Color of the point (white by default)\n param OutlineCol : Outline color of the point (black by default)."},
- {"SetOutlineWidth", (PyCFunction)PySfShape_SetOutlineWidth, METH_O, "Change the width of the shape outline.\n param Width : New width (use 0 to remove the outline)."},
- {"GetOutlineWidth", (PyCFunction)PySfShape_GetOutlineWidth, METH_NOARGS, "Get the width of the shape outline.\n param return Current outline width"},
- {"Line", (PyCFunction)PySfShape_Line, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Line(X0, Y0, X1, Y1, Thickness, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\n\
+ {"GetPointPosition", (PyCFunction)PySfShape_GetPointPosition, METH_O, "GetPointPosition(Index)\n\
+Get the position of a point.\n\
+ Index : Index-th point."},
+ {"GetPointColor", (PyCFunction)PySfShape_GetPointColor, METH_O, "GetPointColor(Index)\n\
+Get the color of a point.\n Index : Index-th point."},
+ {"GetPointOutlineColor", (PyCFunction)PySfShape_GetPointOutlineColor, METH_O, "GetPointOutlineColor(Index)\n\
+Get the outline color of a point.\n Index : Index-th point."},
+ {"SetPointPosition", (PyCFunction)PySfShape_SetPointPosition, METH_VARARGS, "SetPointPosition(Index, X, Y).\n\
+Set the position of a point\n\
+ Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ X : New X coordinate of the Index-th point\n\
+ Y : New Y coordinate of the Index-th point."},
+ {"SetPointColor", (PyCFunction)PySfShape_SetPointColor, METH_VARARGS, "SetPointColor(Index, Color).\n\
+Set the color of a point\n\
+ Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Col : New color of the Index-th point."},
+ {"SetPointOutlineColor", (PyCFunction)PySfShape_SetPointOutlineColor, METH_VARARGS, "SetPointOutlineColor(Index, Color).\n\
+Set the outline color of a point\n\
+ Index : Index of the point, in range [0, GetNbPoints() - 1]\n\
+ Col : New color of the Index-th point."},
+ {"GetNbPoints", (PyCFunction)PySfShape_GetNbPoints, METH_NOARGS, "GetNbPoints()\n\
+Get the number of points composing the shape."},
+ {"EnableFill", (PyCFunction)PySfShape_EnableFill, METH_O, "EnableFill(Enable)\n\
+Enable or disable filling the shape. Fill is enabled by default.\n\
+ Enable : True to enable, false to disable."},
+ {"EnableOutline", (PyCFunction)PySfShape_EnableOutline, METH_O, "EnableOutline(Enable)\n\
+Enable or disable drawing the shape outline. Outline is enabled by default.\n\
+ Enable : True to enable, false to disable"},
+ {"AddPoint", (PyCFunction)PySfShape_AddPoint, METH_VARARGS | METH_KEYWORDS, "AddPoint(X, Y, Col=sf.Color.White, OutlineCol=sf.Color.Black)\n\
+Add a point to the shape.\n\
+ X : X coordinate of the point\n\
+ Y : Y coordinate of the point\n\
+ Col : Color of the point (white by default)\n\
+ OutlineCol : Outline color of the point (black by default)."},
+ {"SetOutlineWidth", (PyCFunction)PySfShape_SetOutlineWidth, METH_O, "SetOutlineWidth(Width)\n\
+Change the width of the shape outline.\n\
+ Width : New width (use 0 to remove the outline)."},
+ {"GetOutlineWidth", (PyCFunction)PySfShape_GetOutlineWidth, METH_NOARGS, "GetOutlineWidth()\n\
+Get the width of the shape outline."},
+ {"Line", (PyCFunction)PySfShape_Line, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Line(X0, Y0, X1, Y1, Thickness, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\
Create a shape made of a single line.\n\
- param X0 : X coordinate of the first point.\n param Y0 : Y coordinate of the first point.\n\
- param X1 : X coordinate of the second point.\n param Y1 : Y coordinate of the second point.\n\
- param Thickness : Line thickness.\n param Col : Color used to draw the line\n param Outline : Outline width (0 by default)\n\
- param OutlineCol : Color used to draw the outline (black by default)."},
- {"Rectangle", (PyCFunction)PySfShape_Rectangle, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Rectangle(X0, Y0, X1, Y1, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\n\
+ X0 : X coordinate of the first point.\n\
+ Y0 : Y coordinate of the first point.\n\
+ X1 : X coordinate of the second point.\n\
+ Y1 : Y coordinate of the second point.\n\
+ Thickness : Line thickness.\n\
+ Col : Color used to draw the line\n\
+ Outline : Outline width (0 by default)\n\
+ OutlineCol : Color used to draw the outline (black by default)."},
+ {"Rectangle", (PyCFunction)PySfShape_Rectangle, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Rectangle(X0, Y0, X1, Y1, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\
Create a shape made of a single rectangle.\n\
- param X0 : X coordinate of the first point.\n param Y0 : Y coordinate of the first point.\n\
- param X1 : X coordinate of the second point.\n param Y1 : Y coordinate of the second point.\n\
- param Col : Color used to fill the rectangle.\n param Outline : Outline width (0 by default).\n\
- param OutlineCol : Color used to draw the outline (black by default)."},
- {"Circle", (PyCFunction)PySfShape_Circle, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Circle(X, Y, Radius, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\n\
+ X0 : X coordinate of the first point.\n\
+ Y0 : Y coordinate of the first point.\n\
+ X1 : X coordinate of the second point.\n\
+ Y1 : Y coordinate of the second point.\n\
+ Col : Color used to fill the rectangle.\n\
+ Outline : Outline width (0 by default).\n\
+ OutlineCol : Color used to draw the outline (black by default)."},
+ {"Circle", (PyCFunction)PySfShape_Circle, METH_STATIC | METH_VARARGS | METH_KEYWORDS, "Circle(X, Y, Radius, Col, Outline = 0., OutlineCol = sf.Color(0, 0, 0))\n\
Create a shape made of a single circle.\n\
- param X : X coordinate of the center.\n param Y : Y coordinate of the center.\n param Radius : Radius\n\
- param Col : Color used to fill the rectangle.\n param Outline : Outline width (0 by default).\n\
- param OutlineCol : Color used to draw the outline (black by default)."},
+ X : X coordinate of the center.\n\
+ Y : Y coordinate of the center.\n\
+ Radius : Radius\n\
+ Col : Color used to fill the rectangle.\n\
+ Outline : Outline width (0 by default).\n\
+ OutlineCol : Color used to draw the outline (black by default)."},
{NULL} /* Sentinel */
};
@@ -242,7 +367,7 @@ PyTypeObject PySfShapeType = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc.", /* tp_doc */
+ "Shape defines a drawable convex shape ; it also defines helper functions to draw simple shapes like lines, rectangles, circles, etc.\nDefault constructor: Shape()", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
diff --git a/python/src/Shape.hpp b/python/src/Shape.hpp
index 0b7adb2..05bab54 100644
--- a/python/src/Shape.hpp
+++ b/python/src/Shape.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSHAPE_HPP
#define __PYSHAPE_HPP
diff --git a/python/src/Sleep.cpp b/python/src/Sleep.cpp
index b28ae89..303c885 100644
--- a/python/src/Sleep.cpp
+++ b/python/src/Sleep.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Sleep.hpp"
PyObject *
diff --git a/python/src/Sleep.hpp b/python/src/Sleep.hpp
index efd7d15..ad2b7e0 100644
--- a/python/src/Sleep.hpp
+++ b/python/src/Sleep.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSLEEP_HPP
#define __PYSLEEP_HPP
diff --git a/python/src/Sound.cpp b/python/src/Sound.cpp
index 7319951..d755d44 100644
--- a/python/src/Sound.cpp
+++ b/python/src/Sound.cpp
@@ -1,16 +1,33 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Sound.hpp"
#include "SoundBuffer.hpp"
extern PyTypeObject PySfSoundBufferType;
-typedef struct {
- PyObject_HEAD
- sf::Sound *obj;
-} PySfSound;
-
-
-
static PyMemberDef PySfSound_members[] = {
{NULL} /* Sentinel */
};
@@ -38,29 +55,7 @@ PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
-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);
-
- char *kwlist[] = {"Buffer", "Loop", "Pitch", "Volume", "X", "Y", "Z", NULL};
- PySfSoundBuffer *BufferTmp=NULL;
- sf::SoundBuffer *Buffer=NULL;
- bool Loop=false;
- PyObject *LoopObj=Py_False;
- float Pitch=1.f, Volume=100.f, X=0.f, Y=0.f, Z=0.f;
- if ( !PyArg_ParseTupleAndKeywords(args, kwds, "|O!Offfff", kwlist, &PySfSoundBufferType, &BufferTmp, &LoopObj, &Pitch, &Volume, &X, &Y, &Z))
- return -1;
-
- if (LoopObj == Py_True)
- Loop = true;
-
- if (BufferTmp != NULL)
- Buffer = BufferTmp->obj;
-
- self->obj = new sf::Sound(*Buffer, Loop, Pitch, Volume, sf::Vector3f(X, Y, Z));
-
- return 0;
-}
+PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds);
static PyObject*
PySfSound_SetBuffer(PySfSound *self, PyObject *args)
@@ -77,7 +72,7 @@ PySfSound_SetBuffer(PySfSound *self, PyObject *args)
static PyObject*
PySfSound_SetLoop(PySfSound *self, PyObject *args)
{
- if (args == Py_True)
+ if (PyObject_IsTrue(args))
self->obj->SetLoop(true);
else
self->obj->SetLoop(false);
@@ -196,7 +191,7 @@ PySfSound_SetPosition(PySfSound *self, PyObject *args)
}
static PyObject *
-PySfSound_GetBuffer(PySfSound *self, PyObject *args)
+PySfSound_GetBuffer(PySfSound *self)
{
PySfSoundBuffer *Buffer;
@@ -206,26 +201,34 @@ PySfSound_GetBuffer(PySfSound *self, PyObject *args)
return (PyObject *)Buffer;
}
+static PyObject*
+PySfSound_SetPlayingOffset(PySfSound *self, PyObject *args)
+{
+ self->obj->SetPlayingOffset(PyFloat_AsDouble(args));
+ Py_RETURN_NONE;
+}
+
static PyMethodDef PySfSound_methods[] = {
- {"SetLoop", (PyCFunction)PySfSound_SetLoop, METH_O, "Set the Sound loop state."},
- {"SetBuffer", (PyCFunction)PySfSound_SetBuffer, METH_O, "Set the source buffer."},
- {"SetPitch", (PyCFunction)PySfSound_SetPitch, METH_O, "Set the sound pitch."},
- {"SetMinDistance", (PyCFunction)PySfSound_SetMinDistance, METH_O, "Set the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume. The default minimum distance is 1.0."},
- {"SetAttenuation", (PyCFunction)PySfSound_SetAttenuation, METH_O, "Set the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener. The default attenuation factor 1.0."},
- {"SetVolume", (PyCFunction)PySfSound_SetVolume, METH_O, "Set the sound volume."},
- {"SetPosition", (PyCFunction)PySfSound_SetPosition, METH_VARARGS, "Set the sound position in the world."},
- {"GetLoop", (PyCFunction)PySfSound_GetLoop, METH_NOARGS, "Tell whether or not the Sound is looping."},
- {"GetBuffer", (PyCFunction)PySfSound_GetBuffer, METH_O, "Get the source buffer. Returns a new sfSoundBuffer object."},
- {"GetPitch", (PyCFunction)PySfSound_GetPitch, METH_NOARGS, "Get the sound pitch."},
- {"GetMinDistance", (PyCFunction)PySfSound_GetMinDistance, METH_NOARGS, "Get the minimum distance."},
- {"GetAttenuation", (PyCFunction)PySfSound_GetAttenuation, METH_NOARGS, "Get the attenuation factor."},
- {"GetVolume", (PyCFunction)PySfSound_GetVolume, METH_NOARGS, "Get the sound volume."},
- {"GetPosition", (PyCFunction)PySfSound_GetPosition, METH_NOARGS, "Get the sound position in the world. Returns a tuple."},
- {"Play", (PyCFunction)PySfSound_Play, METH_NOARGS, "Play the sound."},
- {"Pause", (PyCFunction)PySfSound_Pause, METH_NOARGS, "Pause the sound."},
- {"Stop", (PyCFunction)PySfSound_Stop, METH_NOARGS, "Stop the sound."},
- {"GetStatus", (PyCFunction)PySfSound_GetStatus, METH_NOARGS, "Get the status of the sound (stopped, paused, playing)."},
- {"GetPlayingOffset", (PyCFunction)PySfSound_GetPlayingOffset, METH_NOARGS, "Get the current playing position of the sound."},
+ {"SetPlayingOffset", (PyCFunction)PySfSound_SetPlayingOffset, METH_O, "SetPlayingOffset(TimeOffset)\nSet the current playing position of the sound.\n TimeOffset : New playing position, expressed in seconds"},
+ {"SetLoop", (PyCFunction)PySfSound_SetLoop, METH_O, "SetLoop(Loop)\nSet the Sound loop state.\n Loop : True to play in loop, false to play once"},
+ {"SetBuffer", (PyCFunction)PySfSound_SetBuffer, METH_O, "SetBuffer(Buffer)\nSet the source buffer.\n Buffer : New sound buffer to bind to the sound "},
+ {"SetPitch", (PyCFunction)PySfSound_SetPitch, METH_O, "SetPitch(Pitch)\nSet the sound pitch. The default pitch is 1.\n Pitch : New pitch"},
+ {"SetMinDistance", (PyCFunction)PySfSound_SetMinDistance, METH_O, "SetMinDistance(MinDistance)\nSet the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume. The default minimum distance is 1.0.\n MinDistance : New minimum distance for the sound"},
+ {"SetAttenuation", (PyCFunction)PySfSound_SetAttenuation, METH_O, "SetAttenuation(Attenuation)\nSet the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener. The default attenuation factor 1.0.\n Attenuation : New attenuation factor for the sound"},
+ {"SetVolume", (PyCFunction)PySfSound_SetVolume, METH_O, "SetVolume(Volume)\nSet the sound volume.\n Volume : Volume (in range [0, 100])"},
+ {"SetPosition", (PyCFunction)PySfSound_SetPosition, METH_VARARGS, "SetPosition(X, Y, Z)\nSet the sound position in the world.\n X,Y,Z : Position of the sound in the world"},
+ {"GetLoop", (PyCFunction)PySfSound_GetLoop, METH_NOARGS, "GetLoop()\nTell whether or not the Sound is looping."},
+ {"GetBuffer", (PyCFunction)PySfSound_GetBuffer, METH_NOARGS, "GetBuffer()\nGet the source buffer. Returns a new sf.SoundBuffer object."},
+ {"GetPitch", (PyCFunction)PySfSound_GetPitch, METH_NOARGS, "GetPitch()\nGet the sound pitch."},
+ {"GetMinDistance", (PyCFunction)PySfSound_GetMinDistance, METH_NOARGS, "GetMinDistance()\nGet the minimum distance."},
+ {"GetAttenuation", (PyCFunction)PySfSound_GetAttenuation, METH_NOARGS, "GetAttenuation()\nGet the attenuation factor."},
+ {"GetVolume", (PyCFunction)PySfSound_GetVolume, METH_NOARGS, "GetVolume()\nGet the sound volume."},
+ {"GetPosition", (PyCFunction)PySfSound_GetPosition, METH_NOARGS, "GetPosition()\nGet the sound position in the world. Returns a tuple."},
+ {"Play", (PyCFunction)PySfSound_Play, METH_NOARGS, "Play()\nPlay the sound."},
+ {"Pause", (PyCFunction)PySfSound_Pause, METH_NOARGS, "Pause()\nPause the sound."},
+ {"Stop", (PyCFunction)PySfSound_Stop, METH_NOARGS, "Stop()\nStop the sound."},
+ {"GetStatus", (PyCFunction)PySfSound_GetStatus, METH_NOARGS, "GetStatus()\nGet the status of the sound (stopped, paused, playing)."},
+ {"GetPlayingOffset", (PyCFunction)PySfSound_GetPlayingOffset, METH_NOARGS, "GetPlayingOffset()\nGet the current playing position of the sound."},
{NULL} /* Sentinel */
};
@@ -251,15 +254,17 @@ PyTypeObject PySfSoundType = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfSound defines a big sound played using streaming, so usually what we call a Sound :)\n\n\
-Constructor: Sound(Buffer, Loop = false, Pitch = 1., Volume = 100., X = 0., Y = 0., Z = 0.);\n\
- param Buffer : Sound buffer to play (NULL by default)\n\
- param Loop : Loop flag (false by default)\n\
- param Pitch : Value of the pitch (1 by default)\n\
- param Volume : Volume (100 by default)\n\
- param X : X position (0 by default)\n\
- param Y : Y position (0 by default)\n\
- param Z : Z position (0 by default)", /* tp_doc */
+ "sf.Sound defines the properties of a sound such as position, volume, pitch, etc.\n\
+Default constructor : Sound()\n\
+Construct the sound from its parameters : Sound(Buffer, Loop = False, Pitch = 1., Volume = 100., X = 0., Y = 0., Z = 0.);\n\
+ Buffer : Sound buffer to play (None by default)\n\
+ Loop : Loop flag (False by default)\n\
+ Pitch : Value of the pitch (1. by default)\n\
+ Volume : Volume (100. by default)\n\
+ X : X position (0. by default)\n\
+ Y : Y position (0. by default)\n\
+ Z : Z position (0. by default)\n\
+Copy constructor : Sound(Copy) where Copy is a sf.Sound instance.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
@@ -279,6 +284,44 @@ Constructor: Sound(Buffer, Loop = false, Pitch = 1., Volume = 100., X = 0., Y =
PySfSound_new, /* tp_new */
};
+static int
+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};
+ PySfSoundBuffer *Buffer=NULL;
+ bool Loop=false;
+ PyObject *LoopObj=Py_False;
+ float Pitch=1.f, Volume=100.f, X=0.f, Y=0.f, Z=0.f;
+
+ if (PyTuple_Size(args) == 1)
+ {
+ PySfSound *Copy;
+ if (PyArg_ParseTuple(args, "O!", &PySfSoundType, &Copy))
+ {
+ self->obj = new sf::Sound(*(Copy->obj));
+ return 0;
+ }
+ else
+ PyErr_Clear();
+ }
+ if (PyTuple_Size(args) > 0)
+ {
+ if ( !PyArg_ParseTupleAndKeywords(args, kwds, "O!|Offfff", (char **)kwlist, &PySfSoundBufferType, &Buffer, &LoopObj, &Pitch, &Volume, &X, &Y, &Z))
+ return -1;
+
+ if (PyObject_IsTrue(LoopObj))
+ Loop = true;
+
+ self->obj = new sf::Sound(*(Buffer->obj), Loop, Pitch, Volume, sf::Vector3f(X, Y, Z));
+ }
+ else
+ self->obj = new sf::Sound();
+
+ return 0;
+}
+
void
PySfSound_InitConst()
{
diff --git a/python/src/Sound.hpp b/python/src/Sound.hpp
index 51f1891..d0c3823 100644
--- a/python/src/Sound.hpp
+++ b/python/src/Sound.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSOUND_HPP
#define __PYSOUND_HPP
@@ -7,6 +31,11 @@
#include <Python.h>
#include <structmember.h>
+typedef struct {
+ PyObject_HEAD
+ sf::Sound *obj;
+} PySfSound;
+
void
PySfSound_InitConst();
diff --git a/python/src/SoundBuffer.cpp b/python/src/SoundBuffer.cpp
index af51bf7..cf651bd 100644
--- a/python/src/SoundBuffer.cpp
+++ b/python/src/SoundBuffer.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "SoundBuffer.hpp"
@@ -26,13 +50,8 @@ PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
return (PyObject *)self;
}
-
static int
-PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds)
-{
- self->obj = new sf::SoundBuffer();
- return 0;
-}
+PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds);
static PyObject*
PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args)
@@ -44,73 +63,31 @@ PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args)
Py_RETURN_FALSE;
}
-static PyObject*
-PySfSoundBuffer_LoadFromString(PySfSoundBuffer *self, PyObject *args)
-{
- char *Data = PyString_AsString(args);
- std::size_t SizeInBytes = PyString_Size(args);
- std::cout << SizeInBytes << "\n";
- if (self->obj->LoadFromMemory(Data, SizeInBytes))
- Py_RETURN_TRUE;
- else
- Py_RETURN_FALSE;
-}
-
-static PyObject*
-PySfSoundBuffer_LoadFromPtr(PySfSoundBuffer *self, PyObject *args)
+static PyObject *
+PySfSoundBuffer_LoadFromMemory(PySfSoundBuffer* self, PyObject *args)
{
- PyObject *DataTmp;
+ unsigned int SizeInBytes;
char *Data;
- std::size_t SizeInBytes = 0;
-
- if (! PyArg_ParseTuple(args, "OI", &DataTmp, &SizeInBytes))
- return NULL;
- if (!PyCObject_Check(DataTmp))
- return NULL;
+ if (! PyArg_ParseTuple(args, "s#", &Data, &SizeInBytes))
+ return NULL;
- Data = (char *)PyCObject_AsVoidPtr(DataTmp);
- if (self->obj->LoadFromMemory(Data, SizeInBytes))
+ if (self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
}
-// bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);
-
-static PyObject*
-PySfSoundBuffer_LoadFromSamples(PySfSoundBuffer *self, PyObject *args)
+static PyObject *
+PySfSoundBuffer_LoadFromSamples(PySfSoundBuffer* self, PyObject *args)
{
- // bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate);
- // Py_ssize_t (*readbufferproc) (PyObject *self, Py_ssize_t segment, void **ptrptr)
-/*
- char *Samples;
- PyObject *SamplesObj;
- std::size_t SamplesCount;
- unsigned int ChannelsCount, SampleRate;
- if (! PyArg_ParseTuple(args, "OIII", &SamplesObj, &SamplesCount, &ChannelsCount, &SampleRate))
- return NULL;
- readbufferproc(SamplesObj, 0, &Samples);
- if (self->obj->LoadFromSamples((const short*)Samples, SamplesCount, ChannelsCount, SampleRate))
- Py_RETURN_TRUE;
- else
- Py_RETURN_FALSE;
-*/
-
- PyErr_SetString(PyExc_NotImplementedError, "LoadFromSamples not implemented yet. However you can try to use LoadFromSamplesString by converting your sound samples to a string. If it is an array, use its tostring() method.");
- Py_RETURN_NONE;
-}
+ unsigned int SizeInBytes, ChannelsCount, SampleRate;
+ char *Data;
-static PyObject*
-PySfSoundBuffer_LoadFromSamplesString(PySfSoundBuffer *self, PyObject *args)
-{
- // bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate);
- char *Samples;
- std::size_t SamplesCount;
- unsigned int ChannelsCount, SampleRate;
- if (! PyArg_ParseTuple(args, "wIII", &Samples, &SamplesCount, &ChannelsCount, &SampleRate))
+ if (! PyArg_ParseTuple(args, "s#II", &Data, &SizeInBytes, &ChannelsCount, &SampleRate))
return NULL;
- if (self->obj->LoadFromSamples((const short*)Samples, SamplesCount, ChannelsCount, SampleRate))
+
+ if (self->obj->LoadFromSamples((const sf::Int16*)Data, (std::size_t) SizeInBytes/2, ChannelsCount, SampleRate))
Py_RETURN_TRUE;
else
Py_RETURN_FALSE;
@@ -119,13 +96,7 @@ PySfSoundBuffer_LoadFromSamplesString(PySfSoundBuffer *self, PyObject *args)
static PyObject*
PySfSoundBuffer_GetSamples(PySfSoundBuffer *self)
{
- return PyCObject_FromVoidPtr((void *)(self->obj->GetSamples()), NULL);
-}
-
-static PyObject*
-PySfSoundBuffer_GetSamplesString(PySfSoundBuffer *self)
-{
- return PyString_FromString((const char *)(self->obj->GetSamples()));
+ return PyString_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2);
}
static PyObject*
@@ -164,63 +135,81 @@ PySfSoundBuffer_GetSamplesCount(PySfSoundBuffer *self)
static PyMethodDef PySfSoundBuffer_methods[] = {
- {"LoadFromFile", (PyCFunction)PySfSoundBuffer_LoadFromFile, METH_O, "Load the sound buffer from a file."},
- {"SaveToFile", (PyCFunction)PySfSoundBuffer_SaveToFile, METH_O, "Save the sound buffer to a file."},
- {"LoadFromPtr", (PyCFunction)PySfSoundBuffer_LoadFromPtr, METH_VARARGS, "Load the sound buffer from a C pointer."},
- {"LoadFromString", (PyCFunction)PySfSoundBuffer_LoadFromString, METH_O, "Load the sound buffer from a string in memory. Takes only one parameter: the string."},
- {"LoadFromSamples", (PyCFunction)PySfSoundBuffer_LoadFromSamples, METH_VARARGS, "Load the sound buffer from an array of samples - assumed format for samples is 16 bits signed integer."},
- {"LoadFromSamplesString", (PyCFunction)PySfSoundBuffer_LoadFromSamplesString, METH_VARARGS, "Load the sound buffer from an array of samples - assumed format for samples is 16 bits signed integer. The samples must be converted to a string."},
- {"GetDuration", (PyCFunction)PySfSoundBuffer_GetDuration, METH_NOARGS, "Get the sound duration."},
- {"GetChannelsCount", (PyCFunction)PySfSoundBuffer_GetChannelsCount, METH_NOARGS, "Return the number of channels (1 = mono, 2 = stereo)."},
- {"GetSampleRate", (PyCFunction)PySfSoundBuffer_GetSampleRate, METH_NOARGS, "Get the sound frequency (sample rate)."},
- {"GetSamplesCount", (PyCFunction)PySfSoundBuffer_GetSamplesCount, METH_NOARGS, "Return the samples count."},
- {"GetSamples", (PyCFunction)PySfSoundBuffer_GetSamples, METH_NOARGS, "Return the sound samples as a C pointer."},
- {"GetSamplesString", (PyCFunction)PySfSoundBuffer_GetSamplesString, METH_NOARGS, "Return the sound samples as a string."},
+ {"LoadFromFile", (PyCFunction)PySfSoundBuffer_LoadFromFile, METH_O, "LoadFromFile(FileName)\nLoad the sound buffer from a file. Returns True if loading has been successful.\n Filename : Path of the sound file to load"},
+ {"SaveToFile", (PyCFunction)PySfSoundBuffer_SaveToFile, METH_O, "SaveToFile(Filename)\nSave the sound buffer to a file. Returns True if saving has been successful.\n Filename : Path of the sound file to write"},
+ {"LoadFromMemory", (PyCFunction)PySfSoundBuffer_LoadFromMemory, METH_O, "LoadFromMemory(Data)\nLoad the sound buffer from a string in memory.\n Data : string representing the file data in memory "},
+ {"LoadFromSamples", (PyCFunction)PySfSoundBuffer_LoadFromSamples, METH_VARARGS, "LoadFromSamples(Samples, ChannelsCount, SampleRate)\nLoad the sound buffer from an array of samples - assumed format for samples is 16 bits signed integer.\n\
+ Samples : Pointer to the samples in memory\n\
+ ChannelsCount : Number of channels (1 = mono, 2 = stereo, ...)\n\
+ SampleRate : Frequency (number of samples to play per second)"},
+ {"GetDuration", (PyCFunction)PySfSoundBuffer_GetDuration, METH_NOARGS, "GetDuration()\nGet the sound duration."},
+ {"GetChannelsCount", (PyCFunction)PySfSoundBuffer_GetChannelsCount, METH_NOARGS, "GetChannelsCount()\nReturn the number of channels (1 = mono, 2 = stereo)."},
+ {"GetSampleRate", (PyCFunction)PySfSoundBuffer_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sound frequency (sample rate)."},
+ {"GetSamplesCount", (PyCFunction)PySfSoundBuffer_GetSamplesCount, METH_NOARGS, "GetSamplesCount()\nReturn the samples count."},
+ {"GetSamples", (PyCFunction)PySfSoundBuffer_GetSamples, METH_NOARGS, "GetSamples()\nReturn the sound samples as a string."},
{NULL} /* Sentinel */
};
PyTypeObject PySfSoundBufferType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "SoundBuffer", /*tp_name*/
- sizeof(PySfSoundBuffer), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "SoundBuffer", /*tp_name*/
+ sizeof(PySfSoundBuffer), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfSoundBuffer_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfSoundBuffer defines a big sound played using streaming, so usually what we call a SoundBuffer :)", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfSoundBuffer_methods, /* tp_methods */
- PySfSoundBuffer_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfSoundBuffer_init, /* tp_init */
- 0, /* tp_alloc */
- PySfSoundBuffer_new, /* tp_new */
+ "sf.SoundBuffer is the low-level for loading and manipulating sound buffers.\n\
+Default constructor : SoundBuffer()\n\
+Copy constructor : SoundBuffer(Copy) where Copy is a sf.SoundBuffer instance.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfSoundBuffer_methods, /* tp_methods */
+ PySfSoundBuffer_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfSoundBuffer_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfSoundBuffer_new, /* tp_new */
};
+static int
+PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds)
+{
+ if (PyTuple_Size(args) == 1)
+ {
+ PySfSoundBuffer *Copy;
+ if (PyArg_ParseTuple(args, "O!", &PySfSoundBufferType, &Copy))
+ self->obj = new sf::SoundBuffer(*(Copy->obj));
+ else
+ return -1;
+ }
+ else
+ self->obj = new sf::SoundBuffer();
+ return 0;
+}
+
PySfSoundBuffer *
GetNewPySfSoundBuffer()
{
diff --git a/python/src/SoundBuffer.hpp b/python/src/SoundBuffer.hpp
index 47e76aa..2420bf9 100644
--- a/python/src/SoundBuffer.hpp
+++ b/python/src/SoundBuffer.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSOUNDBUFFER_HPP
#define __PYSOUNDBUFFER_HPP
diff --git a/python/src/SoundBufferRecorder.cpp b/python/src/SoundBufferRecorder.cpp
index 2c75411..37d87e8 100644
--- a/python/src/SoundBufferRecorder.cpp
+++ b/python/src/SoundBufferRecorder.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "SoundBufferRecorder.hpp"
#include "SoundBuffer.hpp"
@@ -48,50 +72,50 @@ PySfSoundBufferRecorder_GetBuffer(PySfSoundBufferRecorder* self)
static PyMethodDef PySfSoundBufferRecorder_methods[] = {
- {"GetBuffer", (PyCFunction)PySfSoundBufferRecorder_GetBuffer, METH_NOARGS, "Get the sound buffer containing the captured audio data. Returns a SoundBuffer object."},
+ {"GetBuffer", (PyCFunction)PySfSoundBufferRecorder_GetBuffer, METH_NOARGS, "GetBuffer()\nGet the sound buffer containing the captured audio data. Returns a SoundBuffer object. Returns a sf.SoundBuffer instance."},
{NULL} /* Sentinel */
};
PyTypeObject PySfSoundBufferRecorderType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "SoundBufferRecorder", /*tp_name*/
- sizeof(PySfSoundBufferRecorder), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "SoundBufferRecorder", /*tp_name*/
+ sizeof(PySfSoundBufferRecorder), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfSoundBufferRecorder_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "Specialized SoundRecorder which saves the captured audio data into a sound buffer.", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfSoundBufferRecorder_methods, /* tp_methods */
- PySfSoundBufferRecorder_members, /* tp_members */
- 0, /* tp_getset */
- &PySfSoundRecorderType, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfSoundBufferRecorder_init, /* tp_init */
- 0, /* tp_alloc */
- PySfSoundBufferRecorder_new, /* tp_new */
+ "Specialized SoundRecorder which saves the captured audio data into a sound buffer.", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfSoundBufferRecorder_methods, /* tp_methods */
+ PySfSoundBufferRecorder_members, /* tp_members */
+ 0, /* tp_getset */
+ &PySfSoundRecorderType, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfSoundBufferRecorder_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfSoundBufferRecorder_new, /* tp_new */
};
diff --git a/python/src/SoundBufferRecorder.hpp b/python/src/SoundBufferRecorder.hpp
index 7bc9d37..9662432 100644
--- a/python/src/SoundBufferRecorder.hpp
+++ b/python/src/SoundBufferRecorder.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSOUNDBUFFERRECORDER_HPP
#define __PYSOUNDBUFFERRECORDER_HPP
diff --git a/python/src/SoundRecorder.cpp b/python/src/SoundRecorder.cpp
index 553440b..887c027 100644
--- a/python/src/SoundRecorder.cpp
+++ b/python/src/SoundRecorder.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "SoundRecorder.hpp"
@@ -7,6 +31,31 @@ static PyMemberDef PySfSoundRecorder_members[] = {
};
+bool CustomSoundRecorder::OnStart()
+{
+ if (PyObject_HasAttrString(SoundRecorder, "OnStart"))
+ if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnStart"), NULL)))
+ return true;
+ return false;
+}
+
+bool CustomSoundRecorder::OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount)
+{
+ if (PyObject_HasAttrString(SoundRecorder, "OnGetData"))
+ {
+ if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnGetData"), (char *)"#s", (char *)Samples, SamplesCount*2)))
+ {
+ return true;
+ }
+ }
+ return false;
+}
+
+void CustomSoundRecorder::OnStop()
+{
+ if (PyObject_HasAttrString(SoundRecorder, "OnStop"))
+ PyObject_CallFunction(PyObject_GetAttrString(SoundRecorder, "OnStop"), NULL);
+}
static void
PySfSoundRecorder_dealloc(PySfSoundRecorder* self)
@@ -24,33 +73,16 @@ PySfSoundRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
if (self != NULL)
{
- self->Callback = NULL;
}
return (PyObject *)self;
}
-static bool
-PySfSoundRecorder_Callback(const short int *Samples, std::size_t SamplesCount, void *Data)
-{
- PySfSoundRecorder *self = (PySfSoundRecorder *)Data;
- if (PyObject_CallFunction(self->Callback, "s#O", (char *)Samples, SamplesCount*2, self->UserData) == Py_True)
- return true;
- else
- return false;
-}
-
static int
PySfSoundRecorder_init(PySfSoundRecorder *self, PyObject *args)
{
- PyObject *Callback, *UserData=NULL;
- if (! PyArg_ParseTuple(args, "O|O", &Callback, &UserData))
- return -1;
-
- self->Callback = Callback;
- self->UserData = UserData;
- self->obj = new sf::SoundRecorder(&PySfSoundRecorder_Callback, (void *)self);
-
+ self->obj = new CustomSoundRecorder();
+ self->obj->SoundRecorder = (PyObject *)self;
return 0;
}
@@ -87,57 +119,56 @@ PySfSoundRecorder_CanCapture(PySfSoundRecorder* self)
static PyMethodDef PySfSoundRecorder_methods[] = {
- {"Start", (PyCFunction)PySfSoundRecorder_Start, METH_O, "Start the capture. Warning : only one capture can happen at the same time.\nParam SampleRate : Sound frequency (the more samples, the higher the quality) (44100 by default = CD quality)."},
- {"Stop", (PyCFunction)PySfSoundRecorder_Stop, METH_NOARGS, "Stop the capture."},
- {"GetSampleRate", (PyCFunction)PySfSoundRecorder_GetSampleRate, METH_NOARGS, "Get the sample rate. Returns the frequency, in samples per second."},
- {"CanCapture", (PyCFunction)PySfSoundRecorder_CanCapture, METH_STATIC | METH_NOARGS, "Tell if the system supports sound capture. If not, this class won't be usable.\n Returns True if audio capture is supported."},
+ {"Start", (PyCFunction)PySfSoundRecorder_Start, METH_O, "Start(SampleRate=44100)\nStart the capture. Warning : only one capture can happen at the same time.\n SampleRate : Sound frequency (the more samples, the higher the quality) (44100 by default = CD quality)."},
+ {"Stop", (PyCFunction)PySfSoundRecorder_Stop, METH_NOARGS, "Stop()\nStop the capture."},
+ {"GetSampleRate", (PyCFunction)PySfSoundRecorder_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sample rate. Returns the frequency, in samples per second."},
+ {"CanCapture", (PyCFunction)PySfSoundRecorder_CanCapture, METH_STATIC | METH_NOARGS, "CanCapture()\nTell if the system supports sound capture. If not, this class won't be usable. Returns True if audio capture is supported."},
{NULL} /* Sentinel */
};
PyTypeObject PySfSoundRecorderType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "SoundRecorder", /*tp_name*/
- sizeof(PySfSoundRecorder), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "SoundRecorder", /*tp_name*/
+ sizeof(PySfSoundRecorder), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfSoundRecorder_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "SoundRecorder is an interface for capturing sound data, it is meant to be used as a base class.\n\n\
-Initialisation function: SoundRecorder(Callback, UserData)\n\
-Construct the sound recorder with a callback function for processing captured samples.\n\
-Callback : Callback function for processing captured samples. This function must take two parameters: the first one is a string containing captured samples, the second one is UserData.\n\
-UserData : Data to pass to the callback function (None by default).\n", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfSoundRecorder_methods, /* tp_methods */
- PySfSoundRecorder_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfSoundRecorder_init, /* tp_init */
- 0, /* tp_alloc */
- PySfSoundRecorder_new, /* tp_new */
+ "SoundRecorder is an interface for capturing sound data, it is meant to be used as a base class.\n\
+Construct the sound recorder with a callback function for processing captured samples : SoundRecorder(Callback, UserData)\n\
+ Callback : Callback function for processing captured samples. This function must take two parameters: the first one is a string containing captured samples, the second one is UserData.\n\
+ UserData : Data to pass to the callback function (None by default).", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfSoundRecorder_methods, /* tp_methods */
+ PySfSoundRecorder_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfSoundRecorder_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfSoundRecorder_new, /* tp_new */
};
diff --git a/python/src/SoundRecorder.hpp b/python/src/SoundRecorder.hpp
index f9fc597..356262d 100644
--- a/python/src/SoundRecorder.hpp
+++ b/python/src/SoundRecorder.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSOUNDRECORDER_HPP
#define __PYSOUNDRECORDER_HPP
@@ -9,12 +33,18 @@
#include "offsetof.hpp"
+class CustomSoundRecorder : public sf::SoundRecorder
+{
+public :
+ PyObject *SoundRecorder;
+ virtual bool OnStart();
+ virtual bool OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount);
+ virtual void OnStop();
+};
typedef struct {
PyObject_HEAD
- sf::SoundRecorder *obj;
- PyObject *Callback;
- PyObject *UserData;
+ CustomSoundRecorder *obj;
} PySfSoundRecorder;
#endif
diff --git a/python/src/SoundStream.cpp b/python/src/SoundStream.cpp
new file mode 100644
index 0000000..112fea0
--- /dev/null
+++ b/python/src/SoundStream.cpp
@@ -0,0 +1,320 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#include "SoundStream.hpp"
+
+
+bool CustomSoundStream::OnStart()
+{
+ if (PyObject_HasAttrString(SoundStream, "OnStart"))
+ if (PyObject_IsTrue(PyObject_CallFunction(PyObject_GetAttrString(SoundStream, "OnStart"), NULL)))
+ return true;
+ return false;
+}
+
+bool CustomSoundStream::OnGetData(Chunk& Data)
+{
+ if (PyObject_HasAttrString(SoundStream, "OnGetData"))
+ {
+ PyObject *PyData=NULL;
+ if ((PyData = PyObject_CallFunction(PyObject_GetAttrString(SoundStream, "OnGetData"), NULL)))
+ {
+ if (PyArg_Parse(PyData, "s#", &(Data.Samples), &(Data.NbSamples)))
+ {
+ Data.NbSamples /= 2;
+ if (Data.NbSamples > 0)
+ return true;
+ }
+ }
+ }
+ return false;
+}
+
+void CustomSoundStream::Init(unsigned int ChannelsCount, unsigned int SampleRate)
+{
+ Initialize(ChannelsCount, SampleRate);
+}
+
+
+static PyMemberDef PySfSoundStream_members[] = {
+ {NULL} /* Sentinel */
+};
+
+
+static int
+PySfSoundStream_init(PySfSoundStream *self, PyObject *args, PyObject *kwds)
+{
+ self->obj = new CustomSoundStream();
+ self->obj->SoundStream = (PyObject *)self;
+ return 0;
+}
+
+static void
+PySfSoundStream_dealloc(PySfSoundStream *self)
+{
+ delete self->obj;
+ self->ob_type->tp_free((PyObject*)self);
+}
+
+static PyObject *
+PySfSoundStream_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfSoundStream *self;
+ self = (PySfSoundStream *)type->tp_alloc(type, 0);
+ return (PyObject *)self;
+}
+
+static PyObject *
+PySfSoundStream_Initialize(PySfSoundStream *self, PyObject *args)
+{
+ unsigned int ChannelsCount, SampleRate;
+ if (!PyArg_ParseTuple(args, "II", &ChannelsCount, &SampleRate))
+ return NULL;
+ self->obj->Init(ChannelsCount, SampleRate);
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_Play(PySfSoundStream *self)
+{
+ self->obj->Play();
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_Stop(PySfSoundStream *self)
+{
+ self->obj->Stop();
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_GetChannelsCount(PySfSoundStream *self)
+{
+ return PyLong_FromUnsignedLong(self->obj->GetChannelsCount());
+}
+
+static PyObject*
+PySfSoundStream_GetSampleRate(PySfSoundStream *self)
+{
+ return PyLong_FromUnsignedLong(self->obj->GetSampleRate());
+}
+
+static PyObject*
+PySfSoundStream_SetPitch(PySfSoundStream *self, PyObject *args)
+{
+ self->obj->SetPitch(PyFloat_AsDouble(args));
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_SetMinDistance(PySfSoundStream *self, PyObject *args)
+{
+ self->obj->SetMinDistance(PyFloat_AsDouble(args));
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_SetAttenuation(PySfSoundStream *self, PyObject *args)
+{
+ self->obj->SetAttenuation(PyFloat_AsDouble(args));
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_SetVolume(PySfSoundStream *self, PyObject *args)
+{
+ self->obj->SetVolume(PyFloat_AsDouble(args));
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_GetPitch(PySfSoundStream *self)
+{
+ return PyFloat_FromDouble(self->obj->GetPitch());
+}
+
+static PyObject*
+PySfSoundStream_GetMinDistance(PySfSoundStream *self)
+{
+ return PyFloat_FromDouble(self->obj->GetMinDistance());
+}
+
+static PyObject*
+PySfSoundStream_GetAttenuation(PySfSoundStream *self)
+{
+ return PyFloat_FromDouble(self->obj->GetAttenuation());
+}
+
+static PyObject*
+PySfSoundStream_GetVolume(PySfSoundStream *self)
+{
+ return PyFloat_FromDouble(self->obj->GetVolume());
+}
+
+static PyObject*
+PySfSoundStream_GetPosition(PySfSoundStream *self)
+{
+ sf::Vector3f Vect = self->obj->GetPosition();
+ return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
+}
+
+static PyObject*
+PySfSoundStream_Pause(PySfSoundStream *self)
+{
+ self->obj->Pause();
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_SetPosition(PySfSoundStream *self, PyObject *args)
+{
+ float X, Y, Z;
+ if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z))
+ return NULL;
+ self->obj->SetPosition(X, Y, Z);
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_GetStatus(PySfSoundStream *self)
+{
+ return PyLong_FromUnsignedLong(self->obj->GetStatus());
+}
+
+static PyObject*
+PySfSoundStream_SetLoop(PySfSoundStream *self, PyObject *args)
+{
+ if (PyObject_IsTrue(args))
+ self->obj->SetLoop(true);
+ else
+ self->obj->SetLoop(false);
+ Py_RETURN_NONE;
+}
+
+static PyObject*
+PySfSoundStream_GetLoop(PySfSoundStream *self)
+{
+ if (self->obj->GetLoop())
+ Py_RETURN_TRUE;
+ else
+ Py_RETURN_FALSE;
+}
+
+static PyObject*
+PySfSoundStream_GetPlayingOffset(PySfSoundStream *self)
+{
+ return PyFloat_FromDouble(self->obj->GetPlayingOffset());
+}
+
+static PyMethodDef PySfSoundStream_methods[] = {
+ {"Initialize", (PyCFunction)PySfSoundStream_Initialize, METH_VARARGS, "Initialize(ChannelsCount, SampleRate)\n\
+Set the audio stream parameters, you must call it before Play()\n\
+ ChannelsCount : Number of channels\n\
+ SampleRate : Sample rate."},
+ {"Play", (PyCFunction)PySfSoundStream_Play, METH_NOARGS, "Play()\nPlay the sound."},
+ {"Stop", (PyCFunction)PySfSoundStream_Stop, METH_NOARGS, "Stop()\nStop the sound."},
+ {"GetChannelsCount", (PyCFunction)PySfSoundStream_GetChannelsCount, METH_NOARGS, "GetChannelsCount()\nReturn the number of channels (1 = mono, 2 = stereo)."},
+ {"GetSampleRate", (PyCFunction)PySfSoundStream_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sound frequency (sample rate)."},
+ {"GetStatus", (PyCFunction)PySfSoundStream_GetStatus, METH_NOARGS, "GetStatus()\nGet the status of the sound (stopped, paused, playing)."},
+ {"SetLoop", (PyCFunction)PySfSoundStream_SetLoop, METH_O, "SetLoop(Loop)\nSet the music loop state. This parameter is disabled by default\n Loop : True to play in loop, false to play once "},
+ {"GetLoop", (PyCFunction)PySfSoundStream_GetLoop, METH_NOARGS, "GetLoop()\nTell whether or not the music is looping."},
+ {"GetPlayingOffset", (PyCFunction)PySfSoundStream_GetPlayingOffset, METH_NOARGS, "GetPlayingOffset()\nGet the current playing position of the stream."},
+/* The following methods should be inherited from sf.Sound */
+ {"SetPitch", (PyCFunction)PySfSoundStream_SetPitch, METH_O, "SetPitch(Pitch)\nSet the sound pitch. The default pitch is 1.\n Pitch : New pitch"},
+ {"SetMinDistance", (PyCFunction)PySfSoundStream_SetMinDistance, METH_O, "SetMinDistance(MinDistance)\nSet the minimum distance - closer than this distance, the listener will hear the sound at its maximum volume. The default minimum distance is 1.0.\n MinDistance : New minimum distance for the sound"},
+ {"SetAttenuation", (PyCFunction)PySfSoundStream_SetAttenuation, METH_O, "SetAttenuation(Attenuation)\nSet the attenuation factor - the higher the attenuation, the more the sound will be attenuated with distance from listener. The default attenuation factor 1.0.\n Attenuation : New attenuation factor for the sound"},
+ {"SetVolume", (PyCFunction)PySfSoundStream_SetVolume, METH_O, "SetVolume(Volume)\nSet the sound volume.\n Volume : Volume (in range [0, 100])"},
+ {"SetPosition", (PyCFunction)PySfSoundStream_SetPosition, METH_VARARGS, "SetPosition(X, Y, Z)\nSet the sound position in the world.\n X,Y,Z : Position of the sound in the world"},
+ {"GetPitch", (PyCFunction)PySfSoundStream_GetPitch, METH_NOARGS, "GetPitch()\nGet the sound pitch."},
+ {"GetMinDistance", (PyCFunction)PySfSoundStream_GetMinDistance, METH_NOARGS, "GetMinDistance()\nGet the minimum distance."},
+ {"GetAttenuation", (PyCFunction)PySfSoundStream_GetAttenuation, METH_NOARGS, "GetAttenuation()\nGet the attenuation factor."},
+ {"GetVolume", (PyCFunction)PySfSoundStream_GetVolume, METH_NOARGS, "GetVolume()\nGet the sound volume."},
+ {"GetPosition", (PyCFunction)PySfSoundStream_GetPosition, METH_NOARGS, "GetPosition()\nGet the sound position in the world. Returns a tuple."},
+ {"Pause", (PyCFunction)PySfSoundStream_Pause, METH_NOARGS, "Pause()\nPause the sound."},
+ {NULL} /* Sentinel */
+};
+
+
+PyTypeObject PySfSoundStreamType = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "SoundStream", /*tp_name*/
+ sizeof(PySfSoundStream), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ (destructor)PySfSoundStream_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "SoundStream is a streamed sound, ie samples are acquired\
+while the sound is playing. Use it for big sounds that would\
+require hundreds of MB in memory (see Music),\
+or for streaming sound from the network", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfSoundStream_methods, /* tp_methods */
+ PySfSoundStream_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfSoundStream_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfSoundStream_new, /* tp_new */
+};
+
+
+void
+PySfSoundStream_InitConst()
+{
+ PyObject *obj;
+ obj = PyInt_FromLong(sf::SoundStream::Stopped);
+ PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Stopped", obj);
+ Py_DECREF(obj);
+ obj = PyInt_FromLong(sf::SoundStream::Paused);
+ PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Paused", obj);
+ Py_DECREF(obj);
+ obj = PyInt_FromLong(sf::SoundStream::Playing);
+ PyDict_SetItemString(PySfSoundStreamType.tp_dict, "Playing", obj);
+ Py_DECREF(obj);
+}
+
diff --git a/python/src/SoundStream.hpp b/python/src/SoundStream.hpp
new file mode 100644
index 0000000..72ddd35
--- /dev/null
+++ b/python/src/SoundStream.hpp
@@ -0,0 +1,53 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSOUNDSTREAM_HPP
+#define __PYSOUNDSTREAM_HPP
+
+#include <SFML/Audio/SoundStream.hpp>
+#include <iostream>
+
+#include <Python.h>
+#include <structmember.h>
+
+class CustomSoundStream : public sf::SoundStream
+{
+public :
+ PyObject *SoundStream;
+ virtual bool OnStart();
+ virtual bool OnGetData(Chunk& Data);
+ void Init(unsigned int ChannelsCount, unsigned int SampleRate);
+};
+
+
+typedef struct {
+ PyObject_HEAD
+ CustomSoundStream *obj;
+} PySfSoundStream;
+
+void
+PySfSoundStream_InitConst();
+
+#endif
+
diff --git a/python/src/Sprite.cpp b/python/src/Sprite.cpp
index 6763461..c783ccd 100644
--- a/python/src/Sprite.cpp
+++ b/python/src/Sprite.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Sprite.hpp"
@@ -15,7 +39,8 @@ static PyMemberDef PySfSprite_members[] = {
static void
PySfSprite_dealloc(PySfSprite *self)
{
- Py_DECREF(self->Image);
+ if (self->Image != NULL)
+ Py_DECREF(self->Image);
delete self->obj;
self->ob_type->tp_free((PyObject*)self);
}
@@ -39,12 +64,12 @@ PySfSprite_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
PySfSprite_init(PySfSprite *self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"Image", "X", "Y", "ScaleX", "ScaleY", "Rotation", "Color", NULL};
+ const char *kwlist[] = {"Image", "X", "Y", "ScaleX", "ScaleY", "Rotation", "Color", NULL};
float X=0, Y=0, ScaleX=1, ScaleY=1, Rotation=0;
PySfImage *Image=NULL;
PySfColor *Color=NULL;
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!|fffffO!", kwlist, &PySfImageType, &Image, &X, &Y, &ScaleX, &ScaleY, &Rotation, &PySfColorType, &Color))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!|fffffO!", (char **)kwlist, &PySfImageType, &Image, &X, &Y, &ScaleX, &ScaleY, &Rotation, &PySfColorType, &Color))
return -1;
Py_INCREF(Image);
@@ -84,14 +109,13 @@ PySfSprite_GetImage(PySfSprite* self)
}
static PyObject *
-PySfSprite_GetPixel(PySfSprite* self, PyObject *args, PyObject *kwds)
+PySfSprite_GetPixel(PySfSprite* self, PyObject *args)
{
PySfColor *Color;
unsigned int x=0, y=0;
- char *kwlist[] = {"x", "y", NULL};
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "II", kwlist, &x, &y))
+ if (! PyArg_ParseTuple(args, "II", &x, &y))
return NULL;
Color = GetNewPySfColor();
@@ -137,7 +161,7 @@ PySfSprite_SetSubRect(PySfSprite* self, PyObject *args)
PySfIntRect *Rect = (PySfIntRect *)args;
if (! PyObject_TypeCheck(Rect, &PySfIntRectType))
{
- PyErr_SetString(PyExc_TypeError, "Argument is not a sfIntRect");
+ PyErr_SetString(PyExc_TypeError, "Argument is not a sf.IntRect instance");
return NULL;
}
self->obj->SetSubRect(*(Rect->obj));
@@ -147,9 +171,9 @@ PySfSprite_SetSubRect(PySfSprite* self, PyObject *args)
static PyObject *
PySfSprite_FlipX(PySfSprite* self, PyObject *args)
{
- bool Flip = true;
- if (args == Py_False)
- Flip = false;
+ bool Flip = false;
+ if (PyObject_IsTrue(args))
+ Flip = true;
self->obj->FlipX(Flip);
Py_RETURN_NONE;
}
@@ -157,9 +181,9 @@ PySfSprite_FlipX(PySfSprite* self, PyObject *args)
static PyObject *
PySfSprite_FlipY(PySfSprite* self, PyObject *args)
{
- bool Flip = true;
- if (args == Py_False)
- Flip = false;
+ bool Flip = false;
+ if (PyObject_IsTrue(args))
+ Flip = true;
self->obj->FlipY(Flip);
Py_RETURN_NONE;
}
@@ -172,15 +196,17 @@ PySfSprite_GetSize(PySfSprite* self)
}
static PyMethodDef PySfSprite_methods[] = {
- {"SetImage", (PyCFunction)PySfSprite_SetImage, METH_O, "Change the image of the sprite."},
- {"GetImage", (PyCFunction)PySfSprite_GetImage, METH_NOARGS, "Get the source image of the sprite."},
- {"GetSize", (PyCFunction)PySfSprite_GetSize, METH_NOARGS, "Get the sprite's size."},
- {"GetPixel", (PyCFunction)PySfSprite_GetPixel, METH_VARARGS | METH_KEYWORDS, "Get the color of a given pixel in the sprite."},
- {"Resize", (PyCFunction)PySfSprite_Resize, METH_VARARGS, "Resize the object (by changing its scale factors)."},
- {"GetSubRect", (PyCFunction)PySfSprite_GetSubRect, METH_NOARGS, "Get the sub-rectangle of the sprite inside the source image."},
- {"SetSubRect", (PyCFunction)PySfSprite_SetSubRect, METH_O, "Set the sub-rectangle of the sprite inside the source image."},
- {"FlipX", (PyCFunction)PySfSprite_FlipX, METH_O, "Flip the sprite horizontally."},
- {"FlipY", (PyCFunction)PySfSprite_FlipY, METH_O, "Flip the sprite vertically."},
+ {"SetImage", (PyCFunction)PySfSprite_SetImage, METH_O, "SetImage(Image)\nChange the image of the sprite.\n Image : new image (sf.Image instance)"},
+ {"GetImage", (PyCFunction)PySfSprite_GetImage, METH_NOARGS, "GetImage()\nGet the source image of the sprite."},
+ {"GetSize", (PyCFunction)PySfSprite_GetSize, METH_NOARGS, "GetSize()\nGet the sprite's size."},
+ {"GetPixel", (PyCFunction)PySfSprite_GetPixel, METH_VARARGS, "GetPixel()\nGet the color of a given pixel in the sprite."},
+ {"Resize", (PyCFunction)PySfSprite_Resize, METH_VARARGS, "Resize(Width, Height)\nResize the sprite (by changing its scale factors). The default size is defined by the subrect.\n\
+ Width : New width (must be strictly positive)\n\
+ Height : New height (must be strictly positive)"},
+ {"GetSubRect", (PyCFunction)PySfSprite_GetSubRect, METH_NOARGS, "GetSubRect()\nGet the sub-rectangle of the sprite inside the source image."},
+ {"SetSubRect", (PyCFunction)PySfSprite_SetSubRect, METH_O, "SetSubRect(SubRect)\nSet the sub-rectangle of the sprite inside the source image. By default, the subrect covers the entire source image.\n SubRect : New sub-rectangle"},
+ {"FlipX", (PyCFunction)PySfSprite_FlipX, METH_O, "FlipX(Flipped)\nFlip the sprite horizontally.\n Flipped : True to flip the sprite"},
+ {"FlipY", (PyCFunction)PySfSprite_FlipY, METH_O, "FlipY(Flipped)\nFlip the sprite vertically.\n Flipped : True to flip the sprite"},
{NULL} /* Sentinel */
};
diff --git a/python/src/Sprite.hpp b/python/src/Sprite.hpp
index fc93b2a..97cd58b 100644
--- a/python/src/Sprite.hpp
+++ b/python/src/Sprite.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSPRITE_HPP
#define __PYSPRITE_HPP
diff --git a/python/src/String.cpp b/python/src/String.cpp
index d99c8cf..8d2fa7f 100644
--- a/python/src/String.cpp
+++ b/python/src/String.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "String.hpp"
#include "Font.hpp"
#include "Color.hpp"
@@ -40,14 +64,15 @@ PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
static int
PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
{
- char *kwlist[] = {"Text", "Font", "Size", NULL};
+ const char *kwlist[] = {"Text", "Font", "Size", NULL};
float Size = 30.f;
std::string Text = "";
char *TextTmp = NULL;
+ unsigned int TextSize;
PySfFont *FontTmp = NULL;
sf::Font *Font;
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "|sO!f", kwlist, &TextTmp, &PySfFontType, &FontTmp, &Size))
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "|s#O!f", (char **)kwlist, &TextTmp, &TextSize, &PySfFontType, &FontTmp, &Size))
return -1;
if (FontTmp)
@@ -55,10 +80,17 @@ PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
else
Font = (sf::Font *)&(sf::Font::GetDefaultFont());
- if (TextTmp)
- Text.assign(TextTmp);
+ if (TextSize >= 2 && TextTmp)
+ if ((unsigned char)TextTmp[0] == 0xff && (unsigned char)TextTmp[1] == 0xfe)
+ {
+ self->obj = new sf::String(sf::Unicode::Text((const sf::Uint16 *)(TextTmp+2)), *Font, Size);
+ return 0;
+ }
- self->obj = new sf::String(Text, *Font, Size);
+ if (TextTmp != NULL)
+ self->obj = new sf::String(sf::Unicode::Text((const sf::Uint8 *)(TextTmp)), *Font, Size);
+ else
+ self->obj = new sf::String();
return 0;
}
@@ -67,19 +99,20 @@ PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
static PyObject *
PySfString_SetText(PySfString* self, PyObject *args)
{
- self->obj->SetText(PyString_AsString(args));
- Py_RETURN_NONE;
-}
+ char *TextTmp = NULL;
+ int Size;
+ if (!PyArg_Parse(args, "s#", &TextTmp, &Size))
+ return NULL;
-static PyObject *
-PySfString_SetUnicodeText(PySfString* self, PyObject *args)
-{
- std::wstring Text = L"";
- if (PyUnicode_Check(args))
- Text.assign((wchar_t *) PyUnicode_AS_UNICODE(args));
- else
- PyErr_SetString(PyExc_TypeError, "Argument must be an unicode string");
- self->obj->SetText(Text);
+ if (Size >= 2)
+ {
+ if ((unsigned char)TextTmp[0] == 0xff && (unsigned char)TextTmp[1] == 0xfe)
+ {
+ self->obj->SetText(sf::Unicode::Text((const sf::Uint16 *)(TextTmp+2)));
+ Py_RETURN_NONE;
+ }
+ }
+ self->obj->SetText(sf::Unicode::Text((const sf::Uint8 *)(TextTmp)));
Py_RETURN_NONE;
}
@@ -122,14 +155,14 @@ PySfString_GetStyle(PySfString* self)
static PyObject *
PySfString_GetText(PySfString* self)
{
- return PyString_FromString((self->obj->GetText()).c_str());
+ return PyString_FromString((std::string(self->obj->GetText())).c_str());
}
static PyObject *
PySfString_GetFont(PySfString* self)
{
PySfFont *Font = GetNewPySfFont();
- Font->obj = (sf::Font *) (&(self->obj->GetFont()));
+ Font->obj = new sf::Font(self->obj->GetFont());
return (PyObject *)Font;
}
@@ -148,61 +181,71 @@ PySfString_GetRect(PySfString* self)
return (PyObject *)Rect;
}
+static PyObject *
+PySfString_GetCharacterPos(PySfString* self, PyObject *args)
+{
+ sf::Vector2f Pos = self->obj->GetCharacterPos(PyLong_AsUnsignedLong(args));
+ return Py_BuildValue("ff", Pos.x, Pos.y);
+}
+
static PyMethodDef PySfString_methods[] = {
- {"SetText", (PyCFunction)PySfString_SetText, METH_O, "Set the text."},
- {"SetUnicodeText", (PyCFunction)PySfString_SetUnicodeText, METH_O, "Set the text."},
- {"GetText", (PyCFunction)PySfString_GetText, METH_NOARGS, "Get the text."},
- {"SetFont", (PyCFunction)PySfString_SetFont, METH_O, "Set the font of the string."},
- {"GetFont", (PyCFunction)PySfString_GetFont, METH_NOARGS, "Get the font used by the string."},
- {"SetSize", (PyCFunction)PySfString_SetSize, METH_O, "Set the size of the string."},
- {"GetSize", (PyCFunction)PySfString_GetSize, METH_NOARGS, "Get the size of the characters."},
- {"SetStyle", (PyCFunction)PySfString_SetStyle, METH_O, "Set the style of the text. The default style is Regular."},
- {"GetStyle", (PyCFunction)PySfString_GetStyle, METH_NOARGS, "Get the style of the text."},
- {"GetRect", (PyCFunction)PySfString_GetRect, METH_NOARGS, "Get the string rectangle on screen."},
+ {"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\
+ 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"},
+ {"GetText", (PyCFunction)PySfString_GetText, METH_NOARGS, "GetText()\nGet the text."},
+ {"SetFont", (PyCFunction)PySfString_SetFont, METH_O, "SetFont(Font)\nSet the font of the string.\n Font : font to use"},
+ {"GetFont", (PyCFunction)PySfString_GetFont, METH_NOARGS, "GetFont()\nGet the font used by the string."},
+ {"SetSize", (PyCFunction)PySfString_SetSize, METH_O, "SetSize(Size)\nSet the size of the string.\n Size : New size, in pixels"},
+ {"GetSize", (PyCFunction)PySfString_GetSize, METH_NOARGS, "GetSize()\nGet the size of the characters."},
+ {"SetStyle", (PyCFunction)PySfString_SetStyle, METH_O, "SetStyle(TextSize)\nSet the style of the text. The default style is Regular.\n TextSize : New text style, (combination of Style values)"},
+ {"GetStyle", (PyCFunction)PySfString_GetStyle, METH_NOARGS, "GetStyle()\nGet the style of the text."},
+ {"GetRect", (PyCFunction)PySfString_GetRect, METH_NOARGS, "GetRect()\nGet the string rectangle on screen."},
{NULL} /* Sentinel */
};
PyTypeObject PySfStringType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "String", /*tp_name*/
- sizeof(PySfString), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "String", /*tp_name*/
+ sizeof(PySfString), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfString_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfString defines a string : texture, transformations, color, and draw on screen", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfString_methods, /* tp_methods */
- PySfString_members, /* tp_members */
- 0, /* tp_getset */
- &PySfDrawableType, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfString_init, /* tp_init */
- 0, /* tp_alloc */
- PySfString_new, /* tp_new */
+ "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 */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfString_methods, /* tp_methods */
+ PySfString_members, /* tp_members */
+ 0, /* tp_getset */
+ &PySfDrawableType, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfString_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfString_new, /* tp_new */
};
diff --git a/python/src/String.hpp b/python/src/String.hpp
index 9d7f743..312eb4b 100644
--- a/python/src/String.hpp
+++ b/python/src/String.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYSTRING_HPP
#define __PYSTRING_HPP
diff --git a/python/src/VideoMode.cpp b/python/src/VideoMode.cpp
index c70e551..19abe2f 100644
--- a/python/src/VideoMode.cpp
+++ b/python/src/VideoMode.cpp
@@ -1,176 +1,202 @@
-#include "VideoMode.hpp"
-
-
-
-static PyMemberDef PySfVideoMode_members[] = {
- {"Width", T_UINT, offsetof(PySfVideoMode, Width), 0, "Video mode width, in pixels."},
- {"Height", T_UINT, offsetof(PySfVideoMode, Height), 0, "Video mode height, in pixels."},
- {"BitsPerPixel", T_UINT, offsetof(PySfVideoMode, BitsPerPixel), 0, "Video mode pixel depth, in bits per pixels."},
- {NULL} /* Sentinel */
-};
-
-
-
-static void
-PySfVideoMode_dealloc(PySfVideoMode* self)
-{
- delete self->obj;
- self->ob_type->tp_free((PyObject*)self);
-}
-
-static PyObject *
-PySfVideoMode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
-{
- PySfVideoMode *self;
-
- self = (PySfVideoMode *)type->tp_alloc(type, 0);
-
- if (self != NULL)
- {
- self->Width = 0;
- self->Height = 0;
- self->BitsPerPixel = 0;
- }
-
- return (PyObject *)self;
-}
-
-void
-PySfVideoModeUpdate(PySfVideoMode *self)
-{
- self->obj->Width = self->Width;
- self->obj->Height = self->Height;
- self->obj->BitsPerPixel = self->BitsPerPixel;
-}
-
-static int
-PySfVideoMode_init(PySfVideoMode *self, PyObject *args, PyObject *kwds)
-{
- char *kwlist[] = {"Width", "Height", "BitsPerPixel", NULL};
-
- if (! PyArg_ParseTupleAndKeywords(args, kwds, "|III", kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
- return -1;
-
- self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
-
- return 0;
-}
-
-
-
-static PyObject *
-PySfVideoMode_IsValid(PySfVideoMode* self)
-{
- self->obj->Width = self->Width;
- self->obj->Height = self->Height;
- self->obj->BitsPerPixel = self->BitsPerPixel;
- return PyBool_FromLong(self->obj->IsValid());
-}
-
-static PyObject *
-PySfVideoMode_GetDesktopMode(PySfVideoMode* self)
-{
- PySfVideoMode *VideoMode;
-
- VideoMode = GetNewPySfVideoMode();
- VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetDesktopMode() );
- VideoMode->Width = VideoMode->obj->Width;
- VideoMode->Height = VideoMode->obj->Height;
- VideoMode->BitsPerPixel = VideoMode->obj->BitsPerPixel;
-
- return (PyObject *)VideoMode;
-}
-
-static PyObject *
-PySfVideoMode_GetMode(PySfVideoMode* self, PyObject *args)
-{
- std::size_t index;
- PySfVideoMode *VideoMode;
-
- index = (std::size_t)PyInt_AsSsize_t(args);
-
- VideoMode = GetNewPySfVideoMode();
- VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetMode(index) );
- VideoMode->Width = VideoMode->obj->Width;
- VideoMode->Height = VideoMode->obj->Height;
- VideoMode->BitsPerPixel = VideoMode->obj->BitsPerPixel;
-
- return (PyObject *)VideoMode;
-}
-
-static PyObject *
-PySfVideoMode_GetModesCount(PySfVideoMode* self)
-{
- return PyInt_FromLong(sf::VideoMode::GetModesCount());
-}
-
-
-
-static PyMethodDef PySfVideoMode_methods[] = {
- {"IsValid", (PyCFunction)PySfVideoMode_IsValid, METH_NOARGS, "Tell whether or not the video mode is supported."},
- {"GetDesktopMode", (PyCFunction)PySfVideoMode_GetDesktopMode, METH_STATIC | METH_NOARGS, "Get the current desktop video mode."},
- {"GetMode", (PyCFunction)PySfVideoMode_GetMode, METH_STATIC | METH_O, "Get a valid video mode Index must be in range [0, GetModesCount()[ Modes are sorted from best to worst."},
- {"GetModesCount", (PyCFunction)PySfVideoMode_GetModesCount, METH_STATIC | METH_NOARGS, "Get valid video modes count."},
- {NULL} /* Sentinel */
-};
-
-int PySfVideoMode_Compare(PyObject *o1, PyObject *o2)
-{
- PySfVideoModeUpdate((PySfVideoMode *)o1);
- PySfVideoModeUpdate((PySfVideoMode *)o2);
- if (((PySfVideoMode *)o1)->obj == ((PySfVideoMode *)o2)->obj)
- return 0;
- else
- return 1;
-}
-
-
-PyTypeObject PySfVideoModeType = {
- PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "VideoMode", /*tp_name*/
- sizeof(PySfVideoMode), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- (destructor)PySfVideoMode_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- PySfVideoMode_Compare, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
- Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfVideoMode defines a video mode (width, height, bpp, frequency) and provides functions for getting modes supported by the display device", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfVideoMode_methods, /* tp_methods */
- PySfVideoMode_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfVideoMode_init, /* tp_init */
- 0, /* tp_alloc */
- PySfVideoMode_new, /* tp_new */
-};
-
-
-PySfVideoMode *
-GetNewPySfVideoMode()
-{
- return PyObject_New(PySfVideoMode, &PySfVideoModeType);
-}
-
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#include "VideoMode.hpp"
+
+
+
+static PyMemberDef PySfVideoMode_members[] = {
+ {(char *)"Width", T_UINT, offsetof(PySfVideoMode, Width), 0, (char *)"Video mode width, in pixels."},
+ {(char *)"Height", T_UINT, offsetof(PySfVideoMode, Height), 0, (char *)"Video mode height, in pixels."},
+ {(char *)"BitsPerPixel", T_UINT, offsetof(PySfVideoMode, BitsPerPixel), 0, (char *)"Video mode pixel depth, in bits per pixels."},
+ {NULL} /* Sentinel */
+};
+
+
+
+static void
+PySfVideoMode_dealloc(PySfVideoMode* self)
+{
+ delete self->obj;
+ self->ob_type->tp_free((PyObject*)self);
+}
+
+static PyObject *
+PySfVideoMode_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
+{
+ PySfVideoMode *self;
+
+ self = (PySfVideoMode *)type->tp_alloc(type, 0);
+
+ if (self != NULL)
+ {
+ self->Width = 0;
+ self->Height = 0;
+ self->BitsPerPixel = 32;
+ }
+
+ return (PyObject *)self;
+}
+
+void
+PySfVideoModeUpdate(PySfVideoMode *self)
+{
+ self->obj->Width = self->Width;
+ self->obj->Height = self->Height;
+ self->obj->BitsPerPixel = self->BitsPerPixel;
+}
+
+static int
+PySfVideoMode_init(PySfVideoMode *self, PyObject *args, PyObject *kwds)
+{
+ const char *kwlist[] = {"Width", "Height", "BitsPerPixel", NULL};
+
+ if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|I", (char **)kwlist, &self->Width, &self->Height, &self->BitsPerPixel))
+ return -1;
+
+ self->obj = new sf::VideoMode(self->Width, self->Height, self->BitsPerPixel);
+
+ return 0;
+}
+
+
+
+static PyObject *
+PySfVideoMode_IsValid(PySfVideoMode* self)
+{
+ self->obj->Width = self->Width;
+ self->obj->Height = self->Height;
+ self->obj->BitsPerPixel = self->BitsPerPixel;
+ return PyBool_FromLong(self->obj->IsValid());
+}
+
+static PyObject *
+PySfVideoMode_GetDesktopMode(PySfVideoMode* self)
+{
+ PySfVideoMode *VideoMode;
+
+ VideoMode = GetNewPySfVideoMode();
+ VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetDesktopMode() );
+ VideoMode->Width = VideoMode->obj->Width;
+ VideoMode->Height = VideoMode->obj->Height;
+ VideoMode->BitsPerPixel = VideoMode->obj->BitsPerPixel;
+
+ return (PyObject *)VideoMode;
+}
+
+static PyObject *
+PySfVideoMode_GetMode(PySfVideoMode* self, PyObject *args)
+{
+ std::size_t index;
+ PySfVideoMode *VideoMode;
+
+ index = (std::size_t)PyInt_AsLong(args);
+
+ VideoMode = GetNewPySfVideoMode();
+ VideoMode->obj = new sf::VideoMode ( sf::VideoMode::GetMode(index) );
+ VideoMode->Width = VideoMode->obj->Width;
+ VideoMode->Height = VideoMode->obj->Height;
+ VideoMode->BitsPerPixel = VideoMode->obj->BitsPerPixel;
+
+ return (PyObject *)VideoMode;
+}
+
+static PyObject *
+PySfVideoMode_GetModesCount(PySfVideoMode* self)
+{
+ return PyInt_FromLong(sf::VideoMode::GetModesCount());
+}
+
+
+
+static PyMethodDef PySfVideoMode_methods[] = {
+ {"IsValid", (PyCFunction)PySfVideoMode_IsValid, METH_NOARGS, "IsValid()\nTell whether or not the video mode is supported."},
+ {"GetDesktopMode", (PyCFunction)PySfVideoMode_GetDesktopMode, METH_STATIC | METH_NOARGS, "GetDesktopMode()\nGet the current desktop video mode."},
+ {"GetMode", (PyCFunction)PySfVideoMode_GetMode, METH_STATIC | METH_O, "GetMode(Index)\nGet a valid video mode. Index must be in range [0, GetModesCount()[ Modes are sorted from best to worst.\n Index : Index of video mode to get"},
+ {"GetModesCount", (PyCFunction)PySfVideoMode_GetModesCount, METH_STATIC | METH_NOARGS, "GetModesCount()\nGet valid video modes count."},
+ {NULL} /* Sentinel */
+};
+
+int PySfVideoMode_Compare(PyObject *o1, PyObject *o2)
+{
+ PySfVideoModeUpdate((PySfVideoMode *)o1);
+ PySfVideoModeUpdate((PySfVideoMode *)o2);
+ if (*(((PySfVideoMode *)o1)->obj) == *(((PySfVideoMode *)o2)->obj))
+ return 0;
+ else
+ return 1;
+}
+
+
+PyTypeObject PySfVideoModeType = {
+ PyObject_HEAD_INIT(NULL)
+ 0, /*ob_size*/
+ "VideoMode", /*tp_name*/
+ sizeof(PySfVideoMode), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ (destructor)PySfVideoMode_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ PySfVideoMode_Compare, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
+ Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
+ "sf.VideoMode defines a video mode (width, height, bpp, frequency) and provides functions for getting modes supported by the display device\n\
+Default constructor : VideoMode()\n\
+Construct the video mode with its attributes : VideoMode(ModeWidth, ModeHeight, ModeBpp = 32)\n ModeWidth : Width in pixels\n ModeHeight : Height in pixels\n ModeBpp : Pixel depths in bits per pixel (32 by default)", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfVideoMode_methods, /* tp_methods */
+ PySfVideoMode_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfVideoMode_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfVideoMode_new, /* tp_new */
+};
+
+
+PySfVideoMode *
+GetNewPySfVideoMode()
+{
+ return (PySfVideoMode *)PySfVideoMode_new(&PySfVideoModeType, NULL, NULL);
+}
+
diff --git a/python/src/VideoMode.hpp b/python/src/VideoMode.hpp
index 08039ba..d7a3dec 100644
--- a/python/src/VideoMode.hpp
+++ b/python/src/VideoMode.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYVIDEOMODE_HPP
#define __PYVIDEOMODE_HPP
diff --git a/python/src/View.cpp b/python/src/View.cpp
index bda246b..d2587f0 100644
--- a/python/src/View.cpp
+++ b/python/src/View.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "View.hpp"
extern PyTypeObject PySfFloatRectType;
@@ -108,13 +132,15 @@ PySfView_Zoom(PySfView* self, PyObject *args)
}
static PyMethodDef PySfView_methods[] = {
- {"GetCenter", (PyCFunction)PySfView_GetCenter, METH_NOARGS, "Get the center of the view."},
- {"GetHalfSize", (PyCFunction)PySfView_GetHalfSize, METH_NOARGS, "Get the half-size of the view."},
- {"GetRect", (PyCFunction)PySfView_GetRect, METH_NOARGS, "Get the bounding rectangle of the view."},
- {"Move", (PyCFunction)PySfView_Move, METH_VARARGS, "Move the view."},
- {"SetCenter", (PyCFunction)PySfView_SetCenter, METH_VARARGS, "Change the center of the view."},
- {"SetHalfSize", (PyCFunction)PySfView_SetHalfSize, METH_VARARGS, "Change the half-size of the view."},
- {"Zoom", (PyCFunction)PySfView_Zoom, METH_O, "Resize the view rectangle to simulate a zoom / unzoom effect."},
+ {"GetCenter", (PyCFunction)PySfView_GetCenter, METH_NOARGS, "GetCenter()\nGet the center of the view."},
+ {"GetHalfSize", (PyCFunction)PySfView_GetHalfSize, METH_NOARGS, "GetHalfSize()\nGet the half-size of the view."},
+ {"GetRect", (PyCFunction)PySfView_GetRect, METH_NOARGS, "GetRect()\nGet the bounding rectangle of the view."},
+ {"Move", (PyCFunction)PySfView_Move, METH_VARARGS, "Move(OffsetX, OffsetY)\nMove the view.\n\
+ OffsetX : Offset to move the view, on X axis\n\
+ OffsetY : Offset to move the view, on Y axis"},
+ {"SetCenter", (PyCFunction)PySfView_SetCenter, METH_VARARGS, "SetCenter(X, Y)\nChange the center of the view."},
+ {"SetHalfSize", (PyCFunction)PySfView_SetHalfSize, METH_VARARGS, "SetHalfSize(HalfWidth, HalfHeight)\nChange the half-size of the view."},
+ {"Zoom", (PyCFunction)PySfView_Zoom, METH_O, "Zoom(Factor)\nResize the view rectangle to simulate a zoom / unzoom effect."},
{NULL} /* Sentinel */
};
@@ -163,6 +189,6 @@ PyTypeObject PySfViewType = {
PySfView *
GetNewPySfView()
{
- return PyObject_New(PySfView, &PySfViewType);
+ return (PySfView *)PySfView_new(&PySfViewType, NULL, NULL);
}
diff --git a/python/src/View.hpp b/python/src/View.hpp
index 0d23f56..af55275 100644
--- a/python/src/View.hpp
+++ b/python/src/View.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYVIEW_HPP
#define __PYVIEW_HPP
diff --git a/python/src/Window.cpp b/python/src/Window.cpp
index c26225d..1f4b17f 100644
--- a/python/src/Window.cpp
+++ b/python/src/Window.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "Window.hpp"
#include "SFML/Window/WindowStyle.hpp"
@@ -24,12 +48,13 @@ PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
self = (PySfWindow *)type->tp_alloc(type, 0);
if (self != NULL)
- {
- self->Settings = GetNewPySfWindowSettings();
+ {
}
return (PyObject *)self;
}
+
+
static PyObject*
PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
@@ -47,19 +72,45 @@ PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
PyEvent->Type = PyEvent->obj->Type;
PyEvent->Text->Unicode = PyEvent->obj->Text.Unicode;
PyEvent->Key->Code = PyEvent->obj->Key.Code;
- if (PyEvent->obj->Key.Alt)
- PyEvent->Key->Alt = Py_True;
- else
- PyEvent->Key->Alt = Py_False;
- if (PyEvent->obj->Key.Control)
- PyEvent->Key->Control = Py_True;
- else
- PyEvent->Key->Control = Py_False;
- if (PyEvent->obj->Key.Shift)
- PyEvent->Key->Shift = Py_True;
- else
- PyEvent->Key->Shift = Py_False;
- PyEvent->MouseButton->Button = PyEvent->obj->MouseButton.Button;
+ if (PyEvent->obj->Key.Alt && PyEvent->Key->Alt == Py_False)
+ {
+ Py_DECREF(Py_False);
+ Py_INCREF(Py_True);
+ PyEvent->Key->Alt = Py_True;
+ }
+ 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->X = PyEvent->obj->MouseButton.X;
+ PyEvent->MouseButton->Y = PyEvent->obj->MouseButton.Y;
PyEvent->MouseMove->X = PyEvent->obj->MouseMove.X;
PyEvent->MouseMove->Y = PyEvent->obj->MouseMove.Y;
PyEvent->JoyMove->JoystickId = PyEvent->obj->JoyMove.JoystickId;
@@ -78,7 +129,7 @@ PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
-static PyObject*
+PyObject*
PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
{
PyObject *VideoModeTmp=NULL;
@@ -104,7 +155,9 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
{
PySfWindowSettingsUpdate(ParamsTmp);
Params = ParamsTmp->obj;
- }
+ }
+ else
+ Params = new sf::WindowSettings();
self->obj->Create(*VideoMode, Title, WindowStyle, *Params);
@@ -114,8 +167,9 @@ PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds)
static int
PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds)
{
- self->obj = new sf::Window();
- PySfWindow_Create(self, args, kwds);
+ self->obj = new sf::Window();
+ if (PyTuple_Size(args) > 0)
+ PySfWindow_Create(self, args, kwds);
return 0;
}
@@ -148,7 +202,7 @@ static PyObject *
PySfWindow_UseVerticalSync(PySfWindow *self, PyObject *args)
{
bool Enabled = false;
- if (args == Py_True)
+ if (PyObject_IsTrue(args))
Enabled = true;
self->obj->UseVerticalSync(Enabled);
Py_RETURN_NONE;
@@ -157,7 +211,7 @@ static PyObject *
PySfWindow_ShowMouseCursor(PySfWindow *self, PyObject *args)
{
bool Show = false;
- if (args == Py_True)
+ if (PyObject_IsTrue(args))
Show = true;
self->obj->ShowMouseCursor(Show);
Py_RETURN_NONE;
@@ -167,7 +221,7 @@ static PyObject *
PySfWindow_SetActive(PySfWindow *self, PyObject *args)
{
bool Active = false;
- if (args == Py_True)
+ if (PyObject_IsTrue(args))
Active = true;
if (self->obj->SetActive(Active))
Py_RETURN_TRUE;
@@ -228,7 +282,7 @@ PySfWindow_SetFramerateLimit(PySfWindow *self, PyObject *args)
static PyObject *
PySfWindow_Show(PySfWindow *self, PyObject *args)
{
- if (args == Py_True)
+ if (PyObject_IsTrue(args))
self->obj->Show(true);
else
self->obj->Show(false);
@@ -238,7 +292,7 @@ PySfWindow_Show(PySfWindow *self, PyObject *args)
static PyObject *
PySfWindow_EnableKeyRepeat(PySfWindow *self, PyObject *args)
{
- if (args == Py_True)
+ if (PyObject_IsTrue(args))
self->obj->EnableKeyRepeat(true);
else
self->obj->EnableKeyRepeat(false);
@@ -257,84 +311,118 @@ PySfWindow_SetCursorPosition(PySfWindow* self, PyObject *args)
}
static PyObject *
+PySfWindow_SetSize(PySfWindow* self, PyObject *args)
+{
+ unsigned int Width=0, Height=0;
+ if (! PyArg_ParseTuple(args, "II", &Width, &Height))
+ return NULL;
+
+ self->obj->SetSize(Width, Height);
+ Py_RETURN_NONE;
+}
+
+static PyObject *
PySfWindow_SetJoystickThreshold(PySfWindow* self, PyObject *args)
{
self->obj->SetJoystickThreshold(PyFloat_AsDouble(args));
Py_RETURN_NONE;
}
-static PyObject *
-PySfWindow_ForceContextInit(PySfWindow* self, PyObject *args)
-{
- self->obj->ForceContextInit();
- Py_RETURN_NONE;
+static PyObject *
+PySfWindow_SetIcon(PySfWindow* self, PyObject *args)
+{
+ unsigned int Width, Height, Size;
+ char *Data;
+
+ if (! PyArg_ParseTuple(args, "IIs#", &Width, &Height, &Data, &Size))
+ return NULL;
+
+ self->obj->SetIcon(Width, Height, (sf::Uint8*) Data);
+ Py_RETURN_NONE;
}
-
static PyMethodDef PySfWindow_methods[] = {
- {"Close", (PyCFunction)PySfWindow_Close, METH_NOARGS, "Close (destroy) the window. The sf.Window instance remains valid and you can call Create to recreate the window."},
- {"Create", (PyCFunction)PySfWindow_Create, METH_VARARGS | METH_KEYWORDS, "Create a window"},
- {"Display", (PyCFunction)PySfWindow_Display, METH_NOARGS, "Display the window on screen."},
- {"EnableKeyRepeat", (PyCFunction)PySfWindow_EnableKeyRepeat, METH_O, "Activate of deactivate the window as the current target for rendering."},
- {"ForceContextInit", (PyCFunction)PySfWindow_ForceContextInit, METH_NOARGS | METH_STATIC, "Force a valid OpenGL context to exist even if no window has been created."},
- {"GetEvent", (PyCFunction)PySfWindow_GetEvent, METH_O, "Get the event on top of events stack, if any, and pop it."},
- {"GetFrameTime", (PyCFunction)PySfWindow_GetFrameTime, METH_NOARGS, "Get time elapsed since last frame."},
- {"GetHeight", (PyCFunction)PySfWindow_GetHeight, METH_NOARGS, "Get the height of the rendering region of the window."},
- {"GetInput", (PyCFunction)PySfWindow_GetInput, METH_NOARGS, "Get the input manager of the window."},
- {"GetSettings", (PyCFunction)PySfWindow_GetSettings, METH_NOARGS, "Get the creation settings of the window."},
- {"GetWidth", (PyCFunction)PySfWindow_GetWidth, METH_NOARGS, "Get the width of the rendering region of the window."},
- {"IsOpened", (PyCFunction)PySfWindow_IsOpened, METH_NOARGS, "Tell whether or not the window is opened (ie. has been created). Note that a hidden window (Show(false)) will still return true."},
- {"SetActive", (PyCFunction)PySfWindow_SetActive, METH_O, "Activate or deactivate the window as the current target for rendering."},
- {"SetCursorPosition", (PyCFunction)PySfWindow_SetCursorPosition, METH_VARARGS, "Change the position of the mouse cursor."},
- {"SetFramerateLimit", (PyCFunction)PySfWindow_SetFramerateLimit, METH_O, "Set the framerate at a fixed frequency."},
- {"SetJoystickThreshold", (PyCFunction)PySfWindow_SetJoystickThreshold, METH_O, "Change the joystick threshold, ie. the value below which no move event will be generated"},
- {"SetPosition", (PyCFunction)PySfWindow_SetPosition, METH_VARARGS, "Change the position of the window on screen."},
- {"Show", (PyCFunction)PySfWindow_Show, METH_O, "Show or hide the window."},
- {"ShowMouseCursor", (PyCFunction)PySfWindow_ShowMouseCursor, METH_O, "Show or hide the mouse cursor."},
- {"UseVerticalSync", (PyCFunction)PySfWindow_UseVerticalSync, METH_O, "Enable / disable vertical synchronization."},
+ {"Close", (PyCFunction)PySfWindow_Close, METH_NOARGS, "Close()\nClose (destroy) the window. The sf.Window instance remains valid and you can call Create to recreate the window."},
+ {"Create", (PyCFunction)PySfWindow_Create, METH_VARARGS | METH_KEYWORDS, "Create(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.WindowSettings())\n\
+Create a window.\n\
+ Mode : Video mode to use (sf.VideoMode instance)\n\
+ Title : Title of the window\n\
+ WindowStyle : Window style (Resize | Close by default)\n\
+ Params : Creation parameters (see default constructor for default values)\n"},
+ {"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"},
+ {"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."},
+ {"GetFrameTime", (PyCFunction)PySfWindow_GetFrameTime, METH_NOARGS, "GetFrameTime()\nGet time elapsed since last frame. Returns time elapsed, in seconds"},
+ {"GetHeight", (PyCFunction)PySfWindow_GetHeight, METH_NOARGS, "GetHeight()\nGet the height of the rendering region of the window."},
+ {"GetInput", (PyCFunction)PySfWindow_GetInput, METH_NOARGS, "GetInput()\nGet the input manager of the window."},
+ {"GetSettings", (PyCFunction)PySfWindow_GetSettings, METH_NOARGS, "GetSettings()\nGet the creation settings of the window."},
+ {"GetWidth", (PyCFunction)PySfWindow_GetWidth, METH_NOARGS, "GetWidth()\nGet the width of the rendering region of the window."},
+ {"IsOpened", (PyCFunction)PySfWindow_IsOpened, METH_NOARGS, "IsOpened()\nTell whether or not the window is opened (ie. has been created). Note that a hidden window (Show(False)) will still return True."},
+ {"SetActive", (PyCFunction)PySfWindow_SetActive, METH_O, "SetActive(Active)\nActivate of deactivate the window as the current target for rendering. Returns True if operation was successful, False otherwise.\n Active : True to activate, False to deactivate (True by default)"},
+ {"SetCursorPosition", (PyCFunction)PySfWindow_SetCursorPosition, METH_VARARGS, "SetCursorPosition(Left, Top)\nChange the position of the mouse cursor.\n Left : Left coordinate of the cursor, relative to the window\n Top : Top coordinate of the cursor, relative to the window"},
+ {"SetSize", (PyCFunction)PySfWindow_SetSize, METH_VARARGS, "SetSize(Width, Height)\nChange the size of the rendering region of the window.\n\
+ Width : New width\n Height : New height"},
+ {"SetFramerateLimit", (PyCFunction)PySfWindow_SetFramerateLimit, METH_O, "SetFramerateLimit(Limit)\nSet the framerate at a fixed frequency.\n Limit : Framerate limit, in frames per seconds (use 0 to disable limit)"},
+ {"SetJoystickThreshold", (PyCFunction)PySfWindow_SetJoystickThreshold, METH_O, "SetJoystickThreshold(Threshold)\nChange the joystick threshold, ie. the value below which no move event will be generated.\n Threshold : New threshold, in range [0., 100.]"},
+ {"SetPosition", (PyCFunction)PySfWindow_SetPosition, METH_VARARGS, "SetPosition(X, Y)\nChange the position of the window on screen. Only works for top-level windows\n Left : Left position\n Top : Top position"},
+ {"Show", (PyCFunction)PySfWindow_Show, METH_O, "Show(State)\nShow or hide the window.\n State : True to show, false to hide."},
+ {"ShowMouseCursor", (PyCFunction)PySfWindow_ShowMouseCursor, METH_O, "ShowMouseCursor(Show)\nShow or hide the mouse cursor.\n Show : True to show, false to hide."},
+ {"UseVerticalSync", (PyCFunction)PySfWindow_UseVerticalSync, METH_O, "UseVerticalSync(Enabled)\nEnable / disable vertical synchronization.\n Enabled : True to enable v-sync, False to deactivate"},
+ {"SetIcon", (PyCFunction)PySfWindow_SetIcon, METH_VARARGS, "SetIcon(Width, Height, Pixels)\n\
+Change the window's icon.\n\
+ Width : Icon's width, in pixels\n\
+ Height : Icon's height, in pixels\n\
+ Pixels : Pointer to the pixels in memory, format must be RGBA 32 bits."},
{NULL} /* Sentinel */
};
PyTypeObject PySfWindowType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Window", /*tp_name*/
- sizeof(PySfWindow), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Window", /*tp_name*/
+ sizeof(PySfWindow), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfWindow_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfWindow objects", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfWindow_methods, /* tp_methods */
- PySfWindow_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfWindow_init, /* tp_init */
- 0, /* tp_alloc */
- PySfWindow_new, /* tp_new */
+ "sf.Window is a rendering window ; it can create a new window or connect to an existing one.\n\
+Default constructor : sf.Window()\n\
+Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.WindowSettings())\n\
+ Mode : Video mode to use (sf.VideoMode instance)\n\
+ Title : Title of the window\n\
+ WindowStyle : Window style (Resize | Close by default)\n\
+ Params : Creation parameters (see default constructor for default values)\n\
+", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfWindow_methods, /* tp_methods */
+ PySfWindow_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfWindow_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfWindow_new, /* tp_new */
};
diff --git a/python/src/Window.hpp b/python/src/Window.hpp
index 1b14cc6..b42084b 100644
--- a/python/src/Window.hpp
+++ b/python/src/Window.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYWINDOW_HPP
#define __PYWINDOW_HPP
@@ -16,9 +40,10 @@
typedef struct {
PyObject_HEAD
- PySfWindowSettings *Settings;
sf::Window *obj;
} PySfWindow;
+PyObject*
+PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds);
#endif
diff --git a/python/src/WindowSettings.cpp b/python/src/WindowSettings.cpp
index 6898752..f6e5be4 100644
--- a/python/src/WindowSettings.cpp
+++ b/python/src/WindowSettings.cpp
@@ -1,9 +1,33 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include "WindowSettings.hpp"
static PyMemberDef PySfWindowSettings_members[] = {
- {"DepthBits", T_UINT, offsetof(PySfWindowSettings, DepthBits), 0, "Depth buffer bits (24 by default)"},
- {"StencilBits", T_UINT, offsetof(PySfWindowSettings, StencilBits), 0, "Stencil buffer bits (8 by default)"},
- {"AntialiasingLevel", T_UINT, offsetof(PySfWindowSettings, AntialiasingLevel), 0, "Antialiasing level (0 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 *)"AntialiasingLevel", T_UINT, offsetof(PySfWindowSettings, AntialiasingLevel), 0, (char *)"Antialiasing level (0 by default)"},
{NULL} /* Sentinel */
};
@@ -11,6 +35,7 @@ static PyMemberDef PySfWindowSettings_members[] = {
static void
PySfWindowSettings_dealloc(PySfWindowSettings *self)
{
+ delete self->obj;
self->ob_type->tp_free((PyObject*)self);
}
@@ -59,8 +84,8 @@ static PyMethodDef PySfWindowSettings_methods[] = {
PyTypeObject PySfWindowSettingsType = {
PyObject_HEAD_INIT(NULL)
0, /*ob_size*/
- "WindowSettings", /*tp_name*/
- sizeof(PySfWindowSettings), /*tp_basicsize*/
+ "WindowSettings", /*tp_name*/
+ sizeof(PySfWindowSettings), /*tp_basicsize*/
0, /*tp_itemsize*/
(destructor)PySfWindowSettings_dealloc, /*tp_dealloc*/
0, /*tp_print*/
@@ -78,7 +103,7 @@ PyTypeObject PySfWindowSettingsType = {
0, /*tp_setattro*/
0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfSettings is an utility class for manipulating Settingss", /* tp_doc */
+ "Structure defining the creation settings of windows.", /* tp_doc */
0, /* tp_traverse */
0, /* tp_clear */
0, /* tp_richcompare */
@@ -95,7 +120,7 @@ PyTypeObject PySfWindowSettingsType = {
0, /* tp_dictoffset */
(initproc)PySfWindowSettings_init, /* tp_init */
0, /* tp_alloc */
- PySfWindowSettings_new, /* tp_new */
+ PySfWindowSettings_new, /* tp_new */
};
PySfWindowSettings *
diff --git a/python/src/WindowSettings.hpp b/python/src/WindowSettings.hpp
index fee6f1c..ac61356 100644
--- a/python/src/WindowSettings.hpp
+++ b/python/src/WindowSettings.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYWINDOWSETTINGS_HPP
#define __PYWINDOWSETTINGS_HPP
diff --git a/python/src/WindowStyle.cpp b/python/src/WindowStyle.cpp
index a933dbf..3846f15 100644
--- a/python/src/WindowStyle.cpp
+++ b/python/src/WindowStyle.cpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
#include <SFML/Window/WindowStyle.hpp>
#include <Python.h>
@@ -49,44 +73,49 @@ static PyMethodDef PySfStyle_methods[] = {
PyTypeObject PySfStyleType = {
PyObject_HEAD_INIT(NULL)
- 0, /*ob_size*/
- "Style", /*tp_name*/
- sizeof(PySfStyle), /*tp_basicsize*/
- 0, /*tp_itemsize*/
+ 0, /*ob_size*/
+ "Style", /*tp_name*/
+ sizeof(PySfStyle), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
(destructor)PySfStyle_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- 0, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash */
- 0, /*tp_call*/
- 0, /*tp_str*/
- 0, /*tp_getattro*/
- 0, /*tp_setattro*/
- 0, /*tp_as_buffer*/
+ 0, /*tp_print*/
+ 0, /*tp_getattr*/
+ 0, /*tp_setattr*/
+ 0, /*tp_compare*/
+ 0, /*tp_repr*/
+ 0, /*tp_as_number*/
+ 0, /*tp_as_sequence*/
+ 0, /*tp_as_mapping*/
+ 0, /*tp_hash */
+ 0, /*tp_call*/
+ 0, /*tp_str*/
+ 0, /*tp_getattro*/
+ 0, /*tp_setattro*/
+ 0, /*tp_as_buffer*/
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
- "sfStyle doc", /* tp_doc */
- 0, /* tp_traverse */
- 0, /* tp_clear */
- 0, /* tp_richcompare */
- 0, /* tp_weaklistoffset */
- 0, /* tp_iter */
- 0, /* tp_iternext */
- PySfStyle_methods, /* tp_methods */
- PySfStyle_members, /* tp_members */
- 0, /* tp_getset */
- 0, /* tp_base */
- 0, /* tp_dict */
- 0, /* tp_descr_get */
- 0, /* tp_descr_set */
- 0, /* tp_dictoffset */
- (initproc)PySfStyle_init, /* tp_init */
- 0, /* tp_alloc */
- PySfStyle_new, /* tp_new */
+ "Enumeration of window creation styles.\n\
+None No border / title bar (this flag and all others are mutually exclusive).\n\
+Titlebar Title bar + fixed border.\n\
+Resize Titlebar + resizable border + maximize button.\n\
+Close Titlebar + close button.\n\
+Fullscreen Fullscreen mode (this flag and all others are mutually exclusive).", /* tp_doc */
+ 0, /* tp_traverse */
+ 0, /* tp_clear */
+ 0, /* tp_richcompare */
+ 0, /* tp_weaklistoffset */
+ 0, /* tp_iter */
+ 0, /* tp_iternext */
+ PySfStyle_methods, /* tp_methods */
+ PySfStyle_members, /* tp_members */
+ 0, /* tp_getset */
+ 0, /* tp_base */
+ 0, /* tp_dict */
+ 0, /* tp_descr_get */
+ 0, /* tp_descr_set */
+ 0, /* tp_dictoffset */
+ (initproc)PySfStyle_init, /* tp_init */
+ 0, /* tp_alloc */
+ PySfStyle_new, /* tp_new */
};
void PySfStyle_InitConst()
diff --git a/python/src/WindowStyle.hpp b/python/src/WindowStyle.hpp
index 9b6053f..042c1b8 100644
--- a/python/src/WindowStyle.hpp
+++ b/python/src/WindowStyle.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYWINDOWSTYLE_HPP
#define __PYWINDOWSTYLE_HPP
diff --git a/python/src/main.cpp b/python/src/main.cpp
index 28b38cb..d879f4a 100644
--- a/python/src/main.cpp
+++ b/python/src/main.cpp
@@ -1,242 +1,276 @@
-#include "main.hpp"
-
-#include "Color.hpp"
-#include "Key.hpp"
-#include "Joy.hpp"
-#include "Event.hpp"
-#include "Mouse.hpp"
-#include "WindowStyle.hpp"
-#include "Blend.hpp"
-#include "Sound.hpp"
-#include "String.hpp"
-
-
-extern PyTypeObject PySfClockType;
-
-extern PyTypeObject PySfEventType;
-extern PyTypeObject PySfEventTextType;
-extern PyTypeObject PySfEventKeyType;
-extern PyTypeObject PySfEventMouseMoveType;
-extern PyTypeObject PySfEventMouseButtonType;
-extern PyTypeObject PySfEventMouseWheelType;
-extern PyTypeObject PySfEventJoyMoveType;
-extern PyTypeObject PySfEventJoyButtonType;
-extern PyTypeObject PySfEventSizeType;
-extern PyTypeObject PySfKeyType;
-extern PyTypeObject PySfJoyType;
-extern PyTypeObject PySfMouseType;
-
-extern PyTypeObject PySfVideoModeType;
-extern PyTypeObject PySfWindowType;
-extern PyTypeObject PySfWindowSettingsType;
-extern PyTypeObject PySfStyleType;
-extern PyTypeObject PySfRenderWindowType;
-extern PyTypeObject PySfViewType;
-extern PyTypeObject PySfInputType;
-
-extern PyTypeObject PySfDrawableType;
-extern PyTypeObject PySfBlendType;
-extern PyTypeObject PySfSpriteType;
-extern PyTypeObject PySfFontType;
-extern PyTypeObject PySfStringType;
-extern PyTypeObject PySfPostFXType;
-
-extern PyTypeObject PySfImageType;
-
-extern PyTypeObject PySfColorType;
-
-extern PyTypeObject PySfShapeType;
-
-extern PyTypeObject PySfIntRectType;
-extern PyTypeObject PySfFloatRectType;
-
-extern PyTypeObject PySfMusicType;
-extern PyTypeObject PySfSoundType;
-extern PyTypeObject PySfSoundBufferType;
-extern PyTypeObject PySfSoundRecorderType;
-extern PyTypeObject PySfSoundBufferRecorderType;
-extern PyTypeObject PySfListenerType;
-
-
-static PyMethodDef module_methods[] = {
- {"Sleep", (PyCFunction)PySFML_Sleep, METH_O, "Sleeps during the specified duration."},
- {NULL} /* Sentinel */
-};
-
-#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
-#define PyMODINIT_FUNC void
-#endif
-PyMODINIT_FUNC
-initsf(void)
-{
- PyObject *m;
-
- initEvents();
-
- if (PyType_Ready(&PySfClockType) < 0)
- return;
-
- if (PyType_Ready(&PySfWindowType) < 0)
- return;
- if (PyType_Ready(&PySfWindowSettingsType) < 0)
- return;
- if (PyType_Ready(&PySfStyleType) < 0)
- return;
- if (PyType_Ready(&PySfRenderWindowType) < 0)
- return;
- if (PyType_Ready(&PySfVideoModeType) < 0)
- return;
- if (PyType_Ready(&PySfViewType) < 0)
- return;
- if (PyType_Ready(&PySfInputType) < 0)
- return;
-
- if (PyType_Ready(&PySfEventType) < 0)
- return;
- if (PyType_Ready(&PySfEventTextType) < 0)
- return;
- if (PyType_Ready(&PySfEventKeyType) < 0)
- return;
- if (PyType_Ready(&PySfEventMouseMoveType) < 0)
- return;
- if (PyType_Ready(&PySfEventMouseButtonType) < 0)
- return;
- if (PyType_Ready(&PySfEventMouseWheelType) < 0)
- return;
- if (PyType_Ready(&PySfEventJoyMoveType) < 0)
- return;
- if (PyType_Ready(&PySfEventJoyButtonType) < 0)
- return;
- if (PyType_Ready(&PySfEventSizeType) < 0)
- return;
- if (PyType_Ready(&PySfKeyType) < 0)
- return;
- if (PyType_Ready(&PySfJoyType) < 0)
- return;
- if (PyType_Ready(&PySfMouseType) < 0)
- return;
-
- if (PyType_Ready(&PySfDrawableType) < 0)
- return;
- if (PyType_Ready(&PySfBlendType) < 0)
- return;
- if (PyType_Ready(&PySfSpriteType) < 0)
- return;
- if (PyType_Ready(&PySfFontType) < 0)
- return;
- if (PyType_Ready(&PySfStringType) < 0)
- return;
- if (PyType_Ready(&PySfPostFXType) < 0)
- return;
-
- if (PyType_Ready(&PySfImageType) < 0)
- return;
-
- if (PyType_Ready(&PySfShapeType) < 0)
- return;
-
- if (PyType_Ready(&PySfColorType) < 0)
- return;
-
- if (PyType_Ready(&PySfIntRectType) < 0)
- return;
- if (PyType_Ready(&PySfFloatRectType) < 0)
- return;
-
- if (PyType_Ready(&PySfMusicType) < 0)
- return;
- if (PyType_Ready(&PySfSoundType) < 0)
- return;
- if (PyType_Ready(&PySfSoundBufferType) < 0)
- return;
- if (PyType_Ready(&PySfSoundBufferRecorderType) < 0)
- return;
- if (PyType_Ready(&PySfSoundRecorderType) < 0)
- return;
- if (PyType_Ready(&PySfListenerType) < 0)
- return;
-
- m = Py_InitModule3("sf", module_methods, "Python binding for sfml (Simple Fast Media Library)");
-
- if (m == NULL)
- return;
-
- Py_INCREF(&PySfClockType);
- PyModule_AddObject(m, "Clock", (PyObject *)&PySfClockType);
-
- Py_INCREF(&PySfWindowType);
- PyModule_AddObject(m, "Window", (PyObject *)&PySfWindowType);
- Py_INCREF(&PySfWindowSettingsType);
- PyModule_AddObject(m, "WindowSettings", (PyObject *)&PySfWindowSettingsType);
- Py_INCREF(&PySfStyleType);
- PyModule_AddObject(m, "Style", (PyObject *)&PySfStyleType);
- Py_INCREF(&PySfRenderWindowType);
- PyModule_AddObject(m, "RenderWindow", (PyObject *)&PySfRenderWindowType);
- Py_INCREF(&PySfVideoModeType);
- PyModule_AddObject(m, "VideoMode", (PyObject *)&PySfVideoModeType);
- Py_INCREF(&PySfViewType);
- PyModule_AddObject(m, "View", (PyObject *)&PySfViewType);
- Py_INCREF(&PySfInputType);
- PyModule_AddObject(m, "Input", (PyObject *)&PySfInputType);
-
- Py_INCREF(&PySfDrawableType);
- PyModule_AddObject(m, "Drawable", (PyObject *)&PySfDrawableType);
- Py_INCREF(&PySfBlendType);
- PyModule_AddObject(m, "Blend", (PyObject *)&PySfBlendType);
- Py_INCREF(&PySfSpriteType);
- PyModule_AddObject(m, "Sprite", (PyObject *)&PySfSpriteType);
- Py_INCREF(&PySfFontType);
- PyModule_AddObject(m, "Font", (PyObject *)&PySfFontType);
- Py_INCREF(&PySfStringType);
- PyModule_AddObject(m, "String", (PyObject *)&PySfStringType);
- Py_INCREF(&PySfPostFXType);
- PyModule_AddObject(m, "PostFX", (PyObject *)&PySfPostFXType);
-
- Py_INCREF(&PySfEventType);
- PyModule_AddObject(m, "Event", (PyObject *)&PySfEventType);
- Py_INCREF(&PySfKeyType);
- PyModule_AddObject(m, "Key", (PyObject *)&PySfKeyType);
- Py_INCREF(&PySfJoyType);
- PyModule_AddObject(m, "Joy", (PyObject *)&PySfJoyType);
- Py_INCREF(&PySfMouseType);
- PyModule_AddObject(m, "Mouse", (PyObject *)&PySfMouseType);
-
- Py_INCREF(&PySfImageType);
- PyModule_AddObject(m, "Image", (PyObject *)&PySfImageType);
-
- Py_INCREF(&PySfColorType);
- PyModule_AddObject(m, "Color", (PyObject *)&PySfColorType);
-
- Py_INCREF(&PySfShapeType);
- PyModule_AddObject(m, "Shape", (PyObject *)&PySfShapeType);
-
- Py_INCREF(&PySfIntRectType);
- PyModule_AddObject(m, "IntRect", (PyObject *)&PySfIntRectType);
- Py_INCREF(&PySfFloatRectType);
- PyModule_AddObject(m, "FloatRect", (PyObject *)&PySfFloatRectType);
-
- Py_INCREF(&PySfMusicType);
- PyModule_AddObject(m, "Music", (PyObject *)&PySfMusicType);
- Py_INCREF(&PySfSoundType);
- PyModule_AddObject(m, "Sound", (PyObject *)&PySfSoundType);
- Py_INCREF(&PySfSoundBufferType);
- PyModule_AddObject(m, "SoundBuffer", (PyObject *)&PySfSoundBufferType);
- Py_INCREF(&PySfSoundRecorderType);
- PyModule_AddObject(m, "SoundRecorder", (PyObject *)&PySfSoundRecorderType);
- Py_INCREF(&PySfSoundBufferRecorderType);
- PyModule_AddObject(m, "SoundBufferRecorder", (PyObject *)&PySfSoundBufferRecorderType);
- Py_INCREF(&PySfListenerType);
- PyModule_AddObject(m, "Listener", (PyObject *)&PySfListenerType);
-
-
- PySfColor_InitConst();
- PySfKey_InitConst();
- PySfJoy_InitConst();
- PySfEvent_InitConst();
- PySfMouse_InitConst();
- PySfStyle_InitConst();
- PySfBlend_InitConst();
- PySfSound_InitConst();
- PySfString_InitConst();
-}
-
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#include "main.hpp"
+
+#include "Color.hpp"
+#include "Key.hpp"
+#include "Joy.hpp"
+#include "Event.hpp"
+#include "Mouse.hpp"
+#include "WindowStyle.hpp"
+#include "Blend.hpp"
+#include "Sound.hpp"
+#include "String.hpp"
+#include "SoundStream.hpp"
+
+extern PyTypeObject PySfClockType;
+
+extern PyTypeObject PySfEventType;
+extern PyTypeObject PySfEventTextType;
+extern PyTypeObject PySfEventKeyType;
+extern PyTypeObject PySfEventMouseMoveType;
+extern PyTypeObject PySfEventMouseButtonType;
+extern PyTypeObject PySfEventMouseWheelType;
+extern PyTypeObject PySfEventJoyMoveType;
+extern PyTypeObject PySfEventJoyButtonType;
+extern PyTypeObject PySfEventSizeType;
+extern PyTypeObject PySfKeyType;
+extern PyTypeObject PySfJoyType;
+extern PyTypeObject PySfMouseType;
+
+extern PyTypeObject PySfVideoModeType;
+extern PyTypeObject PySfWindowType;
+extern PyTypeObject PySfWindowSettingsType;
+extern PyTypeObject PySfStyleType;
+extern PyTypeObject PySfRenderWindowType;
+extern PyTypeObject PySfViewType;
+extern PyTypeObject PySfInputType;
+
+extern PyTypeObject PySfDrawableType;
+extern PyTypeObject PySfBlendType;
+extern PyTypeObject PySfSpriteType;
+extern PyTypeObject PySfFontType;
+extern PyTypeObject PySfGlyphType;
+extern PyTypeObject PySfStringType;
+extern PyTypeObject PySfPostFXType;
+
+extern PyTypeObject PySfImageType;
+
+extern PyTypeObject PySfColorType;
+
+extern PyTypeObject PySfShapeType;
+
+extern PyTypeObject PySfIntRectType;
+extern PyTypeObject PySfFloatRectType;
+
+extern PyTypeObject PySfMusicType;
+extern PyTypeObject PySfSoundType;
+extern PyTypeObject PySfSoundBufferType;
+extern PyTypeObject PySfSoundRecorderType;
+extern PyTypeObject PySfSoundBufferRecorderType;
+extern PyTypeObject PySfSoundStreamType;
+extern PyTypeObject PySfListenerType;
+
+
+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"},
+ {NULL} /* Sentinel */
+};
+
+#ifndef PyMODINIT_FUNC /* declarations for DLL import/export */
+#define PyMODINIT_FUNC void
+#endif
+PyMODINIT_FUNC
+initsf(void)
+{
+ PyObject *m;
+
+ if (PyType_Ready(&PySfClockType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfWindowType) < 0)
+ return;
+ if (PyType_Ready(&PySfWindowSettingsType) < 0)
+ return;
+ if (PyType_Ready(&PySfStyleType) < 0)
+ return;
+ if (PyType_Ready(&PySfRenderWindowType) < 0)
+ return;
+ if (PyType_Ready(&PySfVideoModeType) < 0)
+ return;
+ if (PyType_Ready(&PySfViewType) < 0)
+ return;
+ if (PyType_Ready(&PySfInputType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfEventType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventTextType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventKeyType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventMouseMoveType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventMouseButtonType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventMouseWheelType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventJoyMoveType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventJoyButtonType) < 0)
+ return;
+ if (PyType_Ready(&PySfEventSizeType) < 0)
+ return;
+ if (PyType_Ready(&PySfKeyType) < 0)
+ return;
+ if (PyType_Ready(&PySfJoyType) < 0)
+ return;
+ if (PyType_Ready(&PySfMouseType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfDrawableType) < 0)
+ return;
+ if (PyType_Ready(&PySfBlendType) < 0)
+ return;
+ if (PyType_Ready(&PySfSpriteType) < 0)
+ return;
+ if (PyType_Ready(&PySfFontType) < 0)
+ return;
+ if (PyType_Ready(&PySfGlyphType) < 0)
+ return;
+ if (PyType_Ready(&PySfStringType) < 0)
+ return;
+ if (PyType_Ready(&PySfPostFXType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfImageType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfShapeType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfColorType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfIntRectType) < 0)
+ return;
+ if (PyType_Ready(&PySfFloatRectType) < 0)
+ return;
+
+ if (PyType_Ready(&PySfMusicType) < 0)
+ return;
+ if (PyType_Ready(&PySfSoundType) < 0)
+ return;
+ if (PyType_Ready(&PySfSoundBufferType) < 0)
+ return;
+ if (PyType_Ready(&PySfSoundBufferRecorderType) < 0)
+ return;
+ if (PyType_Ready(&PySfSoundRecorderType) < 0)
+ return;
+ if (PyType_Ready(&PySfSoundStreamType) < 0)
+ return;
+ if (PyType_Ready(&PySfListenerType) < 0)
+ return;
+
+ m = Py_InitModule3("sf", module_methods, "Python binding for sfml (Simple Fast Media Library)");
+
+ if (m == NULL)
+ return;
+
+ Py_INCREF(&PySfClockType);
+ PyModule_AddObject(m, "Clock", (PyObject *)&PySfClockType);
+
+ Py_INCREF(&PySfWindowType);
+ PyModule_AddObject(m, "Window", (PyObject *)&PySfWindowType);
+ Py_INCREF(&PySfWindowSettingsType);
+ PyModule_AddObject(m, "WindowSettings", (PyObject *)&PySfWindowSettingsType);
+ Py_INCREF(&PySfStyleType);
+ PyModule_AddObject(m, "Style", (PyObject *)&PySfStyleType);
+ Py_INCREF(&PySfRenderWindowType);
+ PyModule_AddObject(m, "RenderWindow", (PyObject *)&PySfRenderWindowType);
+ Py_INCREF(&PySfVideoModeType);
+ PyModule_AddObject(m, "VideoMode", (PyObject *)&PySfVideoModeType);
+ Py_INCREF(&PySfViewType);
+ PyModule_AddObject(m, "View", (PyObject *)&PySfViewType);
+ Py_INCREF(&PySfInputType);
+ PyModule_AddObject(m, "Input", (PyObject *)&PySfInputType);
+
+ Py_INCREF(&PySfDrawableType);
+ PyModule_AddObject(m, "Drawable", (PyObject *)&PySfDrawableType);
+ Py_INCREF(&PySfBlendType);
+ PyModule_AddObject(m, "Blend", (PyObject *)&PySfBlendType);
+ Py_INCREF(&PySfSpriteType);
+ PyModule_AddObject(m, "Sprite", (PyObject *)&PySfSpriteType);
+ Py_INCREF(&PySfFontType);
+ PyModule_AddObject(m, "Font", (PyObject *)&PySfFontType);
+ Py_INCREF(&PySfGlyphType);
+ PyModule_AddObject(m, "Glyph", (PyObject *)&PySfGlyphType);
+ Py_INCREF(&PySfStringType);
+ PyModule_AddObject(m, "String", (PyObject *)&PySfStringType);
+ Py_INCREF(&PySfPostFXType);
+ PyModule_AddObject(m, "PostFX", (PyObject *)&PySfPostFXType);
+
+ Py_INCREF(&PySfEventType);
+ PyModule_AddObject(m, "Event", (PyObject *)&PySfEventType);
+ Py_INCREF(&PySfKeyType);
+ PyModule_AddObject(m, "Key", (PyObject *)&PySfKeyType);
+ Py_INCREF(&PySfJoyType);
+ PyModule_AddObject(m, "Joy", (PyObject *)&PySfJoyType);
+ Py_INCREF(&PySfMouseType);
+ PyModule_AddObject(m, "Mouse", (PyObject *)&PySfMouseType);
+
+ Py_INCREF(&PySfImageType);
+ PyModule_AddObject(m, "Image", (PyObject *)&PySfImageType);
+
+ Py_INCREF(&PySfColorType);
+ PyModule_AddObject(m, "Color", (PyObject *)&PySfColorType);
+
+ Py_INCREF(&PySfShapeType);
+ PyModule_AddObject(m, "Shape", (PyObject *)&PySfShapeType);
+
+ Py_INCREF(&PySfIntRectType);
+ PyModule_AddObject(m, "IntRect", (PyObject *)&PySfIntRectType);
+ Py_INCREF(&PySfFloatRectType);
+ PyModule_AddObject(m, "FloatRect", (PyObject *)&PySfFloatRectType);
+
+ Py_INCREF(&PySfMusicType);
+ PyModule_AddObject(m, "Music", (PyObject *)&PySfMusicType);
+ Py_INCREF(&PySfSoundType);
+ PyModule_AddObject(m, "Sound", (PyObject *)&PySfSoundType);
+ Py_INCREF(&PySfSoundBufferType);
+ PyModule_AddObject(m, "SoundBuffer", (PyObject *)&PySfSoundBufferType);
+ Py_INCREF(&PySfSoundRecorderType);
+ PyModule_AddObject(m, "SoundRecorder", (PyObject *)&PySfSoundRecorderType);
+ Py_INCREF(&PySfSoundBufferRecorderType);
+ PyModule_AddObject(m, "SoundBufferRecorder", (PyObject *)&PySfSoundBufferRecorderType);
+ Py_INCREF(&PySfSoundStreamType);
+ PyModule_AddObject(m, "SoundStream", (PyObject *)&PySfSoundStreamType);
+ Py_INCREF(&PySfListenerType);
+ PyModule_AddObject(m, "Listener", (PyObject *)&PySfListenerType);
+
+ PyModule_AddStringConstant(m, "Version", "1.4");
+
+ PySfColor_InitConst();
+ PySfKey_InitConst();
+ PySfJoy_InitConst();
+ PySfEvent_InitConst();
+ PySfMouse_InitConst();
+ PySfStyle_InitConst();
+ PySfBlend_InitConst();
+ PySfSound_InitConst();
+ PySfSoundStream_InitConst();
+ PySfString_InitConst();
+}
+
diff --git a/python/src/main.hpp b/python/src/main.hpp
index ca11a82..fa65683 100644
--- a/python/src/main.hpp
+++ b/python/src/main.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __PYMAIN_HPP
#define __PYMAIN_HPP
diff --git a/python/src/offsetof.hpp b/python/src/offsetof.hpp
index 9592073..73de395 100644
--- a/python/src/offsetof.hpp
+++ b/python/src/offsetof.hpp
@@ -1,3 +1,27 @@
+////////////////////////////////////////////////////////////
+//
+// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
+// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620 at 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 __OFFSETOF_H
#define __OFFSETOF_H
--
Python bindings for the SFML Library
More information about the Pkg-games-commits
mailing list