Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
10
python/MANIFEST.in
Normal file
10
python/MANIFEST.in
Normal file
|
@ -0,0 +1,10 @@
|
|||
graft src
|
||||
graft scripts
|
||||
include doc/style.css
|
||||
include samples/opengl.py
|
||||
include samples/sound.py
|
||||
include samples/sound_capture.py
|
||||
include samples/sound_stream.py
|
||||
include samples/worm.py
|
||||
graft samples/data
|
||||
|
10
python/PKG-INFO
Normal file
10
python/PKG-INFO
Normal file
|
@ -0,0 +1,10 @@
|
|||
Metadata-Version: 1.0
|
||||
Name: PySFML
|
||||
Version: 1.4
|
||||
Summary: Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
Home-page: http://sfml.sourceforge.net/
|
||||
Author: Rémi Koenig
|
||||
Author-email: remi.k2620@gmail.com
|
||||
License: zlib/png
|
||||
Description: UNKNOWN
|
||||
Platform: UNKNOWN
|
2
python/PySFML/__init__.py
Normal file
2
python/PySFML/__init__.py
Normal file
|
@ -0,0 +1,2 @@
|
|||
import sf
|
||||
|
96
python/doc/style.css
Normal file
96
python/doc/style.css
Normal file
|
@ -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%;
|
||||
}
|
||||
|
BIN
python/samples/data/apple.png
Normal file
BIN
python/samples/data/apple.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 868 B |
BIN
python/samples/data/fart.wav
Normal file
BIN
python/samples/data/fart.wav
Normal file
Binary file not shown.
BIN
python/samples/data/rond2.png
Normal file
BIN
python/samples/data/rond2.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.1 KiB |
BIN
python/samples/libsndfile-1.dll
Normal file
BIN
python/samples/libsndfile-1.dll
Normal file
Binary file not shown.
166
python/samples/opengl.py
Normal file
166
python/samples/opengl.py
Normal file
|
@ -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()
|
||||
|
43
python/samples/sound.py
Normal file
43
python/samples/sound.py
Normal file
|
@ -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()
|
||||
|
68
python/samples/sound_capture.py
Normal file
68
python/samples/sound_capture.py
Normal file
|
@ -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()
|
49
python/samples/sound_stream.py
Executable file
49
python/samples/sound_stream.py
Executable file
|
@ -0,0 +1,49 @@
|
|||
#!/usr/bin/python
|
||||
|
||||
from PySFML import sf
|
||||
|
||||
class MyCustomStream(sf.SoundStream):
|
||||
|
||||
def Open(self, Filename):
|
||||
# Load the sound data into a sound buffer
|
||||
self.SoundData = sf.SoundBuffer()
|
||||
if not self.SoundData.LoadFromFile(Filename):
|
||||
return False
|
||||
# Initialize the stream with the sound parameters
|
||||
self.Initialize(self.SoundData.GetChannelsCount(), self.SoundData.GetSampleRate())
|
||||
# Copy the audio samples into our internal array
|
||||
self.myBuffer = self.SoundData.GetSamples()
|
||||
return True
|
||||
|
||||
def OnStart(self):
|
||||
self.myOffset = 0
|
||||
self.myBufferSize = 80000
|
||||
return True
|
||||
|
||||
def OnGetData(self):
|
||||
# Check if there is enough data to stream
|
||||
if self.myOffset > len(self.myBuffer):
|
||||
# Returning something else than a string means that we want to stop playing the stream
|
||||
return False
|
||||
# Data contains the string of samples we will return
|
||||
if self.myOffset + self.myBufferSize >= len(self.myBuffer):
|
||||
print "End of audio data reached"
|
||||
Data = self.myBuffer[self.myOffset:]
|
||||
else:
|
||||
Data = self.myBuffer[self.myOffset:self.myOffset+self.myBufferSize]
|
||||
# Update the offset
|
||||
self.myOffset = self.myBufferSize + self.myOffset
|
||||
return Data
|
||||
|
||||
def Main():
|
||||
Stream = MyCustomStream()
|
||||
Stream.Open("./data/fart.wav")
|
||||
Stream.Play()
|
||||
print "Playing 5 seconds of audio data..."
|
||||
sf.Sleep(5)
|
||||
Stream.Stop()
|
||||
print "Press enter to exit..."
|
||||
raw_input()
|
||||
|
||||
Main()
|
||||
|
240
python/samples/worm.py
Normal file
240
python/samples/worm.py
Normal file
|
@ -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()
|
||||
|
7
python/scripts/footer.htm
Normal file
7
python/scripts/footer.htm
Normal file
|
@ -0,0 +1,7 @@
|
|||
|
||||
<p id="footer">
|
||||
:: Copyright © 2007-2008 Rémi Koenig ::
|
||||
</p>
|
||||
|
||||
</body>
|
||||
</html>
|
118
python/scripts/gen_doc.py
Executable file
118
python/scripts/gen_doc.py
Executable file
|
@ -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()
|
||||
|
11
python/scripts/header.htm
Normal file
11
python/scripts/header.htm
Normal file
|
@ -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>
|
27
python/setup.py
Normal file
27
python/setup.py
Normal file
|
@ -0,0 +1,27 @@
|
|||
#!/usr/bin/env python
|
||||
# coding=UTF-8
|
||||
|
||||
from distutils.core import setup, Extension
|
||||
|
||||
setup(name='PySFML',
|
||||
version='1.4',
|
||||
description='Python binding for SFML (Simple and Fast Multimedia Library)',
|
||||
author='Rémi Koenig',
|
||||
author_email='remi.k2620@gmail.com',
|
||||
url='http://www.sfml-dev.org/',
|
||||
license='zlib/png',
|
||||
ext_modules=[ Extension('PySFML.sf', \
|
||||
['src/Clock.cpp', 'src/Color.cpp', 'src/Drawable.cpp', \
|
||||
'src/Event.cpp', 'src/Image.cpp', 'src/Input.cpp', 'src/Key.cpp', 'src/main.cpp', \
|
||||
'src/Music.cpp', 'src/PostFX.cpp', 'src/Rect.cpp', 'src/RenderWindow.cpp', 'src/Sleep.cpp', \
|
||||
'src/Sprite.cpp', 'src/String.cpp', 'src/VideoMode.cpp', 'src/View.cpp', 'src/Window.cpp', \
|
||||
'src/Joy.cpp', 'src/Mouse.cpp', 'src/WindowStyle.cpp', 'src/Blend.cpp', 'src/Sound.cpp', \
|
||||
'src/SoundBuffer.cpp', 'src/Listener.cpp', 'src/SoundRecorder.cpp', 'src/SoundBufferRecorder.cpp', \
|
||||
'src/SoundStream.cpp', 'src/Font.cpp', 'src/Glyph.cpp', 'src/Shape.cpp', 'src/WindowSettings.cpp' ], \
|
||||
libraries=['sfml-graphics', 'sfml-window', 'sfml-audio', 'sfml-system'], \
|
||||
library_dirs=['../lib/mingw'], \
|
||||
include_dirs=['../include']
|
||||
)],
|
||||
package_dir = {'PySFML':'PySFML'},
|
||||
packages=['PySFML'],
|
||||
)
|
136
python/src/Blend.cpp
Normal file
136
python/src/Blend.cpp
Normal file
|
@ -0,0 +1,136 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Blend.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfBlend;
|
||||
|
||||
|
||||
|
||||
static PyMemberDef PySfBlend_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfBlend_dealloc(PySfBlend *self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfBlend_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfBlend *self;
|
||||
|
||||
self = (PySfBlend *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfBlend_init(PySfBlend *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfBlend_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfBlendType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::Blend::Alpha);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Alpha", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Blend::Add);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Add", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Blend::Multiply);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "Multiply", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Blend::None);
|
||||
PyDict_SetItemString(PySfBlendType.tp_dict, "None", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
31
python/src/Blend.hpp
Normal file
31
python/src/Blend.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYBLEND_HPP
|
||||
#define __PYBLEND_HPP
|
||||
|
||||
void
|
||||
PySfBlend_InitConst();
|
||||
|
||||
#endif
|
130
python/src/Clock.cpp
Normal file
130
python/src/Clock.cpp
Normal file
|
@ -0,0 +1,130 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Clock.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Clock *obj;
|
||||
} PySfClock;
|
||||
|
||||
|
||||
|
||||
static PyMemberDef PySfClock_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfClock_dealloc(PySfClock *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfClock_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfClock *self;
|
||||
|
||||
self = (PySfClock *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfClock_init(PySfClock *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
self->obj = new sf::Clock();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PyObject*
|
||||
PySfClock_GetElapsedTime(PySfClock *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetElapsedTime());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfClock_Reset(PySfClock *self)
|
||||
{
|
||||
self->obj->Reset();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfClock_methods[] = {
|
||||
{"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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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 */
|
||||
};
|
||||
|
||||
|
35
python/src/Clock.hpp
Normal file
35
python/src/Clock.hpp
Normal file
|
@ -0,0 +1,35 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYCLOCK_HPP
|
||||
#define __PYCLOCK_HPP
|
||||
|
||||
|
||||
#include <SFML/System/Clock.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#endif
|
231
python/src/Color.cpp
Normal file
231
python/src/Color.cpp
Normal file
|
@ -0,0 +1,231 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Color.hpp"
|
||||
|
||||
static PyMemberDef PySfColor_members[] = {
|
||||
{(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 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfColor_dealloc(PySfColor *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
void
|
||||
PySfColorUpdate(PySfColor *self)
|
||||
{
|
||||
self->obj->r = self->r;
|
||||
self->obj->g = self->g;
|
||||
self->obj->b = self->b;
|
||||
self->obj->a = self->a;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfColor_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfColor *self;
|
||||
|
||||
self = (PySfColor *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
self->r = 0;
|
||||
self->g = 0;
|
||||
self->b = 0;
|
||||
self->a = 255;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfColor_init(PySfColor *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"r", "g", "b", "a", NULL};
|
||||
|
||||
long int rgba=0;
|
||||
|
||||
|
||||
if (PyTuple_Size(args) == 1)
|
||||
{
|
||||
if ( !PyArg_ParseTuple(args, "l", &rgba))
|
||||
return -1;
|
||||
self->r = rgba & 0xff;
|
||||
self->g = rgba>>8 & 0xff;
|
||||
self->b = rgba>>16 & 0xff;
|
||||
self->a = rgba>>24 & 0xff;
|
||||
}
|
||||
else if (PyTuple_Size(args) > 1)
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "BBB|B", (char **)kwlist, &(self->r), &(self->g), &(self->b), &(self->a)))
|
||||
return -1;
|
||||
|
||||
self->obj = new sf::Color(self->r, self->g, self->b, self->a);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfColor_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfColorType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Color", /*tp_name*/
|
||||
sizeof(PySfColor), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfColor_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*/
|
||||
"sf.Color is an utility class for manipulating 32-bits RGBA colors.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfColor_methods, /* tp_methods */
|
||||
PySfColor_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfColor_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfColor_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfColor *
|
||||
GetNewPySfColor()
|
||||
{
|
||||
return PyObject_New(PySfColor, &PySfColorType);
|
||||
}
|
||||
|
||||
void
|
||||
PySfColor_InitConst()
|
||||
{
|
||||
PySfColor *Black, *White, *Red, *Green, *Blue, *Yellow, *Magenta, *Cyan;
|
||||
Black = GetNewPySfColor();
|
||||
Black->obj = (sf::Color *) &(sf::Color::Black);
|
||||
Black->r = sf::Color::Black.r;
|
||||
Black->g = sf::Color::Black.g;
|
||||
Black->b = sf::Color::Black.b;
|
||||
Black->a = sf::Color::Black.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Black", (PyObject *)Black);
|
||||
Py_DECREF(Black);
|
||||
White = GetNewPySfColor();
|
||||
White->obj = (sf::Color *) &(sf::Color::White);
|
||||
White->r = sf::Color::White.r;
|
||||
White->g = sf::Color::White.g;
|
||||
White->b = sf::Color::White.b;
|
||||
White->a = sf::Color::White.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "White", (PyObject *)White);
|
||||
Py_DECREF(White);
|
||||
Red = GetNewPySfColor();
|
||||
Red->obj = (sf::Color *) &(sf::Color::Red);
|
||||
Red->r = sf::Color::Red.r;
|
||||
Red->g = sf::Color::Red.g;
|
||||
Red->b = sf::Color::Red.b;
|
||||
Red->a = sf::Color::Red.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Red", (PyObject *)Red);
|
||||
Py_DECREF(Red);
|
||||
Green = GetNewPySfColor();
|
||||
Green->obj = (sf::Color *) &(sf::Color::Green);
|
||||
Green->r = sf::Color::Green.r;
|
||||
Green->g = sf::Color::Green.g;
|
||||
Green->b = sf::Color::Green.b;
|
||||
Green->a = sf::Color::Green.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Green", (PyObject *)Green);
|
||||
Py_DECREF(Green);
|
||||
Blue = GetNewPySfColor();
|
||||
Blue->obj = (sf::Color *) &(sf::Color::Blue);
|
||||
Blue->r = sf::Color::Blue.r;
|
||||
Blue->g = sf::Color::Blue.g;
|
||||
Blue->b = sf::Color::Blue.b;
|
||||
Blue->a = sf::Color::Blue.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Blue", (PyObject *)Blue);
|
||||
Py_DECREF(Blue);
|
||||
Yellow = GetNewPySfColor();
|
||||
Yellow->obj = (sf::Color *) &(sf::Color::Yellow);
|
||||
Yellow->r = sf::Color::Yellow.r;
|
||||
Yellow->g = sf::Color::Yellow.g;
|
||||
Yellow->b = sf::Color::Yellow.b;
|
||||
Yellow->a = sf::Color::Yellow.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Yellow", (PyObject *)Yellow);
|
||||
Py_DECREF(Yellow);
|
||||
Magenta = GetNewPySfColor();
|
||||
Magenta->obj = (sf::Color *) &(sf::Color::Magenta);
|
||||
Magenta->r = sf::Color::Magenta.r;
|
||||
Magenta->g = sf::Color::Magenta.g;
|
||||
Magenta->b = sf::Color::Magenta.b;
|
||||
Magenta->a = sf::Color::Magenta.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Magenta", (PyObject *)Magenta);
|
||||
Py_DECREF(Magenta);
|
||||
Cyan = GetNewPySfColor();
|
||||
Cyan->obj = (sf::Color *) &(sf::Color::Cyan);
|
||||
Cyan->r = sf::Color::Cyan.r;
|
||||
Cyan->g = sf::Color::Cyan.g;
|
||||
Cyan->b = sf::Color::Cyan.b;
|
||||
Cyan->a = sf::Color::Cyan.a;
|
||||
PyDict_SetItemString(PySfColorType.tp_dict, "Cyan", (PyObject *)Cyan);
|
||||
Py_DECREF(Cyan);
|
||||
|
||||
/*
|
||||
static const Color Black; ///< Black predefined color
|
||||
static const Color White; ///< White predefined color
|
||||
static const Color Red; ///< Red predefined color
|
||||
static const Color Green; ///< Green predefined color
|
||||
static const Color Blue; ///< Blue predefined color
|
||||
static const Color Yellow; ///< Yellow predefined color
|
||||
static const Color Magenta; ///< Magenta predefined color
|
||||
static const Color Cyan; ///< Cyan predefined color
|
||||
*/
|
||||
}
|
||||
|
55
python/src/Color.hpp
Normal file
55
python/src/Color.hpp
Normal file
|
@ -0,0 +1,55 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYCOLOR_HPP
|
||||
#define __PYCOLOR_HPP
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned char r;
|
||||
unsigned char g;
|
||||
unsigned char b;
|
||||
unsigned char a;
|
||||
sf::Color *obj;
|
||||
} PySfColor;
|
||||
|
||||
PySfColor *
|
||||
GetNewPySfColor();
|
||||
|
||||
void
|
||||
PySfColorUpdate(PySfColor *self);
|
||||
|
||||
void
|
||||
PySfColor_InitConst();
|
||||
|
||||
#endif
|
305
python/src/Drawable.cpp
Normal file
305
python/src/Drawable.cpp
Normal file
|
@ -0,0 +1,305 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Drawable.hpp"
|
||||
|
||||
void CustomDrawable::Render (sf::RenderTarget& Target) const
|
||||
{
|
||||
if (RenderFunction)
|
||||
PyObject_CallFunction(RenderFunction, (char *)"O", RenderWindow);
|
||||
}
|
||||
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
|
||||
static PyMemberDef PySfDrawable_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfDrawable_dealloc(PySfDrawable *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfDrawable *self;
|
||||
|
||||
self = (PySfDrawable *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfDrawable_init(PySfDrawable *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
self->obj = new CustomDrawable();
|
||||
return 0;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetX(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetX(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetY(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetY(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetScale(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float ScaleX, ScaleY;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &ScaleX, &ScaleY) )
|
||||
return NULL;
|
||||
self->obj->SetScale(ScaleX, ScaleY);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetScaleX(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetScaleX(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetScaleY(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetScaleY(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetRotation(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetRotation(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_SetCenter(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->SetCenter(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetCenter(PySfDrawable* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetCenter();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetColor(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
PySfColor *Color = (PySfColor *)args;
|
||||
if (! PyObject_TypeCheck(args, &PySfColorType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Argument is not a sfColor");
|
||||
return NULL;
|
||||
}
|
||||
PySfColorUpdate(Color);
|
||||
self->obj->SetColor(*(Color->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetPosition(PySfDrawable* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetPosition();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetScale(PySfDrawable* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetScale();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_GetRotation(PySfDrawable* self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetRotation());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_GetColor(PySfDrawable* self)
|
||||
{
|
||||
PySfColor *Color;
|
||||
|
||||
Color = GetNewPySfColor();
|
||||
Color->obj = new sf::Color( self->obj->GetColor() );
|
||||
Color->r = Color->obj->r;
|
||||
Color->g = Color->obj->g;
|
||||
Color->b = Color->obj->b;
|
||||
Color->a = Color->obj->a;
|
||||
|
||||
return (PyObject *)Color;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_Move(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->Move(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_Rotate(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->Rotate(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfDrawable_Scale(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float FactorX, FactorY;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &FactorX, &FactorY) )
|
||||
return NULL;
|
||||
self->obj->Scale(FactorX, FactorY);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetBlendMode(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetBlendMode((sf::Blend::Mode)PyLong_AsUnsignedLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfDrawable_SetPosition(PySfDrawable* self, PyObject *args)
|
||||
{
|
||||
float Left, Top;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &Left, &Top) )
|
||||
return NULL;
|
||||
self->obj->SetPosition(Left, Top);
|
||||
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[] = {
|
||||
{"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 */
|
||||
};
|
||||
|
||||
PyTypeObject PySfDrawableType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Drawable", /*tp_name*/
|
||||
sizeof(PySfDrawable), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfDrawable_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*/
|
||||
"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 */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfDrawable_methods, /* tp_methods */
|
||||
PySfDrawable_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfDrawable_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfDrawable_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
54
python/src/Drawable.hpp
Normal file
54
python/src/Drawable.hpp
Normal file
|
@ -0,0 +1,54 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYDRAWABLE_H
|
||||
#define __PYDRAWABLE_H
|
||||
|
||||
#include <SFML/Graphics/Drawable.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "RenderWindow.hpp"
|
||||
|
||||
|
||||
class CustomDrawable : public sf::Drawable
|
||||
{
|
||||
protected :
|
||||
virtual void Render(sf::RenderTarget& Target) const;
|
||||
public :
|
||||
PySfRenderWindow *RenderWindow;
|
||||
PyObject *RenderFunction;
|
||||
};
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
CustomDrawable *obj;
|
||||
} PySfDrawable;
|
||||
|
||||
#endif
|
||||
|
844
python/src/Event.cpp
Normal file
844
python/src/Event.cpp
Normal file
|
@ -0,0 +1,844 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Event.hpp"
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
// Text Events Parameters
|
||||
////////////////////////////////
|
||||
|
||||
PyMemberDef PySfEventText_members[] = {
|
||||
{(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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventText_dealloc(PySfEventText* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
PyTypeObject PySfEventTextType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event.Text", /*tp_name*/
|
||||
sizeof(PySfEventText), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventText_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*/
|
||||
"Text Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventText_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventText_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventText_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
|
||||
/////////////////////////////////////
|
||||
// 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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventKey_dealloc(PySfEventKey* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
PyMemberDef PySfEventKey_members[] = {
|
||||
{(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 */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventKeyType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event.Key", /*tp_name*/
|
||||
sizeof(PySfEventKey), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventKey_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*/
|
||||
"Key Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventKey_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventKey_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventKey_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// 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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventMouseMove_dealloc(PySfEventMouseMove *self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventMouseMove_members[] = {
|
||||
{(char *)"X", T_INT, offsetof(PySfEventMouseMove, X), RO, (char *)""},
|
||||
{(char *)"Y", T_INT, offsetof(PySfEventMouseMove, Y), RO, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventMouseMoveType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event.MouseMove", /*tp_name*/
|
||||
sizeof(PySfEventMouseMove), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventMouseMove_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*/
|
||||
"MouseMove Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventMouseMove_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventMouseMove_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventMouseMove_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// 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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventMouseButton_dealloc(PySfEventMouseButton* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventMouseButton_members[] = {
|
||||
{(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 */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventMouseButtonType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event.MouseButton", /*tp_name*/
|
||||
sizeof(PySfEventMouseButton), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventMouseButton_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*/
|
||||
"MouseButton Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventMouseButton_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventMouseButton_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventMouseButton_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////
|
||||
// MouseWheel Events Parameters
|
||||
////////////////////////////////
|
||||
|
||||
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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
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*/
|
||||
"Event.MouseWheel", /*tp_name*/
|
||||
sizeof(PySfEventMouseWheel), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventMouseWheel_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*/
|
||||
"MouseWheel Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventMouseWheel_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventMouseWheel_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventMouseWheel_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// 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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventJoyMove_dealloc(PySfEventJoyMove* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventJoyMove_members[] = {
|
||||
{(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 */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventJoyMoveType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event.JoyMove", /*tp_name*/
|
||||
sizeof(PySfEventJoyMove), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventJoyMove_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*/
|
||||
"JoyMove Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventJoyMove_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventJoyMove_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventJoyMove_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// 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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventJoyButton_dealloc(PySfEventJoyButton* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
|
||||
PyMemberDef PySfEventJoyButton_members[] = {
|
||||
{(char *)"JoystickId", T_UINT, offsetof(PySfEventJoyButton, JoystickId), RO, (char *)""},
|
||||
{(char *)"Button", T_UINT, offsetof(PySfEventJoyButton, Button), RO, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventJoyButtonType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event.JoyButton", /*tp_name*/
|
||||
sizeof(PySfEventJoyButton), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventJoyButton_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*/
|
||||
"JoyButton Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventJoyButton_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventJoyButton_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventJoyButton_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// 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)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
void
|
||||
PySfEventSize_dealloc(PySfEventSize* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
PyMemberDef PySfEventSize_members[] = {
|
||||
{(char *)"Width", T_UINT, offsetof(PySfEventSize, Width), RO, (char *)""},
|
||||
{(char *)"Height", T_UINT, offsetof(PySfEventSize, Height), RO, (char *)""},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventSizeType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event.Size", /*tp_name*/
|
||||
sizeof(PySfEventSize), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEventSize_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*/
|
||||
"Size Events Parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
0, /* tp_methods */
|
||||
PySfEventSize_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEventSize_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEventSize_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////
|
||||
// sf.Event
|
||||
////////////////////////////////////
|
||||
|
||||
|
||||
static int
|
||||
PySfEvent_init(PySfEvent *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
self->obj = new sf::Event();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfEvent_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfEvent *self;
|
||||
|
||||
self = (PySfEvent *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static void
|
||||
PySfEvent_dealloc(PySfEvent* self)
|
||||
{
|
||||
Py_DECREF(self->Text);
|
||||
Py_DECREF(self->Key);
|
||||
Py_DECREF(self->MouseMove);
|
||||
Py_DECREF(self->MouseButton);
|
||||
Py_DECREF(self->MouseWheel);
|
||||
Py_DECREF(self->JoyMove);
|
||||
Py_DECREF(self->JoyButton);
|
||||
Py_DECREF(self->Size);
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyMemberDef PySfEvent_members[] = {
|
||||
{(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 */
|
||||
};
|
||||
|
||||
static PyMethodDef PySfEvent_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfEventType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Event", /*tp_name*/
|
||||
sizeof(PySfEvent), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfEvent_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*/
|
||||
"sf.Event defines a system event and its parameters", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfEvent_methods, /* tp_methods */
|
||||
PySfEvent_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfEvent_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfEvent_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
void
|
||||
PySfEvent_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::Event::KeyReleased);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "KeyReleased", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::LostFocus);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "LostFocus", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::GainedFocus);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "GainedFocus", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::KeyPressed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "KeyPressed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::MouseWheelMoved);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseWheelMoved", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::TextEntered);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "TextEntered", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::MouseMoved);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseMoved", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::JoyButtonPressed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonPressed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::MouseButtonReleased);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonReleased", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::Closed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "Closed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::MouseButtonPressed);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "MouseButtonPressed", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::JoyMoved);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "JoyMoved", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Event::JoyButtonReleased);
|
||||
PyDict_SetItemString(PySfEventType.tp_dict, "JoyButtonReleased", obj);
|
||||
Py_DECREF(obj);
|
||||
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);
|
||||
}
|
||||
|
108
python/src/Event.hpp
Normal file
108
python/src/Event.hpp
Normal file
|
@ -0,0 +1,108 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYEVENT_HPP
|
||||
#define __PYEVENT_HPP
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
unsigned int short Unicode;
|
||||
} PySfEventText;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
PyObject *Alt;
|
||||
PyObject *Control;
|
||||
PyObject *Shift;
|
||||
unsigned int Code;
|
||||
} PySfEventKey;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
int X;
|
||||
int Y;
|
||||
} PySfEventMouseMove;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
unsigned int Button;
|
||||
int X;
|
||||
int Y;
|
||||
} PySfEventMouseButton;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
int Delta;
|
||||
} PySfEventMouseWheel;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int JoystickId;
|
||||
unsigned int Axis;
|
||||
float Position;
|
||||
} PySfEventJoyMove;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int JoystickId;
|
||||
unsigned int Button;
|
||||
} PySfEventJoyButton;
|
||||
|
||||
typedef struct
|
||||
{
|
||||
PyObject_HEAD
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
} PySfEventSize;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
PySfEventText *Text;
|
||||
PySfEventKey *Key;
|
||||
PySfEventMouseMove *MouseMove;
|
||||
PySfEventMouseButton *MouseButton;
|
||||
PySfEventMouseWheel *MouseWheel;
|
||||
PySfEventJoyMove *JoyMove;
|
||||
PySfEventJoyButton *JoyButton;
|
||||
PySfEventSize *Size;
|
||||
unsigned int Type;
|
||||
sf::Event *obj;
|
||||
} PySfEvent;
|
||||
|
||||
void
|
||||
PySfEvent_InitConst();
|
||||
|
||||
#endif
|
219
python/src/Font.cpp
Normal file
219
python/src/Font.cpp
Normal file
|
@ -0,0 +1,219 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Font.hpp"
|
||||
#include "Glyph.hpp"
|
||||
|
||||
static PyMemberDef PySfFont_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfFont_dealloc(PySfFont *self)
|
||||
{
|
||||
if (self->Owner)
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfFont *self;
|
||||
|
||||
self = (PySfFont *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Owner = true;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfFont_init(PySfFont *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
self->obj = new sf::Font();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_LoadFromFile(PySfFont* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Filename", "Charsize", "Charset", NULL};
|
||||
unsigned int Charsize=30;
|
||||
char *Filename;
|
||||
char *CharsetTmp = NULL;
|
||||
int CharsetSize;
|
||||
bool Result;
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s|Is#", (char **)kwlist, &Filename, &Charsize, &CharsetTmp, &CharsetSize))
|
||||
return NULL;
|
||||
|
||||
if (CharsetTmp)
|
||||
{
|
||||
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, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Data", "Charsize", "Charset", NULL};
|
||||
unsigned int Charsize=30, Size;
|
||||
char *Data;
|
||||
char *CharsetTmp = NULL;
|
||||
int CharsetSize;
|
||||
bool Result;
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "s#|Is#", (char **)kwlist, &Data, &Size, &Charsize, &CharsetTmp, &CharsetSize))
|
||||
return NULL;
|
||||
|
||||
if (CharsetTmp)
|
||||
{
|
||||
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;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFont_GetDefaultFont(PySfFont* self, PyObject *args)
|
||||
{
|
||||
PySfFont *DefaultFont = GetNewPySfFont();
|
||||
DefaultFont->Owner = false;
|
||||
DefaultFont->obj = (sf::Font *)&(sf::Font::GetDefaultFont());
|
||||
return (PyObject *)DefaultFont;
|
||||
}
|
||||
|
||||
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 | 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*/
|
||||
(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*/
|
||||
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.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 *
|
||||
GetNewPySfFont()
|
||||
{
|
||||
return (PySfFont *)PySfFont_new(&PySfFontType, NULL, NULL);
|
||||
}
|
||||
|
||||
|
46
python/src/Font.hpp
Normal file
46
python/src/Font.hpp
Normal file
|
@ -0,0 +1,46 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYFONT_HPP
|
||||
#define __PYFONT_HPP
|
||||
|
||||
#include <SFML/Graphics/Font.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool Owner;
|
||||
sf::Font *obj;
|
||||
} PySfFont;
|
||||
|
||||
PySfFont *
|
||||
GetNewPySfFont();
|
||||
|
||||
#endif
|
158
python/src/Glyph.cpp
Normal file
158
python/src/Glyph.cpp
Normal file
|
@ -0,0 +1,158 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "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);
|
||||
}
|
||||
|
56
python/src/Glyph.hpp
Normal file
56
python/src/Glyph.hpp
Normal file
|
@ -0,0 +1,56 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __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
|
419
python/src/Image.cpp
Normal file
419
python/src/Image.cpp
Normal file
|
@ -0,0 +1,419 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Image.hpp"
|
||||
#include "RenderWindow.hpp"
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfIntRectType;
|
||||
extern PyTypeObject PySfRenderWindowType;
|
||||
|
||||
static PyMemberDef PySfImage_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfImage_dealloc(PySfImage* self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfImage *self;
|
||||
|
||||
self = (PySfImage *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfImage_Create(PySfImage* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfColor *ColorTmp=NULL;
|
||||
sf::Color *Color;
|
||||
unsigned int Width=0, Height=0;
|
||||
const char *kwlist[] = {"Width", "Height", "Color", NULL};
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|IIO!", (char **)kwlist, &Width, &Height, &PySfColorType, &ColorTmp))
|
||||
return NULL;
|
||||
|
||||
if (ColorTmp)
|
||||
{
|
||||
Color = ColorTmp->obj;
|
||||
PySfColorUpdate(ColorTmp);
|
||||
self->obj->Create(Width, Height, *Color);
|
||||
}
|
||||
else
|
||||
self->obj->Create(Width, Height);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_CopyScreen(PySfImage* self, PyObject *args)
|
||||
{
|
||||
// bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));
|
||||
PySfRenderWindow *RenderWindow;
|
||||
PySfIntRect *SourceRect=NULL;
|
||||
bool Result;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "O!|O!", &PySfRenderWindowType, &RenderWindow, &PySfIntRectType, &SourceRect))
|
||||
return NULL;
|
||||
|
||||
|
||||
if (SourceRect)
|
||||
{
|
||||
PySfIntRectUpdateObj(SourceRect);
|
||||
Result = self->obj->CopyScreen(*(RenderWindow->obj), *(SourceRect->obj));
|
||||
}
|
||||
else
|
||||
Result = self->obj->CopyScreen(*(RenderWindow->obj));
|
||||
if (Result)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_SetPixel(PySfImage* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfColor *ColorTmp=NULL;
|
||||
sf::Color *Color;
|
||||
unsigned int x=0, y=0;
|
||||
const char *kwlist[] = {"x", "y", "Color", NULL};
|
||||
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "II|O!", (char **)kwlist, &x, &y, &PySfColorType, &ColorTmp))
|
||||
return NULL;
|
||||
|
||||
|
||||
if (ColorTmp)
|
||||
{
|
||||
Color = ColorTmp->obj;
|
||||
PySfColorUpdate(ColorTmp);
|
||||
self->obj->SetPixel(x, y, *Color);
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetPixel(PySfImage* self, PyObject *args)
|
||||
{
|
||||
PySfColor *Color;
|
||||
unsigned int x=0, y=0;
|
||||
|
||||
|
||||
if (! PyArg_ParseTuple(args, "II", &x, &y))
|
||||
return NULL;
|
||||
|
||||
|
||||
Color = GetNewPySfColor();
|
||||
Color->obj = new sf::Color(self->obj->GetPixel(x, y));
|
||||
Color->r = Color->obj->r;
|
||||
Color->g = Color->obj->g;
|
||||
Color->b = Color->obj->b;
|
||||
Color->a = Color->obj->a;
|
||||
|
||||
return (PyObject *)Color;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_CreateMaskFromColor(PySfImage* self, PyObject *args)
|
||||
{
|
||||
PySfColor *ColorTmp= (PySfColor *)args;
|
||||
sf::Color *Color;
|
||||
|
||||
if ( ! PyObject_TypeCheck(ColorTmp, &PySfColorType))
|
||||
PyErr_SetString(PyExc_ValueError, "Argument must be a sf.Color");
|
||||
Color = ColorTmp->obj;
|
||||
PySfColorUpdate(ColorTmp);
|
||||
self->obj->CreateMaskFromColor(*Color);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_LoadFromMemory(PySfImage* self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes;
|
||||
char *Data;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "s#", &Data, &SizeInBytes))
|
||||
return NULL;
|
||||
|
||||
if (self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_LoadFromPixels(PySfImage* self, PyObject *args)
|
||||
{
|
||||
unsigned int Width, Height, Size;
|
||||
char *Data;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "IIs#", &Width, &Height, &Data, &Size))
|
||||
return NULL;
|
||||
|
||||
self->obj->LoadFromPixels(Width, Height, (sf::Uint8*) Data);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetPixels(PySfImage *self)
|
||||
{
|
||||
return PyString_FromStringAndSize((const char *)(self->obj->GetPixelsPtr()), self->obj->GetWidth()*self->obj->GetHeight()*4);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_LoadFromFile (PySfImage *self, PyObject *args)
|
||||
{
|
||||
char *path = PyString_AsString(args);
|
||||
|
||||
if (self->obj->LoadFromFile(path))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_SaveToFile (PySfImage *self, PyObject *args)
|
||||
{
|
||||
char *path = PyString_AsString(args);
|
||||
|
||||
if (self->obj->SaveToFile(path))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfImage_init(PySfImage *self, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject *
|
||||
PySfImage_Bind(PySfImage *self)
|
||||
{
|
||||
self->obj->Bind();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_SetSmooth (PySfImage *self, PyObject *args)
|
||||
{
|
||||
bool arg=false;
|
||||
if (PyObject_IsTrue(args))
|
||||
arg = true;
|
||||
self->obj->SetSmooth(arg);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetWidth(PySfImage *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetWidth());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetHeight(PySfImage *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetHeight());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetValidTextureSize(PySfImage* self, PyObject *args)
|
||||
{
|
||||
unsigned long S = PyLong_AsUnsignedLong(args);
|
||||
return PyLong_FromUnsignedLong(sf::Image::GetValidTextureSize(S));
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_GetTexCoords(PySfImage* self, PyObject *args)
|
||||
{
|
||||
PySfIntRect *RectArg = NULL;
|
||||
bool Adjust = false;
|
||||
PyObject *AdjustObj = NULL;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "O!|O", &PySfIntRectType, &RectArg, &AdjustObj))
|
||||
return NULL;
|
||||
|
||||
if (PyObject_IsTrue(AdjustObj))
|
||||
Adjust = true;
|
||||
|
||||
PySfFloatRect *Rect;
|
||||
|
||||
Rect = GetNewPySfFloatRect();
|
||||
Rect->obj = new sf::FloatRect ( self->obj->GetTexCoords(*(RectArg->obj), Adjust) );
|
||||
Rect->Left = Rect->obj->Left;
|
||||
Rect->Top = Rect->obj->Top;
|
||||
Rect->Right = Rect->obj->Right;
|
||||
Rect->Bottom = Rect->obj->Bottom;
|
||||
|
||||
return (PyObject *)Rect;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfImage_Copy(PySfImage* self, PyObject *args);
|
||||
|
||||
static PyMethodDef PySfImage_methods[] = {
|
||||
{"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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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()
|
||||
{
|
||||
return PyObject_New(PySfImage, &PySfImageType);
|
||||
}
|
||||
|
49
python/src/Image.hpp
Normal file
49
python/src/Image.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYIMAGE_HPP
|
||||
#define __PYIMAGE_HPP
|
||||
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Color.hpp"
|
||||
#include "Rect.hpp"
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Image *obj;
|
||||
} PySfImage;
|
||||
|
||||
PySfImage *
|
||||
GetNewPySfImage();
|
||||
|
||||
#endif
|
||||
|
167
python/src/Input.cpp
Normal file
167
python/src/Input.cpp
Normal file
|
@ -0,0 +1,167 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Input.hpp"
|
||||
|
||||
|
||||
static PyMemberDef PySfInput_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfInput_dealloc(PySfInput *self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfInput_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfInput *self;
|
||||
|
||||
self = (PySfInput *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
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().");
|
||||
return -1;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_IsKeyDown(PySfInput *self, PyObject *args)
|
||||
{
|
||||
if (self->obj->IsKeyDown( (sf::Key::Code) PyInt_AsLong(args) ))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_IsMouseButtonDown(PySfInput *self, PyObject *args)
|
||||
{
|
||||
if (self->obj->IsMouseButtonDown( (sf::Mouse::Button) PyInt_AsLong(args) ))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_IsJoystickButtonDown(PySfInput *self, PyObject *args)
|
||||
{
|
||||
unsigned int JoyId, Button;
|
||||
if (! PyArg_ParseTuple (args, "II", &JoyId, &Button))
|
||||
return NULL;
|
||||
if (self->obj->IsJoystickButtonDown(JoyId, Button))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_GetMouseX(PySfInput *self)
|
||||
{
|
||||
return PyInt_FromLong(self->obj->GetMouseX());
|
||||
}
|
||||
static PyObject*
|
||||
PySfInput_GetMouseY(PySfInput *self)
|
||||
{
|
||||
return PyInt_FromLong(self->obj->GetMouseY());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfInput_GetJoystickAxis(PySfInput *self, PyObject *args)
|
||||
{
|
||||
unsigned int JoyId, Axis;
|
||||
if (! PyArg_ParseTuple (args, "II", &JoyId, &Axis))
|
||||
return NULL;
|
||||
return PyFloat_FromDouble(self->obj->GetJoystickAxis(JoyId, (sf::Joy::Axis) Axis));
|
||||
}
|
||||
|
||||
static PyMethodDef PySfInput_methods[] = {
|
||||
{"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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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 *
|
||||
GetNewPySfInput()
|
||||
{
|
||||
return PyObject_New(PySfInput, &PySfInputType);
|
||||
}
|
||||
|
43
python/src/Input.hpp
Normal file
43
python/src/Input.hpp
Normal file
|
@ -0,0 +1,43 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYINPUT_HPP
|
||||
#define __PYINPUT_HPP
|
||||
|
||||
#include <SFML/Window/Input.hpp>
|
||||
#include <SFML/Window/Event.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Input *obj;
|
||||
} PySfInput;
|
||||
|
||||
PySfInput *
|
||||
GetNewPySfInput();
|
||||
|
||||
#endif
|
141
python/src/Joy.cpp
Normal file
141
python/src/Joy.cpp
Normal file
|
@ -0,0 +1,141 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Joy.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfJoy;
|
||||
|
||||
|
||||
|
||||
static PyMemberDef PySfJoy_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfJoy_dealloc(PySfJoy *self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfJoy_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfJoy *self;
|
||||
|
||||
self = (PySfJoy *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfJoy_init(PySfJoy *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfJoy_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfJoyType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::Joy::AxisX);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisX", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Joy::AxisY);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisY", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Joy::AxisZ);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisZ", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Joy::AxisR);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisR", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Joy::AxisU);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisU", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Joy::AxisV);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisV", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Joy::AxisPOV);
|
||||
PyDict_SetItemString(PySfJoyType.tp_dict, "AxisPOV", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
31
python/src/Joy.hpp
Normal file
31
python/src/Joy.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYJOY_HPP
|
||||
#define __PYJOY_HPP
|
||||
|
||||
void
|
||||
PySfJoy_InitConst();
|
||||
|
||||
#endif
|
423
python/src/Key.cpp
Normal file
423
python/src/Key.cpp
Normal file
|
@ -0,0 +1,423 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Key.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfKey;
|
||||
|
||||
|
||||
|
||||
static PyMemberDef PySfKey_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfKey_dealloc(PySfKey *self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfKey_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfKey *self;
|
||||
|
||||
self = (PySfKey *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfKey_init(PySfKey *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfKey_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfKeyType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::Key::Numpad2);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad2", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad3);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad3", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad0);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad0", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad1);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad6);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad6", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad7);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad7", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad4);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad4", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad5);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad5", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad8);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad8", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Numpad9);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Numpad9", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::RAlt);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RAlt", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::PageUp);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "PageUp", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Multiply);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Multiply", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::D);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "D", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::SemiColon);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "SemiColon", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::H);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "H", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::L);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "L", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::P);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "P", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num7);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num7", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::T);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "T", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::X);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "X", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::RSystem);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RSystem", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F5);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F5", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num4);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num4", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num5);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num5", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num6);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num6", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Right);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Right", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num0);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num0", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num1);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num2);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num2", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num3);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num3", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::LControl);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LControl", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num8);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num8", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Num9);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Num9", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Tab);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Tab", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::RBracket);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RBracket", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::End);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "End", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::BackSlash);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "BackSlash", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::LShift);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LShift", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::E);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "E", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::C);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "C", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::G);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "G", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::K);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "K", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Up);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Up", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::O);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "O", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::S);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "S", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::W);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "W", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F12);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F12", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F13);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F13", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F10);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F10", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F11);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F11", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F14);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F14", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Delete);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Delete", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Back);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Back", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Tilde);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Tilde", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Home);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Home", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Pause);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Pause", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Add);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Add", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F15);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F15", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Subtract);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Subtract", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::B);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "B", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::J);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "J", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::N);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "N", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::LBracket);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LBracket", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::R);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "R", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::V);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "V", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::LSystem);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LSystem", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Z);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Z", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Left);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Left", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F1);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F2);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F2", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F3);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F3", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F4);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F4", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Divide);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Divide", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F6);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F6", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F7);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F7", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F8);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F8", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::F9);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "F9", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Period);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Period", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Down);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Down", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::PageDown);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "PageDown", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Space);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Space", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Menu);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Menu", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::RControl);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RControl", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Slash);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Slash", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Return);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Return", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Quote);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Quote", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::A);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "A", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Insert);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Insert", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::RShift);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "RShift", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::I);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "I", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Escape);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Escape", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::M);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "M", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Equal);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Equal", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Q);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Q", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::U);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "U", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Y);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Y", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Dash);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Dash", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::Comma);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "Comma", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Key::LAlt);
|
||||
PyDict_SetItemString(PySfKeyType.tp_dict, "LAlt", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
31
python/src/Key.hpp
Normal file
31
python/src/Key.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYKEY_HPP
|
||||
#define __PYKEY_HPP
|
||||
|
||||
void
|
||||
PySfKey_InitConst();
|
||||
|
||||
#endif
|
160
python/src/Listener.cpp
Normal file
160
python/src/Listener.cpp
Normal file
|
@ -0,0 +1,160 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Listener.hpp"
|
||||
|
||||
|
||||
static PyMemberDef PySfListener_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfListener_dealloc(PySfListener* self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfListener *self;
|
||||
|
||||
self = (PySfListener *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfListener_init(PySfListener *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfListener_SetGlobalVolume(PySfListener* self, PyObject *args)
|
||||
{
|
||||
sf::Listener::SetGlobalVolume(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_GetGlobalVolume(PySfListener* self)
|
||||
{
|
||||
return PyFloat_FromDouble(sf::Listener::GetGlobalVolume());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_SetPosition(PySfListener* self, PyObject *args)
|
||||
{
|
||||
float X, Y, Z;
|
||||
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z))
|
||||
return NULL;
|
||||
sf::Listener::SetPosition(X, Y, Z);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfListener_GetPosition(PySfListener *self)
|
||||
{
|
||||
sf::Vector3f Vect = sf::Listener::GetPosition();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfListener_SetTarget(PySfListener* self, PyObject *args)
|
||||
{
|
||||
float X, Y, Z;
|
||||
if (! PyArg_ParseTuple(args, "fff", &X, &Y, &Z))
|
||||
return NULL;
|
||||
sf::Listener::SetTarget(X, Y, Z);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfListener_GetTarget(PySfListener *self)
|
||||
{
|
||||
sf::Vector3f Vect = sf::Listener::GetTarget();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
static PyMethodDef PySfListener_methods[] = {
|
||||
{"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*/
|
||||
"Listener", /*tp_name*/
|
||||
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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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 */
|
||||
};
|
||||
|
||||
|
41
python/src/Listener.hpp
Normal file
41
python/src/Listener.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYLISTENER_HPP
|
||||
#define __PYLISTENER_HPP
|
||||
|
||||
#include <SFML/Audio/Listener.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfListener;
|
||||
|
||||
#endif
|
135
python/src/Mouse.cpp
Normal file
135
python/src/Mouse.cpp
Normal file
|
@ -0,0 +1,135 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <SFML/Window/Event.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Mouse.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfMouse;
|
||||
|
||||
|
||||
|
||||
static PyMemberDef PySfMouse_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfMouse_dealloc(PySfMouse *self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfMouse_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfMouse *self;
|
||||
|
||||
self = (PySfMouse *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfMouse_init(PySfMouse *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfMouse_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfMouseType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::Mouse::Left);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Left", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Mouse::Right);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Right", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Mouse::Middle);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "Middle", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Mouse::XButton1);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton1", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Mouse::XButton2);
|
||||
PyDict_SetItemString(PySfMouseType.tp_dict, "XButton2", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
31
python/src/Mouse.hpp
Normal file
31
python/src/Mouse.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYMOUSE_HPP
|
||||
#define __PYMOUSE_HPP
|
||||
|
||||
void
|
||||
PySfMouse_InitConst();
|
||||
|
||||
#endif
|
152
python/src/Music.cpp
Normal file
152
python/src/Music.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Music.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfSoundStreamType;
|
||||
|
||||
|
||||
static PyMemberDef PySfMusic_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfMusic_dealloc(PySfMusic *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfMusic_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfMusic *self;
|
||||
|
||||
self = (PySfMusic *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfMusic_init(PySfMusic *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
unsigned int BufferSize=44100;
|
||||
if (PyTuple_Size(args) == 1)
|
||||
{
|
||||
if ( !PyArg_ParseTuple(args, "I", &BufferSize))
|
||||
return -1;
|
||||
}
|
||||
self->obj = new sf::Music(BufferSize);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfMusic_OpenFromMemory(PySfMusic *self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes;
|
||||
char *Data;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "s#", &Data, &SizeInBytes))
|
||||
return NULL;
|
||||
|
||||
if (self->obj->OpenFromMemory(Data, (std::size_t) SizeInBytes))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfMusic_OpenFromFile(PySfMusic *self, PyObject *args)
|
||||
{
|
||||
char *path = PyString_AsString(args);
|
||||
if (self->obj->OpenFromFile(path))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfMusic_GetDuration(PySfMusic *self)
|
||||
{
|
||||
return PyFloat_FromDouble((double)(self->obj->GetDuration()));
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfMusic_methods[] = {
|
||||
{"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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Music defines a big sound played using streaming, so usually what we call a music :)", /* tp_doc */
|
||||
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 */
|
||||
};
|
||||
|
||||
|
41
python/src/Music.hpp
Normal file
41
python/src/Music.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYMUSIC_HPP
|
||||
#define __PYMUSIC_HPP
|
||||
|
||||
#include <SFML/Audio/Music.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Music *obj;
|
||||
} PySfMusic;
|
||||
|
||||
#endif
|
211
python/src/PostFX.cpp
Normal file
211
python/src/PostFX.cpp
Normal file
|
@ -0,0 +1,211 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "PostFX.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
static PyMemberDef PySfPostFX_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfPostFX_dealloc(PySfPostFX *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfPostFX *self;
|
||||
|
||||
self = (PySfPostFX *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_LoadFromFile (PySfPostFX *self, PyObject *args)
|
||||
{
|
||||
if (self->obj->LoadFromFile(PyString_AsString(args)))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_LoadFromMemory (PySfPostFX *self, PyObject *args)
|
||||
{
|
||||
if (self->obj->LoadFromMemory(PyString_AsString(args)))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfPostFX_init(PySfPostFX *self, PyObject *args);
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_SetParameter(PySfPostFX* self, PyObject *args)
|
||||
{
|
||||
char *Name;
|
||||
float X, Y, Z, W;
|
||||
int size = PyTuple_Size(args);
|
||||
if (! PyArg_ParseTuple(args, "sf|fff", &Name, &X, &Y, &Z, &W))
|
||||
return NULL;
|
||||
|
||||
switch (size)
|
||||
{
|
||||
case 2:
|
||||
self->obj->SetParameter(Name, X);
|
||||
break;
|
||||
case 3:
|
||||
self->obj->SetParameter(Name, X, Y);
|
||||
break;
|
||||
case 4:
|
||||
self->obj->SetParameter(Name, X, Y, Z);
|
||||
break;
|
||||
case 5:
|
||||
self->obj->SetParameter(Name, X, Y, Z, W);
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_SetTexture(PySfPostFX* self, PyObject *args)
|
||||
{
|
||||
PySfImage *Image = NULL;
|
||||
char *Name;
|
||||
if (! PyArg_ParseTuple(args, "s|O", &Name, &Image))
|
||||
return NULL;
|
||||
if (Image == NULL || (PyObject *)Image == Py_None)
|
||||
self->obj->SetTexture(Name, NULL);
|
||||
else
|
||||
{
|
||||
if (!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;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfPostFX_CanUsePostFX(PySfPostFX* self, PyObject *args)
|
||||
{
|
||||
if (sf::PostFX::CanUsePostFX())
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfPostFX_methods[] = {
|
||||
{"LoadFromFile", (PyCFunction)PySfPostFX_LoadFromFile, METH_O, "LoadFromFile(Filename)\nLoad the effect from a file."},
|
||||
{"LoadFromMemory", (PyCFunction)PySfPostFX_LoadFromMemory, METH_O, "LoadFromMemory(Effect)\nLoad the effect from a text in memory."},
|
||||
{"SetParameter", (PyCFunction)PySfPostFX_SetParameter, METH_VARARGS, "SetParameter(X), SetParameter(X, Y), SetParameter(X, Y, Z), SetParameter(X, Y, Z, W)\nChange a parameter of the effect.\n\
|
||||
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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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;
|
||||
}
|
||||
|
42
python/src/PostFX.hpp
Normal file
42
python/src/PostFX.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYPOSTFX_HPP
|
||||
#define __PYPOSTFX_HPP
|
||||
|
||||
#include <SFML/Graphics/PostFX.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Drawable.hpp"
|
||||
#include "Image.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::PostFX *obj;
|
||||
} PySfPostFX;
|
||||
|
||||
#endif
|
437
python/src/Rect.cpp
Normal file
437
python/src/Rect.cpp
Normal file
|
@ -0,0 +1,437 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Rect.hpp"
|
||||
|
||||
static PyMemberDef PySfIntRect_members[] = {
|
||||
{(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[] = {
|
||||
{(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 */
|
||||
};
|
||||
|
||||
static void
|
||||
PySfIntRect_dealloc(PySfIntRect* self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static void
|
||||
PySfFloatRect_dealloc(PySfFloatRect* self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfIntRect *self;
|
||||
|
||||
self = (PySfIntRect *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfFloatRect *self;
|
||||
|
||||
self = (PySfFloatRect *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfIntRect_init(PySfIntRect *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
|
||||
int Left, Top, Right, Bottom;
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "iiii", (char **)kwlist, &Left, &Top, &Right, &Bottom))
|
||||
return -1;
|
||||
|
||||
self->Left = Left;
|
||||
self->Top = Top;
|
||||
self->Right = Right;
|
||||
self->Bottom = Bottom;
|
||||
self->obj = new sf::IntRect(Left, Top, Right, Bottom);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_GetWidth(PySfIntRect *self)
|
||||
{
|
||||
PySfIntRectUpdateObj(self);
|
||||
return PyInt_FromLong(self->obj->GetWidth());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_GetHeight(PySfIntRect *self)
|
||||
{
|
||||
PySfIntRectUpdateObj(self);
|
||||
return PyInt_FromLong(self->obj->GetHeight());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Contains(PySfIntRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Intersects(PySfIntRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_GetWidth(PySfFloatRect *self)
|
||||
{
|
||||
PySfFloatRectUpdateObj(self);
|
||||
return PyFloat_FromDouble(self->obj->GetWidth());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_GetHeight(PySfFloatRect *self)
|
||||
{
|
||||
PySfFloatRectUpdateObj(self);
|
||||
return PyFloat_FromDouble(self->obj->GetHeight());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Contains(PySfFloatRect* self, PyObject *args);
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args);
|
||||
|
||||
static int
|
||||
PySfFloatRect_init(PySfFloatRect *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"Left", "Top", "Right", "Bottom", NULL};
|
||||
float Left, Top, Right, Bottom;
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "ffff", (char **)kwlist, &Left, &Top, &Right, &Bottom))
|
||||
return -1;
|
||||
|
||||
self->Left = Left;
|
||||
self->Top = Top;
|
||||
self->Right = Right;
|
||||
self->Bottom = Bottom;
|
||||
self->obj = new sf::FloatRect(Left, Top, Right, Bottom);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Offset(PySfIntRect* self, PyObject *args)
|
||||
{
|
||||
int OffsetX, OffsetY;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ii", &OffsetX, &OffsetY))
|
||||
return NULL;
|
||||
|
||||
PySfIntRectUpdateObj(self);
|
||||
self->obj->Offset(OffsetX, OffsetY);
|
||||
PySfIntRectUpdateSelf(self);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Offset(PySfFloatRect* self, PyObject *args)
|
||||
{
|
||||
float OffsetX, OffsetY;
|
||||
|
||||
if (!PyArg_ParseTuple(args, "ff", &OffsetX, &OffsetY))
|
||||
return NULL;
|
||||
|
||||
PySfFloatRectUpdateObj(self);
|
||||
self->obj->Offset(OffsetX, OffsetY);
|
||||
PySfFloatRectUpdateSelf(self);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfIntRect_methods[] = {
|
||||
{"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, "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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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)
|
||||
{
|
||||
float x=0, y=0;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "ff", &x, &y))
|
||||
return NULL;
|
||||
|
||||
PySfFloatRectUpdateObj(self);
|
||||
if (self->obj->Contains(x,y))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfFloatRect_Intersects(PySfFloatRect* self, PyObject *args)
|
||||
{
|
||||
PySfFloatRect *Rect=NULL, *OverlappingRect=NULL;
|
||||
bool result;
|
||||
|
||||
|
||||
if (! PyArg_ParseTuple(args, "O!|O!", &PySfFloatRectType, &Rect, &PySfFloatRectType, &OverlappingRect))
|
||||
return NULL;
|
||||
|
||||
PySfFloatRectUpdateObj(self);
|
||||
if (OverlappingRect)
|
||||
result = self->obj->Intersects(*(Rect->obj), (OverlappingRect->obj));
|
||||
else
|
||||
result = self->obj->Intersects(*(Rect->obj));
|
||||
|
||||
if (result)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Contains(PySfIntRect* self, PyObject *args)
|
||||
{
|
||||
unsigned int x=0, y=0;
|
||||
|
||||
PySfIntRectUpdateObj(self);
|
||||
if (! PyArg_ParseTuple(args, "II", &x, &y))
|
||||
return NULL;
|
||||
|
||||
if (self->obj->Contains(x,y))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfIntRect_Intersects(PySfIntRect* self, PyObject *args)
|
||||
{
|
||||
PySfIntRect *Rect=NULL, *OverlappingRect=NULL;
|
||||
bool result;
|
||||
|
||||
PySfIntRectUpdateObj(self);
|
||||
if (! PyArg_ParseTuple(args, "O!|O!", &PySfIntRectType, &Rect, &PySfIntRectType, &OverlappingRect))
|
||||
return NULL;
|
||||
|
||||
if (OverlappingRect)
|
||||
result = self->obj->Intersects(*(Rect->obj), (OverlappingRect->obj));
|
||||
else
|
||||
result = self->obj->Intersects(*(Rect->obj));
|
||||
|
||||
if (result)
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
void
|
||||
PySfIntRectUpdateObj(PySfIntRect *self)
|
||||
{
|
||||
self->obj->Left = self->Left;
|
||||
self->obj->Right = self->Right;
|
||||
self->obj->Top = self->Top;
|
||||
self->obj->Bottom = self->Bottom;
|
||||
}
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateObj(PySfFloatRect *self)
|
||||
{
|
||||
self->obj->Left = self->Left;
|
||||
self->obj->Right = self->Right;
|
||||
self->obj->Top = self->Top;
|
||||
self->obj->Bottom = self->Bottom;
|
||||
}
|
||||
void
|
||||
PySfIntRectUpdateSelf(PySfIntRect *self)
|
||||
{
|
||||
self->Left = self->obj->Left;
|
||||
self->Right = self->obj->Right;
|
||||
self->Top = self->obj->Top;
|
||||
self->Bottom = self->obj->Bottom;
|
||||
}
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateSelf(PySfFloatRect *self)
|
||||
{
|
||||
self->Left = self->obj->Left;
|
||||
self->Right = self->obj->Right;
|
||||
self->Top = self->obj->Top;
|
||||
self->Bottom = self->obj->Bottom;
|
||||
}
|
||||
|
||||
PySfIntRect *
|
||||
GetNewPySfIntRect()
|
||||
{
|
||||
return PyObject_New(PySfIntRect, &PySfIntRectType);
|
||||
}
|
||||
|
||||
PySfFloatRect *
|
||||
GetNewPySfFloatRect()
|
||||
{
|
||||
return PyObject_New(PySfFloatRect, &PySfFloatRectType);
|
||||
}
|
||||
|
||||
|
73
python/src/Rect.hpp
Normal file
73
python/src/Rect.hpp
Normal file
|
@ -0,0 +1,73 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYRECT_HPP
|
||||
#define __PYRECT_HPP
|
||||
|
||||
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
int Left;
|
||||
int Right;
|
||||
int Top;
|
||||
int Bottom;
|
||||
sf::IntRect *obj;
|
||||
} PySfIntRect;
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
float Left;
|
||||
float Right;
|
||||
float Top;
|
||||
float Bottom;
|
||||
sf::FloatRect *obj;
|
||||
} PySfFloatRect;
|
||||
|
||||
PySfIntRect *
|
||||
GetNewPySfIntRect();
|
||||
|
||||
PySfFloatRect *
|
||||
GetNewPySfFloatRect();
|
||||
|
||||
void
|
||||
PySfIntRectUpdateObj(PySfIntRect *self);
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateObj(PySfFloatRect *self);
|
||||
|
||||
void
|
||||
PySfIntRectUpdateSelf(PySfIntRect *self);
|
||||
|
||||
void
|
||||
PySfFloatRectUpdateSelf(PySfFloatRect *self);
|
||||
|
||||
#endif
|
289
python/src/RenderWindow.cpp
Normal file
289
python/src/RenderWindow.cpp
Normal file
|
@ -0,0 +1,289 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "RenderWindow.hpp"
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "VideoMode.hpp"
|
||||
#include "Drawable.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Rect.hpp"
|
||||
#include "View.hpp"
|
||||
#include "Image.hpp"
|
||||
#include "Window.hpp"
|
||||
|
||||
#include "SFML/Window/WindowStyle.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfEventType;
|
||||
extern PyTypeObject PySfViewType;
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfWindowType;
|
||||
extern PyTypeObject PySfWindowSettingsType;
|
||||
extern PyTypeObject PySfVideoModeType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
static PyMemberDef PySfRenderWindow_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfRenderWindow_dealloc(PySfRenderWindow* self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfRenderWindow *self;
|
||||
|
||||
self = (PySfRenderWindow *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfRenderWindow_init(PySfRenderWindow *self, PyObject *args, PyObject *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)
|
||||
{
|
||||
PySfImage *Image;
|
||||
|
||||
Image = GetNewPySfImage();
|
||||
Image->obj = new sf::Image(self->obj->Capture());
|
||||
return (PyObject *)Image;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_ConvertCoords(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
unsigned int WindowX, WindowY;
|
||||
PySfView *PyTargetView = NULL;
|
||||
sf::View *TargetView = NULL;
|
||||
sf::Vector2f Vect;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "II|O!", &WindowX, &WindowY, &PySfViewType, &PyTargetView))
|
||||
return NULL;
|
||||
|
||||
if (PyTargetView)
|
||||
TargetView = PyTargetView->obj;
|
||||
|
||||
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)
|
||||
{
|
||||
if (!args)
|
||||
return NULL;
|
||||
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_GetDefaultView(PySfRenderWindow *self)
|
||||
{
|
||||
PySfView *View;
|
||||
|
||||
View = GetNewPySfView();
|
||||
View->Owner = false;
|
||||
View->obj = &(self->obj->GetDefaultView());
|
||||
|
||||
return (PyObject *)View;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_GetView(PySfRenderWindow *self)
|
||||
{
|
||||
PySfView *View;
|
||||
|
||||
View = GetNewPySfView();
|
||||
View->obj = new sf::View(self->obj->GetView());
|
||||
|
||||
return (PyObject *)View;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_PreserveOpenGLStates(PySfRenderWindow *self, PyObject *args)
|
||||
{
|
||||
bool Optimize = false;
|
||||
if (PyObject_IsTrue(args))
|
||||
Optimize = true;
|
||||
self->obj->PreserveOpenGLStates(Optimize);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfRenderWindow_SetView(PySfRenderWindow* self, PyObject *args)
|
||||
{
|
||||
PySfView *View = (PySfView *)args;
|
||||
if (! PyObject_TypeCheck(View, &PySfViewType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Argument is not a sfView");
|
||||
return NULL;
|
||||
}
|
||||
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[] = {
|
||||
{"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*/
|
||||
(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 | 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 */
|
||||
};
|
||||
|
||||
|
42
python/src/RenderWindow.hpp
Normal file
42
python/src/RenderWindow.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYRENDERWINDOW_HPP
|
||||
#define __PYRENDERWINDOW_HPP
|
||||
|
||||
#include <SFML/Graphics.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "WindowSettings.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::RenderWindow *obj;
|
||||
} PySfRenderWindow;
|
||||
|
||||
|
||||
#endif
|
396
python/src/Shape.cpp
Normal file
396
python/src/Shape.cpp
Normal file
|
@ -0,0 +1,396 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Shape.hpp"
|
||||
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include "Color.hpp"
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
static PyMemberDef PySfShape_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfShape_dealloc(PySfShape* self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfShape *self;
|
||||
|
||||
self = (PySfShape *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfShape_init(PySfShape *self, PyObject *args)
|
||||
{
|
||||
self->obj = new sf::Shape();
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
// void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_AddPoint(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
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!", (char **)kwlist, &X, &Y, &PySfColorType, &ColTmp, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
|
||||
if (ColTmp)
|
||||
{
|
||||
PySfColorUpdate(ColTmp);
|
||||
Col = ColTmp->obj;
|
||||
}
|
||||
else
|
||||
Col = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
self->obj->AddPoint(X, Y, *Col, *OutlineCol);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_SetOutlineWidth(PySfShape* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetOutlineWidth(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_GetOutlineWidth(PySfShape* self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetOutlineWidth());
|
||||
}
|
||||
|
||||
// static Shape Line(float X0, float Y0, float X1, float Y1, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_Line(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
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!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &Thickness, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
PySfColorUpdate(ColTmp);
|
||||
Line->obj = new sf::Shape(sf::Shape::Line(X0, Y0, X1, Y1, Thickness, *(ColTmp->obj), Outline, *OutlineCol));
|
||||
return (PyObject *)Line;
|
||||
}
|
||||
|
||||
// static Shape Rectangle(float X0, float Y0, float X1, float Y1, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_Rectangle(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
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!", (char **)kwlist, &X0, &Y0, &X1, &Y1, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
PySfColorUpdate(ColTmp);
|
||||
Rectangle->obj = new sf::Shape(sf::Shape::Rectangle(X0, Y0, X1, Y1, *(ColTmp->obj), Outline, *OutlineCol));
|
||||
return (PyObject *)Rectangle;
|
||||
}
|
||||
|
||||
// static Shape Circle(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));
|
||||
static PyObject *
|
||||
PySfShape_Circle(PySfShape* self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
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!", (char **)kwlist, &X, &Y, &Radius, &PySfColorType, &ColTmp, &Outline, &PySfColorType, &OutlineColTmp))
|
||||
return NULL;
|
||||
if (OutlineColTmp)
|
||||
{
|
||||
PySfColorUpdate(OutlineColTmp);
|
||||
OutlineCol = OutlineColTmp->obj;
|
||||
}
|
||||
else
|
||||
OutlineCol = (sf::Color *)&sf::Color::Black;
|
||||
|
||||
PySfColorUpdate(ColTmp);
|
||||
Circle->obj = new sf::Shape(sf::Shape::Circle(X, Y, Radius, *(ColTmp->obj), Outline, *OutlineCol));
|
||||
return (PyObject *)Circle;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_GetPointPosition(PySfShape* self, PyObject *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());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfShape_EnableFill(PySfShape* self, PyObject *args)
|
||||
{
|
||||
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 (PyObject_IsTrue(args))
|
||||
self->obj->EnableOutline(true);
|
||||
else
|
||||
self->obj->EnableOutline(false);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfShape_methods[] = {
|
||||
{"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\
|
||||
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\
|
||||
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\
|
||||
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 */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfShapeType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Shape", /*tp_name*/
|
||||
sizeof(PySfShape), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfShape_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*/
|
||||
"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 */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfShape_methods, /* tp_methods */
|
||||
PySfShape_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfShape_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfShape_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
||||
PySfShape *
|
||||
GetNewPySfShape()
|
||||
{
|
||||
return PyObject_New(PySfShape, &PySfShapeType);
|
||||
}
|
||||
|
45
python/src/Shape.hpp
Normal file
45
python/src/Shape.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSHAPE_HPP
|
||||
#define __PYSHAPE_HPP
|
||||
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Shape *obj;
|
||||
} PySfShape;
|
||||
|
||||
PySfShape *
|
||||
GetNewPySfShape();
|
||||
|
||||
#endif
|
33
python/src/Sleep.cpp
Normal file
33
python/src/Sleep.cpp
Normal file
|
@ -0,0 +1,33 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Sleep.hpp"
|
||||
|
||||
PyObject *
|
||||
PySFML_Sleep (PyObject *self, PyObject *args)
|
||||
{
|
||||
sf::Sleep(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
37
python/src/Sleep.hpp
Normal file
37
python/src/Sleep.hpp
Normal file
|
@ -0,0 +1,37 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSLEEP_HPP
|
||||
#define __PYSLEEP_HPP
|
||||
|
||||
#include <SFML/System/Sleep.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
PyObject *
|
||||
PySFML_Sleep (PyObject *self, PyObject *args);
|
||||
|
||||
#endif
|
339
python/src/Sound.cpp
Normal file
339
python/src/Sound.cpp
Normal file
|
@ -0,0 +1,339 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Sound.hpp"
|
||||
|
||||
#include "SoundBuffer.hpp"
|
||||
|
||||
extern PyTypeObject PySfSoundBufferType;
|
||||
|
||||
static PyMemberDef PySfSound_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfSound_dealloc(PySfSound *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSound_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSound *self;
|
||||
|
||||
self = (PySfSound *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfSound_init(PySfSound *self, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetBuffer(PySfSound *self, PyObject *args)
|
||||
{
|
||||
PySfSoundBuffer *Buffer = (PySfSoundBuffer *)args;
|
||||
if ( ! PyObject_TypeCheck(args, &PySfSoundBufferType))
|
||||
PyErr_SetString(PyExc_TypeError, "The argument must be a sfSoundBuffer.");
|
||||
|
||||
self->obj->SetBuffer(*(Buffer->obj));
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetLoop(PySfSound *self, PyObject *args)
|
||||
{
|
||||
if (PyObject_IsTrue(args))
|
||||
self->obj->SetLoop(true);
|
||||
else
|
||||
self->obj->SetLoop(false);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetPitch(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetPitch(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetMinDistance(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetMinDistance(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetAttenuation(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetAttenuation(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetVolume(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetVolume(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetPitch(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetPitch());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetMinDistance(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetMinDistance());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetAttenuation(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetAttenuation());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetVolume(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetVolume());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetPosition(PySfSound *self)
|
||||
{
|
||||
sf::Vector3f Vect = self->obj->GetPosition();
|
||||
return Py_BuildValue("fff", Vect.x, Vect.y, Vect.z);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetPlayingOffset(PySfSound *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetPlayingOffset());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetLoop(PySfSound *self)
|
||||
{
|
||||
if (self->obj->GetLoop())
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_Play(PySfSound *self)
|
||||
{
|
||||
self->obj->Play();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_Pause(PySfSound *self)
|
||||
{
|
||||
self->obj->Pause();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_Stop(PySfSound *self)
|
||||
{
|
||||
self->obj->Stop();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_GetStatus(PySfSound *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetStatus());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetPosition(PySfSound *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 *
|
||||
PySfSound_GetBuffer(PySfSound *self)
|
||||
{
|
||||
PySfSoundBuffer *Buffer;
|
||||
|
||||
Buffer = GetNewPySfSoundBuffer();
|
||||
Buffer->obj = new sf::SoundBuffer(*(self->obj->GetBuffer()));
|
||||
|
||||
return (PyObject *)Buffer;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSound_SetPlayingOffset(PySfSound *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetPlayingOffset(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfSound_methods[] = {
|
||||
{"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 */
|
||||
};
|
||||
|
||||
PyTypeObject PySfSoundType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Sound", /*tp_name*/
|
||||
sizeof(PySfSound), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSound_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*/
|
||||
"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 */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfSound_methods, /* tp_methods */
|
||||
PySfSound_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfSound_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
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()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::Sound::Stopped);
|
||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Stopped", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Sound::Paused);
|
||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Paused", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Sound::Playing);
|
||||
PyDict_SetItemString(PySfSoundType.tp_dict, "Playing", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
42
python/src/Sound.hpp
Normal file
42
python/src/Sound.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUND_HPP
|
||||
#define __PYSOUND_HPP
|
||||
|
||||
#include <SFML/Audio/Sound.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Sound *obj;
|
||||
} PySfSound;
|
||||
|
||||
void
|
||||
PySfSound_InitConst();
|
||||
|
||||
#endif
|
218
python/src/SoundBuffer.cpp
Normal file
218
python/src/SoundBuffer.cpp
Normal file
|
@ -0,0 +1,218 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SoundBuffer.hpp"
|
||||
|
||||
|
||||
static PyMemberDef PySfSoundBuffer_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfSoundBuffer_dealloc(PySfSoundBuffer *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBuffer_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSoundBuffer *self;
|
||||
|
||||
self = (PySfSoundBuffer *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfSoundBuffer_init(PySfSoundBuffer *self, PyObject *args, PyObject *kwds);
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_LoadFromFile(PySfSoundBuffer *self, PyObject *args)
|
||||
{
|
||||
char *path = PyString_AsString(args);
|
||||
if (self->obj->LoadFromFile(path))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBuffer_LoadFromMemory(PySfSoundBuffer* self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes;
|
||||
char *Data;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "s#", &Data, &SizeInBytes))
|
||||
return NULL;
|
||||
|
||||
if (self->obj->LoadFromMemory(Data, (std::size_t) SizeInBytes))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBuffer_LoadFromSamples(PySfSoundBuffer* self, PyObject *args)
|
||||
{
|
||||
unsigned int SizeInBytes, ChannelsCount, SampleRate;
|
||||
char *Data;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "s#II", &Data, &SizeInBytes, &ChannelsCount, &SampleRate))
|
||||
return NULL;
|
||||
|
||||
if (self->obj->LoadFromSamples((const sf::Int16*)Data, (std::size_t) SizeInBytes/2, ChannelsCount, SampleRate))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetSamples(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyString_FromStringAndSize((const char *)(self->obj->GetSamples()), self->obj->GetSamplesCount()*2);
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_SaveToFile(PySfSoundBuffer *self, PyObject *args)
|
||||
{
|
||||
char *path = PyString_AsString(args);
|
||||
if (self->obj->SaveToFile(path))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetDuration(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyFloat_FromDouble((double)(self->obj->GetDuration()));
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetChannelsCount(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetChannelsCount());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetSampleRate(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetSampleRate());
|
||||
}
|
||||
|
||||
static PyObject*
|
||||
PySfSoundBuffer_GetSamplesCount(PySfSoundBuffer *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetSamplesCount());
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfSoundBuffer_methods[] = {
|
||||
{"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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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()
|
||||
{
|
||||
return PyObject_New(PySfSoundBuffer, &PySfSoundBufferType);
|
||||
}
|
||||
|
42
python/src/SoundBuffer.hpp
Normal file
42
python/src/SoundBuffer.hpp
Normal file
|
@ -0,0 +1,42 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUNDBUFFER_HPP
|
||||
#define __PYSOUNDBUFFER_HPP
|
||||
|
||||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::SoundBuffer *obj;
|
||||
} PySfSoundBuffer;
|
||||
|
||||
PySfSoundBuffer *
|
||||
GetNewPySfSoundBuffer();
|
||||
|
||||
#endif
|
121
python/src/SoundBufferRecorder.cpp
Normal file
121
python/src/SoundBufferRecorder.cpp
Normal file
|
@ -0,0 +1,121 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SoundBufferRecorder.hpp"
|
||||
|
||||
#include "SoundBuffer.hpp"
|
||||
|
||||
extern PyTypeObject PySfSoundRecorderType;
|
||||
|
||||
static PyMemberDef PySfSoundBufferRecorder_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfSoundBufferRecorder_dealloc(PySfSoundBufferRecorder *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBufferRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSoundBufferRecorder *self;
|
||||
|
||||
self = (PySfSoundBufferRecorder *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfSoundBufferRecorder_init(PySfSoundBufferRecorder *self, PyObject *args)
|
||||
{
|
||||
self->obj = new sf::SoundBufferRecorder();
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundBufferRecorder_GetBuffer(PySfSoundBufferRecorder* self)
|
||||
{
|
||||
PySfSoundBuffer *SoundBuffer = GetNewPySfSoundBuffer();
|
||||
SoundBuffer->obj = new sf::SoundBuffer( self->obj->GetBuffer() );
|
||||
return (PyObject *)SoundBuffer;
|
||||
}
|
||||
|
||||
|
||||
static PyMethodDef PySfSoundBufferRecorder_methods[] = {
|
||||
{"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*/
|
||||
(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*/
|
||||
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 */
|
||||
};
|
||||
|
||||
|
41
python/src/SoundBufferRecorder.hpp
Normal file
41
python/src/SoundBufferRecorder.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUNDBUFFERRECORDER_HPP
|
||||
#define __PYSOUNDBUFFERRECORDER_HPP
|
||||
|
||||
#include <SFML/Audio/SoundBufferRecorder.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::SoundBufferRecorder *obj;
|
||||
} PySfSoundBufferRecorder;
|
||||
|
||||
#endif
|
174
python/src/SoundRecorder.cpp
Normal file
174
python/src/SoundRecorder.cpp
Normal file
|
@ -0,0 +1,174 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "SoundRecorder.hpp"
|
||||
|
||||
|
||||
|
||||
static PyMemberDef PySfSoundRecorder_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
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)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSoundRecorder *self;
|
||||
|
||||
self = (PySfSoundRecorder *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfSoundRecorder_init(PySfSoundRecorder *self, PyObject *args)
|
||||
{
|
||||
self->obj = new CustomSoundRecorder();
|
||||
self->obj->SoundRecorder = (PyObject *)self;
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_Start(PySfSoundRecorder* self, PyObject *args)
|
||||
{
|
||||
self->obj->Start( PyInt_AsLong(args) );
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_Stop(PySfSoundRecorder* self)
|
||||
{
|
||||
self->obj->Stop();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_GetSampleRate(PySfSoundRecorder* self)
|
||||
{
|
||||
return PyInt_FromLong(self->obj->GetSampleRate());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSoundRecorder_CanCapture(PySfSoundRecorder* self)
|
||||
{
|
||||
if (sf::SoundRecorder::CanCapture())
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyMethodDef PySfSoundRecorder_methods[] = {
|
||||
{"Start", (PyCFunction)PySfSoundRecorder_Start, METH_O, "Start(SampleRate=44100)\nStart the capture. Warning : only one capture can happen at the same time.\n SampleRate : Sound frequency (the more samples, the higher the quality) (44100 by default = CD quality)."},
|
||||
{"Stop", (PyCFunction)PySfSoundRecorder_Stop, METH_NOARGS, "Stop()\nStop the capture."},
|
||||
{"GetSampleRate", (PyCFunction)PySfSoundRecorder_GetSampleRate, METH_NOARGS, "GetSampleRate()\nGet the sample rate. Returns the frequency, in samples per second."},
|
||||
{"CanCapture", (PyCFunction)PySfSoundRecorder_CanCapture, METH_STATIC | METH_NOARGS, "CanCapture()\nTell if the system supports sound capture. If not, this class won't be usable. Returns True if audio capture is supported."},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfSoundRecorderType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
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*/
|
||||
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\
|
||||
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 */
|
||||
};
|
||||
|
50
python/src/SoundRecorder.hpp
Normal file
50
python/src/SoundRecorder.hpp
Normal file
|
@ -0,0 +1,50 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSOUNDRECORDER_HPP
|
||||
#define __PYSOUNDRECORDER_HPP
|
||||
|
||||
#include <SFML/Audio/SoundRecorder.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#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
|
||||
CustomSoundRecorder *obj;
|
||||
} PySfSoundRecorder;
|
||||
|
||||
#endif
|
320
python/src/SoundStream.cpp
Normal file
320
python/src/SoundStream.cpp
Normal file
|
@ -0,0 +1,320 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "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);
|
||||
}
|
||||
|
53
python/src/SoundStream.hpp
Normal file
53
python/src/SoundStream.hpp
Normal file
|
@ -0,0 +1,53 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __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
|
||||
|
255
python/src/Sprite.cpp
Normal file
255
python/src/Sprite.cpp
Normal file
|
@ -0,0 +1,255 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Sprite.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfIntRectType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
|
||||
static PyMemberDef PySfSprite_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfSprite_dealloc(PySfSprite *self)
|
||||
{
|
||||
if (self->Image != NULL)
|
||||
Py_DECREF(self->Image);
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfSprite *self;
|
||||
|
||||
self = (PySfSprite *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Image = NULL;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfSprite_init(PySfSprite *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
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!", (char **)kwlist, &PySfImageType, &Image, &X, &Y, &ScaleX, &ScaleY, &Rotation, &PySfColorType, &Color))
|
||||
return -1;
|
||||
|
||||
Py_INCREF(Image);
|
||||
self->Image = Image;
|
||||
if (Color != NULL)
|
||||
self->obj = new sf::Sprite(*(Image->obj), sf::Vector2f(X, Y), sf::Vector2f(ScaleX, ScaleY), Rotation, *(Color->obj));
|
||||
else
|
||||
self->obj = new sf::Sprite(*(Image->obj), sf::Vector2f(X, Y), sf::Vector2f(ScaleX, ScaleY), Rotation);
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_SetImage(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
PySfImage *Image = (PySfImage *)args;
|
||||
if (! PyObject_TypeCheck(Image, &PySfImageType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Argument is not a sfImage");
|
||||
return NULL;
|
||||
}
|
||||
Py_DECREF(self->Image);
|
||||
Py_INCREF(Image);
|
||||
self->Image = Image;
|
||||
self->obj->SetImage(*(Image->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetImage(PySfSprite* self)
|
||||
{
|
||||
Py_INCREF(self->Image);
|
||||
return (PyObject *)(self->Image);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetPixel(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
PySfColor *Color;
|
||||
unsigned int x=0, y=0;
|
||||
|
||||
|
||||
if (! PyArg_ParseTuple(args, "II", &x, &y))
|
||||
return NULL;
|
||||
|
||||
Color = GetNewPySfColor();
|
||||
Color->obj = new sf::Color(self->obj->GetPixel(x, y));
|
||||
Color->r = Color->obj->r;
|
||||
Color->g = Color->obj->g;
|
||||
Color->b = Color->obj->b;
|
||||
Color->a = Color->obj->a;
|
||||
|
||||
return (PyObject *)Color;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_Resize(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
float W=0, H=0;
|
||||
|
||||
if (! PyArg_ParseTuple(args, "ff", &W, &H))
|
||||
return NULL;
|
||||
|
||||
self->obj->Resize(W,H);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetSubRect(PySfSprite* self)
|
||||
{
|
||||
PySfIntRect *Rect;
|
||||
|
||||
Rect = GetNewPySfIntRect();
|
||||
Rect->obj = new sf::IntRect(self->obj->GetSubRect());
|
||||
Rect->Left = Rect->obj->Left;
|
||||
Rect->Top = Rect->obj->Top;
|
||||
Rect->Right = Rect->obj->Right;
|
||||
Rect->Bottom = Rect->obj->Bottom;
|
||||
|
||||
return (PyObject *)Rect;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_SetSubRect(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
PySfIntRect *Rect = (PySfIntRect *)args;
|
||||
if (! PyObject_TypeCheck(Rect, &PySfIntRectType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Argument is not a sf.IntRect instance");
|
||||
return NULL;
|
||||
}
|
||||
self->obj->SetSubRect(*(Rect->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_FlipX(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
bool Flip = false;
|
||||
if (PyObject_IsTrue(args))
|
||||
Flip = true;
|
||||
self->obj->FlipX(Flip);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_FlipY(PySfSprite* self, PyObject *args)
|
||||
{
|
||||
bool Flip = false;
|
||||
if (PyObject_IsTrue(args))
|
||||
Flip = true;
|
||||
self->obj->FlipY(Flip);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfSprite_GetSize(PySfSprite* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetSize();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyMethodDef PySfSprite_methods[] = {
|
||||
{"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 */
|
||||
};
|
||||
|
||||
PyTypeObject PySfSpriteType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"Sprite", /*tp_name*/
|
||||
sizeof(PySfSprite), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfSprite_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*/
|
||||
"sfSprite defines a sprite : 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 */
|
||||
PySfSprite_methods, /* tp_methods */
|
||||
PySfSprite_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
&PySfDrawableType, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfSprite_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfSprite_new, /* tp_new */
|
||||
};
|
||||
|
||||
|
45
python/src/Sprite.hpp
Normal file
45
python/src/Sprite.hpp
Normal file
|
@ -0,0 +1,45 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSPRITE_HPP
|
||||
#define __PYSPRITE_HPP
|
||||
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Drawable.hpp"
|
||||
#include "Image.hpp"
|
||||
#include "Rect.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Sprite *obj;
|
||||
PySfImage *Image;
|
||||
} PySfSprite;
|
||||
|
||||
#endif
|
269
python/src/String.cpp
Normal file
269
python/src/String.cpp
Normal file
|
@ -0,0 +1,269 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "String.hpp"
|
||||
#include "Font.hpp"
|
||||
#include "Color.hpp"
|
||||
#include "Rect.hpp"
|
||||
|
||||
|
||||
extern PyTypeObject PySfColorType;
|
||||
extern PyTypeObject PySfImageType;
|
||||
extern PyTypeObject PySfDrawableType;
|
||||
extern PyTypeObject PySfFontType;
|
||||
|
||||
static PyMemberDef PySfString_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
|
||||
static void
|
||||
PySfString_dealloc(PySfString *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfString *self;
|
||||
|
||||
self = (PySfString *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfString_init(PySfString *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
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, "|s#O!f", (char **)kwlist, &TextTmp, &TextSize, &PySfFontType, &FontTmp, &Size))
|
||||
return -1;
|
||||
|
||||
if (FontTmp)
|
||||
Font = (FontTmp->obj);
|
||||
else
|
||||
Font = (sf::Font *)&(sf::Font::GetDefaultFont());
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetText(PySfString* self, PyObject *args)
|
||||
{
|
||||
char *TextTmp = NULL;
|
||||
int Size;
|
||||
if (!PyArg_Parse(args, "s#", &TextTmp, &Size))
|
||||
return NULL;
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetFont(PySfString* self, PyObject *args)
|
||||
{
|
||||
PySfFont *Font = (PySfFont *)args;
|
||||
if (!PyObject_TypeCheck(Font, &PySfFontType))
|
||||
PyErr_SetString(PyExc_ValueError, "Argument must be a sf.Font");
|
||||
self->obj->SetFont(*(Font->obj));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetSize(PySfString* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetSize(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetSize(PySfString* self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetSize());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_SetStyle(PySfString* self, PyObject *args)
|
||||
{
|
||||
self->obj->SetStyle(PyLong_AsUnsignedLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetStyle(PySfString* self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetStyle());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetText(PySfString* self)
|
||||
{
|
||||
return PyString_FromString((std::string(self->obj->GetText())).c_str());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetFont(PySfString* self)
|
||||
{
|
||||
PySfFont *Font = GetNewPySfFont();
|
||||
Font->obj = new sf::Font(self->obj->GetFont());
|
||||
return (PyObject *)Font;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfString_GetRect(PySfString* self)
|
||||
{
|
||||
PySfFloatRect *Rect;
|
||||
|
||||
Rect = GetNewPySfFloatRect();
|
||||
Rect->obj = new sf::FloatRect (self->obj->GetRect());
|
||||
Rect->Left = Rect->obj->Left;
|
||||
Rect->Top = Rect->obj->Top;
|
||||
Rect->Right = Rect->obj->Right;
|
||||
Rect->Bottom = Rect->obj->Bottom;
|
||||
|
||||
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[] = {
|
||||
{"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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.String defines a graphical 2D text, that can be drawn on screen.\n\
|
||||
Default constructor : String ()\nConstruct the string from 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 */
|
||||
};
|
||||
|
||||
|
||||
|
||||
void PySfString_InitConst()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::String::Regular);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Regular", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::String::Bold);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Bold", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::String::Italic);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Italic", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::String::Underlined);
|
||||
PyDict_SetItemString(PySfStringType.tp_dict, "Underlined", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
41
python/src/String.hpp
Normal file
41
python/src/String.hpp
Normal file
|
@ -0,0 +1,41 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYSTRING_HPP
|
||||
#define __PYSTRING_HPP
|
||||
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::String *obj;
|
||||
} PySfString;
|
||||
|
||||
void PySfString_InitConst();
|
||||
|
||||
#endif
|
202
python/src/VideoMode.cpp
Normal file
202
python/src/VideoMode.cpp
Normal file
|
@ -0,0 +1,202 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "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);
|
||||
}
|
||||
|
52
python/src/VideoMode.hpp
Normal file
52
python/src/VideoMode.hpp
Normal file
|
@ -0,0 +1,52 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYVIDEOMODE_HPP
|
||||
#define __PYVIDEOMODE_HPP
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int Width;
|
||||
unsigned int Height;
|
||||
unsigned int BitsPerPixel;
|
||||
sf::VideoMode *obj;
|
||||
} PySfVideoMode;
|
||||
|
||||
void
|
||||
PySfVideoModeUpdate(PySfVideoMode *self);
|
||||
|
||||
PySfVideoMode *
|
||||
GetNewPySfVideoMode();
|
||||
|
||||
#endif
|
194
python/src/View.cpp
Normal file
194
python/src/View.cpp
Normal file
|
@ -0,0 +1,194 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "View.hpp"
|
||||
|
||||
extern PyTypeObject PySfFloatRectType;
|
||||
|
||||
static PyMemberDef PySfView_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfView_dealloc(PySfView *self)
|
||||
{
|
||||
if (self->Owner)
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfView *self;
|
||||
|
||||
self = (PySfView *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
self->Owner = true;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfView_init(PySfView *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfFloatRect *Rect=NULL;
|
||||
if (! PyArg_ParseTuple(args, "|O!", &PySfFloatRectType, &Rect))
|
||||
return -1;
|
||||
|
||||
if (Rect != NULL)
|
||||
self->obj = new sf::View( (const sf::FloatRect) *(Rect->obj));
|
||||
else
|
||||
self->obj = new sf::View();
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_GetCenter(PySfView* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetCenter();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_GetHalfSize(PySfView* self)
|
||||
{
|
||||
sf::Vector2f Vect = self->obj->GetHalfSize();
|
||||
return Py_BuildValue("ff", Vect.x, Vect.y);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_GetRect(PySfView* self)
|
||||
{
|
||||
PySfFloatRect *Rect = GetNewPySfFloatRect();
|
||||
Rect->obj = new sf::FloatRect(self->obj->GetRect());
|
||||
Rect->Left = Rect->obj->Left;
|
||||
Rect->Right = Rect->obj->Right;
|
||||
Rect->Top = Rect->obj->Top;
|
||||
Rect->Bottom = Rect->obj->Bottom;
|
||||
return (PyObject *)Rect;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_Move(PySfView* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->Move(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_SetCenter(PySfView* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->SetCenter(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_SetHalfSize(PySfView* self, PyObject *args)
|
||||
{
|
||||
float x, y;
|
||||
if ( !PyArg_ParseTuple(args, "ff", &x, &y) )
|
||||
return NULL;
|
||||
self->obj->SetHalfSize(x, y);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfView_Zoom(PySfView* self, PyObject *args)
|
||||
{
|
||||
self->obj->Zoom(PyFloat_AsDouble(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfView_methods[] = {
|
||||
{"GetCenter", (PyCFunction)PySfView_GetCenter, METH_NOARGS, "GetCenter()\nGet the center of the view."},
|
||||
{"GetHalfSize", (PyCFunction)PySfView_GetHalfSize, METH_NOARGS, "GetHalfSize()\nGet the half-size of the view."},
|
||||
{"GetRect", (PyCFunction)PySfView_GetRect, METH_NOARGS, "GetRect()\nGet the bounding rectangle of the view."},
|
||||
{"Move", (PyCFunction)PySfView_Move, METH_VARARGS, "Move(OffsetX, OffsetY)\nMove the view.\n\
|
||||
OffsetX : Offset to move the view, on X axis\n\
|
||||
OffsetY : Offset to move the view, on Y axis"},
|
||||
{"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 */
|
||||
};
|
||||
|
||||
PyTypeObject PySfViewType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"View", /*tp_name*/
|
||||
sizeof(PySfView), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfView_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*/
|
||||
"This class defines a view (position, size, etc.) ; you can consider it as a 2D camera.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfView_methods, /* tp_methods */
|
||||
PySfView_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfView_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfView_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfView *
|
||||
GetNewPySfView()
|
||||
{
|
||||
return (PySfView *)PySfView_new(&PySfViewType, NULL, NULL);
|
||||
}
|
||||
|
47
python/src/View.hpp
Normal file
47
python/src/View.hpp
Normal file
|
@ -0,0 +1,47 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYVIEW_HPP
|
||||
#define __PYVIEW_HPP
|
||||
|
||||
#include <SFML/Graphics/View.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include "Rect.hpp"
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
bool Owner;
|
||||
sf::View *obj;
|
||||
} PySfView;
|
||||
|
||||
PySfView *
|
||||
GetNewPySfView();
|
||||
|
||||
#endif
|
428
python/src/Window.cpp
Normal file
428
python/src/Window.cpp
Normal file
|
@ -0,0 +1,428 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "Window.hpp"
|
||||
|
||||
#include "SFML/Window/WindowStyle.hpp"
|
||||
|
||||
extern PyTypeObject PySfEventType;
|
||||
extern PyTypeObject PySfWindowSettingsType;
|
||||
extern PyTypeObject PySfVideoModeType;
|
||||
|
||||
static PyMemberDef PySfWindow_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
static void
|
||||
PySfWindow_dealloc(PySfWindow* self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfWindow *self;
|
||||
|
||||
self = (PySfWindow *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
|
||||
static PyObject*
|
||||
PySfWindow_GetEvent(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
PySfEvent *PyEvent = (PySfEvent *)args;
|
||||
|
||||
if (! PyObject_TypeCheck(PyEvent, &PySfEventType))
|
||||
{
|
||||
PyErr_SetString(PyExc_TypeError, "Argument is not a sfEvent");
|
||||
return NULL;
|
||||
}
|
||||
|
||||
if (self->obj->GetEvent(*(PyEvent->obj)))
|
||||
{
|
||||
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_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;
|
||||
PyEvent->JoyButton->JoystickId = PyEvent->obj->JoyButton.JoystickId;
|
||||
PyEvent->JoyButton->Button = PyEvent->obj->JoyButton.Button;
|
||||
PyEvent->JoyMove->Axis = PyEvent->obj->JoyMove.Axis;
|
||||
PyEvent->JoyMove->Position = PyEvent->obj->JoyMove.Position;
|
||||
PyEvent->Size->Width = PyEvent->obj->Size.Width;
|
||||
PyEvent->Size->Height = PyEvent->obj->Size.Height;
|
||||
PyEvent->MouseWheel->Delta = PyEvent->obj->MouseWheel.Delta;
|
||||
Py_RETURN_TRUE;
|
||||
}
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
|
||||
|
||||
|
||||
PyObject*
|
||||
PySfWindow_Create(PySfWindow* 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 = NULL;
|
||||
|
||||
const char *kwlist[] = {"VideoMode", "Title", "WindowStyle", "Params", NULL};
|
||||
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "O!s|IO!", (char **)kwlist, &PySfVideoModeType, &VideoModeTmp, &Title, &WindowStyle, &PySfWindowSettingsType, &ParamsTmp))
|
||||
return NULL;
|
||||
|
||||
if (VideoModeTmp) {
|
||||
VideoMode = ((PySfVideoMode *)VideoModeTmp)->obj;
|
||||
PySfVideoModeUpdate((PySfVideoMode *)VideoModeTmp);
|
||||
}
|
||||
else
|
||||
return NULL;
|
||||
|
||||
if (ParamsTmp)
|
||||
{
|
||||
PySfWindowSettingsUpdate(ParamsTmp);
|
||||
Params = ParamsTmp->obj;
|
||||
}
|
||||
else
|
||||
Params = new sf::WindowSettings();
|
||||
|
||||
self->obj->Create(*VideoMode, Title, WindowStyle, *Params);
|
||||
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static int
|
||||
PySfWindow_init(PySfWindow *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
self->obj = new sf::Window();
|
||||
if (PyTuple_Size(args) > 0)
|
||||
PySfWindow_Create(self, args, kwds);
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_Close(PySfWindow *self)
|
||||
{
|
||||
self->obj->Close();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_IsOpened(PySfWindow *self)
|
||||
{
|
||||
if (self->obj->IsOpened())
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_GetWidth(PySfWindow *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetWidth());
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_GetHeight(PySfWindow *self)
|
||||
{
|
||||
return PyLong_FromUnsignedLong(self->obj->GetHeight());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_UseVerticalSync(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
bool Enabled = false;
|
||||
if (PyObject_IsTrue(args))
|
||||
Enabled = true;
|
||||
self->obj->UseVerticalSync(Enabled);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_ShowMouseCursor(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
bool Show = false;
|
||||
if (PyObject_IsTrue(args))
|
||||
Show = true;
|
||||
self->obj->ShowMouseCursor(Show);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetActive(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
bool Active = false;
|
||||
if (PyObject_IsTrue(args))
|
||||
Active = true;
|
||||
if (self->obj->SetActive(Active))
|
||||
Py_RETURN_TRUE;
|
||||
else
|
||||
Py_RETURN_FALSE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_Display(PySfWindow *self)
|
||||
{
|
||||
self->obj->Display();
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
static PyObject *
|
||||
PySfWindow_GetFrameTime(PySfWindow *self)
|
||||
{
|
||||
return PyFloat_FromDouble(self->obj->GetFrameTime());
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_GetInput(PySfWindow *self)
|
||||
{
|
||||
PySfInput *Input;
|
||||
Input = GetNewPySfInput();
|
||||
Input->obj = (sf::Input *)&self->obj->GetInput();
|
||||
return (PyObject *)Input;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_GetSettings(PySfWindow *self)
|
||||
{
|
||||
PySfWindowSettings *Settings;
|
||||
Settings = GetNewPySfWindowSettings();
|
||||
Settings->obj = (sf::WindowSettings *)&self->obj->GetSettings();
|
||||
Settings->DepthBits = Settings->obj->DepthBits;
|
||||
Settings->StencilBits = Settings->obj->StencilBits;
|
||||
Settings->AntialiasingLevel = Settings->obj->AntialiasingLevel;
|
||||
return (PyObject *)Settings;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetPosition(PySfWindow* self, PyObject *args)
|
||||
{
|
||||
int Left=0, Top=0;
|
||||
if (! PyArg_ParseTuple(args, "ii", &Left, &Top))
|
||||
return NULL;
|
||||
|
||||
self->obj->SetPosition(Left,Top);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetFramerateLimit(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
self->obj->SetFramerateLimit(PyLong_AsUnsignedLong(args));
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_Show(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
if (PyObject_IsTrue(args))
|
||||
self->obj->Show(true);
|
||||
else
|
||||
self->obj->Show(false);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_EnableKeyRepeat(PySfWindow *self, PyObject *args)
|
||||
{
|
||||
if (PyObject_IsTrue(args))
|
||||
self->obj->EnableKeyRepeat(true);
|
||||
else
|
||||
self->obj->EnableKeyRepeat(false);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindow_SetCursorPosition(PySfWindow* self, PyObject *args)
|
||||
{
|
||||
unsigned int Left=0, Top=0;
|
||||
if (! PyArg_ParseTuple(args, "II", &Left, &Top))
|
||||
return NULL;
|
||||
|
||||
self->obj->SetCursorPosition(Left,Top);
|
||||
Py_RETURN_NONE;
|
||||
}
|
||||
|
||||
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_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()\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*/
|
||||
(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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"sf.Window is a rendering window ; it can create a new window or connect to an existing one.\n\
|
||||
Default constructor : sf.Window()\n\
|
||||
Construct a new window : sf.Window(Mode, Title, sf.Style.Resize | sf.Style.Close, Params = sf.WindowSettings())\n\
|
||||
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 */
|
||||
};
|
||||
|
||||
|
49
python/src/Window.hpp
Normal file
49
python/src/Window.hpp
Normal file
|
@ -0,0 +1,49 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYWINDOW_HPP
|
||||
#define __PYWINDOW_HPP
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "VideoMode.hpp"
|
||||
#include "Input.hpp"
|
||||
#include "WindowSettings.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
sf::Window *obj;
|
||||
} PySfWindow;
|
||||
|
||||
PyObject*
|
||||
PySfWindow_Create(PySfWindow* self, PyObject *args, PyObject *kwds);
|
||||
|
||||
#endif
|
131
python/src/WindowSettings.cpp
Normal file
131
python/src/WindowSettings.cpp
Normal file
|
@ -0,0 +1,131 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "WindowSettings.hpp"
|
||||
|
||||
static PyMemberDef PySfWindowSettings_members[] = {
|
||||
{(char *)"DepthBits", T_UINT, offsetof(PySfWindowSettings, DepthBits), 0, (char *)"Depth buffer bits (24 by default)"},
|
||||
{(char *)"StencilBits", T_UINT, offsetof(PySfWindowSettings, StencilBits), 0, (char *)"Stencil buffer bits (8 by default)"},
|
||||
{(char *)"AntialiasingLevel", T_UINT, offsetof(PySfWindowSettings, AntialiasingLevel), 0, (char *)"Antialiasing level (0 by default)"},
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfWindowSettings_dealloc(PySfWindowSettings *self)
|
||||
{
|
||||
delete self->obj;
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
void
|
||||
PySfWindowSettingsUpdate(PySfWindowSettings *self)
|
||||
{
|
||||
self->obj->DepthBits = self->DepthBits;
|
||||
self->obj->StencilBits = self->StencilBits;
|
||||
self->obj->AntialiasingLevel = self->AntialiasingLevel;
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfWindowSettings_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfWindowSettings *self;
|
||||
|
||||
self = (PySfWindowSettings *)type->tp_alloc(type, 0);
|
||||
|
||||
if (self != NULL)
|
||||
{
|
||||
self->DepthBits = 24;
|
||||
self->StencilBits = 8;
|
||||
self->AntialiasingLevel = 0;
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfWindowSettings_init(PySfWindowSettings *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
const char *kwlist[] = {"DepthBits", "StencilBits", "AntialiasingLevel", NULL};
|
||||
if (! PyArg_ParseTupleAndKeywords(args, kwds, "|III", (char **)kwlist, &(self->DepthBits), &(self->StencilBits), &(self->AntialiasingLevel)))
|
||||
return -1;
|
||||
self->obj = new sf::WindowSettings(self->DepthBits, self->StencilBits, self->AntialiasingLevel);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfWindowSettings_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
PyTypeObject PySfWindowSettingsType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
0, /*ob_size*/
|
||||
"WindowSettings", /*tp_name*/
|
||||
sizeof(PySfWindowSettings), /*tp_basicsize*/
|
||||
0, /*tp_itemsize*/
|
||||
(destructor)PySfWindowSettings_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 defining the creation settings of windows.", /* tp_doc */
|
||||
0, /* tp_traverse */
|
||||
0, /* tp_clear */
|
||||
0, /* tp_richcompare */
|
||||
0, /* tp_weaklistoffset */
|
||||
0, /* tp_iter */
|
||||
0, /* tp_iternext */
|
||||
PySfWindowSettings_methods, /* tp_methods */
|
||||
PySfWindowSettings_members, /* tp_members */
|
||||
0, /* tp_getset */
|
||||
0, /* tp_base */
|
||||
0, /* tp_dict */
|
||||
0, /* tp_descr_get */
|
||||
0, /* tp_descr_set */
|
||||
0, /* tp_dictoffset */
|
||||
(initproc)PySfWindowSettings_init, /* tp_init */
|
||||
0, /* tp_alloc */
|
||||
PySfWindowSettings_new, /* tp_new */
|
||||
};
|
||||
|
||||
PySfWindowSettings *
|
||||
GetNewPySfWindowSettings()
|
||||
{
|
||||
return PyObject_New(PySfWindowSettings, &PySfWindowSettingsType);
|
||||
}
|
||||
|
51
python/src/WindowSettings.hpp
Normal file
51
python/src/WindowSettings.hpp
Normal file
|
@ -0,0 +1,51 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYWINDOWSETTINGS_HPP
|
||||
#define __PYWINDOWSETTINGS_HPP
|
||||
|
||||
#include <SFML/Window/WindowSettings.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "offsetof.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
unsigned int DepthBits;
|
||||
unsigned int StencilBits;
|
||||
unsigned int AntialiasingLevel;
|
||||
sf::WindowSettings *obj;
|
||||
} PySfWindowSettings;
|
||||
|
||||
void
|
||||
PySfWindowSettingsUpdate(PySfWindowSettings *self);
|
||||
|
||||
PySfWindowSettings *
|
||||
GetNewPySfWindowSettings();
|
||||
|
||||
#endif
|
140
python/src/WindowStyle.cpp
Normal file
140
python/src/WindowStyle.cpp
Normal file
|
@ -0,0 +1,140 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include <SFML/Window/WindowStyle.hpp>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "WindowStyle.hpp"
|
||||
|
||||
|
||||
typedef struct {
|
||||
PyObject_HEAD
|
||||
} PySfStyle;
|
||||
|
||||
|
||||
|
||||
static PyMemberDef PySfStyle_members[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
|
||||
static void
|
||||
PySfStyle_dealloc(PySfStyle *self)
|
||||
{
|
||||
self->ob_type->tp_free((PyObject*)self);
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
PySfStyle_new(PyTypeObject *type, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
PySfStyle *self;
|
||||
|
||||
self = (PySfStyle *)type->tp_alloc(type, 0);
|
||||
if (self != NULL)
|
||||
{
|
||||
}
|
||||
|
||||
return (PyObject *)self;
|
||||
}
|
||||
|
||||
|
||||
static int
|
||||
PySfStyle_init(PySfStyle *self, PyObject *args, PyObject *kwds)
|
||||
{
|
||||
return 0;
|
||||
}
|
||||
|
||||
static PyMethodDef PySfStyle_methods[] = {
|
||||
{NULL} /* Sentinel */
|
||||
};
|
||||
|
||||
PyTypeObject PySfStyleType = {
|
||||
PyObject_HEAD_INIT(NULL)
|
||||
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*/
|
||||
Py_TPFLAGS_DEFAULT | Py_TPFLAGS_BASETYPE, /*tp_flags*/
|
||||
"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()
|
||||
{
|
||||
PyObject *obj;
|
||||
obj = PyInt_FromLong(sf::Style::None);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "None", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Style::Titlebar);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Titlebar", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Style::Resize);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Resize", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Style::Close);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Close", obj);
|
||||
Py_DECREF(obj);
|
||||
obj = PyInt_FromLong(sf::Style::Fullscreen);
|
||||
PyDict_SetItemString(PySfStyleType.tp_dict, "Fullscreen", obj);
|
||||
Py_DECREF(obj);
|
||||
}
|
||||
|
31
python/src/WindowStyle.hpp
Normal file
31
python/src/WindowStyle.hpp
Normal file
|
@ -0,0 +1,31 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYWINDOWSTYLE_HPP
|
||||
#define __PYWINDOWSTYLE_HPP
|
||||
|
||||
void
|
||||
PySfStyle_InitConst();
|
||||
|
||||
#endif
|
276
python/src/main.cpp
Normal file
276
python/src/main.cpp
Normal file
|
@ -0,0 +1,276 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#include "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();
|
||||
}
|
||||
|
38
python/src/main.hpp
Normal file
38
python/src/main.hpp
Normal file
|
@ -0,0 +1,38 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __PYMAIN_HPP
|
||||
#define __PYMAIN_HPP
|
||||
|
||||
#include <SFML/System.hpp>
|
||||
#include <SFML/Window.hpp>
|
||||
#include <iostream>
|
||||
|
||||
#include <Python.h>
|
||||
#include <structmember.h>
|
||||
|
||||
#include "Event.hpp"
|
||||
#include "Sleep.hpp"
|
||||
|
||||
#endif
|
32
python/src/offsetof.hpp
Normal file
32
python/src/offsetof.hpp
Normal file
|
@ -0,0 +1,32 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// PySFML - Python binding for SFML (Simple and Fast Multimedia Library)
|
||||
// Copyright (C) 2007, 2008 Rémi Koenig (remi.k2620@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef __OFFSETOF_H
|
||||
#define __OFFSETOF_H
|
||||
|
||||
#undef offsetof
|
||||
#define offsetof(TYPE, MEMBER) (reinterpret_cast <size_t> \
|
||||
(&reinterpret_cast <char &>(static_cast <TYPE *> (0)->MEMBER)))
|
||||
|
||||
#endif
|
Loading…
Add table
Add a link
Reference in a new issue