Added the trunk/branches/tags directories at repository root, and moved previous root into trunk/
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1002 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
commit
2f524481c1
974 changed files with 295448 additions and 0 deletions
98
CSFML/src/SFML/Audio/Listener.cpp
Normal file
98
CSFML/src/SFML/Audio/Listener.cpp
Normal file
|
@ -0,0 +1,98 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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()
|
||||
{
|
||||
return sf::Listener::GetGlobalVolume();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the position of the listener
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfListener_SetPosition(float PosX, float PosY, float PosZ)
|
||||
{
|
||||
sf::Listener::SetPosition(sf::Vector3f(PosX, PosY, PosZ));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current position of the listener
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfListener_GetPosition(float* PosX, float* PosY, float* PosZ)
|
||||
{
|
||||
if (PosX && PosY && PosZ)
|
||||
{
|
||||
sf::Vector3f Position = sf::Listener::GetPosition();
|
||||
*PosX = Position.x;
|
||||
*PosY = Position.y;
|
||||
*PosZ = Position.z;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the orientation of the listener (the point
|
||||
/// he must look at)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfListener_SetTarget(float TargetX, float TargetY, float TargetZ)
|
||||
{
|
||||
sf::Listener::SetTarget(sf::Vector3f(TargetX, TargetY, TargetZ));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current orientation of the listener (the point
|
||||
/// he's looking at)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfListener_GetTarget(float* TargetX, float* TargetY, float* TargetZ)
|
||||
{
|
||||
if (TargetX && TargetY && TargetZ)
|
||||
{
|
||||
sf::Vector3f Target = sf::Listener::GetTarget();
|
||||
*TargetX = Target.x;
|
||||
*TargetY = Target.y;
|
||||
*TargetZ = Target.z;
|
||||
}
|
||||
}
|
23
CSFML/src/SFML/Audio/Makefile
Normal file
23
CSFML/src/SFML/Audio/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
LIB = libcsfml-audio.so
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
LIBNAME = $(LIBPATH)/$(LIB).$(VERSION)
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
libcsfml-audio.so: $(OBJ)
|
||||
$(CPP) $(LDFLAGS) -Wl,-soname,$(LIB).$(VERSION) -o $(LIBNAME) $(OBJ) -lsfml-audio
|
||||
|
||||
$(OBJ): %.o: %.cpp
|
||||
$(CPP) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
@rm -rf $(LIBNAME)
|
||||
|
||||
install:
|
||||
@($(CP) $(LIBNAME) $(DESTLIBDIR) && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB))
|
273
CSFML/src/SFML/Audio/Music.cpp
Normal file
273
CSFML/src/SFML/Audio/Music.cpp
Normal file
|
@ -0,0 +1,273 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Music.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfMusic
|
||||
{
|
||||
sf::Music This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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 char* 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(sfMusic* Music)
|
||||
{
|
||||
CSFML_CALL_RETURN(Music, GetLoop(), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a music duration
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfMusic_GetDuration(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(sfMusic* Music)
|
||||
{
|
||||
CSFML_CALL_RETURN(Music, GetChannelsCount(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the stream sample rate of a music
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfMusic_GetSampleRate(sfMusic* Music)
|
||||
{
|
||||
CSFML_CALL_RETURN(Music, GetSampleRate(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the status of a music (stopped, paused, playing)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSoundStatus sfMusic_GetStatus(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(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)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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 MinDistance)
|
||||
{
|
||||
CSFML_CALL(Music, SetMinDistance(MinDistance));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the pitch of a music
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfMusic_GetPitch(sfMusic* Music)
|
||||
{
|
||||
CSFML_CALL_RETURN(Music, GetPitch(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the volume of a music
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfMusic_GetVolume(sfMusic* Music)
|
||||
{
|
||||
CSFML_CALL_RETURN(Music, GetVolume(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the position of a music
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfMusic_GetPosition(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;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the minimum distance of a music
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfMusic_GetMinDistance(sfMusic* Music)
|
||||
{
|
||||
CSFML_CALL_RETURN(Music, GetMinDistance(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the attenuation factor of a a
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfMusic_GetAttenuation(sfMusic* Music)
|
||||
{
|
||||
CSFML_CALL_RETURN(Music, GetAttenuation(), 0.f);
|
||||
}
|
258
CSFML/src/SFML/Audio/Sound.cpp
Normal file
258
CSFML/src/SFML/Audio/Sound.cpp
Normal file
|
@ -0,0 +1,258 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Sound.hpp>
|
||||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Audio/SoundBuffer.h
|
||||
struct sfSoundBuffer
|
||||
{
|
||||
sf::SoundBuffer This;
|
||||
};
|
||||
struct sfSound
|
||||
{
|
||||
sf::Sound This;
|
||||
sfSoundBuffer* Buffer;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new sound
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSound* sfSound_Create()
|
||||
{
|
||||
return new sfSound;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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, sfSoundBuffer* Buffer)
|
||||
{
|
||||
if (Buffer)
|
||||
{
|
||||
CSFML_CALL(Sound, SetBuffer(Buffer->This))
|
||||
Sound->Buffer = Buffer;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sound buffer bound to a sound
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSoundBuffer* sfSound_GetBuffer(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(sfSound* Sound)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sound, GetLoop(), sfFalse)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the status of a sound (stopped, paused, playing)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSoundStatus sfSound_GetStatus(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)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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 MinDistance)
|
||||
{
|
||||
CSFML_CALL(Sound, SetMinDistance(MinDistance));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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(sfSound* Sound)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sound, GetPitch(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the volume of a sound
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSound_GetVolume(sfSound* Sound)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sound, GetVolume(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the position of a sound
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSound_GetPosition(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;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the minimum distance of a sound
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSound_GetMinDistance(sfSound* Sound)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sound, GetMinDistance(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the attenuation factor of a sound
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSound_GetAttenuation(sfSound* Sound)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sound, GetAttenuation(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current playing position of a sound
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSound_GetPlayingOffset(sfSound* Sound)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sound, GetPlayingOffset(), 0.f)
|
||||
}
|
152
CSFML/src/SFML/Audio/SoundBuffer.cpp
Normal file
152
CSFML/src/SFML/Audio/SoundBuffer.cpp
Normal file
|
@ -0,0 +1,152 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/SoundBuffer.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfSoundBuffer
|
||||
{
|
||||
sf::SoundBuffer This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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 char* 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;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing sound buffer
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSoundBuffer_Destroy(sfSoundBuffer* SoundBuffer)
|
||||
{
|
||||
delete SoundBuffer;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Save a sound buffer to a file
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfSoundBuffer_SaveToFile(sfSoundBuffer* SoundBuffer, const char* Filename)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundBuffer, SaveToFile(Filename), sfFalse)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the samples contained in a sound buffer
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfInt16* sfSoundBuffer_GetSamples(sfSoundBuffer* SoundBuffer)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundBuffer, GetSamples(), NULL)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the number of samples contained in a sound buffer
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfSoundBuffer_GetSamplesCount(sfSoundBuffer* SoundBuffer)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundBuffer, GetSamplesCount(), 0)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sample rate of a sound buffer
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfSoundBuffer_GetSampleRate(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(sfSoundBuffer* SoundBuffer)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundBuffer, GetChannelsCount(), 0)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the duration of a sound buffer
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSoundBuffer_GetDuration(sfSoundBuffer* SoundBuffer)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundBuffer, GetDuration(), 0.f)
|
||||
}
|
104
CSFML/src/SFML/Audio/SoundBufferRecorder.cpp
Normal file
104
CSFML/src/SFML/Audio/SoundBufferRecorder.cpp
Normal file
|
@ -0,0 +1,104 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/SoundBufferRecorder.hpp>
|
||||
#include <SFML/Audio/SoundBuffer.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Audio/SoundBuffer.h
|
||||
struct sfSoundBuffer
|
||||
{
|
||||
sf::SoundBuffer This;
|
||||
};
|
||||
|
||||
struct sfSoundBufferRecorder
|
||||
{
|
||||
sf::SoundBufferRecorder This;
|
||||
sfSoundBuffer SoundBuffer;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new sound buffer recorder
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSoundBufferRecorder* sfSoundBufferRecorder_Create()
|
||||
{
|
||||
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(sfSoundBufferRecorder* SoundBufferRecorder)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundBufferRecorder, GetSampleRate(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sound buffer containing the captured audio data
|
||||
/// of a sound buffer recorder
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSoundBuffer* sfSoundBufferRecorder_GetBuffer(sfSoundBufferRecorder* SoundBufferRecorder)
|
||||
{
|
||||
CSFML_CHECK_RETURN(SoundBufferRecorder, NULL);
|
||||
|
||||
SoundBufferRecorder->SoundBuffer.This = SoundBufferRecorder->This.GetBuffer();
|
||||
|
||||
return &SoundBufferRecorder->SoundBuffer;
|
||||
}
|
150
CSFML/src/SFML/Audio/SoundRecorder.cpp
Normal file
150
CSFML/src/SFML/Audio/SoundRecorder.cpp
Normal file
|
@ -0,0 +1,150 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/SoundRecorder.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
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;
|
||||
};
|
||||
|
||||
|
||||
struct sfSoundRecorder
|
||||
{
|
||||
sfSoundRecorder(sfSoundRecorderStartCallback OnStart,
|
||||
sfSoundRecorderProcessCallback OnProcess,
|
||||
sfSoundRecorderStopCallback OnStop,
|
||||
void* UserData) :
|
||||
This(OnStart, OnProcess, OnStop, UserData)
|
||||
{
|
||||
}
|
||||
|
||||
sfSoundRecorderImpl This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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(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_CanCapture()
|
||||
{
|
||||
return sf::SoundRecorder::CanCapture() ? sfTrue : sfFalse;
|
||||
}
|
294
CSFML/src/SFML/Audio/SoundStream.cpp
Normal file
294
CSFML/src/SFML/Audio/SoundStream.cpp
Normal file
|
@ -0,0 +1,294 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/SoundStream.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
class sfSoundStreamImpl : public sf::SoundStream
|
||||
{
|
||||
public :
|
||||
|
||||
sfSoundStreamImpl(sfSoundStreamStartCallback OnStart,
|
||||
sfSoundStreamGetDataCallback OnGetData,
|
||||
unsigned int ChannelsCount,
|
||||
unsigned int SampleRate,
|
||||
void* UserData) :
|
||||
myStartCallback (OnStart),
|
||||
myGetDataCallback(OnGetData),
|
||||
myUserData (UserData)
|
||||
{
|
||||
Initialize(ChannelsCount, SampleRate);
|
||||
}
|
||||
|
||||
private :
|
||||
|
||||
virtual bool OnStart()
|
||||
{
|
||||
if (myStartCallback)
|
||||
return myStartCallback(myUserData) == sfTrue;
|
||||
else
|
||||
return true;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
sfSoundStreamStartCallback myStartCallback;
|
||||
sfSoundStreamGetDataCallback myGetDataCallback;
|
||||
void* myUserData;
|
||||
};
|
||||
|
||||
|
||||
struct sfSoundStream
|
||||
{
|
||||
|
||||
sfSoundStream(sfSoundStreamStartCallback OnStart,
|
||||
sfSoundStreamGetDataCallback OnGetData,
|
||||
unsigned int ChannelsCount,
|
||||
unsigned int SampleRate,
|
||||
void* UserData) :
|
||||
This(OnStart, OnGetData, ChannelsCount, SampleRate, UserData)
|
||||
{
|
||||
}
|
||||
|
||||
sfSoundStreamImpl This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new sound stream
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSoundStream* sfSoundStream_Create(sfSoundStreamStartCallback OnStart,
|
||||
sfSoundStreamGetDataCallback OnGetData,
|
||||
unsigned int ChannelsCount,
|
||||
unsigned int SampleRate,
|
||||
void* UserData)
|
||||
{
|
||||
return new sfSoundStream(OnStart, OnGetData, 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(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(sfSoundStream* SoundStream)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundStream, GetChannelsCount(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sample rate of a sound stream
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfSoundStream_GetSampleRate(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));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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 MinDistance)
|
||||
{
|
||||
CSFML_CALL(SoundStream, SetMinDistance(MinDistance));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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 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(sfSoundStream* SoundStream)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundStream, GetPitch(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the volume of a sound stream
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSoundStream_GetVolume(sfSoundStream* SoundStream)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundStream, GetVolume(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the position of a sound stream
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSoundStream_GetPosition(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;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the minimum distance of a sound stream
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSoundStream_GetMinDistance(sfSoundStream* SoundStream)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundStream, GetMinDistance(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the attenuation factor of a sound stream
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSoundStream_GetAttenuation(sfSoundStream* SoundStream)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundStream, GetAttenuation(), 0.f);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tell whether or not a stream is looping
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfSoundStream_GetLoop(sfSoundStream* SoundStream)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundStream, GetLoop(), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current playing position of a sound stream
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSoundStream_GetPlayingOffset(sfSoundStream* SoundStream)
|
||||
{
|
||||
CSFML_CALL_RETURN(SoundStream, GetPlayingOffset(), 0.f);
|
||||
}
|
96
CSFML/src/SFML/Graphics/Color.cpp
Normal file
96
CSFML/src/SFML/Graphics/Color.cpp
Normal file
|
@ -0,0 +1,96 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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 = { 0, 0, 0, 255};
|
||||
sfColor sfWhite = {255, 255, 255, 255};
|
||||
sfColor sfRed = {255, 0, 0, 255};
|
||||
sfColor sfGreen = { 0, 255, 0, 255};
|
||||
sfColor sfBlue = { 0, 0, 255, 255};
|
||||
sfColor sfYellow = {255, 255, 0, 255};
|
||||
sfColor sfMagenta = {255, 0, 255, 255};
|
||||
sfColor sfCyan = { 0, 255, 255, 255};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a color from its 3 RGB components
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfColor_FromRGB(sfUint8 R, sfUint8 G, sfUint8 B)
|
||||
{
|
||||
return sfColor_FromRGBA(R, G, B, 255);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a color from its 4 RGBA components
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfColor_FromRGBA(sfUint8 R, sfUint8 G, sfUint8 B, sfUint8 A)
|
||||
{
|
||||
sfColor Color;
|
||||
|
||||
Color.r = R;
|
||||
Color.g = G;
|
||||
Color.b = B;
|
||||
Color.a = A;
|
||||
|
||||
return Color;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Add two colors
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfColor_Add(sfColor Color1, sfColor Color2)
|
||||
{
|
||||
int R = std::min(Color1.r + Color2.r, 255);
|
||||
int G = std::min(Color1.g + Color2.g, 255);
|
||||
int B = std::min(Color1.b + Color2.b, 255);
|
||||
int A = std::min(Color1.a + Color2.a, 255);
|
||||
|
||||
return sfColor_FromRGBA(static_cast<sfUint8>(R), static_cast<sfUint8>(G), static_cast<sfUint8>(B), static_cast<sfUint8>(A));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Modulate two colors
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfColor_Modulate(sfColor Color1, sfColor Color2)
|
||||
{
|
||||
int R = Color1.r * Color2.r / 255;
|
||||
int G = Color1.g * Color2.g / 255;
|
||||
int B = Color1.b * Color2.b / 255;
|
||||
int A = Color1.a * Color2.a / 255;
|
||||
|
||||
return sfColor_FromRGBA(static_cast<sfUint8>(R), static_cast<sfUint8>(G), static_cast<sfUint8>(B), static_cast<sfUint8>(A));
|
||||
}
|
121
CSFML/src/SFML/Graphics/Font.cpp
Normal file
121
CSFML/src/SFML/Graphics/Font.cpp
Normal file
|
@ -0,0 +1,121 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Font.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfFont
|
||||
{
|
||||
sf::Font This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new empty font
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFont* sfFont_Create()
|
||||
{
|
||||
return new sfFont;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new font from a file
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFont* sfFont_CreateFromFile(const char* Filename, unsigned int CharSize, const sfUint32* Charset)
|
||||
{
|
||||
sfFont* Font = new sfFont;
|
||||
|
||||
bool bSucceeded = false;
|
||||
if (Charset)
|
||||
bSucceeded = Font->This.LoadFromFile(Filename, CharSize, Charset);
|
||||
else
|
||||
bSucceeded = Font->This.LoadFromFile(Filename, CharSize);
|
||||
|
||||
if (!bSucceeded)
|
||||
{
|
||||
delete Font;
|
||||
Font = NULL;
|
||||
}
|
||||
|
||||
return Font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new font from a file in memory
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFont* sfFont_CreateFromMemory(const char* Data, size_t SizeInBytes, unsigned int CharSize, const sfUint32* Charset)
|
||||
{
|
||||
sfFont* Font = new sfFont;
|
||||
|
||||
bool bSucceeded = false;
|
||||
if (Charset)
|
||||
bSucceeded = Font->This.LoadFromMemory(Data, SizeInBytes, CharSize, Charset);
|
||||
else
|
||||
bSucceeded = Font->This.LoadFromMemory(Data, SizeInBytes, CharSize);
|
||||
|
||||
if (!bSucceeded)
|
||||
{
|
||||
delete Font;
|
||||
Font = NULL;
|
||||
}
|
||||
|
||||
return Font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing font
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfFont_Destroy(sfFont* Font)
|
||||
{
|
||||
delete Font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the base size of characters in a font;
|
||||
/// All glyphs dimensions are based on this value
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfFont_GetCharacterSize(sfFont* Font)
|
||||
{
|
||||
CSFML_CALL_RETURN(Font, GetCharacterSize(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the built-in default font (Arial)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFont* sfFont_GetDefaultFont()
|
||||
{
|
||||
static sfFont DefaultFont = {sf::Font::GetDefaultFont()};
|
||||
|
||||
return &DefaultFont;
|
||||
}
|
268
CSFML/src/SFML/Graphics/Image.cpp
Normal file
268
CSFML/src/SFML/Graphics/Image.cpp
Normal file
|
@ -0,0 +1,268 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Image.hpp>
|
||||
#include <SFML/Graphics/RenderWindow.hpp>
|
||||
#include <SFML/Window/Input.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Window/Input.h
|
||||
struct sfInput
|
||||
{
|
||||
const sf::Input* This;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Graphics/View.h
|
||||
struct sfView
|
||||
{
|
||||
sf::View* This;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Graphics/RenderWindow.h
|
||||
struct sfRenderWindow
|
||||
{
|
||||
sf::RenderWindow This;
|
||||
sfInput Input;
|
||||
sfView DefaultView;
|
||||
sfView* CurrentView;
|
||||
};
|
||||
|
||||
struct sfImage
|
||||
{
|
||||
sf::Image This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new empty image
|
||||
////////////////////////////////////////////////////////////
|
||||
sfImage* sfImage_Create()
|
||||
{
|
||||
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 char* Data, size_t SizeInBytes)
|
||||
{
|
||||
sfImage* Image = new sfImage;
|
||||
|
||||
if (!Image->This.LoadFromMemory(Data, SizeInBytes))
|
||||
{
|
||||
delete Image;
|
||||
Image = NULL;
|
||||
}
|
||||
|
||||
return Image;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing image
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfImage_Destroy(sfImage* Image)
|
||||
{
|
||||
delete Image;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Save the content of an image to a file
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfImage_SaveToFile(sfImage* Image, const char* Filename)
|
||||
{
|
||||
CSFML_CALL_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(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_Copy(sfImage* Image, sfImage* Source, unsigned int DestX, unsigned int DestY, sfIntRect SourceRect)
|
||||
{
|
||||
CSFML_CHECK(Source);
|
||||
sf::IntRect SFMLRect(SourceRect.Left, SourceRect.Top, SourceRect.Right, SourceRect.Bottom);
|
||||
CSFML_CALL(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.Right, SourceRect.Bottom);
|
||||
CSFML_CALL_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(Image, SetPixel(X, Y, SFMLColor));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a pixel from an image
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfImage_GetPixel(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(sfImage* Image)
|
||||
{
|
||||
CSFML_CALL_RETURN(Image, GetPixelsPtr(), NULL);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Bind the image for rendering
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfImage_Bind(sfImage* Image)
|
||||
{
|
||||
CSFML_CALL(Image, Bind());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Enable or disable image smooth filter
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfImage_SetSmooth(sfImage* Image, sfBool Smooth)
|
||||
{
|
||||
CSFML_CALL(Image, SetSmooth(Smooth == sfTrue));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the width of the image
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfImage_GetWidth(sfImage* Image)
|
||||
{
|
||||
CSFML_CALL_RETURN(Image, GetWidth(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the height of the image
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfImage_GetHeight(sfImage* Image)
|
||||
{
|
||||
CSFML_CALL_RETURN(Image, GetHeight(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tells whether the smoothing filter is enabled or not on an image
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfImage_IsSmooth(sfImage* Image)
|
||||
{
|
||||
CSFML_CALL_RETURN(Image, IsSmooth(), sfFalse);
|
||||
}
|
23
CSFML/src/SFML/Graphics/Makefile
Normal file
23
CSFML/src/SFML/Graphics/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
LIB = libcsfml-graphics.so
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
LIBNAME = $(LIBPATH)/$(LIB).$(VERSION)
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
libcsfml-graphics.so: $(OBJ)
|
||||
$(CPP) $(LDFLAGS) -Wl,-soname,$(LIB).$(VERSION) -o $(LIBNAME) $(OBJ) -lsfml-graphics -lsfml-window -lsfml-system
|
||||
|
||||
$(OBJ): %.o: %.cpp
|
||||
$(CPP) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
@rm -rf $(LIBNAME)
|
||||
|
||||
install:
|
||||
@($(CP) $(LIBNAME) $(DESTLIBDIR) && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB))
|
138
CSFML/src/SFML/Graphics/PostFX.cpp
Normal file
138
CSFML/src/SFML/Graphics/PostFX.cpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/PostFX.h>
|
||||
#include <SFML/Graphics/PostFX.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Graphics/Image.h
|
||||
struct sfImage
|
||||
{
|
||||
sf::Image This;
|
||||
};
|
||||
struct sfPostFX
|
||||
{
|
||||
sf::PostFX This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new post-fx from a file
|
||||
////////////////////////////////////////////////////////////
|
||||
sfPostFX* sfPostFX_CreateFromFile(const char* Filename)
|
||||
{
|
||||
sfPostFX* PostFX = new sfPostFX;
|
||||
|
||||
if (!PostFX->This.LoadFromFile(Filename))
|
||||
{
|
||||
delete PostFX;
|
||||
PostFX = NULL;
|
||||
}
|
||||
|
||||
return PostFX;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new post-fx from an effect source code
|
||||
////////////////////////////////////////////////////////////
|
||||
sfPostFX* sfPostFX_CreateFromMemory(const char* Effect)
|
||||
{
|
||||
sfPostFX* PostFX = new sfPostFX;
|
||||
|
||||
if (!PostFX->This.LoadFromMemory(Effect))
|
||||
{
|
||||
delete PostFX;
|
||||
PostFX = NULL;
|
||||
}
|
||||
|
||||
return PostFX;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing post-fx
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPostFX_Destroy(sfPostFX* PostFX)
|
||||
{
|
||||
delete PostFX;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change a parameter of a post-fx (1 float)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPostFX_SetParameter1(sfPostFX* PostFX, const char* Name, float X)
|
||||
{
|
||||
CSFML_CALL(PostFX, SetParameter(Name, X))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change a parameter of a post-fx (2 floats)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPostFX_SetParameter2(sfPostFX* PostFX, const char* Name, float X, float Y)
|
||||
{
|
||||
CSFML_CALL(PostFX, SetParameter(Name, X, Y))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change a parameter of a post-fx (3 floats)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPostFX_SetParameter3(sfPostFX* PostFX, const char* Name, float X, float Y, float Z)
|
||||
{
|
||||
CSFML_CALL(PostFX, SetParameter(Name, X, Y, Z))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change a parameter of a post-fx (4 floats)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPostFX_SetParameter4(sfPostFX* PostFX, const char* Name, float X, float Y, float Z, float W)
|
||||
{
|
||||
CSFML_CALL(PostFX, SetParameter(Name, X, Y, Z, W))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set a texture parameter in a post-fx
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPostFX_SetTexture(sfPostFX* PostFX, const char* Name, sfImage* Texture)
|
||||
{
|
||||
CSFML_CALL(PostFX, SetTexture(Name, Texture ? &Texture->This : NULL))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tell whether or not the system supports post-effects
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfPostFX_CanUsePostFX()
|
||||
{
|
||||
return sf::PostFX::CanUsePostFX() ? sfTrue : sfFalse;
|
||||
}
|
121
CSFML/src/SFML/Graphics/Rect.cpp
Normal file
121
CSFML/src/SFML/Graphics/Rect.cpp
Normal file
|
@ -0,0 +1,121 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Move a rectangle by the given offset
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfFloatRect_Offset(sfFloatRect* Rect, float OffsetX, float OffsetY)
|
||||
{
|
||||
CSFML_CHECK(Rect)
|
||||
Rect->Left += OffsetX;
|
||||
Rect->Right += OffsetX;
|
||||
Rect->Top += OffsetY;
|
||||
Rect->Bottom += OffsetY;
|
||||
}
|
||||
void sfIntRect_Offset(sfIntRect* Rect, int OffsetX, int OffsetY)
|
||||
{
|
||||
CSFML_CHECK(Rect)
|
||||
Rect->Left += OffsetX;
|
||||
Rect->Right += OffsetX;
|
||||
Rect->Top += OffsetY;
|
||||
Rect->Bottom += OffsetY;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check if a point is inside a rectangle's area
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfFloatRect_Contains(sfFloatRect* Rect, float X, float Y)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Rect, sfFalse)
|
||||
return sf::FloatRect(Rect->Left, Rect->Top, Rect->Right, Rect->Bottom).Contains(X, Y);
|
||||
}
|
||||
sfBool sfIntRect_Contains(sfIntRect* Rect, int X, int Y)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Rect, sfFalse)
|
||||
return sf::IntRect(Rect->Left, Rect->Top, Rect->Right, Rect->Bottom).Contains(X, Y);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check intersection between two rectangles
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfFloatRect_Intersects(sfFloatRect* Rect1, sfFloatRect* Rect2, sfFloatRect* OverlappingRect)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Rect1, sfFalse)
|
||||
CSFML_CHECK_RETURN(Rect2, sfFalse)
|
||||
|
||||
sf::FloatRect SFMLRect1(Rect1->Left, Rect1->Top, Rect1->Right, Rect1->Bottom);
|
||||
sf::FloatRect SFMLRect2(Rect2->Left, Rect2->Top, Rect2->Right, Rect2->Bottom);
|
||||
|
||||
if (OverlappingRect)
|
||||
{
|
||||
sf::FloatRect Overlap;
|
||||
bool Intersect = SFMLRect1.Intersects(SFMLRect2, &Overlap);
|
||||
|
||||
OverlappingRect->Left = Overlap.Left;
|
||||
OverlappingRect->Top = Overlap.Top;
|
||||
OverlappingRect->Right = Overlap.Right;
|
||||
OverlappingRect->Bottom = Overlap.Bottom;
|
||||
|
||||
return Intersect;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SFMLRect1.Intersects(SFMLRect2);
|
||||
}
|
||||
}
|
||||
sfBool sfIntRect_Intersects(sfIntRect* Rect1, sfIntRect* Rect2, sfIntRect* OverlappingRect)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Rect1, sfFalse)
|
||||
CSFML_CHECK_RETURN(Rect2, sfFalse)
|
||||
|
||||
sf::IntRect SFMLRect1(Rect1->Left, Rect1->Top, Rect1->Right, Rect1->Bottom);
|
||||
sf::IntRect SFMLRect2(Rect2->Left, Rect2->Top, Rect2->Right, Rect2->Bottom);
|
||||
|
||||
if (OverlappingRect)
|
||||
{
|
||||
sf::IntRect Overlap;
|
||||
bool Intersect = SFMLRect1.Intersects(SFMLRect2, &Overlap);
|
||||
|
||||
OverlappingRect->Left = Overlap.Left;
|
||||
OverlappingRect->Top = Overlap.Top;
|
||||
OverlappingRect->Right = Overlap.Right;
|
||||
OverlappingRect->Bottom = Overlap.Bottom;
|
||||
|
||||
return Intersect;
|
||||
}
|
||||
else
|
||||
{
|
||||
return SFMLRect1.Intersects(SFMLRect2);
|
||||
}
|
||||
}
|
497
CSFML/src/SFML/Graphics/RenderWindow.cpp
Normal file
497
CSFML/src/SFML/Graphics/RenderWindow.cpp
Normal file
|
@ -0,0 +1,497 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/RenderWindow.hpp>
|
||||
#include <SFML/Graphics/Shape.hpp>
|
||||
#include <SFML/Graphics/PostFX.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Graphics/Sprite.hpp>
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
#include <SFML/Graphics/View.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Graphics/PostFX.h
|
||||
struct sfPostFX
|
||||
{
|
||||
sf::PostFX This;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Graphics/Shape.h
|
||||
struct sfShape
|
||||
{
|
||||
sf::Shape This;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Graphics/Sprite.h
|
||||
struct sfSprite
|
||||
{
|
||||
sf::Sprite This;
|
||||
sfImage* Image;
|
||||
sfIntRect SubRect;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Graphics/String.h
|
||||
struct sfString
|
||||
{
|
||||
sf::String This;
|
||||
std::string Text;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Graphics/Image.h
|
||||
struct sfImage
|
||||
{
|
||||
sf::Image This;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Window/Input.h
|
||||
struct sfInput
|
||||
{
|
||||
const sf::Input* This;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Graphics/View.h
|
||||
struct sfView
|
||||
{
|
||||
sf::View* This;
|
||||
};
|
||||
struct sfRenderWindow
|
||||
{
|
||||
sf::RenderWindow This;
|
||||
sfInput Input;
|
||||
sfView DefaultView;
|
||||
sfView* CurrentView;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new renderwindow
|
||||
////////////////////////////////////////////////////////////
|
||||
sfRenderWindow* sfRenderWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfWindowSettings Params)
|
||||
{
|
||||
// Convert video mode
|
||||
sf::VideoMode VideoMode(Mode.Width, Mode.Height, Mode.BitsPerPixel);
|
||||
|
||||
// Create the window
|
||||
sfRenderWindow* RenderWindow = new sfRenderWindow;
|
||||
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
|
||||
RenderWindow->This.Create(VideoMode, Title, Style, Settings);
|
||||
RenderWindow->Input.This = &RenderWindow->This.GetInput();
|
||||
RenderWindow->DefaultView.This = &RenderWindow->This.GetDefaultView();
|
||||
RenderWindow->CurrentView = &RenderWindow->DefaultView;
|
||||
|
||||
return RenderWindow;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a renderwindow from an existing control
|
||||
////////////////////////////////////////////////////////////
|
||||
sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle Handle, sfWindowSettings Params)
|
||||
{
|
||||
sfRenderWindow* RenderWindow = new sfRenderWindow;
|
||||
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
|
||||
RenderWindow->This.Create(Handle, Settings);
|
||||
RenderWindow->Input.This = &RenderWindow->This.GetInput();
|
||||
RenderWindow->DefaultView.This = &RenderWindow->This.GetDefaultView();
|
||||
RenderWindow->CurrentView = &RenderWindow->DefaultView;
|
||||
|
||||
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(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
CSFML_CALL_RETURN(RenderWindow, IsOpened(), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the width of the rendering region of a window
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfRenderWindow_GetWidth(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
CSFML_CALL_RETURN(RenderWindow, GetWidth(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the height of the rendering region of a window
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfRenderWindow_GetHeight(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
CSFML_CALL_RETURN(RenderWindow, GetHeight(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the creation settings of a window
|
||||
////////////////////////////////////////////////////////////
|
||||
sfWindowSettings sfRenderWindow_GetSettings(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
sfWindowSettings Settings = {0, 0, 0};
|
||||
CSFML_CHECK_RETURN(RenderWindow, Settings);
|
||||
|
||||
const sf::WindowSettings& 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 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;
|
||||
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;
|
||||
}
|
||||
|
||||
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 State)
|
||||
{
|
||||
CSFML_CALL(RenderWindow, Show(State == 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, 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)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Display a window on screen
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfRenderWindow_Display(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
CSFML_CALL(RenderWindow, Display());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the input manager of a window
|
||||
////////////////////////////////////////////////////////////
|
||||
sfInput* sfRenderWindow_GetInput(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(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));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Draw something on a renderwindow
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfRenderWindow_DrawPostFX(sfRenderWindow* RenderWindow, sfPostFX* PostFX)
|
||||
{
|
||||
CSFML_CHECK(PostFX);
|
||||
CSFML_CALL(RenderWindow, Draw(PostFX->This));
|
||||
}
|
||||
void sfRenderWindow_DrawShape(sfRenderWindow* RenderWindow, sfShape* Shape)
|
||||
{
|
||||
CSFML_CHECK(Shape);
|
||||
CSFML_CALL(RenderWindow, Draw(Shape->This));
|
||||
}
|
||||
void sfRenderWindow_DrawSprite(sfRenderWindow* RenderWindow, sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CHECK(Sprite);
|
||||
CSFML_CALL(RenderWindow, Draw(Sprite->This));
|
||||
}
|
||||
void sfRenderWindow_DrawString(sfRenderWindow* RenderWindow, sfString* String)
|
||||
{
|
||||
CSFML_CHECK(String);
|
||||
CSFML_CALL(RenderWindow, Draw(String->This));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Save the content of a renderwindow to an image
|
||||
////////////////////////////////////////////////////////////
|
||||
sfImage* sfRenderWindow_Capture(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
CSFML_CHECK_RETURN(RenderWindow, NULL);
|
||||
|
||||
sfImage* Image = new sfImage;
|
||||
Image->This = RenderWindow->This.Capture();
|
||||
|
||||
return Image;
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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, sfView* View)
|
||||
{
|
||||
CSFML_CHECK(View);
|
||||
CSFML_CALL(RenderWindow, SetView(*View->This));
|
||||
RenderWindow->CurrentView = View;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current active view of a renderwindow
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfView* sfRenderWindow_GetView(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
CSFML_CHECK_RETURN(RenderWindow, NULL);
|
||||
|
||||
return RenderWindow->CurrentView;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the default view of a renderwindow
|
||||
////////////////////////////////////////////////////////////
|
||||
sfView* sfRenderWindow_GetDefaultView(sfRenderWindow* RenderWindow)
|
||||
{
|
||||
CSFML_CHECK_RETURN(RenderWindow, NULL);
|
||||
|
||||
return &RenderWindow->DefaultView;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Convert a point in window coordinates into view coordinates
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfRenderWindow_ConvertCoords(sfRenderWindow* RenderWindow, unsigned int WindowX, unsigned int WindowY, float* ViewX, float* ViewY, sfView* TargetView)
|
||||
{
|
||||
CSFML_CHECK(RenderWindow);
|
||||
|
||||
sf::Vector2f Point = RenderWindow->This.ConvertCoords(WindowX, WindowY, TargetView ? TargetView->This : NULL);
|
||||
|
||||
if (ViewX) *ViewX = Point.x;
|
||||
if (ViewY) *ViewY = Point.y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tell SFML to preserve external OpenGL states, at the expense of
|
||||
/// more CPU charge. Use this function if you don't want SFML
|
||||
/// to mess up your own OpenGL states (if any).
|
||||
/// Don't enable state preservation if not needed, as it will allow
|
||||
/// SFML to do internal optimizations and improve performances.
|
||||
/// This parameter is false by default
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfRenderWindow_PreserveOpenGLStates(sfRenderWindow* RenderWindow, sfBool Preserve)
|
||||
{
|
||||
CSFML_CALL(RenderWindow, PreserveOpenGLStates(Preserve == sfTrue));
|
||||
}
|
464
CSFML/src/SFML/Graphics/Shape.cpp
Normal file
464
CSFML/src/SFML/Graphics/Shape.cpp
Normal file
|
@ -0,0 +1,464 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Shape.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfShape
|
||||
{
|
||||
sf::Shape This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new shape
|
||||
////////////////////////////////////////////////////////////
|
||||
sfShape* sfShape_Create()
|
||||
{
|
||||
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 Col, float Outline, sfColor OutlineCol)
|
||||
{
|
||||
sf::Color Color(Col.r, Col.g, Col.b, Col.a);
|
||||
sf::Color OutlineColor(OutlineCol.r, OutlineCol.g, OutlineCol.b, OutlineCol.a);
|
||||
|
||||
sfShape* Shape = new sfShape;
|
||||
Shape->This = sf::Shape::Line(P1X, P1Y, P2X, P2Y, Thickness, Color, Outline, OutlineColor);
|
||||
return Shape;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new shape made of a single rectangle
|
||||
////////////////////////////////////////////////////////////
|
||||
sfShape* sfShape_CreateRectangle(float P1X, float P1Y, float P2X, float P2Y, sfColor Col, float Outline, sfColor OutlineCol)
|
||||
{
|
||||
sf::Color Color(Col.r, Col.g, Col.b, Col.a);
|
||||
sf::Color OutlineColor(OutlineCol.r, OutlineCol.g, OutlineCol.b, OutlineCol.a);
|
||||
|
||||
sfShape* Shape = new sfShape;
|
||||
Shape->This = sf::Shape::Rectangle(P1X, P1Y, P2X, P2Y, Color, Outline, OutlineColor);
|
||||
return Shape;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new shape made of a single circle
|
||||
////////////////////////////////////////////////////////////
|
||||
sfShape* sfShape_CreateCircle(float X, float Y, float Radius, sfColor Col, float Outline, sfColor OutlineCol)
|
||||
{
|
||||
sf::Color Color(Col.r, Col.g, Col.b, Col.a);
|
||||
sf::Color OutlineColor(OutlineCol.r, OutlineCol.g, OutlineCol.b, OutlineCol.a);
|
||||
|
||||
sfShape* Shape = new sfShape;
|
||||
Shape->This = sf::Shape::Circle(X, Y, Radius, Color, Outline, OutlineColor);
|
||||
return 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 center of a shape, in coordinates
|
||||
/// relative to its left-top corner
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfShape_SetCenter(sfShape* Shape, float X, float Y)
|
||||
{
|
||||
CSFML_CALL(Shape, SetCenter(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(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetPosition().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the Y position of a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfShape_GetY(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetPosition().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the horizontal scale of a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfShape_GetScaleX(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetScale().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the vertical scale of a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfShape_GetScaleY(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetScale().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the orientation of a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfShape_GetRotation(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetRotation(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of the center a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfShape_GetCenterX(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetCenter().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the Y position of the center a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfShape_GetCenterY(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetCenter().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the color of a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfShape_GetColor(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(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 center, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfShape_TransformToLocal(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 center, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfShape_TransformToGlobal(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 Col, sfColor OutlineCol)
|
||||
{
|
||||
sf::Color Color(Col.r, Col.g, Col.b, Col.a);
|
||||
sf::Color OutlineColor(OutlineCol.r, OutlineCol.g, OutlineCol.b, OutlineCol.a);
|
||||
|
||||
CSFML_CALL(Shape, AddPoint(X, Y, Color, OutlineColor))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetOutlineWidth(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the number of points composing a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfShape_GetNbPoints(sfShape* Shape)
|
||||
{
|
||||
CSFML_CALL_RETURN(Shape, GetNbPoints(), 0)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a point of a shape
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfShape_GetPointPosition(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(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(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)));
|
||||
}
|
407
CSFML/src/SFML/Graphics/Sprite.cpp
Normal file
407
CSFML/src/SFML/Graphics/Sprite.cpp
Normal file
|
@ -0,0 +1,407 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Sprite.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Image.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Graphics/Image.h
|
||||
struct sfImage
|
||||
{
|
||||
sf::Image This;
|
||||
};
|
||||
struct sfSprite
|
||||
{
|
||||
sf::Sprite This;
|
||||
sfImage* Image;
|
||||
sfIntRect SubRect;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSprite* sfSprite_Create()
|
||||
{
|
||||
sfSprite* Sprite = new sfSprite;
|
||||
Sprite->Image = NULL;
|
||||
Sprite->SubRect.Left = Sprite->This.GetSubRect().Left;
|
||||
Sprite->SubRect.Top = Sprite->This.GetSubRect().Top;
|
||||
Sprite->SubRect.Right = Sprite->This.GetSubRect().Right;
|
||||
Sprite->SubRect.Bottom = Sprite->This.GetSubRect().Bottom;
|
||||
|
||||
return 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 center of a sprite, in coordinates
|
||||
/// relative to its left-top corner
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSprite_SetCenter(sfSprite* Sprite, float X, float Y)
|
||||
{
|
||||
CSFML_CALL(Sprite, SetCenter(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(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetPosition().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the Y position of a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetY(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetPosition().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the horizontal scale of a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetScaleX(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetScale().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the vertical scale of a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetScaleY(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetScale().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the orientation of a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetRotation(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetRotation(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of the center a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetCenterX(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetCenter().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the Y position of the center a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetCenterY(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetCenter().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the color of a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfSprite_GetColor(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(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 center, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSprite_TransformToLocal(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 center, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSprite_TransformToGlobal(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, sfImage* Image)
|
||||
{
|
||||
if (Image)
|
||||
{
|
||||
CSFML_CALL(Sprite, SetImage(Image->This))
|
||||
Sprite->Image = Image;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the sub-rectangle of a sprite inside the source image
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSprite_SetSubRect(sfSprite* Sprite, sfIntRect SubRect)
|
||||
{
|
||||
CSFML_CALL(Sprite, SetSubRect(sf::IntRect(SubRect.Left, SubRect.Top, SubRect.Right, SubRect.Bottom)))
|
||||
Sprite->SubRect = SubRect;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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
|
||||
////////////////////////////////////////////////////////////
|
||||
sfImage* sfSprite_GetImage(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Sprite, NULL)
|
||||
|
||||
return Sprite->Image;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the sub-rectangle of a sprite inside the source image
|
||||
////////////////////////////////////////////////////////////
|
||||
sfIntRect sfSprite_GetSubRect(sfSprite* Sprite)
|
||||
{
|
||||
sfIntRect Rect = {0, 0, 0, 0};
|
||||
CSFML_CHECK_RETURN(Sprite, Rect)
|
||||
|
||||
return Sprite->SubRect;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a sprite width
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetWidth(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetSize().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a sprite height
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfSprite_GetHeight(sfSprite* Sprite)
|
||||
{
|
||||
CSFML_CALL_RETURN(Sprite, GetSize().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the color of a given pixel in a sprite
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfSprite_GetPixel(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);
|
||||
}
|
436
CSFML/src/SFML/Graphics/String.cpp
Normal file
436
CSFML/src/SFML/Graphics/String.cpp
Normal file
|
@ -0,0 +1,436 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/String.h>
|
||||
#include <SFML/Graphics/String.hpp>
|
||||
#include <SFML/Graphics/Color.hpp>
|
||||
#include <SFML/Graphics/Rect.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Graphics/Font.h
|
||||
struct sfFont
|
||||
{
|
||||
sf::Font This;
|
||||
};
|
||||
|
||||
struct sfString
|
||||
{
|
||||
sf::String This;
|
||||
std::string Text;
|
||||
sfFont* Font;
|
||||
sfFloatRect Rect;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new string
|
||||
////////////////////////////////////////////////////////////
|
||||
sfString* sfString_Create()
|
||||
{
|
||||
sfString* String = new sfString;
|
||||
String->Font = sfFont_GetDefaultFont();
|
||||
|
||||
return String;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Destroy(sfString* String)
|
||||
{
|
||||
delete String;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the X position of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetX(sfString* String, float X)
|
||||
{
|
||||
CSFML_CALL(String, SetX(X))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the Y position of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetY(sfString* String, float Y)
|
||||
{
|
||||
CSFML_CALL(String, SetY(Y))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the position of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetPosition(sfString* String, float X, float Y)
|
||||
{
|
||||
CSFML_CALL(String, SetPosition(sf::Vector2f(X, Y)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the horizontal scale of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetScaleX(sfString* String, float Scale)
|
||||
{
|
||||
CSFML_CALL(String, SetScaleX(Scale))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the vertical scale of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetScaleY(sfString* String, float Scale)
|
||||
{
|
||||
CSFML_CALL(String, SetScaleY(Scale))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the scale of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetScale(sfString* String, float ScaleX, float ScaleY)
|
||||
{
|
||||
CSFML_CALL(String, SetScale(sf::Vector2f(ScaleX, ScaleY)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the orientation of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetRotation(sfString* String, float Rotation)
|
||||
{
|
||||
CSFML_CALL(String, SetRotation(Rotation))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the center of a string, in coordinates
|
||||
/// relative to its left-top corner
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetCenter(sfString* String, float X, float Y)
|
||||
{
|
||||
CSFML_CALL(String, SetCenter(sf::Vector2f(X, Y)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the color of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetColor(sfString* String, sfColor Color)
|
||||
{
|
||||
CSFML_CALL(String, SetColor(sf::Color(Color.r, Color.g, Color.b, Color.a)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the blending mode for a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetBlendMode(sfString* String, sfBlendMode Mode)
|
||||
{
|
||||
CSFML_CALL(String, SetBlendMode(static_cast<sf::Blend::Mode>(Mode)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetX(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetPosition().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the Y position of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetY(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetPosition().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the horizontal scale of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetScaleX(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetScale().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the vertical scale of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetScaleY(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetScale().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the orientation of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetRotation(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetRotation(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X position of the center a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetCenterX(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetCenter().x, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the top Y of the center of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetCenterY(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetCenter().y, 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the color of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
sfColor sfString_GetColor(sfString* String)
|
||||
{
|
||||
sfColor Color = {0, 0, 0, 0};
|
||||
CSFML_CHECK_RETURN(String, Color)
|
||||
|
||||
sf::Color SFMLColor = String->This.GetColor();
|
||||
return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the current blending mode of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBlendMode sfString_GetBlendMode(sfString* String)
|
||||
{
|
||||
CSFML_CHECK_RETURN(String, sfBlendNone)
|
||||
|
||||
return static_cast<sfBlendMode>(String->This.GetBlendMode());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Move a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Move(sfString* String, float OffsetX, float OffsetY)
|
||||
{
|
||||
CSFML_CALL(String, Move(sf::Vector2f(OffsetX, OffsetY)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Scale a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Scale(sfString* String, float FactorX, float FactorY)
|
||||
{
|
||||
CSFML_CALL(String, Scale(sf::Vector2f(FactorX, FactorY)))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Rotate a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_Rotate(sfString* String, float Angle)
|
||||
{
|
||||
CSFML_CALL(String, Rotate(Angle))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Transform a point from global coordinates into the string's local coordinates
|
||||
/// (ie it applies the inverse of object's center, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_TransformToLocal(sfString* String, float PointX, float PointY, float* X, float* Y)
|
||||
{
|
||||
CSFML_CHECK(String)
|
||||
|
||||
sf::Vector2f Point = String->This.TransformToLocal(sf::Vector2f(PointX, PointY));
|
||||
if (X) *X = Point.x;
|
||||
if (Y) *Y = Point.y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Transform a point from the string's local coordinates into global coordinates
|
||||
/// (ie it applies the object's center, translation, rotation and scale to the point)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_TransformToGlobal(sfString* String, float PointX, float PointY, float* X, float* Y)
|
||||
{
|
||||
CSFML_CHECK(String)
|
||||
|
||||
sf::Vector2f Point = String->This.TransformToGlobal(sf::Vector2f(PointX, PointY));
|
||||
if (X) *X = Point.x;
|
||||
if (Y) *Y = Point.y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text of a string (from a multibyte string)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetText(sfString* String, const char* Text)
|
||||
{
|
||||
CSFML_CALL(String, SetText(Text))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the text of a string (from a unicode string)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetUnicodeText(sfString* String, const sfUint32* Text)
|
||||
{
|
||||
sf::Unicode::UTF32String UTF32Text = Text;
|
||||
CSFML_CALL(String, SetText(UTF32Text))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the font of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetFont(sfString* String, sfFont* Font)
|
||||
{
|
||||
CSFML_CHECK(Font);
|
||||
|
||||
CSFML_CALL(String, SetFont(Font->This))
|
||||
String->Font = Font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the size of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetSize(sfString* String, float Size)
|
||||
{
|
||||
CSFML_CALL(String, SetSize(Size))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Set the style of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_SetStyle(sfString* String, unsigned long Style)
|
||||
{
|
||||
CSFML_CALL(String, SetStyle(Style))
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the text of a string (returns a unicode string)
|
||||
////////////////////////////////////////////////////////////
|
||||
const sfUint32* sfString_GetUnicodeText(sfString* String)
|
||||
{
|
||||
CSFML_CHECK_RETURN(String, NULL)
|
||||
|
||||
return static_cast<const sf::Unicode::UTF32String&>(String->This.GetText()).c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the text of a string (returns an ANSI string)
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfString_GetText(sfString* String)
|
||||
{
|
||||
CSFML_CHECK_RETURN(String, NULL)
|
||||
|
||||
String->Text = String->This.GetText();
|
||||
|
||||
return String->Text.c_str();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the font used by a string
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFont* sfString_GetFont(sfString* String)
|
||||
{
|
||||
CSFML_CHECK_RETURN(String, NULL)
|
||||
|
||||
return String->Font;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the size of the characters of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfString_GetSize(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetSize(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the style of a string
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned long sfString_GetStyle(sfString* String)
|
||||
{
|
||||
CSFML_CALL_RETURN(String, GetStyle(), 0)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Return the visual position of the Index-th character of the string,
|
||||
/// in coordinates relative to the string
|
||||
/// (note : translation, center, rotation and scale are not applied)
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfString_GetCharacterPos(sfString* String, size_t Index, float* X, float* Y)
|
||||
{
|
||||
CSFML_CHECK(String);
|
||||
|
||||
sf::Vector2f Pos = String->This.GetCharacterPos(Index);
|
||||
if (X) *X = Pos.x;
|
||||
if (Y) *Y = Pos.y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the bounding rectangle of a string on screen
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFloatRect sfString_GetRect(sfString* String)
|
||||
{
|
||||
sfFloatRect Rect = {0.f, 0.f, 0.f, 0.f};
|
||||
CSFML_CHECK_RETURN(String, Rect)
|
||||
|
||||
sf::FloatRect SFMLRect = String->This.GetRect();
|
||||
String->Rect.Left = SFMLRect.Left;
|
||||
String->Rect.Top = SFMLRect.Top;
|
||||
String->Rect.Right = SFMLRect.Right;
|
||||
String->Rect.Bottom = SFMLRect.Bottom;
|
||||
|
||||
return String->Rect;
|
||||
}
|
175
CSFML/src/SFML/Graphics/View.cpp
Normal file
175
CSFML/src/SFML/Graphics/View.cpp
Normal file
|
@ -0,0 +1,175 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/View.hpp>
|
||||
#include <SFML/Graphics/Rect.h>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfView
|
||||
{
|
||||
sfView() : This(new sf::View) {}
|
||||
sfView(sfFloatRect Rect) : This(new sf::View(sf::FloatRect(Rect.Left, Rect.Top, Rect.Right, Rect.Bottom))) {}
|
||||
~sfView() {delete This;}
|
||||
|
||||
sf::View* This; // pointer needed for RenderView
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a default view (1000x1000)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfView* sfView_Create()
|
||||
{
|
||||
return new sfView;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a view from a rectangle
|
||||
////////////////////////////////////////////////////////////
|
||||
sfView* sfView_CreateFromRect(sfFloatRect Rect)
|
||||
{
|
||||
return new sfView(Rect);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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_PTR(View, SetCenter(X, Y));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the half-size of a view
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfView_SetHalfSize(sfView* View, float HalfWidth, float HalfHeight)
|
||||
{
|
||||
CSFML_CALL_PTR(View, SetHalfSize(HalfWidth, HalfHeight));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Rebuild a view from a rectangle
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfView_SetFromRect(sfView* View, sfFloatRect ViewRect)
|
||||
{
|
||||
CSFML_CALL_PTR(View, SetFromRect(sf::FloatRect(ViewRect.Left, ViewRect.Top, ViewRect.Right, ViewRect.Bottom)));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the X coordinate of the center of a view
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfView_GetCenterX(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(sfView* View)
|
||||
{
|
||||
CSFML_CHECK_RETURN(View, 0.f);
|
||||
|
||||
return View->This->GetCenter().y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the half-width of the view
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfView_GetHalfSizeY(sfView* View)
|
||||
{
|
||||
CSFML_CHECK_RETURN(View, 0.f);
|
||||
|
||||
return View->This->GetHalfSize().x;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the half-height of the view
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfView_GetHalfSizeX(sfView* View)
|
||||
{
|
||||
CSFML_CHECK_RETURN(View, 0.f);
|
||||
|
||||
return View->This->GetHalfSize().y;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the bounding rectangle of a view
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFloatRect sfView_GetRect(sfView* View)
|
||||
{
|
||||
sfFloatRect Rect = {0, 0, 0, 0};
|
||||
CSFML_CHECK_RETURN(View, Rect);
|
||||
|
||||
sf::FloatRect SFMLRect = View->This->GetRect();
|
||||
Rect.Left = SFMLRect.Left;
|
||||
Rect.Top = SFMLRect.Top;
|
||||
Rect.Right = SFMLRect.Right;
|
||||
Rect.Bottom = SFMLRect.Bottom;
|
||||
|
||||
return Rect;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Move a view
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfView_Move(sfView* View, float OffsetX, float OffsetY)
|
||||
{
|
||||
CSFML_CALL_PTR(View, Move(OffsetX, OffsetY));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Resize a view rectangle to simulate a zoom / unzoom effect
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfView_Zoom(sfView* View, float Factor)
|
||||
{
|
||||
CSFML_CALL_PTR(View, Zoom(Factor));
|
||||
}
|
104
CSFML/src/SFML/Internal.h
Normal file
104
CSFML/src/SFML/Internal.h
Normal file
|
@ -0,0 +1,104 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007 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.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// 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)
|
||||
|
||||
#define CSFML_CALL_RETURN(Object, Function, Default) return (Object->This.Function);
|
||||
|
||||
#define CSFML_CALL_PTR_RETURN(Object, Function, Default) return (Object->This->Function);
|
||||
|
||||
#endif
|
42
CSFML/src/SFML/Makefile
Normal file
42
CSFML/src/SFML/Makefile
Normal file
|
@ -0,0 +1,42 @@
|
|||
export CC = gcc
|
||||
export CPP = g++
|
||||
export CFLAGS = -W -Wall -pedantic -fPIC -Wno-unused -I../.. -I../../../include -DNDEBUG -DCSFML_EXPORTS -O2
|
||||
export LDFLAGS = -shared
|
||||
export LIBPATH = ../../../lib
|
||||
export VERSION = 1.4
|
||||
export CP = cp
|
||||
export LN = ln
|
||||
export LNFLAGS = -s -f
|
||||
export DESTDIR = /usr
|
||||
export DESTLIBDIR = $(DESTDIR)/lib
|
||||
export DESTINCDIR = $(DESTDIR)/include
|
||||
|
||||
all: csfml-system csfml-window csfml-network csfml-graphics csfml-audio
|
||||
|
||||
csfml-system:
|
||||
@(cd ./System && $(MAKE))
|
||||
|
||||
csfml-window:
|
||||
@(cd ./Window && $(MAKE))
|
||||
|
||||
csfml-network:
|
||||
@(cd ./Network && $(MAKE))
|
||||
|
||||
csfml-graphics:
|
||||
@(cd ./Graphics && $(MAKE))
|
||||
|
||||
csfml-audio:
|
||||
@(cd ./Audio && $(MAKE))
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@(cd ./System && $(MAKE) $@ && cd ../Window && $(MAKE) $@ && cd ../Network && $(MAKE) $@ && cd ../Graphics && $(MAKE) $@ && cd ../Audio && $(MAKE) $@)
|
||||
|
||||
mrproper: clean
|
||||
@(cd ./System && $(MAKE) $@ && cd ../Window && $(MAKE) $@ && cd ../Network && $(MAKE) $@ && cd ../Graphics && $(MAKE) $@ && cd ../Audio && $(MAKE) $@)
|
||||
|
||||
install:
|
||||
@(mkdir -p $(DESTLIBDIR))
|
||||
@(mkdir -p $(DESTINCDIR))
|
||||
@(cd ./System && $(MAKE) $@ && cd ../Window && $(MAKE) $@ && cd ../Network && $(MAKE) $@ && cd ../Graphics && $(MAKE) $@ && cd ../Audio && $(MAKE) $@ && $(CP) -r ../../../include/SFML/ $(DESTINCDIR))
|
396
CSFML/src/SFML/Network/Ftp.cpp
Normal file
396
CSFML/src/SFML/Network/Ftp.cpp
Normal file
|
@ -0,0 +1,396 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Ftp.hpp>
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfFtpListingResponse
|
||||
{
|
||||
sfFtpListingResponse(const sf::Ftp::ListingResponse& Response) : This(Response) {}
|
||||
|
||||
sf::Ftp::ListingResponse This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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(sfFtpListingResponse* FtpListingResponse)
|
||||
{
|
||||
CSFML_CALL_RETURN(FtpListingResponse, IsOk(), sfFalse);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the response status code
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFtpStatus sfFtpListingResponse_GetStatus(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(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(sfFtpListingResponse* FtpListingResponse)
|
||||
{
|
||||
CSFML_CALL_RETURN(FtpListingResponse, GetCount(), 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the Index-th filename in the directory
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfFtpListingResponse_GetFilename(sfFtpListingResponse* FtpListingResponse, size_t Index)
|
||||
{
|
||||
CSFML_CHECK_RETURN(FtpListingResponse, NULL);
|
||||
|
||||
return FtpListingResponse->This.GetFilename(Index).c_str();
|
||||
}
|
||||
|
||||
|
||||
struct sfFtpDirectoryResponse
|
||||
{
|
||||
sfFtpDirectoryResponse(const sf::Ftp::DirectoryResponse& Response) : This(Response) {}
|
||||
|
||||
sf::Ftp::DirectoryResponse This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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(sfFtpDirectoryResponse* FtpDirectoryResponse)
|
||||
{
|
||||
CSFML_CALL_RETURN(FtpDirectoryResponse, IsOk(), sfFalse);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the response status code
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFtpStatus sfFtpDirectoryResponse_GetStatus(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(sfFtpDirectoryResponse* FtpDirectoryResponse)
|
||||
{
|
||||
CSFML_CHECK_RETURN(FtpDirectoryResponse, NULL);
|
||||
|
||||
return FtpDirectoryResponse->This.GetMessage().c_str();
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the directory returned in the response
|
||||
////////////////////////////////////////////////////////////
|
||||
const char* sfFtpDirectoryResponse_GetDirectory(sfFtpDirectoryResponse* FtpDirectoryResponse)
|
||||
{
|
||||
CSFML_CHECK_RETURN(FtpDirectoryResponse, NULL);
|
||||
|
||||
return FtpDirectoryResponse->This.GetDirectory().c_str();
|
||||
}
|
||||
|
||||
|
||||
struct sfFtpResponse
|
||||
{
|
||||
sfFtpResponse(const sf::Ftp::Response& Response) : This(Response) {}
|
||||
|
||||
sf::Ftp::Response This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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(sfFtpResponse* FtpResponse)
|
||||
{
|
||||
CSFML_CALL_RETURN(FtpResponse, IsOk(), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the response status code
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFtpStatus sfFtpResponse_GetStatus(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(sfFtpResponse* FtpResponse)
|
||||
{
|
||||
CSFML_CHECK_RETURN(FtpResponse, NULL);
|
||||
|
||||
return FtpResponse->This.GetMessage().c_str();
|
||||
}
|
||||
|
||||
|
||||
struct sfFtp
|
||||
{
|
||||
sf::Ftp This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new Ftp
|
||||
////////////////////////////////////////////////////////////
|
||||
sfFtp* sfFtp_Create()
|
||||
{
|
||||
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_MakeDirectory(sfFtp* Ftp, const char* Name)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Ftp, NULL);
|
||||
|
||||
return new sfFtpResponse(Ftp->This.MakeDirectory(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)));
|
||||
}
|
231
CSFML/src/SFML/Network/Http.cpp
Normal file
231
CSFML/src/SFML/Network/Http.cpp
Normal file
|
@ -0,0 +1,231 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Http.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfHttpRequest
|
||||
{
|
||||
sf::Http::Request This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new Http request
|
||||
////////////////////////////////////////////////////////////
|
||||
sfHttpRequest* sfHttpRequest_Create()
|
||||
{
|
||||
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 : ""));
|
||||
}
|
||||
|
||||
|
||||
struct sfHttpResponse
|
||||
{
|
||||
sf::Http::Response This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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(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(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(sfHttpResponse* HttpResponse)
|
||||
{
|
||||
CSFML_CALL_RETURN(HttpResponse, GetMajorHttpVersion(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the minor HTTP version of a response
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfHttpResponse_GetMinorVersion(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(sfHttpResponse* HttpResponse)
|
||||
{
|
||||
CSFML_CHECK_RETURN(HttpResponse, NULL);
|
||||
|
||||
return HttpResponse->This.GetBody().c_str();
|
||||
}
|
||||
|
||||
|
||||
struct sfHttp
|
||||
{
|
||||
sf::Http This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new Http object
|
||||
////////////////////////////////////////////////////////////
|
||||
sfHttp* sfHttp_Create()
|
||||
{
|
||||
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, 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;
|
||||
}
|
138
CSFML/src/SFML/Network/IPAddress.cpp
Normal file
138
CSFML/src/SFML/Network/IPAddress.cpp
Normal file
|
@ -0,0 +1,138 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tell if an address is a valid one
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfIPAddress_IsValid(sfIPAddress Address)
|
||||
{
|
||||
return ToSFMLAddress(Address).IsValid() ? sfTrue : sfFalse;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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()
|
||||
{
|
||||
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()
|
||||
{
|
||||
return FromSFMLAddress(sf::IPAddress::LocalHost);
|
||||
}
|
23
CSFML/src/SFML/Network/Makefile
Normal file
23
CSFML/src/SFML/Network/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
LIB = libcsfml-network.so
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
LIBNAME = $(LIBPATH)/$(LIB).$(VERSION)
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
libcsfml-network.so: $(OBJ)
|
||||
$(CPP) $(LDFLAGS) -Wl,-soname,$(LIB).$(VERSION) -o $(LIBNAME) $(OBJ) -lsfml-network
|
||||
|
||||
$(OBJ): %.o: %.cpp
|
||||
$(CPP) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
@rm -rf $(LIBNAME)
|
||||
|
||||
install:
|
||||
@($(CP) $(LIBNAME) $(DESTLIBDIR) && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB))
|
204
CSFML/src/SFML/Network/Packet.cpp
Normal file
204
CSFML/src/SFML/Network/Packet.cpp
Normal file
|
@ -0,0 +1,204 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Packet.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfPacket
|
||||
{
|
||||
sf::Packet This;
|
||||
};
|
||||
|
||||
|
||||
namespace
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Helper function to read a variable from a packet
|
||||
////////////////////////////////////////////////////////////
|
||||
template <typename T>
|
||||
T PacketRead(sfPacket* Packet, T Default = 0)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Packet, Default);
|
||||
|
||||
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()
|
||||
{
|
||||
return new sfPacket;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing packet
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPacket_Destroy(sfPacket* Packet)
|
||||
{
|
||||
delete Packet;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Append data to the end of a packet
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfPacket_Append(sfPacket* Packet, 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(sfPacket* Packet)
|
||||
{
|
||||
CSFML_CALL_RETURN(Packet, GetData(), NULL);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the size of the data contained in a packet
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfPacket_GetDataSize(sfPacket* Packet)
|
||||
{
|
||||
CSFML_CALL_RETURN(Packet, GetDataSize(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Tell if the reading position has reached the end of the packet
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfPacket_EndOfPacket(sfPacket* Packet)
|
||||
{
|
||||
CSFML_CALL_RETURN(Packet, EndOfPacket(), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check if a packet is in a valid reading state
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfPacket_CanRead(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;
|
||||
}
|
114
CSFML/src/SFML/Network/Selector.cpp
Normal file
114
CSFML/src/SFML/Network/Selector.cpp
Normal file
|
@ -0,0 +1,114 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Selector.h>
|
||||
#include <SFML/Network/Selector.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
#include <map>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Network/SocketTCP.h
|
||||
struct sfSocketTCP
|
||||
{
|
||||
sf::SocketTCP This;
|
||||
};
|
||||
// WARNING : this structure must always be the SAME as in Network/SocketUDP.h
|
||||
struct sfSocketUDP
|
||||
{
|
||||
sf::SocketUDP This;
|
||||
};
|
||||
struct sfSelectorTCP
|
||||
{
|
||||
sf::SelectorTCP This;
|
||||
std::map<sf::SocketTCP, sfSocketTCP*> Sockets;
|
||||
};
|
||||
struct sfSelectorUDP
|
||||
{
|
||||
sf::SelectorUDP This;
|
||||
std::map<sf::SocketUDP, sfSocketUDP*> Sockets;
|
||||
};
|
||||
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new selector
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSelectorTCP* sfSelectorTCP_Create() {return new sfSelectorTCP;}
|
||||
sfSelectorUDP* sfSelectorUDP_Create() {return new sfSelectorUDP;}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing selector
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSelectorTCP_Destroy(sfSelectorTCP* Selector) {delete Selector;}
|
||||
void sfSelectorUDP_Destroy(sfSelectorUDP* Selector) {delete Selector;}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Add a socket to watch to a selector
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSelectorTCP_Add(sfSelectorTCP* Selector, sfSocketTCP* Socket) {CSFML_CALL(Selector, Add(Socket->This)); Selector->Sockets[Socket->This] = Socket;}
|
||||
void sfSelectorUDP_Add(sfSelectorUDP* Selector, sfSocketUDP* Socket) {CSFML_CALL(Selector, Add(Socket->This)); Selector->Sockets[Socket->This] = Socket;}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Remove a socket from a selector
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSelectorTCP_Remove(sfSelectorTCP* Selector, sfSocketTCP* Socket) {CSFML_CALL(Selector, Remove(Socket->This)); Selector->Sockets.erase(Socket->This);}
|
||||
void sfSelectorUDP_Remove(sfSelectorUDP* Selector, sfSocketUDP* Socket) {CSFML_CALL(Selector, Remove(Socket->This)); Selector->Sockets.erase(Socket->This);}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Remove all sockets from a selector
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSelectorTCP_Clear(sfSelectorTCP* Selector) {CSFML_CALL(Selector, Clear()); Selector->Sockets.clear();}
|
||||
void sfSelectorUDP_Clear(sfSelectorUDP* Selector) {CSFML_CALL(Selector, Clear()); Selector->Sockets.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 time is out
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfSelectorTCP_Wait(sfSelectorTCP* Selector, float Timeout) {CSFML_CALL_RETURN(Selector, Wait(Timeout), 0);}
|
||||
unsigned int sfSelectorUDP_Wait(sfSelectorUDP* Selector, float Timeout) {CSFML_CALL_RETURN(Selector, Wait(Timeout), 0);}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// After a call to Wait(), get the Index-th socket which is
|
||||
/// ready for reading. The total number of sockets ready
|
||||
/// is the integer returned by the previous call to Wait()
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketTCP* sfSelectorTCP_GetSocketReady(sfSelectorTCP* Selector, unsigned int Index)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Selector, NULL);
|
||||
return Selector->Sockets[Selector->This.GetSocketReady(Index)];
|
||||
}
|
||||
sfSocketUDP* sfSelectorUDP_GetSocketReady(sfSelectorUDP* Selector, unsigned int Index)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Selector, NULL);
|
||||
return Selector->Sockets[Selector->This.GetSocketReady(Index)];
|
||||
}
|
192
CSFML/src/SFML/Network/SocketTCP.cpp
Normal file
192
CSFML/src/SFML/Network/SocketTCP.cpp
Normal file
|
@ -0,0 +1,192 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/SocketTCP.h>
|
||||
#include <SFML/Network/SocketTCP.hpp>
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
#include <SFML/Network/Packet.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Network/Packet.h
|
||||
struct sfPacket
|
||||
{
|
||||
sf::Packet This;
|
||||
};
|
||||
|
||||
struct sfSocketTCP
|
||||
{
|
||||
sf::SocketTCP This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new TCP socket
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketTCP* sfSocketTCP_Create()
|
||||
{
|
||||
return new sfSocketTCP;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing TCP socket
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSocketTCP_Destroy(sfSocketTCP* Socket)
|
||||
{
|
||||
if (Socket)
|
||||
{
|
||||
Socket->This.Close();
|
||||
delete Socket;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the blocking state of a TCP socket.
|
||||
/// The default behaviour of a socket is blocking
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSocketTCP_SetBlocking(sfSocketTCP* Socket, sfBool Blocking)
|
||||
{
|
||||
CSFML_CALL(Socket, SetBlocking(Blocking == sfTrue));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Connect a TCP socket to another computer on a specified port
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketStatus sfSocketTCP_Connect(sfSocketTCP* Socket, unsigned short Port, sfIPAddress HostAddress, float Timeout)
|
||||
{
|
||||
sf::IPAddress Address(HostAddress.Address);
|
||||
|
||||
CSFML_CHECK_RETURN(Socket, sfSocketError);
|
||||
|
||||
return static_cast<sfSocketStatus>(Socket->This.Connect(Port, Address, Timeout));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Listen to a specified port for incoming data or connections
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfSocketTCP_Listen(sfSocketTCP* Socket, unsigned short Port)
|
||||
{
|
||||
CSFML_CALL_RETURN(Socket, Listen(Port), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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 sfSocketTCP_Accept(sfSocketTCP* Socket, sfSocketTCP** Connected, sfIPAddress* Address)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Socket, sfSocketError);
|
||||
CSFML_CHECK_RETURN(Connected, sfSocketError);
|
||||
|
||||
// Call SFML internal function
|
||||
sf::IPAddress ClientAddress;
|
||||
sf::SocketTCP Client;
|
||||
sf::Socket::Status Status = Socket->This.Accept(Client, &ClientAddress);
|
||||
if (Status != sf::Socket::Done)
|
||||
return static_cast<sfSocketStatus>(Status);
|
||||
|
||||
// Convert the client socket returned
|
||||
*Connected = sfSocketTCP_Create();
|
||||
(*Connected)->This = Client;
|
||||
|
||||
// Convert the address if needed
|
||||
if (Address)
|
||||
strncpy(Address->Address, ClientAddress.ToString().c_str(), 16);
|
||||
|
||||
return sfSocketDone;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Send an array of bytes to the host (must be connected first)
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketStatus sfSocketTCP_Send(sfSocketTCP* 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 sfSocketTCP_Receive(sfSocketTCP* 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 sfSocketTCP_SendPacket(sfSocketTCP* 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 sfSocketTCP_ReceivePacket(sfSocketTCP* Socket, sfPacket* Packet)
|
||||
{
|
||||
CSFML_CHECK_RETURN(Socket, sfSocketError);
|
||||
CSFML_CHECK_RETURN(Packet, sfSocketError);
|
||||
|
||||
return static_cast<sfSocketStatus>(Socket->This.Receive(Packet->This));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check if a socket is in a valid state ; this function
|
||||
/// can be called any time to check if the socket is OK
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfSocketTCP_IsValid(sfSocketTCP* Socket)
|
||||
{
|
||||
CSFML_CALL_RETURN(Socket, IsValid(), sfFalse);
|
||||
}
|
187
CSFML/src/SFML/Network/SocketUDP.cpp
Normal file
187
CSFML/src/SFML/Network/SocketUDP.cpp
Normal file
|
@ -0,0 +1,187 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/SocketUDP.h>
|
||||
#include <SFML/Network/SocketUDP.hpp>
|
||||
#include <SFML/Network/IPAddress.hpp>
|
||||
#include <SFML/Network/Packet.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
#include <string.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Network/Packet.h
|
||||
struct sfPacket
|
||||
{
|
||||
sf::Packet This;
|
||||
};
|
||||
|
||||
struct sfSocketUDP
|
||||
{
|
||||
sf::SocketUDP This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new UDP socket
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketUDP* sfSocketUDP_Create()
|
||||
{
|
||||
return new sfSocketUDP;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing UDP socket
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSocketUDP_Destroy(sfSocketUDP* Socket)
|
||||
{
|
||||
delete Socket;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the blocking state of a UDP socket.
|
||||
/// The default behaviour of a socket is blocking
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfSocketUDP_SetBlocking(sfSocketUDP* Socket, sfBool Blocking)
|
||||
{
|
||||
CSFML_CALL(Socket, SetBlocking(Blocking == sfTrue));
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Bind a socket to a specific port
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfSocketUDP_Bind(sfSocketUDP* Socket, unsigned short Port)
|
||||
{
|
||||
CSFML_CALL_RETURN(Socket, Bind(Port), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Unbind a socket from its previous port, if any
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfSocketUDP_Unbind(sfSocketUDP* Socket)
|
||||
{
|
||||
CSFML_CALL_RETURN(Socket, Unbind(), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Send an array of bytes
|
||||
////////////////////////////////////////////////////////////
|
||||
sfSocketStatus sfSocketUDP_Send(sfSocketUDP* 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 sfSocketUDP_Receive(sfSocketUDP* 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 sfSocketUDP_SendPacket(sfSocketUDP* 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 sfSocketUDP_ReceivePacket(sfSocketUDP* 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;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Check if a socket is in a valid state ; this function
|
||||
/// can be called any time to check if the socket is OK
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfSocketUDP_IsValid(sfSocketUDP* Socket)
|
||||
{
|
||||
CSFML_CALL_RETURN(Socket, IsValid(), sfFalse);
|
||||
}
|
72
CSFML/src/SFML/System/Clock.cpp
Normal file
72
CSFML/src/SFML/System/Clock.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Clock.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfClock
|
||||
{
|
||||
sf::Clock This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new clock and start it
|
||||
////////////////////////////////////////////////////////////
|
||||
sfClock* sfClock_Create()
|
||||
{
|
||||
return new sfClock;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Destroy an existing clock
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfClock_Destroy(sfClock* Clock)
|
||||
{
|
||||
delete Clock;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the time elapsed for a clock
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfClock_GetTime(sfClock* Clock)
|
||||
{
|
||||
CSFML_CALL_RETURN(Clock, GetElapsedTime(), 0.f)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Restart a clock
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfClock_Reset(sfClock* Clock)
|
||||
{
|
||||
CSFML_CALL(Clock, Reset())
|
||||
}
|
23
CSFML/src/SFML/System/Makefile
Normal file
23
CSFML/src/SFML/System/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
LIB = libcsfml-system.so
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
LIBNAME = $(LIBPATH)/$(LIB).$(VERSION)
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
libcsfml-system.so: $(OBJ)
|
||||
$(CPP) $(LDFLAGS) -Wl,-soname,$(LIB).$(VERSION) -o $(LIBNAME) $(OBJ) -lsfml-system
|
||||
|
||||
$(OBJ): %.o: %.cpp
|
||||
$(CPP) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
@rm -rf $(LIBNAME)
|
||||
|
||||
install:
|
||||
@($(CP) $(LIBNAME) $(DESTLIBDIR) && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB))
|
72
CSFML/src/SFML/System/Mutex.cpp
Normal file
72
CSFML/src/SFML/System/Mutex.cpp
Normal file
|
@ -0,0 +1,72 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Mutex.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfMutex
|
||||
{
|
||||
sf::Mutex This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Create a new mutex
|
||||
////////////////////////////////////////////////////////////
|
||||
sfMutex* sfMutex_Create()
|
||||
{
|
||||
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())
|
||||
}
|
67
CSFML/src/SFML/System/Randomizer.cpp
Normal file
67
CSFML/src/SFML/System/Randomizer.cpp
Normal file
|
@ -0,0 +1,67 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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()
|
||||
{
|
||||
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);
|
||||
}
|
39
CSFML/src/SFML/System/Sleep.cpp
Normal file
39
CSFML/src/SFML/System/Sleep.cpp
Normal file
|
@ -0,0 +1,39 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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);
|
||||
}
|
86
CSFML/src/SFML/System/Thread.cpp
Normal file
86
CSFML/src/SFML/System/Thread.cpp
Normal file
|
@ -0,0 +1,86 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Thread.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfThread
|
||||
{
|
||||
sfThread(void (*Function)(void*), void* UserData) : This(Function, UserData) {}
|
||||
|
||||
sf::Thread This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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());
|
||||
}
|
63
CSFML/src/SFML/Window/Context.cpp
Normal file
63
CSFML/src/SFML/Window/Context.cpp
Normal file
|
@ -0,0 +1,63 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 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/Context.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfContext
|
||||
{
|
||||
sf::Context This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new context
|
||||
////////////////////////////////////////////////////////////
|
||||
sfContext* sfContext_Create()
|
||||
{
|
||||
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))
|
||||
}
|
89
CSFML/src/SFML/Window/Input.cpp
Normal file
89
CSFML/src/SFML/Window/Input.cpp
Normal file
|
@ -0,0 +1,89 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008-2008 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/Input.hpp>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
struct sfInput
|
||||
{
|
||||
const sf::Input* This;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the state of a key
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfInput_IsKeyDown(sfInput* Input, sfKeyCode KeyCode)
|
||||
{
|
||||
CSFML_CALL_PTR_RETURN(Input, IsKeyDown((sf::Key::Code)KeyCode), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the state of a mouse button
|
||||
////////////////////////////////////////////////////////////
|
||||
sfBool sfInput_IsMouseButtonDown(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(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(sfInput* Input)
|
||||
{
|
||||
CSFML_CALL_PTR_RETURN(Input, GetMouseX(), 0);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the mouse Y position
|
||||
////////////////////////////////////////////////////////////
|
||||
int sfInput_GetMouseY(sfInput* Input)
|
||||
{
|
||||
CSFML_CALL_PTR_RETURN(Input, GetMouseY(), 0);
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the joystick position on a given axis
|
||||
////////////////////////////////////////////////////////////
|
||||
float sfInput_GetJoystickAxis(sfInput* Input, unsigned int JoyId, sfJoyAxis Axis)
|
||||
{
|
||||
CSFML_CALL_PTR_RETURN(Input, GetJoystickAxis(JoyId, (sf::Joy::Axis)Axis), 0.f);
|
||||
}
|
23
CSFML/src/SFML/Window/Makefile
Normal file
23
CSFML/src/SFML/Window/Makefile
Normal file
|
@ -0,0 +1,23 @@
|
|||
LIB = libcsfml-window.so
|
||||
SRC = $(wildcard *.cpp)
|
||||
OBJ = $(SRC:.cpp=.o)
|
||||
LIBNAME = $(LIBPATH)/$(LIB).$(VERSION)
|
||||
|
||||
all: $(LIB)
|
||||
|
||||
libcsfml-window.so: $(OBJ)
|
||||
$(CPP) $(LDFLAGS) -Wl,-soname,$(LIB).$(VERSION) -o $(LIBNAME) $(OBJ) -lsfml-window -lsfml-system
|
||||
|
||||
$(OBJ): %.o: %.cpp
|
||||
$(CPP) -o $@ -c $< $(CFLAGS)
|
||||
|
||||
.PHONY: clean mrproper
|
||||
|
||||
clean:
|
||||
@rm -rf $(OBJ)
|
||||
|
||||
mrproper: clean
|
||||
@rm -rf $(LIBNAME)
|
||||
|
||||
install:
|
||||
@($(CP) $(LIBNAME) $(DESTLIBDIR) && $(LN) $(LNFLAGS) $(DESTLIBDIR)/$(LIB).$(VERSION) $(DESTLIBDIR)/$(LIB))
|
82
CSFML/src/SFML/Window/VideoMode.cpp
Normal file
82
CSFML/src/SFML/Window/VideoMode.cpp
Normal file
|
@ -0,0 +1,82 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008-2008 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()
|
||||
{
|
||||
sf::VideoMode Desktop = sf::VideoMode::GetDesktopMode();
|
||||
sfVideoMode Ret;
|
||||
Ret.Width = Desktop.Width;
|
||||
Ret.Height = Desktop.Height;
|
||||
Ret.BitsPerPixel = Desktop.BitsPerPixel;
|
||||
|
||||
return Ret;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get a valid video mode
|
||||
/// Index must be in range [0, GetModesCount()[
|
||||
/// Modes are sorted from best to worst
|
||||
////////////////////////////////////////////////////////////
|
||||
sfVideoMode sfVideoMode_GetMode(size_t Index)
|
||||
{
|
||||
sf::VideoMode Mode = sf::VideoMode::GetMode(Index);
|
||||
sfVideoMode Ret;
|
||||
Ret.Width = Mode.Width;
|
||||
Ret.Height = Mode.Height;
|
||||
Ret.BitsPerPixel = Mode.BitsPerPixel;
|
||||
|
||||
return Ret;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get valid video modes count
|
||||
////////////////////////////////////////////////////////////
|
||||
size_t sfVideoMode_GetModesCount()
|
||||
{
|
||||
return sf::VideoMode::GetModesCount();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// 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;
|
||||
}
|
344
CSFML/src/SFML/Window/Window.cpp
Normal file
344
CSFML/src/SFML/Window/Window.cpp
Normal file
|
@ -0,0 +1,344 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008-2008 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/Window.hpp>
|
||||
#include <SFML/Window/Input.h>
|
||||
#include <SFML/Internal.h>
|
||||
|
||||
|
||||
// WARNING : this structure must always be the SAME as in Window/Input.h
|
||||
struct sfInput
|
||||
{
|
||||
const sf::Input* This;
|
||||
};
|
||||
struct sfWindow
|
||||
{
|
||||
sf::Window This;
|
||||
sfInput Input;
|
||||
};
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a new window
|
||||
////////////////////////////////////////////////////////////
|
||||
sfWindow* sfWindow_Create(sfVideoMode Mode, const char* Title, unsigned long Style, sfWindowSettings Params)
|
||||
{
|
||||
// Convert video mode
|
||||
sf::VideoMode VideoMode(Mode.Width, Mode.Height, Mode.BitsPerPixel);
|
||||
|
||||
// Create the window
|
||||
sfWindow* Window = new sfWindow;
|
||||
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
|
||||
Window->This.Create(VideoMode, Title, Style, Settings);
|
||||
Window->Input.This = &Window->This.GetInput();
|
||||
|
||||
return Window;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Construct a window from an existing control
|
||||
////////////////////////////////////////////////////////////
|
||||
sfWindow* sfWindow_CreateFromHandle(sfWindowHandle Handle, sfWindowSettings Params)
|
||||
{
|
||||
sfWindow* Window = new sfWindow;
|
||||
sf::WindowSettings Settings(Params.DepthBits, Params.StencilBits, Params.AntialiasingLevel);
|
||||
Window->This.Create(Handle, Settings);
|
||||
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(sfWindow* Window)
|
||||
{
|
||||
CSFML_CALL_RETURN(Window, IsOpened(), sfFalse);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the width of the rendering region of a window
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfWindow_GetWidth(sfWindow* Window)
|
||||
{
|
||||
CSFML_CALL_RETURN(Window, GetWidth(), 0)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the height of the rendering region of a window
|
||||
////////////////////////////////////////////////////////////
|
||||
unsigned int sfWindow_GetHeight(sfWindow* Window)
|
||||
{
|
||||
CSFML_CALL_RETURN(Window, GetHeight(), 0)
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get the creation settings of a window
|
||||
////////////////////////////////////////////////////////////
|
||||
sfWindowSettings sfWindow_GetSettings(sfWindow* Window)
|
||||
{
|
||||
sfWindowSettings Settings = {0, 0, 0};
|
||||
CSFML_CHECK_RETURN(Window, Settings);
|
||||
|
||||
const sf::WindowSettings& Params = Window->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 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 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;
|
||||
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;
|
||||
}
|
||||
|
||||
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 State)
|
||||
{
|
||||
CSFML_CALL(Window, Show(State == 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, 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
|
||||
////////////////////////////////////////////////////////////
|
||||
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(sfWindow* Window)
|
||||
{
|
||||
CSFML_CALL_RETURN(Window, GetFrameTime(), 0.f)
|
||||
}
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Change the joystick threshold, ie. the value below which
|
||||
/// no move event will be generated
|
||||
///
|
||||
/// \param Threshold : New threshold, in range [0, 100]
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
void sfWindow_SetJoystickThreshold(sfWindow* Window, float Threshold)
|
||||
{
|
||||
CSFML_CALL(Window, SetJoystickThreshold(Threshold))
|
||||
}
|
Loading…
Add table
Add a link
Reference in a new issue