Moved all bindings to the "bindings" sub-directory

Renamed the CSFML directory to c
Renamed the DSFML directory to d
--> bindings must now be updated to match the new organization!

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1630 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
LaurentGom 2010-11-09 17:13:17 +00:00
parent 0cc5563cac
commit 0e2297af28
417 changed files with 0 additions and 0 deletions

View file

@ -0,0 +1,35 @@
set(INCROOT ${CMAKE_SOURCE_DIR}/include/SFML/Audio)
set(SRCROOT ${CMAKE_SOURCE_DIR}/src/SFML/Audio)
# all source files
set(SRC
${SRCROOT}/Listener.cpp
${INCROOT}/Listener.h
${SRCROOT}/Music.cpp
${SRCROOT}/MusicStruct.h
${INCROOT}/Music.h
${SRCROOT}/Sound.cpp
${SRCROOT}/SoundStruct.h
${INCROOT}/Sound.h
${SRCROOT}/SoundBuffer.cpp
${SRCROOT}/SoundBufferStruct.h
${INCROOT}/SoundBuffer.h
${SRCROOT}/SoundBufferRecorder.cpp
${SRCROOT}/SoundBufferRecorderStruct.h
${INCROOT}/SoundBufferRecorder.h
${SRCROOT}/SoundRecorder.cpp
${SRCROOT}/SoundRecorderStruct.h
${INCROOT}/SoundRecorder.h
${INCROOT}/SoundStatus.h
${SRCROOT}/SoundStream.cpp
${SRCROOT}/SoundStreamStruct.h
${INCROOT}/SoundStream.h
${INCROOT}/Types.h
)
# define the csfml-audio target
csfml_add_library(csfml-audio
SOURCES ${SRC}
DEPENDS optimized ${SFML_AUDIO_LIBRARY} debug ${SFML_AUDIO_LIBRARY_DEBUG}
optimized ${SFML_SYSTEM_LIBRARY} debug ${SFML_SYSTEM_LIBRARY_DEBUG})

View file

@ -0,0 +1,96 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Listener.h>
#include <SFML/Audio/Listener.hpp>
////////////////////////////////////////////////////////////
/// Change the global volume of all the sounds
////////////////////////////////////////////////////////////
void sfListener_SetGlobalVolume(float volume)
{
sf::Listener::SetGlobalVolume(volume);
}
////////////////////////////////////////////////////////////
/// Get the current value of the global volume of all the sounds
////////////////////////////////////////////////////////////
float sfListener_GetGlobalVolume(void)
{
return sf::Listener::GetGlobalVolume();
}
////////////////////////////////////////////////////////////
/// Change the position of the listener
////////////////////////////////////////////////////////////
void sfListener_SetPosition(float x, float y, float z)
{
sf::Listener::SetPosition(x, y, z);
}
////////////////////////////////////////////////////////////
/// Get the current position of the listener
////////////////////////////////////////////////////////////
void sfListener_GetPosition(float* x, float* y, float* z)
{
if (x && y && z)
{
sf::Vector3f position = sf::Listener::GetPosition();
*x = position.x;
*y = position.y;
*z = position.z;
}
}
////////////////////////////////////////////////////////////
/// Change the orientation of the listener
////////////////////////////////////////////////////////////
void sfListener_SetDirection(float x, float y, float z)
{
sf::Listener::SetDirection(x, y, z);
}
////////////////////////////////////////////////////////////
/// Get the current orientation of the listener
////////////////////////////////////////////////////////////
void sfListener_GetDirection(float* x, float* y, float* z)
{
if (x && y && z)
{
sf::Vector3f direction = sf::Listener::GetDirection();
*x = direction.x;
*y = direction.y;
*z = direction.z;
}
}

View file

@ -0,0 +1,297 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Music.h>
#include <SFML/Audio/MusicStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new music and load it from a file
////////////////////////////////////////////////////////////
sfMusic* sfMusic_CreateFromFile(const char* filename)
{
sfMusic* music = new sfMusic;
if (!music->This.OpenFromFile(filename))
{
delete music;
music = NULL;
}
return music;
}
////////////////////////////////////////////////////////////
/// Create a new music and load it from a file in memory
////////////////////////////////////////////////////////////
sfMusic* sfMusic_CreateFromMemory(const void* data, size_t sizeInBytes)
{
sfMusic* music = new sfMusic;
if (!music->This.OpenFromMemory(data, sizeInBytes))
{
delete music;
music = NULL;
}
return music;
}
////////////////////////////////////////////////////////////
/// Destroy an existing music
////////////////////////////////////////////////////////////
void sfMusic_Destroy(sfMusic* music)
{
delete music;
}
////////////////////////////////////////////////////////////
/// Set a music loop state
////////////////////////////////////////////////////////////
void sfMusic_SetLoop(sfMusic* music, sfBool loop)
{
CSFML_CALL(music, SetLoop(loop != 0));
}
////////////////////////////////////////////////////////////
/// Tell whether or not a music is looping
////////////////////////////////////////////////////////////
sfBool sfMusic_GetLoop(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetLoop(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get a music duration
////////////////////////////////////////////////////////////
float sfMusic_GetDuration(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetDuration(), 0.f);
}
////////////////////////////////////////////////////////////
/// Start playing a music
////////////////////////////////////////////////////////////
void sfMusic_Play(sfMusic* music)
{
CSFML_CALL(music, Play());
}
////////////////////////////////////////////////////////////
/// Pause a music
////////////////////////////////////////////////////////////
void sfMusic_Pause(sfMusic* music)
{
CSFML_CALL(music, Pause());
}
////////////////////////////////////////////////////////////
/// Stop playing a music
////////////////////////////////////////////////////////////
void sfMusic_Stop(sfMusic* music)
{
CSFML_CALL(music, Stop());
}
////////////////////////////////////////////////////////////
/// Return the number of channels of a music (1 = mono, 2 = stereo)
////////////////////////////////////////////////////////////
unsigned int sfMusic_GetChannelsCount(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetChannelsCount(), 0);
}
////////////////////////////////////////////////////////////
/// Get the stream sample rate of a music
////////////////////////////////////////////////////////////
unsigned int sfMusic_GetSampleRate(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetSampleRate(), 0);
}
////////////////////////////////////////////////////////////
/// Get the status of a music (stopped, paused, playing)
////////////////////////////////////////////////////////////
sfSoundStatus sfMusic_GetStatus(const sfMusic* music)
{
CSFML_CHECK_RETURN(music, sfStopped);
return static_cast<sfSoundStatus>(music->This.GetStatus());
}
////////////////////////////////////////////////////////////
/// Get the current playing position of a music
////////////////////////////////////////////////////////////
float sfMusic_GetPlayingOffset(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetPlayingOffset(), 0.f);
}
////////////////////////////////////////////////////////////
/// Set the pitch of a music
////////////////////////////////////////////////////////////
void sfMusic_SetPitch(sfMusic* music, float pitch)
{
CSFML_CALL(music, SetPitch(pitch));
}
////////////////////////////////////////////////////////////
/// Set the volume of a music
////////////////////////////////////////////////////////////
void sfMusic_SetVolume(sfMusic* music, float volume)
{
CSFML_CALL(music, SetVolume(volume));
}
////////////////////////////////////////////////////////////
/// Set the position of a music
////////////////////////////////////////////////////////////
void sfMusic_SetPosition(sfMusic* music, float x, float y, float z)
{
CSFML_CALL(music, SetPosition(sf::Vector3f(x, y, z)));
}
////////////////////////////////////////////////////////////
/// Make the music's position relative to the listener's
/// position, or absolute.
/// The default value is false (absolute)
////////////////////////////////////////////////////////////
void sfMusic_SetRelativeToListener(sfMusic* music, sfBool relative)
{
CSFML_CALL(music, SetRelativeToListener(relative == sfTrue));
}
////////////////////////////////////////////////////////////
/// Set the minimum distance - closer than this distance,
/// the listener will hear the music at its maximum volume.
/// The default minimum distance is 1.0
////////////////////////////////////////////////////////////
void sfMusic_SetMinDistance(sfMusic* music, float distance)
{
CSFML_CALL(music, SetMinDistance(distance));
}
////////////////////////////////////////////////////////////
/// Set the attenuation factor - the higher the attenuation, the
/// more the sound will be attenuated with distance from listener.
/// The default attenuation factor 1.0
////////////////////////////////////////////////////////////
void sfMusic_SetAttenuation(sfMusic* music, float attenuation)
{
CSFML_CALL(music, SetAttenuation(attenuation));
}
////////////////////////////////////////////////////////////
/// Set the current playing position of a stream
////////////////////////////////////////////////////////////
void sfMusic_SetPlayingOffset(sfMusic* music, float timeOffset)
{
CSFML_CALL(music, SetPlayingOffset(timeOffset));
}
////////////////////////////////////////////////////////////
/// Get the pitch of a music
////////////////////////////////////////////////////////////
float sfMusic_GetPitch(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetPitch(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the volume of a music
////////////////////////////////////////////////////////////
float sfMusic_GetVolume(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetVolume(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the position of a music
////////////////////////////////////////////////////////////
void sfMusic_GetPosition(const sfMusic* music, float* x, float* y, float* z)
{
CSFML_CHECK(music);
if (x && y && z)
{
sf::Vector3f position = music->This.GetPosition();
*x = position.x;
*y = position.y;
*z = position.z;
}
}
////////////////////////////////////////////////////////////
/// Tell if the music's position is relative to the listener's
/// position, or if it's absolute
////////////////////////////////////////////////////////////
CSFML_API sfBool sfMusic_IsRelativeToListener(const sfMusic* music)
{
CSFML_CALL_RETURN(music, IsRelativeToListener(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the minimum distance of a music
////////////////////////////////////////////////////////////
float sfMusic_GetMinDistance(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetMinDistance(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the attenuation factor of a music
////////////////////////////////////////////////////////////
float sfMusic_GetAttenuation(const sfMusic* music)
{
CSFML_CALL_RETURN(music, GetAttenuation(), 0.f);
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_MUSICSTRUCT_H
#define SFML_MUSICSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Music.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfMusic
////////////////////////////////////////////////////////////
struct sfMusic
{
sf::Music This;
};
#endif // SFML_MUSICSTRUCT_H

View file

@ -0,0 +1,277 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Sound.h>
#include <SFML/Audio/SoundStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new sound
////////////////////////////////////////////////////////////
sfSound* sfSound_Create(void)
{
return new sfSound;
}
////////////////////////////////////////////////////////////
/// Copy an existing sound
////////////////////////////////////////////////////////////
sfSound* sfSound_Copy(sfSound* sound)
{
CSFML_CHECK_RETURN(sound, NULL);
return new sfSound(*sound);
}
////////////////////////////////////////////////////////////
/// Destroy an existing sound
////////////////////////////////////////////////////////////
void sfSound_Destroy(sfSound* sound)
{
delete sound;
}
////////////////////////////////////////////////////////////
/// Start playing a sound
////////////////////////////////////////////////////////////
void sfSound_Play(sfSound* sound)
{
CSFML_CALL(sound, Play())
}
////////////////////////////////////////////////////////////
/// Pause a sound
////////////////////////////////////////////////////////////
void sfSound_Pause(sfSound* sound)
{
CSFML_CALL(sound, Pause())
}
////////////////////////////////////////////////////////////
/// Stop playing a sound
////////////////////////////////////////////////////////////
void sfSound_Stop(sfSound* sound)
{
CSFML_CALL(sound, Stop())
}
////////////////////////////////////////////////////////////
/// Bind a sound buffer to a sound
////////////////////////////////////////////////////////////
void sfSound_SetBuffer(sfSound* sound, const sfSoundBuffer* buffer)
{
if (buffer)
{
CSFML_CALL(sound, SetBuffer(buffer->This))
sound->Buffer = buffer;
}
}
////////////////////////////////////////////////////////////
/// Get the sound buffer bound to a sound
////////////////////////////////////////////////////////////
const sfSoundBuffer* sfSound_GetBuffer(const sfSound* sound)
{
CSFML_CHECK_RETURN(sound, NULL)
return sound->Buffer;
}
////////////////////////////////////////////////////////////
/// Set a sound loop state
////////////////////////////////////////////////////////////
void sfSound_SetLoop(sfSound* sound, sfBool loop)
{
CSFML_CALL(sound, SetLoop(loop == sfTrue))
}
////////////////////////////////////////////////////////////
/// Tell whether or not a sound is looping
////////////////////////////////////////////////////////////
sfBool sfSound_GetLoop(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetLoop(), sfFalse)
}
////////////////////////////////////////////////////////////
/// Get the status of a sound (stopped, paused, playing)
////////////////////////////////////////////////////////////
sfSoundStatus sfSound_GetStatus(const sfSound* sound)
{
CSFML_CHECK_RETURN(sound, sfStopped);
return static_cast<sfSoundStatus>(sound->This.GetStatus());
}
////////////////////////////////////////////////////////////
/// Set the pitch of a sound
////////////////////////////////////////////////////////////
void sfSound_SetPitch(sfSound* sound, float pitch)
{
CSFML_CALL(sound, SetPitch(pitch))
}
////////////////////////////////////////////////////////////
/// Set the volume of a sound
////////////////////////////////////////////////////////////
void sfSound_SetVolume(sfSound* sound, float volume)
{
CSFML_CALL(sound, SetVolume(volume))
}
////////////////////////////////////////////////////////////
/// Set the position of a sound
////////////////////////////////////////////////////////////
void sfSound_SetPosition(sfSound* sound, float x, float y, float z)
{
CSFML_CALL(sound, SetPosition(sf::Vector3f(x, y, z)))
}
////////////////////////////////////////////////////////////
/// Make the sound's position relative to the listener's
/// position, or absolute.
/// The default value is false (absolute)
////////////////////////////////////////////////////////////
void sfSound_SetRelativeToListener(sfSound* sound, sfBool relative)
{
CSFML_CALL(sound, SetRelativeToListener(relative == sfTrue));
}
////////////////////////////////////////////////////////////
/// Set the minimum distance - closer than this distance,
/// the listener will hear the sound at its maximum volume.
/// The default minimum distance is 1.0
////////////////////////////////////////////////////////////
void sfSound_SetMinDistance(sfSound* sound, float distance)
{
CSFML_CALL(sound, SetMinDistance(distance));
}
////////////////////////////////////////////////////////////
/// Set the attenuation factor - the higher the attenuation, the
/// more the sound will be attenuated with distance from listener.
/// The default attenuation factor is 1.0
////////////////////////////////////////////////////////////
void sfSound_SetAttenuation(sfSound* sound, float attenuation)
{
CSFML_CALL(sound, SetAttenuation(attenuation));
}
////////////////////////////////////////////////////////////
/// Set the current playing position of a sound
////////////////////////////////////////////////////////////
void sfSound_SetPlayingOffset(sfSound* sound, float timeOffset)
{
CSFML_CALL(sound, SetPlayingOffset(timeOffset));
}
////////////////////////////////////////////////////////////
/// Get the pitch of a sound
////////////////////////////////////////////////////////////
float sfSound_GetPitch(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetPitch(), 0.f)
}
////////////////////////////////////////////////////////////
/// Get the volume of a sound
////////////////////////////////////////////////////////////
float sfSound_GetVolume(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetVolume(), 0.f)
}
////////////////////////////////////////////////////////////
/// Get the position of a sound
////////////////////////////////////////////////////////////
void sfSound_GetPosition(const sfSound* sound, float* x, float* y, float* z)
{
CSFML_CHECK(sound);
sf::Vector3f position = sound->This.GetPosition();
if (x) *x = position.x;
if (y) *y = position.y;
if (z) *z = position.z;
}
////////////////////////////////////////////////////////////
/// Tell if the sound's position is relative to the listener's
/// position, or if it's absolute
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSound_IsRelativeToListener(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, IsRelativeToListener(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the minimum distance of a sound
////////////////////////////////////////////////////////////
float sfSound_GetMinDistance(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetMinDistance(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the attenuation factor of a sound
////////////////////////////////////////////////////////////
float sfSound_GetAttenuation(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetAttenuation(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the current playing position of a sound
////////////////////////////////////////////////////////////
float sfSound_GetPlayingOffset(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, GetPlayingOffset(), 0.f)
}

View file

@ -0,0 +1,157 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundBuffer.h>
#include <SFML/Audio/SoundBufferStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new sound buffer and load it from a file
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_CreateFromFile(const char* filename)
{
sfSoundBuffer* buffer = new sfSoundBuffer;
if (!buffer->This.LoadFromFile(filename))
{
delete buffer;
buffer = NULL;
}
return buffer;
}
////////////////////////////////////////////////////////////
/// Create a new sound buffer and load it from a file in memory
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_CreateFromMemory(const void* data, size_t sizeInBytes)
{
sfSoundBuffer* buffer = new sfSoundBuffer;
if (!buffer->This.LoadFromMemory(data, sizeInBytes))
{
delete buffer;
buffer = NULL;
}
return buffer;
}
////////////////////////////////////////////////////////////
/// Create a new sound buffer and load it from an array of
/// samples in memory - assumed format for samples is
/// 16 bits signed integer
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_CreateFromSamples(const sfInt16* samples, size_t samplesCount, unsigned int channelsCount, unsigned int sampleRate)
{
sfSoundBuffer* buffer = new sfSoundBuffer;
if (!buffer->This.LoadFromSamples(samples, samplesCount, channelsCount, sampleRate))
{
delete buffer;
buffer = NULL;
}
return buffer;
}
////////////////////////////////////////////////////////////
/// Copy an existing sound buffer
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_Copy(sfSoundBuffer* soundBuffer)
{
CSFML_CHECK_RETURN(soundBuffer, NULL);
return new sfSoundBuffer(*soundBuffer);
}
////////////////////////////////////////////////////////////
/// Destroy an existing sound buffer
////////////////////////////////////////////////////////////
void sfSoundBuffer_Destroy(sfSoundBuffer* soundBuffer)
{
delete soundBuffer;
}
////////////////////////////////////////////////////////////
/// Save a sound buffer to a file
////////////////////////////////////////////////////////////
sfBool sfSoundBuffer_SaveToFile(const sfSoundBuffer* soundBuffer, const char* filename)
{
CSFML_CALL_RETURN(soundBuffer, SaveToFile(filename), sfFalse)
}
////////////////////////////////////////////////////////////
/// Return the samples contained in a sound buffer
////////////////////////////////////////////////////////////
const sfInt16* sfSoundBuffer_GetSamples(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetSamples(), NULL)
}
////////////////////////////////////////////////////////////
/// Return the number of samples contained in a sound buffer
////////////////////////////////////////////////////////////
size_t sfSoundBuffer_GetSamplesCount(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetSamplesCount(), 0)
}
////////////////////////////////////////////////////////////
/// Get the sample rate of a sound buffer
////////////////////////////////////////////////////////////
unsigned int sfSoundBuffer_GetSampleRate(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetSampleRate(), 0)
}
////////////////////////////////////////////////////////////
/// Return the number of channels of a sound buffer (1 = mono, 2 = stereo, ...)
////////////////////////////////////////////////////////////
unsigned int sfSoundBuffer_GetChannelsCount(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetChannelsCount(), 0)
}
////////////////////////////////////////////////////////////
/// Get the duration of a sound buffer
////////////////////////////////////////////////////////////
float sfSoundBuffer_GetDuration(const sfSoundBuffer* soundBuffer)
{
CSFML_CALL_RETURN(soundBuffer, GetDuration(), 0.f)
}

View file

@ -0,0 +1,90 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundBufferRecorder.h>
#include <SFML/Audio/SoundBufferRecorderStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new sound buffer recorder
////////////////////////////////////////////////////////////
sfSoundBufferRecorder* sfSoundBufferRecorder_Create(void)
{
return new sfSoundBufferRecorder;
}
////////////////////////////////////////////////////////////
/// Destroy an existing sound buffer recorder
////////////////////////////////////////////////////////////
void sfSoundBufferRecorder_Destroy(sfSoundBufferRecorder* soundBufferRecorder)
{
delete soundBufferRecorder;
}
////////////////////////////////////////////////////////////
/// Start the capture.
/// Warning : only one capture can happen at the same time
////////////////////////////////////////////////////////////
void sfSoundBufferRecorder_Start(sfSoundBufferRecorder* soundBufferRecorder, unsigned int sampleRate)
{
CSFML_CALL(soundBufferRecorder, Start(sampleRate));
}
////////////////////////////////////////////////////////////
/// Stop the capture
////////////////////////////////////////////////////////////
void sfSoundBufferRecorder_Stop(sfSoundBufferRecorder* soundBufferRecorder)
{
CSFML_CALL(soundBufferRecorder, Stop());
}
////////////////////////////////////////////////////////////
/// Get the sample rate of a sound buffer recorder
////////////////////////////////////////////////////////////
unsigned int sfSoundBufferRecorder_GetSampleRate(const sfSoundBufferRecorder* soundBufferRecorder)
{
CSFML_CALL_RETURN(soundBufferRecorder, GetSampleRate(), 0);
}
////////////////////////////////////////////////////////////
/// Get the sound buffer containing the captured audio data
/// of a sound buffer recorder
////////////////////////////////////////////////////////////
const sfSoundBuffer* sfSoundBufferRecorder_GetBuffer(const sfSoundBufferRecorder* soundBufferRecorder)
{
CSFML_CHECK_RETURN(soundBufferRecorder, NULL);
soundBufferRecorder->SoundBuffer.This = soundBufferRecorder->This.GetBuffer();
return &soundBufferRecorder->SoundBuffer;
}

View file

@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDBUFFERRECORDERSTRUCT_H
#define SFML_SOUNDBUFFERRECORDERSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundBufferRecorder.hpp>
#include <SFML/Audio/SoundBufferStruct.h>
////////////////////////////////////////////////////////////
// Internal structure of sfSoundBufferRecorder
////////////////////////////////////////////////////////////
struct sfSoundBufferRecorder
{
sf::SoundBufferRecorder This;
mutable sfSoundBuffer SoundBuffer;
};
#endif // SFML_SOUNDBUFFERRECORDERSTRUCT_H

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDBUFFERSTRUCT_H
#define SFML_SOUNDBUFFERSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundBuffer.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfSoundBuffer
////////////////////////////////////////////////////////////
struct sfSoundBuffer
{
sf::SoundBuffer This;
};
#endif // SFML_SOUNDBUFFERSTRUCT_H

View file

@ -0,0 +1,90 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundRecorder.h>
#include <SFML/Audio/SoundRecorderStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new sound recorder with callback functions
/// for processing captured samples
////////////////////////////////////////////////////////////
sfSoundRecorder* sfSoundRecorder_Create(sfSoundRecorderStartCallback onStart,
sfSoundRecorderProcessCallback onProcess,
sfSoundRecorderStopCallback onStop,
void* userData)
{
return new sfSoundRecorder(onStart, onProcess, onStop, userData);
}
////////////////////////////////////////////////////////////
/// Destroy an existing sound recorder
////////////////////////////////////////////////////////////
void sfSoundRecorder_Destroy(sfSoundRecorder* soundRecorder)
{
delete soundRecorder;
}
////////////////////////////////////////////////////////////
/// Start the capture.
/// Warning : only one capture can happen at the same time
////////////////////////////////////////////////////////////
void sfSoundRecorder_Start(sfSoundRecorder* soundRecorder, unsigned int sampleRate)
{
CSFML_CALL(soundRecorder, Start(sampleRate));
}
////////////////////////////////////////////////////////////
/// Stop the capture
////////////////////////////////////////////////////////////
void sfSoundRecorder_Stop(sfSoundRecorder* soundRecorder)
{
CSFML_CALL(soundRecorder, Stop());
}
////////////////////////////////////////////////////////////
/// Get the sample rate of a sound recorder
////////////////////////////////////////////////////////////
unsigned int sfSoundRecorder_GetSampleRate(const sfSoundRecorder* soundRecorder)
{
CSFML_CALL_RETURN(soundRecorder, GetSampleRate(), 0);
}
////////////////////////////////////////////////////////////
/// Tell if the system supports sound capture.
/// If not, this class won't be usable
////////////////////////////////////////////////////////////
sfBool sfSoundRecorder_IsAvailable(void)
{
return sf::SoundRecorder::IsAvailable() ? sfTrue : sfFalse;
}

View file

@ -0,0 +1,102 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDRECORDERSTRUCT_H
#define SFML_SOUNDRECORDERSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundRecorder.hpp>
#include <SFML/Audio/SoundRecorder.h>
////////////////////////////////////////////////////////////
// Helper class implementing the callback forwarding from
// C++ to C in sfSoundRecorder
////////////////////////////////////////////////////////////
class sfSoundRecorderImpl : public sf::SoundRecorder
{
public :
sfSoundRecorderImpl(sfSoundRecorderStartCallback OnStart,
sfSoundRecorderProcessCallback OnProcess,
sfSoundRecorderStopCallback OnStop,
void* UserData) :
myStartCallback (OnStart),
myProcessCallback(OnProcess),
myStopCallback (OnStop),
myUserData (UserData)
{
}
private :
virtual bool OnStart()
{
if (myStartCallback)
return myStartCallback(myUserData) == sfTrue;
else
return true;
}
virtual bool OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount)
{
if (myProcessCallback)
return myProcessCallback(Samples, SamplesCount, myUserData) == sfTrue;
else
return true;
}
virtual void OnStop()
{
if (myStopCallback)
myStopCallback(myUserData);
}
sfSoundRecorderStartCallback myStartCallback;
sfSoundRecorderProcessCallback myProcessCallback;
sfSoundRecorderStopCallback myStopCallback;
void* myUserData;
};
////////////////////////////////////////////////////////////
// Internal structure of sfPacket
////////////////////////////////////////////////////////////
struct sfSoundRecorder
{
sfSoundRecorder(sfSoundRecorderStartCallback OnStart,
sfSoundRecorderProcessCallback OnProcess,
sfSoundRecorderStopCallback OnStop,
void* UserData) :
This(OnStart, OnProcess, OnStop, UserData)
{
}
sfSoundRecorderImpl This;
};
#endif // SFML_SOUNDRECORDERSTRUCT_H

View file

@ -0,0 +1,265 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundStream.h>
#include <SFML/Audio/SoundStreamStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new sound stream
////////////////////////////////////////////////////////////
sfSoundStream* sfSoundStream_Create(sfSoundStreamGetDataCallback onGetData,
sfSoundStreamSeekCallback onSeek,
unsigned int channelsCount,
unsigned int sampleRate,
void* userData)
{
return new sfSoundStream(onGetData, onSeek, channelsCount, sampleRate, userData);
}
////////////////////////////////////////////////////////////
/// Destroy an existing sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_Destroy(sfSoundStream* soundStream)
{
delete soundStream;
}
////////////////////////////////////////////////////////////
/// Start playing a sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_Play(sfSoundStream* soundStream)
{
CSFML_CALL(soundStream, Play());
}
////////////////////////////////////////////////////////////
/// Pause a sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_Pause(sfSoundStream* soundStream)
{
CSFML_CALL(soundStream, Pause());
}
////////////////////////////////////////////////////////////
/// Stop playing a sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_Stop(sfSoundStream* soundStream)
{
CSFML_CALL(soundStream, Stop());
}
////////////////////////////////////////////////////////////
/// Get the status of a sound stream (stopped, paused, playing)
////////////////////////////////////////////////////////////
sfSoundStatus sfSoundStream_GetStatus(const sfSoundStream* soundStream)
{
CSFML_CHECK_RETURN(soundStream, sfStopped);
return static_cast<sfSoundStatus>(soundStream->This.GetStatus());
}
////////////////////////////////////////////////////////////
/// Return the number of channels of a sound stream
/// (1 = mono, 2 = stereo)
////////////////////////////////////////////////////////////
unsigned int sfSoundStream_GetChannelsCount(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetChannelsCount(), 0);
}
////////////////////////////////////////////////////////////
/// Get the sample rate of a sound stream
////////////////////////////////////////////////////////////
unsigned int sfSoundStream_GetSampleRate(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetSampleRate(), 0);
}
////////////////////////////////////////////////////////////
/// Set the pitch of a sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_SetPitch(sfSoundStream* soundStream, float pitch)
{
CSFML_CALL(soundStream, SetPitch(pitch));
}
////////////////////////////////////////////////////////////
/// Set the volume of a sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_SetVolume(sfSoundStream* soundStream, float volume)
{
CSFML_CALL(soundStream, SetVolume(volume));
}
////////////////////////////////////////////////////////////
/// Set the position of a sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_SetPosition(sfSoundStream* soundStream, float x, float y, float z)
{
CSFML_CALL(soundStream, SetPosition(x, y, z));
}
////////////////////////////////////////////////////////////
/// Make the sound stream's position relative to the listener's
/// position, or absolute.
/// The default value is false (absolute)
////////////////////////////////////////////////////////////
void sfSoundStream_SetRelativeToListener(sfSoundStream* soundStream, sfBool relative)
{
CSFML_CALL(soundStream, SetRelativeToListener(relative == sfTrue));
}
////////////////////////////////////////////////////////////
/// Set the minimum distance - closer than this distance,
/// the listener will hear the sound stream at its maximum volume.
/// The default minimum distance is 1.0
////////////////////////////////////////////////////////////
void sfSoundStream_SetMinDistance(sfSoundStream* soundStream, float distance)
{
CSFML_CALL(soundStream, SetMinDistance(distance));
}
////////////////////////////////////////////////////////////
/// Set the attenuation factor - the higher the attenuation, the
/// more the sound stream will be attenuated with distance from listener.
/// The default attenuation factor 1.0
////////////////////////////////////////////////////////////
void sfSoundStream_SetAttenuation(sfSoundStream* soundStream, float attenuation)
{
CSFML_CALL(soundStream, SetAttenuation(attenuation));
}
////////////////////////////////////////////////////////////
/// Set the current playing position of a stream
////////////////////////////////////////////////////////////
void sfSoundStream_SetPlayingOffset(sfSoundStream* soundStream, float timeOffset)
{
CSFML_CALL(soundStream, SetPlayingOffset(timeOffset));
}
////////////////////////////////////////////////////////////
/// Set a stream loop state
////////////////////////////////////////////////////////////
void sfSoundStream_SetLoop(sfSoundStream* soundStream, sfBool loop)
{
CSFML_CALL(soundStream, SetLoop(loop == sfTrue));
}
////////////////////////////////////////////////////////////
/// Get the pitch of a sound stream
////////////////////////////////////////////////////////////
float sfSoundStream_GetPitch(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetPitch(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the volume of a sound stream
////////////////////////////////////////////////////////////
float sfSoundStream_GetVolume(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetVolume(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the position of a sound stream
////////////////////////////////////////////////////////////
void sfSoundStream_GetPosition(const sfSoundStream* soundStream, float* x, float* y, float* z)
{
CSFML_CHECK(soundStream);
sf::Vector3f position = soundStream->This.GetPosition();
if (x) *x = position.x;
if (y) *y = position.y;
if (z) *z = position.z;
}
////////////////////////////////////////////////////////////
/// Tell if the sound stream's position is relative to the listener's
/// position, or if it's absolute
////////////////////////////////////////////////////////////
CSFML_API sfBool sfSoundStream_IsRelativeToListener(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, IsRelativeToListener(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the minimum distance of a sound stream
////////////////////////////////////////////////////////////
float sfSoundStream_GetMinDistance(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetMinDistance(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the attenuation factor of a sound stream
////////////////////////////////////////////////////////////
float sfSoundStream_GetAttenuation(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetAttenuation(), 0.f);
}
////////////////////////////////////////////////////////////
/// Tell whether or not a stream is looping
////////////////////////////////////////////////////////////
sfBool sfSoundStream_GetLoop(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetLoop(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the current playing position of a sound stream
////////////////////////////////////////////////////////////
float sfSoundStream_GetPlayingOffset(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, GetPlayingOffset(), 0.f);
}

View file

@ -0,0 +1,97 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDSTREAMSTRUCT_H
#define SFML_SOUNDSTREAMSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/SoundStream.hpp>
////////////////////////////////////////////////////////////
// Helper class implementing the callback forwarding from
// C++ to C in sfSoundStream
////////////////////////////////////////////////////////////
class sfSoundStreamImpl : public sf::SoundStream
{
public :
sfSoundStreamImpl(sfSoundStreamGetDataCallback OnGetData,
sfSoundStreamSeekCallback OnSeek,
unsigned int ChannelsCount,
unsigned int SampleRate,
void* UserData) :
myGetDataCallback(OnGetData),
mySeekCallback (OnSeek),
myUserData (UserData)
{
Initialize(ChannelsCount, SampleRate);
}
private :
virtual bool OnGetData(Chunk& Data)
{
sfSoundStreamChunk Chunk = {NULL, 0};
bool Continue = (myGetDataCallback(&Chunk, myUserData) == sfTrue);
Data.Samples = Chunk.Samples;
Data.NbSamples = Chunk.NbSamples;
return Continue;
}
virtual void OnSeek(float TimeOffset)
{
if (mySeekCallback)
mySeekCallback(TimeOffset, myUserData);
}
sfSoundStreamGetDataCallback myGetDataCallback;
sfSoundStreamSeekCallback mySeekCallback;
void* myUserData;
};
////////////////////////////////////////////////////////////
// Internal structure of sfSoundStream
////////////////////////////////////////////////////////////
struct sfSoundStream
{
sfSoundStream(sfSoundStreamGetDataCallback OnGetData,
sfSoundStreamSeekCallback OnSeek,
unsigned int ChannelsCount,
unsigned int SampleRate,
void* UserData) :
This(OnGetData, OnSeek, ChannelsCount, SampleRate, UserData)
{
}
sfSoundStreamImpl This;
};
#endif // SFML_SOUNDSTREAMSTRUCT_H

View file

@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOUNDSTRUCT_H
#define SFML_SOUNDSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Audio/Sound.hpp>
#include <SFML/Audio/SoundBufferStruct.h>
////////////////////////////////////////////////////////////
// Internal structure of sfSound
////////////////////////////////////////////////////////////
struct sfSound
{
sf::Sound This;
const sfSoundBuffer* Buffer;
};
#endif // SFML_SOUNDSTRUCT_H

View file

@ -0,0 +1,33 @@
# include the SFML specific macros
include(${CMAKE_SOURCE_DIR}/cmake/Macros.cmake)
# add the CSFML sources path
include_directories(${CMAKE_SOURCE_DIR}/src)
# define the path of our additional CMake modules
set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake/Modules/")
# set the output directory for CSFML libraries
set(LIBRARY_OUTPUT_PATH "${CMAKE_BINARY_DIR}/lib")
# define the export symbol
add_definitions(-DCSFML_EXPORTS)
# find SFML libraries (C++)
if(WINDOWS)
set(SFML_STATIC_LIBRARIES TRUE)
add_definitions(-DSFML_STATIC)
endif()
find_package(SFML 2 COMPONENTS system window network graphics audio REQUIRED)
include_directories(${SFML_INCLUDE_DIR})
# add the modules subdirectories
add_subdirectory(System)
add_subdirectory(Window)
add_subdirectory(Network)
add_subdirectory(Graphics)
add_subdirectory(Audio)
if(WINDOWS)
add_subdirectory(Main)
endif()

View file

@ -0,0 +1,98 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CONVERTEVENT_H
#define SFML_CONVERTEVENT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Event.hpp>
#include <SFML/Window/Event.h>
////////////////////////////////////////////////////////////
// Define a function to convert a sf::Event ot a sfEvent
////////////////////////////////////////////////////////////
inline void ConvertEvent(const sf::Event& SFMLEvent, sfEvent* event)
{
// Convert its type
event->Type = static_cast<sfEventType>(SFMLEvent.Type);
// Fill its fields
switch (event->Type)
{
case sfEvtResized :
event->Size.Width = SFMLEvent.Size.Width;
event->Size.Height = SFMLEvent.Size.Height;
break;
case sfEvtTextEntered :
event->Text.Unicode = SFMLEvent.Text.Unicode;
break;
case sfEvtKeyReleased :
case sfEvtKeyPressed :
event->Key.Code = static_cast<sfKeyCode>(SFMLEvent.Key.Code);
event->Key.Alt = SFMLEvent.Key.Alt ? sfTrue : sfFalse;
event->Key.Control = SFMLEvent.Key.Control ? sfTrue : sfFalse;
event->Key.Shift = SFMLEvent.Key.Shift ? sfTrue : sfFalse;
break;
case sfEvtMouseWheelMoved :
event->MouseWheel.Delta = SFMLEvent.MouseWheel.Delta;
event->MouseWheel.X = SFMLEvent.MouseWheel.X;
event->MouseWheel.Y = SFMLEvent.MouseWheel.Y;
break;
case sfEvtMouseButtonPressed :
case sfEvtMouseButtonReleased :
event->MouseButton.Button = static_cast<sfMouseButton>(SFMLEvent.MouseButton.Button);
event->MouseButton.X = SFMLEvent.MouseButton.X;
event->MouseButton.Y = SFMLEvent.MouseButton.Y;
break;
case sfEvtMouseMoved :
event->MouseMove.X = SFMLEvent.MouseMove.X;
event->MouseMove.Y = SFMLEvent.MouseMove.Y;
break;
case sfEvtJoyButtonPressed :
case sfEvtJoyButtonReleased :
event->JoyButton.JoystickId = SFMLEvent.JoyButton.JoystickId;
event->JoyButton.Button = SFMLEvent.JoyButton.Button;
break;
case sfEvtJoyMoved :
event->JoyMove.JoystickId = SFMLEvent.JoyMove.JoystickId;
event->JoyMove.Axis = static_cast<sfJoyAxis>(SFMLEvent.JoyMove.Axis);
event->JoyMove.Position = SFMLEvent.JoyMove.Position;
break;
default :
break;
}
}
#endif // SFML_CONVERTEVENT_H

View file

@ -0,0 +1,48 @@
set(INCROOT ${CMAKE_SOURCE_DIR}/include/SFML/Graphics)
set(SRCROOT ${CMAKE_SOURCE_DIR}/src/SFML/Graphics)
# all source files
set(SRC
${INCROOT}/BlendMode.h
${SRCROOT}/Color.cpp
${INCROOT}/Color.h
${SRCROOT}/Font.cpp
${SRCROOT}/FontStruct.h
${INCROOT}/Font.h
${INCROOT}/Glyph.h
${SRCROOT}/Image.cpp
${SRCROOT}/ImageStruct.h
${INCROOT}/Image.h
${SRCROOT}/Rect.cpp
${INCROOT}/Rect.h
${SRCROOT}/RenderImage.cpp
${SRCROOT}/RenderImageStruct.h
${INCROOT}/RenderImage.h
${SRCROOT}/RenderWindow.cpp
${SRCROOT}/RenderWindowStruct.h
${INCROOT}/RenderWindow.h
${SRCROOT}/Shader.cpp
${SRCROOT}/ShaderStruct.h
${INCROOT}/Shader.h
${SRCROOT}/Shape.cpp
${SRCROOT}/ShapeStruct.h
${INCROOT}/Shape.h
${SRCROOT}/Sprite.cpp
${SRCROOT}/SpriteStruct.h
${INCROOT}/Sprite.h
${SRCROOT}/Text.cpp
${SRCROOT}/TextStruct.h
${INCROOT}/Text.h
${INCROOT}/Types.h
${SRCROOT}/View.cpp
${SRCROOT}/ViewStruct.h
${INCROOT}/View.h
)
# define the csfml-graphics target
csfml_add_library(csfml-graphics
SOURCES ${SRC}
DEPENDS optimized ${SFML_GRAPHICS_LIBRARY} debug ${SFML_GRAPHICS_LIBRARY_DEBUG}
optimized ${SFML_WINDOW_LIBRARY} debug ${SFML_WINDOW_LIBRARY_DEBUG}
optimized ${SFML_SYSTEM_LIBRARY} debug ${SFML_SYSTEM_LIBRARY_DEBUG})

View file

@ -0,0 +1,102 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Color.h>
#include <SFML/Internal.h>
#include <algorithm>
////////////////////////////////////////////////////////////
/// Define some common colors
////////////////////////////////////////////////////////////
sfColor sfBlack = sfColor_FromRGB( 0, 0, 0);
sfColor sfWhite = sfColor_FromRGB(255, 255, 255);
sfColor sfRed = sfColor_FromRGB(255, 0, 0);
sfColor sfGreen = sfColor_FromRGB( 0, 255, 0);
sfColor sfBlue = sfColor_FromRGB( 0, 0, 255);
sfColor sfYellow = sfColor_FromRGB(255, 255, 0);
sfColor sfMagenta = sfColor_FromRGB(255, 0, 255);
sfColor sfCyan = sfColor_FromRGB( 0, 255, 255);
////////////////////////////////////////////////////////////
/// Construct a color from its 3 RGB components
////////////////////////////////////////////////////////////
sfColor sfColor_FromRGB(sfUint8 red, sfUint8 green, sfUint8 blue)
{
return sfColor_FromRGBA(red, green, blue, 255);
}
////////////////////////////////////////////////////////////
/// Construct a color from its 4 RGBA components
////////////////////////////////////////////////////////////
sfColor sfColor_FromRGBA(sfUint8 red, sfUint8 green, sfUint8 blue, sfUint8 alpha)
{
sfColor color;
color.r = red;
color.g = green;
color.b = blue;
color.a = alpha;
return color;
}
////////////////////////////////////////////////////////////
/// Add two colors
////////////////////////////////////////////////////////////
sfColor sfColor_Add(sfColor color1, sfColor color2)
{
int red = std::min(color1.r + color2.r, 255);
int green = std::min(color1.g + color2.g, 255);
int blue = std::min(color1.b + color2.b, 255);
int alpha = std::min(color1.a + color2.a, 255);
return sfColor_FromRGBA(static_cast<sfUint8>(red),
static_cast<sfUint8>(green),
static_cast<sfUint8>(blue),
static_cast<sfUint8>(alpha));
}
////////////////////////////////////////////////////////////
/// Modulate two colors
////////////////////////////////////////////////////////////
sfColor sfColor_Modulate(sfColor color1, sfColor color2)
{
int red = color1.r * color2.r / 255;
int green = color1.g * color2.g / 255;
int blue = color1.b * color2.b / 255;
int alpha = color1.a * color2.a / 255;
return sfColor_FromRGBA(static_cast<sfUint8>(red),
static_cast<sfUint8>(green),
static_cast<sfUint8>(blue),
static_cast<sfUint8>(alpha));
}

View file

@ -0,0 +1,148 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Font.h>
#include <SFML/Graphics/FontStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new font from a file
////////////////////////////////////////////////////////////
sfFont* sfFont_CreateFromFile(const char* filename)
{
sfFont* font = new sfFont;
if (!font->This.LoadFromFile(filename))
{
delete font;
font = NULL;
}
return font;
}
////////////////////////////////////////////////////////////
/// Create a new font from a file in memory
////////////////////////////////////////////////////////////
sfFont* sfFont_CreateFromMemory(const void* data, size_t sizeInBytes)
{
sfFont* font = new sfFont;
if (!font->This.LoadFromMemory(data, sizeInBytes))
{
delete font;
font = NULL;
}
return font;
}
////////////////////////////////////////////////////////////
/// Copy an existing font
////////////////////////////////////////////////////////////
sfFont* sfFont_Copy(sfFont* font)
{
CSFML_CHECK_RETURN(font, NULL);
return new sfFont(*font);
}
////////////////////////////////////////////////////////////
/// Destroy an existing font
////////////////////////////////////////////////////////////
void sfFont_Destroy(sfFont* font)
{
delete font;
}
////////////////////////////////////////////////////////////
/// Get a glyph in a font
////////////////////////////////////////////////////////////
sfGlyph sfFont_GetGlyph(sfFont* font, sfUint32 codePoint, unsigned int characterSize, sfBool bold)
{
sfGlyph glyph = {0, {0, 0, 0, 0}, {0, 0, 0, 0}};
CSFML_CHECK_RETURN(font, glyph);
sf::Glyph SFMLGlyph = font->This.GetGlyph(codePoint, characterSize, bold == sfTrue);
glyph.Advance = SFMLGlyph.Advance;
glyph.Bounds.Left = SFMLGlyph.Bounds.Left;
glyph.Bounds.Top = SFMLGlyph.Bounds.Top;
glyph.Bounds.Width = SFMLGlyph.Bounds.Width;
glyph.Bounds.Height = SFMLGlyph.Bounds.Height;
glyph.SubRect.Left = SFMLGlyph.SubRect.Left;
glyph.SubRect.Top = SFMLGlyph.SubRect.Top;
glyph.SubRect.Width = SFMLGlyph.SubRect.Width;
glyph.SubRect.Height = SFMLGlyph.SubRect.Height;
return glyph;
}
////////////////////////////////////////////////////////////
/// Get the kerning value corresponding to a given pair of characters in a font
////////////////////////////////////////////////////////////
int sfFont_GetKerning(sfFont* font, sfUint32 first, sfUint32 second, unsigned int characterSize)
{
CSFML_CALL_RETURN(font, GetKerning(first, second, characterSize), 0);
}
////////////////////////////////////////////////////////////
/// Get the line spacing value
////////////////////////////////////////////////////////////
int sfFont_GetLineSpacing(sfFont* font, unsigned int characterSize)
{
CSFML_CALL_RETURN(font, GetLineSpacing(characterSize), 0);
}
////////////////////////////////////////////////////////////
/// Get the image containing the glyphs of a given size in a font
////////////////////////////////////////////////////////////
const sfImage* sfFont_GetImage(sfFont* font, unsigned int characterSize)
{
CSFML_CHECK_RETURN(font, NULL);
*font->Images[characterSize].This = font->This.GetImage(characterSize);
return &font->Images[characterSize];
}
////////////////////////////////////////////////////////////
/// Get the built-in default font (Arial)
////////////////////////////////////////////////////////////
const sfFont* sfFont_GetDefaultFont(void)
{
static sfFont defaultFont = {sf::Font::GetDefaultFont(), std::map<unsigned int, sfImage>()};
return &defaultFont;
}

View file

@ -0,0 +1,46 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_FONTSTRUCT_H
#define SFML_FONTSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Font.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <map>
////////////////////////////////////////////////////////////
// Internal structure of sfFont
////////////////////////////////////////////////////////////
struct sfFont
{
sf::Font This;
std::map<unsigned int, sfImage> Images;
};
#endif // SFML_FONTSTRUCT_H

View file

@ -0,0 +1,263 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Image.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/RenderWindowStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new empty image
////////////////////////////////////////////////////////////
sfImage* sfImage_Create(void)
{
return new sfImage;
}
////////////////////////////////////////////////////////////
/// Create a new image filled with a color
////////////////////////////////////////////////////////////
sfImage* sfImage_CreateFromColor(unsigned int width, unsigned int height, sfColor color)
{
sfImage* image = new sfImage;
if (!image->This->Create(width, height, sf::Color(color.r, color.g, color.b, color.a)))
{
delete image;
image = NULL;
}
return image;
}
////////////////////////////////////////////////////////////
/// Create a new image from an array of pixels in memory
////////////////////////////////////////////////////////////
sfImage* sfImage_CreateFromPixels(unsigned int width, unsigned int height, const sfUint8* data)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromPixels(width, height, data))
{
delete image;
image = NULL;
}
return image;
}
////////////////////////////////////////////////////////////
/// Create a new image from a file
////////////////////////////////////////////////////////////
sfImage* sfImage_CreateFromFile(const char* filename)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromFile(filename))
{
delete image;
image = NULL;
}
return image;
}
////////////////////////////////////////////////////////////
/// Create a new image from a file in memory
////////////////////////////////////////////////////////////
sfImage* sfImage_CreateFromMemory(const void* data, size_t sizeInBytes)
{
sfImage* image = new sfImage;
if (!image->This->LoadFromMemory(data, sizeInBytes))
{
delete image;
image = NULL;
}
return image;
}
////////////////////////////////////////////////////////////
/// Copy an existing image
////////////////////////////////////////////////////////////
sfImage* sfImage_Copy(sfImage* image)
{
CSFML_CHECK_RETURN(image, NULL);
return new sfImage(*image);
}
////////////////////////////////////////////////////////////
/// Destroy an existing image
////////////////////////////////////////////////////////////
void sfImage_Destroy(sfImage* image)
{
delete image;
}
////////////////////////////////////////////////////////////
/// Save the content of an image to a file
////////////////////////////////////////////////////////////
sfBool sfImage_SaveToFile(const sfImage* image, const char* filename)
{
CSFML_CALL_PTR_RETURN(image, SaveToFile(filename), sfFalse);
}
////////////////////////////////////////////////////////////
/// Create a transparency mask for an image from a specified colorkey
////////////////////////////////////////////////////////////
void sfImage_CreateMaskFromColor(sfImage* image, sfColor colorKey, sfUint8 alpha)
{
sf::Color SFMLColor(colorKey.r, colorKey.g, colorKey.b, colorKey.a);
CSFML_CALL_PTR(image, CreateMaskFromColor(SFMLColor, alpha));
}
////////////////////////////////////////////////////////////
/// Copy pixels from another image onto this one.
/// This function does a slow pixel copy and should only
/// be used at initialization time
////////////////////////////////////////////////////////////
void sfImage_CopyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect)
{
CSFML_CHECK(source);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR(image, Copy(*source->This, destX, destY, SFMLRect));
}
////////////////////////////////////////////////////////////
/// Create the image from the current contents of the
/// given window
////////////////////////////////////////////////////////////
CSFML_API sfBool sfImage_CopyScreen(sfImage* image, sfRenderWindow* window, sfIntRect sourceRect)
{
CSFML_CHECK_RETURN(window, sfFalse);
sf::IntRect SFMLRect(sourceRect.Left, sourceRect.Top, sourceRect.Width, sourceRect.Height);
CSFML_CALL_PTR_RETURN(image, CopyScreen(window->This, SFMLRect), sfFalse);
}
////////////////////////////////////////////////////////////
/// Change the color of a pixel of an image
/// Don't forget to call Update when you end modifying pixels
////////////////////////////////////////////////////////////
void sfImage_SetPixel(sfImage* image, unsigned int x, unsigned int y, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL_PTR(image, SetPixel(x, y, SFMLColor));
}
////////////////////////////////////////////////////////////
/// Get a pixel from an image
////////////////////////////////////////////////////////////
sfColor sfImage_GetPixel(const sfImage* image, unsigned int x, unsigned int y)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(image, color);
sf::Color SFMLColor = image->This->GetPixel(x, y);
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
////////////////////////////////////////////////////////////
/// Get a read-only pointer to the array of pixels of an image (8 bits integers RGBA)
/// Array size is sfImage_GetWidth() x sfImage_GetHeight() x 4
/// This pointer becomes invalid if you reload or resize the image
////////////////////////////////////////////////////////////
const sfUint8* sfImage_GetPixelsPtr(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetPixelsPtr(), NULL);
}
////////////////////////////////////////////////////////////
/// Update a sub-rectangle of the image from an array of pixels
////////////////////////////////////////////////////////////
void sfImage_UpdatePixels(const sfImage* image, const sfUint8* pixels, sfIntRect rectangle)
{
sf::IntRect rect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height);
CSFML_CALL_PTR(image, UpdatePixels(pixels, rect));
}
////////////////////////////////////////////////////////////
/// Bind the image for rendering
////////////////////////////////////////////////////////////
void sfImage_Bind(const sfImage* image)
{
CSFML_CALL_PTR(image, Bind());
}
////////////////////////////////////////////////////////////
/// Enable or disable image smooth filter
////////////////////////////////////////////////////////////
void sfImage_SetSmooth(sfImage* image, sfBool smooth)
{
CSFML_CALL_PTR(image, SetSmooth(smooth == sfTrue));
}
////////////////////////////////////////////////////////////
/// Return the width of the image
////////////////////////////////////////////////////////////
unsigned int sfImage_GetWidth(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Return the height of the image
////////////////////////////////////////////////////////////
unsigned int sfImage_GetHeight(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Tells whether the smoothing filter is enabled or not on an image
////////////////////////////////////////////////////////////
sfBool sfImage_IsSmooth(const sfImage* image)
{
CSFML_CALL_PTR_RETURN(image, IsSmooth(), sfFalse);
}

View file

@ -0,0 +1,68 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_IMAGESTRUCT_H
#define SFML_IMAGESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Image.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfImage
////////////////////////////////////////////////////////////
struct sfImage
{
sfImage()
{
This = new sf::Image;
OwnInstance = true;
}
sfImage(sf::Image* image)
{
This = image;
OwnInstance = false;
}
sfImage(const sfImage& image)
{
This = image.This ? new sf::Image(*image.This) : NULL;
OwnInstance = true;
}
~sfImage()
{
if (OwnInstance)
delete This;
}
sf::Image* This;
bool OwnInstance;
};
#endif // SFML_IMAGESTRUCT_H

View file

@ -0,0 +1,100 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/Rect.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Check if a point is inside a rectangle's area
////////////////////////////////////////////////////////////
sfBool sfFloatRect_Contains(const sfFloatRect* rect, float x, float y)
{
CSFML_CHECK_RETURN(rect, sfFalse)
return sf::FloatRect(rect->Left, rect->Top, rect->Width, rect->Height).Contains(x, y);
}
sfBool sfIntRect_Contains(const sfIntRect* rect, int x, int y)
{
CSFML_CHECK_RETURN(rect, sfFalse)
return sf::IntRect(rect->Left, rect->Top, rect->Width, rect->Height).Contains(x, y);
}
////////////////////////////////////////////////////////////
/// Check intersection between two rectangles
////////////////////////////////////////////////////////////
sfBool sfFloatRect_Intersects(const sfFloatRect* rect1, const sfFloatRect* rect2, sfFloatRect* intersection)
{
CSFML_CHECK_RETURN(rect1, sfFalse)
CSFML_CHECK_RETURN(rect2, sfFalse)
sf::FloatRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
sf::FloatRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
if (intersection)
{
sf::FloatRect overlap;
bool intersects = SFMLRect1.Intersects(SFMLRect2, overlap);
intersection->Left = overlap.Left;
intersection->Top = overlap.Top;
intersection->Width = overlap.Width;
intersection->Height = overlap.Height;
return intersects;
}
else
{
return SFMLRect1.Intersects(SFMLRect2);
}
}
sfBool sfIntRect_Intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection)
{
CSFML_CHECK_RETURN(rect1, sfFalse)
CSFML_CHECK_RETURN(rect2, sfFalse)
sf::IntRect SFMLRect1(rect1->Left, rect1->Top, rect1->Width, rect1->Height);
sf::IntRect SFMLRect2(rect2->Left, rect2->Top, rect2->Width, rect2->Height);
if (intersection)
{
sf::IntRect overlap;
bool intersects = SFMLRect1.Intersects(SFMLRect2, overlap);
intersection->Left = overlap.Left;
intersection->Top = overlap.Top;
intersection->Width = overlap.Width;
intersection->Height = overlap.Height;
return intersects;
}
else
{
return SFMLRect1.Intersects(SFMLRect2);
}
}

View file

@ -0,0 +1,257 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImage.h>
#include <SFML/Graphics/RenderImageStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new renderimage
////////////////////////////////////////////////////////////
sfRenderImage* sfRenderImage_Create(unsigned int width, unsigned int height, sfBool depthBuffer)
{
sfRenderImage* renderImage = new sfRenderImage;
renderImage->This.Create(width, height, depthBuffer == sfTrue);
renderImage->Target = new sfImage(const_cast<sf::Image*>(&renderImage->This.GetImage()));
renderImage->DefaultView.This = renderImage->This.GetDefaultView();
renderImage->CurrentView.This = renderImage->This.GetView();
return renderImage;
}
////////////////////////////////////////////////////////////
/// Destroy an existing renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_Destroy(sfRenderImage* renderImage)
{
delete renderImage->Target;
delete renderImage;
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a renderimage
////////////////////////////////////////////////////////////
unsigned int sfRenderImage_GetWidth(const sfRenderImage* renderImage)
{
CSFML_CALL_RETURN(renderImage, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a renderimage
////////////////////////////////////////////////////////////
unsigned int sfRenderImage_GetHeight(const sfRenderImage* renderImage)
{
CSFML_CALL_RETURN(renderImage, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Set a renderimage as the current target for rendering
////////////////////////////////////////////////////////////
sfBool sfRenderImage_SetActive(sfRenderImage* renderImage, sfBool active)
{
CSFML_CALL_RETURN(renderImage, SetActive(active == sfTrue), sfFalse)
}
////////////////////////////////////////////////////////////
/// Save the current OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderImage_SaveGLStates(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, SaveGLStates());
}
////////////////////////////////////////////////////////////
/// Restore the previously saved OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderImage_RestoreGLStates(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, RestoreGLStates());
}
////////////////////////////////////////////////////////////
/// Update the contents of the target image
////////////////////////////////////////////////////////////
void sfRenderImage_Display(sfRenderImage* renderImage)
{
CSFML_CALL(renderImage, Display())
}
////////////////////////////////////////////////////////////
/// Draw something on a renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_DrawSprite(sfRenderImage* renderImage, const sfSprite* sprite)
{
CSFML_CHECK(sprite);
CSFML_CALL(renderImage, Draw(sprite->This));
}
void sfRenderImage_DrawShape(sfRenderImage* renderImage, const sfShape* shape)
{
CSFML_CHECK(shape);
CSFML_CALL(renderImage, Draw(shape->This));
}
void sfRenderImage_DrawText(sfRenderImage* renderImage, const sfText* text)
{
CSFML_CHECK(text);
CSFML_CALL(renderImage, Draw(text->This));
}
////////////////////////////////////////////////////////////
/// Draw something on a renderimage with a shader
////////////////////////////////////////////////////////////
void sfRenderImage_DrawSpriteWithShader(sfRenderImage* renderImage, const sfSprite* sprite, const sfShader* shader)
{
CSFML_CHECK(sprite);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(sprite->This, shader->This));
}
void sfRenderImage_DrawShapeWithShader(sfRenderImage* renderImage, const sfShape* shape, const sfShader* shader)
{
CSFML_CHECK(shape);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(shape->This, shader->This));
}
void sfRenderImage_DrawTextWithShader(sfRenderImage* renderImage, const sfText* text, const sfShader* shader)
{
CSFML_CHECK(text);
CSFML_CHECK(shader);
CSFML_CALL(renderImage, Draw(text->This, shader->This));
}
////////////////////////////////////////////////////////////
/// Clear the renderimage with the given color
////////////////////////////////////////////////////////////
void sfRenderImage_Clear(sfRenderImage* renderImage, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderImage, Clear(SFMLColor));
}
////////////////////////////////////////////////////////////
/// Change the current active view of a renderimage
////////////////////////////////////////////////////////////
void sfRenderImage_SetView(sfRenderImage* renderImage, const sfView* view)
{
CSFML_CHECK(view);
CSFML_CALL(renderImage, SetView(view->This));
renderImage->CurrentView.This = view->This;
}
////////////////////////////////////////////////////////////
/// Get the current active view of a renderimage
////////////////////////////////////////////////////////////
const sfView* sfRenderImage_GetView(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return &renderImage->CurrentView;
}
////////////////////////////////////////////////////////////
/// Get the default view of a renderimage
////////////////////////////////////////////////////////////
const sfView* sfRenderImage_GetDefaultView(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return &renderImage->DefaultView;
}
////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target
////////////////////////////////////////////////////////////
sfIntRect sfRenderImage_GetViewport(const sfRenderImage* renderImage, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderImage, rect);
sf::IntRect SFMLrect = renderImage->This.GetViewport(view->This);
rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top;
rect.Width = SFMLrect.Width;
rect.Height = SFMLrect.Height;
return rect;
}
////////////////////////////////////////////////////////////
/// Convert a point in image coordinates into view coordinates
////////////////////////////////////////////////////////////
void sfRenderImage_ConvertCoords(const sfRenderImage* renderImage, unsigned int imageX, unsigned int imageY, float* viewX, float* viewY, const sfView* targetView)
{
CSFML_CHECK(renderImage);
sf::Vector2f point;
if (targetView)
point = renderImage->This.ConvertCoords(imageX, imageY, targetView->This);
else
point = renderImage->This.ConvertCoords(imageX, imageY);
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}
////////////////////////////////////////////////////////////
/// Get the target image
////////////////////////////////////////////////////////////
const sfImage* sfRenderImage_GetImage(const sfRenderImage* renderImage)
{
CSFML_CHECK_RETURN(renderImage, NULL);
return renderImage->Target;
}
////////////////////////////////////////////////////////////
/// Check whether the system supports render images or not
////////////////////////////////////////////////////////////
sfBool sfRenderImage_IsAvailable(void)
{
return sf::RenderImage::IsAvailable() ? sfTrue : sfFalse;
}

View file

@ -0,0 +1,49 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERIMAGESTRUCT_H
#define SFML_RENDERIMAGESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderImage.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/ViewStruct.h>
#include <SFML/Window/InputStruct.h>
////////////////////////////////////////////////////////////
// Internal structure of sfRenderWindow
////////////////////////////////////////////////////////////
struct sfRenderImage
{
sf::RenderImage This;
const sfImage* Target;
sfView DefaultView;
sfView CurrentView;
};
#endif // SFML_RENDERIMAGESTRUCT_H

View file

@ -0,0 +1,485 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderWindow.h>
#include <SFML/Graphics/RenderWindowStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Internal.h>
#include <SFML/ConvertEvent.h>
////////////////////////////////////////////////////////////
/// Construct a new renderwindow
////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, unsigned long style, const sfContextSettings* settings)
{
// Convert video mode
sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window
sfRenderWindow* renderWindow = new sfRenderWindow;
renderWindow->This.Create(videoMode, title, style, params);
renderWindow->Input.This = &renderWindow->This.GetInput();
renderWindow->DefaultView.This = renderWindow->This.GetDefaultView();
renderWindow->CurrentView.This = renderWindow->This.GetView();
return renderWindow;
}
////////////////////////////////////////////////////////////
/// Construct a renderwindow from an existing control
////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, const sfContextSettings* settings)
{
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window
sfRenderWindow* renderWindow = new sfRenderWindow;
renderWindow->This.Create(handle, params);
renderWindow->Input.This = &renderWindow->This.GetInput();
renderWindow->DefaultView.This = renderWindow->This.GetDefaultView();
renderWindow->CurrentView.This = renderWindow->This.GetView();
return renderWindow;
}
////////////////////////////////////////////////////////////
/// Destroy an existing renderwindow
////////////////////////////////////////////////////////////
void sfRenderWindow_Destroy(sfRenderWindow* renderWindow)
{
delete renderWindow;
}
////////////////////////////////////////////////////////////
/// Close a renderwindow (but doesn't destroy the internal data)
////////////////////////////////////////////////////////////
void sfRenderWindow_Close(sfRenderWindow* renderWindow)
{
CSFML_CALL(renderWindow, Close());
}
////////////////////////////////////////////////////////////
/// Tell whether or not a renderwindow is opened
////////////////////////////////////////////////////////////
sfBool sfRenderWindow_IsOpened(const sfRenderWindow* renderWindow)
{
CSFML_CALL_RETURN(renderWindow, IsOpened(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a window
////////////////////////////////////////////////////////////
unsigned int sfRenderWindow_GetWidth(const sfRenderWindow* renderWindow)
{
CSFML_CALL_RETURN(renderWindow, GetWidth(), 0);
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a window
////////////////////////////////////////////////////////////
unsigned int sfRenderWindow_GetHeight(const sfRenderWindow* renderWindow)
{
CSFML_CALL_RETURN(renderWindow, GetHeight(), 0);
}
////////////////////////////////////////////////////////////
/// Get the creation settings of a window
////////////////////////////////////////////////////////////
sfContextSettings sfRenderWindow_GetSettings(const sfRenderWindow* renderWindow)
{
sfContextSettings settings = {0, 0, 0, 2, 0};
CSFML_CHECK_RETURN(renderWindow, settings);
const sf::ContextSettings& params = renderWindow->This.GetSettings();
settings.DepthBits = params.DepthBits;
settings.StencilBits = params.StencilBits;
settings.AntialiasingLevel = params.AntialiasingLevel;
return settings;
}
////////////////////////////////////////////////////////////
/// Get the event on top of events stack of a window, if any, and pop it
////////////////////////////////////////////////////////////
sfBool sfRenderWindow_GetEvent(sfRenderWindow* renderWindow, sfEvent* event)
{
CSFML_CHECK_RETURN(renderWindow, sfFalse);
CSFML_CHECK_RETURN(event, sfFalse);
// Get the event
sf::Event SFMLEvent;
sfBool ret = renderWindow->This.GetEvent(SFMLEvent);
// No event, return
if (!ret)
return sfFalse;
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
return sfTrue;
}
////////////////////////////////////////////////////////////
/// Wait for an event and return it
////////////////////////////////////////////////////////////
sfBool sfRenderWindow_WaitEvent(sfRenderWindow* renderWindow, sfEvent* event)
{
CSFML_CHECK_RETURN(renderWindow, sfFalse);
CSFML_CHECK_RETURN(event, sfFalse);
// Get the event
sf::Event SFMLEvent;
sfBool ret = renderWindow->This.WaitEvent(SFMLEvent);
// Error, return
if (!ret)
return sfFalse;
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
return sfTrue;
}
////////////////////////////////////////////////////////////
/// Enable / disable vertical synchronization on a window
////////////////////////////////////////////////////////////
void sfRenderWindow_UseVerticalSync(sfRenderWindow* renderWindow, sfBool enabled)
{
CSFML_CALL(renderWindow, UseVerticalSync(enabled == sfTrue));
}
////////////////////////////////////////////////////////////
/// Show or hide the mouse cursor on a window
////////////////////////////////////////////////////////////
void sfRenderWindow_ShowMouseCursor(sfRenderWindow* renderWindow, sfBool show)
{
CSFML_CALL(renderWindow, ShowMouseCursor(show == sfTrue));
}
////////////////////////////////////////////////////////////
/// Change the position of the mouse cursor on a window
////////////////////////////////////////////////////////////
void sfRenderWindow_SetCursorPosition(sfRenderWindow* renderWindow, unsigned int left, unsigned int top)
{
CSFML_CALL(renderWindow, SetCursorPosition(left, top));
}
////////////////////////////////////////////////////////////
/// Change the position of a window on screen.
/// Only works for top-level windows
////////////////////////////////////////////////////////////
void sfRenderWindow_SetPosition(sfRenderWindow* renderWindow, int left, int top)
{
CSFML_CALL(renderWindow, SetPosition(left, top));
}
////////////////////////////////////////////////////////////
/// Change the size of the rendering region of a window
////////////////////////////////////////////////////////////
void sfRenderWindow_SetSize(sfRenderWindow* renderWindow, unsigned int width, unsigned int height)
{
CSFML_CALL(renderWindow, SetSize(width, height))
}
////////////////////////////////////////////////////////////
/// Show or hide a window
////////////////////////////////////////////////////////////
void sfRenderWindow_Show(sfRenderWindow* renderWindow, sfBool show)
{
CSFML_CALL(renderWindow, Show(show == sfTrue));
}
////////////////////////////////////////////////////////////
/// Enable or disable automatic key-repeat for keydown events.
/// Automatic key-repeat is enabled by default
////////////////////////////////////////////////////////////
void sfRenderWindow_EnableKeyRepeat(sfRenderWindow* renderWindow, sfBool enabled)
{
CSFML_CALL(renderWindow, EnableKeyRepeat(enabled == sfTrue));
}
////////////////////////////////////////////////////////////
/// Change the window's icon
////////////////////////////////////////////////////////////
void sfRenderWindow_SetIcon(sfRenderWindow* renderWindow, unsigned int width, unsigned int height, const sfUint8* pixels)
{
CSFML_CALL(renderWindow, SetIcon(width, height, pixels))
}
////////////////////////////////////////////////////////////
/// Set a window as the current target for rendering
////////////////////////////////////////////////////////////
sfBool sfRenderWindow_SetActive(sfRenderWindow* renderWindow, sfBool active)
{
CSFML_CALL_RETURN(renderWindow, SetActive(active == sfTrue), sfFalse)
}
////////////////////////////////////////////////////////////
/// Save the current OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderWindow_SaveGLStates(sfRenderWindow* renderWindow)
{
CSFML_CALL(renderWindow, SaveGLStates());
}
////////////////////////////////////////////////////////////
/// Restore the previously saved OpenGL render states and matrices
////////////////////////////////////////////////////////////
void sfRenderWindow_RestoreGLStates(sfRenderWindow* renderWindow)
{
CSFML_CALL(renderWindow, RestoreGLStates());
}
////////////////////////////////////////////////////////////
/// Display a window on screen
////////////////////////////////////////////////////////////
void sfRenderWindow_Display(sfRenderWindow* renderWindow)
{
CSFML_CALL(renderWindow, Display());
}
////////////////////////////////////////////////////////////
/// Get the input manager of a window
////////////////////////////////////////////////////////////
const sfInput* sfRenderWindow_GetInput(const sfRenderWindow* renderWindow)
{
CSFML_CHECK_RETURN(renderWindow, NULL);
return &renderWindow->Input;
}
////////////////////////////////////////////////////////////
/// Limit the framerate to a maximum fixed frequency for a window
////////////////////////////////////////////////////////////
void sfRenderWindow_SetFramerateLimit(sfRenderWindow* renderWindow, unsigned int limit)
{
CSFML_CALL(renderWindow, SetFramerateLimit(limit));
}
////////////////////////////////////////////////////////////
/// Get time elapsed since last frame of a window
////////////////////////////////////////////////////////////
float sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow)
{
CSFML_CALL_RETURN(renderWindow, GetFrameTime(), 0.f);
}
////////////////////////////////////////////////////////////
/// Change the joystick threshold, ie. the value below which
/// no move event will be generated
////////////////////////////////////////////////////////////
void sfRenderWindow_SetJoystickThreshold(sfRenderWindow* renderWindow, float threshold)
{
CSFML_CALL(renderWindow, SetJoystickThreshold(threshold));
}
////////////////////////////////////////////////////////////
/// Retrieve the Os-specific handle of a window
////////////////////////////////////////////////////////////
sfWindowHandle sfRenderWindow_GetSystemHandle(const sfRenderWindow* renderWindow)
{
CSFML_CHECK_RETURN(renderWindow, NULL);
return (sfWindowHandle)renderWindow->This.GetSystemHandle();
}
////////////////////////////////////////////////////////////
/// Draw something on a renderwindow
////////////////////////////////////////////////////////////
void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, const sfSprite* sprite)
{
CSFML_CHECK(sprite);
CSFML_CALL(renderWindow, Draw(sprite->This));
}
void sfRenderWindow_DrawShape(sfRenderWindow* renderWindow, const sfShape* shape)
{
CSFML_CHECK(shape);
CSFML_CALL(renderWindow, Draw(shape->This));
}
void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, const sfText* text)
{
CSFML_CHECK(text);
CSFML_CALL(renderWindow, Draw(text->This));
}
////////////////////////////////////////////////////////////
/// Draw something on a renderwindow with a shader
////////////////////////////////////////////////////////////
void sfRenderWindow_DrawSpriteWithShader(sfRenderWindow* renderWindow, const sfSprite* sprite, const sfShader* shader)
{
CSFML_CHECK(sprite);
CSFML_CHECK(shader);
CSFML_CALL(renderWindow, Draw(sprite->This, shader->This));
}
void sfRenderWindow_DrawShapeWithShader(sfRenderWindow* renderWindow, const sfShape* shape, const sfShader* shader)
{
CSFML_CHECK(shape);
CSFML_CHECK(shader);
CSFML_CALL(renderWindow, Draw(shape->This, shader->This));
}
void sfRenderWindow_DrawTextWithShader(sfRenderWindow* renderWindow, const sfText* text, const sfShader* shader)
{
CSFML_CHECK(text);
CSFML_CHECK(shader);
CSFML_CALL(renderWindow, Draw(text->This, shader->This));
}
////////////////////////////////////////////////////////////
/// Clear the screen with the given color
////////////////////////////////////////////////////////////
void sfRenderWindow_Clear(sfRenderWindow* renderWindow, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderWindow, Clear(SFMLColor));
}
////////////////////////////////////////////////////////////
/// Change the current active view of a renderwindow
////////////////////////////////////////////////////////////
void sfRenderWindow_SetView(sfRenderWindow* renderWindow, const sfView* view)
{
CSFML_CHECK(view);
CSFML_CALL(renderWindow, SetView(view->This));
renderWindow->CurrentView.This = view->This;
}
////////////////////////////////////////////////////////////
/// Get the current active view of a renderwindow
////////////////////////////////////////////////////////////
const sfView* sfRenderWindow_GetView(const sfRenderWindow* renderWindow)
{
CSFML_CHECK_RETURN(renderWindow, NULL);
return &renderWindow->CurrentView;
}
////////////////////////////////////////////////////////////
/// Get the default view of a renderwindow
////////////////////////////////////////////////////////////
const sfView* sfRenderWindow_GetDefaultView(const sfRenderWindow* renderWindow)
{
CSFML_CHECK_RETURN(renderWindow, NULL);
return &renderWindow->DefaultView;
}
////////////////////////////////////////////////////////////
/// Get the viewport of a view applied to this target
////////////////////////////////////////////////////////////
sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindow, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderWindow, rect);
sf::IntRect SFMLrect = renderWindow->This.GetViewport(view->This);
rect.Left = SFMLrect.Left;
rect.Top = SFMLrect.Top;
rect.Width = SFMLrect.Width;
rect.Height = SFMLrect.Height;
return rect;
}
////////////////////////////////////////////////////////////
/// Convert a point in window coordinates into view coordinates
////////////////////////////////////////////////////////////
void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView)
{
CSFML_CHECK(renderWindow);
sf::Vector2f point;
if (targetView)
point = renderWindow->This.ConvertCoords(windowX, windowY, targetView->This);
else
point = renderWindow->This.ConvertCoords(windowX, windowY);
if (viewX) *viewX = point.x;
if (viewY) *viewY = point.y;
}

View file

@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_RENDERWINDOWSTRUCT_H
#define SFML_RENDERWINDOWSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/RenderWindow.hpp>
#include <SFML/Graphics/ViewStruct.h>
#include <SFML/Window/InputStruct.h>
////////////////////////////////////////////////////////////
// Internal structure of sfRenderWindow
////////////////////////////////////////////////////////////
struct sfRenderWindow
{
sf::RenderWindow This;
sfInput Input;
sfView DefaultView;
sfView CurrentView;
};
#endif // SFML_RENDERWINDOWSTRUCT_H

View file

@ -0,0 +1,157 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Shader.h>
#include <SFML/Graphics/ShaderStruct.h>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new shader from a file
////////////////////////////////////////////////////////////
sfShader* sfShader_CreateFromFile(const char* filename)
{
sfShader* shader = new sfShader;
if (!shader->This.LoadFromFile(filename))
{
delete shader;
shader = NULL;
}
return shader;
}
////////////////////////////////////////////////////////////
/// Create a new shader from an effect source code
////////////////////////////////////////////////////////////
sfShader* sfShader_CreateFromMemory(const char* effect)
{
sfShader* shader = new sfShader;
if (!shader->This.LoadFromMemory(effect))
{
delete shader;
shader = NULL;
}
return shader;
}
////////////////////////////////////////////////////////////
/// Copy an existing clock
////////////////////////////////////////////////////////////
sfShader* sfShader_Copy(sfShader* shader)
{
CSFML_CHECK_RETURN(shader, NULL);
return new sfShader(*shader);
}
////////////////////////////////////////////////////////////
/// Destroy an existing shader
////////////////////////////////////////////////////////////
void sfShader_Destroy(sfShader* shader)
{
delete shader;
}
////////////////////////////////////////////////////////////
/// Change a parameter of a shader (1 float)
////////////////////////////////////////////////////////////
void sfShader_SetParameter1(sfShader* shader, const char* name, float x)
{
CSFML_CALL(shader, SetParameter(name, x))
}
////////////////////////////////////////////////////////////
/// Change a parameter of a shader (2 floats)
////////////////////////////////////////////////////////////
void sfShader_SetParameter2(sfShader* shader, const char* name, float x, float y)
{
CSFML_CALL(shader, SetParameter(name, x, y))
}
////////////////////////////////////////////////////////////
/// Change a parameter of a shader (3 floats)
////////////////////////////////////////////////////////////
void sfShader_SetParameter3(sfShader* shader, const char* name, float x, float y, float z)
{
CSFML_CALL(shader, SetParameter(name, x, y, z))
}
////////////////////////////////////////////////////////////
/// Change a parameter of a shader (4 floats)
////////////////////////////////////////////////////////////
void sfShader_SetParameter4(sfShader* shader, const char* name, float x, float y, float z, float w)
{
CSFML_CALL(shader, SetParameter(name, x, y, z, w))
}
////////////////////////////////////////////////////////////
/// Set a texture parameter in a shader
////////////////////////////////////////////////////////////
void sfShader_SetTexture(sfShader* shader, const char* name, const sfImage* texture)
{
CSFML_CALL(shader, SetTexture(name, texture && texture->This ? *texture->This : sf::Shader::CurrentTexture))
}
////////////////////////////////////////////////////////////
/// Bind a shader for rendering
////////////////////////////////////////////////////////////
void sfShader_Bind(const sfShader* shader)
{
CSFML_CALL(shader, Bind())
}
////////////////////////////////////////////////////////////
/// Unbind a shader
////////////////////////////////////////////////////////////
void sfShader_Unbind(const sfShader* shader)
{
CSFML_CALL(shader, Unbind())
}
////////////////////////////////////////////////////////////
/// Tell whether or not the system supports shaders
////////////////////////////////////////////////////////////
sfBool sfShader_IsAvailable(void)
{
return sf::Shader::IsAvailable() ? sfTrue : sfFalse;
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SHADERSTRUCT_H
#define SFML_SHADERSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Shader.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfShader
////////////////////////////////////////////////////////////
struct sfShader
{
sf::Shader This;
};
#endif // SFML_SHADERSTRUCT_H

View file

@ -0,0 +1,469 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Shape.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new shape
////////////////////////////////////////////////////////////
sfShape* sfShape_Create(void)
{
return new sfShape;
}
////////////////////////////////////////////////////////////
/// Create a new shape made of a single line
////////////////////////////////////////////////////////////
sfShape* sfShape_CreateLine(float p1x, float p1y, float p2x, float p2y, float thickness, sfColor color, float outline, sfColor outlineColor)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a);
sfShape* shape = new sfShape;
shape->This = sf::Shape::Line(p1x, p1y, p2x, p2y, thickness, SFMLColor, outline, SFMLOutlineColor);
return shape;
}
////////////////////////////////////////////////////////////
/// Create a new shape made of a single rectangle
////////////////////////////////////////////////////////////
sfShape* sfShape_CreateRectangle(float left, float top, float width, float height, sfColor color, float outline, sfColor outlineColor)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a);
sfShape* shape = new sfShape;
shape->This = sf::Shape::Rectangle(left, top, width, height, SFMLColor, outline, SFMLOutlineColor);
return shape;
}
////////////////////////////////////////////////////////////
/// Create a new shape made of a single circle
////////////////////////////////////////////////////////////
sfShape* sfShape_CreateCircle(float x, float y, float radius, sfColor color, float outline, sfColor outlineColor)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a);
sfShape* shape = new sfShape;
shape->This = sf::Shape::Circle(x, y, radius, SFMLColor, outline, SFMLOutlineColor);
return shape;
}
////////////////////////////////////////////////////////////
/// Copy an existing shape
////////////////////////////////////////////////////////////
sfShape* sfShape_Copy(sfShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
return new sfShape(*shape);
}
////////////////////////////////////////////////////////////
/// Destroy an existing shape
////////////////////////////////////////////////////////////
void sfShape_Destroy(sfShape* shape)
{
delete shape;
}
////////////////////////////////////////////////////////////
/// Set the X position of a shape
////////////////////////////////////////////////////////////
void sfShape_SetX(sfShape* shape, float x)
{
CSFML_CALL(shape, SetX(x))
}
////////////////////////////////////////////////////////////
/// Set the Y position of a shape
////////////////////////////////////////////////////////////
void sfShape_SetY(sfShape* shape, float y)
{
CSFML_CALL(shape, SetY(y))
}
////////////////////////////////////////////////////////////
/// Set the position of a shape
////////////////////////////////////////////////////////////
void sfShape_SetPosition(sfShape* shape, float x, float y)
{
CSFML_CALL(shape, SetPosition(sf::Vector2f(x, y)))
}
////////////////////////////////////////////////////////////
/// Set the horizontal scale of a shape
////////////////////////////////////////////////////////////
void sfShape_SetScaleX(sfShape* shape, float scale)
{
CSFML_CALL(shape, SetScaleX(scale))
}
////////////////////////////////////////////////////////////
/// Set the vertical scale of a shape
////////////////////////////////////////////////////////////
void sfShape_SetScaleY(sfShape* shape, float scale)
{
CSFML_CALL(shape, SetScaleY(scale))
}
////////////////////////////////////////////////////////////
/// Set the scale of a shape
////////////////////////////////////////////////////////////
void sfShape_SetScale(sfShape* shape, float scaleX, float scaleY)
{
CSFML_CALL(shape, SetScale(sf::Vector2f(scaleX, scaleY)))
}
////////////////////////////////////////////////////////////
/// Set the orientation of a shape
////////////////////////////////////////////////////////////
void sfShape_SetRotation(sfShape* shape, float rotation)
{
CSFML_CALL(shape, SetRotation(rotation))
}
////////////////////////////////////////////////////////////
/// Set the local origin of a shape, in coordinates
/// relative to its left-top corner
////////////////////////////////////////////////////////////
void sfShape_SetOrigin(sfShape* shape, float x, float y)
{
CSFML_CALL(shape, SetOrigin(sf::Vector2f(x, y)))
}
////////////////////////////////////////////////////////////
/// Set the color of a shape
////////////////////////////////////////////////////////////
void sfShape_SetColor(sfShape* shape, sfColor color)
{
CSFML_CALL(shape, SetColor(sf::Color(color.r, color.g, color.b, color.a)))
}
////////////////////////////////////////////////////////////
/// Set the blending mode for a shape
////////////////////////////////////////////////////////////
void sfShape_SetBlendMode(sfShape* shape, sfBlendMode mode)
{
CSFML_CALL(shape, SetBlendMode(static_cast<sf::Blend::Mode>(mode)))
}
////////////////////////////////////////////////////////////
/// Get the X position of a shape
////////////////////////////////////////////////////////////
float sfShape_GetX(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetPosition().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the Y position of a shape
////////////////////////////////////////////////////////////
float sfShape_GetY(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetPosition().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the horizontal scale of a shape
////////////////////////////////////////////////////////////
float sfShape_GetScaleX(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetScale().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the vertical scale of a shape
////////////////////////////////////////////////////////////
float sfShape_GetScaleY(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetScale().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the orientation of a shape
////////////////////////////////////////////////////////////
float sfShape_GetRotation(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetRotation(), 0.f)
}
////////////////////////////////////////////////////////////
/// Get the X position of the origin a shape
////////////////////////////////////////////////////////////
float sfShape_GetOriginX(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetOrigin().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the Y position of the origin a shape
////////////////////////////////////////////////////////////
float sfShape_GetOriginY(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetOrigin().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the color of a shape
////////////////////////////////////////////////////////////
sfColor sfShape_GetColor(const sfShape* shape)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color)
sf::Color SFMLColor = shape->This.GetColor();
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
////////////////////////////////////////////////////////////
/// Get the current blending mode of a shape
////////////////////////////////////////////////////////////
sfBlendMode sfShape_GetBlendMode(const sfShape* shape)
{
CSFML_CHECK_RETURN(shape, sfBlendNone)
return static_cast<sfBlendMode>(shape->This.GetBlendMode());
}
////////////////////////////////////////////////////////////
/// Move a shape
////////////////////////////////////////////////////////////
void sfShape_Move(sfShape* shape, float offsetX, float offsetY)
{
CSFML_CALL(shape, Move(sf::Vector2f(offsetX, offsetY)))
}
////////////////////////////////////////////////////////////
/// Scale a shape
////////////////////////////////////////////////////////////
void sfShape_Scale(sfShape* shape, float factorX, float factorY)
{
CSFML_CALL(shape, Scale(sf::Vector2f(factorX, factorY)))
}
////////////////////////////////////////////////////////////
/// Rotate a shape
////////////////////////////////////////////////////////////
void sfShape_Rotate(sfShape* shape, float angle)
{
CSFML_CALL(shape, Rotate(angle))
}
////////////////////////////////////////////////////////////
/// Transform a point from global coordinates into the shape's local coordinates
/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
////////////////////////////////////////////////////////////
void sfShape_TransformToLocal(const sfShape* shape, float pointX, float pointY, float* x, float* y)
{
CSFML_CHECK(shape)
sf::Vector2f point = shape->This.TransformToLocal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x;
if (y) *y = point.y;
}
////////////////////////////////////////////////////////////
/// Transform a point from the shape's local coordinates into global coordinates
/// (ie it applies the object's origin, translation, rotation and scale to the point)
////////////////////////////////////////////////////////////
void sfShape_TransformToGlobal(const sfShape* shape, float pointX, float pointY, float* x, float* y)
{
CSFML_CHECK(shape)
sf::Vector2f point = shape->This.TransformToGlobal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x;
if (y) *y = point.y;
}
////////////////////////////////////////////////////////////
/// Add a point to a shape
////////////////////////////////////////////////////////////
void sfShape_AddPoint(sfShape* shape, float x, float y, sfColor color, sfColor outlineColor)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a);
CSFML_CALL(shape, AddPoint(x, y, SFMLColor, SFMLOutlineColor))
}
////////////////////////////////////////////////////////////
/// Enable or disable filling a shape.
/// Fill is enabled by default
////////////////////////////////////////////////////////////
void sfShape_EnableFill(sfShape* shape, sfBool enable)
{
CSFML_CALL(shape, EnableFill(enable == sfTrue))
}
////////////////////////////////////////////////////////////
/// Enable or disable drawing a shape outline.
/// Outline is enabled by default
////////////////////////////////////////////////////////////
void sfShape_EnableOutline(sfShape* shape, sfBool enable)
{
CSFML_CALL(shape, EnableOutline(enable == sfTrue))
}
////////////////////////////////////////////////////////////
/// Change the width of a shape outline
////////////////////////////////////////////////////////////
void sfShape_SetOutlineWidth(sfShape* shape, float width)
{
CSFML_CALL(shape, SetOutlineWidth(width))
}
////////////////////////////////////////////////////////////
/// Get the width of a shape outline
////////////////////////////////////////////////////////////
float sfShape_GetOutlineWidth(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetOutlineWidth(), 0.f)
}
////////////////////////////////////////////////////////////
/// Get the number of points composing a shape
////////////////////////////////////////////////////////////
unsigned int sfShape_GetPointsCount(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetPointsCount(), 0)
}
////////////////////////////////////////////////////////////
/// Get a point of a shape
////////////////////////////////////////////////////////////
void sfShape_GetPointPosition(const sfShape* shape, unsigned int index, float* x, float* y)
{
CSFML_CHECK(shape)
sf::Vector2f point = shape->This.GetPointPosition(index);
if (x) *x = point.x;
if (y) *y = point.y;
}
////////////////////////////////////////////////////////////
/// Get a the color of a shape's point
////////////////////////////////////////////////////////////
sfColor sfShape_GetPointColor(const sfShape* shape, unsigned int index)
{
sfColor color = {255, 255, 255, 255};
CSFML_CHECK_RETURN(shape, color)
const sf::Color& SFMLColor = shape->This.GetPointColor(index);
color.r = SFMLColor.r;
color.g = SFMLColor.g;
color.b = SFMLColor.b;
color.a = SFMLColor.a;
return color;
}
////////////////////////////////////////////////////////////
/// Get a the outline color of a shape's point
////////////////////////////////////////////////////////////
sfColor sfShape_GetPointOutlineColor(const sfShape* shape, unsigned int index)
{
sfColor color = {255, 255, 255, 255};
CSFML_CHECK_RETURN(shape, color)
const sf::Color& SFMLColor = shape->This.GetPointOutlineColor(index);
color.r = SFMLColor.r;
color.g = SFMLColor.g;
color.b = SFMLColor.b;
color.a = SFMLColor.a;
return color;
}
////////////////////////////////////////////////////////////
/// Set a the position of a shape's point
////////////////////////////////////////////////////////////
void sfShape_SetPointPosition(sfShape* shape, unsigned int index, float x, float y)
{
CSFML_CALL(shape, SetPointPosition(index, x, y));
}
////////////////////////////////////////////////////////////
/// Set a the color of a shape's point
////////////////////////////////////////////////////////////
void sfShape_SetPointColor(sfShape* shape, unsigned int index, sfColor color)
{
CSFML_CALL(shape, SetPointColor(index, sf::Color(color.r, color.g, color.b, color.a)));
}
////////////////////////////////////////////////////////////
/// Set a the outline color of a shape's point
////////////////////////////////////////////////////////////
void sfShape_SetPointOutlineColor(sfShape* shape, unsigned int index, sfColor color)
{
CSFML_CALL(shape, SetPointOutlineColor(index, sf::Color(color.r, color.g, color.b, color.a)));
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SHAPESTRUCT_H
#define SFML_SHAPESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Shape.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfShape
////////////////////////////////////////////////////////////
struct sfShape
{
sf::Shape This;
};
#endif // SFML_SHAPESTRUCT_H

View file

@ -0,0 +1,405 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Sprite.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Image.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new sprite
////////////////////////////////////////////////////////////
sfSprite* sfSprite_Create(void)
{
sfSprite* sprite = new sfSprite;
sprite->Image = NULL;
sprite->SubRect.Left = sprite->This.GetSubRect().Left;
sprite->SubRect.Top = sprite->This.GetSubRect().Top;
sprite->SubRect.Width = sprite->This.GetSubRect().Width;
sprite->SubRect.Height = sprite->This.GetSubRect().Height;
return sprite;
}
////////////////////////////////////////////////////////////
/// Copy an existing sprite
////////////////////////////////////////////////////////////
sfSprite* sfSprite_Copy(sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, NULL);
return new sfSprite(*sprite);
}
////////////////////////////////////////////////////////////
/// Destroy an existing sprite
////////////////////////////////////////////////////////////
void sfSprite_Destroy(sfSprite* sprite)
{
delete sprite;
}
////////////////////////////////////////////////////////////
/// Set the X position of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetX(sfSprite* sprite, float x)
{
CSFML_CALL(sprite, SetX(x))
}
////////////////////////////////////////////////////////////
/// Set the Y position of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetY(sfSprite* sprite, float y)
{
CSFML_CALL(sprite, SetY(y))
}
////////////////////////////////////////////////////////////
/// Set the position of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetPosition(sfSprite* sprite, float x, float y)
{
CSFML_CALL(sprite, SetPosition(sf::Vector2f(x, y)))
}
////////////////////////////////////////////////////////////
/// Set the horizontal scale of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetScaleX(sfSprite* sprite, float scale)
{
CSFML_CALL(sprite, SetScaleX(scale))
}
////////////////////////////////////////////////////////////
/// Set the vertical scale of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetScaleY(sfSprite* sprite, float scale)
{
CSFML_CALL(sprite, SetScaleY(scale))
}
////////////////////////////////////////////////////////////
/// Set the scale of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetScale(sfSprite* sprite, float scaleX, float scaleY)
{
CSFML_CALL(sprite, SetScale(sf::Vector2f(scaleX, scaleY)))
}
////////////////////////////////////////////////////////////
/// Set the orientation of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetRotation(sfSprite* sprite, float rotation)
{
CSFML_CALL(sprite, SetRotation(rotation))
}
////////////////////////////////////////////////////////////
/// Set the local origin of a sprite, in coordinates
/// relative to its left-top corner
////////////////////////////////////////////////////////////
void sfSprite_SetOrigin(sfSprite* sprite, float x, float y)
{
CSFML_CALL(sprite, SetOrigin(sf::Vector2f(x, y)))
}
////////////////////////////////////////////////////////////
/// Set the color of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetColor(sfSprite* sprite, sfColor color)
{
CSFML_CALL(sprite, SetColor(sf::Color(color.r, color.g, color.b, color.a)))
}
////////////////////////////////////////////////////////////
/// Set the blending mode for a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetBlendMode(sfSprite* sprite, sfBlendMode mode)
{
CSFML_CALL(sprite, SetBlendMode(static_cast<sf::Blend::Mode>(mode)))
}
////////////////////////////////////////////////////////////
/// Get the X position of a sprite
////////////////////////////////////////////////////////////
float sfSprite_GetX(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetPosition().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the Y position of a sprite
////////////////////////////////////////////////////////////
float sfSprite_GetY(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetPosition().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the horizontal scale of a sprite
////////////////////////////////////////////////////////////
float sfSprite_GetScaleX(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetScale().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the vertical scale of a sprite
////////////////////////////////////////////////////////////
float sfSprite_GetScaleY(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetScale().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the orientation of a sprite
////////////////////////////////////////////////////////////
float sfSprite_GetRotation(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetRotation(), 0.f)
}
////////////////////////////////////////////////////////////
/// Get the X position of the origin a sprite
////////////////////////////////////////////////////////////
float sfSprite_GetOriginX(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetOrigin().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the Y position of the origin a sprite
////////////////////////////////////////////////////////////
float sfSprite_GetOriginY(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetOrigin().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the color of a sprite
////////////////////////////////////////////////////////////
sfColor sfSprite_GetColor(const sfSprite* sprite)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, color)
sf::Color SFMLColor = sprite->This.GetColor();
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
////////////////////////////////////////////////////////////
/// Get the current blending mode of a sprite
////////////////////////////////////////////////////////////
sfBlendMode sfSprite_GetBlendMode(const sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, sfBlendNone)
return static_cast<sfBlendMode>(sprite->This.GetBlendMode());
}
////////////////////////////////////////////////////////////
/// Move a sprite
////////////////////////////////////////////////////////////
void sfSprite_Move(sfSprite* sprite, float offsetX, float offsetY)
{
CSFML_CALL(sprite, Move(sf::Vector2f(offsetX, offsetY)))
}
////////////////////////////////////////////////////////////
/// Scale a sprite
////////////////////////////////////////////////////////////
void sfSprite_Scale(sfSprite* sprite, float factorX, float factorY)
{
CSFML_CALL(sprite, Scale(sf::Vector2f(factorX, factorY)))
}
////////////////////////////////////////////////////////////
/// Rotate a sprite
////////////////////////////////////////////////////////////
void sfSprite_Rotate(sfSprite* sprite, float angle)
{
CSFML_CALL(sprite, Rotate(angle))
}
////////////////////////////////////////////////////////////
/// Transform a point from global coordinates into the sprite's local coordinates
/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
////////////////////////////////////////////////////////////
void sfSprite_TransformToLocal(const sfSprite* sprite, float pointX, float pointY, float* x, float* y)
{
CSFML_CHECK(sprite)
sf::Vector2f point = sprite->This.TransformToLocal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x;
if (y) *y = point.y;
}
////////////////////////////////////////////////////////////
/// Transform a point from the sprite's local coordinates into global coordinates
/// (ie it applies the object's origin, translation, rotation and scale to the point)
////////////////////////////////////////////////////////////
void sfSprite_TransformToGlobal(const sfSprite* sprite, float pointX, float pointY, float* x, float* y)
{
CSFML_CHECK(sprite)
sf::Vector2f point = sprite->This.TransformToGlobal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x;
if (y) *y = point.y;
}
////////////////////////////////////////////////////////////
/// Change the image of a sprite
////////////////////////////////////////////////////////////
void sfSprite_SetImage(sfSprite* sprite, const sfImage* image, sfBool adjustToNewSize)
{
if (image)
{
CSFML_CALL(sprite, SetImage(*image->This, adjustToNewSize == sfTrue))
sprite->Image = image;
}
}
////////////////////////////////////////////////////////////
/// Set the sub-rectangle of a sprite inside the source image
////////////////////////////////////////////////////////////
void sfSprite_SetSubRect(sfSprite* sprite, sfIntRect rectangle)
{
CSFML_CALL(sprite, SetSubRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)))
sprite->SubRect = rectangle;
}
////////////////////////////////////////////////////////////
/// Resize a sprite (by changing its scale factors)
////////////////////////////////////////////////////////////
void sfSprite_Resize(sfSprite* sprite, float width, float height)
{
CSFML_CALL(sprite, Resize(sf::Vector2f(width, height)))
}
////////////////////////////////////////////////////////////
/// Flip a sprite horizontally
////////////////////////////////////////////////////////////
void sfSprite_FlipX(sfSprite* sprite, sfBool flipped)
{
CSFML_CALL(sprite, FlipX(flipped == sfTrue))
}
////////////////////////////////////////////////////////////
/// Flip a sprite vertically
////////////////////////////////////////////////////////////
void sfSprite_FlipY(sfSprite* sprite, sfBool flipped)
{
CSFML_CALL(sprite, FlipY(flipped == sfTrue))
}
////////////////////////////////////////////////////////////
/// Get the source image of a sprite
////////////////////////////////////////////////////////////
const sfImage* sfSprite_GetImage(const sfSprite* sprite)
{
CSFML_CHECK_RETURN(sprite, NULL)
return sprite->Image;
}
////////////////////////////////////////////////////////////
/// Get the sub-rectangle of a sprite inside the source image
////////////////////////////////////////////////////////////
sfIntRect sfSprite_GetSubRect(const sfSprite* sprite)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, rect)
return sprite->SubRect;
}
////////////////////////////////////////////////////////////
/// Get a sprite width
////////////////////////////////////////////////////////////
float sfSprite_GetWidth(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetSize().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get a sprite height
////////////////////////////////////////////////////////////
float sfSprite_GetHeight(const sfSprite* sprite)
{
CSFML_CALL_RETURN(sprite, GetSize().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the color of a given pixel in a sprite
////////////////////////////////////////////////////////////
sfColor sfSprite_GetPixel(const sfSprite* sprite, unsigned int x, unsigned int y)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, color)
sf::Color SFMLColor = sprite->This.GetPixel(x, y);
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}

View file

@ -0,0 +1,47 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SPRITESTRUCT_H
#define SFML_SPRITESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Sprite.hpp>
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/Rect.h>
////////////////////////////////////////////////////////////
// Internal structure of sfMusic
////////////////////////////////////////////////////////////
struct sfSprite
{
sf::Sprite This;
const sfImage* Image;
sfIntRect SubRect;
};
#endif // SFML_SPRITESTRUCT_H

View file

@ -0,0 +1,432 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Text.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Graphics/Font.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new text
////////////////////////////////////////////////////////////
sfText* sfText_Create(void)
{
sfText* text = new sfText;
text->Font = sfFont_GetDefaultFont();
return text;
}
////////////////////////////////////////////////////////////
/// Copy an existing text
////////////////////////////////////////////////////////////
sfText* sfText_Copy(sfText* text)
{
CSFML_CHECK_RETURN(text, NULL);
return new sfText(*text);
}
////////////////////////////////////////////////////////////
/// Destroy an existing text
////////////////////////////////////////////////////////////
void sfText_Destroy(sfText* text)
{
delete text;
}
////////////////////////////////////////////////////////////
/// Set the X position of a text
////////////////////////////////////////////////////////////
void sfText_SetX(sfText* text, float x)
{
CSFML_CALL(text, SetX(x))
}
////////////////////////////////////////////////////////////
/// Set the Y position of a text
////////////////////////////////////////////////////////////
void sfText_SetY(sfText* text, float y)
{
CSFML_CALL(text, SetY(y))
}
////////////////////////////////////////////////////////////
/// Set the position of a text
////////////////////////////////////////////////////////////
void sfText_SetPosition(sfText* text, float x, float y)
{
CSFML_CALL(text, SetPosition(sf::Vector2f(x, y)))
}
////////////////////////////////////////////////////////////
/// Set the horizontal scale of a text
////////////////////////////////////////////////////////////
void sfText_SetScaleX(sfText* text, float scale)
{
CSFML_CALL(text, SetScaleX(scale))
}
////////////////////////////////////////////////////////////
/// Set the vertical scale of a text
////////////////////////////////////////////////////////////
void sfText_SetScaleY(sfText* text, float scale)
{
CSFML_CALL(text, SetScaleY(scale))
}
////////////////////////////////////////////////////////////
/// Set the scale of a text
////////////////////////////////////////////////////////////
void sfText_SetScale(sfText* text, float scaleX, float scaleY)
{
CSFML_CALL(text, SetScale(sf::Vector2f(scaleX, scaleY)))
}
////////////////////////////////////////////////////////////
/// Set the orientation of a text
////////////////////////////////////////////////////////////
void sfText_SetRotation(sfText* text, float rotation)
{
CSFML_CALL(text, SetRotation(rotation))
}
////////////////////////////////////////////////////////////
/// Set the local origin of a text, in coordinates
/// relative to its left-top corner
////////////////////////////////////////////////////////////
void sfText_SetOrigin(sfText* text, float x, float y)
{
CSFML_CALL(text, SetOrigin(sf::Vector2f(x, y)))
}
////////////////////////////////////////////////////////////
/// Set the color of a text
////////////////////////////////////////////////////////////
void sfText_SetColor(sfText* text, sfColor color)
{
CSFML_CALL(text, SetColor(sf::Color(color.r, color.g, color.b, color.a)))
}
////////////////////////////////////////////////////////////
/// Set the blending mode for a text
////////////////////////////////////////////////////////////
void sfText_SetBlendMode(sfText* text, sfBlendMode mode)
{
CSFML_CALL(text, SetBlendMode(static_cast<sf::Blend::Mode>(mode)))
}
////////////////////////////////////////////////////////////
/// Get the X position of a text
////////////////////////////////////////////////////////////
float sfText_GetX(const sfText* text)
{
CSFML_CALL_RETURN(text, GetPosition().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the Y position of a text
////////////////////////////////////////////////////////////
float sfText_GetY(const sfText* text)
{
CSFML_CALL_RETURN(text, GetPosition().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the horizontal scale of a text
////////////////////////////////////////////////////////////
float sfText_GetScaleX(const sfText* text)
{
CSFML_CALL_RETURN(text, GetScale().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the vertical scale of a text
////////////////////////////////////////////////////////////
float sfText_GetScaleY(const sfText* text)
{
CSFML_CALL_RETURN(text, GetScale().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the orientation of a text
////////////////////////////////////////////////////////////
float sfText_GetRotation(const sfText* text)
{
CSFML_CALL_RETURN(text, GetRotation(), 0.f)
}
////////////////////////////////////////////////////////////
/// Get the X position of the origin a text
////////////////////////////////////////////////////////////
float sfText_GetOriginX(const sfText* text)
{
CSFML_CALL_RETURN(text, GetOrigin().x, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the top Y of the origin of a text
////////////////////////////////////////////////////////////
float sfText_GetOriginY(const sfText* text)
{
CSFML_CALL_RETURN(text, GetOrigin().y, 0.f)
}
////////////////////////////////////////////////////////////
/// Get the color of a text
////////////////////////////////////////////////////////////
sfColor sfText_GetColor(const sfText* text)
{
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(text, color)
sf::Color SFMLColor = text->This.GetColor();
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
}
////////////////////////////////////////////////////////////
/// Get the current blending mode of a text
////////////////////////////////////////////////////////////
sfBlendMode sfText_GetBlendMode(const sfText* text)
{
CSFML_CHECK_RETURN(text, sfBlendNone)
return static_cast<sfBlendMode>(text->This.GetBlendMode());
}
////////////////////////////////////////////////////////////
/// Move a text
////////////////////////////////////////////////////////////
void sfText_Move(sfText* text, float offsetX, float offsetY)
{
CSFML_CALL(text, Move(sf::Vector2f(offsetX, offsetY)))
}
////////////////////////////////////////////////////////////
/// Scale a text
////////////////////////////////////////////////////////////
void sfText_Scale(sfText* text, float factorX, float factorY)
{
CSFML_CALL(text, Scale(sf::Vector2f(factorX, factorY)))
}
////////////////////////////////////////////////////////////
/// Rotate a text
////////////////////////////////////////////////////////////
void sfText_Rotate(sfText* text, float angle)
{
CSFML_CALL(text, Rotate(angle))
}
////////////////////////////////////////////////////////////
/// Transform a point from global coordinates into the text's local coordinates
/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point)
////////////////////////////////////////////////////////////
void sfText_TransformToLocal(const sfText* text, float pointX, float pointY, float* x, float* y)
{
CSFML_CHECK(text)
sf::Vector2f point = text->This.TransformToLocal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x;
if (y) *y = point.y;
}
////////////////////////////////////////////////////////////
/// Transform a point from the text's local coordinates into global coordinates
/// (ie it applies the object's origin, translation, rotation and scale to the point)
////////////////////////////////////////////////////////////
void sfText_TransformToGlobal(const sfText* text, float pointX, float pointY, float* x, float* y)
{
CSFML_CHECK(text)
sf::Vector2f point = text->This.TransformToGlobal(sf::Vector2f(pointX, pointY));
if (x) *x = point.x;
if (y) *y = point.y;
}
////////////////////////////////////////////////////////////
/// Set the string of a text (from a multibyte string)
////////////////////////////////////////////////////////////
void sfText_SetString(sfText* text, const char* string)
{
CSFML_CALL(text, SetString(string))
}
////////////////////////////////////////////////////////////
/// Set the string of a text (from a unicode string)
////////////////////////////////////////////////////////////
void sfText_SetUnicodeString(sfText* text, const sfUint32* string)
{
sf::String UTF32Text = string;
CSFML_CALL(text, SetString(UTF32Text))
}
////////////////////////////////////////////////////////////
/// Set the font of a string
////////////////////////////////////////////////////////////
void sfText_SetFont(sfText* text, const sfFont* font)
{
CSFML_CHECK(font);
CSFML_CALL(text, SetFont(font->This))
text->Font = font;
}
////////////////////////////////////////////////////////////
/// Set the size of a string
////////////////////////////////////////////////////////////
void sfText_SetCharacterSize(sfText* text, unsigned int size)
{
CSFML_CALL(text, SetCharacterSize(size))
}
////////////////////////////////////////////////////////////
/// Set the style of a string
////////////////////////////////////////////////////////////
void sfText_SetStyle(sfText* text, unsigned long style)
{
CSFML_CALL(text, SetStyle(style))
}
////////////////////////////////////////////////////////////
/// Get the string of a text (returns a unicode string)
////////////////////////////////////////////////////////////
const sfUint32* sfText_GetUnicodeString(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL)
return text->This.GetString().GetData();
}
////////////////////////////////////////////////////////////
/// Get the string of a text (returns an ANSI string)
////////////////////////////////////////////////////////////
const char* sfText_GetString(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL)
text->String = text->This.GetString().ToAnsiString();
return text->String.c_str();
}
////////////////////////////////////////////////////////////
/// Get the font used by a text
////////////////////////////////////////////////////////////
const sfFont* sfText_GetFont(const sfText* text)
{
CSFML_CHECK_RETURN(text, NULL)
return text->Font;
}
////////////////////////////////////////////////////////////
/// Get the size of the characters of a text
////////////////////////////////////////////////////////////
unsigned int sfText_GetCharacterSize(const sfText* text)
{
CSFML_CALL_RETURN(text, GetCharacterSize(), 0)
}
////////////////////////////////////////////////////////////
/// Get the style of a text
////////////////////////////////////////////////////////////
unsigned long sfText_GetStyle(const sfText* text)
{
CSFML_CALL_RETURN(text, GetStyle(), 0)
}
////////////////////////////////////////////////////////////
/// Return the visual position of the Index-th character of the text,
/// in coordinates relative to the text
/// (note : translation, origin, rotation and scale are not applied)
////////////////////////////////////////////////////////////
void sfText_GetCharacterPos(const sfText* text, size_t index, float* x, float* y)
{
CSFML_CHECK(text);
sf::Vector2f pos = text->This.GetCharacterPos(index);
if (x) *x = pos.x;
if (y) *y = pos.y;
}
////////////////////////////////////////////////////////////
/// Get the bounding rectangle of a text on screen
////////////////////////////////////////////////////////////
sfFloatRect sfText_GetRect(const sfText* text)
{
sfFloatRect rect = {0.f, 0.f, 0.f, 0.f};
CSFML_CHECK_RETURN(text, rect)
sf::FloatRect SFMLRect = text->This.GetRect();
text->Rect.Left = SFMLRect.Left;
text->Rect.Top = SFMLRect.Top;
text->Rect.Width = SFMLRect.Width;
text->Rect.Height = SFMLRect.Height;
return text->Rect;
}

View file

@ -0,0 +1,49 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TEXTSTRUCT_H
#define SFML_TEXTSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Text.hpp>
#include <SFML/Graphics/FontStruct.h>
#include <SFML/Graphics/Rect.h>
#include <string>
////////////////////////////////////////////////////////////
// Internal structure of sfText
////////////////////////////////////////////////////////////
struct sfText
{
sf::Text This;
const sfFont* Font;
mutable std::string String;
mutable sfFloatRect Rect;
};
#endif // SFML_TEXTSTRUCT_H

View file

@ -0,0 +1,215 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/View.h>
#include <SFML/Graphics/ViewStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a default view (1000x1000)
////////////////////////////////////////////////////////////
sfView* sfView_Create(void)
{
return new sfView;
}
////////////////////////////////////////////////////////////
/// Construct a view from a rectangle
////////////////////////////////////////////////////////////
sfView* sfView_CreateFromRect(sfFloatRect rectangle)
{
sfView* view = new sfView;
sfView_Reset(view, rectangle);
return view;
}
////////////////////////////////////////////////////////////
/// Copy an existing view
////////////////////////////////////////////////////////////
sfView* sfView_Copy(sfView* view)
{
CSFML_CHECK_RETURN(view, NULL);
return new sfView(*view);
}
////////////////////////////////////////////////////////////
/// Destroy an existing view
////////////////////////////////////////////////////////////
void sfView_Destroy(sfView* view)
{
delete view;
}
////////////////////////////////////////////////////////////
/// Change the center of a view
////////////////////////////////////////////////////////////
void sfView_SetCenter(sfView* view, float x, float y)
{
CSFML_CALL(view, SetCenter(x, y));
}
////////////////////////////////////////////////////////////
/// Change the size of a view
////////////////////////////////////////////////////////////
void sfView_SetSize(sfView* view, float width, float height)
{
CSFML_CALL(view, SetSize(width, height));
}
////////////////////////////////////////////////////////////
/// Set the angle of rotation of a view
////////////////////////////////////////////////////////////
void sfView_SetRotation(sfView* view, float angle)
{
CSFML_CALL(view, SetRotation(angle));
}
////////////////////////////////////////////////////////////
/// Set the target viewport of a view
////////////////////////////////////////////////////////////
void sfView_SetViewport(sfView* view, sfFloatRect viewport)
{
CSFML_CALL(view, SetViewport(sf::FloatRect(viewport.Left, viewport.Top, viewport.Width, viewport.Height)));
}
////////////////////////////////////////////////////////////
/// Reset a view to the given rectangle.
/// Note: this function resets the rotation angle to 0.
////////////////////////////////////////////////////////////
void sfView_Reset(sfView* view, sfFloatRect rectangle)
{
CSFML_CALL(view, Reset(sf::FloatRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)));
}
////////////////////////////////////////////////////////////
/// Get the X coordinate of the center of a view
////////////////////////////////////////////////////////////
float sfView_GetCenterX(const sfView* view)
{
CSFML_CHECK_RETURN(view, 0.f);
return view->This.GetCenter().x;
}
////////////////////////////////////////////////////////////
/// Get the Y coordinate of the center of a view
////////////////////////////////////////////////////////////
float sfView_GetCenterY(const sfView* view)
{
CSFML_CHECK_RETURN(view, 0.f);
return view->This.GetCenter().y;
}
////////////////////////////////////////////////////////////
/// Get the width of the view
////////////////////////////////////////////////////////////
float sfView_GetWidth(const sfView* view)
{
CSFML_CHECK_RETURN(view, 0.f);
return view->This.GetSize().x;
}
////////////////////////////////////////////////////////////
/// Get the height of the view
////////////////////////////////////////////////////////////
float sfView_GetHeight(const sfView* view)
{
CSFML_CHECK_RETURN(view, 0.f);
return view->This.GetSize().y;
}
////////////////////////////////////////////////////////////
/// Get the current rotation of a view
////////////////////////////////////////////////////////////
float sfView_GetRotation(const sfView* view)
{
CSFML_CALL_RETURN(view, GetRotation(), 0.f);
}
////////////////////////////////////////////////////////////
/// Get the target viewport of a view
////////////////////////////////////////////////////////////
sfFloatRect sfView_GetViewport(const sfView* view)
{
sfFloatRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(view, rect);
sf::FloatRect SFMLRect = view->This.GetViewport();
rect.Left = SFMLRect.Left;
rect.Top = SFMLRect.Top;
rect.Width = SFMLRect.Width;
rect.Height = SFMLRect.Height;
return rect;
}
////////////////////////////////////////////////////////////
/// Move a view
////////////////////////////////////////////////////////////
void sfView_Move(sfView* view, float offsetX, float offsetY)
{
CSFML_CALL(view, Move(offsetX, offsetY));
}
////////////////////////////////////////////////////////////
/// Rotate a view
////////////////////////////////////////////////////////////
void sfView_Rotate(sfView* view, float angle)
{
CSFML_CALL(view, Rotate(angle));
}
////////////////////////////////////////////////////////////
/// Resize a view rectangle to simulate a zoom / unzoom effect
////////////////////////////////////////////////////////////
void sfView_Zoom(sfView* view, float factor)
{
CSFML_CALL(view, Zoom(factor));
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_VIEWSTRUCT_H
#define SFML_VIEWSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/View.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfMusic
////////////////////////////////////////////////////////////
struct sfView
{
sf::View This;
};
#endif // SFML_VIEWSTRUCT_H

View file

@ -0,0 +1,108 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_INTERNAL_H
#define SFML_INTERNAL_H
////////////////////////////////////////////////////////////
// Define macros to check the validity of CSFML objects
// in debug run
////////////////////////////////////////////////////////////
#include <stdio.h>
#ifndef NDEBUG
#define CSFML_CHECK(Object) \
if (Object == NULL) \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return; \
}
#define CSFML_CALL(Object, Function) \
if (Object) \
{ \
(Object->This.Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
} \
#define CSFML_CALL_PTR(Object, Function) \
if (Object) \
{ \
(Object->This->Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
} \
#define CSFML_CHECK_RETURN(Object, Default) \
if (Object == NULL) \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return Default; \
}
#define CSFML_CALL_RETURN(Object, Function, Default) \
if (Object) \
{ \
return (Object->This.Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return Default; \
} \
#define CSFML_CALL_PTR_RETURN(Object, Function, Default) \
if (Object) \
{ \
return (Object->This->Function); \
} \
else \
{ \
fprintf(stderr, "SFML warning : trying to use a null " #Object " object\n"); \
return Default; \
} \
#else
#define CSFML_CHECK(Object)
#define CSFML_CALL(Object, Function) (Object->This.Function);
#define CSFML_CALL_PTR(Object, Function) (Object->This->Function);
#define CSFML_CHECK_RETURN(Object, Default) (void)Default;
#define CSFML_CALL_RETURN(Object, Function, Default) (void)Default; return (Object->This.Function);
#define CSFML_CALL_PTR_RETURN(Object, Function, Default) (void)Default; return (Object->This->Function);
#endif
#endif // SFML_INTERNAL_H

View file

@ -0,0 +1,9 @@
# define the csfml-main target
add_library(csfml-main STATIC ${CMAKE_SOURCE_DIR}/src/SFML/Main/SFML_Main.cpp)
# set the debug suffix
set_target_properties(csfml-main PROPERTIES DEBUG_POSTFIX -d)
# insert the major version number in the output filename
set_target_properties(csfml-main PROPERTIES OUTPUT_NAME "csfml-main")

View file

@ -0,0 +1,44 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Windows specific : defines the WinMain entry function,
// so that developers can use the standard main function
// even in a Win32 Application project, and keep a portable code
////////////////////////////////////////////////////////////
#if defined(_WIN32)
#include <windows.h>
extern int main(int argc, char* argv[]);
int WINAPI WinMain(HINSTANCE, HINSTANCE, LPSTR, INT)
{
return main(__argc, __argv);
}
#endif // _WIN32

View file

@ -0,0 +1,38 @@
set(INCROOT ${CMAKE_SOURCE_DIR}/include/SFML/Network)
set(SRCROOT ${CMAKE_SOURCE_DIR}/src/SFML/Network)
# all source files
set(SRC
${SRCROOT}/Ftp.cpp
${SRCROOT}/FtpStruct.h
${INCROOT}/Ftp.h
${SRCROOT}/Http.cpp
${SRCROOT}/HttpStruct.h
${INCROOT}/Http.h
${SRCROOT}/IpAddress.cpp
${INCROOT}/IpAddress.h
${SRCROOT}/Packet.cpp
${SRCROOT}/PacketStruct.h
${INCROOT}/Packet.h
${SRCROOT}/SocketSelector.cpp
${SRCROOT}/SocketSelectorStruct.h
${INCROOT}/SocketSelector.h
${INCROOT}/SocketStatus.h
${SRCROOT}/TcpListener.cpp
${SRCROOT}/TcpListenerStruct.h
${INCROOT}/TcpListener.h
${SRCROOT}/TcpSocket.cpp
${SRCROOT}/TcpSocketStruct.h
${INCROOT}/TcpSocket.h
${INCROOT}/Types.h
${SRCROOT}/UdpSocket.cpp
${SRCROOT}/UdpSocketStruct.h
${INCROOT}/UdpSocket.h
)
# define the csfml-network target
csfml_add_library(csfml-network
SOURCES ${SRC}
DEPENDS optimized ${SFML_NETWORK_LIBRARY} debug ${SFML_NETWORK_LIBRARY_DEBUG}
optimized ${SFML_SYSTEM_LIBRARY} debug ${SFML_SYSTEM_LIBRARY_DEBUG})

View file

@ -0,0 +1,377 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/Ftp.h>
#include <SFML/Network/FtpStruct.h>
#include <SFML/Network/IpAddress.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp directory response
////////////////////////////////////////////////////////////
void sfFtpListingResponse_Destroy(sfFtpListingResponse* ftpListingResponse)
{
delete ftpListingResponse;
}
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
////////////////////////////////////////////////////////////
sfBool sfFtpListingResponse_IsOk(const sfFtpListingResponse* ftpListingResponse)
{
CSFML_CALL_RETURN(ftpListingResponse, IsOk(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the response status code
////////////////////////////////////////////////////////////
sfFtpStatus sfFtpListingResponse_GetStatus(const sfFtpListingResponse* ftpListingResponse)
{
CSFML_CHECK_RETURN(ftpListingResponse, sfFtpInvalidResponse);
return static_cast<sfFtpStatus>(ftpListingResponse->This.GetStatus());
}
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
////////////////////////////////////////////////////////////
const char* sfFtpListingResponse_GetMessage(const sfFtpListingResponse* ftpListingResponse)
{
CSFML_CHECK_RETURN(ftpListingResponse, NULL);
return ftpListingResponse->This.GetMessage().c_str();
}
////////////////////////////////////////////////////////////
/// Get the number of filenames in the listing
////////////////////////////////////////////////////////////
size_t sfFtpListingResponse_GetCount(const sfFtpListingResponse* ftpListingResponse)
{
CSFML_CHECK_RETURN(ftpListingResponse, 0);
return ftpListingResponse->This.GetFilenames().size();
}
////////////////////////////////////////////////////////////
/// Get the Index-th filename in the directory
////////////////////////////////////////////////////////////
const char* sfFtpListingResponse_GetFilename(const sfFtpListingResponse* ftpListingResponse, size_t index)
{
CSFML_CHECK_RETURN(ftpListingResponse, NULL);
return ftpListingResponse->This.GetFilenames()[index].c_str();
}
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp directory response
////////////////////////////////////////////////////////////
void sfFtpDirectoryResponse_Destroy(sfFtpDirectoryResponse* ftpDirectoryResponse)
{
delete ftpDirectoryResponse;
}
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
////////////////////////////////////////////////////////////
sfBool sfFtpDirectoryResponse_IsOk(const sfFtpDirectoryResponse* ftpDirectoryResponse)
{
CSFML_CALL_RETURN(ftpDirectoryResponse, IsOk(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the response status code
////////////////////////////////////////////////////////////
sfFtpStatus sfFtpDirectoryResponse_GetStatus(const sfFtpDirectoryResponse* ftpDirectoryResponse)
{
CSFML_CHECK_RETURN(ftpDirectoryResponse, sfFtpInvalidResponse);
return static_cast<sfFtpStatus>(ftpDirectoryResponse->This.GetStatus());
}
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
////////////////////////////////////////////////////////////
const char* sfFtpDirectoryResponse_GetMessage(const sfFtpDirectoryResponse* ftpDirectoryResponse)
{
CSFML_CHECK_RETURN(ftpDirectoryResponse, NULL);
return ftpDirectoryResponse->This.GetMessage().c_str();
}
////////////////////////////////////////////////////////////
/// Get the directory returned in the response
////////////////////////////////////////////////////////////
const char* sfFtpDirectoryResponse_GetDirectory(const sfFtpDirectoryResponse* ftpDirectoryResponse)
{
CSFML_CHECK_RETURN(ftpDirectoryResponse, NULL);
return ftpDirectoryResponse->This.GetDirectory().c_str();
}
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp response
////////////////////////////////////////////////////////////
void sfFtpResponse_Destroy(sfFtpResponse* ftpResponse)
{
delete ftpResponse;
}
////////////////////////////////////////////////////////////
/// Convenience function to check if the response status code
/// means a success
////////////////////////////////////////////////////////////
sfBool sfFtpResponse_IsOk(const sfFtpResponse* ftpResponse)
{
CSFML_CALL_RETURN(ftpResponse, IsOk(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the response status code
////////////////////////////////////////////////////////////
sfFtpStatus sfFtpResponse_GetStatus(const sfFtpResponse* ftpResponse)
{
CSFML_CHECK_RETURN(ftpResponse, sfFtpInvalidResponse);
return static_cast<sfFtpStatus>(ftpResponse->This.GetStatus());
}
////////////////////////////////////////////////////////////
/// Get the full message contained in the response
////////////////////////////////////////////////////////////
const char* sfFtpResponse_GetMessage(const sfFtpResponse* ftpResponse)
{
CSFML_CHECK_RETURN(ftpResponse, NULL);
return ftpResponse->This.GetMessage().c_str();
}
////////////////////////////////////////////////////////////
/// Construct a new Ftp
////////////////////////////////////////////////////////////
sfFtp* sfFtp_Create(void)
{
return new sfFtp;
}
////////////////////////////////////////////////////////////
/// Destroy an existing Ftp
////////////////////////////////////////////////////////////
void sfFtp_Destroy(sfFtp* ftp)
{
delete ftp;
}
////////////////////////////////////////////////////////////
/// Connect to the specified FTP server
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_Connect(sfFtp* ftp, sfIpAddress server, unsigned short port, float timeout)
{
CSFML_CHECK_RETURN(ftp, NULL);
sf::IpAddress SFMLServer(server.Address);
return new sfFtpResponse(ftp->This.Connect(SFMLServer, port, timeout));
}
////////////////////////////////////////////////////////////
/// Log in using anonymous account
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_LoginAnonymous(sfFtp* ftp)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.Login());
}
////////////////////////////////////////////////////////////
/// Log in using a username and a password
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_Login(sfFtp* ftp, const char* userName, const char* password)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.Login(userName ? userName : "", password ? password : ""));
}
////////////////////////////////////////////////////////////
/// Close the connection with FTP server
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_Disconnect(sfFtp* ftp)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.Disconnect());
}
////////////////////////////////////////////////////////////
/// Send a null command just to prevent from being disconnected
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_KeepAlive(sfFtp* ftp)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.KeepAlive());
}
////////////////////////////////////////////////////////////
/// Get the current working directory
////////////////////////////////////////////////////////////
sfFtpDirectoryResponse* sfFtp_GetWorkingDirectory(sfFtp* ftp)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpDirectoryResponse(ftp->This.GetWorkingDirectory());
}
////////////////////////////////////////////////////////////
/// Get the contents of the given directory
/// (subdirectories and files)
////////////////////////////////////////////////////////////
sfFtpListingResponse* sfFtp_GetDirectoryListing(sfFtp* ftp, const char* directory)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpListingResponse(ftp->This.GetDirectoryListing(directory ? directory : ""));
}
////////////////////////////////////////////////////////////
/// Change the current working directory
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_ChangeDirectory(sfFtp* ftp, const char* directory)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.ChangeDirectory(directory ? directory : ""));
}
////////////////////////////////////////////////////////////
/// Go to the parent directory of the current one
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_ParentDirectory(sfFtp* ftp)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.ParentDirectory());
}
////////////////////////////////////////////////////////////
/// Create a new directory
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_CreateDirectory(sfFtp* ftp, const char* name)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.CreateDirectory(name ? name : ""));
}
////////////////////////////////////////////////////////////
/// Remove an existing directory
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_DeleteDirectory(sfFtp* ftp, const char* name)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.DeleteDirectory(name ? name : ""));
}
////////////////////////////////////////////////////////////
/// Rename a file
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_RenameFile(sfFtp* ftp, const char* file, const char* newName)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.RenameFile(file ? file : "", newName ? newName : ""));
}
////////////////////////////////////////////////////////////
/// Remove an existing file
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_DeleteFile(sfFtp* ftp, const char* name)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.DeleteFile(name ? name : ""));
}
////////////////////////////////////////////////////////////
/// Download a file from the server
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_Download(sfFtp* ftp, const char* distantFile, const char* destPath, sfFtpTransferMode mode)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.Download(distantFile ? distantFile : "",
destPath ? destPath : "",
static_cast<sf::Ftp::TransferMode>(mode)));
}
////////////////////////////////////////////////////////////
/// Upload a file to the server
////////////////////////////////////////////////////////////
sfFtpResponse* sfFtp_Upload(sfFtp* ftp, const char* localFile, const char* destPath, sfFtpTransferMode mode)
{
CSFML_CHECK_RETURN(ftp, NULL);
return new sfFtpResponse(ftp->This.Upload(localFile ? localFile : "",
destPath ? destPath : "",
static_cast<sf::Ftp::TransferMode>(mode)));
}

View file

@ -0,0 +1,93 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_FTPSTRUCT_H
#define SFML_FTPSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/Ftp.hpp>
#include <vector>
////////////////////////////////////////////////////////////
// Internal structure of sfFtp
////////////////////////////////////////////////////////////
struct sfFtp
{
sf::Ftp This;
};
////////////////////////////////////////////////////////////
// Internal structure of sfFtpResponse
////////////////////////////////////////////////////////////
struct sfFtpResponse
{
sfFtpResponse(const sf::Ftp::Response& Response)
: This(Response)
{
}
sf::Ftp::Response This;
};
////////////////////////////////////////////////////////////
// Internal structure of sfFtpDirectoryResponse
////////////////////////////////////////////////////////////
struct sfFtpDirectoryResponse
{
sfFtpDirectoryResponse(const sf::Ftp::DirectoryResponse& Response)
: This(Response)
{
}
sf::Ftp::DirectoryResponse This;
};
////////////////////////////////////////////////////////////
// Internal structure of sfFtpListingResponse
////////////////////////////////////////////////////////////
struct sfFtpListingResponse
{
sfFtpListingResponse(const sf::Ftp::ListingResponse& Response)
: This(Response)
{
}
~sfFtpListingResponse()
{
for (std::vector<const char*>::iterator it = Filenames.begin(); it != Filenames.end(); ++it)
delete[] *it;
}
sf::Ftp::ListingResponse This;
std::vector<const char*> Filenames;
};
#endif // SFML_FTPSTRUCT_H

View file

@ -0,0 +1,213 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/Http.h>
#include <SFML/Network/HttpStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new Http request
////////////////////////////////////////////////////////////
sfHttpRequest* sfHttpRequest_Create(void)
{
return new sfHttpRequest;
}
////////////////////////////////////////////////////////////
/// Destroy an existing Http request
////////////////////////////////////////////////////////////
void sfHttpRequest_Destroy(sfHttpRequest* httpRequest)
{
delete httpRequest;
}
////////////////////////////////////////////////////////////
/// Set the value of a field; the field is added if it doesn't exist
////////////////////////////////////////////////////////////
void sfHttpRequest_SetField(sfHttpRequest* httpRequest, const char* field, const char* value)
{
CSFML_CHECK(httpRequest);
if (field)
httpRequest->This.SetField(field, value);
}
////////////////////////////////////////////////////////////
/// Set the request method.
/// This parameter is sfHttpGet by default
////////////////////////////////////////////////////////////
void sfHttpRequest_SetMethod(sfHttpRequest* httpRequest, sfHttpMethod method)
{
CSFML_CALL(httpRequest, SetMethod(static_cast<sf::Http::Request::Method>(method)));
}
////////////////////////////////////////////////////////////
/// Set the target URI of the request.
/// This parameter is "/" by default
////////////////////////////////////////////////////////////
void sfHttpRequest_SetUri(sfHttpRequest* httpRequest, const char* uri)
{
CSFML_CALL(httpRequest, SetUri(uri ? uri : ""));
}
////////////////////////////////////////////////////////////
/// Set the HTTP version of the request.
/// This parameter is 1.0 by default
////////////////////////////////////////////////////////////
void sfHttpRequest_SetHttpVersion(sfHttpRequest* httpRequest, unsigned int major, unsigned int minor)
{
CSFML_CALL(httpRequest, SetHttpVersion(major, minor));
}
////////////////////////////////////////////////////////////
/// Set the body of the request. This parameter is optional and
/// makes sense only for POST requests.
/// This parameter is empty by default
////////////////////////////////////////////////////////////
void sfHttpRequest_SetBody(sfHttpRequest* httpRequest, const char* body)
{
CSFML_CALL(httpRequest, SetBody(body ? body : ""));
}
////////////////////////////////////////////////////////////
/// Destroy an existing Http response
////////////////////////////////////////////////////////////
void sfHttpResponse_Destroy(sfHttpResponse* httpResponse)
{
delete httpResponse;
}
////////////////////////////////////////////////////////////
/// Get the value of a field; returns NULL if the field doesn't exist
////////////////////////////////////////////////////////////
const char* sfHttpResponse_GetField(const sfHttpResponse* httpResponse, const char* field)
{
CSFML_CHECK_RETURN(httpResponse, NULL);
if (!field)
return NULL;
return httpResponse->This.GetField(field).c_str();
}
////////////////////////////////////////////////////////////
/// Get the status of a response
////////////////////////////////////////////////////////////
sfHttpStatus sfHttpResponse_GetStatus(const sfHttpResponse* httpResponse)
{
CSFML_CHECK_RETURN(httpResponse, sfHttpInvalidResponse);
return static_cast<sfHttpStatus>(httpResponse->This.GetStatus());
}
////////////////////////////////////////////////////////////
/// Get the major HTTP version of a response
////////////////////////////////////////////////////////////
unsigned int sfHttpResponse_GetMajorVersion(const sfHttpResponse* httpResponse)
{
CSFML_CALL_RETURN(httpResponse, GetMajorHttpVersion(), 0);
}
////////////////////////////////////////////////////////////
/// Get the minor HTTP version of a response
////////////////////////////////////////////////////////////
unsigned int sfHttpResponse_GetMinorVersion(const sfHttpResponse* httpResponse)
{
CSFML_CALL_RETURN(httpResponse, GetMinorHttpVersion(), 0);
}
////////////////////////////////////////////////////////////
/// Get the body of the response. The body can contain :
/// - the requested page (for GET requests)
/// - a response from the server (for POST requests)
/// - nothing (for HEAD requests)
/// - an error message (in case of an error)
////////////////////////////////////////////////////////////
const char* sfHttpResponse_GetBody(const sfHttpResponse* httpResponse)
{
CSFML_CHECK_RETURN(httpResponse, NULL);
return httpResponse->This.GetBody().c_str();
}
////////////////////////////////////////////////////////////
/// Construct a new Http object
////////////////////////////////////////////////////////////
sfHttp* sfHttp_Create(void)
{
return new sfHttp;
}
////////////////////////////////////////////////////////////
/// Destroy an existing Http object
////////////////////////////////////////////////////////////
void sfHttp_Destroy(sfHttp* http)
{
delete http;
}
////////////////////////////////////////////////////////////
/// Set the target host of a Http server
////////////////////////////////////////////////////////////
void sfHttp_SetHost(sfHttp* http, const char* host, unsigned short port)
{
CSFML_CALL(http, SetHost(host ? host : "", port));
}
////////////////////////////////////////////////////////////
/// Send a HTTP request and return the server's response.
/// You must be connected to a host before sending requests.
/// Any missing mandatory header field will be added with an appropriate value.
/// Warning : this function waits for the server's response and may
/// not return instantly; use a thread if you don't want to block your
/// application.
////////////////////////////////////////////////////////////
sfHttpResponse* sfHttp_SendRequest(sfHttp* http, const sfHttpRequest* request, float timeout)
{
CSFML_CHECK_RETURN(http, NULL);
CSFML_CHECK_RETURN(request, NULL);
sfHttpResponse* response = new sfHttpResponse;
response->This = http->This.SendRequest(request->This, timeout);
return response;
}

View file

@ -0,0 +1,61 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_HTTPSTRUCT_H
#define SFML_HTTPSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/Http.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfHttp
////////////////////////////////////////////////////////////
struct sfHttp
{
sf::Http This;
};
////////////////////////////////////////////////////////////
// Internal structure of sfHttpRequest
////////////////////////////////////////////////////////////
struct sfHttpRequest
{
sf::Http::Request This;
};
////////////////////////////////////////////////////////////
// Internal structure of sfHttpResponse
////////////////////////////////////////////////////////////
struct sfHttpResponse
{
sf::Http::Response This;
};
#endif // SFML_HTTPSTRUCT_H

View file

@ -0,0 +1,137 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/IpAddress.h>
#include <SFML/Network/IpAddress.hpp>
#include <string.h>
namespace
{
////////////////////////////////////////////////////////////
/// Helper function for converting a SFML address to a CSFML one
////////////////////////////////////////////////////////////
sfIpAddress FromSFMLAddress(sf::IpAddress address)
{
sfIpAddress result;
strncpy(result.Address, address.ToString().c_str(), 16);
return result;
}
////////////////////////////////////////////////////////////
/// Helper function for converting a CSFML address to a SFML one
////////////////////////////////////////////////////////////
sf::IpAddress ToSFMLAddress(sfIpAddress address)
{
return sf::IpAddress(address.Address);
}
}
////////////////////////////////////////////////////////////
/// Construct an address from a string
////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_FromString(const char* string)
{
return FromSFMLAddress(sf::IpAddress(string));
}
////////////////////////////////////////////////////////////
/// Construct an address from 4 bytes
////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_FromBytes(sfUint8 byte0, sfUint8 byte1, sfUint8 byte2, sfUint8 byte3)
{
return FromSFMLAddress(sf::IpAddress(byte0, byte1, byte2, byte3));
}
////////////////////////////////////////////////////////////
/// Construct the address from a 32-bits integer
////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_FromInteger(sfUint32 address)
{
return FromSFMLAddress(sf::IpAddress(address));
}
////////////////////////////////////////////////////////////
/// Get a string representation of an address
////////////////////////////////////////////////////////////
void sfIpAddress_ToString(sfIpAddress address, char* string)
{
if (string)
strcpy(string, address.Address);
}
////////////////////////////////////////////////////////////
/// Get an integer representation of the address
////////////////////////////////////////////////////////////
sfUint32 sfIpAddress_ToInteger(sfIpAddress address)
{
return ToSFMLAddress(address).ToInteger();
}
////////////////////////////////////////////////////////////
/// Get the computer's local IP address (from the LAN point of view)
////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_GetLocalAddress(void)
{
return FromSFMLAddress(sf::IpAddress::GetLocalAddress());
}
////////////////////////////////////////////////////////////
/// Get the computer's public IP address (from the web point of view).
/// The only way to get a public address is to ask it to a
/// distant website ; as a consequence, this function may be
/// very slow -- use it as few as possible !
////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_GetPublicAddress(float timeout)
{
return FromSFMLAddress(sf::IpAddress::GetPublicAddress(timeout));
}
////////////////////////////////////////////////////////////
/// Get the computer's loopback address
////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_LocalHost(void)
{
return FromSFMLAddress(sf::IpAddress::LocalHost);
}
////////////////////////////////////////////////////////////
/// Get the empty/invalid address
////////////////////////////////////////////////////////////
sfIpAddress sfIpAddress_None(void)
{
return FromSFMLAddress(sf::IpAddress::None);
}

View file

@ -0,0 +1,209 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/Packet.h>
#include <SFML/Network/PacketStruct.h>
#include <SFML/Internal.h>
namespace
{
////////////////////////////////////////////////////////////
/// Helper function to read a variable from a packet
////////////////////////////////////////////////////////////
template <typename T>
T PacketRead(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, 0);
T value;
packet->This >> value;
return value;
}
////////////////////////////////////////////////////////////
/// Helper function to write a variable to a packet
////////////////////////////////////////////////////////////
template <typename T>
void PacketWrite(sfPacket* packet, T value)
{
CSFML_CHECK(packet);
packet->This << value;
}
}
////////////////////////////////////////////////////////////
/// Create a new empty packet
////////////////////////////////////////////////////////////
sfPacket* sfPacket_Create(void)
{
return new sfPacket;
}
////////////////////////////////////////////////////////////
/// Copy an existing packet
////////////////////////////////////////////////////////////
sfPacket* sfPacket_Copy(sfPacket* packet)
{
CSFML_CHECK_RETURN(packet, NULL);
return new sfPacket(*packet);
}
////////////////////////////////////////////////////////////
/// Destroy an existing packet
////////////////////////////////////////////////////////////
void sfPacket_Destroy(sfPacket* packet)
{
delete packet;
}
////////////////////////////////////////////////////////////
/// Append data to the end of a packet
////////////////////////////////////////////////////////////
void sfPacket_Append(sfPacket* packet, const void* data, size_t sizeInBytes)
{
CSFML_CALL(packet, Append(data, sizeInBytes));
}
////////////////////////////////////////////////////////////
/// Clear all the data of a packet
///////////////////////////////////////////////////////////
void sfPacket_Clear(sfPacket* packet)
{
CSFML_CALL(packet, Clear());
}
////////////////////////////////////////////////////////////
/// Get a pointer to the data contained in a packet
/// Warning : the returned pointer may be invalid after you
/// append data to the packet
////////////////////////////////////////////////////////////
const char* sfPacket_GetData(const sfPacket* packet)
{
CSFML_CALL_RETURN(packet, GetData(), NULL);
}
////////////////////////////////////////////////////////////
/// Get the size of the data contained in a packet
////////////////////////////////////////////////////////////
size_t sfPacket_GetDataSize(const sfPacket* packet)
{
CSFML_CALL_RETURN(packet, GetDataSize(), 0);
}
////////////////////////////////////////////////////////////
/// Tell if the reading position has reached the end of the packet
////////////////////////////////////////////////////////////
sfBool sfPacket_EndOfPacket(const sfPacket* packet)
{
CSFML_CALL_RETURN(packet, EndOfPacket(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Check if a packet is in a valid reading state
////////////////////////////////////////////////////////////
sfBool sfPacket_CanRead(const sfPacket* packet)
{
CSFML_CALL_RETURN(packet, operator bool(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Functions to extract data from a packet
///
/// \param Packet : Packet to read
///
////////////////////////////////////////////////////////////
sfBool sfPacket_ReadBool(sfPacket* packet) {return PacketRead<sfUint8>(packet);}
sfInt8 sfPacket_ReadInt8(sfPacket* packet) {return PacketRead<sfInt8>(packet);}
sfUint8 sfPacket_ReadUint8(sfPacket* packet) {return PacketRead<sfUint8>(packet);}
sfInt16 sfPacket_ReadInt16(sfPacket* packet) {return PacketRead<sfInt16>(packet);}
sfUint16 sfPacket_ReadUint16(sfPacket* packet) {return PacketRead<sfUint16>(packet);}
sfInt32 sfPacket_ReadInt32(sfPacket* packet) {return PacketRead<sfInt32>(packet);}
sfUint32 sfPacket_ReadUint32(sfPacket* packet) {return PacketRead<sfUint32>(packet);}
float sfPacket_ReadFloat(sfPacket* packet) {return PacketRead<float>(packet);}
double sfPacket_ReadDouble(sfPacket* packet) {return PacketRead<double>(packet);}
void sfPacket_ReadString(sfPacket* packet, char* string)
{
CSFML_CHECK(packet);
if (string)
packet->This >> string;
}
void sfPacket_ReadWideString(sfPacket* packet, wchar_t* string)
{
CSFML_CHECK(packet);
if (string)
packet->This >> string;
}
////////////////////////////////////////////////////////////
/// Functions to insert data into a packet
///
/// \param Packet : Packet to write
///
////////////////////////////////////////////////////////////
void sfPacket_WriteBool(sfPacket* packet, sfBool value) {PacketWrite(packet, static_cast<sfUint8>(value));}
void sfPacket_WriteInt8(sfPacket* packet, sfInt8 value) {PacketWrite(packet, value);}
void sfPacket_WriteUint8(sfPacket* packet, sfUint8 value) {PacketWrite(packet, value);}
void sfPacket_WriteInt16(sfPacket* packet, sfInt16 value) {PacketWrite(packet, value);}
void sfPacket_WriteUint16(sfPacket* packet, sfUint16 value) {PacketWrite(packet, value);}
void sfPacket_WriteInt32(sfPacket* packet, sfInt32 value) {PacketWrite(packet, value);}
void sfPacket_WriteUint32(sfPacket* packet, sfUint32 value) {PacketWrite(packet, value);}
void sfPacket_WriteFloat(sfPacket* packet, float value) {PacketWrite(packet, value);}
void sfPacket_WriteDouble(sfPacket* packet, double value) {PacketWrite(packet, value);}
void sfPacket_WriteString(sfPacket* packet, const char* string)
{
CSFML_CHECK(packet);
if (string)
packet->This << string;
}
void sfPacket_WriteWideString(sfPacket* packet, const wchar_t* string)
{
CSFML_CHECK(packet);
if (string)
packet->This << string;
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_PACKETSTRUCT_H
#define SFML_PACKETSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/Packet.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfPacket
////////////////////////////////////////////////////////////
struct sfPacket
{
sf::Packet This;
};
#endif // SFML_PACKETSTRUCT_H

View file

@ -0,0 +1,142 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/SocketSelector.h>
#include <SFML/Network/SocketSelectorStruct.h>
#include <SFML/Network/TcpListenerStruct.h>
#include <SFML/Network/TcpSocketStruct.h>
#include <SFML/Network/UdpSocketStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new selector
////////////////////////////////////////////////////////////
sfSocketSelector* sfSocketSelector_Create(void)
{
return new sfSocketSelector;
}
////////////////////////////////////////////////////////////
/// Copy an existing selector
////////////////////////////////////////////////////////////
sfSocketSelector* sfSocketSelector_Copy(sfSocketSelector* selector)
{
CSFML_CHECK_RETURN(selector, NULL);
return new sfSocketSelector(*selector);
}
////////////////////////////////////////////////////////////
/// Destroy an existing selector
////////////////////////////////////////////////////////////
void sfSocketSelector_Destroy(sfSocketSelector* selector)
{
delete selector;
}
////////////////////////////////////////////////////////////
/// Add a socket to watch to a selector
////////////////////////////////////////////////////////////
void sfSocketSelector_AddTcpListener(sfSocketSelector* selector, sfTcpListener* socket)
{
CSFML_CHECK(socket);
CSFML_CALL(selector, Add(socket->This));
}
void sfSocketSelector_AddTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket)
{
CSFML_CHECK(socket);
CSFML_CALL(selector, Add(socket->This));
}
void sfSocketSelector_AddUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket)
{
CSFML_CHECK(socket);
CSFML_CALL(selector, Add(socket->This));
}
////////////////////////////////////////////////////////////
/// Remove a socket from a selector
////////////////////////////////////////////////////////////
void sfSocketSelector_RemoveTcpListener(sfSocketSelector* selector, sfTcpListener* socket)
{
CSFML_CHECK(socket);
CSFML_CALL(selector, Remove(socket->This));
}
void sfSocketSelector_RemoveTcpSocket(sfSocketSelector* selector, sfTcpSocket* socket)
{
CSFML_CHECK(socket);
CSFML_CALL(selector, Remove(socket->This));
}
void sfSocketSelector_RemoveUdpSocket(sfSocketSelector* selector, sfUdpSocket* socket)
{
CSFML_CHECK(socket);
CSFML_CALL(selector, Remove(socket->This));
}
////////////////////////////////////////////////////////////
/// Remove all sockets from a selector
////////////////////////////////////////////////////////////
void sfSocketSelector_Clear(sfSocketSelector* selector)
{
CSFML_CALL(selector, Clear());
}
////////////////////////////////////////////////////////////
/// Wait and collect sockets which are ready for reading.
/// This functions will return either when at least one socket
/// is ready, or when the given timeout is over
////////////////////////////////////////////////////////////
sfBool sfSocketSelector_Wait(sfSocketSelector* selector, float timeout)
{
CSFML_CALL_RETURN(selector, Wait(timeout), sfFalse);
}
////////////////////////////////////////////////////////////
/// Test a socket to know if it is ready to receive data
////////////////////////////////////////////////////////////
sfBool sfSocketSelector_IsTcpListenerReady(const sfSocketSelector* selector, sfTcpListener* socket)
{
CSFML_CHECK_RETURN(socket, sfFalse);
CSFML_CALL_RETURN(selector, IsReady(socket->This), sfFalse);
}
sfBool sfSocketSelector_IsTcpSocketReady(const sfSocketSelector* selector, sfTcpSocket* socket)
{
CSFML_CHECK_RETURN(socket, sfFalse);
CSFML_CALL_RETURN(selector, IsReady(socket->This), sfFalse);
}
sfBool sfSocketSelector_IsUdpSocketReady(const sfSocketSelector* selector, sfUdpSocket* socket)
{
CSFML_CHECK_RETURN(socket, sfFalse);
CSFML_CALL_RETURN(selector, IsReady(socket->This), sfFalse);
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_SOCKETSELECTORSTRUCT_H
#define SFML_SOCKETSELECTORSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/SocketSelector.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfSocketSelector
////////////////////////////////////////////////////////////
struct sfSocketSelector
{
sf::SocketSelector This;
};
#endif // SFML_SOCKETSELECTORSTRUCT_H

View file

@ -0,0 +1,94 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/TcpListener.h>
#include <SFML/Network/TcpListenerStruct.h>
#include <SFML/Network/TcpSocketStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new TCP socket
////////////////////////////////////////////////////////////
sfTcpListener* sfTcpListener_Create(void)
{
return new sfTcpListener;
}
////////////////////////////////////////////////////////////
/// Destroy an existing TCP socket
////////////////////////////////////////////////////////////
void sfTcpListener_Destroy(sfTcpListener* socket)
{
delete socket;
}
////////////////////////////////////////////////////////////
/// Change the blocking state of a TCP socket.
/// The default behaviour of a socket is blocking
////////////////////////////////////////////////////////////
void sfTcpListener_SetBlocking(sfTcpListener* socket, sfBool blocking)
{
CSFML_CALL(socket, SetBlocking(blocking == sfTrue));
}
////////////////////////////////////////////////////////////
/// Get the blocking state of the socket
////////////////////////////////////////////////////////////
sfBool sfTcpListener_IsBlocking(const sfTcpListener* socket)
{
CSFML_CALL_RETURN(socket, IsBlocking(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Listen to a specified port for incoming data or connections
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpListener_Listen(sfTcpListener* socket, unsigned short port)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
return static_cast<sfSocketStatus>(socket->This.Listen(port));
}
////////////////////////////////////////////////////////////
/// Wait for a connection (must be listening to a port).
/// This function is blocking, ie. it won't return before
/// a connection has been accepted
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpListener_Accept(sfTcpListener* socket, sfTcpSocket** connected)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
CSFML_CHECK_RETURN(connected, sfSocketError);
*connected = new sfTcpSocket;
return static_cast<sfSocketStatus>(socket->This.Accept((*connected)->This));
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TCPLISTENERSTRUCT_H
#define SFML_TCPLISTENERSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/TcpListener.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfTcpListener
////////////////////////////////////////////////////////////
struct sfTcpListener
{
sf::TcpListener This;
};
#endif // SFML_TCPLISTENERSTRUCT_H

View file

@ -0,0 +1,179 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/TcpSocket.h>
#include <SFML/Network/TcpSocketStruct.h>
#include <SFML/Network/PacketStruct.h>
#include <SFML/Network/IpAddress.hpp>
#include <SFML/Internal.h>
#include <string.h>
////////////////////////////////////////////////////////////
/// Construct a new TCP socket
////////////////////////////////////////////////////////////
sfTcpSocket* sfTcpSocket_Create(void)
{
return new sfTcpSocket;
}
////////////////////////////////////////////////////////////
/// Destroy an existing TCP socket
////////////////////////////////////////////////////////////
void sfTcpSocket_Destroy(sfTcpSocket* socket)
{
delete socket;
}
////////////////////////////////////////////////////////////
/// Change the blocking state of a TCP socket.
/// The default behaviour of a socket is blocking
////////////////////////////////////////////////////////////
void sfTcpSocket_SetBlocking(sfTcpSocket* socket, sfBool blocking)
{
CSFML_CALL(socket, SetBlocking(blocking == sfTrue));
}
////////////////////////////////////////////////////////////
/// Get the blocking state of the socket
////////////////////////////////////////////////////////////
sfBool sfTcpSocket_IsBlocking(const sfTcpSocket* socket)
{
CSFML_CALL_RETURN(socket, IsBlocking(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the port to which a socket is bound locally
////////////////////////////////////////////////////////////
unsigned short sfTcpSocket_GetLocalPort(const sfTcpSocket* socket)
{
CSFML_CALL_RETURN(socket, GetLocalPort(), 0);
}
////////////////////////////////////////////////////////////
/// Get the address of the connected peer of a socket
////////////////////////////////////////////////////////////
sfIpAddress sfTcpSocket_GetRemoteAddress(const sfTcpSocket* socket)
{
sfIpAddress result;
CSFML_CHECK_RETURN(socket, result);
sf::IpAddress address = socket->This.GetRemoteAddress();
strncpy(result.Address, address.ToString().c_str(), 16);
return result;
}
////////////////////////////////////////////////////////////
/// Get the port of the connected peer to which a socket is connected
////////////////////////////////////////////////////////////
unsigned short sfTcpSocket_GetRemotePort(const sfTcpSocket* socket)
{
CSFML_CALL_RETURN(socket, GetRemotePort(), 0);
}
////////////////////////////////////////////////////////////
/// Connect a TCP socket to another computer on a specified port
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpSocket_Connect(sfTcpSocket* socket, sfIpAddress host, unsigned short port, float timeout)
{
sf::IpAddress address(host.Address);
CSFML_CHECK_RETURN(socket, sfSocketError);
return static_cast<sfSocketStatus>(socket->This.Connect(address, port, timeout));
}
////////////////////////////////////////////////////////////
/// Disconnect a connect from its remote peer
////////////////////////////////////////////////////////////
void sfTcpSocket_Disconnect(sfTcpSocket* socket)
{
CSFML_CALL(socket, Disconnect());
}
////////////////////////////////////////////////////////////
/// Send an array of bytes to the host (must be connected first)
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpSocket_Send(sfTcpSocket* socket, const char* data, size_t size)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
return static_cast<sfSocketStatus>(socket->This.Send(data, size));
}
////////////////////////////////////////////////////////////
/// Receive an array of bytes from the host (must be connected first)
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpSocket_Receive(sfTcpSocket* socket, char* data, size_t maxSize, size_t* sizeReceived)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
if (sizeReceived)
{
return static_cast<sfSocketStatus>(socket->This.Receive(data, maxSize, *sizeReceived));
}
else
{
std::size_t size = 0;
return static_cast<sfSocketStatus>(socket->This.Receive(data, maxSize, size));
}
}
////////////////////////////////////////////////////////////
/// Send a packet of data to the host (must be connected first)
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpSocket_SendPacket(sfTcpSocket* socket, sfPacket* packet)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
CSFML_CHECK_RETURN(packet, sfSocketError);
return static_cast<sfSocketStatus>(socket->This.Send(packet->This));
}
////////////////////////////////////////////////////////////
/// Receive a packet from the host (must be connected first)
////////////////////////////////////////////////////////////
sfSocketStatus sfTcpSocket_ReceivePacket(sfTcpSocket* socket, sfPacket* packet)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
CSFML_CHECK_RETURN(packet, sfSocketError);
return static_cast<sfSocketStatus>(socket->This.Receive(packet->This));
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_TCPSOCKETSTRUCT_H
#define SFML_TCPSOCKETSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/TcpSocket.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfTcpSocket
////////////////////////////////////////////////////////////
struct sfTcpSocket
{
sf::TcpSocket This;
};
#endif // SFML_TCPSOCKETSTRUCT_H

View file

@ -0,0 +1,184 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/UdpSocket.h>
#include <SFML/Network/UdpSocketStruct.h>
#include <SFML/Network/PacketStruct.h>
#include <SFML/Network/IpAddress.hpp>
#include <SFML/Internal.h>
#include <string.h>
////////////////////////////////////////////////////////////
/// Construct a new UDP socket
////////////////////////////////////////////////////////////
sfUdpSocket* sfUdpSocket_Create(void)
{
return new sfUdpSocket;
}
////////////////////////////////////////////////////////////
/// Destroy an existing UDP socket
////////////////////////////////////////////////////////////
void sfUdpSocket_Destroy(sfUdpSocket* socket)
{
delete socket;
}
////////////////////////////////////////////////////////////
/// Change the blocking state of a UDP socket.
/// The default behaviour of a socket is blocking
////////////////////////////////////////////////////////////
void sfUdpSocket_SetBlocking(sfUdpSocket* socket, sfBool blocking)
{
CSFML_CALL(socket, SetBlocking(blocking == sfTrue));
}
////////////////////////////////////////////////////////////
/// Get the blocking state of the socket
////////////////////////////////////////////////////////////
sfBool sfUdpSocket_IsBlocking(const sfUdpSocket* socket)
{
CSFML_CALL_RETURN(socket, IsBlocking(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the port to which the socket is bound locally
////////////////////////////////////////////////////////////
unsigned short sfUdpSocket_GetLocalPort(const sfUdpSocket* socket)
{
CSFML_CALL_RETURN(socket, GetLocalPort(), 0);
}
////////////////////////////////////////////////////////////
/// Bind a socket to a specific port
////////////////////////////////////////////////////////////
sfSocketStatus sfUdpSocket_Bind(sfUdpSocket* socket, unsigned short port)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
return static_cast<sfSocketStatus>(socket->This.Bind(port));
}
////////////////////////////////////////////////////////////
/// Unbind a socket from its previous port, if any
////////////////////////////////////////////////////////////
void sfUdpSocket_Unbind(sfUdpSocket* socket)
{
CSFML_CALL(socket, Unbind());
}
////////////////////////////////////////////////////////////
/// Send an array of bytes
////////////////////////////////////////////////////////////
sfSocketStatus sfUdpSocket_Send(sfUdpSocket* socket, const char* data, size_t size, sfIpAddress address, unsigned short port)
{
CSFML_CHECK_RETURN(socket, sfSocketError)
// Convert the address
sf::IpAddress receiver(address.Address);
return static_cast<sfSocketStatus>(socket->This.Send(data, size, receiver, port));
}
////////////////////////////////////////////////////////////
/// Receive an array of bytes.
/// This function is blocking, ie. it won't return before some
/// bytes have been received
////////////////////////////////////////////////////////////
sfSocketStatus sfUdpSocket_Receive(sfUdpSocket* socket, char* data, size_t maxSize, size_t* sizeReceived, sfIpAddress* address, unsigned short* port)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
// Call SFML internal function
sf::IpAddress sender;
unsigned short senderPort;
std::size_t received;
sf::Socket::Status status = socket->This.Receive(data, maxSize, received, sender, senderPort);
if (status != sf::Socket::Done)
return static_cast<sfSocketStatus>(status);
if (sizeReceived)
*sizeReceived = received;
if (address)
strncpy(address->Address, sender.ToString().c_str(), 16);
if (port)
*port = senderPort;
return sfSocketDone;
}
////////////////////////////////////////////////////////////
/// Send a packet of data
////////////////////////////////////////////////////////////
sfSocketStatus sfUdpSocket_SendPacket(sfUdpSocket* socket, sfPacket* packet, sfIpAddress address, unsigned short port)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
CSFML_CHECK_RETURN(packet, sfSocketError);
// Convert the address
sf::IpAddress receiver(address.Address);
return static_cast<sfSocketStatus>(socket->This.Send(packet->This, receiver, port));
}
////////////////////////////////////////////////////////////
/// Receive a packet.
/// This function is blocking, ie. it won't return before a
/// packet is received
////////////////////////////////////////////////////////////
sfSocketStatus sfUdpSocket_ReceivePacket(sfUdpSocket* socket, sfPacket* packet, sfIpAddress* address, unsigned short* port)
{
CSFML_CHECK_RETURN(socket, sfSocketError);
CSFML_CHECK_RETURN(packet, sfSocketError);
sf::IpAddress sender;
unsigned short senderPort;
sf::Socket::Status status = socket->This.Receive(packet->This, sender, senderPort);
if (status != sf::Socket::Done)
return static_cast<sfSocketStatus>(status);
if (address)
strncpy(address->Address, sender.ToString().c_str(), 16);
if (port)
*port = senderPort;
return sfSocketDone;
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_UDPSOCKETSTRUCT_H
#define SFML_UDPSOCKETSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Network/UdpSocket.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfUdpSocket
////////////////////////////////////////////////////////////
struct sfUdpSocket
{
sf::UdpSocket This;
};
#endif // SFML_UDPSOCKETSTRUCT_H

View file

@ -0,0 +1,26 @@
set(INCROOT ${CMAKE_SOURCE_DIR}/include/SFML/System)
set(SRCROOT ${CMAKE_SOURCE_DIR}/src/SFML/System)
# all source files
set(SRC
${SRCROOT}/Clock.cpp
${SRCROOT}/ClockStruct.h
${INCROOT}/Clock.h
${SRCROOT}/Mutex.cpp
${SRCROOT}/MutexStruct.h
${INCROOT}/Mutex.h
${SRCROOT}/Randomizer.cpp
${INCROOT}/Randomizer.h
${SRCROOT}/Sleep.cpp
${INCROOT}/Sleep.h
${SRCROOT}/Thread.cpp
${SRCROOT}/ThreadStruct.h
${INCROOT}/Thread.h
${INCROOT}/Types.h
)
# define the csfml-system target
csfml_add_library(csfml-system
SOURCES ${SRC}
DEPENDS optimized ${SFML_SYSTEM_LIBRARY} debug ${SFML_SYSTEM_LIBRARY_DEBUG})

View file

@ -0,0 +1,77 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Clock.h>
#include <SFML/System/ClockStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new clock and start it
////////////////////////////////////////////////////////////
sfClock* sfClock_Create(void)
{
return new sfClock;
}
////////////////////////////////////////////////////////////
/// Copy an existing clock
////////////////////////////////////////////////////////////
sfClock* sfClock_Copy(sfClock* clock)
{
CSFML_CHECK_RETURN(clock, NULL);
return new sfClock(*clock);
}
////////////////////////////////////////////////////////////
/// Destroy an existing clock
////////////////////////////////////////////////////////////
void sfClock_Destroy(sfClock* clock)
{
delete clock;
}
////////////////////////////////////////////////////////////
/// Get the time elapsed for a clock
////////////////////////////////////////////////////////////
float sfClock_GetTime(const sfClock* clock)
{
CSFML_CALL_RETURN(clock, GetElapsedTime(), 0.f)
}
////////////////////////////////////////////////////////////
/// Restart a clock
////////////////////////////////////////////////////////////
void sfClock_Reset(sfClock* clock)
{
CSFML_CALL(clock, Reset())
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CLOCKSTRUCT_H
#define SFML_CLOCKSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Clock.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfClock
////////////////////////////////////////////////////////////
struct sfClock
{
sf::Clock This;
};
#endif // SFML_CLOCKSTRUCT_H

View file

@ -0,0 +1,66 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Mutex.h>
#include <SFML/System/MutexStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Create a new mutex
////////////////////////////////////////////////////////////
sfMutex* sfMutex_Create(void)
{
return new sfMutex;
}
////////////////////////////////////////////////////////////
/// Destroy an existing mutex
////////////////////////////////////////////////////////////
void sfMutex_Destroy(sfMutex* mutex)
{
delete mutex;
}
////////////////////////////////////////////////////////////
/// Lock a mutex
////////////////////////////////////////////////////////////
void sfMutex_Lock(sfMutex* mutex)
{
CSFML_CALL(mutex, Lock())
}
////////////////////////////////////////////////////////////
/// Unlock a mutex
////////////////////////////////////////////////////////////
void sfMutex_Unlock(sfMutex* mutex)
{
CSFML_CALL(mutex, Unlock())
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_MUTEXSTRUCT_H
#define SFML_MUTEXSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Mutex.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfMutex
////////////////////////////////////////////////////////////
struct sfMutex
{
sf::Mutex This;
};
#endif // SFML_MUTEXSTRUCT_H

View file

@ -0,0 +1,67 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Randomizer.h>
#include <SFML/System/Randomizer.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Set the seed for the random numbers generator. Using a known seed
/// allows you to reproduce the same sequence of random numbers
////////////////////////////////////////////////////////////
void sfRandom_SetSeed(unsigned int seed)
{
sf::Randomizer::SetSeed(seed);
}
////////////////////////////////////////////////////////////
/// Get the seed used to generate random numbers the generator
////////////////////////////////////////////////////////////
unsigned int sfRandom_GetSeed(void)
{
return sf::Randomizer::GetSeed();
}
////////////////////////////////////////////////////////////
/// Get a random float number in a given range
////////////////////////////////////////////////////////////
float sfRandom_Float(float begin, float end)
{
return sf::Randomizer::Random(begin, end);
}
////////////////////////////////////////////////////////////
/// Get a random integer number in a given range
////////////////////////////////////////////////////////////
int sfRandom_Int(int begin, int end)
{
return sf::Randomizer::Random(begin, end);
}

View file

@ -0,0 +1,39 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Sleep.h>
#include <SFML/System/Sleep.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Make the current thread sleep for a given time
////////////////////////////////////////////////////////////
void sfSleep(float Duration)
{
sf::Sleep(Duration);
}

View file

@ -0,0 +1,78 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Thread.h>
#include <SFML/System/ThreadStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new thread from a function pointer
////////////////////////////////////////////////////////////
sfThread* sfThread_Create(void (*function)(void*), void* userData)
{
return new sfThread(function, userData);
}
////////////////////////////////////////////////////////////
/// Destroy an existing thread
////////////////////////////////////////////////////////////
void sfThread_Destroy(sfThread* thread)
{
delete thread;
}
////////////////////////////////////////////////////////////
/// Run a thread
////////////////////////////////////////////////////////////
void sfThread_Launch(sfThread* thread)
{
CSFML_CALL(thread, Launch());
}
////////////////////////////////////////////////////////////
/// Wait until a thread finishes
////////////////////////////////////////////////////////////
void sfThread_Wait(sfThread* thread)
{
CSFML_CALL(thread, Wait());
}
////////////////////////////////////////////////////////////
/// Terminate a thread
/// Terminating a thread with this function is not safe,
/// you should rather try to make the thread function
/// terminate by itself
////////////////////////////////////////////////////////////
void sfThread_Terminate(sfThread* thread)
{
CSFML_CALL(thread, Terminate());
}

View file

@ -0,0 +1,48 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_THREADSTRUCT_H
#define SFML_THREADSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Thread.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfThread
////////////////////////////////////////////////////////////
struct sfThread
{
sfThread(void (*Function)(void*), void* UserData) :
This(Function, UserData)
{
}
sf::Thread This;
};
#endif // SFML_THREADSTRUCT_H

View file

@ -0,0 +1,27 @@
set(INCROOT ${CMAKE_SOURCE_DIR}/include/SFML/Window)
set(SRCROOT ${CMAKE_SOURCE_DIR}/src/SFML/Window)
# all source files
set(SRC
${SRCROOT}/Context.cpp
${SRCROOT}/ContextStruct.h
${INCROOT}/Context.h
${INCROOT}/Event.h
${SRCROOT}/Input.cpp
${SRCROOT}/InputStruct.h
${INCROOT}/Input.h
${INCROOT}/Types.h
${SRCROOT}/VideoMode.cpp
${INCROOT}/VideoMode.h
${SRCROOT}/Window.cpp
${SRCROOT}/WindowStruct.h
${INCROOT}/Window.h
${INCROOT}/WindowHandle.h
)
# define the csfml-window target
csfml_add_library(csfml-window
SOURCES ${SRC}
DEPENDS optimized ${SFML_WINDOW_LIBRARY} debug ${SFML_WINDOW_LIBRARY_DEBUG}
optimized ${SFML_SYSTEM_LIBRARY} debug ${SFML_SYSTEM_LIBRARY_DEBUG})

View file

@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Context.h>
#include <SFML/Window/ContextStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Construct a new context
////////////////////////////////////////////////////////////
sfContext* sfContext_Create(void)
{
return new sfContext;
}
////////////////////////////////////////////////////////////
/// Destroy an existing context
////////////////////////////////////////////////////////////
void sfContext_Destroy(sfContext* context)
{
delete context;
}
////////////////////////////////////////////////////////////
/// Activate or deactivate a context
////////////////////////////////////////////////////////////
void sfContext_SetActive(sfContext* context, sfBool active)
{
CSFML_CALL(context, SetActive(active == sfTrue))
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_CONTEXTSTRUCT_H
#define SFML_CONTEXTSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Context.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfContext
////////////////////////////////////////////////////////////
struct sfContext
{
sf::Context This;
};
#endif // SFML_CONTEXTSTRUCT_H

View file

@ -0,0 +1,83 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Input.h>
#include <SFML/Window/InputStruct.h>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Get the state of a key
////////////////////////////////////////////////////////////
sfBool sfInput_IsKeyDown(const sfInput* input, sfKeyCode code)
{
CSFML_CALL_PTR_RETURN(input, IsKeyDown((sf::Key::Code)code), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the state of a mouse button
////////////////////////////////////////////////////////////
sfBool sfInput_IsMouseButtonDown(const sfInput* input, sfMouseButton button)
{
CSFML_CALL_PTR_RETURN(input, IsMouseButtonDown((sf::Mouse::Button)button), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the state of a joystick button
////////////////////////////////////////////////////////////
sfBool sfInput_IsJoystickButtonDown(const sfInput* input, unsigned int joyId, unsigned int button)
{
CSFML_CALL_PTR_RETURN(input, IsJoystickButtonDown(joyId, button), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the mouse X position
////////////////////////////////////////////////////////////
int sfInput_GetMouseX(const sfInput* input)
{
CSFML_CALL_PTR_RETURN(input, GetMouseX(), 0);
}
////////////////////////////////////////////////////////////
/// Get the mouse Y position
////////////////////////////////////////////////////////////
int sfInput_GetMouseY(const sfInput* input)
{
CSFML_CALL_PTR_RETURN(input, GetMouseY(), 0);
}
////////////////////////////////////////////////////////////
/// Get the joystick position on a given axis
////////////////////////////////////////////////////////////
float sfInput_GetJoystickAxis(const sfInput* input, unsigned int joyId, sfJoyAxis axis)
{
CSFML_CALL_PTR_RETURN(input, GetJoystickAxis(joyId, (sf::Joy::Axis)axis), 0.f);
}

View file

@ -0,0 +1,43 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_INPUTSTRUCT_H
#define SFML_INPUTSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Input.hpp>
////////////////////////////////////////////////////////////
// Internal structure of sfInput
////////////////////////////////////////////////////////////
struct sfInput
{
const sf::Input* This;
};
#endif // SFML_INPUTSTRUCT_H

View file

@ -0,0 +1,84 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/VideoMode.h>
#include <SFML/Window/VideoMode.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Get the current desktop video mode
////////////////////////////////////////////////////////////
sfVideoMode sfVideoMode_GetDesktopMode(void)
{
sf::VideoMode desktop = sf::VideoMode::GetDesktopMode();
sfVideoMode ret;
ret.Width = desktop.Width;
ret.Height = desktop.Height;
ret.BitsPerPixel = desktop.BitsPerPixel;
return ret;
}
////////////////////////////////////////////////////////////
/// Get all the supported video modes for fullscreen mode.
/// Modes are sorted from best to worst.
////////////////////////////////////////////////////////////
const sfVideoMode* sfVideoMode_GetFullscreenModes(size_t* Count)
{
static std::vector<sfVideoMode> modes;
// Populate the array on first call
if (modes.empty())
{
const std::vector<sf::VideoMode>& SFMLModes = sf::VideoMode::GetFullscreenModes();
for (std::vector<sf::VideoMode>::const_iterator it = SFMLModes.begin(); it != SFMLModes.end(); ++it)
{
sfVideoMode mode;
mode.Width = it->Width;
mode.Height = it->Height;
mode.BitsPerPixel = it->BitsPerPixel;
modes.push_back(mode);
}
}
if (Count)
*Count = modes.size();
return !modes.empty() ? &modes[0] : NULL;
}
////////////////////////////////////////////////////////////
/// Tell whether or not a video mode is supported
////////////////////////////////////////////////////////////
sfBool sfVideoMode_IsValid(sfVideoMode mode)
{
sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel);
return videoMode.IsValid() ? sfTrue : sfFalse;
}

View file

@ -0,0 +1,335 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Window.h>
#include <SFML/Window/WindowStruct.h>
#include <SFML/Internal.h>
#include <SFML/ConvertEvent.h>
////////////////////////////////////////////////////////////
/// Construct a new window
////////////////////////////////////////////////////////////
sfWindow* sfWindow_Create(sfVideoMode mode, const char* title, unsigned long style, const sfContextSettings* settings)
{
// Convert video mode
sf::VideoMode videoMode(mode.Width, mode.Height, mode.BitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window
sfWindow* window = new sfWindow;
window->This.Create(videoMode, title, style, params);
window->Input.This = &window->This.GetInput();
return window;
}
////////////////////////////////////////////////////////////
/// Construct a window from an existing control
////////////////////////////////////////////////////////////
sfWindow* sfWindow_CreateFromHandle(sfWindowHandle handle, const sfContextSettings* settings)
{
// Convert context settings
sf::ContextSettings params;
if (settings)
{
params.DepthBits = settings->DepthBits;
params.StencilBits = settings->StencilBits;
params.AntialiasingLevel = settings->AntialiasingLevel;
params.MajorVersion = settings->MajorVersion;
params.MinorVersion = settings->MinorVersion;
}
// Create the window
sfWindow* window = new sfWindow;
window->This.Create(handle, params);
window->Input.This = &window->This.GetInput();
return window;
}
////////////////////////////////////////////////////////////
/// Destroy an existing window
////////////////////////////////////////////////////////////
void sfWindow_Destroy(sfWindow* window)
{
delete window;
}
////////////////////////////////////////////////////////////
/// Close a window (but doesn't destroy the internal data)
////////////////////////////////////////////////////////////
void sfWindow_Close(sfWindow* window)
{
CSFML_CALL(window, Close());
}
////////////////////////////////////////////////////////////
/// Tell whether or not a window is opened
////////////////////////////////////////////////////////////
sfBool sfWindow_IsOpened(const sfWindow* window)
{
CSFML_CALL_RETURN(window, IsOpened(), sfFalse);
}
////////////////////////////////////////////////////////////
/// Get the width of the rendering region of a window
////////////////////////////////////////////////////////////
unsigned int sfWindow_GetWidth(const sfWindow* window)
{
CSFML_CALL_RETURN(window, GetWidth(), 0)
}
////////////////////////////////////////////////////////////
/// Get the height of the rendering region of a window
////////////////////////////////////////////////////////////
unsigned int sfWindow_GetHeight(const sfWindow* window)
{
CSFML_CALL_RETURN(window, GetHeight(), 0)
}
////////////////////////////////////////////////////////////
/// Get the creation settings of a window
////////////////////////////////////////////////////////////
sfContextSettings sfWindow_GetSettings(const sfWindow* window)
{
sfContextSettings settings = {0, 0, 0, 0, 0};
CSFML_CHECK_RETURN(window, settings);
const sf::ContextSettings& params = window->This.GetSettings();
settings.DepthBits = params.DepthBits;
settings.StencilBits = params.StencilBits;
settings.AntialiasingLevel = params.AntialiasingLevel;
settings.MajorVersion = params.MajorVersion;
settings.MinorVersion = params.MinorVersion;
return settings;
}
////////////////////////////////////////////////////////////
/// Get the event on top of events stack of a window, if any, and pop it
////////////////////////////////////////////////////////////
sfBool sfWindow_GetEvent(sfWindow* window, sfEvent* event)
{
CSFML_CHECK_RETURN(window, sfFalse);
CSFML_CHECK_RETURN(event, sfFalse);
// Get the event
sf::Event SFMLEvent;
sfBool ret = window->This.GetEvent(SFMLEvent);
// No event, return
if (!ret)
return sfFalse;
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
return sfTrue;
}
////////////////////////////////////////////////////////////
/// Wait for an event and return it
////////////////////////////////////////////////////////////
sfBool sfWindow_WaitEvent(sfWindow* window, sfEvent* event)
{
CSFML_CHECK_RETURN(window, sfFalse);
CSFML_CHECK_RETURN(event, sfFalse);
// Get the event
sf::Event SFMLEvent;
sfBool ret = window->This.WaitEvent(SFMLEvent);
// Error, return
if (!ret)
return sfFalse;
// Convert the sf::Event event to a sfEvent
ConvertEvent(SFMLEvent, event);
return sfTrue;
}
////////////////////////////////////////////////////////////
/// Enable / disable vertical synchronization on a window
////////////////////////////////////////////////////////////
void sfWindow_UseVerticalSync(sfWindow* window, sfBool enabled)
{
CSFML_CALL(window, UseVerticalSync(enabled == sfTrue))
}
////////////////////////////////////////////////////////////
/// Show or hide the mouse cursor on a window
////////////////////////////////////////////////////////////
void sfWindow_ShowMouseCursor(sfWindow* window, sfBool show)
{
CSFML_CALL(window, ShowMouseCursor(show == sfTrue))
}
////////////////////////////////////////////////////////////
/// Change the position of the mouse cursor on a window
////////////////////////////////////////////////////////////
void sfWindow_SetCursorPosition(sfWindow* window, unsigned int left, unsigned int top)
{
CSFML_CALL(window, SetCursorPosition(left, top))
}
////////////////////////////////////////////////////////////
/// Change the position of a window on screen.
/// Only works for top-level windows
////////////////////////////////////////////////////////////
void sfWindow_SetPosition(sfWindow* window, int left, int top)
{
CSFML_CALL(window, SetPosition(left, top))
}
////////////////////////////////////////////////////////////
/// Change the size of the rendering region of a window
////////////////////////////////////////////////////////////
void sfWindow_SetSize(sfWindow* window, unsigned int width, unsigned int height)
{
CSFML_CALL(window, SetSize(width, height))
}
////////////////////////////////////////////////////////////
/// Show or hide a window
////////////////////////////////////////////////////////////
void sfWindow_Show(sfWindow* window, sfBool show)
{
CSFML_CALL(window, Show(show == sfTrue))
}
////////////////////////////////////////////////////////////
/// Enable or disable automatic key-repeat for keydown events.
/// Automatic key-repeat is enabled by default
////////////////////////////////////////////////////////////
void sfWindow_EnableKeyRepeat(sfWindow* window, sfBool enabled)
{
CSFML_CALL(window, EnableKeyRepeat(enabled == sfTrue))
}
////////////////////////////////////////////////////////////
/// Change the window's icon
////////////////////////////////////////////////////////////
void sfWindow_SetIcon(sfWindow* window, unsigned int width, unsigned int height, const sfUint8* pixels)
{
CSFML_CALL(window, SetIcon(width, height, pixels))
}
////////////////////////////////////////////////////////////
/// Activate or deactivate a window as the current target for rendering
////////////////////////////////////////////////////////////
sfBool sfWindow_SetActive(sfWindow* window, sfBool active)
{
CSFML_CALL_RETURN(window, SetActive(active == sfTrue), sfFalse)
}
////////////////////////////////////////////////////////////
/// Display a window on screen
////////////////////////////////////////////////////////////
void sfWindow_Display(sfWindow* window)
{
CSFML_CALL(window, Display())
}
////////////////////////////////////////////////////////////
/// Get the input manager of a window
////////////////////////////////////////////////////////////
const sfInput* sfWindow_GetInput(sfWindow* window)
{
CSFML_CHECK_RETURN(window, NULL);
return &window->Input;
}
////////////////////////////////////////////////////////////
/// Limit the framerate to a maximum fixed frequency for a window
////////////////////////////////////////////////////////////
void sfWindow_SetFramerateLimit(sfWindow* window, unsigned int limit)
{
CSFML_CALL(window, SetFramerateLimit(limit))
}
////////////////////////////////////////////////////////////
/// Get time elapsed since last frame of a window
////////////////////////////////////////////////////////////
float sfWindow_GetFrameTime(const sfWindow* window)
{
CSFML_CALL_RETURN(window, GetFrameTime(), 0.f)
}
////////////////////////////////////////////////////////////
/// Change the joystick threshold, ie. the value below which
/// no move event will be generated
////////////////////////////////////////////////////////////
void sfWindow_SetJoystickThreshold(sfWindow* window, float threshold)
{
CSFML_CALL(window, SetJoystickThreshold(threshold))
}
////////////////////////////////////////////////////////////
/// Retrieve the Os-specific handle of a window
////////////////////////////////////////////////////////////
sfWindowHandle sfWindow_GetSystemHandle(const sfWindow* window)
{
CSFML_CHECK_RETURN(window, NULL);
return (sfWindowHandle)window->This.GetSystemHandle();
}

View file

@ -0,0 +1,45 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
//
// This software is provided 'as-is', without any express or implied warranty.
// In no event will the authors be held liable for any damages arising from the use of this software.
//
// Permission is granted to anyone to use this software for any purpose,
// including commercial applications, and to alter it and redistribute it freely,
// subject to the following restrictions:
//
// 1. The origin of this software must not be misrepresented;
// you must not claim that you wrote the original software.
// If you use this software in a product, an acknowledgment
// in the product documentation would be appreciated but is not required.
//
// 2. Altered source versions must be plainly marked as such,
// and must not be misrepresented as being the original software.
//
// 3. This notice may not be removed or altered from any source distribution.
//
////////////////////////////////////////////////////////////
#ifndef SFML_WINDOWSTRUCT_H
#define SFML_WINDOWSTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Window.hpp>
#include <SFML/Window/InputStruct.h>
////////////////////////////////////////////////////////////
// Internal structure of sfWindow
////////////////////////////////////////////////////////////
struct sfWindow
{
sf::Window This;
sfInput Input;
};
#endif // SFML_WINDOWSTRUCT_H