--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_AUDIORESOURCE_HPP\r
+#define SFML_AUDIORESOURCE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Abstract base class for every class that owns a\r
+/// device-dependant resource -- allow them to initialize / shutdown\r
+/// even when the audio context is not created\r
+////////////////////////////////////////////////////////////\r
+class SFML_API AudioResource\r
+{\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ AudioResource();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ AudioResource(const AudioResource&);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~AudioResource();\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_AUDIORESOURCE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_LISTENER_HPP\r
+#define SFML_LISTENER_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <SFML/System/Vector3.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Listener is a global interface for defining the audio\r
+/// listener properties ; the audio listener is the point in\r
+/// the scene from where all the sounds are heard\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Listener\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the global volume of all the sounds.\r
+ /// The default volume is 100\r
+ ///\r
+ /// \param Volume : New global volume, in the range [0, 100]\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetGlobalVolume(float Volume);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current value of the global volume of all the sounds\r
+ ///\r
+ /// \return Current global volume, in the range [0, 100]\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static float GetGlobalVolume();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the position of the listener (take 3 values).\r
+ /// The default position is (0, 0, 0)\r
+ ///\r
+ /// \param X, Y, Z : Position of the listener in the world\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetPosition(float X, float Y, float Z);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the position of the listener (take a 3D vector).\r
+ /// The default position is (0, 0, 0)\r
+ ///\r
+ /// \param Position : Position of the listener in the world\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetPosition(const Vector3f& Position);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current position of the listener\r
+ ///\r
+ /// \return Position of the listener in the world\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Vector3f GetPosition();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the orientation of the listener (the point\r
+ /// he must look at) (take 3 values).\r
+ /// The default target is (0, 0, -1)\r
+ ///\r
+ /// \param X, Y, Z : Position of the point the listener must look at\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetTarget(float X, float Y, float Z);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the orientation of the listener (the point\r
+ /// he must look at) (take a 3D vector).\r
+ /// The default target is (0, 0, -1)\r
+ ///\r
+ /// \param Target : Position of the point the listener must look at\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetTarget(const Vector3f& Target);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current orientation of the listener (the point\r
+ /// he's looking at)\r
+ ///\r
+ /// \return : Position of the point the listener is looking at\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Vector3f GetTarget();\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_LISTENER_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_MUSIC_HPP\r
+#define SFML_MUSIC_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Audio/SoundStream.hpp>\r
+#include <string>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+namespace priv\r
+{\r
+ class SoundFile;\r
+}\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Music defines a big sound played using streaming,\r
+/// so usually what we call a music :)\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Music : public SoundStream\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the music with a buffer size\r
+ ///\r
+ /// \param BufferSize : Size of the internal buffer, expressed in number of samples\r
+ /// (ie. size taken by the music in memory) (44100 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ explicit Music(std::size_t BufferSize = 44100);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Music();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Open a music file (doesn't play it -- call Play() for that)\r
+ ///\r
+ /// \param Filename : Path of the music file to open\r
+ ///\r
+ /// \return True if loading has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool OpenFromFile(const std::string& Filename);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Open a music file from memory (doesn't play it -- call Play() for that)\r
+ ///\r
+ /// \param Data : Pointer to the file data in memory\r
+ /// \param SizeInBytes : Size of the data to load, in bytes\r
+ ///\r
+ /// \return True if loading has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool OpenFromMemory(const char* Data, std::size_t SizeInBytes);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the music duration\r
+ ///\r
+ /// \return Music duration, in seconds\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetDuration() const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see SoundStream::OnStart\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnStart();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see SoundStream::OnGetData\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnGetData(Chunk& Data);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ priv::SoundFile* myFile; ///< Sound file\r
+ float myDuration; ///< Music duration, in seconds\r
+ std::vector<Int16> mySamples; ///< Temporary buffer of samples\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_MUSIC_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOUND_HPP\r
+#define SFML_SOUND_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Resource.hpp>\r
+#include <SFML/System/Vector3.hpp>\r
+#include <SFML/Audio/AudioResource.hpp>\r
+#include <cstdlib>\r
+\r
+\r
+namespace sf\r
+{\r
+class SoundBuffer;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Sound defines the properties of a sound such as position,\r
+/// volume, pitch, etc.\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Sound : public AudioResource\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enumeration of the sound states\r
+ ////////////////////////////////////////////////////////////\r
+ enum Status\r
+ {\r
+ Stopped, ///< Sound is not playing\r
+ Paused, ///< Sound is paused\r
+ Playing ///< Sound is playing\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Sound();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the sound from its parameters\r
+ ///\r
+ /// \param Buffer : Sound buffer to play (NULL by default)\r
+ /// \param Loop : Loop flag (false by default)\r
+ /// \param Pitch : Value of the pitch (1 by default)\r
+ /// \param Volume : Volume (100 by default)\r
+ /// \param Position : Position (0, 0, 0 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ explicit Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, const Vector3f& Position = Vector3f(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor\r
+ ///\r
+ /// \param Copy : Instance to copy\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Sound(const Sound& Copy);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Sound();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Play the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Play();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Pause the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Pause();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Stop the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Stop();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the source buffer\r
+ ///\r
+ /// \param Buffer : New sound buffer to bind to the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetBuffer(const SoundBuffer& Buffer);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the sound loop state.\r
+ /// This parameter is disabled by default\r
+ ///\r
+ /// \param Loop : True to play in loop, false to play once\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetLoop(bool Loop);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the sound pitch.\r
+ /// The default pitch is 1\r
+ ///\r
+ /// \param Pitch : New pitch\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPitch(float Pitch);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the sound volume.\r
+ /// The default volume is 100\r
+ ///\r
+ /// \param Volume : Volume (in range [0, 100])\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetVolume(float Volume);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the sound position (take 3 values).\r
+ /// The default position is (0, 0, 0)\r
+ ///\r
+ /// \param X, Y, Z : Position of the sound in the world\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPosition(float X, float Y, float Z);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the sound position (take a 3D vector).\r
+ /// The default position is (0, 0, 0)\r
+ ///\r
+ /// \param Position : Position of the sound in the world\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPosition(const Vector3f& Position);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Make the sound's position relative to the listener's\r
+ /// position, or absolute.\r
+ /// The default value is false (absolute)\r
+ ///\r
+ /// \param Relative : True to set the position relative, false to set it absolute\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetRelativeToListener(bool Relative);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the minimum distance - closer than this distance,\r
+ /// the listener will hear the sound at its maximum volume.\r
+ /// The default minimum distance is 1.0\r
+ ///\r
+ /// \param MinDistance : New minimum distance for the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetMinDistance(float MinDistance);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the attenuation factor - the higher the attenuation, the\r
+ /// more the sound will be attenuated with distance from listener.\r
+ /// The default attenuation factor 1.0\r
+ ///\r
+ /// \param Attenuation : New attenuation factor for the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetAttenuation(float Attenuation);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the current playing position of the sound\r
+ ///\r
+ /// \param TimeOffset : New playing position, expressed in seconds\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPlayingOffset(float TimeOffset);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the source buffer\r
+ ///\r
+ /// \return Sound buffer bound to the sound (can be NULL)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const SoundBuffer* GetBuffer() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell whether or not the sound is looping\r
+ ///\r
+ /// \return True if the sound is looping, false otherwise\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool GetLoop() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the pitch\r
+ ///\r
+ /// \return Pitch value\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetPitch() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the volume\r
+ ///\r
+ /// \return Volume value (in range [1, 100])\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetVolume() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the sound position\r
+ ///\r
+ /// \return Position of the sound in the world\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Vector3f GetPosition() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell if the sound's position is relative to the listener's\r
+ /// position, or if it's absolute\r
+ ///\r
+ /// \return True if the position is relative, false if it's absolute\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsRelativeToListener() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the minimum distance\r
+ ///\r
+ /// \return Minimum distance for the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetMinDistance() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the attenuation factor\r
+ ///\r
+ /// \return Attenuation factor of the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetAttenuation() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the status of the sound (stopped, paused, playing)\r
+ ///\r
+ /// \return Current status of the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Status GetStatus() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current playing position of the sound\r
+ ///\r
+ /// \return Current playing position, expressed in seconds\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetPlayingOffset() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator\r
+ ///\r
+ /// \param Other : Instance to assign\r
+ ///\r
+ /// \return Reference to the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Sound& operator =(const Sound& Other);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Reset the internal buffer\r
+ ///\r
+ /// This function is for internal use only, you don't have\r
+ /// to use it.\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void ResetBuffer();\r
+\r
+private :\r
+\r
+ friend class SoundStream;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int mySource; ///< OpenAL source identifier\r
+ ResourcePtr<SoundBuffer> myBuffer; ///< Sound buffer bound to the source\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOUND_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOUNDBUFFER_HPP\r
+#define SFML_SOUNDBUFFER_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Resource.hpp>\r
+#include <SFML/Audio/AudioResource.hpp>\r
+#include <string>\r
+#include <vector>\r
+#include <set>\r
+\r
+\r
+namespace sf\r
+{\r
+class Sound;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// SoundBuffer is the low-level for loading and manipulating\r
+/// sound buffers\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SoundBuffer : public AudioResource, public Resource<SoundBuffer>\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SoundBuffer();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor\r
+ ///\r
+ /// \param Copy : Instance to copy\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SoundBuffer(const SoundBuffer& Copy);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~SoundBuffer();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the sound buffer from a file\r
+ ///\r
+ /// \param Filename : Path of the sound file to load\r
+ ///\r
+ /// \return True if loading has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromFile(const std::string& Filename);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the sound buffer from a file in memory\r
+ ///\r
+ /// \param Data : Pointer to the file data in memory\r
+ /// \param SizeInBytes : Size of the data to load, in bytes\r
+ ///\r
+ /// \return True if loading has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the sound buffer from an array of samples - assumed format for\r
+ /// samples is 16 bits signed integer\r
+ ///\r
+ /// \param Samples : Pointer to the samples in memory\r
+ /// \param SamplesCount : Number of samples pointed by Samples\r
+ /// \param ChannelsCount : Number of channels (1 = mono, 2 = stereo, ...)\r
+ /// \param SampleRate : Frequency (number of samples to play per second)\r
+ ///\r
+ /// \return True if loading has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Save the sound buffer to a file\r
+ ///\r
+ /// \param Filename : Path of the sound file to write\r
+ ///\r
+ /// \return True if saving has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool SaveToFile(const std::string& Filename) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the sound samples\r
+ ///\r
+ /// \return Pointer to the array of sound samples, in 16 bits signed integer format\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Int16* GetSamples() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the samples count\r
+ ///\r
+ /// \return Number of samples\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ std::size_t GetSamplesCount() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the sample rate\r
+ ///\r
+ /// \return Sound frequency (number of samples per second)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetSampleRate() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the number of channels (1 = mono, 2 = stereo, ...)\r
+ ///\r
+ /// \return Number of channels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetChannelsCount() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the sound duration\r
+ ///\r
+ /// \return Sound duration, in seconds\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetDuration() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator\r
+ ///\r
+ /// \param Other : Instance to assign\r
+ ///\r
+ /// \return Reference to the sound buffer\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SoundBuffer& operator =(const SoundBuffer& Other);\r
+\r
+private :\r
+\r
+ friend class Sound;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Update the internal buffer with the audio samples\r
+ ///\r
+ /// \param ChannelsCount : Number of channels\r
+ /// \param SampleRate : Sample rate\r
+ ///\r
+ /// \return True on success\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Update(unsigned int ChannelsCount, unsigned int SampleRate);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Add a sound to the list of sounds that use this buffer\r
+ ///\r
+ /// \param Instance : Sound object to attach\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void AttachSound(Sound* Instance) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Remove a sound from the list of sounds that use this buffer\r
+ ///\r
+ /// \param Instance : Sound object to detach\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void DetachSound(Sound* Instance) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Types\r
+ ////////////////////////////////////////////////////////////\r
+ typedef std::set<Sound*> SoundList; ///< Set of unique sound instances\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int myBuffer; ///< OpenAL buffer identifier\r
+ std::vector<Int16> mySamples; ///< Samples buffer\r
+ float myDuration; ///< Sound duration, in seconds\r
+ mutable SoundList mySounds; ///< List of sounds that are using this buffer\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOUNDBUFFER_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOUNDBUFFERRECORDER_HPP\r
+#define SFML_SOUNDBUFFERRECORDER_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Audio/SoundBuffer.hpp>\r
+#include <SFML/Audio/SoundRecorder.hpp>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Specialized SoundRecorder which saves the captured\r
+/// audio data into a sound buffer\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SoundBufferRecorder : public SoundRecorder\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the sound buffer containing the captured audio data\r
+ ///\r
+ /// \return Constant reference to the sound buffer\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const SoundBuffer& GetBuffer() const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see SoundBuffer::OnStart\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnStart();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see SoundBuffer::OnProcessSamples\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see SoundBuffer::OnStop\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnStop();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ std::vector<Int16> mySamples; ///< Temporary sample buffer to hold the recorded data\r
+ SoundBuffer myBuffer; ///< Sound buffer that will contain the recorded data\r
+};\r
+\r
+} // namespace sf\r
+\r
+#endif // SFML_SOUNDBUFFERRECORDER_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOUNDRECORDER_HPP\r
+#define SFML_SOUNDRECORDER_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Thread.hpp>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// SoundRecorder is an interface for capturing sound data,\r
+/// it is meant to be used as a base class\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SoundRecorder : private Thread\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Virtual destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~SoundRecorder();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Start the capture.\r
+ /// Warning : only one capture can happen at the same time\r
+ ///\r
+ /// \param SampleRate : Sound frequency (the more samples, the higher the quality)\r
+ /// (44100 by default = CD quality)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Start(unsigned int SampleRate = 44100);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Stop the capture\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Stop();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the sample rate\r
+ ///\r
+ /// \return Frequency, in samples per second\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetSampleRate() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell if the system supports sound capture.\r
+ /// If not, this class won't be usable\r
+ ///\r
+ /// \return True if audio capture is supported\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static bool CanCapture();\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SoundRecorder();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Start recording audio data\r
+ ///\r
+ /// \return False to abort recording audio data, true to start\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnStart();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Process a new chunk of recorded samples\r
+ ///\r
+ /// \param Samples : Pointer to the new chunk of recorded samples\r
+ /// \param SamplesCount : Number of samples pointed by Samples\r
+ ///\r
+ /// \return False to stop recording audio data, true to continue\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount) = 0;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Stop recording audio data\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnStop();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see Thread::Run\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Run();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the available captured samples and process them\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void ProcessCapturedSamples();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Clean up the recorder internal resources\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void CleanUp();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ std::vector<Int16> mySamples; ///< Buffer to store captured samples\r
+ unsigned int mySampleRate; ///< Sample rate\r
+ bool myIsCapturing; ///< Capturing state\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOUNDRECORDER_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOUNDSTREAM_HPP\r
+#define SFML_SOUNDSTREAM_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Audio/Sound.hpp>\r
+#include <SFML/System/Thread.hpp>\r
+#include <cstdlib>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// SoundStream is a streamed sound, ie samples are acquired\r
+/// while the sound is playing. Use it for big sounds that would\r
+/// require hundreds of MB in memory (see Music),\r
+/// or for streaming sound from the network\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SoundStream : private Thread, private Sound\r
+{\r
+public :\r
+\r
+ using Sound::Status;\r
+ using Sound::Stopped;\r
+ using Sound::Paused;\r
+ using Sound::Playing;\r
+ using Sound::Pause;\r
+ using Sound::SetPitch;\r
+ using Sound::SetVolume;\r
+ using Sound::SetPosition;\r
+ using Sound::SetRelativeToListener;\r
+ using Sound::SetMinDistance;\r
+ using Sound::SetAttenuation;\r
+ using Sound::GetPitch;\r
+ using Sound::GetVolume;\r
+ using Sound::GetPosition;\r
+ using Sound::IsRelativeToListener;\r
+ using Sound::GetMinDistance;\r
+ using Sound::GetAttenuation;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Structure defining a chunk of audio data to stream\r
+ ////////////////////////////////////////////////////////////\r
+ struct Chunk\r
+ {\r
+ const Int16* Samples; ///< Pointer to the audio samples\r
+ std::size_t NbSamples; ///< Number of samples pointed by Samples\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Virtual destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~SoundStream();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Start playing the audio stream\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Play();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Stop playing the audio stream\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Stop();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the number of channels (1 = mono, 2 = stereo)\r
+ ///\r
+ /// \return Number of channels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetChannelsCount() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the stream sample rate\r
+ ///\r
+ /// \return Stream frequency (number of samples per second)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetSampleRate() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the status of the stream (stopped, paused, playing)\r
+ ///\r
+ /// \return Current status of the sound\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Status GetStatus() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current playing position of the stream\r
+ ///\r
+ /// \return Current playing position, expressed in seconds\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetPlayingOffset() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the stream loop state.\r
+ /// This parameter is disabled by default\r
+ ///\r
+ /// \param Loop : True to play in loop, false to play once\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetLoop(bool Loop);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell whether or not the stream is looping\r
+ ///\r
+ /// \return True if the music is looping, false otherwise\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool GetLoop() const;\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SoundStream();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the audio stream parameters, you must call it before Play()\r
+ ///\r
+ /// \param ChannelsCount : Number of channels\r
+ /// \param SampleRate : Sample rate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Initialize(unsigned int ChannelsCount, unsigned int SampleRate);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see Thread::Run\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Run();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Called when the sound restarts\r
+ ///\r
+ /// \return If false is returned, the playback is aborted\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnStart();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Called each time new audio data is needed to feed the stream\r
+ ///\r
+ /// \param Data : New chunk of data to stream\r
+ ///\r
+ /// \return True to continue playback, false to stop\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool OnGetData(Chunk& Data) = 0;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Fill a new buffer with audio data, and push it to the\r
+ /// playing queue\r
+ ///\r
+ /// \param Buffer : Number of the buffer to fill (in [0, BuffersCount])\r
+ ///\r
+ /// \return True if the derived class has requested to stop\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool FillAndPushBuffer(unsigned int BufferNum);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Fill the buffers queue with all available buffers\r
+ ///\r
+ /// \return True if the derived class has requested to stop\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool FillQueue();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Clear the queue of any remaining buffers\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void ClearQueue();\r
+\r
+ enum {BuffersCount = 3};\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ bool myIsStreaming; ///< Streaming state (true = playing, false = stopped)\r
+ unsigned int myBuffers[BuffersCount]; ///< Sound buffers used to store temporary audio data\r
+ unsigned int myChannelsCount; ///< Number of channels (1 = mono, 2 = stereo, ...)\r
+ unsigned int mySampleRate; ///< Frequency (samples / second)\r
+ unsigned long myFormat; ///< Format of the internal sound buffers\r
+ bool myLoop; ///< Loop flag (true to loop, false to play once)\r
+ unsigned int mySamplesProcessed; ///< Number of buffers processed since beginning of the stream\r
+ bool myEndBuffers[BuffersCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOUNDSTREAM_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_COLOR_HPP\r
+#define SFML_COLOR_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Color is an utility class for manipulating\r
+/// 32-bits RGBA colors\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Color\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Color();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the color from its 4 RGBA components\r
+ ///\r
+ /// \param R : Red component (0 .. 255)\r
+ /// \param G : Green component (0 .. 255)\r
+ /// \param B : Blue component (0 .. 255)\r
+ /// \param A : Alpha component (0 .. 255) (255 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Color(Uint8 R, Uint8 G, Uint8 B, Uint8 A = 255);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator += overload to add a color\r
+ ///\r
+ /// \param Other : Color to add\r
+ ///\r
+ /// \return Component-wise saturated addition of the two colors\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Color& operator +=(const Color& Other);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator *= overload to modulate a color\r
+ ///\r
+ /// \param Other : Color to modulate\r
+ ///\r
+ /// \return Component-wise multiplication of the two colors\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Color& operator *=(const Color& Other);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Compare two colors (for equality)\r
+ ///\r
+ /// \param Other : Color to compare\r
+ ///\r
+ /// \return True if colors are equal\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator ==(const Color& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Compare two colors (for difference)\r
+ ///\r
+ /// \param Other : Color to compare\r
+ ///\r
+ /// \return True if colors are different\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator !=(const Color& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Static member data\r
+ ////////////////////////////////////////////////////////////\r
+ static const Color Black; ///< Black predefined color\r
+ static const Color White; ///< White predefined color\r
+ static const Color Red; ///< Red predefined color\r
+ static const Color Green; ///< Green predefined color\r
+ static const Color Blue; ///< Blue predefined color\r
+ static const Color Yellow; ///< Yellow predefined color\r
+ static const Color Magenta; ///< Magenta predefined color\r
+ static const Color Cyan; ///< Cyan predefined color\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ Uint8 r; ///< Red component\r
+ Uint8 g; ///< Green component\r
+ Uint8 b; ///< Blue component\r
+ Uint8 a; ///< Alpha (transparency) component\r
+};\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator + overload to add two colors\r
+///\r
+/// \param Color1 : First color\r
+/// \param Color2 : Second color\r
+///\r
+/// \return Component-wise saturated addition of the two colors\r
+///\r
+////////////////////////////////////////////////////////////\r
+SFML_API Color operator +(const Color& Color1, const Color& Color2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload to modulate two colors\r
+///\r
+/// \param Color1 : First color\r
+/// \param Color2 : Second color\r
+///\r
+/// \return Component-wise multiplication of the two colors\r
+///\r
+////////////////////////////////////////////////////////////\r
+SFML_API Color operator *(const Color& Color1, const Color& Color2);\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_COLOR_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_DRAWABLE_HPP\r
+#define SFML_DRAWABLE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Vector2.hpp>\r
+#include <SFML/Graphics/Color.hpp>\r
+#include <SFML/Graphics/Matrix3.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+class RenderTarget;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Enumerate the blending modes for drawable objects\r
+////////////////////////////////////////////////////////////\r
+namespace Blend\r
+{\r
+ enum Mode\r
+ {\r
+ Alpha, ///< Pixel = Src * a + Dest * (1 - a)\r
+ Add, ///< Pixel = Src + Dest\r
+ Multiply, ///< Pixel = Src * Dest\r
+ None ///< No blending\r
+ };\r
+}\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Abstract base class for every object that can be drawn\r
+/// into a render window\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Drawable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ /// \param Position : Position of the object (0, 0 by default)\r
+ /// \param Scale : Scale factor (1, 1 by default)\r
+ /// \param Rotation : Orientation, in degrees (0 by default)\r
+ /// \param Col : Color of the object (white by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Drawable(const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Virtual destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~Drawable();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the position of the object (take 2 values)\r
+ ///\r
+ /// \param X : New X coordinate\r
+ /// \param Y : New Y coordinate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPosition(float X, float Y);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the position of the object (take a 2D vector)\r
+ ///\r
+ /// \param Position : New position\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPosition(const Vector2f& Position);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the X position of the object\r
+ ///\r
+ /// \param X : New X coordinate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetX(float X);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the Y position of the object\r
+ ///\r
+ /// \param Y : New Y coordinate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetY(float Y);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the scale of the object (take 2 values)\r
+ ///\r
+ /// \param ScaleX : New horizontal scale (must be strictly positive)\r
+ /// \param ScaleY : New vertical scale (must be strictly positive)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetScale(float ScaleX, float ScaleY);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the scale of the object (take a 2D vector)\r
+ ///\r
+ /// \param Scale : New scale (both values must be strictly positive)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetScale(const Vector2f& Scale);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the X scale factor of the object\r
+ ///\r
+ /// \param X : New X scale factor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetScaleX(float FactorX);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the Y scale factor of the object\r
+ ///\r
+ /// \param Y : New Y scale factor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetScaleY(float FactorY);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the center of the object, in coordinates relative to the\r
+ /// top-left of the object (take 2 values).\r
+ /// The default center is (0, 0)\r
+ ///\r
+ /// \param CenterX : X coordinate of the center\r
+ /// \param CenterY : Y coordinate of the center\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetCenter(float CenterX, float CenterY);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the center of the object, in coordinates relative to the\r
+ /// top-left of the object (take a 2D vector).\r
+ /// The default center is (0, 0)\r
+ ///\r
+ /// \param Center : New center\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetCenter(const Vector2f& Center);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the orientation of the object\r
+ ///\r
+ /// \param Rotation : Angle of rotation, in degrees\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetRotation(float Rotation);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the color of the object.\r
+ /// The default color is white\r
+ ///\r
+ /// \param Col : New color\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetColor(const Color& Col);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the blending mode for the object.\r
+ /// The default blend mode is Blend::Alpha\r
+ ///\r
+ /// \param Mode : New blending mode\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetBlendMode(Blend::Mode Mode);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the position of the object\r
+ ///\r
+ /// \return Current position\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Vector2f& GetPosition() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current scale of the object\r
+ ///\r
+ /// \return Current scale factor (always positive)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Vector2f& GetScale() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the center of the object\r
+ ///\r
+ /// \return Current position of the center\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Vector2f& GetCenter() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the orientation of the object.\r
+ /// Rotation is always in the range [0, 360]\r
+ ///\r
+ /// \return Current rotation, in degrees\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetRotation() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the color of the object\r
+ ///\r
+ /// \return Current color\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Color& GetColor() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current blending mode\r
+ ///\r
+ /// \return Current blending mode\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Blend::Mode GetBlendMode() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Move the object of a given offset (take 2 values)\r
+ ///\r
+ /// \param OffsetX : X offset\r
+ /// \param OffsetY : Y offset\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Move(float OffsetX, float OffsetY);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Move the object of a given offset (take a 2D vector)\r
+ ///\r
+ /// \param Offset : Amount of units to move the object of\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Move(const Vector2f& Offset);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Scale the object (take 2 values)\r
+ ///\r
+ /// \param FactorX : Scaling factor on X (must be strictly positive)\r
+ /// \param FactorY : Scaling factor on Y (must be strictly positive)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Scale(float FactorX, float FactorY);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Scale the object (take a 2D vector)\r
+ ///\r
+ /// \param Factor : Scaling factors (both values must be strictly positive)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Scale(const Vector2f& Factor);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Rotate the object\r
+ ///\r
+ /// \param Angle : Angle of rotation, in degrees\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Rotate(float Angle);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Transform a point from global coordinates into local coordinates\r
+ /// (ie it applies the inverse of object's center, translation, rotation and scale to the point)\r
+ ///\r
+ /// \param Point : Point to transform\r
+ ///\r
+ /// \return Transformed point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ sf::Vector2f TransformToLocal(const sf::Vector2f& Point) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Transform a point from local coordinates into global coordinates\r
+ /// (ie it applies the object's center, translation, rotation and scale to the point)\r
+ ///\r
+ /// \param Point : Point to transform\r
+ ///\r
+ /// \return Transformed point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ sf::Vector2f TransformToGlobal(const sf::Vector2f& Point) const;\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the transform matrix of the drawable\r
+ ///\r
+ /// \return Transform matrix\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Matrix3& GetMatrix() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the inverse transform matrix of the drawable\r
+ ///\r
+ /// \return Inverse transform matrix\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Matrix3& GetInverseMatrix() const;\r
+\r
+private :\r
+\r
+ friend class RenderTarget;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Draw the object into the specified window\r
+ ///\r
+ /// \param Target : Target into which render the object\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Draw(RenderTarget& Target) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Render the specific geometry of the object\r
+ ///\r
+ /// \param Target : Target into which render the object\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Render(RenderTarget& Target) const = 0;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ Vector2f myPosition; ///< Position of the object on screen\r
+ Vector2f myScale; ///< Scale of the object\r
+ Vector2f myCenter; ///< Origin of translation / rotation / scaling of the object\r
+ float myRotation; ///< Orientation of the object, in degrees\r
+ Color myColor; ///< Overlay color of the object\r
+ Blend::Mode myBlendMode; ///< Blending mode\r
+ mutable bool myNeedUpdate; ///< Do we need to recompute the transform matrix ?\r
+ mutable bool myInvNeedUpdate; ///< Do we need to recompute the inverse transform matrix ?\r
+ mutable Matrix3 myMatrix; ///< Precomputed transform matrix gathering the translation / rotation / scale / center\r
+ mutable Matrix3 myInvMatrix; ///< Precomputed inverse transform matrix gathering the translation / rotation / scale / center\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_DRAWABLE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_FONT_HPP\r
+#define SFML_FONT_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Resource.hpp>\r
+#include <SFML/System/Vector2.hpp>\r
+#include <SFML/System/Unicode.hpp>\r
+#include <SFML/Graphics/Glyph.hpp>\r
+#include <SFML/Graphics/Image.hpp>\r
+#include <SFML/Graphics/Rect.hpp>\r
+#include <map>\r
+#include <string>\r
+\r
+\r
+namespace sf\r
+{\r
+class String;\r
+\r
+namespace priv\r
+{\r
+class FontLoader;\r
+}\r
+////////////////////////////////////////////////////////////\r
+/// Font is the low-level class for loading and\r
+/// manipulating character fonts. This class is meant to\r
+/// be used by sf::String\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Font : public Resource<Font>\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Font();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the font from a file\r
+ ///\r
+ /// \param Filename : Font file to load\r
+ /// \param CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\r
+ /// \param Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters)\r
+ ///\r
+ /// \return True if loading was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromFile(const std::string& Filename, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the font from a file in memory\r
+ ///\r
+ /// \param Data : Pointer to the data to load\r
+ /// \param SizeInBytes : Size of the data, in bytes\r
+ /// \param CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default)\r
+ /// \param Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters)\r
+ ///\r
+ /// \return True if loading was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the base size of characters in the font;\r
+ /// All glyphs dimensions are based on this value\r
+ ///\r
+ /// \return Base size of characters\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetCharacterSize() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the description of a glyph (character)\r
+ /// given by its unicode value\r
+ ///\r
+ /// \param CodePoint : Unicode value of the character to get\r
+ ///\r
+ /// \return Glyph's visual settings, or an invalid glyph if character not found\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Glyph& GetGlyph(Uint32 CodePoint) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the image containing the rendered characters (glyphs)\r
+ ///\r
+ /// \return Image containing glyphs\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Image& GetImage() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the SFML default built-in font (Arial)\r
+ ///\r
+ /// \return Instance of the default font\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static const Font& GetDefaultFont();\r
+\r
+private :\r
+\r
+ friend class priv::FontLoader;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Static member data\r
+ ////////////////////////////////////////////////////////////\r
+ static Uint32 ourDefaultCharset[]; ///< The default charset (all printable ISO-8859-1 characters)\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ Image myTexture; ///< Texture holding the bitmap font\r
+ unsigned int myCharSize; ///< Size of characters in the bitmap font\r
+ std::map<Uint32, Glyph> myGlyphs; ///< Rendering settings of each character (glyph)\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_FONT_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_GLYPH_HPP\r
+#define SFML_GLYPH_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <SFML/Graphics/Rect.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Structure describing a glyph (a visual character)\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Glyph\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Glyph() : Advance(0) {}\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ int Advance; ///< Offset to move horizontically to the next character\r
+ IntRect Rectangle; ///< Bounding rectangle of the glyph, in relative coordinates\r
+ FloatRect TexCoords; ///< Texture coordinates of the glyph inside the bitmap font\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_GLYPH_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_IMAGE_HPP\r
+#define SFML_IMAGE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Resource.hpp>\r
+#include <SFML/Graphics/Color.hpp>\r
+#include <SFML/Graphics/Rect.hpp>\r
+#include <string>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+class RenderWindow;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Image is the low-level class for loading and\r
+/// manipulating images\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Image : public Resource<Image>\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Image();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor\r
+ ///\r
+ /// \param Copy : instance to copy\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Image(const Image& Copy);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct an empty image\r
+ ///\r
+ /// \param Width : Image width\r
+ /// \param Height : Image height\r
+ /// \param Col : Image color (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Image(unsigned int Width, unsigned int Height, const Color& Col = Color(0, 0, 0, 255));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the image from pixels in memory\r
+ ///\r
+ /// \param Width : Image width\r
+ /// \param Height : Image height\r
+ /// \param Data : Pointer to the pixels in memory (assumed format is RGBA)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Image(unsigned int Width, unsigned int Height, const Uint8* Data);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Image();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the image from a file\r
+ ///\r
+ /// \param Filename : Path of the image file to load\r
+ ///\r
+ /// \return True if loading was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromFile(const std::string& Filename);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the image from a file in memory\r
+ ///\r
+ /// \param Data : Pointer to the file data in memory\r
+ /// \param SizeInBytes : Size of the data to load, in bytes\r
+ ///\r
+ /// \return True if loading was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromMemory(const char* Data, std::size_t SizeInBytes);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the image directly from an array of pixels\r
+ ///\r
+ /// \param Width : Image width\r
+ /// \param Height : Image height\r
+ /// \param Data : Pointer to the pixels in memory (assumed format is RGBA)\r
+ ///\r
+ /// \return True if loading was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8* Data);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Save the content of the image to a file\r
+ ///\r
+ /// \param Filename : Path of the file to save (overwritten if already exist)\r
+ ///\r
+ /// \return True if saving was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool SaveToFile(const std::string& Filename) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create an empty image\r
+ ///\r
+ /// \param Width : Image width\r
+ /// \param Height : Image height\r
+ /// \param Col : Image color (black by default)\r
+ ///\r
+ /// \return True if creation was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Create(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create transparency mask from a specified colorkey\r
+ ///\r
+ /// \param ColorKey : Color to become transparent\r
+ /// \param Alpha : Alpha value to use for transparent pixels (0 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void CreateMaskFromColor(Color ColorKey, Uint8 Alpha = 0);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy pixels from another image onto this one.\r
+ /// This function does a slow pixel copy and should only\r
+ /// be used at initialization time\r
+ ///\r
+ /// \param Source : Source image to copy\r
+ /// \param DestX : X coordinate of the destination position\r
+ /// \param DestY : Y coordinate of the destination position\r
+ /// \param SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image)\r
+ /// \param ApplyAlpha : Should the copy take in account the source transparency? (false by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0), bool ApplyAlpha = false);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create the image from the current contents of the\r
+ /// given window\r
+ ///\r
+ /// \param Window : Window to capture\r
+ /// \param SourceRect : Sub-rectangle of the screen to copy (empty by default - entire image)\r
+ ///\r
+ /// \return True if copy was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the color of a pixel\r
+ ///\r
+ /// \param X : X coordinate of pixel in the image\r
+ /// \param Y : Y coordinate of pixel in the image\r
+ /// \param Col : New color for pixel (X, Y)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPixel(unsigned int X, unsigned int Y, const Color& Col);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a pixel from the image\r
+ ///\r
+ /// \param X : X coordinate of pixel in the image\r
+ /// \param Y : Y coordinate of pixel in the image\r
+ ///\r
+ /// \return Color of pixel (X, Y)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Color& GetPixel(unsigned int X, unsigned int Y) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a read-only pointer to the array of pixels (RGBA 8 bits integers components)\r
+ /// Array size is GetWidth() x GetHeight() x 4\r
+ /// This pointer becomes invalid if you reload or resize the image\r
+ ///\r
+ /// \return Const pointer to the array of pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Uint8* GetPixelsPtr() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Bind the image for rendering\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Bind() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enable or disable image smooth filter.\r
+ /// This parameter is enabled by default\r
+ ///\r
+ /// \param Smooth : True to enable smoothing filter, false to disable it\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetSmooth(bool Smooth);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the width of the image\r
+ ///\r
+ /// \return Width in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetWidth() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the height of the image\r
+ ///\r
+ /// \return Height in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetHeight() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tells whether the smooth filtering is enabled or not\r
+ ///\r
+ /// \return True if image smoothing is enabled\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsSmooth() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Convert a subrect expressed in pixels, into float\r
+ /// texture coordinates\r
+ ///\r
+ /// \param Rect : Sub-rectangle of image to convert\r
+ ///\r
+ /// \return Texture coordinates corresponding to the sub-rectangle\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ FloatRect GetTexCoords(const IntRect& Rect) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a valid texture size according to hardware support\r
+ ///\r
+ /// \param Size : Size to convert\r
+ ///\r
+ /// \return Valid nearest size (greater than or equal to specified size)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static unsigned int GetValidTextureSize(unsigned int Size);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator\r
+ ///\r
+ /// \param Other : instance to assign\r
+ ///\r
+ /// \return Reference to the image\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Image& operator =(const Image& Other);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create the OpenGL texture\r
+ ///\r
+ /// \return True if texture has been successfully created\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool CreateTexture();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Make sure the texture in video memory is updated with the\r
+ /// array of pixels\r
+ ////////////////////////////////////////////////////////////\r
+ void EnsureTextureUpdate() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Make sure the array of pixels is updated with the\r
+ /// texture in video memory\r
+ ////////////////////////////////////////////////////////////\r
+ void EnsureArrayUpdate() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Reset the image attributes\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Reset();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destroy the OpenGL texture\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void DestroyTexture();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int myWidth; ///< Image width\r
+ unsigned int myHeight; ///< Image Height\r
+ unsigned int myTextureWidth; ///< Actual texture width (can be greater than image width because of padding)\r
+ unsigned int myTextureHeight; ///< Actual texture height (can be greater than image height because of padding)\r
+ unsigned int myTexture; ///< Internal texture identifier\r
+ bool myIsSmooth; ///< Status of the smooth filter\r
+ mutable std::vector<Color> myPixels; ///< Pixels of the image\r
+ mutable bool myNeedTextureUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory\r
+ mutable bool myNeedArrayUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_IMAGE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_MATRIX3_HPP\r
+#define SFML_MATRIX3_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <SFML/System/Vector2.hpp>\r
+#include <math.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Utility class to manipulate 3x3 matrices representing\r
+/// 2D transformations\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Matrix3\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor (builds an identity matrix)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Matrix3();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct a matrix from its 9 elements\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Matrix3(float a00, float a01, float a02,\r
+ float a10, float a11, float a12,\r
+ float a20, float a21, float a22);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Build a matrix from a set of transformations\r
+ ///\r
+ /// \param Center : Origin for the transformations\r
+ /// \param Translation : Translation offset\r
+ /// \param Rotation : Rotation angle in degrees\r
+ /// \param Scale : Scaling factors\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Transform a point by the matrix\r
+ ///\r
+ /// \param Point : Point to transform\r
+ ///\r
+ /// \return Transformed point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Vector2f Transform(const Vector2f& Point) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the inverse of the matrix\r
+ ///\r
+ /// \return A new matrix which is the inverse of this\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Matrix3 GetInverse() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the elements of the matrix as a 4x4,\r
+ /// in an array of 16 floats\r
+ ///\r
+ /// \return Pointer to the 4x4 matrix elements\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const float* Get4x4Elements() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator () overloads to access the matrix elements\r
+ ///\r
+ /// \param Row : Element row (0 based)\r
+ /// \param Col : Element column (0 based)\r
+ ///\r
+ /// \return Matrix element (Row, Col)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float operator ()(unsigned int Row, unsigned int Col) const;\r
+ float& operator ()(unsigned int Row, unsigned int Col);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator * overload to multiply two matrices\r
+ ///\r
+ /// \param Mat : Matrix to multiply\r
+ ///\r
+ /// \return this * Mat\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Matrix3 operator *(const Matrix3& Mat) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator *= overload to multiply-assign two matrices\r
+ ///\r
+ /// \param Mat : Matrix to multiply\r
+ ///\r
+ /// \return this * Mat\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Matrix3& operator *=(const Matrix3& Mat);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Static member data\r
+ ////////////////////////////////////////////////////////////\r
+ static const Matrix3 Identity; ///< Identity matrix\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ float myData[16]; /// Matrix elements (we directly store it as a 4x4 matrix for optimization purpose)\r
+};\r
+\r
+#include <SFML/Graphics/Matrix3.inl>\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_MATRIX3_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFGE - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Default constructor (builds an identity matrix)\r
+////////////////////////////////////////////////////////////\r
+inline Matrix3::Matrix3()\r
+{\r
+ myData[0] = 1.f; myData[4] = 0.f; myData[8] = 0.f; myData[12] = 0.f;\r
+ myData[1] = 0.f; myData[5] = 1.f; myData[9] = 0.f; myData[13] = 0.f;\r
+ myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;\r
+ myData[3] = 0.f; myData[7] = 0.f; myData[11] = 0.f; myData[15] = 1.f;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Construct a matrix from its 9 elements\r
+////////////////////////////////////////////////////////////\r
+inline Matrix3::Matrix3(float a00, float a01, float a02,\r
+ float a10, float a11, float a12,\r
+ float a20, float a21, float a22)\r
+{\r
+ myData[0] = a00; myData[4] = a01; myData[8] = 0.f; myData[12] = a02;\r
+ myData[1] = a10; myData[5] = a11; myData[9] = 0.f; myData[13] = a12;\r
+ myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;\r
+ myData[3] = a20; myData[7] = a21; myData[11] = 0.f; myData[15] = a22;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Build a matrix from a set of transformations\r
+////////////////////////////////////////////////////////////\r
+inline void Matrix3::SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale)\r
+{\r
+ float Angle = Rotation * 3.141592654f / 180.f;\r
+ float Cos = static_cast<float>(cos(Angle));\r
+ float Sin = static_cast<float>(sin(Angle));\r
+ float SxCos = Scale.x * Cos;\r
+ float SyCos = Scale.y * Cos;\r
+ float SxSin = Scale.x * Sin;\r
+ float SySin = Scale.y * Sin;\r
+ float Tx = -Center.x * SxCos - Center.y * SySin + Translation.x;\r
+ float Ty = Center.x * SxSin - Center.y * SyCos + Translation.y;\r
+\r
+ myData[0] = SxCos; myData[4] = SySin; myData[8] = 0.f; myData[12] = Tx;\r
+ myData[1] = -SxSin; myData[5] = SyCos; myData[9] = 0.f; myData[13] = Ty;\r
+ myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f;\r
+ myData[3] = 0.f; myData[7] = 0.f; myData[11] = 0.f; myData[15] = 1.f;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Transform a point by the matrix\r
+////////////////////////////////////////////////////////////\r
+inline Vector2f Matrix3::Transform(const Vector2f& Point) const\r
+{\r
+ return Vector2f(myData[0] * Point.x + myData[4] * Point.y + myData[12],\r
+ myData[1] * Point.x + myData[5] * Point.y + myData[13]);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Return the inverse of the matrix\r
+////////////////////////////////////////////////////////////\r
+inline Matrix3 Matrix3::GetInverse() const\r
+{\r
+ // Compute the determinant\r
+ float Det = myData[0] * (myData[15] * myData[5] - myData[7] * myData[13]) -\r
+ myData[1] * (myData[15] * myData[4] - myData[7] * myData[12]) +\r
+ myData[3] * (myData[13] * myData[4] - myData[5] * myData[12]);\r
+\r
+ // Compute the inverse if determinant is not zero\r
+ if ((Det < -1E-7f) || (Det > 1E-7f))\r
+ {\r
+ return Matrix3( (myData[15] * myData[5] - myData[7] * myData[13]) / Det,\r
+ -(myData[15] * myData[4] - myData[7] * myData[12]) / Det,\r
+ (myData[13] * myData[4] - myData[5] * myData[12]) / Det,\r
+ -(myData[15] * myData[1] - myData[3] * myData[13]) / Det,\r
+ (myData[15] * myData[0] - myData[3] * myData[12]) / Det,\r
+ -(myData[13] * myData[0] - myData[1] * myData[12]) / Det,\r
+ (myData[7] * myData[1] - myData[3] * myData[5]) / Det,\r
+ -(myData[7] * myData[0] - myData[3] * myData[4]) / Det,\r
+ (myData[5] * myData[0] - myData[1] * myData[4]) / Det);\r
+ }\r
+ else\r
+ {\r
+ return Identity;\r
+ }\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Return the elements of the matrix as a 4x4,\r
+/// in an array of 16 floats\r
+////////////////////////////////////////////////////////////\r
+inline const float* Matrix3::Get4x4Elements() const\r
+{\r
+ return myData;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator () overloads to access the matrix elements\r
+////////////////////////////////////////////////////////////\r
+inline float Matrix3::operator ()(unsigned int Row, unsigned int Col) const\r
+{\r
+ switch (Row + Col * 3)\r
+ {\r
+ case 0 : return myData[0];\r
+ case 1 : return myData[1];\r
+ case 2 : return myData[3];\r
+ case 3 : return myData[4];\r
+ case 4 : return myData[5];\r
+ case 5 : return myData[7];\r
+ case 6 : return myData[12];\r
+ case 7 : return myData[13];\r
+ case 8 : return myData[15];\r
+\r
+ default : return myData[0];\r
+ }\r
+}\r
+inline float& Matrix3::operator ()(unsigned int Row, unsigned int Col)\r
+{\r
+ switch (Row + Col * 3)\r
+ {\r
+ case 0 : return myData[0];\r
+ case 1 : return myData[1];\r
+ case 2 : return myData[3];\r
+ case 3 : return myData[4];\r
+ case 4 : return myData[5];\r
+ case 5 : return myData[7];\r
+ case 6 : return myData[12];\r
+ case 7 : return myData[13];\r
+ case 8 : return myData[15];\r
+\r
+ default : return myData[0];\r
+ }\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload to multiply two matrices\r
+////////////////////////////////////////////////////////////\r
+inline Matrix3 Matrix3::operator *(const Matrix3& Mat) const\r
+{\r
+ return Matrix3(myData[0] * Mat.myData[0] + myData[4] * Mat.myData[1] + myData[12] * Mat.myData[3],\r
+ myData[0] * Mat.myData[4] + myData[4] * Mat.myData[5] + myData[12] * Mat.myData[7],\r
+ myData[0] * Mat.myData[12] + myData[4] * Mat.myData[13] + myData[12] * Mat.myData[15],\r
+ myData[1] * Mat.myData[0] + myData[5] * Mat.myData[1] + myData[13] * Mat.myData[3],\r
+ myData[1] * Mat.myData[4] + myData[5] * Mat.myData[5] + myData[13] * Mat.myData[7],\r
+ myData[1] * Mat.myData[12] + myData[5] * Mat.myData[13] + myData[13] * Mat.myData[15],\r
+ myData[3] * Mat.myData[0] + myData[7] * Mat.myData[1] + myData[15] * Mat.myData[3],\r
+ myData[3] * Mat.myData[4] + myData[7] * Mat.myData[5] + myData[15] * Mat.myData[7],\r
+ myData[3] * Mat.myData[12] + myData[7] * Mat.myData[13] + myData[15] * Mat.myData[15]);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator *= overload to multiply-assign two matrices\r
+////////////////////////////////////////////////////////////\r
+inline Matrix3& Matrix3::operator *=(const Matrix3& Mat)\r
+{\r
+ return *this = *this * Mat;\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_POSTFX_HPP\r
+#define SFML_POSTFX_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Graphics/Drawable.hpp>\r
+#include <SFML/Graphics/Image.hpp>\r
+#include <istream>\r
+#include <map>\r
+#include <string>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// PostFX is used to apply a post effect to a window\r
+////////////////////////////////////////////////////////////\r
+class SFML_API PostFX : public Drawable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ PostFX();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor\r
+ ///\r
+ /// \param Copy : Instance to copy\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ PostFX(const PostFX& Copy);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~PostFX();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the effect from a file\r
+ ///\r
+ /// \param Filename : Path of the effect file to load\r
+ ///\r
+ /// \return True on success\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromFile(const std::string& Filename);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Load the effect from a text in memory\r
+ ///\r
+ /// \param Effect : String containing the effect code\r
+ ///\r
+ /// \return True on success\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool LoadFromMemory(const std::string& Effect);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change a parameter of the effect (1 float)\r
+ ///\r
+ /// \param Name : Parameter name in the effect\r
+ /// \param X : Value to assign\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetParameter(const std::string& Name, float X);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change a parameter of the effect (2 floats)\r
+ ///\r
+ /// \param Name : Parameter name in the effect\r
+ /// \param X, Y : Values to assign\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetParameter(const std::string& Name, float X, float Y);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change a parameter of the effect (3 floats)\r
+ ///\r
+ /// \param Name : Parameter name in the effect\r
+ /// \param X, Y, Z : Values to assign\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetParameter(const std::string& Name, float X, float Y, float Z);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change a parameter of the effect (4 floats)\r
+ ///\r
+ /// \param Name : Parameter name in the effect\r
+ /// \param X, Y, Z, W : Values to assign\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetParameter(const std::string& Name, float X, float Y, float Z, float W);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set a texture parameter\r
+ ///\r
+ /// \param Name : Texture name in the effect\r
+ /// \param Texture : Image to set (pass NULL to use content of current framebuffer)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetTexture(const std::string& Name, Image* Texture);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator\r
+ ///\r
+ /// \param Other : Instance to assign\r
+ ///\r
+ /// \return Reference to the post-effect\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ PostFX& operator =(const PostFX& Other);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell whether or not the system supports post-effects\r
+ ///\r
+ /// \return True if the system can use post-effects\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static bool CanUsePostFX();\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see Drawable::Render\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Render(RenderTarget& Target) const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Preprocess a SFML effect file\r
+ /// to convert it to a valid GLSL fragment shader\r
+ ///\r
+ /// \param File : Stream containing the code to process\r
+ ///\r
+ /// \return Valid fragment shader source code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static std::string PreprocessEffect(std::istream& File);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create the program and attach the shaders\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void CreateProgram();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Types\r
+ ////////////////////////////////////////////////////////////\r
+ typedef std::map<std::string, const Image*> TextureTable;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int myShaderProgram; ///< OpenGL identifier for the program\r
+ TextureTable myTextures; ///< Texture variables in the effect\r
+ std::string myFragmentShader; ///< Fragment shader source code\r
+ mutable Image myFrameBuffer; ///< Texture containing the current frame buffer\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_POSTFX_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_RECT_HPP\r
+#define SFML_RECT_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <algorithm>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Rect is an utility class for manipulating rectangles.\r
+/// Template parameter defines the type of coordinates (integer, float, ...)\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+class Rect\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Rect();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the rectangle from its coordinates\r
+ ///\r
+ /// \param LeftCoord : Left coordinate of the rectangle\r
+ /// \param TopCoord : Top coordinate of the rectangle\r
+ /// \param RightCoord : Right coordinate of the rectangle\r
+ /// \param BottomCoord : Bottom coordinate of the rectangle\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the width of the rectangle\r
+ ///\r
+ /// \return Width of rectangle\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ T GetWidth() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the height of the rectangle\r
+ ///\r
+ /// \return Height of rectangle\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ T GetHeight() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Move the whole rectangle by the given offset\r
+ ///\r
+ /// \param OffsetX : Horizontal offset\r
+ /// \param OffsetY : Vertical offset\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Offset(T OffsetX, T OffsetY);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Check if a point is inside the rectangle's area\r
+ ///\r
+ /// \param X : X coordinate of the point to test\r
+ /// \param Y : Y coordinate of the point to test\r
+ ///\r
+ /// \return True if the point is inside\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Contains(T X, T Y) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Check intersection between two rectangles\r
+ ///\r
+ /// \param Rectangle : Rectangle to test\r
+ /// \param OverlappingRect : Rectangle to be filled with overlapping rect (NULL by default)\r
+ ///\r
+ /// \return True if rectangles overlap\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect = NULL) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ T Left; ///< Left coordinate of the rectangle\r
+ T Top; ///< Top coordinate of the rectangle\r
+ T Right; ///< Right coordinate of the rectangle\r
+ T Bottom; ///< Bottom coordinate of the rectangle\r
+};\r
+\r
+#include <SFML/Graphics/Rect.inl>\r
+\r
+// Define the most common types\r
+typedef Rect<int> IntRect;\r
+typedef Rect<float> FloatRect;\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_RECT_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Default constructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Rect<T>::Rect() :\r
+Left (0),\r
+Top (0),\r
+Right (0),\r
+Bottom(0)\r
+{\r
+\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Construct the color from its coordinates\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Rect<T>::Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord) :\r
+Left (LeftCoord),\r
+Top (TopCoord),\r
+Right (RightCoord),\r
+Bottom(BottomCoord)\r
+{\r
+\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Get the width of the rectangle\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+T Rect<T>::GetWidth() const\r
+{\r
+ return Right - Left;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Get the height of the rectangle\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+T Rect<T>::GetHeight() const\r
+{\r
+ return Bottom - Top;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Move the whole rectangle by the given offset\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+void Rect<T>::Offset(T OffsetX, T OffsetY)\r
+{\r
+ Left += OffsetX;\r
+ Right += OffsetX;\r
+ Top += OffsetY;\r
+ Bottom += OffsetY;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Check if a point is inside the rectangle's area\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool Rect<T>::Contains(T X, T Y) const\r
+{\r
+ return (X >= Left) && (X <= Right) && (Y >= Top) && (Y <= Bottom);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Check intersection between two rectangles\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool Rect<T>::Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect) const\r
+{\r
+ // Compute overlapping rect\r
+ Rect Overlapping(std::max(Left, Rectangle.Left),\r
+ std::max(Top, Rectangle.Top),\r
+ std::min(Right, Rectangle.Right),\r
+ std::min(Bottom, Rectangle.Bottom));\r
+\r
+ // If overlapping rect is valid, then there is intersection\r
+ if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom))\r
+ {\r
+ if (OverlappingRect)\r
+ *OverlappingRect = Overlapping;\r
+ return true;\r
+ }\r
+ else\r
+ {\r
+ if (OverlappingRect)\r
+ *OverlappingRect = Rect(0, 0, 0, 0);\r
+ return false;\r
+ }\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_RENDERTARGET_HPP\r
+#define SFML_RENDERTARGET_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Graphics/Color.hpp>\r
+#include <SFML/Graphics/View.hpp>\r
+#include <SFML/Graphics/Rect.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+class Drawable;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Base class for all render targets (window, image, ...)\r
+////////////////////////////////////////////////////////////\r
+class SFML_API RenderTarget\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~RenderTarget();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Clear the entire target with a single color\r
+ ///\r
+ /// \param FillColor : Color to use to clear the render target\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Clear(const Color& FillColor = Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Draw something into the target\r
+ ///\r
+ /// \param Object : Object to draw\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Draw(const Drawable& Object);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the width of the rendering region of the target\r
+ ///\r
+ /// \return Width in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual unsigned int GetWidth() const = 0;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the height of the rendering region of the target\r
+ ///\r
+ /// \return Height in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual unsigned int GetHeight() const = 0;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the current active view.\r
+ ///\r
+ /// \param NewView : New view to use (pass GetDefaultView() to set the default view)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetView(const View& NewView);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current view\r
+ ///\r
+ /// \return Current view active in the window\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const View& GetView() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the default view of the window for read / write\r
+ ///\r
+ /// \return Default view\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ View& GetDefaultView();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell SFML to preserve external OpenGL states, at the expense of\r
+ /// more CPU charge. Use this function if you don't want SFML\r
+ /// to mess up your own OpenGL states (if any).\r
+ /// Don't enable state preservation if not needed, as it will allow\r
+ /// SFML to do internal optimizations and improve performances.\r
+ /// This parameter is false by default\r
+ ///\r
+ /// \param Preserve : True to preserve OpenGL states, false to let SFML optimize\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void PreserveOpenGLStates(bool Preserve);\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ RenderTarget();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Called by the derived class when it's ready to be initialized\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Initialize();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Activate the target for rendering\r
+ ///\r
+ /// \param Active : True to activate rendering, false to deactivate\r
+ ///\r
+ /// \return True if activation succeeded\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool Activate(bool Active) = 0;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the OpenGL render states needed for the SFML rendering\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetRenderStates();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ View myDefaultView; ///< Default view\r
+ const View* myCurrentView; ///< Current active view\r
+ bool myPreserveStates; ///< Should we preserve external OpenGL states ?\r
+ bool myIsDrawing; ///< True when Draw is called from inside, to allow some renderstates optimizations\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_RENDERTARGET_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_RENDERWINDOW_HPP\r
+#define SFML_RENDERWINDOW_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Graphics/Image.hpp>\r
+#include <SFML/Graphics/RenderTarget.hpp>\r
+#include <SFML/Window/Window.hpp>\r
+#include <string>\r
+\r
+\r
+namespace sf\r
+{\r
+class Drawable;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Simple wrapper for sf::Window that allows easy\r
+/// 2D rendering\r
+////////////////////////////////////////////////////////////\r
+class SFML_API RenderWindow : public Window, public RenderTarget\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ RenderWindow();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the window\r
+ ///\r
+ /// \param Mode : Video mode to use\r
+ /// \param Title : Title of the window\r
+ /// \param WindowStyle : Window style, see sf::Style (Resize | Close by default)\r
+ /// \param Params : Creation parameters (see default constructor for default values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the window from an existing control\r
+ ///\r
+ /// \param Handle : Platform-specific handle of the control\r
+ /// \param Params : Creation parameters (see default constructor for default values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ RenderWindow(WindowHandle Handle, const WindowSettings& Params = WindowSettings());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~RenderWindow();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the width of the rendering region of the window\r
+ ///\r
+ /// \return Width in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual unsigned int GetWidth() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the height of the rendering region of the window\r
+ ///\r
+ /// \return Height in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual unsigned int GetHeight() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Save the content of the window to an image\r
+ ///\r
+ /// \return Image instance containing the contents of the screen\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Image Capture() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Convert a point in window coordinates into view coordinates\r
+ ///\r
+ /// \param WindowX : X coordinate of the point to convert, relative to the window\r
+ /// \param WindowY : Y coordinate of the point to convert, relative to the window\r
+ /// \param TargetView : Target view to convert the point to (NULL by default -- uses the current view)\r
+ ///\r
+ /// \return Converted point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View* TargetView = NULL) const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see Window::OnCreate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnCreate();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see RenderTarget::Activate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual bool Activate(bool Active);\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_RENDERWINDOW_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SHAPE_HPP\r
+#define SFML_SHAPE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Graphics/Drawable.hpp>\r
+#include <SFML/System/Vector2.hpp>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Shape defines a drawable convex shape ; it also defines\r
+/// helper functions to draw simple shapes like\r
+/// lines, rectangles, circles, etc.\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Shape : public sf::Drawable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Shape();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Add a point to the shape\r
+ ///\r
+ /// \param X, Y : Position of the point\r
+ /// \param Col : Color of the point (white by default)\r
+ /// \param OutlineCol : Outline color of the point (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Add a point to the shape\r
+ ///\r
+ /// \param Position : Position of the point\r
+ /// \param Col : Color of the point (white by default)\r
+ /// \param OutlineCol : Outline color of the point (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void AddPoint(const Vector2f& Position, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the number of points composing the shape\r
+ ///\r
+ /// \param Total number of points\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetNbPoints() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enable or disable filling the shape.\r
+ /// Fill is enabled by default\r
+ ///\r
+ /// \param Enable : True to enable, false to disable\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void EnableFill(bool Enable);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enable or disable drawing the shape outline.\r
+ /// Outline is enabled by default\r
+ ///\r
+ /// \param Enable : True to enable, false to disable\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void EnableOutline(bool Enable);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the position of a point\r
+ ///\r
+ /// \param Index : Index of the point, in range [0, GetNbPoints() - 1]\r
+ /// \param Position : New position of the Index-th point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPointPosition(unsigned int Index, const Vector2f& Position);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the position of a point\r
+ ///\r
+ /// \param Index : Index of the point, in range [0, GetNbPoints() - 1]\r
+ /// \param X : New X coordinate of the Index-th point\r
+ /// \param Y : New Y coordinate of the Index-th point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPointPosition(unsigned int Index, float X, float Y);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the color of a point\r
+ ///\r
+ /// \param Index : Index of the point, in range [0, GetNbPoints() - 1]\r
+ /// \param Col : New color of the Index-th point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPointColor(unsigned int Index, const Color& Col);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the outline color of a point\r
+ ///\r
+ /// \param Index : Index of the point, in range [0, GetNbPoints() - 1]\r
+ /// \param OutlineCol : New outline color of the Index-th point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPointOutlineColor(unsigned int Index, const Color& OutlineCol);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the width of the shape outline\r
+ ///\r
+ /// \param Width : New width\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetOutlineWidth(float Width);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the position of a point\r
+ ///\r
+ /// \param Index : Index of the point, in range [0, GetNbPoints() - 1]\r
+ ///\r
+ /// \return Position of the Index-th point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Vector2f& GetPointPosition(unsigned int Index) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the color of a point\r
+ ///\r
+ /// \param Index : Index of the point, in range [0, GetNbPoints() - 1]\r
+ ///\r
+ /// \return Color of the Index-th point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Color& GetPointColor(unsigned int Index) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the outline color of a point\r
+ ///\r
+ /// \param Index : Index of the point, in range [0, GetNbPoints() - 1]\r
+ ///\r
+ /// \return Outline color of the Index-th point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Color& GetPointOutlineColor(unsigned int Index) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the width of the shape outline\r
+ ///\r
+ /// \return Current outline width\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetOutlineWidth() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create a shape made of a single line (use floats)\r
+ ///\r
+ /// \param P1X, P1Y : Position of the first point\r
+ /// \param P2X, P2Y : Position second point\r
+ /// \param Thickness : Line thickness\r
+ /// \param Col : Color used to draw the line\r
+ /// \param Outline : Outline width (0 by default)\r
+ /// \param OutlineCol : Color used to draw the outline (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Shape Line(float P1X, float P1Y, float P2X, float P2Y, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create a shape made of a single line (use vectors)\r
+ ///\r
+ /// \param P1X, P1Y : Position of the first point\r
+ /// \param P2X, P2Y : Position second point\r
+ /// \param Thickness : Line thickness\r
+ /// \param Col : Color used to draw the line\r
+ /// \param Outline : Outline width (0 by default)\r
+ /// \param OutlineCol : Color used to draw the outline (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Shape Line(const Vector2f& P1, const Vector2f& P2, float Thickness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create a shape made of a single rectangle (use floats)\r
+ ///\r
+ /// \param P1X, P1Y : Position of the first point\r
+ /// \param P2X, P2Y : Position second point\r
+ /// \param Col : Color used to fill the rectangle\r
+ /// \param Outline : Outline width (0 by default)\r
+ /// \param OutlineCol : Color used to draw the outline (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Shape Rectangle(float P1X, float P1Y, float P2X, float P2Y, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create a shape made of a single rectangle (use vectors)\r
+ ///\r
+ /// \param P1 : Position of the first point\r
+ /// \param P2 : Position second point\r
+ /// \param Col : Color used to fill the rectangle\r
+ /// \param Outline : Outline width (0 by default)\r
+ /// \param OutlineCol : Color used to draw the outline (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Shape Rectangle(const Vector2f& P1, const Vector2f& P2, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create a shape made of a single circle (use floats)\r
+ ///\r
+ /// \param X, Y : Position of the center\r
+ /// \param Radius : Radius\r
+ /// \param Col : Color used to fill the circle\r
+ /// \param Outline : Outline width (0 by default)\r
+ /// \param OutlineCol : Color used to draw the outline (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Shape Circle(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create a shape made of a single circle (use vectors)\r
+ ///\r
+ /// \param Center : Position of the center\r
+ /// \param Radius : Radius\r
+ /// \param Col : Color used to fill the circle\r
+ /// \param Outline : Outline width (0 by default)\r
+ /// \param OutlineCol : Color used to draw the outline (black by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Shape Circle(const Vector2f& Center, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0));\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see Drawable::Render\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Render(RenderTarget& Target) const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Compile the shape : compute its center and its outline\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Compile();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Compute the normal of a given 2D segment\r
+ ///\r
+ /// \param P1 : First point of the segment\r
+ /// \param P2 : Second point of the segment\r
+ /// \param Normal : Calculated normal\r
+ ///\r
+ /// \return False if the normal couldn't be calculated (segment is null)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static bool ComputeNormal(const Vector2f& P1, const Vector2f& P2, Vector2f& Normal);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Defines a simple 2D point\r
+ ////////////////////////////////////////////////////////////\r
+ struct Point\r
+ {\r
+ Point(const Vector2f& Pos = Vector2f(0, 0), const Color& C = Color(255, 255, 255), const Color& OutlineC = Color(255, 255, 255));\r
+\r
+ Vector2f Position; ///< Position\r
+ Vector2f Normal; ///< Extruded normal\r
+ Color Col; ///< Color of the point\r
+ Color OutlineCol; ///< Outline color of the point\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ std::vector<Point> myPoints; ///< Points composing the shape\r
+ float myOutline; ///< Outline width\r
+ bool myIsFillEnabled; ///< Should we draw the inside if the shape ?\r
+ bool myIsOutlineEnabled; ///< Should we draw the outline if the shape ?\r
+ bool myIsCompiled; ///< Compiled state of the shape\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SHAPE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SPRITE_HPP\r
+#define SFML_SPRITE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Resource.hpp>\r
+#include <SFML/Graphics/Drawable.hpp>\r
+#include <SFML/Graphics/Rect.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+class Image;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Sprite defines a sprite : texture, transformations,\r
+/// color, and draw on screen\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Sprite : public Drawable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Sprite();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the sprite from a source image\r
+ ///\r
+ /// \param Img : Image of the sprite\r
+ /// \param Position : Position of the sprite (0, 0 by default)\r
+ /// \param Scale : Scale factor (1, 1 by default)\r
+ /// \param Rotation : Orientation, in degrees (0 by default)\r
+ /// \param Col : Color of the sprite (white by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ explicit Sprite(const Image& Img, const Vector2f& Position = Vector2f(0, 0), const Vector2f& Scale = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 255, 255, 255));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the image of the sprite\r
+ ///\r
+ /// \param Img : New image\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetImage(const Image& Img);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the sub-rectangle of the sprite inside the source image.\r
+ /// By default, the subrect covers the entire source image\r
+ ///\r
+ /// \param SubRect : New sub-rectangle\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetSubRect(const IntRect& SubRect);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Resize the sprite (by changing its scale factors) (take 2 values).\r
+ /// The default size is defined by the subrect\r
+ ///\r
+ /// \param Width : New width (must be strictly positive)\r
+ /// \param Height : New height (must be strictly positive)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Resize(float Width, float Height);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Resize the sprite (by changing its scale factors) (take a 2D vector).\r
+ /// The default size is defined by the subrect\r
+ ///\r
+ /// \param Size : New size (both coordinates must be strictly positive)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Resize(const Vector2f& Size);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Flip the sprite horizontally\r
+ ///\r
+ /// \param Flipped : True to flip the sprite\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void FlipX(bool Flipped);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Flip the sprite vertically\r
+ ///\r
+ /// \param Flipped : True to flip the sprite\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void FlipY(bool Flipped);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the source image of the sprite\r
+ ///\r
+ /// \return Pointer to the image (can be NULL)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Image* GetImage() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the sub-rectangle of the sprite inside the source image\r
+ ///\r
+ /// \return Sub-rectangle\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const IntRect& GetSubRect() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the sprite size\r
+ ///\r
+ /// \return Size of the sprite\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Vector2f GetSize() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the color of a given pixel in the sprite\r
+ /// (point is in local coordinates)\r
+ ///\r
+ /// \param X : X coordinate of the pixel to get\r
+ /// \param Y : Y coordinate of the pixel to get\r
+ ///\r
+ /// \return Color of pixel (X, Y)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Color GetPixel(unsigned int X, unsigned int Y) const;\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see Drawable::Render\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Render(RenderTarget& Target) const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ ResourcePtr<Image> myImage; ///< Image used to draw the sprite\r
+ IntRect mySubRect; ///< Sub-rectangle of source image to assign to the sprite\r
+ bool myIsFlippedX; ///< Is the sprite flipped on the X axis ?\r
+ bool myIsFlippedY; ///< Is the sprite flipped on the Y axis ?\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SPRITE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_STRING_HPP\r
+#define SFML_STRING_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/Resource.hpp>\r
+#include <SFML/System/Unicode.hpp>\r
+#include <SFML/Graphics/Drawable.hpp>\r
+#include <SFML/Graphics/Font.hpp>\r
+#include <SFML/Graphics/Rect.hpp>\r
+#include <string>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// String defines a graphical 2D text, that can be drawn on screen\r
+////////////////////////////////////////////////////////////\r
+class SFML_API String : public Drawable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enumerate the string drawing styles\r
+ ////////////////////////////////////////////////////////////\r
+ enum Style\r
+ {\r
+ Regular = 0, ///< Regular characters, no style\r
+ Bold = 1 << 0, ///< Characters are bold\r
+ Italic = 1 << 1, ///< Characters are in italic\r
+ Underlined = 1 << 2 ///< Characters are underlined\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ String();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the string from any kind of text\r
+ ///\r
+ /// \param Text : Text assigned to the string\r
+ /// \param Font : Font used to draw the string (SFML built-in font by default)\r
+ /// \param Size : Characters size (30 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ explicit String(const Unicode::Text& Text, const Font& CharFont = Font::GetDefaultFont(), float Size = 30.f);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the text (from any kind of string)\r
+ ///\r
+ /// \param Text : New text\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetText(const Unicode::Text& Text);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the font of the string\r
+ ///\r
+ /// \param Font : Font to use\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetFont(const Font& CharFont);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the size of the string\r
+ /// The default size is 30\r
+ ///\r
+ /// \param Size : New size, in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetSize(float Size);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the style of the text\r
+ /// The default style is Regular\r
+ ///\r
+ /// \param TextStyle : New text style, (combination of Style enum values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetStyle(unsigned long TextStyle);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the text (the returned text can be converted implicitely to any kind of string)\r
+ ///\r
+ /// \return String's text\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Unicode::Text& GetText() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the font used by the string\r
+ ///\r
+ /// \return Font used\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Font& GetFont() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the size of the characters\r
+ ///\r
+ /// \return Size of the characters\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetSize() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the style of the text\r
+ ///\r
+ /// \return Current string style (combination of Style enum values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned long GetStyle() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the visual position of the Index-th character of the string,\r
+ /// in coordinates relative to the string\r
+ /// (note : translation, center, rotation and scale are not applied)\r
+ ///\r
+ /// \param Index : Index of the character\r
+ ///\r
+ /// \return Position of the Index-th character (end of string if Index is out of range)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ sf::Vector2f GetCharacterPos(std::size_t Index) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the string rectangle on screen\r
+ ///\r
+ /// \return Rectangle contaning the string in screen coordinates\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ FloatRect GetRect() const;\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see Drawable::Render\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Render(RenderTarget& Target) const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Recompute the bounding rectangle of the text\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void RecomputeRect();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ Unicode::Text myText; ///< Text to display\r
+ ResourcePtr<Font> myFont; ///< Font used to display the string\r
+ float mySize; ///< Size of the characters\r
+ unsigned long myStyle; ///< Text style (see Style enum)\r
+ FloatRect myBaseRect; ///< Bounding rectangle of the text in object coordinates\r
+ bool myNeedRectUpdate; ///< Does the bounding rect need an update ?\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_STRING_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_VIEW_HPP\r
+#define SFML_VIEW_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <SFML/Graphics/Rect.hpp>\r
+#include <SFML/Graphics/Matrix3.hpp>\r
+#include <SFML/System/Vector2.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+class RenderTarget;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// This class defines a view (position, size, etc.) ;\r
+/// you can consider it as a 2D camera\r
+////////////////////////////////////////////////////////////\r
+class SFML_API View\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the view from a rectangle\r
+ ///\r
+ /// \param ViewRect : Rectangle defining the position and size of the view (1000x1000 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ explicit View(const FloatRect& ViewRect = FloatRect(0, 0, 1000, 1000));\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the view from its center and half-size\r
+ ///\r
+ /// \param Center : Center of the view\r
+ /// \param HalfSize : Half-size of the view (from center to corner)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ View(const sf::Vector2f& Center, const sf::Vector2f& HalfSize);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the center of the view (take 2 values)\r
+ ///\r
+ /// \param X : X coordinate of the new center\r
+ /// \param Y : Y coordinate of the new center\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetCenter(float X, float Y);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the center of the view (take a vector)\r
+ ///\r
+ /// \param Center : New center\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetCenter(const sf::Vector2f& Center);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the half-size of the view (take 2 values)\r
+ ///\r
+ /// \param HalfWidth : New half-width\r
+ /// \param HalfHeight : New half-height\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetHalfSize(float HalfWidth, float HalfHeight);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the half-size of the view (take a vector)\r
+ ///\r
+ /// \param HalfSize : New half-size\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetHalfSize(const sf::Vector2f& HalfSize);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Rebuild the view from a rectangle\r
+ ///\r
+ /// \param ViewRect : Rectangle defining the position and size of the view\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetFromRect(const FloatRect& ViewRect);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the center of the view\r
+ ///\r
+ /// \return Center of the view\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const sf::Vector2f& GetCenter() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the half-size of the view\r
+ ///\r
+ /// \return Half-size of the view\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const sf::Vector2f& GetHalfSize() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the bounding rectangle of the view\r
+ ///\r
+ /// \return Bounding rectangle of the view\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const sf::FloatRect& GetRect() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Move the view (take 2 values)\r
+ ///\r
+ /// \param OffsetX : Offset to move the view, on X axis\r
+ /// \param OffsetY : Offset to move the view, on Y axis\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Move(float OffsetX, float OffsetY);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Move the view (take a vector)\r
+ ///\r
+ /// \param Offset : Offset to move the view\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Move(const sf::Vector2f& Offset);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Resize the view rectangle to simulate a zoom / unzoom effect\r
+ ///\r
+ /// \param Factor : Zoom factor to apply, relative to the current zoom\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Zoom(float Factor);\r
+\r
+private :\r
+\r
+ friend class RenderTarget;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the projection matrix of the view\r
+ ///\r
+ /// \return Projection matrix containing the view settings\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Matrix3& GetMatrix() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Recompute the view rectangle and the projection matrix\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void RecomputeMatrix();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ sf::Vector2f myCenter; ///< Center of the view\r
+ sf::Vector2f myHalfSize; ///< Half-size of the view\r
+ FloatRect myRect; ///< Rectangle defining the bounds of the view\r
+ Matrix3 myMatrix; ///< Precomputed projection matrix corresponding to the view\r
+ bool myNeedUpdate; ///< Internal state telling if the matrix needs to be updated\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_VIEW_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_FTP_HPP\r
+#define SFML_FTP_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <SFML/Network/SocketTCP.hpp>\r
+#include <string>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+class IPAddress;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// This class provides methods for manipulating the FTP\r
+/// protocol (described in RFC 959).\r
+/// It provides easy access and transfers to remote\r
+/// directories and files on a FTP server\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Ftp : NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enumeration of transfer modes\r
+ ////////////////////////////////////////////////////////////\r
+ enum TransferMode\r
+ {\r
+ Binary, ///< Binary mode (file is transfered as a sequence of bytes)\r
+ Ascii, ///< Text mode using ASCII encoding\r
+ Ebcdic ///< Text mode using EBCDIC encoding\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// This class wraps a FTP response, which is basically :\r
+ /// - a status code\r
+ /// - a message\r
+ ////////////////////////////////////////////////////////////\r
+ class SFML_API Response\r
+ {\r
+ public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enumerate all the valid status codes returned in\r
+ /// a FTP response\r
+ ////////////////////////////////////////////////////////////\r
+ enum Status\r
+ {\r
+ // 1xx: the requested action is being initiated,\r
+ // expect another reply before proceeding with a new command\r
+ RestartMarkerReply = 110, ///< Restart marker reply\r
+ ServiceReadySoon = 120, ///< Service ready in N minutes\r
+ DataConnectionAlreadyOpened = 125, ///< Data connection already opened, transfer starting\r
+ OpeningDataConnection = 150, ///< File status ok, about to open data connection\r
+\r
+ // 2xx: the requested action has been successfully completed\r
+ Ok = 200, ///< Command ok\r
+ PointlessCommand = 202, ///< Command not implemented\r
+ SystemStatus = 211, ///< System status, or system help reply\r
+ DirectoryStatus = 212, ///< Directory status\r
+ FileStatus = 213, ///< File status\r
+ HelpMessage = 214, ///< Help message\r
+ SystemType = 215, ///< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document\r
+ ServiceReady = 220, ///< Service ready for new user\r
+ ClosingConnection = 221, ///< Service closing control connection\r
+ DataConnectionOpened = 225, ///< Data connection open, no transfer in progress\r
+ ClosingDataConnection = 226, ///< Closing data connection, requested file action successful\r
+ EnteringPassiveMode = 227, ///< Entering passive mode\r
+ LoggedIn = 230, ///< User logged in, proceed. Logged out if appropriate\r
+ FileActionOk = 250, ///< Requested file action ok\r
+ DirectoryOk = 257, ///< PATHNAME created\r
+\r
+ // 3xx: the command has been accepted, but the requested action\r
+ // is dormant, pending receipt of further information\r
+ NeedPassword = 331, ///< User name ok, need password\r
+ NeedAccountToLogIn = 332, ///< Need account for login\r
+ NeedInformation = 350, ///< Requested file action pending further information\r
+\r
+ // 4xx: the command was not accepted and the requested action did not take place,\r
+ // but the error condition is temporary and the action may be requested again\r
+ ServiceUnavailable = 421, ///< Service not available, closing control connection\r
+ DataConnectionUnavailable = 425, ///< Can't open data connection\r
+ TransferAborted = 426, ///< Connection closed, transfer aborted\r
+ FileActionAborted = 450, ///< Requested file action not taken\r
+ LocalError = 451, ///< Requested action aborted, local error in processing\r
+ InsufficientStorageSpace = 452, ///< Requested action not taken; insufficient storage space in system, file unavailable\r
+\r
+ // 5xx: the command was not accepted and\r
+ // the requested action did not take place\r
+ CommandUnknown = 500, ///< Syntax error, command unrecognized\r
+ ParametersUnknown = 501, ///< Syntax error in parameters or arguments\r
+ CommandNotImplemented = 502, ///< Command not implemented\r
+ BadCommandSequence = 503, ///< Bad sequence of commands\r
+ ParameterNotImplemented = 504, ///< Command not implemented for that parameter\r
+ NotLoggedIn = 530, ///< Not logged in\r
+ NeedAccountToStore = 532, ///< Need account for storing files\r
+ FileUnavailable = 550, ///< Requested action not taken, file unavailable\r
+ PageTypeUnknown = 551, ///< Requested action aborted, page type unknown\r
+ NotEnoughMemory = 552, ///< Requested file action aborted, exceeded storage allocation\r
+ FilenameNotAllowed = 553, ///< Requested action not taken, file name not allowed\r
+\r
+ // 10xx: SFML custom codes\r
+ InvalidResponse = 1000, ///< Response is not a valid FTP one\r
+ ConnectionFailed = 1001, ///< Connection with server failed\r
+ ConnectionClosed = 1002, ///< Connection with server closed\r
+ InvalidFile = 1003 ///< Invalid file to upload / download\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ /// \param Code : Response status code (InvalidResponse by default)\r
+ /// \param Message : Response message (empty by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response(Status Code = InvalidResponse, const std::string& Message = "");\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Convenience function to check if the response status code\r
+ /// means a success\r
+ ///\r
+ /// \return True if status is success (code < 400)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsOk() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the response status code\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Status GetStatus() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the full message contained in the response\r
+ ///\r
+ /// \return The response message\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const std::string& GetMessage() const;\r
+\r
+ private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ Status myStatus; ///< Status code returned from the server\r
+ std::string myMessage; ///< Last message received from the server\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Specialization of FTP response returning a directory\r
+ ////////////////////////////////////////////////////////////\r
+ class SFML_API DirectoryResponse : public Response\r
+ {\r
+ public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ /// \param Resp : Source response\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ DirectoryResponse(Response Resp);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the directory returned in the response\r
+ ///\r
+ /// \return Directory name\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const std::string& GetDirectory() const;\r
+\r
+ private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ std::string myDirectory; ///< Directory extracted from the response message\r
+ };\r
+\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Specialization of FTP response returning a filename lisiting\r
+ ////////////////////////////////////////////////////////////\r
+ class SFML_API ListingResponse : public Response\r
+ {\r
+ public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ /// \param Resp : Source response\r
+ /// \param Data : Data containing the raw listing\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ListingResponse(Response Resp, const std::vector<char>& Data);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the number of filenames in the listing\r
+ ///\r
+ /// \return Total number of filenames\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ std::size_t GetCount() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the Index-th filename in the directory\r
+ ///\r
+ /// \param Index : Index of the filename to get\r
+ ///\r
+ /// \return Index-th filename\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const std::string& GetFilename(std::size_t Index) const;\r
+\r
+ private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ std::vector<std::string> myFilenames; ///< Filenames extracted from the data\r
+ };\r
+\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor -- close the connection with the server\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Ftp();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Connect to the specified FTP server\r
+ ///\r
+ /// \param Server : FTP server to connect to\r
+ /// \param Port : Port used for connection (21 by default, standard FTP port)\r
+ /// \param Timeout : Maximum time to wait, in seconds (0 by default, means no timeout)\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response Connect(const IPAddress& Server, unsigned short Port = 21, float Timeout = 0.f);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Log in using anonymous account\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response Login();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Log in using a username and a password\r
+ ///\r
+ /// \param UserName : User name\r
+ /// \param Password : Password\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response Login(const std::string& UserName, const std::string& Password);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Close the connection with FTP server\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response Disconnect();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Send a null command just to prevent from being disconnected\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response KeepAlive();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current working directory\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ DirectoryResponse GetWorkingDirectory();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the contents of the given directory\r
+ /// (subdirectories and files)\r
+ ///\r
+ /// \param Directory : Directory to list ("" by default, the current one)\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ListingResponse GetDirectoryListing(const std::string& Directory = "");\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the current working directory\r
+ ///\r
+ /// \param Directory : New directory, relative to the current one\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response ChangeDirectory(const std::string& Directory);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Go to the parent directory of the current one\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response ParentDirectory();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create a new directory\r
+ ///\r
+ /// \param Name : Name of the directory to create\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response MakeDirectory(const std::string& Name);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Remove an existing directory\r
+ ///\r
+ /// \param Name : Name of the directory to remove\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response DeleteDirectory(const std::string& Name);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Rename a file\r
+ ///\r
+ /// \param File : File to rename\r
+ /// \param NewName : New name\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response RenameFile(const std::string& File, const std::string& NewName);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Remove an existing file\r
+ ///\r
+ /// \param Name : File to remove\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response DeleteFile(const std::string& Name);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Download a file from the server\r
+ ///\r
+ /// \param DistantFile : Path of the distant file to download\r
+ /// \param DestPath : Where to put to file on the local computer\r
+ /// \param Mode : Transfer mode (binary by default)\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response Download(const std::string& DistantFile, const std::string& DestPath, TransferMode Mode = Binary);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Upload a file to the server\r
+ ///\r
+ /// \param LocalFile : Path of the local file to upload\r
+ /// \param DestPath : Where to put to file on the server\r
+ /// \param Mode : Transfer mode (binary by default)\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response Upload(const std::string& LocalFile, const std::string& DestPath, TransferMode Mode = Binary);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Send a command to the FTP server\r
+ ///\r
+ /// \param Command : Command to send\r
+ /// \param Parameter : Command parameter ("" by default)\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response SendCommand(const std::string& Command, const std::string& Parameter = "");\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Receive a response from the server\r
+ /// (usually after a command has been sent)\r
+ ///\r
+ /// \return Server response to the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response GetResponse();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Utility class for exchanging datas with the server\r
+ /// on the data channel\r
+ ////////////////////////////////////////////////////////////\r
+ class DataChannel;\r
+\r
+ friend class DataChannel;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ SocketTCP myCommandSocket; ///< Socket holding the control connection with the server\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_FTP_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_HTTP_HPP\r
+#define SFML_HTTP_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <SFML/Network/IPAddress.hpp>\r
+#include <SFML/Network/SocketTCP.hpp>\r
+#include <map>\r
+#include <string>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// This class provides methods for manipulating the HTTP\r
+/// protocol (described in RFC 1945).\r
+/// It can connect to a website, get its files, send requests, etc.\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Http : NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// This class wraps an HTTP request, which is basically :\r
+ /// - a header with a method, a target URI, and a set of field/value pairs\r
+ /// - an optional body (for POST requests)\r
+ ////////////////////////////////////////////////////////////\r
+ class SFML_API Request\r
+ {\r
+ public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enumerate the available HTTP methods for a request\r
+ ////////////////////////////////////////////////////////////\r
+ enum Method\r
+ {\r
+ Get, ///< Request in get mode, standard method to retrieve a page\r
+ Post, ///< Request in post mode, usually to send data to a page\r
+ Head ///< Request a page's header only\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ /// \param RequestMethod : Method to use for the request (Get by default)\r
+ /// \param URI : Target URI ("/" by default -- index page)\r
+ /// \param Body : Content of the request's body (empty by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Request(Method RequestMethod = Get, const std::string& URI = "/", const std::string& Body = "");\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the value of a field; the field is added if it doesn't exist\r
+ ///\r
+ /// \param Field : Name of the field to set (case-insensitive)\r
+ /// \param Value : Value of the field\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetField(const std::string& Field, const std::string& Value);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the request method.\r
+ /// This parameter is Http::Request::Get by default\r
+ ///\r
+ /// \param RequestMethod : Method to use for the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetMethod(Method RequestMethod);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the target URI of the request.\r
+ /// This parameter is "/" by default\r
+ ///\r
+ /// \param URI : URI to request, local to the host\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetURI(const std::string& URI);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the HTTP version of the request.\r
+ /// This parameter is 1.0 by default\r
+ ///\r
+ /// \param Major : Major version number\r
+ /// \param Minor : Minor version number\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetHttpVersion(unsigned int Major, unsigned int Minor);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the body of the request. This parameter is optional and\r
+ /// makes sense only for POST requests.\r
+ /// This parameter is empty by default\r
+ ///\r
+ /// \param Body : Content of the request body\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetBody(const std::string& Body);\r
+\r
+ private :\r
+\r
+ friend class Http;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the string representation of the request header\r
+ ///\r
+ /// \return String containing the request\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ std::string ToString() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Check if the given field has been defined\r
+ ///\r
+ /// \param Field : Name of the field to check (case-insensitive)\r
+ ///\r
+ /// \return True if the field exists\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool HasField(const std::string& Field) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Types\r
+ ////////////////////////////////////////////////////////////\r
+ typedef std::map<std::string, std::string> FieldTable;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ FieldTable myFields; ///< Fields of the header\r
+ Method myMethod; ///< Method to use for the request\r
+ std::string myURI; ///< Target URI of the request\r
+ unsigned int myMajorVersion; ///< Major HTTP version\r
+ unsigned int myMinorVersion; ///< Minor HTTP version\r
+ std::string myBody; ///< Body of the request\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// This class wraps an HTTP response, which is basically :\r
+ /// - a header with a status code and a set of field/value pairs\r
+ /// - a body (the content of the requested resource)\r
+ ////////////////////////////////////////////////////////////\r
+ class SFML_API Response\r
+ {\r
+ public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enumerate all the valid status codes returned in\r
+ /// a HTTP response\r
+ ////////////////////////////////////////////////////////////\r
+ enum Status\r
+ {\r
+ // 2xx: success\r
+ Ok = 200, ///< Most common code returned when operation was successful\r
+ Created = 201, ///< The resource has successfully been created\r
+ Accepted = 202, ///< The request has been accepted, but will be processed later by the server\r
+ NoContent = 204, ///< Sent when the server didn't send any data in return\r
+\r
+ // 3xx: redirection\r
+ MultipleChoices = 300, ///< The requested page can be accessed from several locations\r
+ MovedPermanently = 301, ///< The requested page has permanently moved to a new location\r
+ MovedTemporarily = 302, ///< The requested page has temporarily moved to a new location\r
+ NotModified = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed\r
+\r
+ // 4xx: client error\r
+ BadRequest = 400, ///< The server couldn't understand the request (syntax error)\r
+ Unauthorized = 401, ///< The requested page needs an authentification to be accessed\r
+ Forbidden = 403, ///< The requested page cannot be accessed at all, even with authentification\r
+ NotFound = 404, ///< The requested page doesn't exist\r
+\r
+ // 5xx: server error\r
+ InternalServerError = 500, ///< The server encountered an unexpected error\r
+ NotImplemented = 501, ///< The server doesn't implement a requested feature\r
+ BadGateway = 502, ///< The gateway server has received an error from the source server\r
+ ServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...)\r
+\r
+ // 10xx: SFML custom codes\r
+ InvalidResponse = 1000, ///< Response is not a valid HTTP one\r
+ ConnectionFailed = 1001 ///< Connection with server failed\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the value of a field\r
+ ///\r
+ /// \param Field : Name of the field to get (case-insensitive)\r
+ ///\r
+ /// \return Value of the field, or empty string if not found\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const std::string& GetField(const std::string& Field) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the header's status code\r
+ ///\r
+ /// \return Header's status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Status GetStatus() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the major HTTP version number of the response\r
+ ///\r
+ /// \return Major version number\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetMajorHttpVersion() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the major HTTP version number of the response\r
+ ///\r
+ /// \return Major version number\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetMinorHttpVersion() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the body of the response. The body can contain :\r
+ /// - the requested page (for GET requests)\r
+ /// - a response from the server (for POST requests)\r
+ /// - nothing (for HEAD requests)\r
+ /// - an error message (in case of an error)\r
+ ///\r
+ /// \return The response body\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const std::string& GetBody() const;\r
+\r
+ private :\r
+\r
+ friend class Http;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the header from a response string\r
+ ///\r
+ /// \param Data : Content of the response's header to parse\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void FromString(const std::string& Data);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Types\r
+ ////////////////////////////////////////////////////////////\r
+ typedef std::map<std::string, std::string> FieldTable;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ FieldTable myFields; ///< Fields of the header\r
+ Status myStatus; ///< Status code\r
+ unsigned int myMajorVersion; ///< Major HTTP version\r
+ unsigned int myMinorVersion; ///< Minor HTTP version\r
+ std::string myBody; ///< Body of the response\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Http();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the Http instance with the target host\r
+ ///\r
+ /// \param Host : Web server to connect to\r
+ /// \param Port : Port to use for connection (0 by default -- use the standard port of the protocol used)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Http(const std::string& Host, unsigned short Port = 0);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the target host\r
+ ///\r
+ /// \param Host : Web server to connect to\r
+ /// \param Port : Port to use for connection (0 by default -- use the standard port of the protocol used)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetHost(const std::string& Host, unsigned short Port = 0);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Send a HTTP request and return the server's response.\r
+ /// You must be connected to a host before sending requests.\r
+ /// Any missing mandatory header field will be added with an appropriate value.\r
+ /// Warning : this function waits for the server's response and may\r
+ /// not return instantly; use a thread if you don't want to block your\r
+ /// application.\r
+ ///\r
+ /// \param Req : Request to send\r
+ /// \param Timeout : Maximum time to wait, in seconds (0 by default, means no timeout)\r
+ ///\r
+ /// \return Server's response\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Response SendRequest(const Request& Req, float Timeout = 0.f);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ SocketTCP myConnection; ///< Connection to the host\r
+ IPAddress myHost; ///< Web host address\r
+ std::string myHostName; ///< Web host name\r
+ unsigned short myPort; ///< Port used for connection with host\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_HTTP_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_IPADDRESS_HPP\r
+#define SFML_IPADDRESS_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <istream>\r
+#include <ostream>\r
+#include <string>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// IPAddress provides easy manipulation of IP v4 addresses\r
+////////////////////////////////////////////////////////////\r
+class SFML_API IPAddress\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor -- constructs an invalid address\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ IPAddress();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the address from a string\r
+ ///\r
+ /// \param Address : IP address ("xxx.xxx.xxx.xxx") or network name\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ IPAddress(const std::string& Address);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the address from a C-style string ;\r
+ /// Needed for implicit conversions from literal strings to IPAddress to work\r
+ ///\r
+ /// \param Address : IP address ("xxx.xxx.xxx.xxx") or network name\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ IPAddress(const char* Address);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the address from 4 bytes\r
+ ///\r
+ /// \param Byte0 : First byte of the address\r
+ /// \param Byte1 : Second byte of the address\r
+ /// \param Byte2 : Third byte of the address\r
+ /// \param Byte3 : Fourth byte of the address\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ IPAddress(Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the address from a 32-bits integer\r
+ ///\r
+ /// \param Address : 4 bytes of the address packed into a 32-bits integer\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ IPAddress(Uint32 Address);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell if the address is a valid one\r
+ ///\r
+ /// \return True if address has a valid syntax\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsValid() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a string representation of the address\r
+ ///\r
+ /// \return String representation of the IP address ("xxx.xxx.xxx.xxx")\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ std::string ToString() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get an integer representation of the address\r
+ ///\r
+ /// \return 32-bits integer containing the 4 bytes of the address, in system endianness\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Uint32 ToInteger() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the computer's local IP address (from the LAN point of view)\r
+ ///\r
+ /// \return Local IP address\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static IPAddress GetLocalAddress();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the computer's public IP address (from the web point of view).\r
+ /// The only way to get a public address is to ask it to a\r
+ /// distant website ; as a consequence, this function may be\r
+ /// very slow -- use it as few as possible !\r
+ ///\r
+ /// \param Timeout : Maximum time to wait, in seconds (0 by default : no timeout)\r
+ ///\r
+ /// \return Public IP address\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static IPAddress GetPublicAddress(float Timeout = 0.f);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator ==\r
+ ///\r
+ /// \param Other : Address to compare\r
+ ///\r
+ /// \return True if *this == Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator ==(const IPAddress& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator !=\r
+ ///\r
+ /// \param Other : Address to compare\r
+ ///\r
+ /// \return True if *this != Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator !=(const IPAddress& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator <\r
+ ///\r
+ /// \param Other : Address to compare\r
+ ///\r
+ /// \return True if *this < Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator <(const IPAddress& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator >\r
+ ///\r
+ /// \param Other : Address to compare\r
+ ///\r
+ /// \return True if *this > Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator >(const IPAddress& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator <=\r
+ ///\r
+ /// \param Other : Address to compare\r
+ ///\r
+ /// \return True if *this <= Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator <=(const IPAddress& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator >=\r
+ ///\r
+ /// \param Other : Address to compare\r
+ ///\r
+ /// \return True if *this >= Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator >=(const IPAddress& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Static member data\r
+ ////////////////////////////////////////////////////////////\r
+ static const IPAddress LocalHost; ///< Local host address (to connect to the same computer)\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ Uint32 myAddress; ///< Address stored as an unsigned 32 bits integer\r
+};\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator >> overload to extract an address from an input stream\r
+///\r
+/// \param Stream : Input stream\r
+/// \param Address : Address to extract\r
+///\r
+/// \return Reference to the input stream\r
+///\r
+////////////////////////////////////////////////////////////\r
+SFML_API std::istream& operator >>(std::istream& Stream, IPAddress& Address);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator << overload to print an address to an output stream\r
+///\r
+/// \param Stream : Output stream\r
+/// \param Address : Address to print\r
+///\r
+/// \return Reference to the output stream\r
+///\r
+////////////////////////////////////////////////////////////\r
+SFML_API std::ostream& operator <<(std::ostream& Stream, const IPAddress& Address);\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_IPADDRESS_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_PACKET_HPP\r
+#define SFML_PACKET_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <string>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Packet wraps data to send / to receive through the network\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Packet\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Packet();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Virtual destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~Packet();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Append data to the end of the packet\r
+ ///\r
+ /// \param Data : Pointer to the bytes to append\r
+ /// \param SizeInBytes : Number of bytes to append\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Append(const void* Data, std::size_t SizeInBytes);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Clear the packet data\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Clear();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a pointer to the data contained in the packet\r
+ /// Warning : the returned pointer may be invalid after you\r
+ /// append data to the packet\r
+ ///\r
+ /// \return Pointer to the data\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const char* GetData() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the size of the data contained in the packet\r
+ ///\r
+ /// \return Data size, in bytes\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ std::size_t GetDataSize() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell if the reading position has reached the end of the packet\r
+ ///\r
+ /// \return True if all data have been read into the packet\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool EndOfPacket() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the validity of packet\r
+ ///\r
+ /// \return True if last data extraction from packet was successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ operator bool() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator >> overloads to extract data from the packet\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Packet& operator >>(bool& Data);\r
+ Packet& operator >>(Int8& Data);\r
+ Packet& operator >>(Uint8& Data);\r
+ Packet& operator >>(Int16& Data);\r
+ Packet& operator >>(Uint16& Data);\r
+ Packet& operator >>(Int32& Data);\r
+ Packet& operator >>(Uint32& Data);\r
+ Packet& operator >>(float& Data);\r
+ Packet& operator >>(double& Data);\r
+ Packet& operator >>(char* Data);\r
+ Packet& operator >>(std::string& Data);\r
+ Packet& operator >>(wchar_t* Data);\r
+ Packet& operator >>(std::wstring& Data);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator << overloads to put data into the packet\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Packet& operator <<(bool Data);\r
+ Packet& operator <<(Int8 Data);\r
+ Packet& operator <<(Uint8 Data);\r
+ Packet& operator <<(Int16 Data);\r
+ Packet& operator <<(Uint16 Data);\r
+ Packet& operator <<(Int32 Data);\r
+ Packet& operator <<(Uint32 Data);\r
+ Packet& operator <<(float Data);\r
+ Packet& operator <<(double Data);\r
+ Packet& operator <<(const char* Data);\r
+ Packet& operator <<(const std::string& Data);\r
+ Packet& operator <<(const wchar_t* Data);\r
+ Packet& operator <<(const std::wstring& Data);\r
+\r
+private :\r
+\r
+ friend class SocketTCP;\r
+ friend class SocketUDP;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Check if the packet can extract a given size of bytes\r
+ ///\r
+ /// \param Size : Size to check\r
+ ///\r
+ /// \return True if Size bytes can be read from the packet's data\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool CheckSize(std::size_t Size);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Called before the packet is sent to the network\r
+ ///\r
+ /// \param DataSize : Variable to fill with the size of data to send\r
+ ///\r
+ /// \return Pointer to the array of bytes to send\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual const char* OnSend(std::size_t& DataSize);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Called after the packet has been received from the network\r
+ ///\r
+ /// \param Data : Pointer to the array of received bytes\r
+ /// \param DataSize : Size of the array of bytes\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnReceive(const char* Data, std::size_t DataSize);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ std::vector<char> myData; ///< Data stored in the packet\r
+ std::size_t myReadPos; ///< Current reading position in the packet\r
+ bool myIsValid; ///< Reading state of the packet\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_PACKET_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SELECTOR_HPP\r
+#define SFML_SELECTOR_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Network/SocketUDP.hpp>\r
+#include <SFML/Network/SocketTCP.hpp>\r
+#include <SFML/Network/SelectorBase.hpp>\r
+#include <map>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Selector allow reading from multiple sockets\r
+/// without blocking. It's a kind of multiplexer\r
+////////////////////////////////////////////////////////////\r
+template <typename Type>\r
+class Selector : private SelectorBase\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Add a socket to watch\r
+ ///\r
+ /// \param Socket : Socket to add\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Add(Type Socket);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Remove a socket\r
+ ///\r
+ /// \param Socket : Socket to remove\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Remove(Type Socket);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Remove all sockets\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Clear();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Wait and collect sockets which are ready for reading.\r
+ /// This functions will return either when at least one socket\r
+ /// is ready, or when the given time is out\r
+ ///\r
+ /// \param Timeout : Timeout, in seconds (0 by default : no timeout)\r
+ ///\r
+ /// \return Number of sockets ready to be read\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int Wait(float Timeout = 0.f);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// After a call to Wait(), get the Index-th socket which is\r
+ /// ready for reading. The total number of sockets ready\r
+ /// is the integer returned by the previous call to Wait()\r
+ ///\r
+ /// \param Index : Index of the socket to get\r
+ ///\r
+ /// \return The Index-th socket\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Type GetSocketReady(unsigned int Index);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Types\r
+ ////////////////////////////////////////////////////////////\r
+ typedef std::map<SocketHelper::SocketType, Type> SocketTable;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ SocketTable mySockets; ///< Table matching the SFML socket instances with their low-level handles\r
+};\r
+\r
+#include <SFML/Network/Selector.inl>\r
+\r
+// Let's define the two only valid types of Selector\r
+typedef Selector<SocketUDP> SelectorUDP;\r
+typedef Selector<SocketTCP> SelectorTCP;\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SELECTOR_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Add a socket to watch\r
+////////////////////////////////////////////////////////////\r
+template <typename Type>\r
+void Selector<Type>::Add(Type Socket)\r
+{\r
+ if (Socket.IsValid())\r
+ {\r
+ SelectorBase::Add(Socket.mySocket);\r
+ mySockets[Socket.mySocket] = Socket;\r
+ }\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Remove a socket\r
+////////////////////////////////////////////////////////////\r
+template <typename Type>\r
+void Selector<Type>::Remove(Type Socket)\r
+{\r
+ typename SocketTable::iterator It = mySockets.find(Socket.mySocket);\r
+ if (It != mySockets.end())\r
+ {\r
+ SelectorBase::Remove(Socket.mySocket);\r
+ mySockets.erase(It);\r
+ }\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Remove all sockets\r
+////////////////////////////////////////////////////////////\r
+template <typename Type>\r
+void Selector<Type>::Clear()\r
+{\r
+ SelectorBase::Clear();\r
+ mySockets.clear();\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Wait and collect sockets which are ready for reading.\r
+/// This functions will return either when at least one socket\r
+/// is ready, or when the given time is out\r
+////////////////////////////////////////////////////////////\r
+template <typename Type>\r
+unsigned int Selector<Type>::Wait(float Timeout)\r
+{\r
+ // No socket in the selector : return 0\r
+ if (mySockets.empty())\r
+ return 0;\r
+\r
+ return SelectorBase::Wait(Timeout);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// After a call to Wait(), get the Index-th socket which is\r
+/// ready for reading. The total number of sockets ready\r
+/// is the integer returned by the previous call to Wait()\r
+////////////////////////////////////////////////////////////\r
+template <typename Type>\r
+Type Selector<Type>::GetSocketReady(unsigned int Index)\r
+{\r
+ SocketHelper::SocketType Socket = SelectorBase::GetSocketReady(Index);\r
+\r
+ typename SocketTable::const_iterator It = mySockets.find(Socket);\r
+ if (It != mySockets.end())\r
+ return It->second;\r
+ else\r
+ return Type(Socket);\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SELECTORBASE_HPP\r
+#define SFML_SELECTORBASE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <SFML/Network/SocketHelper.hpp>\r
+#include <map>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Private base class for selectors.\r
+/// As Selector is a template class, this base is needed so that\r
+/// every system call get compiled in SFML (not inlined)\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SelectorBase\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SelectorBase();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Add a socket to watch\r
+ ///\r
+ /// \param Socket : Socket to add\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Add(SocketHelper::SocketType Socket);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Remove a socket\r
+ ///\r
+ /// \param Socket : Socket to remove\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Remove(SocketHelper::SocketType Socket);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Remove all sockets\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Clear();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Wait and collect sockets which are ready for reading.\r
+ /// This functions will return either when at least one socket\r
+ /// is ready, or when the given time is out\r
+ ///\r
+ /// \param Timeout : Timeout, in seconds (0 by default : no timeout)\r
+ ///\r
+ /// \return Number of sockets ready to be read\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int Wait(float Timeout = 0.f);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// After a call to Wait(), get the Index-th socket which is\r
+ /// ready for reading. The total number of sockets ready\r
+ /// is the integer returned by the previous call to Wait()\r
+ ///\r
+ /// \param Index : Index of the socket to get\r
+ ///\r
+ /// \return The Index-th socket\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SocketHelper::SocketType GetSocketReady(unsigned int Index);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ fd_set mySet; ///< Set of socket to watch\r
+ fd_set mySetReady; ///< Set of socket which are ready for reading\r
+ int myMaxSocket; ///< Maximum socket index\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SELECTORBASE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOCKETHELPER_HPP\r
+#define SFML_SOCKETHELPER_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+namespace Socket\r
+{\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enumeration of status returned by socket functions\r
+ ////////////////////////////////////////////////////////////\r
+ enum Status\r
+ {\r
+ Done, ///< The socket has sent / received the data\r
+ NotReady, ///< The socket is not ready to send / receive data yet\r
+ Disconnected, ///< The TCP socket has been disconnected\r
+ Error ///< An unexpected error happened\r
+ };\r
+}\r
+\r
+} // namespace sf\r
+\r
+\r
+#ifdef SFML_SYSTEM_WINDOWS\r
+\r
+ #include <SFML/Network/Win32/SocketHelper.hpp>\r
+\r
+#else\r
+\r
+ #include <SFML/Network/Unix/SocketHelper.hpp>\r
+\r
+#endif\r
+\r
+\r
+#endif // SFML_SOCKETHELPER_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOCKETTCP_HPP\r
+#define SFML_SOCKETTCP_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Network/SocketHelper.hpp>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+class Packet;\r
+class IPAddress;\r
+template <typename> class Selector;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// SocketTCP wraps a socket using TCP protocol to\r
+/// send data safely (but a bit slower)\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SocketTCP\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SocketTCP();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the blocking state of the socket.\r
+ /// The default behaviour of a socket is blocking\r
+ ///\r
+ /// \param Blocking : Pass true to set the socket as blocking, or false for non-blocking\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetBlocking(bool Blocking);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Connect to another computer on a specified port\r
+ ///\r
+ /// \param Port : Port to use for transfers (warning : ports < 1024 are reserved)\r
+ /// \param HostAddress : IP Address of the host to connect to\r
+ /// \param Timeout : Maximum time to wait, in seconds (0 by default : no timeout) (this parameter is ignored for non-blocking sockets)\r
+ ///\r
+ /// \return True if operation has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Connect(unsigned short Port, const IPAddress& HostAddress, float Timeout = 0.f);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Listen to a specified port for incoming data or connections\r
+ ///\r
+ /// \param Port : Port to listen to\r
+ ///\r
+ /// \return True if operation has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Listen(unsigned short Port);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Wait for a connection (must be listening to a port).\r
+ /// This function will block if the socket is blocking\r
+ ///\r
+ /// \param Connected : Socket containing the connection with the connected client\r
+ /// \param Address : Pointer to an address to fill with client infos (NULL by default)\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Accept(SocketTCP& Connected, IPAddress* Address = NULL);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Send an array of bytes to the host (must be connected first)\r
+ ///\r
+ /// \param Data : Pointer to the bytes to send\r
+ /// \param Size : Number of bytes to send\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Send(const char* Data, std::size_t Size);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Receive an array of bytes from the host (must be connected first).\r
+ /// This function will block if the socket is blocking\r
+ ///\r
+ /// \param Data : Pointer to a byte array to fill (make sure it is big enough)\r
+ /// \param MaxSize : Maximum number of bytes to read\r
+ /// \param SizeReceived : Number of bytes received\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Send a packet of data to the host (must be connected first)\r
+ ///\r
+ /// \param PacketToSend : Packet to send\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Send(Packet& PacketToSend);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Receive a packet from the host (must be connected first).\r
+ /// This function will block if the socket is blocking\r
+ ///\r
+ /// \param PacketToReceive : Packet to fill with received data\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Receive(Packet& PacketToReceive);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Close the socket\r
+ ///\r
+ /// \return True if operation has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Close();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Check if the socket is in a valid state ; this function\r
+ /// can be called any time to check if the socket is OK\r
+ ///\r
+ /// \return True if the socket is valid\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsValid() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator ==\r
+ ///\r
+ /// \param Other : Socket to compare\r
+ ///\r
+ /// \return True if *this == Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator ==(const SocketTCP& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator !=\r
+ ///\r
+ /// \param Other : Socket to compare\r
+ ///\r
+ /// \return True if *this != Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator !=(const SocketTCP& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator <.\r
+ /// Provided for compatibility with standard containers, as\r
+ /// comparing two sockets doesn't make much sense...\r
+ ///\r
+ /// \param Other : Socket to compare\r
+ ///\r
+ /// \return True if *this < Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator <(const SocketTCP& Other) const;\r
+\r
+private :\r
+\r
+ friend class Selector<SocketTCP>;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the socket from a socket descriptor\r
+ /// (for internal use only)\r
+ ///\r
+ /// \param Descriptor : Socket descriptor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SocketTCP(SocketHelper::SocketType Descriptor);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create the socket\r
+ ///\r
+ /// \param Descriptor : System socket descriptor to use (0 by default -- create a new socket)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Create(SocketHelper::SocketType Descriptor = 0);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ SocketHelper::SocketType mySocket; ///< Socket descriptor\r
+ Uint32 myPendingHeader; ///< Data of the current pending packet header, if any\r
+ Uint32 myPendingHeaderSize; ///< Size of the current pending packet header, if any\r
+ std::vector<char> myPendingPacket; ///< Data of the current pending packet, if any\r
+ Int32 myPendingPacketSize; ///< Size of the current pending packet, if any\r
+ bool myIsBlocking; ///< Is the socket blocking or non-blocking ?\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOCKETTCP_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOCKETUDP_HPP\r
+#define SFML_SOCKETUDP_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Network/SocketHelper.hpp>\r
+#include <vector>\r
+\r
+\r
+namespace sf\r
+{\r
+class Packet;\r
+class IPAddress;\r
+template <typename> class Selector;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// SocketUDP wraps a socket using UDP protocol to\r
+/// send data fastly (but with less safety)\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SocketUDP\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SocketUDP();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the blocking state of the socket.\r
+ /// The default behaviour of a socket is blocking\r
+ ///\r
+ /// \param Blocking : Pass true to set the socket as blocking, or false for non-blocking\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetBlocking(bool Blocking);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Bind the socket to a specific port\r
+ ///\r
+ /// \param Port : Port to bind the socket to\r
+ ///\r
+ /// \return True if operation has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Bind(unsigned short Port);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Unbind the socket from its previous port, if any\r
+ ///\r
+ /// \return True if operation has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Unbind();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Send an array of bytes\r
+ ///\r
+ /// \param Data : Pointer to the bytes to send\r
+ /// \param Size : Number of bytes to send\r
+ /// \param Address : Address of the computer to send the packet to\r
+ /// \param Port : Port to send the data to\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Send(const char* Data, std::size_t Size, const IPAddress& Address, unsigned short Port);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Receive an array of bytes.\r
+ /// This function will block if the socket is blocking\r
+ ///\r
+ /// \param Data : Pointer to a byte array to fill (make sure it is big enough)\r
+ /// \param MaxSize : Maximum number of bytes to read\r
+ /// \param SizeReceived : Number of bytes received\r
+ /// \param Address : Address of the computer which sent the data\r
+ /// \param Port : Port on which the remote computer sent the data\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address, unsigned short& Port);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Send a packet of data\r
+ ///\r
+ /// \param PacketToSend : Packet to send\r
+ /// \param Address : Address of the computer to send the packet to\r
+ /// \param Port : Port to send the data to\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Send(Packet& PacketToSend, const IPAddress& Address, unsigned short Port);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Receive a packet.\r
+ /// This function will block if the socket is blocking\r
+ ///\r
+ /// \param PacketToReceive : Packet to fill with received data\r
+ /// \param Address : Address of the computer which sent the packet\r
+ /// \param Port : Port on which the remote computer sent the data\r
+ ///\r
+ /// \return Status code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Socket::Status Receive(Packet& PacketToReceive, IPAddress& Address, unsigned short& Port);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Close the socket\r
+ ///\r
+ /// \return True if operation has been successful\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool Close();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Check if the socket is in a valid state ; this function\r
+ /// can be called any time to check if the socket is OK\r
+ ///\r
+ /// \return True if the socket is valid\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsValid() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the port the socket is currently bound to\r
+ ///\r
+ /// \return Current port (0 means the socket is not bound)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned short GetPort() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator ==\r
+ ///\r
+ /// \param Other : Socket to compare\r
+ ///\r
+ /// \return True if *this == Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator ==(const SocketUDP& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator !=\r
+ ///\r
+ /// \param Other : Socket to compare\r
+ ///\r
+ /// \return True if *this != Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator !=(const SocketUDP& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator <.\r
+ /// Provided for compatibility with standard containers, as\r
+ /// comparing two sockets doesn't make much sense...\r
+ ///\r
+ /// \param Other : Socket to compare\r
+ ///\r
+ /// \return True if *this < Other\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator <(const SocketUDP& Other) const;\r
+\r
+private :\r
+\r
+ friend class Selector<SocketUDP>;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the socket from a socket descriptor\r
+ /// (for internal use only)\r
+ ///\r
+ /// \param Descriptor : Socket descriptor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ SocketUDP(SocketHelper::SocketType Descriptor);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create the socket\r
+ ///\r
+ /// \param Descriptor : System socket descriptor to use (0 by default -- create a new socket)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Create(SocketHelper::SocketType Descriptor = 0);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ SocketHelper::SocketType mySocket; ///< Socket identifier\r
+ unsigned short myPort; ///< Port to which the socket is bound\r
+ Uint32 myPendingHeader; ///< Data of the current pending packet header, if any\r
+ Uint32 myPendingHeaderSize; ///< Size of the current pending packet header, if any\r
+ std::vector<char> myPendingPacket; ///< Data of the current pending packet, if any\r
+ Int32 myPendingPacketSize; ///< Size of the current pending packet, if any\r
+ bool myIsBlocking; ///< Is the socket blocking or non-blocking ?\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOCKETUDP_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOCKETS_HPP\r
+#define SFML_SOCKETS_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+#ifdef SFML_SYSTEM_WINDOWS\r
+\r
+ #include <SFML/Network/Win32/Sockets.hpp>\r
+\r
+#else\r
+\r
+ #include <SFML/Network/Unix/Sockets.hpp>\r
+\r
+#endif\r
+\r
+\r
+#endif // SFML_SOCKETS_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOCKETHELPERUNIX_HPP\r
+#define SFML_SOCKETHELPERUNIX_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <sys/types.h>\r
+#include <sys/socket.h>\r
+#include <netinet/in.h>\r
+#include <netinet/tcp.h>\r
+#include <arpa/inet.h>\r
+#include <netdb.h>\r
+#include <unistd.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// This class defines helper functions to do all the\r
+/// non-portable socket stuff. This class is meant for internal\r
+/// use only\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SocketHelper\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Define some socket types\r
+ ////////////////////////////////////////////////////////////\r
+ typedef int SocketType;\r
+ typedef socklen_t LengthType;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the value of the invalid socket\r
+ ///\r
+ /// \return Unique value of the invalid socket\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static SocketType InvalidSocket();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Close / destroy a socket\r
+ ///\r
+ /// \param Socket : Socket to close\r
+ ///\r
+ /// \return True on success\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static bool Close(SocketType Socket);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set a socket as blocking or non-blocking\r
+ ///\r
+ /// \param Socket : Socket to modify\r
+ /// \param Block : New blocking state of the socket\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetBlocking(SocketType Socket, bool Block);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the last socket error status\r
+ ///\r
+ /// \return Status corresponding to the last socket error\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Socket::Status GetErrorStatus();\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOCKETHELPERUNIX_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SOCKETHELPERWIN32_HPP\r
+#define SFML_SOCKETHELPERWIN32_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <winsock2.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// This class defines helper functions to do all the\r
+/// non-portable socket stuff. This class is meant for internal\r
+/// use only\r
+////////////////////////////////////////////////////////////\r
+class SFML_API SocketHelper\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Define some socket types\r
+ ////////////////////////////////////////////////////////////\r
+ typedef SOCKET SocketType;\r
+ typedef int LengthType;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Return the value of the invalid socket\r
+ ///\r
+ /// \return Unique value of the invalid socket\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static SocketType InvalidSocket();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Close / destroy a socket\r
+ ///\r
+ /// \param Socket : Socket to close\r
+ ///\r
+ /// \return True on success\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static bool Close(SocketType Socket);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set a socket as blocking or non-blocking\r
+ ///\r
+ /// \param Socket : Socket to modify\r
+ /// \param Block : New blocking state of the socket\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetBlocking(SocketType Socket, bool Block);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the last socket error status\r
+ ///\r
+ /// \return Status corresponding to the last socket error\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Socket::Status GetErrorStatus();\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SOCKETHELPERWIN32_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_CLOCK_HPP\r
+#define SFML_CLOCK_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Clock is an utility class for manipulating time\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Clock\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Clock();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the time elapsed since last reset\r
+ ///\r
+ /// \return Time elapsed, in seconds\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetElapsedTime() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Restart the timer\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Reset();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ double myStartTime; ///< Time of last reset\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_CLOCK_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_LOCK_HPP\r
+#define SFML_LOCK_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/NonCopyable.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+class Mutex;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Lock is an exception-safe automatic wrapper for\r
+/// locking and unlocking mutexes\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Lock : NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the lock with a target mutex (lock it)\r
+ ///\r
+ /// @param Mutex : Mutex to lock\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Lock(Mutex& Mutex);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor (unlocks the mutex)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Lock();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ Mutex& myMutex; ///< Mutex to lock / unlock\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_LOCK_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_MUTEX_HPP\r
+#define SFML_MUTEX_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+#ifdef SFML_SYSTEM_WINDOWS\r
+\r
+ #include <SFML/System/Win32/Mutex.hpp>\r
+\r
+#else\r
+\r
+ #include <SFML/System/Unix/Mutex.hpp>\r
+\r
+#endif\r
+\r
+\r
+#endif // SFML_MUTEX_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_NONCOPYABLE_HPP\r
+#define SFML_NONCOPYABLE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Utility base class to easily declare non-copyable classes.\r
+/// Just inherit from NonCopyable to get a non-copyable class\r
+////////////////////////////////////////////////////////////\r
+struct SFML_API NonCopyable\r
+{\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// The default constructor won't be generated, so provide it\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ NonCopyable() {}\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor : declare it private and don't implement\r
+ /// it to prevent from calling it\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ NonCopyable(const NonCopyable&);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator : declare it private and don't implement\r
+ /// it to prevent from calling it\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ NonCopyable& operator =(const NonCopyable&);\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_NONCOPYABLE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_RANDOMIZER_HPP\r
+#define SFML_RANDOMIZER_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Randomizer is an utility class for generating pseudo-random\r
+/// numbers\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Randomizer\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Set the seed for the generator. Using a known seed\r
+ /// allows you to reproduce the same sequence of random number\r
+ ///\r
+ /// \param Seed : Number to use as the seed\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void SetSeed(unsigned int Seed);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the seed used to generate random numbers the generator.\r
+ ///\r
+ /// \return Current seed\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static unsigned int GetSeed();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a random float number in a given range\r
+ ///\r
+ /// \return Start : Start of the range\r
+ /// \return End : End of the range\r
+ ///\r
+ /// \return Random number in [Begin, End]\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static float Random(float Begin, float End);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a random integer number in a given range\r
+ ///\r
+ /// \return Start : Start of the range\r
+ /// \return End : End of the range\r
+ ///\r
+ /// \return Random number in [Begin, End]\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static int Random(int Begin, int End);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Static member variables\r
+ ////////////////////////////////////////////////////////////\r
+ static unsigned int ourSeed;\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_RANDOMIZER_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_RESOURCE_HPP\r
+#define SFML_RESOURCE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <set>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+// These two classes are defined in the same header because\r
+// they depend on each other. And as they're template classes,\r
+// they must be entirely defined in header files, which\r
+// prevents from proper separate compiling\r
+////////////////////////////////////////////////////////////\r
+\r
+template <typename> class ResourcePtr;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Base class for every resource that needs to notify\r
+/// dependent classes about its destruction\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+class Resource\r
+{\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Resource();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor\r
+ ///\r
+ /// \param Copy : Resource to copy\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Resource(const Resource<T>& Copy);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Resource();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator\r
+ ///\r
+ /// \param Other : Resource to copy\r
+ ///\r
+ /// \return Reference to this\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Resource<T>& operator =(const Resource<T>& Other);\r
+\r
+private :\r
+\r
+ friend class ResourcePtr<T>;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Connect a ResourcePtr to this resource\r
+ ///\r
+ /// \param Observer : Observer to add\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Connect(ResourcePtr<T>& Observer) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Disconnect a ResourcePtr from this resource\r
+ ///\r
+ /// \param Observer : Observer to remove\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Disconnect(ResourcePtr<T>& Observer) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ mutable std::set<ResourcePtr<T>*> myObservers;\r
+};\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Safe pointer to a T resource (inheriting from sf::Resource<T>),\r
+/// its pointer is automatically reseted when the resource is destroyed\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+class ResourcePtr\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ResourcePtr();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct from a raw resource\r
+ ///\r
+ /// \param Resource : Internal resource\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ResourcePtr(const T* Resource);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Copy constructor\r
+ ///\r
+ /// \param Copy : Instance to copy\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ResourcePtr(const ResourcePtr<T>& Copy);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~ResourcePtr();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator from another ResourcePtr\r
+ ///\r
+ /// \param Other : Resource pointer to assign\r
+ ///\r
+ /// \return Reference to this\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ResourcePtr<T>& operator =(const ResourcePtr<T>& Other);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Assignment operator from a raw resource\r
+ ///\r
+ /// \param Resource : Resource to assign\r
+ ///\r
+ /// \return Reference to this\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ResourcePtr<T>& operator =(const T* Resource);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Cast operator to implicitely convert the resource pointer to\r
+ /// its raw pointer type.\r
+ /// This might be dangerous in the general case, but in this context\r
+ /// it is safe enough to define this operator\r
+ ///\r
+ /// \return Pointer to the actual resource\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ operator const T*() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator * overload to return a reference to the actual resource\r
+ ///\r
+ /// \return Reference to the internal resource\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const T& operator *() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator -> overload to return a pointer to the actual resource\r
+ ///\r
+ /// \return Pointer to the internal resource\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const T* operator ->() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Function called when the observed resource is about to be\r
+ /// destroyed\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void OnResourceDestroyed();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ const T* myResource; /// Pointer to the actual resource\r
+};\r
+\r
+#include <SFML/System/Resource.inl>\r
+#include <SFML/System/ResourcePtr.inl>\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_RESOURCE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Default constructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Resource<T>::Resource()\r
+{\r
+ // Nothing to do\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Copy constructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Resource<T>::Resource(const Resource<T>&)\r
+{\r
+ // Nothing to do, we don't want to copy observers\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Destructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Resource<T>::~Resource()\r
+{\r
+ // Notify all observers\r
+ for (typename std::set<ResourcePtr<T>*>::iterator i = myObservers.begin(); i != myObservers.end(); ++i)\r
+ {\r
+ (*i)->OnResourceDestroyed();\r
+ }\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Assignment operator\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Resource<T>& Resource<T>::operator =(const Resource<T>&)\r
+{\r
+ // Nothing to do, we don't want to copy observers\r
+ return *this;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Connect a ResourcePtr to this resource\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+void Resource<T>::Connect(ResourcePtr<T>& Observer) const\r
+{\r
+ myObservers.insert(&Observer);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Disconnect a ResourcePtr from this resource\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+void Resource<T>::Disconnect(ResourcePtr<T>& Observer) const\r
+{\r
+ myObservers.erase(&Observer);\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Default constructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+ResourcePtr<T>::ResourcePtr() :\r
+myResource(NULL)\r
+{\r
+\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Construct from a raw resource\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+ResourcePtr<T>::ResourcePtr(const T* Resource) :\r
+myResource(Resource)\r
+{\r
+ if (myResource)\r
+ myResource->Connect(*this);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Copy constructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+ResourcePtr<T>::ResourcePtr(const ResourcePtr<T>& Copy) :\r
+myResource(Copy.myResource)\r
+{\r
+ if (myResource)\r
+ myResource->Connect(*this);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Destructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+ResourcePtr<T>::~ResourcePtr()\r
+{\r
+ if (myResource)\r
+ myResource->Disconnect(*this);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Assignment operator from another ResourcePtr\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+ResourcePtr<T>& ResourcePtr<T>::operator =(const ResourcePtr<T>& Other)\r
+{\r
+ if (myResource)\r
+ myResource->Disconnect(*this);\r
+\r
+ myResource = Other.myResource;\r
+\r
+ if (myResource)\r
+ myResource->Connect(*this);\r
+\r
+ return *this;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Assignment operator from a raw resource\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+ResourcePtr<T>& ResourcePtr<T>::operator =(const T* Resource)\r
+{\r
+ if (myResource)\r
+ myResource->Disconnect(*this);\r
+\r
+ myResource = Resource;\r
+\r
+ if (myResource)\r
+ myResource->Connect(*this);\r
+\r
+ return *this;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Cast operator to implicitely convert the resource pointer to\r
+/// its raw pointer type.\r
+/// This might be dangerous in the general case, but in this context\r
+/// it is safe enough to define this operator\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+ResourcePtr<T>::operator const T*() const\r
+{\r
+ return myResource;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload to return a reference to the actual resource\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+const T& ResourcePtr<T>::operator *() const\r
+{\r
+ return *myResource;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator -> overload to return a pointer to the actual resource\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+const T* ResourcePtr<T>::operator ->() const\r
+{\r
+ return myResource;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Function called when the observed resource is about to be\r
+/// destroyed\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+void ResourcePtr<T>::OnResourceDestroyed()\r
+{\r
+ myResource = NULL;\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_SLEEP_HPP\r
+#define SFML_SLEEP_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+ ////////////////////////////////////////////////////////////\r
+ /// Make the current thread sleep for a given time\r
+ ///\r
+ /// \param Duration : Time to sleep, in seconds (must be >= 0)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SFML_API Sleep(float Duration);\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_SLEEP_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_THREAD_HPP\r
+#define SFML_THREAD_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+#ifdef SFML_SYSTEM_WINDOWS\r
+\r
+ #include <SFML/System/Win32/Thread.hpp>\r
+\r
+#else\r
+\r
+ #include <SFML/System/Unix/Thread.hpp>\r
+\r
+#endif\r
+\r
+\r
+#endif // SFML_THREAD_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_UNICODE_HPP\r
+#define SFML_UNICODE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <iterator>\r
+#include <locale>\r
+#include <string>\r
+#include <stdlib.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Provides utility functions to convert from and to\r
+/// any unicode and ASCII encoding\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Unicode\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Define a string type for each encoding\r
+ /// Warning : in UTF8 and UTF16 strings, one element doesn't\r
+ /// necessarily maps to one character ; only an UTF32 element\r
+ /// is wide enough to hold all possible unicode values\r
+ ////////////////////////////////////////////////////////////\r
+ typedef std::basic_string<Uint8> UTF8String;\r
+ typedef std::basic_string<Uint16> UTF16String;\r
+ typedef std::basic_string<Uint32> UTF32String;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// This class is an abstract definition of a unicode text,\r
+ /// it can be converted from and to any kind of string\r
+ /// and encoding\r
+ ////////////////////////////////////////////////////////////\r
+ class SFML_API Text\r
+ {\r
+ public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor (empty text)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Text();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the unicode text from any type of string\r
+ ///\r
+ /// \param Str : String to convert\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Text(const char* Str);\r
+ Text(const wchar_t* Str);\r
+ Text(const Uint8* Str);\r
+ Text(const Uint16* Str);\r
+ Text(const Uint32* Str);\r
+ Text(const std::string& Str);\r
+ Text(const std::wstring& Str);\r
+ Text(const Unicode::UTF8String& Str);\r
+ Text(const Unicode::UTF16String& Str);\r
+ Text(const Unicode::UTF32String& Str);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Operator to cast the text to any type of string\r
+ ///\r
+ /// \return Converted string\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ operator std::string () const;\r
+ operator std::wstring () const;\r
+ operator Unicode::UTF8String () const;\r
+ operator Unicode::UTF16String () const;\r
+ operator const Unicode::UTF32String&() const;\r
+\r
+ private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Data member\r
+ ////////////////////////////////////////////////////////////\r
+ sf::Unicode::UTF32String myUTF32String; ///< UTF-32 unicode text\r
+ };\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an UTF-32 characters range\r
+ /// to an ANSI characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)\r
+ /// \param Locale : Locale to use for conversion (uses the current one by default)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out UTF32ToANSI(In Begin, In End, Out Output, char Replacement = '?', const std::locale& Locale = GetDefaultLocale());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an ANSI characters range\r
+ /// to an UTF-32 characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Locale : Locale to use for conversion (uses the current one by default)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale = GetDefaultLocale());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an UTF-8 characters range\r
+ /// to an UTF-16 characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an UTF-8 characters range\r
+ /// to an UTF-32 characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an UTF-16 characters range\r
+ /// to an UTF-8 characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an UTF-16 characters range\r
+ /// to an UTF-32 characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?');\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an UTF-32 characters range\r
+ /// to an UTF-8 characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?');\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Generic function to convert an UTF-32 characters range\r
+ /// to an UTF-16 characters range, using the given locale\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ /// \param Output : Iterator pointing to the beginning of the output sequence\r
+ /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character)\r
+ ///\r
+ /// \return Iterator to the end of the output sequence which has been written\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In, typename Out>\r
+ static Out UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?');\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the number of characters composing an UTF-8 string\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ ///\r
+ /// \return Count of the characters in the string\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In>\r
+ static std::size_t GetUTF8Length(In Begin, In End);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the number of characters composing an UTF-16 string\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ ///\r
+ /// \return Count of the characters in the string\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In>\r
+ static std::size_t GetUTF16Length(In Begin, In End);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the number of characters composing an UTF-32 string\r
+ ///\r
+ /// \param Begin : Iterator pointing to the beginning of the input sequence\r
+ /// \param End : Iterator pointing to the end of the input sequence\r
+ ///\r
+ /// \return Count of the characters in the string\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ template <typename In>\r
+ static std::size_t GetUTF32Length(In Begin, In End);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the default system locale\r
+ ///\r
+ /// \return Reference to the default system locale\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static const std::locale& GetDefaultLocale();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Static member data\r
+ ////////////////////////////////////////////////////////////\r
+ static const int UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence\r
+ static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions\r
+ static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences\r
+};\r
+\r
+#include <SFML/System/Unicode.inl>\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_UNICODE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an UTF-32 characters range\r
+/// to an ANSI characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::UTF32ToANSI(In Begin, In End, Out Output, char Replacement, const std::locale& Locale)\r
+{\r
+ #ifdef __MINGW32__\r
+\r
+ // MinGW has a almost no support for unicode stuff\r
+ // As a consequence, the MinGW version of this function can only use the default locale\r
+ // and ignores the one passed as parameter\r
+ while (Begin < End)\r
+ {\r
+ char Char = 0;\r
+ if (wctomb(&Char, static_cast<wchar_t>(*Begin++)) >= 0)\r
+ *Output++ = Char;\r
+ else if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+\r
+ #else\r
+\r
+ // Get the facet of the locale which deals with character conversion\r
+ const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);\r
+\r
+ // Use the facet to convert each character of the input string\r
+ while (Begin < End)\r
+ *Output++ = Facet.narrow(static_cast<wchar_t>(*Begin++), Replacement);\r
+\r
+ #endif\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an ANSI characters range\r
+/// to an UTF-32 characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale)\r
+{\r
+ #ifdef __MINGW32__\r
+\r
+ // MinGW has a almost no support for unicode stuff\r
+ // As a consequence, the MinGW version of this function can only use the default locale\r
+ // and ignores the one passed as parameter\r
+ while (Begin < End)\r
+ {\r
+ wchar_t Char = 0;\r
+ mbtowc(&Char, &*Begin, 1);\r
+ Begin++;\r
+ *Output++ = static_cast<Uint32>(Char);\r
+ }\r
+\r
+ #else\r
+\r
+ // Get the facet of the locale which deals with character conversion\r
+ const std::ctype<wchar_t>& Facet = std::use_facet< std::ctype<wchar_t> >(Locale);\r
+\r
+ // Use the facet to convert each character of the input string\r
+ while (Begin < End)\r
+ *Output++ = static_cast<Uint32>(Facet.widen(*Begin++));\r
+\r
+ #endif\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an UTF-8 characters range\r
+/// to an UTF-16 characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement)\r
+{\r
+ while (Begin < End)\r
+ {\r
+ Uint32 c = 0;\r
+ int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];\r
+ if (Begin + TrailingBytes < End)\r
+ {\r
+ // First decode the UTF-8 character\r
+ switch (TrailingBytes)\r
+ {\r
+ case 5 : c += *Begin++; c <<= 6;\r
+ case 4 : c += *Begin++; c <<= 6;\r
+ case 3 : c += *Begin++; c <<= 6;\r
+ case 2 : c += *Begin++; c <<= 6;\r
+ case 1 : c += *Begin++; c <<= 6;\r
+ case 0 : c += *Begin++;\r
+ }\r
+ c -= UTF8Offsets[TrailingBytes];\r
+\r
+ // Then encode it in UTF-16\r
+ if (c < 0xFFFF)\r
+ {\r
+ // Character can be converted directly to 16 bits, just need to check it's in the valid range\r
+ if ((c >= 0xD800) && (c <= 0xDFFF))\r
+ {\r
+ // Invalid character (this range is reserved)\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ else\r
+ {\r
+ // Valid character directly convertible to 16 bits\r
+ *Output++ = static_cast<Uint16>(c);\r
+ }\r
+ }\r
+ else if (c > 0x0010FFFF)\r
+ {\r
+ // Invalid character (greater than the maximum unicode value)\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ else\r
+ {\r
+ // Character will be converted to 2 UTF-16 elements\r
+ c -= 0x0010000;\r
+ *Output++ = static_cast<Uint16>((c >> 10) + 0xD800);\r
+ *Output++ = static_cast<Uint16>((c & 0x3FFUL) + 0xDC00);\r
+ }\r
+ }\r
+ }\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an UTF-8 characters range\r
+/// to an UTF-32 characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement)\r
+{\r
+ while (Begin < End)\r
+ {\r
+ Uint32 c = 0;\r
+ int TrailingBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];\r
+ if (Begin + TrailingBytes < End)\r
+ {\r
+ // First decode the UTF-8 character\r
+ switch (TrailingBytes)\r
+ {\r
+ case 5 : c += *Begin++; c <<= 6;\r
+ case 4 : c += *Begin++; c <<= 6;\r
+ case 3 : c += *Begin++; c <<= 6;\r
+ case 2 : c += *Begin++; c <<= 6;\r
+ case 1 : c += *Begin++; c <<= 6;\r
+ case 0 : c += *Begin++;\r
+ }\r
+ c -= UTF8Offsets[TrailingBytes];\r
+\r
+ // Then write it if valid\r
+ if ((c < 0xD800) || (c > 0xDFFF))\r
+ {\r
+ // Valid UTF-32 character\r
+ *Output++ = c;\r
+ }\r
+ else\r
+ {\r
+ // Invalid UTF-32 character\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ }\r
+ }\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an UTF-16 characters range\r
+/// to an UTF-8 characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement)\r
+{\r
+ while (Begin < End)\r
+ {\r
+ Uint32 c = *Begin++;\r
+\r
+ // If it's a surrogate pair, first convert to a single UTF-32 character\r
+ if ((c >= 0xD800) && (c <= 0xDBFF))\r
+ {\r
+ if (Begin < End)\r
+ {\r
+ // The second element is valid : convert the two elements to a UTF-32 character\r
+ Uint32 d = *Begin++;\r
+ if ((d >= 0xDC00) && (d <= 0xDFFF))\r
+ c = static_cast<Uint32>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);\r
+ }\r
+ else\r
+ {\r
+ // Invalid second element\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ }\r
+\r
+ // Then convert to UTF-8\r
+ if (c > 0x0010FFFF)\r
+ {\r
+ // Invalid character (greater than the maximum unicode value)\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ else\r
+ {\r
+ // Valid character\r
+\r
+ // Get number of bytes to write\r
+ int BytesToWrite = 1;\r
+ if (c < 0x80) BytesToWrite = 1;\r
+ else if (c < 0x800) BytesToWrite = 2;\r
+ else if (c < 0x10000) BytesToWrite = 3;\r
+ else if (c <= 0x0010FFFF) BytesToWrite = 4;\r
+\r
+ // Extract bytes to write\r
+ Uint8 Bytes[4];\r
+ switch (BytesToWrite)\r
+ {\r
+ case 4 : Bytes[3] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;\r
+ case 3 : Bytes[2] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;\r
+ case 2 : Bytes[1] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;\r
+ case 1 : Bytes[0] = static_cast<Uint8> (c | UTF8FirstBytes[BytesToWrite]);\r
+ }\r
+\r
+ // Add them to the output\r
+ const Uint8* CurByte = Bytes;\r
+ switch (BytesToWrite)\r
+ {\r
+ case 4 : *Output++ = *CurByte++;\r
+ case 3 : *Output++ = *CurByte++;\r
+ case 2 : *Output++ = *CurByte++;\r
+ case 1 : *Output++ = *CurByte++;\r
+ }\r
+ }\r
+ }\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an UTF-16 characters range\r
+/// to an UTF-32 characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement)\r
+{\r
+ while (Begin < End)\r
+ {\r
+ Uint16 c = *Begin++;\r
+ if ((c >= 0xD800) && (c <= 0xDBFF))\r
+ {\r
+ // We have a surrogate pair, ie. a character composed of two elements\r
+ if (Begin < End)\r
+ {\r
+ Uint16 d = *Begin++;\r
+ if ((d >= 0xDC00) && (d <= 0xDFFF))\r
+ {\r
+ // The second element is valid : convert the two elements to a UTF-32 character\r
+ *Output++ = static_cast<Uint32>(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000);\r
+ }\r
+ else\r
+ {\r
+ // Invalid second element\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ }\r
+ }\r
+ else if ((c >= 0xDC00) && (c <= 0xDFFF))\r
+ {\r
+ // Invalid character\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ else\r
+ {\r
+ // Valid character directly convertible to UTF-32\r
+ *Output++ = static_cast<Uint32>(c);\r
+ }\r
+ }\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an UTF-32 characters range\r
+/// to an UTF-8 characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement)\r
+{\r
+ while (Begin < End)\r
+ {\r
+ Uint32 c = *Begin++;\r
+ if (c > 0x0010FFFF)\r
+ {\r
+ // Invalid character (greater than the maximum unicode value)\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ else\r
+ {\r
+ // Valid character\r
+\r
+ // Get number of bytes to write\r
+ int BytesToWrite = 1;\r
+ if (c < 0x80) BytesToWrite = 1;\r
+ else if (c < 0x800) BytesToWrite = 2;\r
+ else if (c < 0x10000) BytesToWrite = 3;\r
+ else if (c <= 0x0010FFFF) BytesToWrite = 4;\r
+\r
+ // Extract bytes to write\r
+ Uint8 Bytes[4];\r
+ switch (BytesToWrite)\r
+ {\r
+ case 4 : Bytes[3] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;\r
+ case 3 : Bytes[2] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;\r
+ case 2 : Bytes[1] = static_cast<Uint8>((c | 0x80) & 0xBF); c >>= 6;\r
+ case 1 : Bytes[0] = static_cast<Uint8> (c | UTF8FirstBytes[BytesToWrite]);\r
+ }\r
+\r
+ // Add them to the output\r
+ const Uint8* CurByte = Bytes;\r
+ switch (BytesToWrite)\r
+ {\r
+ case 4 : *Output++ = *CurByte++;\r
+ case 3 : *Output++ = *CurByte++;\r
+ case 2 : *Output++ = *CurByte++;\r
+ case 1 : *Output++ = *CurByte++;\r
+ }\r
+ }\r
+ }\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Generic function to convert an UTF-32 characters range\r
+/// to an UTF-16 characters range, using the given locale\r
+////////////////////////////////////////////////////////////\r
+template <typename In, typename Out>\r
+inline Out Unicode::UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement)\r
+{\r
+ while (Begin < End)\r
+ {\r
+ Uint32 c = *Begin++;\r
+ if (c < 0xFFFF)\r
+ {\r
+ // Character can be converted directly to 16 bits, just need to check it's in the valid range\r
+ if ((c >= 0xD800) && (c <= 0xDFFF))\r
+ {\r
+ // Invalid character (this range is reserved)\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ else\r
+ {\r
+ // Valid character directly convertible to 16 bits\r
+ *Output++ = static_cast<Uint16>(c);\r
+ }\r
+ }\r
+ else if (c > 0x0010FFFF)\r
+ {\r
+ // Invalid character (greater than the maximum unicode value)\r
+ if (Replacement)\r
+ *Output++ = Replacement;\r
+ }\r
+ else\r
+ {\r
+ // Character will be converted to 2 UTF-16 elements\r
+ c -= 0x0010000;\r
+ *Output++ = static_cast<Uint16>((c >> 10) + 0xD800);\r
+ *Output++ = static_cast<Uint16>((c & 0x3FFUL) + 0xDC00);\r
+ }\r
+ }\r
+\r
+ return Output;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Get the number of characters composing an UTF-8 string\r
+////////////////////////////////////////////////////////////\r
+template <typename In>\r
+inline std::size_t Unicode::GetUTF8Length(In Begin, In End)\r
+{\r
+ std::size_t Length = 0;\r
+ while (Begin < End)\r
+ {\r
+ int NbBytes = UTF8TrailingBytes[static_cast<int>(*Begin)];\r
+ if (Begin + NbBytes < End)\r
+ ++Length;\r
+\r
+ Begin += NbBytes + 1;\r
+ }\r
+\r
+ return Length;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Get the number of characters composing an UTF-16 string\r
+////////////////////////////////////////////////////////////\r
+template <typename In>\r
+inline std::size_t Unicode::GetUTF16Length(In Begin, In End)\r
+{\r
+ std::size_t Length = 0;\r
+ while (Begin < End)\r
+ {\r
+ if ((*Begin >= 0xD800) && (*Begin <= 0xDBFF))\r
+ {\r
+ ++Begin;\r
+ if ((Begin < End) && ((*Begin >= 0xDC00) && (*Begin <= 0xDFFF)))\r
+ {\r
+ ++Length;\r
+ }\r
+ }\r
+ else\r
+ {\r
+ ++Length;\r
+ }\r
+\r
+ ++Begin;\r
+ }\r
+\r
+ return Length;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Get the number of characters composing an UTF-32 string\r
+////////////////////////////////////////////////////////////\r
+template <typename In>\r
+inline std::size_t Unicode::GetUTF32Length(In Begin, In End)\r
+{\r
+ return End - Begin;\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_MUTEXUNIX_HPP\r
+#define SFML_MUTEXUNIX_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <pthread.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Mutex defines a mutex (MUTual EXclusion) object,\r
+/// that allows a thread to lock critical instructions\r
+/// to avoid simultaneous access with other threads.\r
+/// See Lock for an efficient way of using it.\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Mutex : NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Mutex();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Mutex();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Lock the mutex\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Lock();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Unlock the mutex\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Unlock();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ pthread_mutex_t myMutex; ///< pthread instance of the mutex\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_MUTEXUNIX_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_THREADUNIX_HPP\r
+#define SFML_THREADUNIX_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <pthread.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Thread defines a thread.\r
+/// There is two ways to use Thread :\r
+/// - Inherit from it and override the Run() virtual function\r
+/// - Construct a sfThread instance and pass it a function\r
+/// pointer to call\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Thread : NonCopyable\r
+{\r
+public :\r
+\r
+ typedef void (*FuncType)(void*);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the thread from a function pointer\r
+ ///\r
+ /// \param Function : Entry point of the thread\r
+ /// \param UserData : Data to pass to the thread function (NULL by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Thread(FuncType Function, void* UserData = NULL);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Virtual destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~Thread();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create and run the thread\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Launch();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Wait until the thread finishes\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Wait();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Terminate the thread\r
+ /// Terminating a thread with this function is not safe,\r
+ /// you should rather try to make the thread function\r
+ /// terminate by itself\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Terminate();\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Thread();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Function called as the thread entry point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Run();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Actual thread entry point, dispatches to instances\r
+ ///\r
+ /// \param UserData : Data to pass to the thread function\r
+ ///\r
+ /// \return Error code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static void* ThreadFunc(void* UserData);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ pthread_t myThread; ///< Unix thread instance\r
+ bool myIsActive; ///< Thread state (active or inactive)\r
+ FuncType myFunction; ///< Function to call as the thread entry point\r
+ void* myUserData; ///< Data to pass to the thread function\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_THREADUNIX_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_VECTOR2_HPP\r
+#define SFML_VECTOR2_HPP\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Vector2 is an utility class for manipulating 2 dimensional\r
+/// vectors. Template parameter defines the type of coordinates\r
+/// (integer, float, ...)\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+class Vector2\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Vector2();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the vector from its coordinates\r
+ ///\r
+ /// \param X : X coordinate\r
+ /// \param Y : Y coordinate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Vector2(T X, T Y);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ T x; ///< X coordinate of the vector\r
+ T y; ///< Y coordinate of the vector\r
+};\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; returns the opposite of a vector\r
+///\r
+/// \param V : Vector to negate\r
+///\r
+/// \return -V\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator -(const Vector2<T>& V);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator += overload ; add two vectors and assign to the first op\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 + V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator -= overload ; subtract two vectors and assign to the first op\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 - V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator + overload ; adds two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 + V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; subtracts two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 - V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V * X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator *(const Vector2<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a scalar value by a vector\r
+///\r
+/// \param X : Scalar value\r
+/// \param V : Vector\r
+///\r
+/// \return X * V\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator *(T X, const Vector2<T>& V);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator *= overload ; multiply-assign a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V * X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator *=(Vector2<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator / overload ; divide a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V / X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator /(const Vector2<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator /= overload ; divide-assign a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V / X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator /=(Vector2<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator == overload ; compares the equality of two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return True if V1 is equal to V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator != overload ; compares the difference of two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return True if V1 is different than V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2);\r
+\r
+#include <SFML/System/Vector2.inl>\r
+\r
+// Define the most common types\r
+typedef Vector2<int> Vector2i;\r
+typedef Vector2<float> Vector2f;\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_VECTOR2_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Default constructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>::Vector2() :\r
+x(0),\r
+y(0)\r
+{\r
+\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Construct the color from its coordinates\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>::Vector2(T X, T Y) :\r
+x(X),\r
+y(Y)\r
+{\r
+\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; returns the opposite of a vector\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator -(const Vector2<T>& V)\r
+{\r
+ return Vector2<T>(-V.x, -V.y);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator += overload ; add two vectors and assign to the first op\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2)\r
+{\r
+ V1.x += V2.x;\r
+ V1.y += V2.y;\r
+\r
+ return V1;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator -= overload ; subtract two vectors and assign to the first op\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2)\r
+{\r
+ V1.x -= V2.x;\r
+ V1.y -= V2.y;\r
+\r
+ return V1;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator + overload ; adds two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2)\r
+{\r
+ return Vector2<T>(V1.x + V2.x, V1.y + V2.y);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; subtracts two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2)\r
+{\r
+ return Vector2<T>(V1.x - V2.x, V1.y - V2.y);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator *(const Vector2<T>& V, T X)\r
+{\r
+ return Vector2<T>(V.x * X, V.y * X);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a scalar value by a vector\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator *(T X, const Vector2<T>& V)\r
+{\r
+ return Vector2<T>(V.x * X, V.y * X);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator *= overload ; multiply-assign a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator *=(Vector2<T>& V, T X)\r
+{\r
+ V.x *= X;\r
+ V.y *= X;\r
+\r
+ return V;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator / overload ; divide a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T> operator /(const Vector2<T>& V, T X)\r
+{\r
+ return Vector2<T>(V.x / X, V.y / X);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator /= overload ; divide-assign a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector2<T>& operator /=(Vector2<T>& V, T X)\r
+{\r
+ V.x /= X;\r
+ V.y /= X;\r
+\r
+ return V;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator == overload ; compares the equality of two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2)\r
+{\r
+ return (V1.x == V2.x) && (V1.y == V2.y);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator != overload ; compares the difference of two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2)\r
+{\r
+ return (V1.x != V2.x) || (V1.y != V2.y);\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_VECTOR3_HPP\r
+#define SFML_VECTOR3_HPP\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Vector3 is an utility class for manipulating 3 dimensional\r
+/// vectors. Template parameter defines the type of coordinates\r
+/// (integer, float, ...)\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+class Vector3\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Vector3();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the vector from its coordinates\r
+ ///\r
+ /// \param X : X coordinate\r
+ /// \param Y : Y coordinate\r
+ /// \param Z : Z coordinate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Vector3(T X, T Y, T Z);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ T x; ///< X coordinate of the vector\r
+ T y; ///< Y coordinate of the vector\r
+ T z; ///< Z coordinate of the vector\r
+};\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; returns the opposite of a vector\r
+///\r
+/// \param V : Vector to negate\r
+///\r
+/// \return -V\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator -(const Vector3<T>& V);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator += overload ; add two vectors and assign to the first op\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 + V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator -= overload ; subtract two vectors and assign to the first op\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 - V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator + overload ; adds two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 + V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; subtracts two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return V1 - V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V * X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator *(const Vector3<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a scalar value by a vector\r
+///\r
+/// \param X : Scalar value\r
+/// \param V : Vector\r
+///\r
+/// \return X * V\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator *(T X, const Vector3<T>& V);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator *= overload ; multiply-assign a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V * X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator *=(Vector3<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator / overload ; divide a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V / X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator /(const Vector3<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator /= overload ; divide-assign a vector by a scalar value\r
+///\r
+/// \param V : Vector\r
+/// \param X : Scalar value\r
+///\r
+/// \return V / X\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator /=(Vector3<T>& V, T X);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator == overload ; compares the equality of two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return True if V1 is equal to V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2);\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator != overload ; compares the difference of two vectors\r
+///\r
+/// \param V1 : First vector\r
+/// \param V2 : Second vector\r
+///\r
+/// \return True if V1 is different than V2\r
+///\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2);\r
+\r
+#include <SFML/System/Vector3.inl>\r
+\r
+// Define the most common types\r
+typedef Vector3<int> Vector3i;\r
+typedef Vector3<float> Vector3f;\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_VECTOR3_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Default constructor\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>::Vector3() :\r
+x(0),\r
+y(0),\r
+z(0)\r
+{\r
+\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Construct the color from its coordinates\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>::Vector3(T X, T Y, T Z) :\r
+x(X),\r
+y(Y),\r
+z(Z)\r
+{\r
+\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; returns the opposite of a vector\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator -(const Vector3<T>& V)\r
+{\r
+ return Vector3<T>(-V.x, -V.y, -V.z);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator += overload ; add two vectors and assign to the first op\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2)\r
+{\r
+ V1.x += V2.x;\r
+ V1.y += V2.y;\r
+ V1.z += V2.z;\r
+\r
+ return V1;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator -= overload ; subtract two vectors and assign to the first op\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2)\r
+{\r
+ V1.x -= V2.x;\r
+ V1.y -= V2.y;\r
+ V1.z -= V2.z;\r
+\r
+ return V1;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator + overload ; adds two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2)\r
+{\r
+ return Vector3<T>(V1.x + V2.x, V1.y + V2.y, V1.z + V2.z);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator - overload ; subtracts two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2)\r
+{\r
+ return Vector3<T>(V1.x - V2.x, V1.y - V2.y, V1.z - V2.z);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator *(const Vector3<T>& V, T X)\r
+{\r
+ return Vector3<T>(V.x * X, V.y * X, V.z * X);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator * overload ; multiply a scalar value by a vector\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator *(T X, const Vector3<T>& V)\r
+{\r
+ return Vector3<T>(V.x * X, V.y * X, V.z * X);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator *= overload ; multiply-assign a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator *=(Vector3<T>& V, T X)\r
+{\r
+ V.x *= X;\r
+ V.y *= X;\r
+ V.z *= X;\r
+\r
+ return V;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator / overload ; divide a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T> operator /(const Vector3<T>& V, T X)\r
+{\r
+ return Vector3<T>(V.x / X, V.y / X, V.z / X);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator /= overload ; divide-assign a vector by a scalar value\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+Vector3<T>& operator /=(Vector3<T>& V, T X)\r
+{\r
+ V.x /= X;\r
+ V.y /= X;\r
+ V.z /= X;\r
+\r
+ return V;\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator == overload ; compares the equality of two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2)\r
+{\r
+ return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z);\r
+}\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Operator != overload ; compares the difference of two vectors\r
+////////////////////////////////////////////////////////////\r
+template <typename T>\r
+bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2)\r
+{\r
+ return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z);\r
+}\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_MUTEXWIN32_HPP\r
+#define SFML_MUTEXWIN32_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <windows.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Mutex defines a mutex (MUTual EXclusion) object,\r
+/// that allows a thread to lock critical instructions\r
+/// to avoid simultaneous access with other threads.\r
+/// The Win32 version uses critical sections, as it is\r
+/// faster than mutexes.<br/>\r
+/// See Lock for an efficient way of using it.\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Mutex : NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Mutex();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Mutex();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Lock the mutex\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Lock();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Unlock the mutex\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Unlock();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ CRITICAL_SECTION myHandle; ///< Win32 handle of the mutex\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_MUTEXWIN32_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_THREADWIN32_HPP\r
+#define SFML_THREADWIN32_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <windows.h>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Thread defines an easy way to manipulate a thread.\r
+/// There are two ways to use Thread :\r
+/// - Inherit from it and override the Run() virtual function\r
+/// - Construct a Thread instance and pass it a function\r
+/// pointer to call\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Thread : NonCopyable\r
+{\r
+public :\r
+\r
+ typedef void (*FuncType)(void*);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the thread from a function pointer\r
+ ///\r
+ /// \param Function : Entry point of the thread\r
+ /// \param UserData : Data to pass to the thread function (NULL by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Thread(FuncType Function, void* UserData = NULL);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Virtual destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~Thread();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create and run the thread\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Launch();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Wait until the thread finishes\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Wait();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Terminate the thread\r
+ /// Terminating a thread with this function is not safe,\r
+ /// you should rather try to make the thread function\r
+ /// terminate by itself\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Terminate();\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Thread();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Function called as the thread entry point\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void Run();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Actual thread entry point, dispatches to instances\r
+ ///\r
+ /// \param UserData : Data to pass to the thread function\r
+ ///\r
+ /// \return Error code\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static unsigned int __stdcall ThreadFunc(void* UserData);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ HANDLE myHandle; ///< Win32 thread handle\r
+ FuncType myFunction; ///< Function to call as the thread entry point\r
+ void* myUserData; ///< Data to pass to the thread function\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_THREADWIN32_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_CONTEXT_HPP\r
+#define SFML_CONTEXT_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <SFML/System/NonCopyable.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+namespace priv\r
+{\r
+ class WindowImpl;\r
+}\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Class wrapping an OpenGL context.\r
+/// All SFML windows already have their own context, so\r
+/// this class is more a helper for specific issues involving\r
+/// OpenGL and multi-threading.\r
+/// It's meant to be used internally.\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Context : NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor, create the context\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Context();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor, destroy the context\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ ~Context();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Activate or deactivate the context\r
+ ///\r
+ /// \param Active : True to activate the context, false to deactivate it\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetActive(bool Active);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Check if there's a context bound to the current thread\r
+ ///\r
+ /// \return True if there's a context bound to the current thread\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static bool IsContextActive();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the global context\r
+ ///\r
+ /// \return Reference to the global context\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static Context& GetGlobal();\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ priv::WindowImpl* myDummyWindow; ///< Dummy window holding the context\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_CONTEXT_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////
+//
+// SFML - Simple and Fast Multimedia Library
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#ifndef SFML_EVENT_HPP
+#define SFML_EVENT_HPP
+
+////////////////////////////////////////////////////////////
+// Headers
+////////////////////////////////////////////////////////////
+#include <SFML/Config.hpp>
+
+
+namespace sf
+{
+////////////////////////////////////////////////////////////
+/// Definition of key codes for keyboard events
+////////////////////////////////////////////////////////////
+namespace Key
+{
+ enum Code
+ {
+ A = 'a',
+ B = 'b',
+ C = 'c',
+ D = 'd',
+ E = 'e',
+ F = 'f',
+ G = 'g',
+ H = 'h',
+ I = 'i',
+ J = 'j',
+ K = 'k',
+ L = 'l',
+ M = 'm',
+ N = 'n',
+ O = 'o',
+ P = 'p',
+ Q = 'q',
+ R = 'r',
+ S = 's',
+ T = 't',
+ U = 'u',
+ V = 'v',
+ W = 'w',
+ X = 'x',
+ Y = 'y',
+ Z = 'z',
+ Num0 = '0',
+ Num1 = '1',
+ Num2 = '2',
+ Num3 = '3',
+ Num4 = '4',
+ Num5 = '5',
+ Num6 = '6',
+ Num7 = '7',
+ Num8 = '8',
+ Num9 = '9',
+ Escape = 256,
+ LControl,
+ LShift,
+ LAlt,
+ LSystem, ///< OS specific key (left side) : windows (Win and Linux), apple (MacOS), ...
+ RControl,
+ RShift,
+ RAlt,
+ RSystem, ///< OS specific key (right side) : windows (Win and Linux), apple (MacOS), ...
+ Menu,
+ LBracket, ///< [
+ RBracket, ///< ]
+ SemiColon, ///< ;
+ Comma, ///< ,
+ Period, ///< .
+ Quote, ///< '
+ Slash, ///< /
+ BackSlash,
+ Tilde, ///< ~
+ Equal, ///< =
+ Dash, ///< -
+ Space,
+ Return,
+ Back,
+ Tab,
+ PageUp,
+ PageDown,
+ End,
+ Home,
+ Insert,
+ Delete,
+ Add, ///< +
+ Subtract, ///< -
+ Multiply, ///< *
+ Divide, ///< /
+ Left, ///< Left arrow
+ Right, ///< Right arrow
+ Up, ///< Up arrow
+ Down, ///< Down arrow
+ Numpad0,
+ Numpad1,
+ Numpad2,
+ Numpad3,
+ Numpad4,
+ Numpad5,
+ Numpad6,
+ Numpad7,
+ Numpad8,
+ Numpad9,
+ F1,
+ F2,
+ F3,
+ F4,
+ F5,
+ F6,
+ F7,
+ F8,
+ F9,
+ F10,
+ F11,
+ F12,
+ F13,
+ F14,
+ F15,
+ Pause,
+
+ Count // Keep last -- total number of keyboard keys
+ };
+}
+
+
+////////////////////////////////////////////////////////////
+/// Definition of button codes for mouse events
+////////////////////////////////////////////////////////////
+namespace Mouse
+{
+ enum Button
+ {
+ Left,
+ Right,
+ Middle,
+ XButton1,
+ XButton2,
+
+ ButtonCount // Keep last -- total number of mouse buttons
+ };
+}
+
+
+////////////////////////////////////////////////////////////
+/// Definition of joystick axis for joystick events
+////////////////////////////////////////////////////////////
+namespace Joy
+{
+ enum Axis
+ {
+ AxisX,
+ AxisY,
+ AxisZ,
+ AxisR,
+ AxisU,
+ AxisV,
+ AxisPOV,
+
+ AxisCount // Keep last -- total number of joystick axis
+ };
+
+ enum
+ {
+ Count = 4, ///< Total number of supported joysticks
+ ButtonCount = 32 ///< Total number of supported joystick buttons
+ };
+}
+
+
+////////////////////////////////////////////////////////////
+/// Event defines a system event and its parameters
+////////////////////////////////////////////////////////////
+class Event
+{
+public :
+
+ ////////////////////////////////////////////////////////////
+ /// Keyboard event parameters
+ ////////////////////////////////////////////////////////////
+ struct KeyEvent
+ {
+ Key::Code Code;
+ bool Alt;
+ bool Control;
+ bool Shift;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Text event parameters
+ ////////////////////////////////////////////////////////////
+ struct TextEvent
+ {
+ Uint32 Unicode;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Mouse move event parameters
+ ////////////////////////////////////////////////////////////
+ struct MouseMoveEvent
+ {
+ int X;
+ int Y;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Mouse buttons events parameters
+ ////////////////////////////////////////////////////////////
+ struct MouseButtonEvent
+ {
+ Mouse::Button Button;
+ int X;
+ int Y;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Mouse wheel events parameters
+ ////////////////////////////////////////////////////////////
+ struct MouseWheelEvent
+ {
+ int Delta;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Joystick axis move event parameters
+ ////////////////////////////////////////////////////////////
+ struct JoyMoveEvent
+ {
+ unsigned int JoystickId;
+ Joy::Axis Axis;
+ float Position;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Joystick buttons events parameters
+ ////////////////////////////////////////////////////////////
+ struct JoyButtonEvent
+ {
+ unsigned int JoystickId;
+ unsigned int Button;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Size events parameters
+ ////////////////////////////////////////////////////////////
+ struct SizeEvent
+ {
+ unsigned int Width;
+ unsigned int Height;
+ };
+
+ ////////////////////////////////////////////////////////////
+ /// Enumeration of the different types of events
+ ////////////////////////////////////////////////////////////
+ enum EventType
+ {
+ Closed,
+ Resized,
+ LostFocus,
+ GainedFocus,
+ TextEntered,
+ KeyPressed,
+ KeyReleased,
+ MouseWheelMoved,
+ MouseButtonPressed,
+ MouseButtonReleased,
+ MouseMoved,
+ MouseEntered,
+ MouseLeft,
+ JoyButtonPressed,
+ JoyButtonReleased,
+ JoyMoved,
+
+ Count // Keep last -- total number of event types
+ };
+
+ ////////////////////////////////////////////////////////////
+ // Member data
+ ////////////////////////////////////////////////////////////
+ EventType Type; ///< Type of the event
+
+ union
+ {
+ KeyEvent Key;
+ TextEvent Text;
+ MouseMoveEvent MouseMove;
+ MouseButtonEvent MouseButton;
+ MouseWheelEvent MouseWheel;
+ JoyMoveEvent JoyMove;
+ JoyButtonEvent JoyButton;
+ SizeEvent Size;
+ };
+};
+
+} // namespace sf
+
+
+#endif // SFML_EVENT_HPP
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_INPUT_HPP\r
+#define SFML_INPUT_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <SFML/Window/Event.hpp>\r
+#include <SFML/Window/WindowListener.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Input handles real-time input from keyboard and mouse.\r
+/// Use it instead of events to handle continuous moves and more\r
+/// game-friendly inputs\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Input : public WindowListener, NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Input();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the state of a key\r
+ ///\r
+ /// \param KeyCode : Key to check\r
+ ///\r
+ /// \return True if key is down, false if key is up\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsKeyDown(Key::Code KeyCode) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the state of a mouse button\r
+ ///\r
+ /// \param Button : Button to check\r
+ ///\r
+ /// \return True if button is down, false if button is up\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsMouseButtonDown(Mouse::Button Button) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the state of a joystick button\r
+ ///\r
+ /// \param JoyId : Identifier of the joystick to check (0 or 1)\r
+ /// \param Button : Button to check\r
+ ///\r
+ /// \return True if button is down, false if button is up\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the mouse X position\r
+ ///\r
+ /// \return Current mouse left position, relative to owner window\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ int GetMouseX() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the mouse Y position\r
+ ///\r
+ /// \return Current mouse top position, relative to owner window\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ int GetMouseY() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a joystick axis position\r
+ ///\r
+ /// \param JoyId : Identifier of the joystick to check (0 or 1)\r
+ /// \param Axis : Axis to get\r
+ ///\r
+ /// \return Current axis position, in the range [-100, 100] (except for POV, which is [0, 360])\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const;\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see WindowListener::OnEvent\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnEvent(const Event& EventReceived);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Reset all the states\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void ResetStates();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys\r
+ bool myMouseButtons[Mouse::ButtonCount]; ///< Array containing the state of all mouse buttons\r
+ int myMouseX; ///< Mouse position on X\r
+ int myMouseY; ///< Mouse position on Y\r
+ bool myJoystickButtons[Joy::Count][Joy::ButtonCount]; ///< Array containing the state of all joysticks buttons\r
+ float myJoystickAxis[Joy::Count][Joy::AxisCount]; ///< Joysticks position on each axis\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_INPUT_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_OPENGL_HPP\r
+#define SFML_OPENGL_HPP\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+////////////////////////////////////////////////////////////\r
+/// This file just includes the OpenGL (GL and GLU) headers,\r
+/// which have actually different paths on each system\r
+////////////////////////////////////////////////////////////\r
+#if defined(SFML_SYSTEM_WINDOWS)\r
+\r
+ #include <windows.h>\r
+ #include <GL/gl.h>\r
+ #include <GL/glu.h>\r
+\r
+#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)\r
+\r
+ #include <GL/gl.h>\r
+ #include <GL/glu.h>\r
+\r
+#elif defined(SFML_SYSTEM_MACOS)\r
+\r
+ #include <OpenGL/gl.h>\r
+ #include <OpenGL/glu.h>\r
+\r
+#endif\r
+\r
+\r
+#endif // SFML_OPENGL_HPP\r
+\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_VIDEOMODE_HPP\r
+#define SFML_VIDEOMODE_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+#include <cstdlib>\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// VideoMode defines a video mode (width, height, bpp, frequency)\r
+/// and provides static functions for getting modes supported\r
+/// by the display device\r
+////////////////////////////////////////////////////////////\r
+class SFML_API VideoMode\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ VideoMode();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the video mode with its attributes\r
+ ///\r
+ /// \param ModeWidth : Width in pixels\r
+ /// \param ModeHeight : Height in pixels\r
+ /// \param ModeBpp : Pixel depths in bits per pixel (32 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ VideoMode(unsigned int ModeWidth, unsigned int ModeHeight, unsigned int ModeBpp = 32);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the current desktop video mode\r
+ ///\r
+ /// \return Current desktop video mode\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static VideoMode GetDesktopMode();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get a valid video mode\r
+ /// Index must be in range [0, GetModesCount()[\r
+ /// Modes are sorted from best to worst\r
+ ///\r
+ /// \param Index : Index of video mode to get\r
+ ///\r
+ /// \return Corresponding video mode (invalid mode if index is out of range)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static VideoMode GetMode(std::size_t Index);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get valid video modes count\r
+ ///\r
+ /// \return Number of valid video modes available\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ static std::size_t GetModesCount();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell whether or not the video mode is supported\r
+ ///\r
+ /// \return True if video mode is supported, false otherwise\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsValid() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator overload -- tell if two video modes are equal\r
+ ///\r
+ /// \param Other : Video mode to compare\r
+ ///\r
+ /// \return True if modes are equal\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator ==(const VideoMode& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Comparison operator overload -- tell if two video modes are different\r
+ ///\r
+ /// \param Other : Video mode to compare\r
+ ///\r
+ /// \return True if modes are different\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool operator !=(const VideoMode& Other) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int Width; ///< Video mode width, in pixels\r
+ unsigned int Height; ///< Video mode height, in pixels\r
+ unsigned int BitsPerPixel; ///< Video mode pixel depth, in bits per pixels\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get and sort valid video modes\r
+ ////////////////////////////////////////////////////////////\r
+ static void InitializeModes();\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_VIDEOMODE_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_WINDOW_HPP\r
+#define SFML_WINDOW_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Window/Event.hpp>\r
+#include <SFML/Window/Input.hpp>\r
+#include <SFML/Window/VideoMode.hpp>\r
+#include <SFML/Window/WindowHandle.hpp>\r
+#include <SFML/Window/WindowListener.hpp>\r
+#include <SFML/Window/WindowSettings.hpp>\r
+#include <SFML/Window/WindowStyle.hpp>\r
+#include <SFML/System/Clock.hpp>\r
+#include <SFML/System/NonCopyable.hpp>\r
+#include <queue>\r
+#include <string>\r
+\r
+\r
+namespace sf\r
+{\r
+namespace priv\r
+{\r
+ class WindowImpl;\r
+}\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Window is a rendering window ; it can create a new window\r
+/// or connect to an existing one\r
+////////////////////////////////////////////////////////////\r
+class SFML_API Window : public WindowListener, NonCopyable\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Window();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct a new window\r
+ ///\r
+ /// \param Mode : Video mode to use\r
+ /// \param Title : Title of the window\r
+ /// \param WindowStyle : Window style, see sf::Style (Resize | Close by default)\r
+ /// \param Params : Creation parameters (see default constructor for default values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Construct the window from an existing control\r
+ ///\r
+ /// \param Handle : Platform-specific handle of the control\r
+ /// \param Params : Creation parameters (see default constructor for default values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ Window(WindowHandle Handle, const WindowSettings& Params = WindowSettings());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~Window();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create (or recreate) the window\r
+ ///\r
+ /// \param Mode : Video mode to use\r
+ /// \param Title : Title of the window\r
+ /// \param WindowStyle : Window style, see sf::Style (Resize | Close by default)\r
+ /// \param Params : Creation parameters (see default constructor for default values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Create (or recreate) the window from an existing control\r
+ ///\r
+ /// \param Handle : Platform-specific handle of the control\r
+ /// \param Params : Creation parameters (see default constructor for default values)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Create(WindowHandle Handle, const WindowSettings& Params = WindowSettings());\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Close (destroy) the window.\r
+ /// The sf::Window instance remains valid and you can call\r
+ /// Create to recreate the window\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Close();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Tell whether or not the window is opened (ie. has been created).\r
+ /// Note that a hidden window (Show(false))\r
+ /// will still return true\r
+ ///\r
+ /// \return True if the window is opened\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool IsOpened() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the width of the rendering region of the window\r
+ ///\r
+ /// \return Width in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetWidth() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the height of the rendering region of the window\r
+ ///\r
+ /// \return Height in pixels\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int GetHeight() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the creation settings of the window\r
+ ///\r
+ /// \return Structure containing the creation settings\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const WindowSettings& GetSettings() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the event on top of events stack, if any, and pop it\r
+ ///\r
+ /// \param EventReceived : Event to fill, if any\r
+ ///\r
+ /// \return True if an event was returned, false if events stack was empty\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool GetEvent(Event& EventReceived);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enable / disable vertical synchronization\r
+ ///\r
+ /// \param Enabled : True to enable v-sync, false to deactivate\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void UseVerticalSync(bool Enabled);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Show or hide the mouse cursor\r
+ ///\r
+ /// \param Show : True to show, false to hide\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void ShowMouseCursor(bool Show);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the position of the mouse cursor\r
+ ///\r
+ /// \param Left : Left coordinate of the cursor, relative to the window\r
+ /// \param Top : Top coordinate of the cursor, relative to the window\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetCursorPosition(unsigned int Left, unsigned int Top);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the position of the window on screen.\r
+ /// Only works for top-level windows\r
+ ///\r
+ /// \param Left : Left position\r
+ /// \param Top : Top position\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetPosition(int Left, int Top);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the size of the rendering region of the window\r
+ ///\r
+ /// \param Width : New width\r
+ /// \param Height : New height\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetSize(unsigned int Width, unsigned int Height);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Show or hide the window\r
+ ///\r
+ /// \param State : True to show, false to hide\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Show(bool State);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Enable or disable automatic key-repeat.\r
+ /// Automatic key-repeat is enabled by default\r
+ ///\r
+ /// \param Enabled : True to enable, false to disable\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void EnableKeyRepeat(bool Enabled);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the window's icon\r
+ ///\r
+ /// \param Width : Icon's width, in pixels\r
+ /// \param Height : Icon's height, in pixels\r
+ /// \param Pixels : Pointer to the pixels in memory, format must be RGBA 32 bits\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Activate of deactivate the window as the current target\r
+ /// for rendering\r
+ ///\r
+ /// \param Active : True to activate, false to deactivate (true by default)\r
+ ///\r
+ /// \return True if operation was successful, false otherwise\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ bool SetActive(bool Active = true) const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Display the window on screen\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Display();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get the input manager of the window\r
+ ///\r
+ /// \return Reference to the input\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ const Input& GetInput() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Limit the framerate to a maximum fixed frequency\r
+ ///\r
+ /// \param Limit : Framerate limit, in frames per seconds (use 0 to disable limit)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetFramerateLimit(unsigned int Limit);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Get time elapsed since last frame\r
+ ///\r
+ /// \return Time elapsed, in seconds\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ float GetFrameTime() const;\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Change the joystick threshold, ie. the value below which\r
+ /// no move event will be generated\r
+ ///\r
+ /// \param Threshold : New threshold, in range [0, 100]\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void SetJoystickThreshold(float Threshold);\r
+\r
+private :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Called after the window has been created\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnCreate();\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// /see WindowListener::OnEvent\r
+ ///\r
+ /// \param EventReceived : Event received\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnEvent(const Event& EventReceived);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Initialize internal window\r
+ ///\r
+ /// \param Impl : New internal window implementation\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ void Initialize(priv::WindowImpl* Impl);\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ priv::WindowImpl* myWindow; ///< Platform-specific implementation of window\r
+ std::queue<Event> myEvents; ///< Queue of received events\r
+ Input myInput; ///< Input manager connected to window\r
+ Clock myClock; ///< Clock for measuring the elapsed time between frames\r
+ WindowSettings mySettings; ///< Creation settings of the window\r
+ float myLastFrameTime; ///< Time elapsed since last frame\r
+ bool myIsExternal; ///< Tell whether the window is internal or external (created by SFML or not)\r
+ unsigned int myFramerateLimit; ///< Current framerate limit\r
+ int mySetCursorPosX; ///< X coordinate passed to the last call to SetCursorPosition\r
+ int mySetCursorPosY; ///< Y coordinate passed to the last call to SetCursorPosition\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_WINDOW_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////
+//
+// SFML - Simple and Fast Multimedia Library
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
+//
+// This software is provided 'as-is', without any express or implied warranty.
+// In no event will the authors be held liable for any damages arising from the use of this software.
+//
+// Permission is granted to anyone to use this software for any purpose,
+// including commercial applications, and to alter it and redistribute it freely,
+// subject to the following restrictions:
+//
+// 1. The origin of this software must not be misrepresented;
+// you must not claim that you wrote the original software.
+// If you use this software in a product, an acknowledgment
+// in the product documentation would be appreciated but is not required.
+//
+// 2. Altered source versions must be plainly marked as such,
+// and must not be misrepresented as being the original software.
+//
+// 3. This notice may not be removed or altered from any source distribution.
+//
+////////////////////////////////////////////////////////////
+
+#ifndef SFML_WINDOWHANDLE_HPP
+#define SFML_WINDOWHANDLE_HPP
+
+////////////////////////////////////////////////////////////
+// Headers
+////////////////////////////////////////////////////////////
+#include <SFML/Config.hpp>
+
+
+namespace sf
+{
+////////////////////////////////////////////////////////////
+/// Define a low-level window handle type, specific to
+/// each platform
+////////////////////////////////////////////////////////////
+#if defined(SFML_SYSTEM_WINDOWS)
+
+ // Windows defines a void* handle (HWND)
+ typedef void* WindowHandle;
+
+#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
+
+ // Unix - X11 defines an unsigned integer handle (Window)
+ typedef unsigned long WindowHandle;
+
+#elif defined(SFML_SYSTEM_MACOS)
+
+ // Mac OS X defines a void* handle (NSWindow)
+ typedef void* WindowHandle;
+
+#endif
+
+} // namespace sf
+
+
+#endif // SFML_WINDOWHANDLE_HPP
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_WINDOWLISTENER_HPP\r
+#define SFML_WINDOWLISTENER_HPP\r
+\r
+////////////////////////////////////////////////////////////\r
+// Headers\r
+////////////////////////////////////////////////////////////\r
+#include <SFML/Config.hpp>\r
+\r
+\r
+namespace sf\r
+{\r
+class Event;\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Base class for classes that want to receive events\r
+/// from a window (for internal use only)\r
+////////////////////////////////////////////////////////////\r
+class SFML_API WindowListener\r
+{\r
+public :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Called each time an event is received from attached window\r
+ ///\r
+ /// \param EventReceived : Event received\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual void OnEvent(const Event& EventReceived) = 0;\r
+\r
+protected :\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ /// Destructor\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ virtual ~WindowListener() {}\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_WINDOWLISTENER_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_WINDOWSETTINGS_HPP\r
+#define SFML_WINDOWSETTINGS_HPP\r
+\r
+\r
+namespace sf\r
+{\r
+////////////////////////////////////////////////////////////\r
+/// Structure defining the creation settings of windows\r
+////////////////////////////////////////////////////////////\r
+struct WindowSettings\r
+{\r
+ ////////////////////////////////////////////////////////////\r
+ /// Default constructor\r
+ ///\r
+ /// \param Depth : Depth buffer bits (24 by default)\r
+ /// \param Stencil : Stencil buffer bits (8 by default)\r
+ /// \param Antialiasing : Antialiasing level (0 by default)\r
+ ///\r
+ ////////////////////////////////////////////////////////////\r
+ explicit WindowSettings(unsigned int Depth = 24, unsigned int Stencil = 8, unsigned int Antialiasing = 0) :\r
+ DepthBits (Depth),\r
+ StencilBits (Stencil),\r
+ AntialiasingLevel(Antialiasing)\r
+ {\r
+ }\r
+\r
+ ////////////////////////////////////////////////////////////\r
+ // Member data\r
+ ////////////////////////////////////////////////////////////\r
+ unsigned int DepthBits; ///< Bits of the depth buffer\r
+ unsigned int StencilBits; ///< Bits of the stencil buffer\r
+ unsigned int AntialiasingLevel; ///< Level of antialiasing\r
+};\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_WINDOWSETTINGS_HPP\r
--- /dev/null
+////////////////////////////////////////////////////////////\r
+//\r
+// SFML - Simple and Fast Multimedia Library\r
+// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)\r
+//\r
+// This software is provided 'as-is', without any express or implied warranty.\r
+// In no event will the authors be held liable for any damages arising from the use of this software.\r
+//\r
+// Permission is granted to anyone to use this software for any purpose,\r
+// including commercial applications, and to alter it and redistribute it freely,\r
+// subject to the following restrictions:\r
+//\r
+// 1. The origin of this software must not be misrepresented;\r
+// you must not claim that you wrote the original software.\r
+// If you use this software in a product, an acknowledgment\r
+// in the product documentation would be appreciated but is not required.\r
+//\r
+// 2. Altered source versions must be plainly marked as such,\r
+// and must not be misrepresented as being the original software.\r
+//\r
+// 3. This notice may not be removed or altered from any source distribution.\r
+//\r
+////////////////////////////////////////////////////////////\r
+\r
+#ifndef SFML_WINDOWSTYLE_HPP\r
+#define SFML_WINDOWSTYLE_HPP\r
+\r
+\r
+namespace sf\r
+{\r
+\r
+////////////////////////////////////////////////////////////\r
+/// Enumeration of window creation styles\r
+////////////////////////////////////////////////////////////\r
+namespace Style\r
+{\r
+ enum\r
+ {\r
+ None = 0, ///< No border / title bar (this flag and all others are mutually exclusive)\r
+ Titlebar = 1 << 0, ///< Title bar + fixed border\r
+ Resize = 1 << 1, ///< Titlebar + resizable border + maximize button\r
+ Close = 1 << 2, ///< Titlebar + close button\r
+ Fullscreen = 1 << 3 ///< Fullscreen mode (this flag and all others are mutually exclusive)\r
+ };\r
+}\r
+\r
+\r
+} // namespace sf\r
+\r
+\r
+#endif // SFML_WINDOWSTYLE_HPP\r