From aaa12d4a52ba203d5127852ddc9d5b8f5d56edff Mon Sep 17 00:00:00 2001 From: ronag Date: Sun, 26 Sep 2010 14:40:10 +0000 Subject: [PATCH] --- SFML-1.6/include/SFML/Audio/AudioResource.hpp | 67 +++ SFML-1.6/include/SFML/Audio/Listener.hpp | 122 +++++ SFML-1.6/include/SFML/Audio/Music.hpp | 120 +++++ SFML-1.6/include/SFML/Audio/Sound.hpp | 314 ++++++++++++ SFML-1.6/include/SFML/Audio/SoundBuffer.hpp | 213 ++++++++ .../SFML/Audio/SoundBufferRecorder.hpp | 83 +++ SFML-1.6/include/SFML/Audio/SoundRecorder.hpp | 148 ++++++ SFML-1.6/include/SFML/Audio/SoundStream.hpp | 228 +++++++++ SFML-1.6/include/SFML/Graphics/Color.hpp | 147 ++++++ SFML-1.6/include/SFML/Graphics/Drawable.hpp | 361 +++++++++++++ SFML-1.6/include/SFML/Graphics/Font.hpp | 145 ++++++ SFML-1.6/include/SFML/Graphics/Glyph.hpp | 61 +++ SFML-1.6/include/SFML/Graphics/Image.hpp | 332 ++++++++++++ SFML-1.6/include/SFML/Graphics/Matrix3.hpp | 148 ++++++ SFML-1.6/include/SFML/Graphics/Matrix3.inl | 186 +++++++ SFML-1.6/include/SFML/Graphics/PostFX.hpp | 194 +++++++ SFML-1.6/include/SFML/Graphics/Rect.hpp | 127 +++++ SFML-1.6/include/SFML/Graphics/Rect.inl | 122 +++++ .../include/SFML/Graphics/RenderTarget.hpp | 166 ++++++ .../include/SFML/Graphics/RenderWindow.hpp | 135 +++++ SFML-1.6/include/SFML/Graphics/Shape.hpp | 310 ++++++++++++ SFML-1.6/include/SFML/Graphics/Sprite.hpp | 176 +++++++ SFML-1.6/include/SFML/Graphics/String.hpp | 191 +++++++ SFML-1.6/include/SFML/Graphics/View.hpp | 188 +++++++ SFML-1.6/include/SFML/Network/Ftp.hpp | 448 +++++++++++++++++ SFML-1.6/include/SFML/Network/Http.hpp | 340 +++++++++++++ SFML-1.6/include/SFML/Network/IPAddress.hpp | 231 +++++++++ SFML-1.6/include/SFML/Network/Packet.hpp | 187 +++++++ SFML-1.6/include/SFML/Network/Selector.hpp | 116 +++++ SFML-1.6/include/SFML/Network/Selector.inl | 97 ++++ .../include/SFML/Network/SelectorBase.hpp | 112 +++++ .../include/SFML/Network/SocketHelper.hpp | 64 +++ SFML-1.6/include/SFML/Network/SocketTCP.hpp | 227 +++++++++ SFML-1.6/include/SFML/Network/SocketUDP.hpp | 228 +++++++++ SFML-1.6/include/SFML/Network/Sockets.hpp | 45 ++ .../SFML/Network/Unix/SocketHelper.hpp | 96 ++++ .../SFML/Network/Win32/SocketHelper.hpp | 90 ++++ SFML-1.6/include/SFML/System/Clock.hpp | 74 +++ SFML-1.6/include/SFML/System/Lock.hpp | 71 +++ SFML-1.6/include/SFML/System/Mutex.hpp | 45 ++ SFML-1.6/include/SFML/System/NonCopyable.hpp | 70 +++ SFML-1.6/include/SFML/System/Randomizer.hpp | 94 ++++ SFML-1.6/include/SFML/System/Resource.hpp | 216 ++++++++ SFML-1.6/include/SFML/System/Resource.inl | 88 ++++ SFML-1.6/include/SFML/System/ResourcePtr.inl | 149 ++++++ SFML-1.6/include/SFML/System/Sleep.hpp | 47 ++ SFML-1.6/include/SFML/System/Thread.hpp | 45 ++ SFML-1.6/include/SFML/System/Unicode.hpp | 290 +++++++++++ SFML-1.6/include/SFML/System/Unicode.inl | 474 ++++++++++++++++++ SFML-1.6/include/SFML/System/Unix/Mutex.hpp | 82 +++ SFML-1.6/include/SFML/System/Unix/Thread.hpp | 124 +++++ SFML-1.6/include/SFML/System/Vector2.hpp | 215 ++++++++ SFML-1.6/include/SFML/System/Vector2.inl | 179 +++++++ SFML-1.6/include/SFML/System/Vector3.hpp | 217 ++++++++ SFML-1.6/include/SFML/System/Vector3.inl | 185 +++++++ SFML-1.6/include/SFML/System/Win32/Mutex.hpp | 84 ++++ SFML-1.6/include/SFML/System/Win32/Thread.hpp | 123 +++++ SFML-1.6/include/SFML/Window/Context.hpp | 100 ++++ SFML-1.6/include/SFML/Window/Event.hpp | 321 ++++++++++++ SFML-1.6/include/SFML/Window/Input.hpp | 140 ++++++ SFML-1.6/include/SFML/Window/OpenGL.hpp | 59 +++ SFML-1.6/include/SFML/Window/VideoMode.hpp | 136 +++++ SFML-1.6/include/SFML/Window/Window.hpp | 326 ++++++++++++ SFML-1.6/include/SFML/Window/WindowHandle.hpp | 60 +++ .../include/SFML/Window/WindowListener.hpp | 66 +++ .../include/SFML/Window/WindowSettings.hpp | 62 +++ SFML-1.6/include/SFML/Window/WindowStyle.hpp | 51 ++ 67 files changed, 10758 insertions(+) create mode 100644 SFML-1.6/include/SFML/Audio/AudioResource.hpp create mode 100644 SFML-1.6/include/SFML/Audio/Listener.hpp create mode 100644 SFML-1.6/include/SFML/Audio/Music.hpp create mode 100644 SFML-1.6/include/SFML/Audio/Sound.hpp create mode 100644 SFML-1.6/include/SFML/Audio/SoundBuffer.hpp create mode 100644 SFML-1.6/include/SFML/Audio/SoundBufferRecorder.hpp create mode 100644 SFML-1.6/include/SFML/Audio/SoundRecorder.hpp create mode 100644 SFML-1.6/include/SFML/Audio/SoundStream.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Color.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Drawable.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Font.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Glyph.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Image.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Matrix3.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Matrix3.inl create mode 100644 SFML-1.6/include/SFML/Graphics/PostFX.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Rect.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Rect.inl create mode 100644 SFML-1.6/include/SFML/Graphics/RenderTarget.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/RenderWindow.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Shape.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/Sprite.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/String.hpp create mode 100644 SFML-1.6/include/SFML/Graphics/View.hpp create mode 100644 SFML-1.6/include/SFML/Network/Ftp.hpp create mode 100644 SFML-1.6/include/SFML/Network/Http.hpp create mode 100644 SFML-1.6/include/SFML/Network/IPAddress.hpp create mode 100644 SFML-1.6/include/SFML/Network/Packet.hpp create mode 100644 SFML-1.6/include/SFML/Network/Selector.hpp create mode 100644 SFML-1.6/include/SFML/Network/Selector.inl create mode 100644 SFML-1.6/include/SFML/Network/SelectorBase.hpp create mode 100644 SFML-1.6/include/SFML/Network/SocketHelper.hpp create mode 100644 SFML-1.6/include/SFML/Network/SocketTCP.hpp create mode 100644 SFML-1.6/include/SFML/Network/SocketUDP.hpp create mode 100644 SFML-1.6/include/SFML/Network/Sockets.hpp create mode 100644 SFML-1.6/include/SFML/Network/Unix/SocketHelper.hpp create mode 100644 SFML-1.6/include/SFML/Network/Win32/SocketHelper.hpp create mode 100644 SFML-1.6/include/SFML/System/Clock.hpp create mode 100644 SFML-1.6/include/SFML/System/Lock.hpp create mode 100644 SFML-1.6/include/SFML/System/Mutex.hpp create mode 100644 SFML-1.6/include/SFML/System/NonCopyable.hpp create mode 100644 SFML-1.6/include/SFML/System/Randomizer.hpp create mode 100644 SFML-1.6/include/SFML/System/Resource.hpp create mode 100644 SFML-1.6/include/SFML/System/Resource.inl create mode 100644 SFML-1.6/include/SFML/System/ResourcePtr.inl create mode 100644 SFML-1.6/include/SFML/System/Sleep.hpp create mode 100644 SFML-1.6/include/SFML/System/Thread.hpp create mode 100644 SFML-1.6/include/SFML/System/Unicode.hpp create mode 100644 SFML-1.6/include/SFML/System/Unicode.inl create mode 100644 SFML-1.6/include/SFML/System/Unix/Mutex.hpp create mode 100644 SFML-1.6/include/SFML/System/Unix/Thread.hpp create mode 100644 SFML-1.6/include/SFML/System/Vector2.hpp create mode 100644 SFML-1.6/include/SFML/System/Vector2.inl create mode 100644 SFML-1.6/include/SFML/System/Vector3.hpp create mode 100644 SFML-1.6/include/SFML/System/Vector3.inl create mode 100644 SFML-1.6/include/SFML/System/Win32/Mutex.hpp create mode 100644 SFML-1.6/include/SFML/System/Win32/Thread.hpp create mode 100644 SFML-1.6/include/SFML/Window/Context.hpp create mode 100644 SFML-1.6/include/SFML/Window/Event.hpp create mode 100644 SFML-1.6/include/SFML/Window/Input.hpp create mode 100644 SFML-1.6/include/SFML/Window/OpenGL.hpp create mode 100644 SFML-1.6/include/SFML/Window/VideoMode.hpp create mode 100644 SFML-1.6/include/SFML/Window/Window.hpp create mode 100644 SFML-1.6/include/SFML/Window/WindowHandle.hpp create mode 100644 SFML-1.6/include/SFML/Window/WindowListener.hpp create mode 100644 SFML-1.6/include/SFML/Window/WindowSettings.hpp create mode 100644 SFML-1.6/include/SFML/Window/WindowStyle.hpp diff --git a/SFML-1.6/include/SFML/Audio/AudioResource.hpp b/SFML-1.6/include/SFML/Audio/AudioResource.hpp new file mode 100644 index 000000000..410466dd5 --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/AudioResource.hpp @@ -0,0 +1,67 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_AUDIORESOURCE_HPP +#define SFML_AUDIORESOURCE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Abstract base class for every class that owns a +/// device-dependant resource -- allow them to initialize / shutdown +/// even when the audio context is not created +//////////////////////////////////////////////////////////// +class SFML_API AudioResource +{ +protected : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + AudioResource(); + + //////////////////////////////////////////////////////////// + /// Copy constructor + /// + //////////////////////////////////////////////////////////// + AudioResource(const AudioResource&); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + virtual ~AudioResource(); +}; + +} // namespace sf + + +#endif // SFML_AUDIORESOURCE_HPP diff --git a/SFML-1.6/include/SFML/Audio/Listener.hpp b/SFML-1.6/include/SFML/Audio/Listener.hpp new file mode 100644 index 000000000..95227cacf --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/Listener.hpp @@ -0,0 +1,122 @@ +//////////////////////////////////////////////////////////// +// +// 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_LISTENER_HPP +#define SFML_LISTENER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Listener is a global interface for defining the audio +/// listener properties ; the audio listener is the point in +/// the scene from where all the sounds are heard +//////////////////////////////////////////////////////////// +class SFML_API Listener +{ +public : + + //////////////////////////////////////////////////////////// + /// Change the global volume of all the sounds. + /// The default volume is 100 + /// + /// \param Volume : New global volume, in the range [0, 100] + /// + //////////////////////////////////////////////////////////// + static void SetGlobalVolume(float Volume); + + //////////////////////////////////////////////////////////// + /// Get the current value of the global volume of all the sounds + /// + /// \return Current global volume, in the range [0, 100] + /// + //////////////////////////////////////////////////////////// + static float GetGlobalVolume(); + + //////////////////////////////////////////////////////////// + /// Change the position of the listener (take 3 values). + /// The default position is (0, 0, 0) + /// + /// \param X, Y, Z : Position of the listener in the world + /// + //////////////////////////////////////////////////////////// + static void SetPosition(float X, float Y, float Z); + + //////////////////////////////////////////////////////////// + /// Change the position of the listener (take a 3D vector). + /// The default position is (0, 0, 0) + /// + /// \param Position : Position of the listener in the world + /// + //////////////////////////////////////////////////////////// + static void SetPosition(const Vector3f& Position); + + //////////////////////////////////////////////////////////// + /// Get the current position of the listener + /// + /// \return Position of the listener in the world + /// + //////////////////////////////////////////////////////////// + static Vector3f GetPosition(); + + //////////////////////////////////////////////////////////// + /// Change the orientation of the listener (the point + /// he must look at) (take 3 values). + /// The default target is (0, 0, -1) + /// + /// \param X, Y, Z : Position of the point the listener must look at + /// + //////////////////////////////////////////////////////////// + static void SetTarget(float X, float Y, float Z); + + //////////////////////////////////////////////////////////// + /// Change the orientation of the listener (the point + /// he must look at) (take a 3D vector). + /// The default target is (0, 0, -1) + /// + /// \param Target : Position of the point the listener must look at + /// + //////////////////////////////////////////////////////////// + static void SetTarget(const Vector3f& Target); + + //////////////////////////////////////////////////////////// + /// Get the current orientation of the listener (the point + /// he's looking at) + /// + /// \return : Position of the point the listener is looking at + /// + //////////////////////////////////////////////////////////// + static Vector3f GetTarget(); +}; + +} // namespace sf + + +#endif // SFML_LISTENER_HPP diff --git a/SFML-1.6/include/SFML/Audio/Music.hpp b/SFML-1.6/include/SFML/Audio/Music.hpp new file mode 100644 index 000000000..0b8f70d09 --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/Music.hpp @@ -0,0 +1,120 @@ +//////////////////////////////////////////////////////////// +// +// 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_MUSIC_HPP +#define SFML_MUSIC_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +namespace priv +{ + class SoundFile; +} + +//////////////////////////////////////////////////////////// +/// Music defines a big sound played using streaming, +/// so usually what we call a music :) +//////////////////////////////////////////////////////////// +class SFML_API Music : public SoundStream +{ +public : + + //////////////////////////////////////////////////////////// + /// Construct the music with a buffer size + /// + /// \param BufferSize : Size of the internal buffer, expressed in number of samples + /// (ie. size taken by the music in memory) (44100 by default) + /// + //////////////////////////////////////////////////////////// + explicit Music(std::size_t BufferSize = 44100); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~Music(); + + //////////////////////////////////////////////////////////// + /// Open a music file (doesn't play it -- call Play() for that) + /// + /// \param Filename : Path of the music file to open + /// + /// \return True if loading has been successful + /// + //////////////////////////////////////////////////////////// + bool OpenFromFile(const std::string& Filename); + + //////////////////////////////////////////////////////////// + /// Open a music file from memory (doesn't play it -- call Play() for that) + /// + /// \param Data : Pointer to the file data in memory + /// \param SizeInBytes : Size of the data to load, in bytes + /// + /// \return True if loading has been successful + /// + //////////////////////////////////////////////////////////// + bool OpenFromMemory(const char* Data, std::size_t SizeInBytes); + + //////////////////////////////////////////////////////////// + /// Get the music duration + /// + /// \return Music duration, in seconds + /// + //////////////////////////////////////////////////////////// + float GetDuration() const; + +private : + + //////////////////////////////////////////////////////////// + /// /see SoundStream::OnStart + /// + //////////////////////////////////////////////////////////// + virtual bool OnStart(); + + //////////////////////////////////////////////////////////// + /// /see SoundStream::OnGetData + /// + //////////////////////////////////////////////////////////// + virtual bool OnGetData(Chunk& Data); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + priv::SoundFile* myFile; ///< Sound file + float myDuration; ///< Music duration, in seconds + std::vector mySamples; ///< Temporary buffer of samples +}; + +} // namespace sf + + +#endif // SFML_MUSIC_HPP diff --git a/SFML-1.6/include/SFML/Audio/Sound.hpp b/SFML-1.6/include/SFML/Audio/Sound.hpp new file mode 100644 index 000000000..7cb800269 --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/Sound.hpp @@ -0,0 +1,314 @@ +//////////////////////////////////////////////////////////// +// +// 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_SOUND_HPP +#define SFML_SOUND_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +class SoundBuffer; + +//////////////////////////////////////////////////////////// +/// Sound defines the properties of a sound such as position, +/// volume, pitch, etc. +//////////////////////////////////////////////////////////// +class SFML_API Sound : public AudioResource +{ +public : + + //////////////////////////////////////////////////////////// + /// Enumeration of the sound states + //////////////////////////////////////////////////////////// + enum Status + { + Stopped, ///< Sound is not playing + Paused, ///< Sound is paused + Playing ///< Sound is playing + }; + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Sound(); + + //////////////////////////////////////////////////////////// + /// Construct the sound from its parameters + /// + /// \param Buffer : Sound buffer to play (NULL by default) + /// \param Loop : Loop flag (false by default) + /// \param Pitch : Value of the pitch (1 by default) + /// \param Volume : Volume (100 by default) + /// \param Position : Position (0, 0, 0 by default) + /// + //////////////////////////////////////////////////////////// + explicit Sound(const SoundBuffer& Buffer, bool Loop = false, float Pitch = 1.f, float Volume = 100.f, const Vector3f& Position = Vector3f(0, 0, 0)); + + //////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param Copy : Instance to copy + /// + //////////////////////////////////////////////////////////// + Sound(const Sound& Copy); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~Sound(); + + //////////////////////////////////////////////////////////// + /// Play the sound + /// + //////////////////////////////////////////////////////////// + void Play(); + + //////////////////////////////////////////////////////////// + /// Pause the sound + /// + //////////////////////////////////////////////////////////// + void Pause(); + + //////////////////////////////////////////////////////////// + /// Stop the sound + /// + //////////////////////////////////////////////////////////// + void Stop(); + + //////////////////////////////////////////////////////////// + /// Set the source buffer + /// + /// \param Buffer : New sound buffer to bind to the sound + /// + //////////////////////////////////////////////////////////// + void SetBuffer(const SoundBuffer& Buffer); + + //////////////////////////////////////////////////////////// + /// Set the sound loop state. + /// This parameter is disabled by default + /// + /// \param Loop : True to play in loop, false to play once + /// + //////////////////////////////////////////////////////////// + void SetLoop(bool Loop); + + //////////////////////////////////////////////////////////// + /// Set the sound pitch. + /// The default pitch is 1 + /// + /// \param Pitch : New pitch + /// + //////////////////////////////////////////////////////////// + void SetPitch(float Pitch); + + //////////////////////////////////////////////////////////// + /// Set the sound volume. + /// The default volume is 100 + /// + /// \param Volume : Volume (in range [0, 100]) + /// + //////////////////////////////////////////////////////////// + void SetVolume(float Volume); + + //////////////////////////////////////////////////////////// + /// Set the sound position (take 3 values). + /// The default position is (0, 0, 0) + /// + /// \param X, Y, Z : Position of the sound in the world + /// + //////////////////////////////////////////////////////////// + void SetPosition(float X, float Y, float Z); + + //////////////////////////////////////////////////////////// + /// Set the sound position (take a 3D vector). + /// The default position is (0, 0, 0) + /// + /// \param Position : Position of the sound in the world + /// + //////////////////////////////////////////////////////////// + void SetPosition(const Vector3f& Position); + + //////////////////////////////////////////////////////////// + /// Make the sound's position relative to the listener's + /// position, or absolute. + /// The default value is false (absolute) + /// + /// \param Relative : True to set the position relative, false to set it absolute + /// + //////////////////////////////////////////////////////////// + void SetRelativeToListener(bool Relative); + + //////////////////////////////////////////////////////////// + /// Set the minimum distance - closer than this distance, + /// the listener will hear the sound at its maximum volume. + /// The default minimum distance is 1.0 + /// + /// \param MinDistance : New minimum distance for the sound + /// + //////////////////////////////////////////////////////////// + void SetMinDistance(float MinDistance); + + //////////////////////////////////////////////////////////// + /// Set the attenuation factor - the higher the attenuation, the + /// more the sound will be attenuated with distance from listener. + /// The default attenuation factor 1.0 + /// + /// \param Attenuation : New attenuation factor for the sound + /// + //////////////////////////////////////////////////////////// + void SetAttenuation(float Attenuation); + + //////////////////////////////////////////////////////////// + /// Set the current playing position of the sound + /// + /// \param TimeOffset : New playing position, expressed in seconds + /// + //////////////////////////////////////////////////////////// + void SetPlayingOffset(float TimeOffset); + + //////////////////////////////////////////////////////////// + /// Get the source buffer + /// + /// \return Sound buffer bound to the sound (can be NULL) + /// + //////////////////////////////////////////////////////////// + const SoundBuffer* GetBuffer() const; + + //////////////////////////////////////////////////////////// + /// Tell whether or not the sound is looping + /// + /// \return True if the sound is looping, false otherwise + /// + //////////////////////////////////////////////////////////// + bool GetLoop() const; + + //////////////////////////////////////////////////////////// + /// Get the pitch + /// + /// \return Pitch value + /// + //////////////////////////////////////////////////////////// + float GetPitch() const; + + //////////////////////////////////////////////////////////// + /// Get the volume + /// + /// \return Volume value (in range [1, 100]) + /// + //////////////////////////////////////////////////////////// + float GetVolume() const; + + //////////////////////////////////////////////////////////// + /// Get the sound position + /// + /// \return Position of the sound in the world + /// + //////////////////////////////////////////////////////////// + Vector3f GetPosition() const; + + //////////////////////////////////////////////////////////// + /// Tell if the sound's position is relative to the listener's + /// position, or if it's absolute + /// + /// \return True if the position is relative, false if it's absolute + /// + //////////////////////////////////////////////////////////// + bool IsRelativeToListener() const; + + //////////////////////////////////////////////////////////// + /// Get the minimum distance + /// + /// \return Minimum distance for the sound + /// + //////////////////////////////////////////////////////////// + float GetMinDistance() const; + + //////////////////////////////////////////////////////////// + /// Get the attenuation factor + /// + /// \return Attenuation factor of the sound + /// + //////////////////////////////////////////////////////////// + float GetAttenuation() const; + + //////////////////////////////////////////////////////////// + /// Get the status of the sound (stopped, paused, playing) + /// + /// \return Current status of the sound + /// + //////////////////////////////////////////////////////////// + Status GetStatus() const; + + //////////////////////////////////////////////////////////// + /// Get the current playing position of the sound + /// + /// \return Current playing position, expressed in seconds + /// + //////////////////////////////////////////////////////////// + float GetPlayingOffset() const; + + //////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param Other : Instance to assign + /// + /// \return Reference to the sound + /// + //////////////////////////////////////////////////////////// + Sound& operator =(const Sound& Other); + + //////////////////////////////////////////////////////////// + /// Reset the internal buffer + /// + /// This function is for internal use only, you don't have + /// to use it. + /// + //////////////////////////////////////////////////////////// + void ResetBuffer(); + +private : + + friend class SoundStream; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int mySource; ///< OpenAL source identifier + ResourcePtr myBuffer; ///< Sound buffer bound to the source +}; + +} // namespace sf + + +#endif // SFML_SOUND_HPP diff --git a/SFML-1.6/include/SFML/Audio/SoundBuffer.hpp b/SFML-1.6/include/SFML/Audio/SoundBuffer.hpp new file mode 100644 index 000000000..023e5aa05 --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/SoundBuffer.hpp @@ -0,0 +1,213 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SOUNDBUFFER_HPP +#define SFML_SOUNDBUFFER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + + +namespace sf +{ +class Sound; + +//////////////////////////////////////////////////////////// +/// SoundBuffer is the low-level for loading and manipulating +/// sound buffers +//////////////////////////////////////////////////////////// +class SFML_API SoundBuffer : public AudioResource, public Resource +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + SoundBuffer(); + + //////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param Copy : Instance to copy + /// + //////////////////////////////////////////////////////////// + SoundBuffer(const SoundBuffer& Copy); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~SoundBuffer(); + + //////////////////////////////////////////////////////////// + /// Load the sound buffer from a file + /// + /// \param Filename : Path of the sound file to load + /// + /// \return True if loading has been successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromFile(const std::string& Filename); + + //////////////////////////////////////////////////////////// + /// Load the sound buffer from a file in memory + /// + /// \param Data : Pointer to the file data in memory + /// \param SizeInBytes : Size of the data to load, in bytes + /// + /// \return True if loading has been successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromMemory(const char* Data, std::size_t SizeInBytes); + + //////////////////////////////////////////////////////////// + /// Load the sound buffer from an array of samples - assumed format for + /// samples is 16 bits signed integer + /// + /// \param Samples : Pointer to the samples in memory + /// \param SamplesCount : Number of samples pointed by Samples + /// \param ChannelsCount : Number of channels (1 = mono, 2 = stereo, ...) + /// \param SampleRate : Frequency (number of samples to play per second) + /// + /// \return True if loading has been successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, unsigned int ChannelsCount, unsigned int SampleRate); + + //////////////////////////////////////////////////////////// + /// Save the sound buffer to a file + /// + /// \param Filename : Path of the sound file to write + /// + /// \return True if saving has been successful + /// + //////////////////////////////////////////////////////////// + bool SaveToFile(const std::string& Filename) const; + + //////////////////////////////////////////////////////////// + /// Return the sound samples + /// + /// \return Pointer to the array of sound samples, in 16 bits signed integer format + /// + //////////////////////////////////////////////////////////// + const Int16* GetSamples() const; + + //////////////////////////////////////////////////////////// + /// Return the samples count + /// + /// \return Number of samples + /// + //////////////////////////////////////////////////////////// + std::size_t GetSamplesCount() const; + + //////////////////////////////////////////////////////////// + /// Get the sample rate + /// + /// \return Sound frequency (number of samples per second) + /// + //////////////////////////////////////////////////////////// + unsigned int GetSampleRate() const; + + //////////////////////////////////////////////////////////// + /// Return the number of channels (1 = mono, 2 = stereo, ...) + /// + /// \return Number of channels + /// + //////////////////////////////////////////////////////////// + unsigned int GetChannelsCount() const; + + //////////////////////////////////////////////////////////// + /// Get the sound duration + /// + /// \return Sound duration, in seconds + /// + //////////////////////////////////////////////////////////// + float GetDuration() const; + + //////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param Other : Instance to assign + /// + /// \return Reference to the sound buffer + /// + //////////////////////////////////////////////////////////// + SoundBuffer& operator =(const SoundBuffer& Other); + +private : + + friend class Sound; + + //////////////////////////////////////////////////////////// + /// Update the internal buffer with the audio samples + /// + /// \param ChannelsCount : Number of channels + /// \param SampleRate : Sample rate + /// + /// \return True on success + /// + //////////////////////////////////////////////////////////// + bool Update(unsigned int ChannelsCount, unsigned int SampleRate); + + //////////////////////////////////////////////////////////// + /// Add a sound to the list of sounds that use this buffer + /// + /// \param Instance : Sound object to attach + /// + //////////////////////////////////////////////////////////// + void AttachSound(Sound* Instance) const; + + //////////////////////////////////////////////////////////// + /// Remove a sound from the list of sounds that use this buffer + /// + /// \param Instance : Sound object to detach + /// + //////////////////////////////////////////////////////////// + void DetachSound(Sound* Instance) const; + + //////////////////////////////////////////////////////////// + // Types + //////////////////////////////////////////////////////////// + typedef std::set SoundList; ///< Set of unique sound instances + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int myBuffer; ///< OpenAL buffer identifier + std::vector mySamples; ///< Samples buffer + float myDuration; ///< Sound duration, in seconds + mutable SoundList mySounds; ///< List of sounds that are using this buffer +}; + +} // namespace sf + + +#endif // SFML_SOUNDBUFFER_HPP diff --git a/SFML-1.6/include/SFML/Audio/SoundBufferRecorder.hpp b/SFML-1.6/include/SFML/Audio/SoundBufferRecorder.hpp new file mode 100644 index 000000000..e949a1cb1 --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/SoundBufferRecorder.hpp @@ -0,0 +1,83 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SOUNDBUFFERRECORDER_HPP +#define SFML_SOUNDBUFFERRECORDER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Specialized SoundRecorder which saves the captured +/// audio data into a sound buffer +//////////////////////////////////////////////////////////// +class SFML_API SoundBufferRecorder : public SoundRecorder +{ +public : + + //////////////////////////////////////////////////////////// + /// Get the sound buffer containing the captured audio data + /// + /// \return Constant reference to the sound buffer + /// + //////////////////////////////////////////////////////////// + const SoundBuffer& GetBuffer() const; + +private : + + //////////////////////////////////////////////////////////// + /// /see SoundBuffer::OnStart + /// + //////////////////////////////////////////////////////////// + virtual bool OnStart(); + + //////////////////////////////////////////////////////////// + /// /see SoundBuffer::OnProcessSamples + /// + //////////////////////////////////////////////////////////// + virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount); + + //////////////////////////////////////////////////////////// + /// /see SoundBuffer::OnStop + /// + //////////////////////////////////////////////////////////// + virtual void OnStop(); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::vector mySamples; ///< Temporary sample buffer to hold the recorded data + SoundBuffer myBuffer; ///< Sound buffer that will contain the recorded data +}; + +} // namespace sf + +#endif // SFML_SOUNDBUFFERRECORDER_HPP diff --git a/SFML-1.6/include/SFML/Audio/SoundRecorder.hpp b/SFML-1.6/include/SFML/Audio/SoundRecorder.hpp new file mode 100644 index 000000000..551a4b906 --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/SoundRecorder.hpp @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SOUNDRECORDER_HPP +#define SFML_SOUNDRECORDER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// SoundRecorder is an interface for capturing sound data, +/// it is meant to be used as a base class +//////////////////////////////////////////////////////////// +class SFML_API SoundRecorder : private Thread +{ +public : + + //////////////////////////////////////////////////////////// + /// Virtual destructor + /// + //////////////////////////////////////////////////////////// + virtual ~SoundRecorder(); + + //////////////////////////////////////////////////////////// + /// Start the capture. + /// Warning : only one capture can happen at the same time + /// + /// \param SampleRate : Sound frequency (the more samples, the higher the quality) + /// (44100 by default = CD quality) + /// + //////////////////////////////////////////////////////////// + void Start(unsigned int SampleRate = 44100); + + //////////////////////////////////////////////////////////// + /// Stop the capture + /// + //////////////////////////////////////////////////////////// + void Stop(); + + //////////////////////////////////////////////////////////// + /// Get the sample rate + /// + /// \return Frequency, in samples per second + /// + //////////////////////////////////////////////////////////// + unsigned int GetSampleRate() const; + + //////////////////////////////////////////////////////////// + /// Tell if the system supports sound capture. + /// If not, this class won't be usable + /// + /// \return True if audio capture is supported + /// + //////////////////////////////////////////////////////////// + static bool CanCapture(); + +protected : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + SoundRecorder(); + +private : + + //////////////////////////////////////////////////////////// + /// Start recording audio data + /// + /// \return False to abort recording audio data, true to start + /// + //////////////////////////////////////////////////////////// + virtual bool OnStart(); + + //////////////////////////////////////////////////////////// + /// Process a new chunk of recorded samples + /// + /// \param Samples : Pointer to the new chunk of recorded samples + /// \param SamplesCount : Number of samples pointed by Samples + /// + /// \return False to stop recording audio data, true to continue + /// + //////////////////////////////////////////////////////////// + virtual bool OnProcessSamples(const Int16* Samples, std::size_t SamplesCount) = 0; + + //////////////////////////////////////////////////////////// + /// Stop recording audio data + /// + //////////////////////////////////////////////////////////// + virtual void OnStop(); + + //////////////////////////////////////////////////////////// + /// /see Thread::Run + /// + //////////////////////////////////////////////////////////// + virtual void Run(); + + //////////////////////////////////////////////////////////// + /// Get the available captured samples and process them + /// + //////////////////////////////////////////////////////////// + void ProcessCapturedSamples(); + + //////////////////////////////////////////////////////////// + /// Clean up the recorder internal resources + /// + //////////////////////////////////////////////////////////// + void CleanUp(); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::vector mySamples; ///< Buffer to store captured samples + unsigned int mySampleRate; ///< Sample rate + bool myIsCapturing; ///< Capturing state +}; + +} // namespace sf + + +#endif // SFML_SOUNDRECORDER_HPP diff --git a/SFML-1.6/include/SFML/Audio/SoundStream.hpp b/SFML-1.6/include/SFML/Audio/SoundStream.hpp new file mode 100644 index 000000000..67b2babed --- /dev/null +++ b/SFML-1.6/include/SFML/Audio/SoundStream.hpp @@ -0,0 +1,228 @@ +//////////////////////////////////////////////////////////// +// +// 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_SOUNDSTREAM_HPP +#define SFML_SOUNDSTREAM_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// SoundStream is a streamed sound, ie samples are acquired +/// while the sound is playing. Use it for big sounds that would +/// require hundreds of MB in memory (see Music), +/// or for streaming sound from the network +//////////////////////////////////////////////////////////// +class SFML_API SoundStream : private Thread, private Sound +{ +public : + + using Sound::Status; + using Sound::Stopped; + using Sound::Paused; + using Sound::Playing; + using Sound::Pause; + using Sound::SetPitch; + using Sound::SetVolume; + using Sound::SetPosition; + using Sound::SetRelativeToListener; + using Sound::SetMinDistance; + using Sound::SetAttenuation; + using Sound::GetPitch; + using Sound::GetVolume; + using Sound::GetPosition; + using Sound::IsRelativeToListener; + using Sound::GetMinDistance; + using Sound::GetAttenuation; + + //////////////////////////////////////////////////////////// + /// Structure defining a chunk of audio data to stream + //////////////////////////////////////////////////////////// + struct Chunk + { + const Int16* Samples; ///< Pointer to the audio samples + std::size_t NbSamples; ///< Number of samples pointed by Samples + }; + + //////////////////////////////////////////////////////////// + /// Virtual destructor + /// + //////////////////////////////////////////////////////////// + virtual ~SoundStream(); + + //////////////////////////////////////////////////////////// + /// Start playing the audio stream + /// + //////////////////////////////////////////////////////////// + void Play(); + + //////////////////////////////////////////////////////////// + /// Stop playing the audio stream + /// + //////////////////////////////////////////////////////////// + void Stop(); + + //////////////////////////////////////////////////////////// + /// Return the number of channels (1 = mono, 2 = stereo) + /// + /// \return Number of channels + /// + //////////////////////////////////////////////////////////// + unsigned int GetChannelsCount() const; + + //////////////////////////////////////////////////////////// + /// Get the stream sample rate + /// + /// \return Stream frequency (number of samples per second) + /// + //////////////////////////////////////////////////////////// + unsigned int GetSampleRate() const; + + //////////////////////////////////////////////////////////// + /// Get the status of the stream (stopped, paused, playing) + /// + /// \return Current status of the sound + /// + //////////////////////////////////////////////////////////// + Status GetStatus() const; + + //////////////////////////////////////////////////////////// + /// Get the current playing position of the stream + /// + /// \return Current playing position, expressed in seconds + /// + //////////////////////////////////////////////////////////// + float GetPlayingOffset() const; + + //////////////////////////////////////////////////////////// + /// Set the stream loop state. + /// This parameter is disabled by default + /// + /// \param Loop : True to play in loop, false to play once + /// + //////////////////////////////////////////////////////////// + void SetLoop(bool Loop); + + //////////////////////////////////////////////////////////// + /// Tell whether or not the stream is looping + /// + /// \return True if the music is looping, false otherwise + /// + //////////////////////////////////////////////////////////// + bool GetLoop() const; + +protected : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + SoundStream(); + + //////////////////////////////////////////////////////////// + /// Set the audio stream parameters, you must call it before Play() + /// + /// \param ChannelsCount : Number of channels + /// \param SampleRate : Sample rate + /// + //////////////////////////////////////////////////////////// + void Initialize(unsigned int ChannelsCount, unsigned int SampleRate); + +private : + + //////////////////////////////////////////////////////////// + /// /see Thread::Run + /// + //////////////////////////////////////////////////////////// + virtual void Run(); + + //////////////////////////////////////////////////////////// + /// Called when the sound restarts + /// + /// \return If false is returned, the playback is aborted + /// + //////////////////////////////////////////////////////////// + virtual bool OnStart(); + + //////////////////////////////////////////////////////////// + /// Called each time new audio data is needed to feed the stream + /// + /// \param Data : New chunk of data to stream + /// + /// \return True to continue playback, false to stop + /// + //////////////////////////////////////////////////////////// + virtual bool OnGetData(Chunk& Data) = 0; + + //////////////////////////////////////////////////////////// + /// Fill a new buffer with audio data, and push it to the + /// playing queue + /// + /// \param Buffer : Number of the buffer to fill (in [0, BuffersCount]) + /// + /// \return True if the derived class has requested to stop + /// + //////////////////////////////////////////////////////////// + bool FillAndPushBuffer(unsigned int BufferNum); + + //////////////////////////////////////////////////////////// + /// Fill the buffers queue with all available buffers + /// + /// \return True if the derived class has requested to stop + /// + //////////////////////////////////////////////////////////// + bool FillQueue(); + + //////////////////////////////////////////////////////////// + /// Clear the queue of any remaining buffers + /// + //////////////////////////////////////////////////////////// + void ClearQueue(); + + enum {BuffersCount = 3}; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + bool myIsStreaming; ///< Streaming state (true = playing, false = stopped) + unsigned int myBuffers[BuffersCount]; ///< Sound buffers used to store temporary audio data + unsigned int myChannelsCount; ///< Number of channels (1 = mono, 2 = stereo, ...) + unsigned int mySampleRate; ///< Frequency (samples / second) + unsigned long myFormat; ///< Format of the internal sound buffers + bool myLoop; ///< Loop flag (true to loop, false to play once) + unsigned int mySamplesProcessed; ///< Number of buffers processed since beginning of the stream + bool myEndBuffers[BuffersCount]; ///< Each buffer is marked as "end buffer" or not, for proper duration calculation +}; + +} // namespace sf + + +#endif // SFML_SOUNDSTREAM_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Color.hpp b/SFML-1.6/include/SFML/Graphics/Color.hpp new file mode 100644 index 000000000..5f4d4d7a1 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Color.hpp @@ -0,0 +1,147 @@ +//////////////////////////////////////////////////////////// +// +// 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_COLOR_HPP +#define SFML_COLOR_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Color is an utility class for manipulating +/// 32-bits RGBA colors +//////////////////////////////////////////////////////////// +class SFML_API Color +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Color(); + + //////////////////////////////////////////////////////////// + /// Construct the color from its 4 RGBA components + /// + /// \param R : Red component (0 .. 255) + /// \param G : Green component (0 .. 255) + /// \param B : Blue component (0 .. 255) + /// \param A : Alpha component (0 .. 255) (255 by default) + /// + //////////////////////////////////////////////////////////// + Color(Uint8 R, Uint8 G, Uint8 B, Uint8 A = 255); + + //////////////////////////////////////////////////////////// + /// Operator += overload to add a color + /// + /// \param Other : Color to add + /// + /// \return Component-wise saturated addition of the two colors + /// + //////////////////////////////////////////////////////////// + Color& operator +=(const Color& Other); + + //////////////////////////////////////////////////////////// + /// Operator *= overload to modulate a color + /// + /// \param Other : Color to modulate + /// + /// \return Component-wise multiplication of the two colors + /// + //////////////////////////////////////////////////////////// + Color& operator *=(const Color& Other); + + //////////////////////////////////////////////////////////// + /// Compare two colors (for equality) + /// + /// \param Other : Color to compare + /// + /// \return True if colors are equal + /// + //////////////////////////////////////////////////////////// + bool operator ==(const Color& Other) const; + + //////////////////////////////////////////////////////////// + /// Compare two colors (for difference) + /// + /// \param Other : Color to compare + /// + /// \return True if colors are different + /// + //////////////////////////////////////////////////////////// + bool operator !=(const Color& Other) const; + + //////////////////////////////////////////////////////////// + // Static member data + //////////////////////////////////////////////////////////// + static const Color Black; ///< Black predefined color + static const Color White; ///< White predefined color + static const Color Red; ///< Red predefined color + static const Color Green; ///< Green predefined color + static const Color Blue; ///< Blue predefined color + static const Color Yellow; ///< Yellow predefined color + static const Color Magenta; ///< Magenta predefined color + static const Color Cyan; ///< Cyan predefined color + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Uint8 r; ///< Red component + Uint8 g; ///< Green component + Uint8 b; ///< Blue component + Uint8 a; ///< Alpha (transparency) component +}; + +//////////////////////////////////////////////////////////// +/// Operator + overload to add two colors +/// +/// \param Color1 : First color +/// \param Color2 : Second color +/// +/// \return Component-wise saturated addition of the two colors +/// +//////////////////////////////////////////////////////////// +SFML_API Color operator +(const Color& Color1, const Color& Color2); + +//////////////////////////////////////////////////////////// +/// Operator * overload to modulate two colors +/// +/// \param Color1 : First color +/// \param Color2 : Second color +/// +/// \return Component-wise multiplication of the two colors +/// +//////////////////////////////////////////////////////////// +SFML_API Color operator *(const Color& Color1, const Color& Color2); + +} // namespace sf + + +#endif // SFML_COLOR_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Drawable.hpp b/SFML-1.6/include/SFML/Graphics/Drawable.hpp new file mode 100644 index 000000000..a93ec57e0 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Drawable.hpp @@ -0,0 +1,361 @@ +//////////////////////////////////////////////////////////// +// +// 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_DRAWABLE_HPP +#define SFML_DRAWABLE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +class RenderTarget; + +//////////////////////////////////////////////////////////// +/// Enumerate the blending modes for drawable objects +//////////////////////////////////////////////////////////// +namespace Blend +{ + enum Mode + { + Alpha, ///< Pixel = Src * a + Dest * (1 - a) + Add, ///< Pixel = Src + Dest + Multiply, ///< Pixel = Src * Dest + None ///< No blending + }; +} + +//////////////////////////////////////////////////////////// +/// Abstract base class for every object that can be drawn +/// into a render window +//////////////////////////////////////////////////////////// +class SFML_API Drawable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + /// \param Position : Position of the object (0, 0 by default) + /// \param Scale : Scale factor (1, 1 by default) + /// \param Rotation : Orientation, in degrees (0 by default) + /// \param Col : Color of the object (white by default) + /// + //////////////////////////////////////////////////////////// + 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)); + + //////////////////////////////////////////////////////////// + /// Virtual destructor + /// + //////////////////////////////////////////////////////////// + virtual ~Drawable(); + + //////////////////////////////////////////////////////////// + /// Set the position of the object (take 2 values) + /// + /// \param X : New X coordinate + /// \param Y : New Y coordinate + /// + //////////////////////////////////////////////////////////// + void SetPosition(float X, float Y); + + //////////////////////////////////////////////////////////// + /// Set the position of the object (take a 2D vector) + /// + /// \param Position : New position + /// + //////////////////////////////////////////////////////////// + void SetPosition(const Vector2f& Position); + + //////////////////////////////////////////////////////////// + /// Set the X position of the object + /// + /// \param X : New X coordinate + /// + //////////////////////////////////////////////////////////// + void SetX(float X); + + //////////////////////////////////////////////////////////// + /// Set the Y position of the object + /// + /// \param Y : New Y coordinate + /// + //////////////////////////////////////////////////////////// + void SetY(float Y); + + //////////////////////////////////////////////////////////// + /// Set the scale of the object (take 2 values) + /// + /// \param ScaleX : New horizontal scale (must be strictly positive) + /// \param ScaleY : New vertical scale (must be strictly positive) + /// + //////////////////////////////////////////////////////////// + void SetScale(float ScaleX, float ScaleY); + + //////////////////////////////////////////////////////////// + /// Set the scale of the object (take a 2D vector) + /// + /// \param Scale : New scale (both values must be strictly positive) + /// + //////////////////////////////////////////////////////////// + void SetScale(const Vector2f& Scale); + + //////////////////////////////////////////////////////////// + /// Set the X scale factor of the object + /// + /// \param X : New X scale factor + /// + //////////////////////////////////////////////////////////// + void SetScaleX(float FactorX); + + //////////////////////////////////////////////////////////// + /// Set the Y scale factor of the object + /// + /// \param Y : New Y scale factor + /// + //////////////////////////////////////////////////////////// + void SetScaleY(float FactorY); + + //////////////////////////////////////////////////////////// + /// Set the center of the object, in coordinates relative to the + /// top-left of the object (take 2 values). + /// The default center is (0, 0) + /// + /// \param CenterX : X coordinate of the center + /// \param CenterY : Y coordinate of the center + /// + //////////////////////////////////////////////////////////// + void SetCenter(float CenterX, float CenterY); + + //////////////////////////////////////////////////////////// + /// Set the center of the object, in coordinates relative to the + /// top-left of the object (take a 2D vector). + /// The default center is (0, 0) + /// + /// \param Center : New center + /// + //////////////////////////////////////////////////////////// + void SetCenter(const Vector2f& Center); + + //////////////////////////////////////////////////////////// + /// Set the orientation of the object + /// + /// \param Rotation : Angle of rotation, in degrees + /// + //////////////////////////////////////////////////////////// + void SetRotation(float Rotation); + + //////////////////////////////////////////////////////////// + /// Set the color of the object. + /// The default color is white + /// + /// \param Col : New color + /// + //////////////////////////////////////////////////////////// + void SetColor(const Color& Col); + + //////////////////////////////////////////////////////////// + /// Set the blending mode for the object. + /// The default blend mode is Blend::Alpha + /// + /// \param Mode : New blending mode + /// + //////////////////////////////////////////////////////////// + void SetBlendMode(Blend::Mode Mode); + + //////////////////////////////////////////////////////////// + /// Get the position of the object + /// + /// \return Current position + /// + //////////////////////////////////////////////////////////// + const Vector2f& GetPosition() const; + + //////////////////////////////////////////////////////////// + /// Get the current scale of the object + /// + /// \return Current scale factor (always positive) + /// + //////////////////////////////////////////////////////////// + const Vector2f& GetScale() const; + + //////////////////////////////////////////////////////////// + /// Get the center of the object + /// + /// \return Current position of the center + /// + //////////////////////////////////////////////////////////// + const Vector2f& GetCenter() const; + + //////////////////////////////////////////////////////////// + /// Get the orientation of the object. + /// Rotation is always in the range [0, 360] + /// + /// \return Current rotation, in degrees + /// + //////////////////////////////////////////////////////////// + float GetRotation() const; + + //////////////////////////////////////////////////////////// + /// Get the color of the object + /// + /// \return Current color + /// + //////////////////////////////////////////////////////////// + const Color& GetColor() const; + + //////////////////////////////////////////////////////////// + /// Get the current blending mode + /// + /// \return Current blending mode + /// + //////////////////////////////////////////////////////////// + Blend::Mode GetBlendMode() const; + + //////////////////////////////////////////////////////////// + /// Move the object of a given offset (take 2 values) + /// + /// \param OffsetX : X offset + /// \param OffsetY : Y offset + /// + //////////////////////////////////////////////////////////// + void Move(float OffsetX, float OffsetY); + + //////////////////////////////////////////////////////////// + /// Move the object of a given offset (take a 2D vector) + /// + /// \param Offset : Amount of units to move the object of + /// + //////////////////////////////////////////////////////////// + void Move(const Vector2f& Offset); + + //////////////////////////////////////////////////////////// + /// Scale the object (take 2 values) + /// + /// \param FactorX : Scaling factor on X (must be strictly positive) + /// \param FactorY : Scaling factor on Y (must be strictly positive) + /// + //////////////////////////////////////////////////////////// + void Scale(float FactorX, float FactorY); + + //////////////////////////////////////////////////////////// + /// Scale the object (take a 2D vector) + /// + /// \param Factor : Scaling factors (both values must be strictly positive) + /// + //////////////////////////////////////////////////////////// + void Scale(const Vector2f& Factor); + + //////////////////////////////////////////////////////////// + /// Rotate the object + /// + /// \param Angle : Angle of rotation, in degrees + /// + //////////////////////////////////////////////////////////// + void Rotate(float Angle); + + //////////////////////////////////////////////////////////// + /// Transform a point from global coordinates into local coordinates + /// (ie it applies the inverse of object's center, translation, rotation and scale to the point) + /// + /// \param Point : Point to transform + /// + /// \return Transformed point + /// + //////////////////////////////////////////////////////////// + sf::Vector2f TransformToLocal(const sf::Vector2f& Point) const; + + //////////////////////////////////////////////////////////// + /// Transform a point from local coordinates into global coordinates + /// (ie it applies the object's center, translation, rotation and scale to the point) + /// + /// \param Point : Point to transform + /// + /// \return Transformed point + /// + //////////////////////////////////////////////////////////// + sf::Vector2f TransformToGlobal(const sf::Vector2f& Point) const; + +protected : + + //////////////////////////////////////////////////////////// + /// Get the transform matrix of the drawable + /// + /// \return Transform matrix + /// + //////////////////////////////////////////////////////////// + const Matrix3& GetMatrix() const; + + //////////////////////////////////////////////////////////// + /// Get the inverse transform matrix of the drawable + /// + /// \return Inverse transform matrix + /// + //////////////////////////////////////////////////////////// + const Matrix3& GetInverseMatrix() const; + +private : + + friend class RenderTarget; + + //////////////////////////////////////////////////////////// + /// Draw the object into the specified window + /// + /// \param Target : Target into which render the object + /// + //////////////////////////////////////////////////////////// + void Draw(RenderTarget& Target) const; + + //////////////////////////////////////////////////////////// + /// Render the specific geometry of the object + /// + /// \param Target : Target into which render the object + /// + //////////////////////////////////////////////////////////// + virtual void Render(RenderTarget& Target) const = 0; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Vector2f myPosition; ///< Position of the object on screen + Vector2f myScale; ///< Scale of the object + Vector2f myCenter; ///< Origin of translation / rotation / scaling of the object + float myRotation; ///< Orientation of the object, in degrees + Color myColor; ///< Overlay color of the object + Blend::Mode myBlendMode; ///< Blending mode + mutable bool myNeedUpdate; ///< Do we need to recompute the transform matrix ? + mutable bool myInvNeedUpdate; ///< Do we need to recompute the inverse transform matrix ? + mutable Matrix3 myMatrix; ///< Precomputed transform matrix gathering the translation / rotation / scale / center + mutable Matrix3 myInvMatrix; ///< Precomputed inverse transform matrix gathering the translation / rotation / scale / center +}; + +} // namespace sf + + +#endif // SFML_DRAWABLE_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Font.hpp b/SFML-1.6/include/SFML/Graphics/Font.hpp new file mode 100644 index 000000000..866b974d0 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Font.hpp @@ -0,0 +1,145 @@ +//////////////////////////////////////////////////////////// +// +// 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_FONT_HPP +#define SFML_FONT_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace sf +{ +class String; + +namespace priv +{ +class FontLoader; +} +//////////////////////////////////////////////////////////// +/// Font is the low-level class for loading and +/// manipulating character fonts. This class is meant to +/// be used by sf::String +//////////////////////////////////////////////////////////// +class SFML_API Font : public Resource +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Font(); + + //////////////////////////////////////////////////////////// + /// Load the font from a file + /// + /// \param Filename : Font file to load + /// \param CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default) + /// \param Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters) + /// + /// \return True if loading was successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromFile(const std::string& Filename, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset); + + //////////////////////////////////////////////////////////// + /// Load the font from a file in memory + /// + /// \param Data : Pointer to the data to load + /// \param SizeInBytes : Size of the data, in bytes + /// \param CharSize : Size of characters in bitmap - the bigger, the higher quality (30 by default) + /// \param Charset : Characters set to generate (by default, contains the ISO-8859-1 printable characters) + /// + /// \return True if loading was successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset); + + //////////////////////////////////////////////////////////// + /// Get the base size of characters in the font; + /// All glyphs dimensions are based on this value + /// + /// \return Base size of characters + /// + //////////////////////////////////////////////////////////// + unsigned int GetCharacterSize() const; + + //////////////////////////////////////////////////////////// + /// Get the description of a glyph (character) + /// given by its unicode value + /// + /// \param CodePoint : Unicode value of the character to get + /// + /// \return Glyph's visual settings, or an invalid glyph if character not found + /// + //////////////////////////////////////////////////////////// + const Glyph& GetGlyph(Uint32 CodePoint) const; + + //////////////////////////////////////////////////////////// + /// Get the image containing the rendered characters (glyphs) + /// + /// \return Image containing glyphs + /// + //////////////////////////////////////////////////////////// + const Image& GetImage() const; + + //////////////////////////////////////////////////////////// + /// Get the SFML default built-in font (Arial) + /// + /// \return Instance of the default font + /// + //////////////////////////////////////////////////////////// + static const Font& GetDefaultFont(); + +private : + + friend class priv::FontLoader; + + //////////////////////////////////////////////////////////// + // Static member data + //////////////////////////////////////////////////////////// + static Uint32 ourDefaultCharset[]; ///< The default charset (all printable ISO-8859-1 characters) + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Image myTexture; ///< Texture holding the bitmap font + unsigned int myCharSize; ///< Size of characters in the bitmap font + std::map myGlyphs; ///< Rendering settings of each character (glyph) +}; + +} // namespace sf + + +#endif // SFML_FONT_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Glyph.hpp b/SFML-1.6/include/SFML/Graphics/Glyph.hpp new file mode 100644 index 000000000..ec1b88695 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Glyph.hpp @@ -0,0 +1,61 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_GLYPH_HPP +#define SFML_GLYPH_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Structure describing a glyph (a visual character) +//////////////////////////////////////////////////////////// +class SFML_API Glyph +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Glyph() : Advance(0) {} + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + int Advance; ///< Offset to move horizontically to the next character + IntRect Rectangle; ///< Bounding rectangle of the glyph, in relative coordinates + FloatRect TexCoords; ///< Texture coordinates of the glyph inside the bitmap font +}; + +} // namespace sf + + +#endif // SFML_GLYPH_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Image.hpp b/SFML-1.6/include/SFML/Graphics/Image.hpp new file mode 100644 index 000000000..c2f5c898b --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Image.hpp @@ -0,0 +1,332 @@ +//////////////////////////////////////////////////////////// +// +// 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_IMAGE_HPP +#define SFML_IMAGE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + + +namespace sf +{ +class RenderWindow; + +//////////////////////////////////////////////////////////// +/// Image is the low-level class for loading and +/// manipulating images +//////////////////////////////////////////////////////////// +class SFML_API Image : public Resource +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Image(); + + //////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param Copy : instance to copy + /// + //////////////////////////////////////////////////////////// + Image(const Image& Copy); + + //////////////////////////////////////////////////////////// + /// Construct an empty image + /// + /// \param Width : Image width + /// \param Height : Image height + /// \param Col : Image color (black by default) + /// + //////////////////////////////////////////////////////////// + Image(unsigned int Width, unsigned int Height, const Color& Col = Color(0, 0, 0, 255)); + + //////////////////////////////////////////////////////////// + /// Construct the image from pixels in memory + /// + /// \param Width : Image width + /// \param Height : Image height + /// \param Data : Pointer to the pixels in memory (assumed format is RGBA) + /// + //////////////////////////////////////////////////////////// + Image(unsigned int Width, unsigned int Height, const Uint8* Data); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~Image(); + + //////////////////////////////////////////////////////////// + /// Load the image from a file + /// + /// \param Filename : Path of the image file to load + /// + /// \return True if loading was successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromFile(const std::string& Filename); + + //////////////////////////////////////////////////////////// + /// Load the image from a file in memory + /// + /// \param Data : Pointer to the file data in memory + /// \param SizeInBytes : Size of the data to load, in bytes + /// + /// \return True if loading was successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromMemory(const char* Data, std::size_t SizeInBytes); + + //////////////////////////////////////////////////////////// + /// Load the image directly from an array of pixels + /// + /// \param Width : Image width + /// \param Height : Image height + /// \param Data : Pointer to the pixels in memory (assumed format is RGBA) + /// + /// \return True if loading was successful + /// + //////////////////////////////////////////////////////////// + bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint8* Data); + + //////////////////////////////////////////////////////////// + /// Save the content of the image to a file + /// + /// \param Filename : Path of the file to save (overwritten if already exist) + /// + /// \return True if saving was successful + /// + //////////////////////////////////////////////////////////// + bool SaveToFile(const std::string& Filename) const; + + //////////////////////////////////////////////////////////// + /// Create an empty image + /// + /// \param Width : Image width + /// \param Height : Image height + /// \param Col : Image color (black by default) + /// + /// \return True if creation was successful + /// + //////////////////////////////////////////////////////////// + bool Create(unsigned int Width, unsigned int Height, Color Col = Color(0, 0, 0, 255)); + + //////////////////////////////////////////////////////////// + /// Create transparency mask from a specified colorkey + /// + /// \param ColorKey : Color to become transparent + /// \param Alpha : Alpha value to use for transparent pixels (0 by default) + /// + //////////////////////////////////////////////////////////// + void CreateMaskFromColor(Color ColorKey, Uint8 Alpha = 0); + + //////////////////////////////////////////////////////////// + /// Copy pixels from another image onto this one. + /// This function does a slow pixel copy and should only + /// be used at initialization time + /// + /// \param Source : Source image to copy + /// \param DestX : X coordinate of the destination position + /// \param DestY : Y coordinate of the destination position + /// \param SourceRect : Sub-rectangle of the source image to copy (empty by default - entire image) + /// \param ApplyAlpha : Should the copy take in account the source transparency? (false by default) + /// + //////////////////////////////////////////////////////////// + void Copy(const Image& Source, unsigned int DestX, unsigned int DestY, const IntRect& SourceRect = IntRect(0, 0, 0, 0), bool ApplyAlpha = false); + + //////////////////////////////////////////////////////////// + /// Create the image from the current contents of the + /// given window + /// + /// \param Window : Window to capture + /// \param SourceRect : Sub-rectangle of the screen to copy (empty by default - entire image) + /// + /// \return True if copy was successful + /// + //////////////////////////////////////////////////////////// + bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRect(0, 0, 0, 0)); + + //////////////////////////////////////////////////////////// + /// Change the color of a pixel + /// + /// \param X : X coordinate of pixel in the image + /// \param Y : Y coordinate of pixel in the image + /// \param Col : New color for pixel (X, Y) + /// + //////////////////////////////////////////////////////////// + void SetPixel(unsigned int X, unsigned int Y, const Color& Col); + + //////////////////////////////////////////////////////////// + /// Get a pixel from the image + /// + /// \param X : X coordinate of pixel in the image + /// \param Y : Y coordinate of pixel in the image + /// + /// \return Color of pixel (X, Y) + /// + //////////////////////////////////////////////////////////// + const Color& GetPixel(unsigned int X, unsigned int Y) const; + + //////////////////////////////////////////////////////////// + /// Get a read-only pointer to the array of pixels (RGBA 8 bits integers components) + /// Array size is GetWidth() x GetHeight() x 4 + /// This pointer becomes invalid if you reload or resize the image + /// + /// \return Const pointer to the array of pixels + /// + //////////////////////////////////////////////////////////// + const Uint8* GetPixelsPtr() const; + + //////////////////////////////////////////////////////////// + /// Bind the image for rendering + /// + //////////////////////////////////////////////////////////// + void Bind() const; + + //////////////////////////////////////////////////////////// + /// Enable or disable image smooth filter. + /// This parameter is enabled by default + /// + /// \param Smooth : True to enable smoothing filter, false to disable it + /// + //////////////////////////////////////////////////////////// + void SetSmooth(bool Smooth); + + //////////////////////////////////////////////////////////// + /// Return the width of the image + /// + /// \return Width in pixels + /// + //////////////////////////////////////////////////////////// + unsigned int GetWidth() const; + + //////////////////////////////////////////////////////////// + /// Return the height of the image + /// + /// \return Height in pixels + /// + //////////////////////////////////////////////////////////// + unsigned int GetHeight() const; + + //////////////////////////////////////////////////////////// + /// Tells whether the smooth filtering is enabled or not + /// + /// \return True if image smoothing is enabled + /// + //////////////////////////////////////////////////////////// + bool IsSmooth() const; + + //////////////////////////////////////////////////////////// + /// Convert a subrect expressed in pixels, into float + /// texture coordinates + /// + /// \param Rect : Sub-rectangle of image to convert + /// + /// \return Texture coordinates corresponding to the sub-rectangle + /// + //////////////////////////////////////////////////////////// + FloatRect GetTexCoords(const IntRect& Rect) const; + + //////////////////////////////////////////////////////////// + /// Get a valid texture size according to hardware support + /// + /// \param Size : Size to convert + /// + /// \return Valid nearest size (greater than or equal to specified size) + /// + //////////////////////////////////////////////////////////// + static unsigned int GetValidTextureSize(unsigned int Size); + + //////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param Other : instance to assign + /// + /// \return Reference to the image + /// + //////////////////////////////////////////////////////////// + Image& operator =(const Image& Other); + +private : + + //////////////////////////////////////////////////////////// + /// Create the OpenGL texture + /// + /// \return True if texture has been successfully created + /// + //////////////////////////////////////////////////////////// + bool CreateTexture(); + + //////////////////////////////////////////////////////////// + /// Make sure the texture in video memory is updated with the + /// array of pixels + //////////////////////////////////////////////////////////// + void EnsureTextureUpdate() const; + + //////////////////////////////////////////////////////////// + /// Make sure the array of pixels is updated with the + /// texture in video memory + //////////////////////////////////////////////////////////// + void EnsureArrayUpdate() const; + + //////////////////////////////////////////////////////////// + /// Reset the image attributes + /// + //////////////////////////////////////////////////////////// + void Reset(); + + //////////////////////////////////////////////////////////// + /// Destroy the OpenGL texture + /// + //////////////////////////////////////////////////////////// + void DestroyTexture(); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int myWidth; ///< Image width + unsigned int myHeight; ///< Image Height + unsigned int myTextureWidth; ///< Actual texture width (can be greater than image width because of padding) + unsigned int myTextureHeight; ///< Actual texture height (can be greater than image height because of padding) + unsigned int myTexture; ///< Internal texture identifier + bool myIsSmooth; ///< Status of the smooth filter + mutable std::vector myPixels; ///< Pixels of the image + mutable bool myNeedTextureUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory + mutable bool myNeedArrayUpdate; ///< Status of synchronization between pixels in central memory and the internal texture un video memory +}; + +} // namespace sf + + +#endif // SFML_IMAGE_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Matrix3.hpp b/SFML-1.6/include/SFML/Graphics/Matrix3.hpp new file mode 100644 index 000000000..eeea1b0b5 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Matrix3.hpp @@ -0,0 +1,148 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_MATRIX3_HPP +#define SFML_MATRIX3_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Utility class to manipulate 3x3 matrices representing +/// 2D transformations +//////////////////////////////////////////////////////////// +class SFML_API Matrix3 +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor (builds an identity matrix) + /// + //////////////////////////////////////////////////////////// + Matrix3(); + + //////////////////////////////////////////////////////////// + /// Construct a matrix from its 9 elements + /// + //////////////////////////////////////////////////////////// + Matrix3(float a00, float a01, float a02, + float a10, float a11, float a12, + float a20, float a21, float a22); + + //////////////////////////////////////////////////////////// + /// Build a matrix from a set of transformations + /// + /// \param Center : Origin for the transformations + /// \param Translation : Translation offset + /// \param Rotation : Rotation angle in degrees + /// \param Scale : Scaling factors + /// + //////////////////////////////////////////////////////////// + void SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale); + + //////////////////////////////////////////////////////////// + /// Transform a point by the matrix + /// + /// \param Point : Point to transform + /// + /// \return Transformed point + /// + //////////////////////////////////////////////////////////// + Vector2f Transform(const Vector2f& Point) const; + + //////////////////////////////////////////////////////////// + /// Return the inverse of the matrix + /// + /// \return A new matrix which is the inverse of this + /// + //////////////////////////////////////////////////////////// + Matrix3 GetInverse() const; + + //////////////////////////////////////////////////////////// + /// Return the elements of the matrix as a 4x4, + /// in an array of 16 floats + /// + /// \return Pointer to the 4x4 matrix elements + /// + //////////////////////////////////////////////////////////// + const float* Get4x4Elements() const; + + //////////////////////////////////////////////////////////// + /// Operator () overloads to access the matrix elements + /// + /// \param Row : Element row (0 based) + /// \param Col : Element column (0 based) + /// + /// \return Matrix element (Row, Col) + /// + //////////////////////////////////////////////////////////// + float operator ()(unsigned int Row, unsigned int Col) const; + float& operator ()(unsigned int Row, unsigned int Col); + + //////////////////////////////////////////////////////////// + /// Operator * overload to multiply two matrices + /// + /// \param Mat : Matrix to multiply + /// + /// \return this * Mat + /// + //////////////////////////////////////////////////////////// + Matrix3 operator *(const Matrix3& Mat) const; + + //////////////////////////////////////////////////////////// + /// Operator *= overload to multiply-assign two matrices + /// + /// \param Mat : Matrix to multiply + /// + /// \return this * Mat + /// + //////////////////////////////////////////////////////////// + Matrix3& operator *=(const Matrix3& Mat); + + //////////////////////////////////////////////////////////// + // Static member data + //////////////////////////////////////////////////////////// + static const Matrix3 Identity; ///< Identity matrix + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + float myData[16]; /// Matrix elements (we directly store it as a 4x4 matrix for optimization purpose) +}; + +#include + +} // namespace sf + + +#endif // SFML_MATRIX3_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Matrix3.inl b/SFML-1.6/include/SFML/Graphics/Matrix3.inl new file mode 100644 index 000000000..449941579 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Matrix3.inl @@ -0,0 +1,186 @@ +//////////////////////////////////////////////////////////// +// +// SFGE - 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. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Default constructor (builds an identity matrix) +//////////////////////////////////////////////////////////// +inline Matrix3::Matrix3() +{ + myData[0] = 1.f; myData[4] = 0.f; myData[8] = 0.f; myData[12] = 0.f; + myData[1] = 0.f; myData[5] = 1.f; myData[9] = 0.f; myData[13] = 0.f; + myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f; + myData[3] = 0.f; myData[7] = 0.f; myData[11] = 0.f; myData[15] = 1.f; +} + + +//////////////////////////////////////////////////////////// +/// Construct a matrix from its 9 elements +//////////////////////////////////////////////////////////// +inline Matrix3::Matrix3(float a00, float a01, float a02, + float a10, float a11, float a12, + float a20, float a21, float a22) +{ + myData[0] = a00; myData[4] = a01; myData[8] = 0.f; myData[12] = a02; + myData[1] = a10; myData[5] = a11; myData[9] = 0.f; myData[13] = a12; + myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f; + myData[3] = a20; myData[7] = a21; myData[11] = 0.f; myData[15] = a22; +} + + +//////////////////////////////////////////////////////////// +/// Build a matrix from a set of transformations +//////////////////////////////////////////////////////////// +inline void Matrix3::SetFromTransformations(const Vector2f& Center, const Vector2f& Translation, float Rotation, const Vector2f& Scale) +{ + float Angle = Rotation * 3.141592654f / 180.f; + float Cos = static_cast(cos(Angle)); + float Sin = static_cast(sin(Angle)); + float SxCos = Scale.x * Cos; + float SyCos = Scale.y * Cos; + float SxSin = Scale.x * Sin; + float SySin = Scale.y * Sin; + float Tx = -Center.x * SxCos - Center.y * SySin + Translation.x; + float Ty = Center.x * SxSin - Center.y * SyCos + Translation.y; + + myData[0] = SxCos; myData[4] = SySin; myData[8] = 0.f; myData[12] = Tx; + myData[1] = -SxSin; myData[5] = SyCos; myData[9] = 0.f; myData[13] = Ty; + myData[2] = 0.f; myData[6] = 0.f; myData[10] = 1.f; myData[14] = 0.f; + myData[3] = 0.f; myData[7] = 0.f; myData[11] = 0.f; myData[15] = 1.f; +} + + +//////////////////////////////////////////////////////////// +/// Transform a point by the matrix +//////////////////////////////////////////////////////////// +inline Vector2f Matrix3::Transform(const Vector2f& Point) const +{ + return Vector2f(myData[0] * Point.x + myData[4] * Point.y + myData[12], + myData[1] * Point.x + myData[5] * Point.y + myData[13]); +} + + +//////////////////////////////////////////////////////////// +/// Return the inverse of the matrix +//////////////////////////////////////////////////////////// +inline Matrix3 Matrix3::GetInverse() const +{ + // Compute the determinant + float Det = myData[0] * (myData[15] * myData[5] - myData[7] * myData[13]) - + myData[1] * (myData[15] * myData[4] - myData[7] * myData[12]) + + myData[3] * (myData[13] * myData[4] - myData[5] * myData[12]); + + // Compute the inverse if determinant is not zero + if ((Det < -1E-7f) || (Det > 1E-7f)) + { + return Matrix3( (myData[15] * myData[5] - myData[7] * myData[13]) / Det, + -(myData[15] * myData[4] - myData[7] * myData[12]) / Det, + (myData[13] * myData[4] - myData[5] * myData[12]) / Det, + -(myData[15] * myData[1] - myData[3] * myData[13]) / Det, + (myData[15] * myData[0] - myData[3] * myData[12]) / Det, + -(myData[13] * myData[0] - myData[1] * myData[12]) / Det, + (myData[7] * myData[1] - myData[3] * myData[5]) / Det, + -(myData[7] * myData[0] - myData[3] * myData[4]) / Det, + (myData[5] * myData[0] - myData[1] * myData[4]) / Det); + } + else + { + return Identity; + } +} + + +//////////////////////////////////////////////////////////// +/// Return the elements of the matrix as a 4x4, +/// in an array of 16 floats +//////////////////////////////////////////////////////////// +inline const float* Matrix3::Get4x4Elements() const +{ + return myData; +} + + +//////////////////////////////////////////////////////////// +/// Operator () overloads to access the matrix elements +//////////////////////////////////////////////////////////// +inline float Matrix3::operator ()(unsigned int Row, unsigned int Col) const +{ + switch (Row + Col * 3) + { + case 0 : return myData[0]; + case 1 : return myData[1]; + case 2 : return myData[3]; + case 3 : return myData[4]; + case 4 : return myData[5]; + case 5 : return myData[7]; + case 6 : return myData[12]; + case 7 : return myData[13]; + case 8 : return myData[15]; + + default : return myData[0]; + } +} +inline float& Matrix3::operator ()(unsigned int Row, unsigned int Col) +{ + switch (Row + Col * 3) + { + case 0 : return myData[0]; + case 1 : return myData[1]; + case 2 : return myData[3]; + case 3 : return myData[4]; + case 4 : return myData[5]; + case 5 : return myData[7]; + case 6 : return myData[12]; + case 7 : return myData[13]; + case 8 : return myData[15]; + + default : return myData[0]; + } +} + + +//////////////////////////////////////////////////////////// +/// Operator * overload to multiply two matrices +//////////////////////////////////////////////////////////// +inline Matrix3 Matrix3::operator *(const Matrix3& Mat) const +{ + return Matrix3(myData[0] * Mat.myData[0] + myData[4] * Mat.myData[1] + myData[12] * Mat.myData[3], + myData[0] * Mat.myData[4] + myData[4] * Mat.myData[5] + myData[12] * Mat.myData[7], + myData[0] * Mat.myData[12] + myData[4] * Mat.myData[13] + myData[12] * Mat.myData[15], + myData[1] * Mat.myData[0] + myData[5] * Mat.myData[1] + myData[13] * Mat.myData[3], + myData[1] * Mat.myData[4] + myData[5] * Mat.myData[5] + myData[13] * Mat.myData[7], + myData[1] * Mat.myData[12] + myData[5] * Mat.myData[13] + myData[13] * Mat.myData[15], + myData[3] * Mat.myData[0] + myData[7] * Mat.myData[1] + myData[15] * Mat.myData[3], + myData[3] * Mat.myData[4] + myData[7] * Mat.myData[5] + myData[15] * Mat.myData[7], + myData[3] * Mat.myData[12] + myData[7] * Mat.myData[13] + myData[15] * Mat.myData[15]); +} + + +//////////////////////////////////////////////////////////// +/// Operator *= overload to multiply-assign two matrices +//////////////////////////////////////////////////////////// +inline Matrix3& Matrix3::operator *=(const Matrix3& Mat) +{ + return *this = *this * Mat; +} diff --git a/SFML-1.6/include/SFML/Graphics/PostFX.hpp b/SFML-1.6/include/SFML/Graphics/PostFX.hpp new file mode 100644 index 000000000..c87537792 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/PostFX.hpp @@ -0,0 +1,194 @@ +//////////////////////////////////////////////////////////// +// +// 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_POSTFX_HPP +#define SFML_POSTFX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// PostFX is used to apply a post effect to a window +//////////////////////////////////////////////////////////// +class SFML_API PostFX : public Drawable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + PostFX(); + + //////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param Copy : Instance to copy + /// + //////////////////////////////////////////////////////////// + PostFX(const PostFX& Copy); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~PostFX(); + + //////////////////////////////////////////////////////////// + /// Load the effect from a file + /// + /// \param Filename : Path of the effect file to load + /// + /// \return True on success + /// + //////////////////////////////////////////////////////////// + bool LoadFromFile(const std::string& Filename); + + //////////////////////////////////////////////////////////// + /// Load the effect from a text in memory + /// + /// \param Effect : String containing the effect code + /// + /// \return True on success + /// + //////////////////////////////////////////////////////////// + bool LoadFromMemory(const std::string& Effect); + + //////////////////////////////////////////////////////////// + /// Change a parameter of the effect (1 float) + /// + /// \param Name : Parameter name in the effect + /// \param X : Value to assign + /// + //////////////////////////////////////////////////////////// + void SetParameter(const std::string& Name, float X); + + //////////////////////////////////////////////////////////// + /// Change a parameter of the effect (2 floats) + /// + /// \param Name : Parameter name in the effect + /// \param X, Y : Values to assign + /// + //////////////////////////////////////////////////////////// + void SetParameter(const std::string& Name, float X, float Y); + + //////////////////////////////////////////////////////////// + /// Change a parameter of the effect (3 floats) + /// + /// \param Name : Parameter name in the effect + /// \param X, Y, Z : Values to assign + /// + //////////////////////////////////////////////////////////// + void SetParameter(const std::string& Name, float X, float Y, float Z); + + //////////////////////////////////////////////////////////// + /// Change a parameter of the effect (4 floats) + /// + /// \param Name : Parameter name in the effect + /// \param X, Y, Z, W : Values to assign + /// + //////////////////////////////////////////////////////////// + void SetParameter(const std::string& Name, float X, float Y, float Z, float W); + + //////////////////////////////////////////////////////////// + /// Set a texture parameter + /// + /// \param Name : Texture name in the effect + /// \param Texture : Image to set (pass NULL to use content of current framebuffer) + /// + //////////////////////////////////////////////////////////// + void SetTexture(const std::string& Name, Image* Texture); + + //////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param Other : Instance to assign + /// + /// \return Reference to the post-effect + /// + //////////////////////////////////////////////////////////// + PostFX& operator =(const PostFX& Other); + + //////////////////////////////////////////////////////////// + /// Tell whether or not the system supports post-effects + /// + /// \return True if the system can use post-effects + /// + //////////////////////////////////////////////////////////// + static bool CanUsePostFX(); + +protected : + + //////////////////////////////////////////////////////////// + /// /see Drawable::Render + /// + //////////////////////////////////////////////////////////// + virtual void Render(RenderTarget& Target) const; + +private : + + //////////////////////////////////////////////////////////// + /// Preprocess a SFML effect file + /// to convert it to a valid GLSL fragment shader + /// + /// \param File : Stream containing the code to process + /// + /// \return Valid fragment shader source code + /// + //////////////////////////////////////////////////////////// + static std::string PreprocessEffect(std::istream& File); + + //////////////////////////////////////////////////////////// + /// Create the program and attach the shaders + /// + //////////////////////////////////////////////////////////// + void CreateProgram(); + + //////////////////////////////////////////////////////////// + // Types + //////////////////////////////////////////////////////////// + typedef std::map TextureTable; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int myShaderProgram; ///< OpenGL identifier for the program + TextureTable myTextures; ///< Texture variables in the effect + std::string myFragmentShader; ///< Fragment shader source code + mutable Image myFrameBuffer; ///< Texture containing the current frame buffer +}; + +} // namespace sf + + +#endif // SFML_POSTFX_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Rect.hpp b/SFML-1.6/include/SFML/Graphics/Rect.hpp new file mode 100644 index 000000000..5decd3c56 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Rect.hpp @@ -0,0 +1,127 @@ +//////////////////////////////////////////////////////////// +// +// 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_RECT_HPP +#define SFML_RECT_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Rect is an utility class for manipulating rectangles. +/// Template parameter defines the type of coordinates (integer, float, ...) +//////////////////////////////////////////////////////////// +template +class Rect +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Rect(); + + //////////////////////////////////////////////////////////// + /// Construct the rectangle from its coordinates + /// + /// \param LeftCoord : Left coordinate of the rectangle + /// \param TopCoord : Top coordinate of the rectangle + /// \param RightCoord : Right coordinate of the rectangle + /// \param BottomCoord : Bottom coordinate of the rectangle + /// + //////////////////////////////////////////////////////////// + Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord); + + //////////////////////////////////////////////////////////// + /// Get the width of the rectangle + /// + /// \return Width of rectangle + /// + //////////////////////////////////////////////////////////// + T GetWidth() const; + + //////////////////////////////////////////////////////////// + /// Get the height of the rectangle + /// + /// \return Height of rectangle + /// + //////////////////////////////////////////////////////////// + T GetHeight() const; + + //////////////////////////////////////////////////////////// + /// Move the whole rectangle by the given offset + /// + /// \param OffsetX : Horizontal offset + /// \param OffsetY : Vertical offset + /// + //////////////////////////////////////////////////////////// + void Offset(T OffsetX, T OffsetY); + + //////////////////////////////////////////////////////////// + /// Check if a point is inside the rectangle's area + /// + /// \param X : X coordinate of the point to test + /// \param Y : Y coordinate of the point to test + /// + /// \return True if the point is inside + /// + //////////////////////////////////////////////////////////// + bool Contains(T X, T Y) const; + + //////////////////////////////////////////////////////////// + /// Check intersection between two rectangles + /// + /// \param Rectangle : Rectangle to test + /// \param OverlappingRect : Rectangle to be filled with overlapping rect (NULL by default) + /// + /// \return True if rectangles overlap + /// + //////////////////////////////////////////////////////////// + bool Intersects(const Rect& Rectangle, Rect* OverlappingRect = NULL) const; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T Left; ///< Left coordinate of the rectangle + T Top; ///< Top coordinate of the rectangle + T Right; ///< Right coordinate of the rectangle + T Bottom; ///< Bottom coordinate of the rectangle +}; + +#include + +// Define the most common types +typedef Rect IntRect; +typedef Rect FloatRect; + +} // namespace sf + + +#endif // SFML_RECT_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Rect.inl b/SFML-1.6/include/SFML/Graphics/Rect.inl new file mode 100644 index 000000000..6c5962ddd --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Rect.inl @@ -0,0 +1,122 @@ +//////////////////////////////////////////////////////////// +// +// 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. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Default constructor +//////////////////////////////////////////////////////////// +template +Rect::Rect() : +Left (0), +Top (0), +Right (0), +Bottom(0) +{ + +} + + +//////////////////////////////////////////////////////////// +/// Construct the color from its coordinates +//////////////////////////////////////////////////////////// +template +Rect::Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord) : +Left (LeftCoord), +Top (TopCoord), +Right (RightCoord), +Bottom(BottomCoord) +{ + +} + + +//////////////////////////////////////////////////////////// +/// Get the width of the rectangle +//////////////////////////////////////////////////////////// +template +T Rect::GetWidth() const +{ + return Right - Left; +} + + +//////////////////////////////////////////////////////////// +/// Get the height of the rectangle +//////////////////////////////////////////////////////////// +template +T Rect::GetHeight() const +{ + return Bottom - Top; +} + + +//////////////////////////////////////////////////////////// +/// Move the whole rectangle by the given offset +//////////////////////////////////////////////////////////// +template +void Rect::Offset(T OffsetX, T OffsetY) +{ + Left += OffsetX; + Right += OffsetX; + Top += OffsetY; + Bottom += OffsetY; +} + + +//////////////////////////////////////////////////////////// +/// Check if a point is inside the rectangle's area +//////////////////////////////////////////////////////////// +template +bool Rect::Contains(T X, T Y) const +{ + return (X >= Left) && (X <= Right) && (Y >= Top) && (Y <= Bottom); +} + + +//////////////////////////////////////////////////////////// +/// Check intersection between two rectangles +//////////////////////////////////////////////////////////// +template +bool Rect::Intersects(const Rect& Rectangle, Rect* OverlappingRect) const +{ + // Compute overlapping rect + Rect Overlapping(std::max(Left, Rectangle.Left), + std::max(Top, Rectangle.Top), + std::min(Right, Rectangle.Right), + std::min(Bottom, Rectangle.Bottom)); + + // If overlapping rect is valid, then there is intersection + if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overlapping.Bottom)) + { + if (OverlappingRect) + *OverlappingRect = Overlapping; + return true; + } + else + { + if (OverlappingRect) + *OverlappingRect = Rect(0, 0, 0, 0); + return false; + } +} diff --git a/SFML-1.6/include/SFML/Graphics/RenderTarget.hpp b/SFML-1.6/include/SFML/Graphics/RenderTarget.hpp new file mode 100644 index 000000000..ea303d9c1 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/RenderTarget.hpp @@ -0,0 +1,166 @@ +//////////////////////////////////////////////////////////// +// +// 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_RENDERTARGET_HPP +#define SFML_RENDERTARGET_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +class Drawable; + +//////////////////////////////////////////////////////////// +/// Base class for all render targets (window, image, ...) +//////////////////////////////////////////////////////////// +class SFML_API RenderTarget +{ +public : + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + virtual ~RenderTarget(); + + //////////////////////////////////////////////////////////// + /// Clear the entire target with a single color + /// + /// \param FillColor : Color to use to clear the render target + /// + //////////////////////////////////////////////////////////// + void Clear(const Color& FillColor = Color(0, 0, 0)); + + //////////////////////////////////////////////////////////// + /// Draw something into the target + /// + /// \param Object : Object to draw + /// + //////////////////////////////////////////////////////////// + virtual void Draw(const Drawable& Object); + + //////////////////////////////////////////////////////////// + /// Get the width of the rendering region of the target + /// + /// \return Width in pixels + /// + //////////////////////////////////////////////////////////// + virtual unsigned int GetWidth() const = 0; + + //////////////////////////////////////////////////////////// + /// Get the height of the rendering region of the target + /// + /// \return Height in pixels + /// + //////////////////////////////////////////////////////////// + virtual unsigned int GetHeight() const = 0; + + //////////////////////////////////////////////////////////// + /// Change the current active view. + /// + /// \param NewView : New view to use (pass GetDefaultView() to set the default view) + /// + //////////////////////////////////////////////////////////// + void SetView(const View& NewView); + + //////////////////////////////////////////////////////////// + /// Get the current view + /// + /// \return Current view active in the window + /// + //////////////////////////////////////////////////////////// + const View& GetView() const; + + //////////////////////////////////////////////////////////// + /// Get the default view of the window for read / write + /// + /// \return Default view + /// + //////////////////////////////////////////////////////////// + View& GetDefaultView(); + + //////////////////////////////////////////////////////////// + /// Tell SFML to preserve external OpenGL states, at the expense of + /// more CPU charge. Use this function if you don't want SFML + /// to mess up your own OpenGL states (if any). + /// Don't enable state preservation if not needed, as it will allow + /// SFML to do internal optimizations and improve performances. + /// This parameter is false by default + /// + /// \param Preserve : True to preserve OpenGL states, false to let SFML optimize + /// + //////////////////////////////////////////////////////////// + void PreserveOpenGLStates(bool Preserve); + +protected : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + RenderTarget(); + + //////////////////////////////////////////////////////////// + /// Called by the derived class when it's ready to be initialized + /// + //////////////////////////////////////////////////////////// + void Initialize(); + +private : + + //////////////////////////////////////////////////////////// + /// Activate the target for rendering + /// + /// \param Active : True to activate rendering, false to deactivate + /// + /// \return True if activation succeeded + /// + //////////////////////////////////////////////////////////// + virtual bool Activate(bool Active) = 0; + + //////////////////////////////////////////////////////////// + /// Set the OpenGL render states needed for the SFML rendering + /// + //////////////////////////////////////////////////////////// + void SetRenderStates(); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + View myDefaultView; ///< Default view + const View* myCurrentView; ///< Current active view + bool myPreserveStates; ///< Should we preserve external OpenGL states ? + bool myIsDrawing; ///< True when Draw is called from inside, to allow some renderstates optimizations +}; + +} // namespace sf + + +#endif // SFML_RENDERTARGET_HPP diff --git a/SFML-1.6/include/SFML/Graphics/RenderWindow.hpp b/SFML-1.6/include/SFML/Graphics/RenderWindow.hpp new file mode 100644 index 000000000..088e36827 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/RenderWindow.hpp @@ -0,0 +1,135 @@ +//////////////////////////////////////////////////////////// +// +// 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_RENDERWINDOW_HPP +#define SFML_RENDERWINDOW_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +class Drawable; + +//////////////////////////////////////////////////////////// +/// Simple wrapper for sf::Window that allows easy +/// 2D rendering +//////////////////////////////////////////////////////////// +class SFML_API RenderWindow : public Window, public RenderTarget +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + RenderWindow(); + + //////////////////////////////////////////////////////////// + /// Construct the window + /// + /// \param Mode : Video mode to use + /// \param Title : Title of the window + /// \param WindowStyle : Window style, see sf::Style (Resize | Close by default) + /// \param Params : Creation parameters (see default constructor for default values) + /// + //////////////////////////////////////////////////////////// + RenderWindow(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings()); + + //////////////////////////////////////////////////////////// + /// Construct the window from an existing control + /// + /// \param Handle : Platform-specific handle of the control + /// \param Params : Creation parameters (see default constructor for default values) + /// + //////////////////////////////////////////////////////////// + RenderWindow(WindowHandle Handle, const WindowSettings& Params = WindowSettings()); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + virtual ~RenderWindow(); + + //////////////////////////////////////////////////////////// + /// Get the width of the rendering region of the window + /// + /// \return Width in pixels + /// + //////////////////////////////////////////////////////////// + virtual unsigned int GetWidth() const; + + //////////////////////////////////////////////////////////// + /// Get the height of the rendering region of the window + /// + /// \return Height in pixels + /// + //////////////////////////////////////////////////////////// + virtual unsigned int GetHeight() const; + + //////////////////////////////////////////////////////////// + /// Save the content of the window to an image + /// + /// \return Image instance containing the contents of the screen + /// + //////////////////////////////////////////////////////////// + Image Capture() const; + + //////////////////////////////////////////////////////////// + /// Convert a point in window coordinates into view coordinates + /// + /// \param WindowX : X coordinate of the point to convert, relative to the window + /// \param WindowY : Y coordinate of the point to convert, relative to the window + /// \param TargetView : Target view to convert the point to (NULL by default -- uses the current view) + /// + /// \return Converted point + /// + //////////////////////////////////////////////////////////// + sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY, const View* TargetView = NULL) const; + +private : + + //////////////////////////////////////////////////////////// + /// /see Window::OnCreate + /// + //////////////////////////////////////////////////////////// + virtual void OnCreate(); + + //////////////////////////////////////////////////////////// + /// /see RenderTarget::Activate + /// + //////////////////////////////////////////////////////////// + virtual bool Activate(bool Active); +}; + +} // namespace sf + + +#endif // SFML_RENDERWINDOW_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Shape.hpp b/SFML-1.6/include/SFML/Graphics/Shape.hpp new file mode 100644 index 000000000..37fb3c4f6 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Shape.hpp @@ -0,0 +1,310 @@ +//////////////////////////////////////////////////////////// +// +// 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_SHAPE_HPP +#define SFML_SHAPE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Shape defines a drawable convex shape ; it also defines +/// helper functions to draw simple shapes like +/// lines, rectangles, circles, etc. +//////////////////////////////////////////////////////////// +class SFML_API Shape : public sf::Drawable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Shape(); + + //////////////////////////////////////////////////////////// + /// Add a point to the shape + /// + /// \param X, Y : Position of the point + /// \param Col : Color of the point (white by default) + /// \param OutlineCol : Outline color of the point (black by default) + /// + //////////////////////////////////////////////////////////// + void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0)); + + //////////////////////////////////////////////////////////// + /// Add a point to the shape + /// + /// \param Position : Position of the point + /// \param Col : Color of the point (white by default) + /// \param OutlineCol : Outline color of the point (black by default) + /// + //////////////////////////////////////////////////////////// + void AddPoint(const Vector2f& Position, const Color& Col = Color(255, 255, 255), const Color& OutlineCol = Color(0, 0, 0)); + + //////////////////////////////////////////////////////////// + /// Get the number of points composing the shape + /// + /// \param Total number of points + /// + //////////////////////////////////////////////////////////// + unsigned int GetNbPoints() const; + + //////////////////////////////////////////////////////////// + /// Enable or disable filling the shape. + /// Fill is enabled by default + /// + /// \param Enable : True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + void EnableFill(bool Enable); + + //////////////////////////////////////////////////////////// + /// Enable or disable drawing the shape outline. + /// Outline is enabled by default + /// + /// \param Enable : True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + void EnableOutline(bool Enable); + + //////////////////////////////////////////////////////////// + /// Set the position of a point + /// + /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] + /// \param Position : New position of the Index-th point + /// + //////////////////////////////////////////////////////////// + void SetPointPosition(unsigned int Index, const Vector2f& Position); + + //////////////////////////////////////////////////////////// + /// Set the position of a point + /// + /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] + /// \param X : New X coordinate of the Index-th point + /// \param Y : New Y coordinate of the Index-th point + /// + //////////////////////////////////////////////////////////// + void SetPointPosition(unsigned int Index, float X, float Y); + + //////////////////////////////////////////////////////////// + /// Set the color of a point + /// + /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] + /// \param Col : New color of the Index-th point + /// + //////////////////////////////////////////////////////////// + void SetPointColor(unsigned int Index, const Color& Col); + + //////////////////////////////////////////////////////////// + /// Set the outline color of a point + /// + /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] + /// \param OutlineCol : New outline color of the Index-th point + /// + //////////////////////////////////////////////////////////// + void SetPointOutlineColor(unsigned int Index, const Color& OutlineCol); + + //////////////////////////////////////////////////////////// + /// Change the width of the shape outline + /// + /// \param Width : New width + /// + //////////////////////////////////////////////////////////// + void SetOutlineWidth(float Width); + + //////////////////////////////////////////////////////////// + /// Get the position of a point + /// + /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] + /// + /// \return Position of the Index-th point + /// + //////////////////////////////////////////////////////////// + const Vector2f& GetPointPosition(unsigned int Index) const; + + //////////////////////////////////////////////////////////// + /// Get the color of a point + /// + /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] + /// + /// \return Color of the Index-th point + /// + //////////////////////////////////////////////////////////// + const Color& GetPointColor(unsigned int Index) const; + + //////////////////////////////////////////////////////////// + /// Get the outline color of a point + /// + /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] + /// + /// \return Outline color of the Index-th point + /// + //////////////////////////////////////////////////////////// + const Color& GetPointOutlineColor(unsigned int Index) const; + + //////////////////////////////////////////////////////////// + /// Get the width of the shape outline + /// + /// \return Current outline width + /// + //////////////////////////////////////////////////////////// + float GetOutlineWidth() const; + + //////////////////////////////////////////////////////////// + /// Create a shape made of a single line (use floats) + /// + /// \param P1X, P1Y : Position of the first point + /// \param P2X, P2Y : Position second point + /// \param Thickness : Line thickness + /// \param Col : Color used to draw the line + /// \param Outline : Outline width (0 by default) + /// \param OutlineCol : Color used to draw the outline (black by default) + /// + //////////////////////////////////////////////////////////// + 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)); + + //////////////////////////////////////////////////////////// + /// Create a shape made of a single line (use vectors) + /// + /// \param P1X, P1Y : Position of the first point + /// \param P2X, P2Y : Position second point + /// \param Thickness : Line thickness + /// \param Col : Color used to draw the line + /// \param Outline : Outline width (0 by default) + /// \param OutlineCol : Color used to draw the outline (black by default) + /// + //////////////////////////////////////////////////////////// + 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)); + + //////////////////////////////////////////////////////////// + /// Create a shape made of a single rectangle (use floats) + /// + /// \param P1X, P1Y : Position of the first point + /// \param P2X, P2Y : Position second point + /// \param Col : Color used to fill the rectangle + /// \param Outline : Outline width (0 by default) + /// \param OutlineCol : Color used to draw the outline (black by default) + /// + //////////////////////////////////////////////////////////// + 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)); + + //////////////////////////////////////////////////////////// + /// Create a shape made of a single rectangle (use vectors) + /// + /// \param P1 : Position of the first point + /// \param P2 : Position second point + /// \param Col : Color used to fill the rectangle + /// \param Outline : Outline width (0 by default) + /// \param OutlineCol : Color used to draw the outline (black by default) + /// + //////////////////////////////////////////////////////////// + static Shape Rectangle(const Vector2f& P1, const Vector2f& P2, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0)); + + //////////////////////////////////////////////////////////// + /// Create a shape made of a single circle (use floats) + /// + /// \param X, Y : Position of the center + /// \param Radius : Radius + /// \param Col : Color used to fill the circle + /// \param Outline : Outline width (0 by default) + /// \param OutlineCol : Color used to draw the outline (black by default) + /// + //////////////////////////////////////////////////////////// + static Shape Circle(float X, float Y, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0)); + + //////////////////////////////////////////////////////////// + /// Create a shape made of a single circle (use vectors) + /// + /// \param Center : Position of the center + /// \param Radius : Radius + /// \param Col : Color used to fill the circle + /// \param Outline : Outline width (0 by default) + /// \param OutlineCol : Color used to draw the outline (black by default) + /// + //////////////////////////////////////////////////////////// + static Shape Circle(const Vector2f& Center, float Radius, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0)); + +protected : + + //////////////////////////////////////////////////////////// + /// /see Drawable::Render + /// + //////////////////////////////////////////////////////////// + virtual void Render(RenderTarget& Target) const; + +private : + + //////////////////////////////////////////////////////////// + /// Compile the shape : compute its center and its outline + /// + //////////////////////////////////////////////////////////// + void Compile(); + + //////////////////////////////////////////////////////////// + /// Compute the normal of a given 2D segment + /// + /// \param P1 : First point of the segment + /// \param P2 : Second point of the segment + /// \param Normal : Calculated normal + /// + /// \return False if the normal couldn't be calculated (segment is null) + /// + //////////////////////////////////////////////////////////// + static bool ComputeNormal(const Vector2f& P1, const Vector2f& P2, Vector2f& Normal); + + //////////////////////////////////////////////////////////// + /// Defines a simple 2D point + //////////////////////////////////////////////////////////// + struct Point + { + Point(const Vector2f& Pos = Vector2f(0, 0), const Color& C = Color(255, 255, 255), const Color& OutlineC = Color(255, 255, 255)); + + Vector2f Position; ///< Position + Vector2f Normal; ///< Extruded normal + Color Col; ///< Color of the point + Color OutlineCol; ///< Outline color of the point + }; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::vector myPoints; ///< Points composing the shape + float myOutline; ///< Outline width + bool myIsFillEnabled; ///< Should we draw the inside if the shape ? + bool myIsOutlineEnabled; ///< Should we draw the outline if the shape ? + bool myIsCompiled; ///< Compiled state of the shape +}; + +} // namespace sf + + +#endif // SFML_SHAPE_HPP diff --git a/SFML-1.6/include/SFML/Graphics/Sprite.hpp b/SFML-1.6/include/SFML/Graphics/Sprite.hpp new file mode 100644 index 000000000..9d47bb44a --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/Sprite.hpp @@ -0,0 +1,176 @@ +//////////////////////////////////////////////////////////// +// +// 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_SPRITE_HPP +#define SFML_SPRITE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +class Image; + +//////////////////////////////////////////////////////////// +/// Sprite defines a sprite : texture, transformations, +/// color, and draw on screen +//////////////////////////////////////////////////////////// +class SFML_API Sprite : public Drawable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Sprite(); + + //////////////////////////////////////////////////////////// + /// Construct the sprite from a source image + /// + /// \param Img : Image of the sprite + /// \param Position : Position of the sprite (0, 0 by default) + /// \param Scale : Scale factor (1, 1 by default) + /// \param Rotation : Orientation, in degrees (0 by default) + /// \param Col : Color of the sprite (white by default) + /// + //////////////////////////////////////////////////////////// + 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)); + + //////////////////////////////////////////////////////////// + /// Change the image of the sprite + /// + /// \param Img : New image + /// + //////////////////////////////////////////////////////////// + void SetImage(const Image& Img); + + //////////////////////////////////////////////////////////// + /// Set the sub-rectangle of the sprite inside the source image. + /// By default, the subrect covers the entire source image + /// + /// \param SubRect : New sub-rectangle + /// + //////////////////////////////////////////////////////////// + void SetSubRect(const IntRect& SubRect); + + //////////////////////////////////////////////////////////// + /// Resize the sprite (by changing its scale factors) (take 2 values). + /// The default size is defined by the subrect + /// + /// \param Width : New width (must be strictly positive) + /// \param Height : New height (must be strictly positive) + /// + //////////////////////////////////////////////////////////// + void Resize(float Width, float Height); + + //////////////////////////////////////////////////////////// + /// Resize the sprite (by changing its scale factors) (take a 2D vector). + /// The default size is defined by the subrect + /// + /// \param Size : New size (both coordinates must be strictly positive) + /// + //////////////////////////////////////////////////////////// + void Resize(const Vector2f& Size); + + //////////////////////////////////////////////////////////// + /// Flip the sprite horizontally + /// + /// \param Flipped : True to flip the sprite + /// + //////////////////////////////////////////////////////////// + void FlipX(bool Flipped); + + //////////////////////////////////////////////////////////// + /// Flip the sprite vertically + /// + /// \param Flipped : True to flip the sprite + /// + //////////////////////////////////////////////////////////// + void FlipY(bool Flipped); + + //////////////////////////////////////////////////////////// + /// Get the source image of the sprite + /// + /// \return Pointer to the image (can be NULL) + /// + //////////////////////////////////////////////////////////// + const Image* GetImage() const; + + //////////////////////////////////////////////////////////// + /// Get the sub-rectangle of the sprite inside the source image + /// + /// \return Sub-rectangle + /// + //////////////////////////////////////////////////////////// + const IntRect& GetSubRect() const; + + //////////////////////////////////////////////////////////// + /// Get the sprite size + /// + /// \return Size of the sprite + /// + //////////////////////////////////////////////////////////// + Vector2f GetSize() const; + + //////////////////////////////////////////////////////////// + /// Get the color of a given pixel in the sprite + /// (point is in local coordinates) + /// + /// \param X : X coordinate of the pixel to get + /// \param Y : Y coordinate of the pixel to get + /// + /// \return Color of pixel (X, Y) + /// + //////////////////////////////////////////////////////////// + Color GetPixel(unsigned int X, unsigned int Y) const; + +protected : + + //////////////////////////////////////////////////////////// + /// /see Drawable::Render + /// + //////////////////////////////////////////////////////////// + virtual void Render(RenderTarget& Target) const; + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + ResourcePtr myImage; ///< Image used to draw the sprite + IntRect mySubRect; ///< Sub-rectangle of source image to assign to the sprite + bool myIsFlippedX; ///< Is the sprite flipped on the X axis ? + bool myIsFlippedY; ///< Is the sprite flipped on the Y axis ? +}; + +} // namespace sf + + +#endif // SFML_SPRITE_HPP diff --git a/SFML-1.6/include/SFML/Graphics/String.hpp b/SFML-1.6/include/SFML/Graphics/String.hpp new file mode 100644 index 000000000..b0ca81bf0 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/String.hpp @@ -0,0 +1,191 @@ +//////////////////////////////////////////////////////////// +// +// 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_STRING_HPP +#define SFML_STRING_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// String defines a graphical 2D text, that can be drawn on screen +//////////////////////////////////////////////////////////// +class SFML_API String : public Drawable +{ +public : + + //////////////////////////////////////////////////////////// + /// Enumerate the string drawing styles + //////////////////////////////////////////////////////////// + enum Style + { + Regular = 0, ///< Regular characters, no style + Bold = 1 << 0, ///< Characters are bold + Italic = 1 << 1, ///< Characters are in italic + Underlined = 1 << 2 ///< Characters are underlined + }; + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + String(); + + //////////////////////////////////////////////////////////// + /// Construct the string from any kind of text + /// + /// \param Text : Text assigned to the string + /// \param Font : Font used to draw the string (SFML built-in font by default) + /// \param Size : Characters size (30 by default) + /// + //////////////////////////////////////////////////////////// + explicit String(const Unicode::Text& Text, const Font& CharFont = Font::GetDefaultFont(), float Size = 30.f); + + //////////////////////////////////////////////////////////// + /// Set the text (from any kind of string) + /// + /// \param Text : New text + /// + //////////////////////////////////////////////////////////// + void SetText(const Unicode::Text& Text); + + //////////////////////////////////////////////////////////// + /// Set the font of the string + /// + /// \param Font : Font to use + /// + //////////////////////////////////////////////////////////// + void SetFont(const Font& CharFont); + + //////////////////////////////////////////////////////////// + /// Set the size of the string + /// The default size is 30 + /// + /// \param Size : New size, in pixels + /// + //////////////////////////////////////////////////////////// + void SetSize(float Size); + + //////////////////////////////////////////////////////////// + /// Set the style of the text + /// The default style is Regular + /// + /// \param TextStyle : New text style, (combination of Style enum values) + /// + //////////////////////////////////////////////////////////// + void SetStyle(unsigned long TextStyle); + + //////////////////////////////////////////////////////////// + /// Get the text (the returned text can be converted implicitely to any kind of string) + /// + /// \return String's text + /// + //////////////////////////////////////////////////////////// + const Unicode::Text& GetText() const; + + //////////////////////////////////////////////////////////// + /// Get the font used by the string + /// + /// \return Font used + /// + //////////////////////////////////////////////////////////// + const Font& GetFont() const; + + //////////////////////////////////////////////////////////// + /// Get the size of the characters + /// + /// \return Size of the characters + /// + //////////////////////////////////////////////////////////// + float GetSize() const; + + //////////////////////////////////////////////////////////// + /// Get the style of the text + /// + /// \return Current string style (combination of Style enum values) + /// + //////////////////////////////////////////////////////////// + unsigned long GetStyle() const; + + //////////////////////////////////////////////////////////// + /// Return the visual position of the Index-th character of the string, + /// in coordinates relative to the string + /// (note : translation, center, rotation and scale are not applied) + /// + /// \param Index : Index of the character + /// + /// \return Position of the Index-th character (end of string if Index is out of range) + /// + //////////////////////////////////////////////////////////// + sf::Vector2f GetCharacterPos(std::size_t Index) const; + + //////////////////////////////////////////////////////////// + /// Get the string rectangle on screen + /// + /// \return Rectangle contaning the string in screen coordinates + /// + //////////////////////////////////////////////////////////// + FloatRect GetRect() const; + +protected : + + //////////////////////////////////////////////////////////// + /// /see Drawable::Render + /// + //////////////////////////////////////////////////////////// + virtual void Render(RenderTarget& Target) const; + +private : + + //////////////////////////////////////////////////////////// + /// Recompute the bounding rectangle of the text + /// + //////////////////////////////////////////////////////////// + void RecomputeRect(); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Unicode::Text myText; ///< Text to display + ResourcePtr myFont; ///< Font used to display the string + float mySize; ///< Size of the characters + unsigned long myStyle; ///< Text style (see Style enum) + FloatRect myBaseRect; ///< Bounding rectangle of the text in object coordinates + bool myNeedRectUpdate; ///< Does the bounding rect need an update ? +}; + +} // namespace sf + + +#endif // SFML_STRING_HPP diff --git a/SFML-1.6/include/SFML/Graphics/View.hpp b/SFML-1.6/include/SFML/Graphics/View.hpp new file mode 100644 index 000000000..d5e401a33 --- /dev/null +++ b/SFML-1.6/include/SFML/Graphics/View.hpp @@ -0,0 +1,188 @@ +//////////////////////////////////////////////////////////// +// +// 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_VIEW_HPP +#define SFML_VIEW_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +class RenderTarget; + +//////////////////////////////////////////////////////////// +/// This class defines a view (position, size, etc.) ; +/// you can consider it as a 2D camera +//////////////////////////////////////////////////////////// +class SFML_API View +{ +public : + + //////////////////////////////////////////////////////////// + /// Construct the view from a rectangle + /// + /// \param ViewRect : Rectangle defining the position and size of the view (1000x1000 by default) + /// + //////////////////////////////////////////////////////////// + explicit View(const FloatRect& ViewRect = FloatRect(0, 0, 1000, 1000)); + + //////////////////////////////////////////////////////////// + /// Construct the view from its center and half-size + /// + /// \param Center : Center of the view + /// \param HalfSize : Half-size of the view (from center to corner) + /// + //////////////////////////////////////////////////////////// + View(const sf::Vector2f& Center, const sf::Vector2f& HalfSize); + + //////////////////////////////////////////////////////////// + /// Change the center of the view (take 2 values) + /// + /// \param X : X coordinate of the new center + /// \param Y : Y coordinate of the new center + /// + //////////////////////////////////////////////////////////// + void SetCenter(float X, float Y); + + //////////////////////////////////////////////////////////// + /// Change the center of the view (take a vector) + /// + /// \param Center : New center + /// + //////////////////////////////////////////////////////////// + void SetCenter(const sf::Vector2f& Center); + + //////////////////////////////////////////////////////////// + /// Change the half-size of the view (take 2 values) + /// + /// \param HalfWidth : New half-width + /// \param HalfHeight : New half-height + /// + //////////////////////////////////////////////////////////// + void SetHalfSize(float HalfWidth, float HalfHeight); + + //////////////////////////////////////////////////////////// + /// Change the half-size of the view (take a vector) + /// + /// \param HalfSize : New half-size + /// + //////////////////////////////////////////////////////////// + void SetHalfSize(const sf::Vector2f& HalfSize); + + //////////////////////////////////////////////////////////// + /// Rebuild the view from a rectangle + /// + /// \param ViewRect : Rectangle defining the position and size of the view + /// + //////////////////////////////////////////////////////////// + void SetFromRect(const FloatRect& ViewRect); + + //////////////////////////////////////////////////////////// + /// Get the center of the view + /// + /// \return Center of the view + /// + //////////////////////////////////////////////////////////// + const sf::Vector2f& GetCenter() const; + + //////////////////////////////////////////////////////////// + /// Get the half-size of the view + /// + /// \return Half-size of the view + /// + //////////////////////////////////////////////////////////// + const sf::Vector2f& GetHalfSize() const; + + //////////////////////////////////////////////////////////// + /// Get the bounding rectangle of the view + /// + /// \return Bounding rectangle of the view + /// + //////////////////////////////////////////////////////////// + const sf::FloatRect& GetRect() const; + + //////////////////////////////////////////////////////////// + /// Move the view (take 2 values) + /// + /// \param OffsetX : Offset to move the view, on X axis + /// \param OffsetY : Offset to move the view, on Y axis + /// + //////////////////////////////////////////////////////////// + void Move(float OffsetX, float OffsetY); + + //////////////////////////////////////////////////////////// + /// Move the view (take a vector) + /// + /// \param Offset : Offset to move the view + /// + //////////////////////////////////////////////////////////// + void Move(const sf::Vector2f& Offset); + + //////////////////////////////////////////////////////////// + /// Resize the view rectangle to simulate a zoom / unzoom effect + /// + /// \param Factor : Zoom factor to apply, relative to the current zoom + /// + //////////////////////////////////////////////////////////// + void Zoom(float Factor); + +private : + + friend class RenderTarget; + + //////////////////////////////////////////////////////////// + /// Get the projection matrix of the view + /// + /// \return Projection matrix containing the view settings + /// + //////////////////////////////////////////////////////////// + const Matrix3& GetMatrix() const; + + //////////////////////////////////////////////////////////// + /// Recompute the view rectangle and the projection matrix + /// + //////////////////////////////////////////////////////////// + void RecomputeMatrix(); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + sf::Vector2f myCenter; ///< Center of the view + sf::Vector2f myHalfSize; ///< Half-size of the view + FloatRect myRect; ///< Rectangle defining the bounds of the view + Matrix3 myMatrix; ///< Precomputed projection matrix corresponding to the view + bool myNeedUpdate; ///< Internal state telling if the matrix needs to be updated +}; + +} // namespace sf + + +#endif // SFML_VIEW_HPP diff --git a/SFML-1.6/include/SFML/Network/Ftp.hpp b/SFML-1.6/include/SFML/Network/Ftp.hpp new file mode 100644 index 000000000..f2f1bd33d --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Ftp.hpp @@ -0,0 +1,448 @@ +//////////////////////////////////////////////////////////// +// +// 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_FTP_HPP +#define SFML_FTP_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +class IPAddress; + +//////////////////////////////////////////////////////////// +/// This class provides methods for manipulating the FTP +/// protocol (described in RFC 959). +/// It provides easy access and transfers to remote +/// directories and files on a FTP server +//////////////////////////////////////////////////////////// +class SFML_API Ftp : NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// Enumeration of transfer modes + //////////////////////////////////////////////////////////// + enum TransferMode + { + Binary, ///< Binary mode (file is transfered as a sequence of bytes) + Ascii, ///< Text mode using ASCII encoding + Ebcdic ///< Text mode using EBCDIC encoding + }; + + //////////////////////////////////////////////////////////// + /// This class wraps a FTP response, which is basically : + /// - a status code + /// - a message + //////////////////////////////////////////////////////////// + class SFML_API Response + { + public : + + //////////////////////////////////////////////////////////// + /// Enumerate all the valid status codes returned in + /// a FTP response + //////////////////////////////////////////////////////////// + enum Status + { + // 1xx: the requested action is being initiated, + // expect another reply before proceeding with a new command + RestartMarkerReply = 110, ///< Restart marker reply + ServiceReadySoon = 120, ///< Service ready in N minutes + DataConnectionAlreadyOpened = 125, ///< Data connection already opened, transfer starting + OpeningDataConnection = 150, ///< File status ok, about to open data connection + + // 2xx: the requested action has been successfully completed + Ok = 200, ///< Command ok + PointlessCommand = 202, ///< Command not implemented + SystemStatus = 211, ///< System status, or system help reply + DirectoryStatus = 212, ///< Directory status + FileStatus = 213, ///< File status + HelpMessage = 214, ///< Help message + SystemType = 215, ///< NAME system type, where NAME is an official system name from the list in the Assigned Numbers document + ServiceReady = 220, ///< Service ready for new user + ClosingConnection = 221, ///< Service closing control connection + DataConnectionOpened = 225, ///< Data connection open, no transfer in progress + ClosingDataConnection = 226, ///< Closing data connection, requested file action successful + EnteringPassiveMode = 227, ///< Entering passive mode + LoggedIn = 230, ///< User logged in, proceed. Logged out if appropriate + FileActionOk = 250, ///< Requested file action ok + DirectoryOk = 257, ///< PATHNAME created + + // 3xx: the command has been accepted, but the requested action + // is dormant, pending receipt of further information + NeedPassword = 331, ///< User name ok, need password + NeedAccountToLogIn = 332, ///< Need account for login + NeedInformation = 350, ///< Requested file action pending further information + + // 4xx: the command was not accepted and the requested action did not take place, + // but the error condition is temporary and the action may be requested again + ServiceUnavailable = 421, ///< Service not available, closing control connection + DataConnectionUnavailable = 425, ///< Can't open data connection + TransferAborted = 426, ///< Connection closed, transfer aborted + FileActionAborted = 450, ///< Requested file action not taken + LocalError = 451, ///< Requested action aborted, local error in processing + InsufficientStorageSpace = 452, ///< Requested action not taken; insufficient storage space in system, file unavailable + + // 5xx: the command was not accepted and + // the requested action did not take place + CommandUnknown = 500, ///< Syntax error, command unrecognized + ParametersUnknown = 501, ///< Syntax error in parameters or arguments + CommandNotImplemented = 502, ///< Command not implemented + BadCommandSequence = 503, ///< Bad sequence of commands + ParameterNotImplemented = 504, ///< Command not implemented for that parameter + NotLoggedIn = 530, ///< Not logged in + NeedAccountToStore = 532, ///< Need account for storing files + FileUnavailable = 550, ///< Requested action not taken, file unavailable + PageTypeUnknown = 551, ///< Requested action aborted, page type unknown + NotEnoughMemory = 552, ///< Requested file action aborted, exceeded storage allocation + FilenameNotAllowed = 553, ///< Requested action not taken, file name not allowed + + // 10xx: SFML custom codes + InvalidResponse = 1000, ///< Response is not a valid FTP one + ConnectionFailed = 1001, ///< Connection with server failed + ConnectionClosed = 1002, ///< Connection with server closed + InvalidFile = 1003 ///< Invalid file to upload / download + }; + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + /// \param Code : Response status code (InvalidResponse by default) + /// \param Message : Response message (empty by default) + /// + //////////////////////////////////////////////////////////// + Response(Status Code = InvalidResponse, const std::string& Message = ""); + + //////////////////////////////////////////////////////////// + /// Convenience function to check if the response status code + /// means a success + /// + /// \return True if status is success (code < 400) + /// + //////////////////////////////////////////////////////////// + bool IsOk() const; + + //////////////////////////////////////////////////////////// + /// Get the response status code + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Status GetStatus() const; + + //////////////////////////////////////////////////////////// + /// Get the full message contained in the response + /// + /// \return The response message + /// + //////////////////////////////////////////////////////////// + const std::string& GetMessage() const; + + private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Status myStatus; ///< Status code returned from the server + std::string myMessage; ///< Last message received from the server + }; + + //////////////////////////////////////////////////////////// + /// Specialization of FTP response returning a directory + //////////////////////////////////////////////////////////// + class SFML_API DirectoryResponse : public Response + { + public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + /// \param Resp : Source response + /// + //////////////////////////////////////////////////////////// + DirectoryResponse(Response Resp); + + //////////////////////////////////////////////////////////// + /// Get the directory returned in the response + /// + /// \return Directory name + /// + //////////////////////////////////////////////////////////// + const std::string& GetDirectory() const; + + private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::string myDirectory; ///< Directory extracted from the response message + }; + + + //////////////////////////////////////////////////////////// + /// Specialization of FTP response returning a filename lisiting + //////////////////////////////////////////////////////////// + class SFML_API ListingResponse : public Response + { + public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + /// \param Resp : Source response + /// \param Data : Data containing the raw listing + /// + //////////////////////////////////////////////////////////// + ListingResponse(Response Resp, const std::vector& Data); + + //////////////////////////////////////////////////////////// + /// Get the number of filenames in the listing + /// + /// \return Total number of filenames + /// + //////////////////////////////////////////////////////////// + std::size_t GetCount() const; + + //////////////////////////////////////////////////////////// + /// Get the Index-th filename in the directory + /// + /// \param Index : Index of the filename to get + /// + /// \return Index-th filename + /// + //////////////////////////////////////////////////////////// + const std::string& GetFilename(std::size_t Index) const; + + private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::vector myFilenames; ///< Filenames extracted from the data + }; + + + //////////////////////////////////////////////////////////// + /// Destructor -- close the connection with the server + /// + //////////////////////////////////////////////////////////// + ~Ftp(); + + //////////////////////////////////////////////////////////// + /// Connect to the specified FTP server + /// + /// \param Server : FTP server to connect to + /// \param Port : Port used for connection (21 by default, standard FTP port) + /// \param Timeout : Maximum time to wait, in seconds (0 by default, means no timeout) + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response Connect(const IPAddress& Server, unsigned short Port = 21, float Timeout = 0.f); + + //////////////////////////////////////////////////////////// + /// Log in using anonymous account + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response Login(); + + //////////////////////////////////////////////////////////// + /// Log in using a username and a password + /// + /// \param UserName : User name + /// \param Password : Password + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response Login(const std::string& UserName, const std::string& Password); + + //////////////////////////////////////////////////////////// + /// Close the connection with FTP server + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response Disconnect(); + + //////////////////////////////////////////////////////////// + /// Send a null command just to prevent from being disconnected + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response KeepAlive(); + + //////////////////////////////////////////////////////////// + /// Get the current working directory + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + DirectoryResponse GetWorkingDirectory(); + + //////////////////////////////////////////////////////////// + /// Get the contents of the given directory + /// (subdirectories and files) + /// + /// \param Directory : Directory to list ("" by default, the current one) + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + ListingResponse GetDirectoryListing(const std::string& Directory = ""); + + //////////////////////////////////////////////////////////// + /// Change the current working directory + /// + /// \param Directory : New directory, relative to the current one + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response ChangeDirectory(const std::string& Directory); + + //////////////////////////////////////////////////////////// + /// Go to the parent directory of the current one + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response ParentDirectory(); + + //////////////////////////////////////////////////////////// + /// Create a new directory + /// + /// \param Name : Name of the directory to create + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response MakeDirectory(const std::string& Name); + + //////////////////////////////////////////////////////////// + /// Remove an existing directory + /// + /// \param Name : Name of the directory to remove + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response DeleteDirectory(const std::string& Name); + + //////////////////////////////////////////////////////////// + /// Rename a file + /// + /// \param File : File to rename + /// \param NewName : New name + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response RenameFile(const std::string& File, const std::string& NewName); + + //////////////////////////////////////////////////////////// + /// Remove an existing file + /// + /// \param Name : File to remove + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response DeleteFile(const std::string& Name); + + //////////////////////////////////////////////////////////// + /// Download a file from the server + /// + /// \param DistantFile : Path of the distant file to download + /// \param DestPath : Where to put to file on the local computer + /// \param Mode : Transfer mode (binary by default) + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response Download(const std::string& DistantFile, const std::string& DestPath, TransferMode Mode = Binary); + + //////////////////////////////////////////////////////////// + /// Upload a file to the server + /// + /// \param LocalFile : Path of the local file to upload + /// \param DestPath : Where to put to file on the server + /// \param Mode : Transfer mode (binary by default) + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response Upload(const std::string& LocalFile, const std::string& DestPath, TransferMode Mode = Binary); + +private : + + //////////////////////////////////////////////////////////// + /// Send a command to the FTP server + /// + /// \param Command : Command to send + /// \param Parameter : Command parameter ("" by default) + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response SendCommand(const std::string& Command, const std::string& Parameter = ""); + + //////////////////////////////////////////////////////////// + /// Receive a response from the server + /// (usually after a command has been sent) + /// + /// \return Server response to the request + /// + //////////////////////////////////////////////////////////// + Response GetResponse(); + + //////////////////////////////////////////////////////////// + /// Utility class for exchanging datas with the server + /// on the data channel + //////////////////////////////////////////////////////////// + class DataChannel; + + friend class DataChannel; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + SocketTCP myCommandSocket; ///< Socket holding the control connection with the server +}; + +} // namespace sf + + +#endif // SFML_FTP_HPP diff --git a/SFML-1.6/include/SFML/Network/Http.hpp b/SFML-1.6/include/SFML/Network/Http.hpp new file mode 100644 index 000000000..54e5c1fcc --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Http.hpp @@ -0,0 +1,340 @@ +//////////////////////////////////////////////////////////// +// +// 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_HTTP_HPP +#define SFML_HTTP_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// This class provides methods for manipulating the HTTP +/// protocol (described in RFC 1945). +/// It can connect to a website, get its files, send requests, etc. +//////////////////////////////////////////////////////////// +class SFML_API Http : NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// This class wraps an HTTP request, which is basically : + /// - a header with a method, a target URI, and a set of field/value pairs + /// - an optional body (for POST requests) + //////////////////////////////////////////////////////////// + class SFML_API Request + { + public : + + //////////////////////////////////////////////////////////// + /// Enumerate the available HTTP methods for a request + //////////////////////////////////////////////////////////// + enum Method + { + Get, ///< Request in get mode, standard method to retrieve a page + Post, ///< Request in post mode, usually to send data to a page + Head ///< Request a page's header only + }; + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + /// \param RequestMethod : Method to use for the request (Get by default) + /// \param URI : Target URI ("/" by default -- index page) + /// \param Body : Content of the request's body (empty by default) + /// + //////////////////////////////////////////////////////////// + Request(Method RequestMethod = Get, const std::string& URI = "/", const std::string& Body = ""); + + //////////////////////////////////////////////////////////// + /// Set the value of a field; the field is added if it doesn't exist + /// + /// \param Field : Name of the field to set (case-insensitive) + /// \param Value : Value of the field + /// + //////////////////////////////////////////////////////////// + void SetField(const std::string& Field, const std::string& Value); + + //////////////////////////////////////////////////////////// + /// Set the request method. + /// This parameter is Http::Request::Get by default + /// + /// \param RequestMethod : Method to use for the request + /// + //////////////////////////////////////////////////////////// + void SetMethod(Method RequestMethod); + + //////////////////////////////////////////////////////////// + /// Set the target URI of the request. + /// This parameter is "/" by default + /// + /// \param URI : URI to request, local to the host + /// + //////////////////////////////////////////////////////////// + void SetURI(const std::string& URI); + + //////////////////////////////////////////////////////////// + /// Set the HTTP version of the request. + /// This parameter is 1.0 by default + /// + /// \param Major : Major version number + /// \param Minor : Minor version number + /// + //////////////////////////////////////////////////////////// + void SetHttpVersion(unsigned int Major, unsigned int Minor); + + //////////////////////////////////////////////////////////// + /// Set the body of the request. This parameter is optional and + /// makes sense only for POST requests. + /// This parameter is empty by default + /// + /// \param Body : Content of the request body + /// + //////////////////////////////////////////////////////////// + void SetBody(const std::string& Body); + + private : + + friend class Http; + + //////////////////////////////////////////////////////////// + /// Get the string representation of the request header + /// + /// \return String containing the request + /// + //////////////////////////////////////////////////////////// + std::string ToString() const; + + //////////////////////////////////////////////////////////// + /// Check if the given field has been defined + /// + /// \param Field : Name of the field to check (case-insensitive) + /// + /// \return True if the field exists + /// + //////////////////////////////////////////////////////////// + bool HasField(const std::string& Field) const; + + //////////////////////////////////////////////////////////// + // Types + //////////////////////////////////////////////////////////// + typedef std::map FieldTable; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + FieldTable myFields; ///< Fields of the header + Method myMethod; ///< Method to use for the request + std::string myURI; ///< Target URI of the request + unsigned int myMajorVersion; ///< Major HTTP version + unsigned int myMinorVersion; ///< Minor HTTP version + std::string myBody; ///< Body of the request + }; + + //////////////////////////////////////////////////////////// + /// This class wraps an HTTP response, which is basically : + /// - a header with a status code and a set of field/value pairs + /// - a body (the content of the requested resource) + //////////////////////////////////////////////////////////// + class SFML_API Response + { + public : + + //////////////////////////////////////////////////////////// + /// Enumerate all the valid status codes returned in + /// a HTTP response + //////////////////////////////////////////////////////////// + enum Status + { + // 2xx: success + Ok = 200, ///< Most common code returned when operation was successful + Created = 201, ///< The resource has successfully been created + Accepted = 202, ///< The request has been accepted, but will be processed later by the server + NoContent = 204, ///< Sent when the server didn't send any data in return + + // 3xx: redirection + MultipleChoices = 300, ///< The requested page can be accessed from several locations + MovedPermanently = 301, ///< The requested page has permanently moved to a new location + MovedTemporarily = 302, ///< The requested page has temporarily moved to a new location + NotModified = 304, ///< For conditionnal requests, means the requested page hasn't changed and doesn't need to be refreshed + + // 4xx: client error + BadRequest = 400, ///< The server couldn't understand the request (syntax error) + Unauthorized = 401, ///< The requested page needs an authentification to be accessed + Forbidden = 403, ///< The requested page cannot be accessed at all, even with authentification + NotFound = 404, ///< The requested page doesn't exist + + // 5xx: server error + InternalServerError = 500, ///< The server encountered an unexpected error + NotImplemented = 501, ///< The server doesn't implement a requested feature + BadGateway = 502, ///< The gateway server has received an error from the source server + ServiceNotAvailable = 503, ///< The server is temporarily unavailable (overloaded, in maintenance, ...) + + // 10xx: SFML custom codes + InvalidResponse = 1000, ///< Response is not a valid HTTP one + ConnectionFailed = 1001 ///< Connection with server failed + }; + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Response(); + + //////////////////////////////////////////////////////////// + /// Get the value of a field + /// + /// \param Field : Name of the field to get (case-insensitive) + /// + /// \return Value of the field, or empty string if not found + /// + //////////////////////////////////////////////////////////// + const std::string& GetField(const std::string& Field) const; + + //////////////////////////////////////////////////////////// + /// Get the header's status code + /// + /// \return Header's status code + /// + //////////////////////////////////////////////////////////// + Status GetStatus() const; + + //////////////////////////////////////////////////////////// + /// Get the major HTTP version number of the response + /// + /// \return Major version number + /// + //////////////////////////////////////////////////////////// + unsigned int GetMajorHttpVersion() const; + + //////////////////////////////////////////////////////////// + /// Get the major HTTP version number of the response + /// + /// \return Major version number + /// + //////////////////////////////////////////////////////////// + unsigned int GetMinorHttpVersion() const; + + //////////////////////////////////////////////////////////// + /// Get the body of the response. The body can contain : + /// - the requested page (for GET requests) + /// - a response from the server (for POST requests) + /// - nothing (for HEAD requests) + /// - an error message (in case of an error) + /// + /// \return The response body + /// + //////////////////////////////////////////////////////////// + const std::string& GetBody() const; + + private : + + friend class Http; + + //////////////////////////////////////////////////////////// + /// Construct the header from a response string + /// + /// \param Data : Content of the response's header to parse + /// + //////////////////////////////////////////////////////////// + void FromString(const std::string& Data); + + //////////////////////////////////////////////////////////// + // Types + //////////////////////////////////////////////////////////// + typedef std::map FieldTable; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + FieldTable myFields; ///< Fields of the header + Status myStatus; ///< Status code + unsigned int myMajorVersion; ///< Major HTTP version + unsigned int myMinorVersion; ///< Minor HTTP version + std::string myBody; ///< Body of the response + }; + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Http(); + + //////////////////////////////////////////////////////////// + /// Construct the Http instance with the target host + /// + /// \param Host : Web server to connect to + /// \param Port : Port to use for connection (0 by default -- use the standard port of the protocol used) + /// + //////////////////////////////////////////////////////////// + Http(const std::string& Host, unsigned short Port = 0); + + //////////////////////////////////////////////////////////// + /// Set the target host + /// + /// \param Host : Web server to connect to + /// \param Port : Port to use for connection (0 by default -- use the standard port of the protocol used) + /// + //////////////////////////////////////////////////////////// + void SetHost(const std::string& Host, unsigned short Port = 0); + + //////////////////////////////////////////////////////////// + /// Send a HTTP request and return the server's response. + /// You must be connected to a host before sending requests. + /// Any missing mandatory header field will be added with an appropriate value. + /// Warning : this function waits for the server's response and may + /// not return instantly; use a thread if you don't want to block your + /// application. + /// + /// \param Req : Request to send + /// \param Timeout : Maximum time to wait, in seconds (0 by default, means no timeout) + /// + /// \return Server's response + /// + //////////////////////////////////////////////////////////// + Response SendRequest(const Request& Req, float Timeout = 0.f); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + SocketTCP myConnection; ///< Connection to the host + IPAddress myHost; ///< Web host address + std::string myHostName; ///< Web host name + unsigned short myPort; ///< Port used for connection with host +}; + +} // namespace sf + + +#endif // SFML_HTTP_HPP diff --git a/SFML-1.6/include/SFML/Network/IPAddress.hpp b/SFML-1.6/include/SFML/Network/IPAddress.hpp new file mode 100644 index 000000000..638dc4788 --- /dev/null +++ b/SFML-1.6/include/SFML/Network/IPAddress.hpp @@ -0,0 +1,231 @@ +//////////////////////////////////////////////////////////// +// +// 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_IPADDRESS_HPP +#define SFML_IPADDRESS_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// IPAddress provides easy manipulation of IP v4 addresses +//////////////////////////////////////////////////////////// +class SFML_API IPAddress +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor -- constructs an invalid address + /// + //////////////////////////////////////////////////////////// + IPAddress(); + + //////////////////////////////////////////////////////////// + /// Construct the address from a string + /// + /// \param Address : IP address ("xxx.xxx.xxx.xxx") or network name + /// + //////////////////////////////////////////////////////////// + IPAddress(const std::string& Address); + + //////////////////////////////////////////////////////////// + /// Construct the address from a C-style string ; + /// Needed for implicit conversions from literal strings to IPAddress to work + /// + /// \param Address : IP address ("xxx.xxx.xxx.xxx") or network name + /// + //////////////////////////////////////////////////////////// + IPAddress(const char* Address); + + //////////////////////////////////////////////////////////// + /// Construct the address from 4 bytes + /// + /// \param Byte0 : First byte of the address + /// \param Byte1 : Second byte of the address + /// \param Byte2 : Third byte of the address + /// \param Byte3 : Fourth byte of the address + /// + //////////////////////////////////////////////////////////// + IPAddress(Uint8 Byte0, Uint8 Byte1, Uint8 Byte2, Uint8 Byte3); + + //////////////////////////////////////////////////////////// + /// Construct the address from a 32-bits integer + /// + /// \param Address : 4 bytes of the address packed into a 32-bits integer + /// + //////////////////////////////////////////////////////////// + IPAddress(Uint32 Address); + + //////////////////////////////////////////////////////////// + /// Tell if the address is a valid one + /// + /// \return True if address has a valid syntax + /// + //////////////////////////////////////////////////////////// + bool IsValid() const; + + //////////////////////////////////////////////////////////// + /// Get a string representation of the address + /// + /// \return String representation of the IP address ("xxx.xxx.xxx.xxx") + /// + //////////////////////////////////////////////////////////// + std::string ToString() const; + + //////////////////////////////////////////////////////////// + /// Get an integer representation of the address + /// + /// \return 32-bits integer containing the 4 bytes of the address, in system endianness + /// + //////////////////////////////////////////////////////////// + Uint32 ToInteger() const; + + //////////////////////////////////////////////////////////// + /// Get the computer's local IP address (from the LAN point of view) + /// + /// \return Local IP address + /// + //////////////////////////////////////////////////////////// + static IPAddress GetLocalAddress(); + + //////////////////////////////////////////////////////////// + /// Get the computer's public IP address (from the web point of view). + /// The only way to get a public address is to ask it to a + /// distant website ; as a consequence, this function may be + /// very slow -- use it as few as possible ! + /// + /// \param Timeout : Maximum time to wait, in seconds (0 by default : no timeout) + /// + /// \return Public IP address + /// + //////////////////////////////////////////////////////////// + static IPAddress GetPublicAddress(float Timeout = 0.f); + + //////////////////////////////////////////////////////////// + /// Comparison operator == + /// + /// \param Other : Address to compare + /// + /// \return True if *this == Other + /// + //////////////////////////////////////////////////////////// + bool operator ==(const IPAddress& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator != + /// + /// \param Other : Address to compare + /// + /// \return True if *this != Other + /// + //////////////////////////////////////////////////////////// + bool operator !=(const IPAddress& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator < + /// + /// \param Other : Address to compare + /// + /// \return True if *this < Other + /// + //////////////////////////////////////////////////////////// + bool operator <(const IPAddress& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator > + /// + /// \param Other : Address to compare + /// + /// \return True if *this > Other + /// + //////////////////////////////////////////////////////////// + bool operator >(const IPAddress& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator <= + /// + /// \param Other : Address to compare + /// + /// \return True if *this <= Other + /// + //////////////////////////////////////////////////////////// + bool operator <=(const IPAddress& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator >= + /// + /// \param Other : Address to compare + /// + /// \return True if *this >= Other + /// + //////////////////////////////////////////////////////////// + bool operator >=(const IPAddress& Other) const; + + //////////////////////////////////////////////////////////// + // Static member data + //////////////////////////////////////////////////////////// + static const IPAddress LocalHost; ///< Local host address (to connect to the same computer) + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Uint32 myAddress; ///< Address stored as an unsigned 32 bits integer +}; + +//////////////////////////////////////////////////////////// +/// Operator >> overload to extract an address from an input stream +/// +/// \param Stream : Input stream +/// \param Address : Address to extract +/// +/// \return Reference to the input stream +/// +//////////////////////////////////////////////////////////// +SFML_API std::istream& operator >>(std::istream& Stream, IPAddress& Address); + +//////////////////////////////////////////////////////////// +/// Operator << overload to print an address to an output stream +/// +/// \param Stream : Output stream +/// \param Address : Address to print +/// +/// \return Reference to the output stream +/// +//////////////////////////////////////////////////////////// +SFML_API std::ostream& operator <<(std::ostream& Stream, const IPAddress& Address); + +} // namespace sf + + +#endif // SFML_IPADDRESS_HPP diff --git a/SFML-1.6/include/SFML/Network/Packet.hpp b/SFML-1.6/include/SFML/Network/Packet.hpp new file mode 100644 index 000000000..9c5463f42 --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Packet.hpp @@ -0,0 +1,187 @@ +//////////////////////////////////////////////////////////// +// +// 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_PACKET_HPP +#define SFML_PACKET_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Packet wraps data to send / to receive through the network +//////////////////////////////////////////////////////////// +class SFML_API Packet +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Packet(); + + //////////////////////////////////////////////////////////// + /// Virtual destructor + /// + //////////////////////////////////////////////////////////// + virtual ~Packet(); + + //////////////////////////////////////////////////////////// + /// Append data to the end of the packet + /// + /// \param Data : Pointer to the bytes to append + /// \param SizeInBytes : Number of bytes to append + /// + //////////////////////////////////////////////////////////// + void Append(const void* Data, std::size_t SizeInBytes); + + //////////////////////////////////////////////////////////// + /// Clear the packet data + /// + //////////////////////////////////////////////////////////// + void Clear(); + + //////////////////////////////////////////////////////////// + /// Get a pointer to the data contained in the packet + /// Warning : the returned pointer may be invalid after you + /// append data to the packet + /// + /// \return Pointer to the data + /// + //////////////////////////////////////////////////////////// + const char* GetData() const; + + //////////////////////////////////////////////////////////// + /// Get the size of the data contained in the packet + /// + /// \return Data size, in bytes + /// + //////////////////////////////////////////////////////////// + std::size_t GetDataSize() const; + + //////////////////////////////////////////////////////////// + /// Tell if the reading position has reached the end of the packet + /// + /// \return True if all data have been read into the packet + /// + //////////////////////////////////////////////////////////// + bool EndOfPacket() const; + + //////////////////////////////////////////////////////////// + /// Return the validity of packet + /// + /// \return True if last data extraction from packet was successful + /// + //////////////////////////////////////////////////////////// + operator bool() const; + + //////////////////////////////////////////////////////////// + /// Operator >> overloads to extract data from the packet + /// + //////////////////////////////////////////////////////////// + Packet& operator >>(bool& Data); + Packet& operator >>(Int8& Data); + Packet& operator >>(Uint8& Data); + Packet& operator >>(Int16& Data); + Packet& operator >>(Uint16& Data); + Packet& operator >>(Int32& Data); + Packet& operator >>(Uint32& Data); + Packet& operator >>(float& Data); + Packet& operator >>(double& Data); + Packet& operator >>(char* Data); + Packet& operator >>(std::string& Data); + Packet& operator >>(wchar_t* Data); + Packet& operator >>(std::wstring& Data); + + //////////////////////////////////////////////////////////// + /// Operator << overloads to put data into the packet + /// + //////////////////////////////////////////////////////////// + Packet& operator <<(bool Data); + Packet& operator <<(Int8 Data); + Packet& operator <<(Uint8 Data); + Packet& operator <<(Int16 Data); + Packet& operator <<(Uint16 Data); + Packet& operator <<(Int32 Data); + Packet& operator <<(Uint32 Data); + Packet& operator <<(float Data); + Packet& operator <<(double Data); + Packet& operator <<(const char* Data); + Packet& operator <<(const std::string& Data); + Packet& operator <<(const wchar_t* Data); + Packet& operator <<(const std::wstring& Data); + +private : + + friend class SocketTCP; + friend class SocketUDP; + + //////////////////////////////////////////////////////////// + /// Check if the packet can extract a given size of bytes + /// + /// \param Size : Size to check + /// + /// \return True if Size bytes can be read from the packet's data + /// + //////////////////////////////////////////////////////////// + bool CheckSize(std::size_t Size); + + //////////////////////////////////////////////////////////// + /// Called before the packet is sent to the network + /// + /// \param DataSize : Variable to fill with the size of data to send + /// + /// \return Pointer to the array of bytes to send + /// + //////////////////////////////////////////////////////////// + virtual const char* OnSend(std::size_t& DataSize); + + //////////////////////////////////////////////////////////// + /// Called after the packet has been received from the network + /// + /// \param Data : Pointer to the array of received bytes + /// \param DataSize : Size of the array of bytes + /// + //////////////////////////////////////////////////////////// + virtual void OnReceive(const char* Data, std::size_t DataSize); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::vector myData; ///< Data stored in the packet + std::size_t myReadPos; ///< Current reading position in the packet + bool myIsValid; ///< Reading state of the packet +}; + +} // namespace sf + + +#endif // SFML_PACKET_HPP diff --git a/SFML-1.6/include/SFML/Network/Selector.hpp b/SFML-1.6/include/SFML/Network/Selector.hpp new file mode 100644 index 000000000..588a72c1c --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Selector.hpp @@ -0,0 +1,116 @@ +//////////////////////////////////////////////////////////// +// +// 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_SELECTOR_HPP +#define SFML_SELECTOR_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Selector allow reading from multiple sockets +/// without blocking. It's a kind of multiplexer +//////////////////////////////////////////////////////////// +template +class Selector : private SelectorBase +{ +public : + + //////////////////////////////////////////////////////////// + /// Add a socket to watch + /// + /// \param Socket : Socket to add + /// + //////////////////////////////////////////////////////////// + void Add(Type Socket); + + //////////////////////////////////////////////////////////// + /// Remove a socket + /// + /// \param Socket : Socket to remove + /// + //////////////////////////////////////////////////////////// + void Remove(Type Socket); + + //////////////////////////////////////////////////////////// + /// Remove all sockets + /// + //////////////////////////////////////////////////////////// + void Clear(); + + //////////////////////////////////////////////////////////// + /// Wait and collect sockets which are ready for reading. + /// This functions will return either when at least one socket + /// is ready, or when the given time is out + /// + /// \param Timeout : Timeout, in seconds (0 by default : no timeout) + /// + /// \return Number of sockets ready to be read + /// + //////////////////////////////////////////////////////////// + unsigned int Wait(float Timeout = 0.f); + + //////////////////////////////////////////////////////////// + /// After a call to Wait(), get the Index-th socket which is + /// ready for reading. The total number of sockets ready + /// is the integer returned by the previous call to Wait() + /// + /// \param Index : Index of the socket to get + /// + /// \return The Index-th socket + /// + //////////////////////////////////////////////////////////// + Type GetSocketReady(unsigned int Index); + +private : + + //////////////////////////////////////////////////////////// + // Types + //////////////////////////////////////////////////////////// + typedef std::map SocketTable; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + SocketTable mySockets; ///< Table matching the SFML socket instances with their low-level handles +}; + +#include + +// Let's define the two only valid types of Selector +typedef Selector SelectorUDP; +typedef Selector SelectorTCP; + +} // namespace sf + + +#endif // SFML_SELECTOR_HPP diff --git a/SFML-1.6/include/SFML/Network/Selector.inl b/SFML-1.6/include/SFML/Network/Selector.inl new file mode 100644 index 000000000..40ac948af --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Selector.inl @@ -0,0 +1,97 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Add a socket to watch +//////////////////////////////////////////////////////////// +template +void Selector::Add(Type Socket) +{ + if (Socket.IsValid()) + { + SelectorBase::Add(Socket.mySocket); + mySockets[Socket.mySocket] = Socket; + } +} + + +//////////////////////////////////////////////////////////// +/// Remove a socket +//////////////////////////////////////////////////////////// +template +void Selector::Remove(Type Socket) +{ + typename SocketTable::iterator It = mySockets.find(Socket.mySocket); + if (It != mySockets.end()) + { + SelectorBase::Remove(Socket.mySocket); + mySockets.erase(It); + } +} + + +//////////////////////////////////////////////////////////// +/// Remove all sockets +//////////////////////////////////////////////////////////// +template +void Selector::Clear() +{ + SelectorBase::Clear(); + mySockets.clear(); +} + + +//////////////////////////////////////////////////////////// +/// Wait and collect sockets which are ready for reading. +/// This functions will return either when at least one socket +/// is ready, or when the given time is out +//////////////////////////////////////////////////////////// +template +unsigned int Selector::Wait(float Timeout) +{ + // No socket in the selector : return 0 + if (mySockets.empty()) + return 0; + + return SelectorBase::Wait(Timeout); +} + + +//////////////////////////////////////////////////////////// +/// After a call to Wait(), get the Index-th socket which is +/// ready for reading. The total number of sockets ready +/// is the integer returned by the previous call to Wait() +//////////////////////////////////////////////////////////// +template +Type Selector::GetSocketReady(unsigned int Index) +{ + SocketHelper::SocketType Socket = SelectorBase::GetSocketReady(Index); + + typename SocketTable::const_iterator It = mySockets.find(Socket); + if (It != mySockets.end()) + return It->second; + else + return Type(Socket); +} diff --git a/SFML-1.6/include/SFML/Network/SelectorBase.hpp b/SFML-1.6/include/SFML/Network/SelectorBase.hpp new file mode 100644 index 000000000..4b9e9157a --- /dev/null +++ b/SFML-1.6/include/SFML/Network/SelectorBase.hpp @@ -0,0 +1,112 @@ +//////////////////////////////////////////////////////////// +// +// 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_SELECTORBASE_HPP +#define SFML_SELECTORBASE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Private base class for selectors. +/// As Selector is a template class, this base is needed so that +/// every system call get compiled in SFML (not inlined) +//////////////////////////////////////////////////////////// +class SFML_API SelectorBase +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + SelectorBase(); + + //////////////////////////////////////////////////////////// + /// Add a socket to watch + /// + /// \param Socket : Socket to add + /// + //////////////////////////////////////////////////////////// + void Add(SocketHelper::SocketType Socket); + + //////////////////////////////////////////////////////////// + /// Remove a socket + /// + /// \param Socket : Socket to remove + /// + //////////////////////////////////////////////////////////// + void Remove(SocketHelper::SocketType Socket); + + //////////////////////////////////////////////////////////// + /// Remove all sockets + /// + //////////////////////////////////////////////////////////// + void Clear(); + + //////////////////////////////////////////////////////////// + /// Wait and collect sockets which are ready for reading. + /// This functions will return either when at least one socket + /// is ready, or when the given time is out + /// + /// \param Timeout : Timeout, in seconds (0 by default : no timeout) + /// + /// \return Number of sockets ready to be read + /// + //////////////////////////////////////////////////////////// + unsigned int Wait(float Timeout = 0.f); + + //////////////////////////////////////////////////////////// + /// After a call to Wait(), get the Index-th socket which is + /// ready for reading. The total number of sockets ready + /// is the integer returned by the previous call to Wait() + /// + /// \param Index : Index of the socket to get + /// + /// \return The Index-th socket + /// + //////////////////////////////////////////////////////////// + SocketHelper::SocketType GetSocketReady(unsigned int Index); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + fd_set mySet; ///< Set of socket to watch + fd_set mySetReady; ///< Set of socket which are ready for reading + int myMaxSocket; ///< Maximum socket index +}; + +} // namespace sf + + +#endif // SFML_SELECTORBASE_HPP diff --git a/SFML-1.6/include/SFML/Network/SocketHelper.hpp b/SFML-1.6/include/SFML/Network/SocketHelper.hpp new file mode 100644 index 000000000..166ce6074 --- /dev/null +++ b/SFML-1.6/include/SFML/Network/SocketHelper.hpp @@ -0,0 +1,64 @@ +//////////////////////////////////////////////////////////// +// +// 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_SOCKETHELPER_HPP +#define SFML_SOCKETHELPER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +namespace Socket +{ + //////////////////////////////////////////////////////////// + /// Enumeration of status returned by socket functions + //////////////////////////////////////////////////////////// + enum Status + { + Done, ///< The socket has sent / received the data + NotReady, ///< The socket is not ready to send / receive data yet + Disconnected, ///< The TCP socket has been disconnected + Error ///< An unexpected error happened + }; +} + +} // namespace sf + + +#ifdef SFML_SYSTEM_WINDOWS + + #include + +#else + + #include + +#endif + + +#endif // SFML_SOCKETHELPER_HPP diff --git a/SFML-1.6/include/SFML/Network/SocketTCP.hpp b/SFML-1.6/include/SFML/Network/SocketTCP.hpp new file mode 100644 index 000000000..8929dc959 --- /dev/null +++ b/SFML-1.6/include/SFML/Network/SocketTCP.hpp @@ -0,0 +1,227 @@ +//////////////////////////////////////////////////////////// +// +// 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_SOCKETTCP_HPP +#define SFML_SOCKETTCP_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +class Packet; +class IPAddress; +template class Selector; + +//////////////////////////////////////////////////////////// +/// SocketTCP wraps a socket using TCP protocol to +/// send data safely (but a bit slower) +//////////////////////////////////////////////////////////// +class SFML_API SocketTCP +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + SocketTCP(); + + //////////////////////////////////////////////////////////// + /// Change the blocking state of the socket. + /// The default behaviour of a socket is blocking + /// + /// \param Blocking : Pass true to set the socket as blocking, or false for non-blocking + /// + //////////////////////////////////////////////////////////// + void SetBlocking(bool Blocking); + + //////////////////////////////////////////////////////////// + /// Connect to another computer on a specified port + /// + /// \param Port : Port to use for transfers (warning : ports < 1024 are reserved) + /// \param HostAddress : IP Address of the host to connect to + /// \param Timeout : Maximum time to wait, in seconds (0 by default : no timeout) (this parameter is ignored for non-blocking sockets) + /// + /// \return True if operation has been successful + /// + //////////////////////////////////////////////////////////// + Socket::Status Connect(unsigned short Port, const IPAddress& HostAddress, float Timeout = 0.f); + + //////////////////////////////////////////////////////////// + /// Listen to a specified port for incoming data or connections + /// + /// \param Port : Port to listen to + /// + /// \return True if operation has been successful + /// + //////////////////////////////////////////////////////////// + bool Listen(unsigned short Port); + + //////////////////////////////////////////////////////////// + /// Wait for a connection (must be listening to a port). + /// This function will block if the socket is blocking + /// + /// \param Connected : Socket containing the connection with the connected client + /// \param Address : Pointer to an address to fill with client infos (NULL by default) + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Accept(SocketTCP& Connected, IPAddress* Address = NULL); + + //////////////////////////////////////////////////////////// + /// Send an array of bytes to the host (must be connected first) + /// + /// \param Data : Pointer to the bytes to send + /// \param Size : Number of bytes to send + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Send(const char* Data, std::size_t Size); + + //////////////////////////////////////////////////////////// + /// Receive an array of bytes from the host (must be connected first). + /// This function will block if the socket is blocking + /// + /// \param Data : Pointer to a byte array to fill (make sure it is big enough) + /// \param MaxSize : Maximum number of bytes to read + /// \param SizeReceived : Number of bytes received + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived); + + //////////////////////////////////////////////////////////// + /// Send a packet of data to the host (must be connected first) + /// + /// \param PacketToSend : Packet to send + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Send(Packet& PacketToSend); + + //////////////////////////////////////////////////////////// + /// Receive a packet from the host (must be connected first). + /// This function will block if the socket is blocking + /// + /// \param PacketToReceive : Packet to fill with received data + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Receive(Packet& PacketToReceive); + + //////////////////////////////////////////////////////////// + /// Close the socket + /// + /// \return True if operation has been successful + /// + //////////////////////////////////////////////////////////// + bool Close(); + + //////////////////////////////////////////////////////////// + /// Check if the socket is in a valid state ; this function + /// can be called any time to check if the socket is OK + /// + /// \return True if the socket is valid + /// + //////////////////////////////////////////////////////////// + bool IsValid() const; + + //////////////////////////////////////////////////////////// + /// Comparison operator == + /// + /// \param Other : Socket to compare + /// + /// \return True if *this == Other + /// + //////////////////////////////////////////////////////////// + bool operator ==(const SocketTCP& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator != + /// + /// \param Other : Socket to compare + /// + /// \return True if *this != Other + /// + //////////////////////////////////////////////////////////// + bool operator !=(const SocketTCP& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator <. + /// Provided for compatibility with standard containers, as + /// comparing two sockets doesn't make much sense... + /// + /// \param Other : Socket to compare + /// + /// \return True if *this < Other + /// + //////////////////////////////////////////////////////////// + bool operator <(const SocketTCP& Other) const; + +private : + + friend class Selector; + + //////////////////////////////////////////////////////////// + /// Construct the socket from a socket descriptor + /// (for internal use only) + /// + /// \param Descriptor : Socket descriptor + /// + //////////////////////////////////////////////////////////// + SocketTCP(SocketHelper::SocketType Descriptor); + + //////////////////////////////////////////////////////////// + /// Create the socket + /// + /// \param Descriptor : System socket descriptor to use (0 by default -- create a new socket) + /// + //////////////////////////////////////////////////////////// + void Create(SocketHelper::SocketType Descriptor = 0); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + SocketHelper::SocketType mySocket; ///< Socket descriptor + Uint32 myPendingHeader; ///< Data of the current pending packet header, if any + Uint32 myPendingHeaderSize; ///< Size of the current pending packet header, if any + std::vector myPendingPacket; ///< Data of the current pending packet, if any + Int32 myPendingPacketSize; ///< Size of the current pending packet, if any + bool myIsBlocking; ///< Is the socket blocking or non-blocking ? +}; + +} // namespace sf + + +#endif // SFML_SOCKETTCP_HPP diff --git a/SFML-1.6/include/SFML/Network/SocketUDP.hpp b/SFML-1.6/include/SFML/Network/SocketUDP.hpp new file mode 100644 index 000000000..7cb6b19d3 --- /dev/null +++ b/SFML-1.6/include/SFML/Network/SocketUDP.hpp @@ -0,0 +1,228 @@ +//////////////////////////////////////////////////////////// +// +// 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_SOCKETUDP_HPP +#define SFML_SOCKETUDP_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +class Packet; +class IPAddress; +template class Selector; + +//////////////////////////////////////////////////////////// +/// SocketUDP wraps a socket using UDP protocol to +/// send data fastly (but with less safety) +//////////////////////////////////////////////////////////// +class SFML_API SocketUDP +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + SocketUDP(); + + //////////////////////////////////////////////////////////// + /// Change the blocking state of the socket. + /// The default behaviour of a socket is blocking + /// + /// \param Blocking : Pass true to set the socket as blocking, or false for non-blocking + /// + //////////////////////////////////////////////////////////// + void SetBlocking(bool Blocking); + + //////////////////////////////////////////////////////////// + /// Bind the socket to a specific port + /// + /// \param Port : Port to bind the socket to + /// + /// \return True if operation has been successful + /// + //////////////////////////////////////////////////////////// + bool Bind(unsigned short Port); + + //////////////////////////////////////////////////////////// + /// Unbind the socket from its previous port, if any + /// + /// \return True if operation has been successful + /// + //////////////////////////////////////////////////////////// + bool Unbind(); + + //////////////////////////////////////////////////////////// + /// Send an array of bytes + /// + /// \param Data : Pointer to the bytes to send + /// \param Size : Number of bytes to send + /// \param Address : Address of the computer to send the packet to + /// \param Port : Port to send the data to + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Send(const char* Data, std::size_t Size, const IPAddress& Address, unsigned short Port); + + //////////////////////////////////////////////////////////// + /// Receive an array of bytes. + /// This function will block if the socket is blocking + /// + /// \param Data : Pointer to a byte array to fill (make sure it is big enough) + /// \param MaxSize : Maximum number of bytes to read + /// \param SizeReceived : Number of bytes received + /// \param Address : Address of the computer which sent the data + /// \param Port : Port on which the remote computer sent the data + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Receive(char* Data, std::size_t MaxSize, std::size_t& SizeReceived, IPAddress& Address, unsigned short& Port); + + //////////////////////////////////////////////////////////// + /// Send a packet of data + /// + /// \param PacketToSend : Packet to send + /// \param Address : Address of the computer to send the packet to + /// \param Port : Port to send the data to + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Send(Packet& PacketToSend, const IPAddress& Address, unsigned short Port); + + //////////////////////////////////////////////////////////// + /// Receive a packet. + /// This function will block if the socket is blocking + /// + /// \param PacketToReceive : Packet to fill with received data + /// \param Address : Address of the computer which sent the packet + /// \param Port : Port on which the remote computer sent the data + /// + /// \return Status code + /// + //////////////////////////////////////////////////////////// + Socket::Status Receive(Packet& PacketToReceive, IPAddress& Address, unsigned short& Port); + + //////////////////////////////////////////////////////////// + /// Close the socket + /// + /// \return True if operation has been successful + /// + //////////////////////////////////////////////////////////// + bool Close(); + + //////////////////////////////////////////////////////////// + /// Check if the socket is in a valid state ; this function + /// can be called any time to check if the socket is OK + /// + /// \return True if the socket is valid + /// + //////////////////////////////////////////////////////////// + bool IsValid() const; + + //////////////////////////////////////////////////////////// + /// Get the port the socket is currently bound to + /// + /// \return Current port (0 means the socket is not bound) + /// + //////////////////////////////////////////////////////////// + unsigned short GetPort() const; + + //////////////////////////////////////////////////////////// + /// Comparison operator == + /// + /// \param Other : Socket to compare + /// + /// \return True if *this == Other + /// + //////////////////////////////////////////////////////////// + bool operator ==(const SocketUDP& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator != + /// + /// \param Other : Socket to compare + /// + /// \return True if *this != Other + /// + //////////////////////////////////////////////////////////// + bool operator !=(const SocketUDP& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator <. + /// Provided for compatibility with standard containers, as + /// comparing two sockets doesn't make much sense... + /// + /// \param Other : Socket to compare + /// + /// \return True if *this < Other + /// + //////////////////////////////////////////////////////////// + bool operator <(const SocketUDP& Other) const; + +private : + + friend class Selector; + + //////////////////////////////////////////////////////////// + /// Construct the socket from a socket descriptor + /// (for internal use only) + /// + /// \param Descriptor : Socket descriptor + /// + //////////////////////////////////////////////////////////// + SocketUDP(SocketHelper::SocketType Descriptor); + + //////////////////////////////////////////////////////////// + /// Create the socket + /// + /// \param Descriptor : System socket descriptor to use (0 by default -- create a new socket) + /// + //////////////////////////////////////////////////////////// + void Create(SocketHelper::SocketType Descriptor = 0); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + SocketHelper::SocketType mySocket; ///< Socket identifier + unsigned short myPort; ///< Port to which the socket is bound + Uint32 myPendingHeader; ///< Data of the current pending packet header, if any + Uint32 myPendingHeaderSize; ///< Size of the current pending packet header, if any + std::vector myPendingPacket; ///< Data of the current pending packet, if any + Int32 myPendingPacketSize; ///< Size of the current pending packet, if any + bool myIsBlocking; ///< Is the socket blocking or non-blocking ? +}; + +} // namespace sf + + +#endif // SFML_SOCKETUDP_HPP diff --git a/SFML-1.6/include/SFML/Network/Sockets.hpp b/SFML-1.6/include/SFML/Network/Sockets.hpp new file mode 100644 index 000000000..1359cb973 --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Sockets.hpp @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SOCKETS_HPP +#define SFML_SOCKETS_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +#ifdef SFML_SYSTEM_WINDOWS + + #include + +#else + + #include + +#endif + + +#endif // SFML_SOCKETS_HPP diff --git a/SFML-1.6/include/SFML/Network/Unix/SocketHelper.hpp b/SFML-1.6/include/SFML/Network/Unix/SocketHelper.hpp new file mode 100644 index 000000000..1068cd853 --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Unix/SocketHelper.hpp @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SOCKETHELPERUNIX_HPP +#define SFML_SOCKETHELPERUNIX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// This class defines helper functions to do all the +/// non-portable socket stuff. This class is meant for internal +/// use only +//////////////////////////////////////////////////////////// +class SFML_API SocketHelper +{ +public : + + //////////////////////////////////////////////////////////// + // Define some socket types + //////////////////////////////////////////////////////////// + typedef int SocketType; + typedef socklen_t LengthType; + + //////////////////////////////////////////////////////////// + /// Return the value of the invalid socket + /// + /// \return Unique value of the invalid socket + /// + //////////////////////////////////////////////////////////// + static SocketType InvalidSocket(); + + //////////////////////////////////////////////////////////// + /// Close / destroy a socket + /// + /// \param Socket : Socket to close + /// + /// \return True on success + /// + //////////////////////////////////////////////////////////// + static bool Close(SocketType Socket); + + //////////////////////////////////////////////////////////// + /// Set a socket as blocking or non-blocking + /// + /// \param Socket : Socket to modify + /// \param Block : New blocking state of the socket + /// + //////////////////////////////////////////////////////////// + static void SetBlocking(SocketType Socket, bool Block); + + //////////////////////////////////////////////////////////// + /// Get the last socket error status + /// + /// \return Status corresponding to the last socket error + /// + //////////////////////////////////////////////////////////// + static Socket::Status GetErrorStatus(); +}; + +} // namespace sf + + +#endif // SFML_SOCKETHELPERUNIX_HPP diff --git a/SFML-1.6/include/SFML/Network/Win32/SocketHelper.hpp b/SFML-1.6/include/SFML/Network/Win32/SocketHelper.hpp new file mode 100644 index 000000000..6199c0a2c --- /dev/null +++ b/SFML-1.6/include/SFML/Network/Win32/SocketHelper.hpp @@ -0,0 +1,90 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SOCKETHELPERWIN32_HPP +#define SFML_SOCKETHELPERWIN32_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// This class defines helper functions to do all the +/// non-portable socket stuff. This class is meant for internal +/// use only +//////////////////////////////////////////////////////////// +class SFML_API SocketHelper +{ +public : + + //////////////////////////////////////////////////////////// + // Define some socket types + //////////////////////////////////////////////////////////// + typedef SOCKET SocketType; + typedef int LengthType; + + //////////////////////////////////////////////////////////// + /// Return the value of the invalid socket + /// + /// \return Unique value of the invalid socket + /// + //////////////////////////////////////////////////////////// + static SocketType InvalidSocket(); + + //////////////////////////////////////////////////////////// + /// Close / destroy a socket + /// + /// \param Socket : Socket to close + /// + /// \return True on success + /// + //////////////////////////////////////////////////////////// + static bool Close(SocketType Socket); + + //////////////////////////////////////////////////////////// + /// Set a socket as blocking or non-blocking + /// + /// \param Socket : Socket to modify + /// \param Block : New blocking state of the socket + /// + //////////////////////////////////////////////////////////// + static void SetBlocking(SocketType Socket, bool Block); + + //////////////////////////////////////////////////////////// + /// Get the last socket error status + /// + /// \return Status corresponding to the last socket error + /// + //////////////////////////////////////////////////////////// + static Socket::Status GetErrorStatus(); +}; + +} // namespace sf + + +#endif // SFML_SOCKETHELPERWIN32_HPP diff --git a/SFML-1.6/include/SFML/System/Clock.hpp b/SFML-1.6/include/SFML/System/Clock.hpp new file mode 100644 index 000000000..76c005508 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Clock.hpp @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////// +// +// 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_CLOCK_HPP +#define SFML_CLOCK_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Clock is an utility class for manipulating time +//////////////////////////////////////////////////////////// +class SFML_API Clock +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Clock(); + + //////////////////////////////////////////////////////////// + /// Get the time elapsed since last reset + /// + /// \return Time elapsed, in seconds + /// + //////////////////////////////////////////////////////////// + float GetElapsedTime() const; + + //////////////////////////////////////////////////////////// + /// Restart the timer + /// + //////////////////////////////////////////////////////////// + void Reset(); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + double myStartTime; ///< Time of last reset +}; + +} // namespace sf + + +#endif // SFML_CLOCK_HPP diff --git a/SFML-1.6/include/SFML/System/Lock.hpp b/SFML-1.6/include/SFML/System/Lock.hpp new file mode 100644 index 000000000..6f84f7349 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Lock.hpp @@ -0,0 +1,71 @@ +//////////////////////////////////////////////////////////// +// +// 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_LOCK_HPP +#define SFML_LOCK_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +class Mutex; + +//////////////////////////////////////////////////////////// +/// Lock is an exception-safe automatic wrapper for +/// locking and unlocking mutexes +//////////////////////////////////////////////////////////// +class SFML_API Lock : NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// Construct the lock with a target mutex (lock it) + /// + /// @param Mutex : Mutex to lock + /// + //////////////////////////////////////////////////////////// + Lock(Mutex& Mutex); + + //////////////////////////////////////////////////////////// + /// Destructor (unlocks the mutex) + /// + //////////////////////////////////////////////////////////// + ~Lock(); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + Mutex& myMutex; ///< Mutex to lock / unlock +}; + +} // namespace sf + + +#endif // SFML_LOCK_HPP diff --git a/SFML-1.6/include/SFML/System/Mutex.hpp b/SFML-1.6/include/SFML/System/Mutex.hpp new file mode 100644 index 000000000..536c5371e --- /dev/null +++ b/SFML-1.6/include/SFML/System/Mutex.hpp @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_MUTEX_HPP +#define SFML_MUTEX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +#ifdef SFML_SYSTEM_WINDOWS + + #include + +#else + + #include + +#endif + + +#endif // SFML_MUTEX_HPP diff --git a/SFML-1.6/include/SFML/System/NonCopyable.hpp b/SFML-1.6/include/SFML/System/NonCopyable.hpp new file mode 100644 index 000000000..3ac6719fc --- /dev/null +++ b/SFML-1.6/include/SFML/System/NonCopyable.hpp @@ -0,0 +1,70 @@ +//////////////////////////////////////////////////////////// +// +// 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_NONCOPYABLE_HPP +#define SFML_NONCOPYABLE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Utility base class to easily declare non-copyable classes. +/// Just inherit from NonCopyable to get a non-copyable class +//////////////////////////////////////////////////////////// +struct SFML_API NonCopyable +{ +protected : + + //////////////////////////////////////////////////////////// + /// The default constructor won't be generated, so provide it + /// + //////////////////////////////////////////////////////////// + NonCopyable() {} + +private : + + //////////////////////////////////////////////////////////// + /// Copy constructor : declare it private and don't implement + /// it to prevent from calling it + /// + //////////////////////////////////////////////////////////// + NonCopyable(const NonCopyable&); + + //////////////////////////////////////////////////////////// + /// Assignment operator : declare it private and don't implement + /// it to prevent from calling it + /// + //////////////////////////////////////////////////////////// + NonCopyable& operator =(const NonCopyable&); +}; + +} // namespace sf + + +#endif // SFML_NONCOPYABLE_HPP diff --git a/SFML-1.6/include/SFML/System/Randomizer.hpp b/SFML-1.6/include/SFML/System/Randomizer.hpp new file mode 100644 index 000000000..8ed27cdee --- /dev/null +++ b/SFML-1.6/include/SFML/System/Randomizer.hpp @@ -0,0 +1,94 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_RANDOMIZER_HPP +#define SFML_RANDOMIZER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Randomizer is an utility class for generating pseudo-random +/// numbers +//////////////////////////////////////////////////////////// +class SFML_API Randomizer +{ +public : + + //////////////////////////////////////////////////////////// + /// Set the seed for the generator. Using a known seed + /// allows you to reproduce the same sequence of random number + /// + /// \param Seed : Number to use as the seed + /// + //////////////////////////////////////////////////////////// + static void SetSeed(unsigned int Seed); + + //////////////////////////////////////////////////////////// + /// Get the seed used to generate random numbers the generator. + /// + /// \return Current seed + /// + //////////////////////////////////////////////////////////// + static unsigned int GetSeed(); + + //////////////////////////////////////////////////////////// + /// Get a random float number in a given range + /// + /// \return Start : Start of the range + /// \return End : End of the range + /// + /// \return Random number in [Begin, End] + /// + //////////////////////////////////////////////////////////// + static float Random(float Begin, float End); + + //////////////////////////////////////////////////////////// + /// Get a random integer number in a given range + /// + /// \return Start : Start of the range + /// \return End : End of the range + /// + /// \return Random number in [Begin, End] + /// + //////////////////////////////////////////////////////////// + static int Random(int Begin, int End); + +private : + + //////////////////////////////////////////////////////////// + // Static member variables + //////////////////////////////////////////////////////////// + static unsigned int ourSeed; +}; + +} // namespace sf + + +#endif // SFML_RANDOMIZER_HPP diff --git a/SFML-1.6/include/SFML/System/Resource.hpp b/SFML-1.6/include/SFML/System/Resource.hpp new file mode 100644 index 000000000..8f5088dc5 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Resource.hpp @@ -0,0 +1,216 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_RESOURCE_HPP +#define SFML_RESOURCE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +// These two classes are defined in the same header because +// they depend on each other. And as they're template classes, +// they must be entirely defined in header files, which +// prevents from proper separate compiling +//////////////////////////////////////////////////////////// + +template class ResourcePtr; + +//////////////////////////////////////////////////////////// +/// Base class for every resource that needs to notify +/// dependent classes about its destruction +//////////////////////////////////////////////////////////// +template +class Resource +{ +protected : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Resource(); + + //////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param Copy : Resource to copy + /// + //////////////////////////////////////////////////////////// + Resource(const Resource& Copy); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~Resource(); + + //////////////////////////////////////////////////////////// + /// Assignment operator + /// + /// \param Other : Resource to copy + /// + /// \return Reference to this + /// + //////////////////////////////////////////////////////////// + Resource& operator =(const Resource& Other); + +private : + + friend class ResourcePtr; + + //////////////////////////////////////////////////////////// + /// Connect a ResourcePtr to this resource + /// + /// \param Observer : Observer to add + /// + //////////////////////////////////////////////////////////// + void Connect(ResourcePtr& Observer) const; + + //////////////////////////////////////////////////////////// + /// Disconnect a ResourcePtr from this resource + /// + /// \param Observer : Observer to remove + /// + //////////////////////////////////////////////////////////// + void Disconnect(ResourcePtr& Observer) const; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + mutable std::set*> myObservers; +}; + + +//////////////////////////////////////////////////////////// +/// Safe pointer to a T resource (inheriting from sf::Resource), +/// its pointer is automatically reseted when the resource is destroyed +//////////////////////////////////////////////////////////// +template +class ResourcePtr +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + ResourcePtr(); + + //////////////////////////////////////////////////////////// + /// Construct from a raw resource + /// + /// \param Resource : Internal resource + /// + //////////////////////////////////////////////////////////// + ResourcePtr(const T* Resource); + + //////////////////////////////////////////////////////////// + /// Copy constructor + /// + /// \param Copy : Instance to copy + /// + //////////////////////////////////////////////////////////// + ResourcePtr(const ResourcePtr& Copy); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~ResourcePtr(); + + //////////////////////////////////////////////////////////// + /// Assignment operator from another ResourcePtr + /// + /// \param Other : Resource pointer to assign + /// + /// \return Reference to this + /// + //////////////////////////////////////////////////////////// + ResourcePtr& operator =(const ResourcePtr& Other); + + //////////////////////////////////////////////////////////// + /// Assignment operator from a raw resource + /// + /// \param Resource : Resource to assign + /// + /// \return Reference to this + /// + //////////////////////////////////////////////////////////// + ResourcePtr& operator =(const T* Resource); + + //////////////////////////////////////////////////////////// + /// Cast operator to implicitely convert the resource pointer to + /// its raw pointer type. + /// This might be dangerous in the general case, but in this context + /// it is safe enough to define this operator + /// + /// \return Pointer to the actual resource + /// + //////////////////////////////////////////////////////////// + operator const T*() const; + + //////////////////////////////////////////////////////////// + /// Operator * overload to return a reference to the actual resource + /// + /// \return Reference to the internal resource + /// + //////////////////////////////////////////////////////////// + const T& operator *() const; + + //////////////////////////////////////////////////////////// + /// Operator -> overload to return a pointer to the actual resource + /// + /// \return Pointer to the internal resource + /// + //////////////////////////////////////////////////////////// + const T* operator ->() const; + + //////////////////////////////////////////////////////////// + /// Function called when the observed resource is about to be + /// destroyed + /// + //////////////////////////////////////////////////////////// + void OnResourceDestroyed(); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + const T* myResource; /// Pointer to the actual resource +}; + +#include +#include + +} // namespace sf + + +#endif // SFML_RESOURCE_HPP diff --git a/SFML-1.6/include/SFML/System/Resource.inl b/SFML-1.6/include/SFML/System/Resource.inl new file mode 100644 index 000000000..c4276a191 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Resource.inl @@ -0,0 +1,88 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Default constructor +//////////////////////////////////////////////////////////// +template +Resource::Resource() +{ + // Nothing to do +} + + +//////////////////////////////////////////////////////////// +/// Copy constructor +//////////////////////////////////////////////////////////// +template +Resource::Resource(const Resource&) +{ + // Nothing to do, we don't want to copy observers +} + + +//////////////////////////////////////////////////////////// +/// Destructor +//////////////////////////////////////////////////////////// +template +Resource::~Resource() +{ + // Notify all observers + for (typename std::set*>::iterator i = myObservers.begin(); i != myObservers.end(); ++i) + { + (*i)->OnResourceDestroyed(); + } +} + + +//////////////////////////////////////////////////////////// +/// Assignment operator +//////////////////////////////////////////////////////////// +template +Resource& Resource::operator =(const Resource&) +{ + // Nothing to do, we don't want to copy observers + return *this; +} + + +//////////////////////////////////////////////////////////// +/// Connect a ResourcePtr to this resource +//////////////////////////////////////////////////////////// +template +void Resource::Connect(ResourcePtr& Observer) const +{ + myObservers.insert(&Observer); +} + + +//////////////////////////////////////////////////////////// +/// Disconnect a ResourcePtr from this resource +//////////////////////////////////////////////////////////// +template +void Resource::Disconnect(ResourcePtr& Observer) const +{ + myObservers.erase(&Observer); +} diff --git a/SFML-1.6/include/SFML/System/ResourcePtr.inl b/SFML-1.6/include/SFML/System/ResourcePtr.inl new file mode 100644 index 000000000..dbfcd0d76 --- /dev/null +++ b/SFML-1.6/include/SFML/System/ResourcePtr.inl @@ -0,0 +1,149 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Default constructor +//////////////////////////////////////////////////////////// +template +ResourcePtr::ResourcePtr() : +myResource(NULL) +{ + +} + + +//////////////////////////////////////////////////////////// +/// Construct from a raw resource +//////////////////////////////////////////////////////////// +template +ResourcePtr::ResourcePtr(const T* Resource) : +myResource(Resource) +{ + if (myResource) + myResource->Connect(*this); +} + + +//////////////////////////////////////////////////////////// +/// Copy constructor +//////////////////////////////////////////////////////////// +template +ResourcePtr::ResourcePtr(const ResourcePtr& Copy) : +myResource(Copy.myResource) +{ + if (myResource) + myResource->Connect(*this); +} + + +//////////////////////////////////////////////////////////// +/// Destructor +//////////////////////////////////////////////////////////// +template +ResourcePtr::~ResourcePtr() +{ + if (myResource) + myResource->Disconnect(*this); +} + + +//////////////////////////////////////////////////////////// +/// Assignment operator from another ResourcePtr +//////////////////////////////////////////////////////////// +template +ResourcePtr& ResourcePtr::operator =(const ResourcePtr& Other) +{ + if (myResource) + myResource->Disconnect(*this); + + myResource = Other.myResource; + + if (myResource) + myResource->Connect(*this); + + return *this; +} + + +//////////////////////////////////////////////////////////// +/// Assignment operator from a raw resource +//////////////////////////////////////////////////////////// +template +ResourcePtr& ResourcePtr::operator =(const T* Resource) +{ + if (myResource) + myResource->Disconnect(*this); + + myResource = Resource; + + if (myResource) + myResource->Connect(*this); + + return *this; +} + + +//////////////////////////////////////////////////////////// +/// Cast operator to implicitely convert the resource pointer to +/// its raw pointer type. +/// This might be dangerous in the general case, but in this context +/// it is safe enough to define this operator +//////////////////////////////////////////////////////////// +template +ResourcePtr::operator const T*() const +{ + return myResource; +} + + +//////////////////////////////////////////////////////////// +/// Operator * overload to return a reference to the actual resource +//////////////////////////////////////////////////////////// +template +const T& ResourcePtr::operator *() const +{ + return *myResource; +} + + +//////////////////////////////////////////////////////////// +/// Operator -> overload to return a pointer to the actual resource +//////////////////////////////////////////////////////////// +template +const T* ResourcePtr::operator ->() const +{ + return myResource; +} + + +//////////////////////////////////////////////////////////// +/// Function called when the observed resource is about to be +/// destroyed +//////////////////////////////////////////////////////////// +template +void ResourcePtr::OnResourceDestroyed() +{ + myResource = NULL; +} diff --git a/SFML-1.6/include/SFML/System/Sleep.hpp b/SFML-1.6/include/SFML/System/Sleep.hpp new file mode 100644 index 000000000..2d0ebcaf3 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Sleep.hpp @@ -0,0 +1,47 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_SLEEP_HPP +#define SFML_SLEEP_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ + //////////////////////////////////////////////////////////// + /// Make the current thread sleep for a given time + /// + /// \param Duration : Time to sleep, in seconds (must be >= 0) + /// + //////////////////////////////////////////////////////////// + void SFML_API Sleep(float Duration); + +} // namespace sf + + +#endif // SFML_SLEEP_HPP diff --git a/SFML-1.6/include/SFML/System/Thread.hpp b/SFML-1.6/include/SFML/System/Thread.hpp new file mode 100644 index 000000000..1cfe1e60f --- /dev/null +++ b/SFML-1.6/include/SFML/System/Thread.hpp @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_THREAD_HPP +#define SFML_THREAD_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +#ifdef SFML_SYSTEM_WINDOWS + + #include + +#else + + #include + +#endif + + +#endif // SFML_THREAD_HPP diff --git a/SFML-1.6/include/SFML/System/Unicode.hpp b/SFML-1.6/include/SFML/System/Unicode.hpp new file mode 100644 index 000000000..f807fb36a --- /dev/null +++ b/SFML-1.6/include/SFML/System/Unicode.hpp @@ -0,0 +1,290 @@ +//////////////////////////////////////////////////////////// +// +// 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_UNICODE_HPP +#define SFML_UNICODE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Provides utility functions to convert from and to +/// any unicode and ASCII encoding +//////////////////////////////////////////////////////////// +class SFML_API Unicode +{ +public : + + //////////////////////////////////////////////////////////// + /// Define a string type for each encoding + /// Warning : in UTF8 and UTF16 strings, one element doesn't + /// necessarily maps to one character ; only an UTF32 element + /// is wide enough to hold all possible unicode values + //////////////////////////////////////////////////////////// + typedef std::basic_string UTF8String; + typedef std::basic_string UTF16String; + typedef std::basic_string UTF32String; + + //////////////////////////////////////////////////////////// + /// This class is an abstract definition of a unicode text, + /// it can be converted from and to any kind of string + /// and encoding + //////////////////////////////////////////////////////////// + class SFML_API Text + { + public : + + //////////////////////////////////////////////////////////// + /// Default constructor (empty text) + /// + //////////////////////////////////////////////////////////// + Text(); + + //////////////////////////////////////////////////////////// + /// Construct the unicode text from any type of string + /// + /// \param Str : String to convert + /// + //////////////////////////////////////////////////////////// + Text(const char* Str); + Text(const wchar_t* Str); + Text(const Uint8* Str); + Text(const Uint16* Str); + Text(const Uint32* Str); + Text(const std::string& Str); + Text(const std::wstring& Str); + Text(const Unicode::UTF8String& Str); + Text(const Unicode::UTF16String& Str); + Text(const Unicode::UTF32String& Str); + + //////////////////////////////////////////////////////////// + /// Operator to cast the text to any type of string + /// + /// \return Converted string + /// + //////////////////////////////////////////////////////////// + operator std::string () const; + operator std::wstring () const; + operator Unicode::UTF8String () const; + operator Unicode::UTF16String () const; + operator const Unicode::UTF32String&() const; + + private : + + //////////////////////////////////////////////////////////// + // Data member + //////////////////////////////////////////////////////////// + sf::Unicode::UTF32String myUTF32String; ///< UTF-32 unicode text + }; + + //////////////////////////////////////////////////////////// + /// Generic function to convert an UTF-32 characters range + /// to an ANSI characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character) + /// \param Locale : Locale to use for conversion (uses the current one by default) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out UTF32ToANSI(In Begin, In End, Out Output, char Replacement = '?', const std::locale& Locale = GetDefaultLocale()); + + //////////////////////////////////////////////////////////// + /// Generic function to convert an ANSI characters range + /// to an UTF-32 characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Locale : Locale to use for conversion (uses the current one by default) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale = GetDefaultLocale()); + + //////////////////////////////////////////////////////////// + /// Generic function to convert an UTF-8 characters range + /// to an UTF-16 characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?'); + + //////////////////////////////////////////////////////////// + /// Generic function to convert an UTF-8 characters range + /// to an UTF-32 characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?'); + + //////////////////////////////////////////////////////////// + /// Generic function to convert an UTF-16 characters range + /// to an UTF-8 characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?'); + + //////////////////////////////////////////////////////////// + /// Generic function to convert an UTF-16 characters range + /// to an UTF-32 characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement = '?'); + + //////////////////////////////////////////////////////////// + /// Generic function to convert an UTF-32 characters range + /// to an UTF-8 characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement = '?'); + + //////////////////////////////////////////////////////////// + /// Generic function to convert an UTF-32 characters range + /// to an UTF-16 characters range, using the given locale + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// \param Output : Iterator pointing to the beginning of the output sequence + /// \param Replacement : Replacement character for characters not convertible to output encoding ('?' by default -- use 0 to use no replacement character) + /// + /// \return Iterator to the end of the output sequence which has been written + /// + //////////////////////////////////////////////////////////// + template + static Out UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement = '?'); + + //////////////////////////////////////////////////////////// + /// Get the number of characters composing an UTF-8 string + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// + /// \return Count of the characters in the string + /// + //////////////////////////////////////////////////////////// + template + static std::size_t GetUTF8Length(In Begin, In End); + + //////////////////////////////////////////////////////////// + /// Get the number of characters composing an UTF-16 string + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// + /// \return Count of the characters in the string + /// + //////////////////////////////////////////////////////////// + template + static std::size_t GetUTF16Length(In Begin, In End); + + //////////////////////////////////////////////////////////// + /// Get the number of characters composing an UTF-32 string + /// + /// \param Begin : Iterator pointing to the beginning of the input sequence + /// \param End : Iterator pointing to the end of the input sequence + /// + /// \return Count of the characters in the string + /// + //////////////////////////////////////////////////////////// + template + static std::size_t GetUTF32Length(In Begin, In End); + +private : + + //////////////////////////////////////////////////////////// + /// Get the default system locale + /// + /// \return Reference to the default system locale + /// + //////////////////////////////////////////////////////////// + static const std::locale& GetDefaultLocale(); + + //////////////////////////////////////////////////////////// + // Static member data + //////////////////////////////////////////////////////////// + static const int UTF8TrailingBytes[256]; ///< Lookup table to find the length of an UTF-8 sequence + static const Uint32 UTF8Offsets[6]; ///< Magic values to subtract during UTF-8 conversions + static const Uint8 UTF8FirstBytes[7]; ///< First bytes for UTF-8 sequences +}; + +#include + +} // namespace sf + + +#endif // SFML_UNICODE_HPP diff --git a/SFML-1.6/include/SFML/System/Unicode.inl b/SFML-1.6/include/SFML/System/Unicode.inl new file mode 100644 index 000000000..a16981103 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Unicode.inl @@ -0,0 +1,474 @@ +//////////////////////////////////////////////////////////// +// +// 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. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an UTF-32 characters range +/// to an ANSI characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::UTF32ToANSI(In Begin, In End, Out Output, char Replacement, const std::locale& Locale) +{ + #ifdef __MINGW32__ + + // MinGW has a almost no support for unicode stuff + // As a consequence, the MinGW version of this function can only use the default locale + // and ignores the one passed as parameter + while (Begin < End) + { + char Char = 0; + if (wctomb(&Char, static_cast(*Begin++)) >= 0) + *Output++ = Char; + else if (Replacement) + *Output++ = Replacement; + } + + #else + + // Get the facet of the locale which deals with character conversion + const std::ctype& Facet = std::use_facet< std::ctype >(Locale); + + // Use the facet to convert each character of the input string + while (Begin < End) + *Output++ = Facet.narrow(static_cast(*Begin++), Replacement); + + #endif + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an ANSI characters range +/// to an UTF-32 characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::ANSIToUTF32(In Begin, In End, Out Output, const std::locale& Locale) +{ + #ifdef __MINGW32__ + + // MinGW has a almost no support for unicode stuff + // As a consequence, the MinGW version of this function can only use the default locale + // and ignores the one passed as parameter + while (Begin < End) + { + wchar_t Char = 0; + mbtowc(&Char, &*Begin, 1); + Begin++; + *Output++ = static_cast(Char); + } + + #else + + // Get the facet of the locale which deals with character conversion + const std::ctype& Facet = std::use_facet< std::ctype >(Locale); + + // Use the facet to convert each character of the input string + while (Begin < End) + *Output++ = static_cast(Facet.widen(*Begin++)); + + #endif + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an UTF-8 characters range +/// to an UTF-16 characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::UTF8ToUTF16(In Begin, In End, Out Output, Uint16 Replacement) +{ + while (Begin < End) + { + Uint32 c = 0; + int TrailingBytes = UTF8TrailingBytes[static_cast(*Begin)]; + if (Begin + TrailingBytes < End) + { + // First decode the UTF-8 character + switch (TrailingBytes) + { + case 5 : c += *Begin++; c <<= 6; + case 4 : c += *Begin++; c <<= 6; + case 3 : c += *Begin++; c <<= 6; + case 2 : c += *Begin++; c <<= 6; + case 1 : c += *Begin++; c <<= 6; + case 0 : c += *Begin++; + } + c -= UTF8Offsets[TrailingBytes]; + + // Then encode it in UTF-16 + if (c < 0xFFFF) + { + // Character can be converted directly to 16 bits, just need to check it's in the valid range + if ((c >= 0xD800) && (c <= 0xDFFF)) + { + // Invalid character (this range is reserved) + if (Replacement) + *Output++ = Replacement; + } + else + { + // Valid character directly convertible to 16 bits + *Output++ = static_cast(c); + } + } + else if (c > 0x0010FFFF) + { + // Invalid character (greater than the maximum unicode value) + if (Replacement) + *Output++ = Replacement; + } + else + { + // Character will be converted to 2 UTF-16 elements + c -= 0x0010000; + *Output++ = static_cast((c >> 10) + 0xD800); + *Output++ = static_cast((c & 0x3FFUL) + 0xDC00); + } + } + } + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an UTF-8 characters range +/// to an UTF-32 characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::UTF8ToUTF32(In Begin, In End, Out Output, Uint32 Replacement) +{ + while (Begin < End) + { + Uint32 c = 0; + int TrailingBytes = UTF8TrailingBytes[static_cast(*Begin)]; + if (Begin + TrailingBytes < End) + { + // First decode the UTF-8 character + switch (TrailingBytes) + { + case 5 : c += *Begin++; c <<= 6; + case 4 : c += *Begin++; c <<= 6; + case 3 : c += *Begin++; c <<= 6; + case 2 : c += *Begin++; c <<= 6; + case 1 : c += *Begin++; c <<= 6; + case 0 : c += *Begin++; + } + c -= UTF8Offsets[TrailingBytes]; + + // Then write it if valid + if ((c < 0xD800) || (c > 0xDFFF)) + { + // Valid UTF-32 character + *Output++ = c; + } + else + { + // Invalid UTF-32 character + if (Replacement) + *Output++ = Replacement; + } + } + } + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an UTF-16 characters range +/// to an UTF-8 characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::UTF16ToUTF8(In Begin, In End, Out Output, Uint8 Replacement) +{ + while (Begin < End) + { + Uint32 c = *Begin++; + + // If it's a surrogate pair, first convert to a single UTF-32 character + if ((c >= 0xD800) && (c <= 0xDBFF)) + { + if (Begin < End) + { + // The second element is valid : convert the two elements to a UTF-32 character + Uint32 d = *Begin++; + if ((d >= 0xDC00) && (d <= 0xDFFF)) + c = static_cast(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000); + } + else + { + // Invalid second element + if (Replacement) + *Output++ = Replacement; + } + } + + // Then convert to UTF-8 + if (c > 0x0010FFFF) + { + // Invalid character (greater than the maximum unicode value) + if (Replacement) + *Output++ = Replacement; + } + else + { + // Valid character + + // Get number of bytes to write + int BytesToWrite = 1; + if (c < 0x80) BytesToWrite = 1; + else if (c < 0x800) BytesToWrite = 2; + else if (c < 0x10000) BytesToWrite = 3; + else if (c <= 0x0010FFFF) BytesToWrite = 4; + + // Extract bytes to write + Uint8 Bytes[4]; + switch (BytesToWrite) + { + case 4 : Bytes[3] = static_cast((c | 0x80) & 0xBF); c >>= 6; + case 3 : Bytes[2] = static_cast((c | 0x80) & 0xBF); c >>= 6; + case 2 : Bytes[1] = static_cast((c | 0x80) & 0xBF); c >>= 6; + case 1 : Bytes[0] = static_cast (c | UTF8FirstBytes[BytesToWrite]); + } + + // Add them to the output + const Uint8* CurByte = Bytes; + switch (BytesToWrite) + { + case 4 : *Output++ = *CurByte++; + case 3 : *Output++ = *CurByte++; + case 2 : *Output++ = *CurByte++; + case 1 : *Output++ = *CurByte++; + } + } + } + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an UTF-16 characters range +/// to an UTF-32 characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::UTF16ToUTF32(In Begin, In End, Out Output, Uint32 Replacement) +{ + while (Begin < End) + { + Uint16 c = *Begin++; + if ((c >= 0xD800) && (c <= 0xDBFF)) + { + // We have a surrogate pair, ie. a character composed of two elements + if (Begin < End) + { + Uint16 d = *Begin++; + if ((d >= 0xDC00) && (d <= 0xDFFF)) + { + // The second element is valid : convert the two elements to a UTF-32 character + *Output++ = static_cast(((c - 0xD800) << 10) + (d - 0xDC00) + 0x0010000); + } + else + { + // Invalid second element + if (Replacement) + *Output++ = Replacement; + } + } + } + else if ((c >= 0xDC00) && (c <= 0xDFFF)) + { + // Invalid character + if (Replacement) + *Output++ = Replacement; + } + else + { + // Valid character directly convertible to UTF-32 + *Output++ = static_cast(c); + } + } + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an UTF-32 characters range +/// to an UTF-8 characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::UTF32ToUTF8(In Begin, In End, Out Output, Uint8 Replacement) +{ + while (Begin < End) + { + Uint32 c = *Begin++; + if (c > 0x0010FFFF) + { + // Invalid character (greater than the maximum unicode value) + if (Replacement) + *Output++ = Replacement; + } + else + { + // Valid character + + // Get number of bytes to write + int BytesToWrite = 1; + if (c < 0x80) BytesToWrite = 1; + else if (c < 0x800) BytesToWrite = 2; + else if (c < 0x10000) BytesToWrite = 3; + else if (c <= 0x0010FFFF) BytesToWrite = 4; + + // Extract bytes to write + Uint8 Bytes[4]; + switch (BytesToWrite) + { + case 4 : Bytes[3] = static_cast((c | 0x80) & 0xBF); c >>= 6; + case 3 : Bytes[2] = static_cast((c | 0x80) & 0xBF); c >>= 6; + case 2 : Bytes[1] = static_cast((c | 0x80) & 0xBF); c >>= 6; + case 1 : Bytes[0] = static_cast (c | UTF8FirstBytes[BytesToWrite]); + } + + // Add them to the output + const Uint8* CurByte = Bytes; + switch (BytesToWrite) + { + case 4 : *Output++ = *CurByte++; + case 3 : *Output++ = *CurByte++; + case 2 : *Output++ = *CurByte++; + case 1 : *Output++ = *CurByte++; + } + } + } + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Generic function to convert an UTF-32 characters range +/// to an UTF-16 characters range, using the given locale +//////////////////////////////////////////////////////////// +template +inline Out Unicode::UTF32ToUTF16(In Begin, In End, Out Output, Uint16 Replacement) +{ + while (Begin < End) + { + Uint32 c = *Begin++; + if (c < 0xFFFF) + { + // Character can be converted directly to 16 bits, just need to check it's in the valid range + if ((c >= 0xD800) && (c <= 0xDFFF)) + { + // Invalid character (this range is reserved) + if (Replacement) + *Output++ = Replacement; + } + else + { + // Valid character directly convertible to 16 bits + *Output++ = static_cast(c); + } + } + else if (c > 0x0010FFFF) + { + // Invalid character (greater than the maximum unicode value) + if (Replacement) + *Output++ = Replacement; + } + else + { + // Character will be converted to 2 UTF-16 elements + c -= 0x0010000; + *Output++ = static_cast((c >> 10) + 0xD800); + *Output++ = static_cast((c & 0x3FFUL) + 0xDC00); + } + } + + return Output; +} + + +//////////////////////////////////////////////////////////// +/// Get the number of characters composing an UTF-8 string +//////////////////////////////////////////////////////////// +template +inline std::size_t Unicode::GetUTF8Length(In Begin, In End) +{ + std::size_t Length = 0; + while (Begin < End) + { + int NbBytes = UTF8TrailingBytes[static_cast(*Begin)]; + if (Begin + NbBytes < End) + ++Length; + + Begin += NbBytes + 1; + } + + return Length; +} + + +//////////////////////////////////////////////////////////// +/// Get the number of characters composing an UTF-16 string +//////////////////////////////////////////////////////////// +template +inline std::size_t Unicode::GetUTF16Length(In Begin, In End) +{ + std::size_t Length = 0; + while (Begin < End) + { + if ((*Begin >= 0xD800) && (*Begin <= 0xDBFF)) + { + ++Begin; + if ((Begin < End) && ((*Begin >= 0xDC00) && (*Begin <= 0xDFFF))) + { + ++Length; + } + } + else + { + ++Length; + } + + ++Begin; + } + + return Length; +} + + +//////////////////////////////////////////////////////////// +/// Get the number of characters composing an UTF-32 string +//////////////////////////////////////////////////////////// +template +inline std::size_t Unicode::GetUTF32Length(In Begin, In End) +{ + return End - Begin; +} diff --git a/SFML-1.6/include/SFML/System/Unix/Mutex.hpp b/SFML-1.6/include/SFML/System/Unix/Mutex.hpp new file mode 100644 index 000000000..f8f24b6b6 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Unix/Mutex.hpp @@ -0,0 +1,82 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_MUTEXUNIX_HPP +#define SFML_MUTEXUNIX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Mutex defines a mutex (MUTual EXclusion) object, +/// that allows a thread to lock critical instructions +/// to avoid simultaneous access with other threads. +/// See Lock for an efficient way of using it. +//////////////////////////////////////////////////////////// +class SFML_API Mutex : NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Mutex(); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~Mutex(); + + //////////////////////////////////////////////////////////// + /// Lock the mutex + /// + //////////////////////////////////////////////////////////// + void Lock(); + + //////////////////////////////////////////////////////////// + /// Unlock the mutex + /// + //////////////////////////////////////////////////////////// + void Unlock(); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + pthread_mutex_t myMutex; ///< pthread instance of the mutex +}; + +} // namespace sf + + +#endif // SFML_MUTEXUNIX_HPP diff --git a/SFML-1.6/include/SFML/System/Unix/Thread.hpp b/SFML-1.6/include/SFML/System/Unix/Thread.hpp new file mode 100644 index 000000000..b26d38ff5 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Unix/Thread.hpp @@ -0,0 +1,124 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_THREADUNIX_HPP +#define SFML_THREADUNIX_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Thread defines a thread. +/// There is two ways to use Thread : +/// - Inherit from it and override the Run() virtual function +/// - Construct a sfThread instance and pass it a function +/// pointer to call +//////////////////////////////////////////////////////////// +class SFML_API Thread : NonCopyable +{ +public : + + typedef void (*FuncType)(void*); + + //////////////////////////////////////////////////////////// + /// Construct the thread from a function pointer + /// + /// \param Function : Entry point of the thread + /// \param UserData : Data to pass to the thread function (NULL by default) + /// + //////////////////////////////////////////////////////////// + Thread(FuncType Function, void* UserData = NULL); + + //////////////////////////////////////////////////////////// + /// Virtual destructor + /// + //////////////////////////////////////////////////////////// + virtual ~Thread(); + + //////////////////////////////////////////////////////////// + /// Create and run the thread + /// + //////////////////////////////////////////////////////////// + void Launch(); + + //////////////////////////////////////////////////////////// + /// Wait until the thread finishes + /// + //////////////////////////////////////////////////////////// + void Wait(); + + //////////////////////////////////////////////////////////// + /// Terminate the thread + /// Terminating a thread with this function is not safe, + /// you should rather try to make the thread function + /// terminate by itself + /// + //////////////////////////////////////////////////////////// + void Terminate(); + +protected : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Thread(); + +private : + + //////////////////////////////////////////////////////////// + /// Function called as the thread entry point + /// + //////////////////////////////////////////////////////////// + virtual void Run(); + + //////////////////////////////////////////////////////////// + /// Actual thread entry point, dispatches to instances + /// + /// \param UserData : Data to pass to the thread function + /// + /// \return Error code + /// + //////////////////////////////////////////////////////////// + static void* ThreadFunc(void* UserData); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + pthread_t myThread; ///< Unix thread instance + bool myIsActive; ///< Thread state (active or inactive) + FuncType myFunction; ///< Function to call as the thread entry point + void* myUserData; ///< Data to pass to the thread function +}; + +} // namespace sf + + +#endif // SFML_THREADUNIX_HPP diff --git a/SFML-1.6/include/SFML/System/Vector2.hpp b/SFML-1.6/include/SFML/System/Vector2.hpp new file mode 100644 index 000000000..0a5267c7b --- /dev/null +++ b/SFML-1.6/include/SFML/System/Vector2.hpp @@ -0,0 +1,215 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_VECTOR2_HPP +#define SFML_VECTOR2_HPP + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Vector2 is an utility class for manipulating 2 dimensional +/// vectors. Template parameter defines the type of coordinates +/// (integer, float, ...) +//////////////////////////////////////////////////////////// +template +class Vector2 +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Vector2(); + + //////////////////////////////////////////////////////////// + /// Construct the vector from its coordinates + /// + /// \param X : X coordinate + /// \param Y : Y coordinate + /// + //////////////////////////////////////////////////////////// + Vector2(T X, T Y); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector +}; + +//////////////////////////////////////////////////////////// +/// Operator - overload ; returns the opposite of a vector +/// +/// \param V : Vector to negate +/// +/// \return -V +/// +//////////////////////////////////////////////////////////// +template +Vector2 operator -(const Vector2& V); + +//////////////////////////////////////////////////////////// +/// Operator += overload ; add two vectors and assign to the first op +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 + V2 +/// +//////////////////////////////////////////////////////////// +template +Vector2& operator +=(Vector2& V1, const Vector2& V2); + +//////////////////////////////////////////////////////////// +/// Operator -= overload ; subtract two vectors and assign to the first op +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 - V2 +/// +//////////////////////////////////////////////////////////// +template +Vector2& operator -=(Vector2& V1, const Vector2& V2); + +//////////////////////////////////////////////////////////// +/// Operator + overload ; adds two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 + V2 +/// +//////////////////////////////////////////////////////////// +template +Vector2 operator +(const Vector2& V1, const Vector2& V2); + +//////////////////////////////////////////////////////////// +/// Operator - overload ; subtracts two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 - V2 +/// +//////////////////////////////////////////////////////////// +template +Vector2 operator -(const Vector2& V1, const Vector2& V2); + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V * X +/// +//////////////////////////////////////////////////////////// +template +Vector2 operator *(const Vector2& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a scalar value by a vector +/// +/// \param X : Scalar value +/// \param V : Vector +/// +/// \return X * V +/// +//////////////////////////////////////////////////////////// +template +Vector2 operator *(T X, const Vector2& V); + +//////////////////////////////////////////////////////////// +/// Operator *= overload ; multiply-assign a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V * X +/// +//////////////////////////////////////////////////////////// +template +Vector2& operator *=(Vector2& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator / overload ; divide a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V / X +/// +//////////////////////////////////////////////////////////// +template +Vector2 operator /(const Vector2& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator /= overload ; divide-assign a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V / X +/// +//////////////////////////////////////////////////////////// +template +Vector2& operator /=(Vector2& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator == overload ; compares the equality of two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return True if V1 is equal to V2 +/// +//////////////////////////////////////////////////////////// +template +bool operator ==(const Vector2& V1, const Vector2& V2); + +//////////////////////////////////////////////////////////// +/// Operator != overload ; compares the difference of two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return True if V1 is different than V2 +/// +//////////////////////////////////////////////////////////// +template +bool operator !=(const Vector2& V1, const Vector2& V2); + +#include + +// Define the most common types +typedef Vector2 Vector2i; +typedef Vector2 Vector2f; + +} // namespace sf + + +#endif // SFML_VECTOR2_HPP diff --git a/SFML-1.6/include/SFML/System/Vector2.inl b/SFML-1.6/include/SFML/System/Vector2.inl new file mode 100644 index 000000000..febd49366 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Vector2.inl @@ -0,0 +1,179 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Default constructor +//////////////////////////////////////////////////////////// +template +Vector2::Vector2() : +x(0), +y(0) +{ + +} + + +//////////////////////////////////////////////////////////// +/// Construct the color from its coordinates +//////////////////////////////////////////////////////////// +template +Vector2::Vector2(T X, T Y) : +x(X), +y(Y) +{ + +} + + +//////////////////////////////////////////////////////////// +/// Operator - overload ; returns the opposite of a vector +//////////////////////////////////////////////////////////// +template +Vector2 operator -(const Vector2& V) +{ + return Vector2(-V.x, -V.y); +} + + +//////////////////////////////////////////////////////////// +/// Operator += overload ; add two vectors and assign to the first op +//////////////////////////////////////////////////////////// +template +Vector2& operator +=(Vector2& V1, const Vector2& V2) +{ + V1.x += V2.x; + V1.y += V2.y; + + return V1; +} + + +//////////////////////////////////////////////////////////// +/// Operator -= overload ; subtract two vectors and assign to the first op +//////////////////////////////////////////////////////////// +template +Vector2& operator -=(Vector2& V1, const Vector2& V2) +{ + V1.x -= V2.x; + V1.y -= V2.y; + + return V1; +} + + +//////////////////////////////////////////////////////////// +/// Operator + overload ; adds two vectors +//////////////////////////////////////////////////////////// +template +Vector2 operator +(const Vector2& V1, const Vector2& V2) +{ + return Vector2(V1.x + V2.x, V1.y + V2.y); +} + + +//////////////////////////////////////////////////////////// +/// Operator - overload ; subtracts two vectors +//////////////////////////////////////////////////////////// +template +Vector2 operator -(const Vector2& V1, const Vector2& V2) +{ + return Vector2(V1.x - V2.x, V1.y - V2.y); +} + + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector2 operator *(const Vector2& V, T X) +{ + return Vector2(V.x * X, V.y * X); +} + + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a scalar value by a vector +//////////////////////////////////////////////////////////// +template +Vector2 operator *(T X, const Vector2& V) +{ + return Vector2(V.x * X, V.y * X); +} + + +//////////////////////////////////////////////////////////// +/// Operator *= overload ; multiply-assign a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector2& operator *=(Vector2& V, T X) +{ + V.x *= X; + V.y *= X; + + return V; +} + + +//////////////////////////////////////////////////////////// +/// Operator / overload ; divide a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector2 operator /(const Vector2& V, T X) +{ + return Vector2(V.x / X, V.y / X); +} + + +//////////////////////////////////////////////////////////// +/// Operator /= overload ; divide-assign a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector2& operator /=(Vector2& V, T X) +{ + V.x /= X; + V.y /= X; + + return V; +} + + +//////////////////////////////////////////////////////////// +/// Operator == overload ; compares the equality of two vectors +//////////////////////////////////////////////////////////// +template +bool operator ==(const Vector2& V1, const Vector2& V2) +{ + return (V1.x == V2.x) && (V1.y == V2.y); +} + + +//////////////////////////////////////////////////////////// +/// Operator != overload ; compares the difference of two vectors +//////////////////////////////////////////////////////////// +template +bool operator !=(const Vector2& V1, const Vector2& V2) +{ + return (V1.x != V2.x) || (V1.y != V2.y); +} diff --git a/SFML-1.6/include/SFML/System/Vector3.hpp b/SFML-1.6/include/SFML/System/Vector3.hpp new file mode 100644 index 000000000..6ab4b84c1 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Vector3.hpp @@ -0,0 +1,217 @@ +//////////////////////////////////////////////////////////// +// +// 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_VECTOR3_HPP +#define SFML_VECTOR3_HPP + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Vector3 is an utility class for manipulating 3 dimensional +/// vectors. Template parameter defines the type of coordinates +/// (integer, float, ...) +//////////////////////////////////////////////////////////// +template +class Vector3 +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Vector3(); + + //////////////////////////////////////////////////////////// + /// Construct the vector from its coordinates + /// + /// \param X : X coordinate + /// \param Y : Y coordinate + /// \param Z : Z coordinate + /// + //////////////////////////////////////////////////////////// + Vector3(T X, T Y, T Z); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T x; ///< X coordinate of the vector + T y; ///< Y coordinate of the vector + T z; ///< Z coordinate of the vector +}; + +//////////////////////////////////////////////////////////// +/// Operator - overload ; returns the opposite of a vector +/// +/// \param V : Vector to negate +/// +/// \return -V +/// +//////////////////////////////////////////////////////////// +template +Vector3 operator -(const Vector3& V); + +//////////////////////////////////////////////////////////// +/// Operator += overload ; add two vectors and assign to the first op +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 + V2 +/// +//////////////////////////////////////////////////////////// +template +Vector3& operator +=(Vector3& V1, const Vector3& V2); + +//////////////////////////////////////////////////////////// +/// Operator -= overload ; subtract two vectors and assign to the first op +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 - V2 +/// +//////////////////////////////////////////////////////////// +template +Vector3& operator -=(Vector3& V1, const Vector3& V2); + +//////////////////////////////////////////////////////////// +/// Operator + overload ; adds two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 + V2 +/// +//////////////////////////////////////////////////////////// +template +Vector3 operator +(const Vector3& V1, const Vector3& V2); + +//////////////////////////////////////////////////////////// +/// Operator - overload ; subtracts two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return V1 - V2 +/// +//////////////////////////////////////////////////////////// +template +Vector3 operator -(const Vector3& V1, const Vector3& V2); + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V * X +/// +//////////////////////////////////////////////////////////// +template +Vector3 operator *(const Vector3& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a scalar value by a vector +/// +/// \param X : Scalar value +/// \param V : Vector +/// +/// \return X * V +/// +//////////////////////////////////////////////////////////// +template +Vector3 operator *(T X, const Vector3& V); + +//////////////////////////////////////////////////////////// +/// Operator *= overload ; multiply-assign a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V * X +/// +//////////////////////////////////////////////////////////// +template +Vector3& operator *=(Vector3& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator / overload ; divide a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V / X +/// +//////////////////////////////////////////////////////////// +template +Vector3 operator /(const Vector3& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator /= overload ; divide-assign a vector by a scalar value +/// +/// \param V : Vector +/// \param X : Scalar value +/// +/// \return V / X +/// +//////////////////////////////////////////////////////////// +template +Vector3& operator /=(Vector3& V, T X); + +//////////////////////////////////////////////////////////// +/// Operator == overload ; compares the equality of two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return True if V1 is equal to V2 +/// +//////////////////////////////////////////////////////////// +template +bool operator ==(const Vector3& V1, const Vector3& V2); + +//////////////////////////////////////////////////////////// +/// Operator != overload ; compares the difference of two vectors +/// +/// \param V1 : First vector +/// \param V2 : Second vector +/// +/// \return True if V1 is different than V2 +/// +//////////////////////////////////////////////////////////// +template +bool operator !=(const Vector3& V1, const Vector3& V2); + +#include + +// Define the most common types +typedef Vector3 Vector3i; +typedef Vector3 Vector3f; + +} // namespace sf + + +#endif // SFML_VECTOR3_HPP diff --git a/SFML-1.6/include/SFML/System/Vector3.inl b/SFML-1.6/include/SFML/System/Vector3.inl new file mode 100644 index 000000000..859460180 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Vector3.inl @@ -0,0 +1,185 @@ +//////////////////////////////////////////////////////////// +// +// 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. +// +//////////////////////////////////////////////////////////// + + +//////////////////////////////////////////////////////////// +/// Default constructor +//////////////////////////////////////////////////////////// +template +Vector3::Vector3() : +x(0), +y(0), +z(0) +{ + +} + + +//////////////////////////////////////////////////////////// +/// Construct the color from its coordinates +//////////////////////////////////////////////////////////// +template +Vector3::Vector3(T X, T Y, T Z) : +x(X), +y(Y), +z(Z) +{ + +} + + +//////////////////////////////////////////////////////////// +/// Operator - overload ; returns the opposite of a vector +//////////////////////////////////////////////////////////// +template +Vector3 operator -(const Vector3& V) +{ + return Vector3(-V.x, -V.y, -V.z); +} + + +//////////////////////////////////////////////////////////// +/// Operator += overload ; add two vectors and assign to the first op +//////////////////////////////////////////////////////////// +template +Vector3& operator +=(Vector3& V1, const Vector3& V2) +{ + V1.x += V2.x; + V1.y += V2.y; + V1.z += V2.z; + + return V1; +} + + +//////////////////////////////////////////////////////////// +/// Operator -= overload ; subtract two vectors and assign to the first op +//////////////////////////////////////////////////////////// +template +Vector3& operator -=(Vector3& V1, const Vector3& V2) +{ + V1.x -= V2.x; + V1.y -= V2.y; + V1.z -= V2.z; + + return V1; +} + + +//////////////////////////////////////////////////////////// +/// Operator + overload ; adds two vectors +//////////////////////////////////////////////////////////// +template +Vector3 operator +(const Vector3& V1, const Vector3& V2) +{ + return Vector3(V1.x + V2.x, V1.y + V2.y, V1.z + V2.z); +} + + +//////////////////////////////////////////////////////////// +/// Operator - overload ; subtracts two vectors +//////////////////////////////////////////////////////////// +template +Vector3 operator -(const Vector3& V1, const Vector3& V2) +{ + return Vector3(V1.x - V2.x, V1.y - V2.y, V1.z - V2.z); +} + + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector3 operator *(const Vector3& V, T X) +{ + return Vector3(V.x * X, V.y * X, V.z * X); +} + + +//////////////////////////////////////////////////////////// +/// Operator * overload ; multiply a scalar value by a vector +//////////////////////////////////////////////////////////// +template +Vector3 operator *(T X, const Vector3& V) +{ + return Vector3(V.x * X, V.y * X, V.z * X); +} + + +//////////////////////////////////////////////////////////// +/// Operator *= overload ; multiply-assign a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector3& operator *=(Vector3& V, T X) +{ + V.x *= X; + V.y *= X; + V.z *= X; + + return V; +} + + +//////////////////////////////////////////////////////////// +/// Operator / overload ; divide a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector3 operator /(const Vector3& V, T X) +{ + return Vector3(V.x / X, V.y / X, V.z / X); +} + + +//////////////////////////////////////////////////////////// +/// Operator /= overload ; divide-assign a vector by a scalar value +//////////////////////////////////////////////////////////// +template +Vector3& operator /=(Vector3& V, T X) +{ + V.x /= X; + V.y /= X; + V.z /= X; + + return V; +} + + +//////////////////////////////////////////////////////////// +/// Operator == overload ; compares the equality of two vectors +//////////////////////////////////////////////////////////// +template +bool operator ==(const Vector3& V1, const Vector3& V2) +{ + return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z); +} + + +//////////////////////////////////////////////////////////// +/// Operator != overload ; compares the difference of two vectors +//////////////////////////////////////////////////////////// +template +bool operator !=(const Vector3& V1, const Vector3& V2) +{ + return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z); +} diff --git a/SFML-1.6/include/SFML/System/Win32/Mutex.hpp b/SFML-1.6/include/SFML/System/Win32/Mutex.hpp new file mode 100644 index 000000000..3cf5f9da7 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Win32/Mutex.hpp @@ -0,0 +1,84 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_MUTEXWIN32_HPP +#define SFML_MUTEXWIN32_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Mutex defines a mutex (MUTual EXclusion) object, +/// that allows a thread to lock critical instructions +/// to avoid simultaneous access with other threads. +/// The Win32 version uses critical sections, as it is +/// faster than mutexes.
+/// See Lock for an efficient way of using it. +//////////////////////////////////////////////////////////// +class SFML_API Mutex : NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Mutex(); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + ~Mutex(); + + //////////////////////////////////////////////////////////// + /// Lock the mutex + /// + //////////////////////////////////////////////////////////// + void Lock(); + + //////////////////////////////////////////////////////////// + /// Unlock the mutex + /// + //////////////////////////////////////////////////////////// + void Unlock(); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + CRITICAL_SECTION myHandle; ///< Win32 handle of the mutex +}; + +} // namespace sf + + +#endif // SFML_MUTEXWIN32_HPP diff --git a/SFML-1.6/include/SFML/System/Win32/Thread.hpp b/SFML-1.6/include/SFML/System/Win32/Thread.hpp new file mode 100644 index 000000000..f44dfe125 --- /dev/null +++ b/SFML-1.6/include/SFML/System/Win32/Thread.hpp @@ -0,0 +1,123 @@ +//////////////////////////////////////////////////////////// +// +// 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_THREADWIN32_HPP +#define SFML_THREADWIN32_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Thread defines an easy way to manipulate a thread. +/// There are two ways to use Thread : +/// - Inherit from it and override the Run() virtual function +/// - Construct a Thread instance and pass it a function +/// pointer to call +//////////////////////////////////////////////////////////// +class SFML_API Thread : NonCopyable +{ +public : + + typedef void (*FuncType)(void*); + + //////////////////////////////////////////////////////////// + /// Construct the thread from a function pointer + /// + /// \param Function : Entry point of the thread + /// \param UserData : Data to pass to the thread function (NULL by default) + /// + //////////////////////////////////////////////////////////// + Thread(FuncType Function, void* UserData = NULL); + + //////////////////////////////////////////////////////////// + /// Virtual destructor + /// + //////////////////////////////////////////////////////////// + virtual ~Thread(); + + //////////////////////////////////////////////////////////// + /// Create and run the thread + /// + //////////////////////////////////////////////////////////// + void Launch(); + + //////////////////////////////////////////////////////////// + /// Wait until the thread finishes + /// + //////////////////////////////////////////////////////////// + void Wait(); + + //////////////////////////////////////////////////////////// + /// Terminate the thread + /// Terminating a thread with this function is not safe, + /// you should rather try to make the thread function + /// terminate by itself + /// + //////////////////////////////////////////////////////////// + void Terminate(); + +protected : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Thread(); + +private : + + //////////////////////////////////////////////////////////// + /// Function called as the thread entry point + /// + //////////////////////////////////////////////////////////// + virtual void Run(); + + //////////////////////////////////////////////////////////// + /// Actual thread entry point, dispatches to instances + /// + /// \param UserData : Data to pass to the thread function + /// + /// \return Error code + /// + //////////////////////////////////////////////////////////// + static unsigned int __stdcall ThreadFunc(void* UserData); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + HANDLE myHandle; ///< Win32 thread handle + FuncType myFunction; ///< Function to call as the thread entry point + void* myUserData; ///< Data to pass to the thread function +}; + +} // namespace sf + + +#endif // SFML_THREADWIN32_HPP diff --git a/SFML-1.6/include/SFML/Window/Context.hpp b/SFML-1.6/include/SFML/Window/Context.hpp new file mode 100644 index 000000000..fede21cd1 --- /dev/null +++ b/SFML-1.6/include/SFML/Window/Context.hpp @@ -0,0 +1,100 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CONTEXT_HPP +#define SFML_CONTEXT_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +namespace priv +{ + class WindowImpl; +} + +//////////////////////////////////////////////////////////// +/// Class wrapping an OpenGL context. +/// All SFML windows already have their own context, so +/// this class is more a helper for specific issues involving +/// OpenGL and multi-threading. +/// It's meant to be used internally. +//////////////////////////////////////////////////////////// +class SFML_API Context : NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor, create the context + /// + //////////////////////////////////////////////////////////// + Context(); + + //////////////////////////////////////////////////////////// + /// Destructor, destroy the context + /// + //////////////////////////////////////////////////////////// + ~Context(); + + //////////////////////////////////////////////////////////// + /// Activate or deactivate the context + /// + /// \param Active : True to activate the context, false to deactivate it + /// + //////////////////////////////////////////////////////////// + void SetActive(bool Active); + + //////////////////////////////////////////////////////////// + /// Check if there's a context bound to the current thread + /// + /// \return True if there's a context bound to the current thread + /// + //////////////////////////////////////////////////////////// + static bool IsContextActive(); + + //////////////////////////////////////////////////////////// + /// Get the global context + /// + /// \return Reference to the global context + /// + //////////////////////////////////////////////////////////// + static Context& GetGlobal(); + +private : + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + priv::WindowImpl* myDummyWindow; ///< Dummy window holding the context +}; + +} // namespace sf + + +#endif // SFML_CONTEXT_HPP diff --git a/SFML-1.6/include/SFML/Window/Event.hpp b/SFML-1.6/include/SFML/Window/Event.hpp new file mode 100644 index 000000000..35ac57553 --- /dev/null +++ b/SFML-1.6/include/SFML/Window/Event.hpp @@ -0,0 +1,321 @@ +//////////////////////////////////////////////////////////// +// +// 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 + + +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 diff --git a/SFML-1.6/include/SFML/Window/Input.hpp b/SFML-1.6/include/SFML/Window/Input.hpp new file mode 100644 index 000000000..e9e9c5e4a --- /dev/null +++ b/SFML-1.6/include/SFML/Window/Input.hpp @@ -0,0 +1,140 @@ +//////////////////////////////////////////////////////////// +// +// 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_INPUT_HPP +#define SFML_INPUT_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Input handles real-time input from keyboard and mouse. +/// Use it instead of events to handle continuous moves and more +/// game-friendly inputs +//////////////////////////////////////////////////////////// +class SFML_API Input : public WindowListener, NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Input(); + + //////////////////////////////////////////////////////////// + /// Get the state of a key + /// + /// \param KeyCode : Key to check + /// + /// \return True if key is down, false if key is up + /// + //////////////////////////////////////////////////////////// + bool IsKeyDown(Key::Code KeyCode) const; + + //////////////////////////////////////////////////////////// + /// Get the state of a mouse button + /// + /// \param Button : Button to check + /// + /// \return True if button is down, false if button is up + /// + //////////////////////////////////////////////////////////// + bool IsMouseButtonDown(Mouse::Button Button) const; + + //////////////////////////////////////////////////////////// + /// Get the state of a joystick button + /// + /// \param JoyId : Identifier of the joystick to check (0 or 1) + /// \param Button : Button to check + /// + /// \return True if button is down, false if button is up + /// + //////////////////////////////////////////////////////////// + bool IsJoystickButtonDown(unsigned int JoyId, unsigned int Button) const; + + //////////////////////////////////////////////////////////// + /// Get the mouse X position + /// + /// \return Current mouse left position, relative to owner window + /// + //////////////////////////////////////////////////////////// + int GetMouseX() const; + + //////////////////////////////////////////////////////////// + /// Get the mouse Y position + /// + /// \return Current mouse top position, relative to owner window + /// + //////////////////////////////////////////////////////////// + int GetMouseY() const; + + //////////////////////////////////////////////////////////// + /// Get a joystick axis position + /// + /// \param JoyId : Identifier of the joystick to check (0 or 1) + /// \param Axis : Axis to get + /// + /// \return Current axis position, in the range [-100, 100] (except for POV, which is [0, 360]) + /// + //////////////////////////////////////////////////////////// + float GetJoystickAxis(unsigned int JoyId, Joy::Axis Axis) const; + +private : + + //////////////////////////////////////////////////////////// + /// /see WindowListener::OnEvent + /// + //////////////////////////////////////////////////////////// + virtual void OnEvent(const Event& EventReceived); + + //////////////////////////////////////////////////////////// + /// Reset all the states + /// + //////////////////////////////////////////////////////////// + void ResetStates(); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + bool myKeys[Key::Count]; ///< Array containing the state of all keyboard keys + bool myMouseButtons[Mouse::ButtonCount]; ///< Array containing the state of all mouse buttons + int myMouseX; ///< Mouse position on X + int myMouseY; ///< Mouse position on Y + bool myJoystickButtons[Joy::Count][Joy::ButtonCount]; ///< Array containing the state of all joysticks buttons + float myJoystickAxis[Joy::Count][Joy::AxisCount]; ///< Joysticks position on each axis +}; + +} // namespace sf + + +#endif // SFML_INPUT_HPP diff --git a/SFML-1.6/include/SFML/Window/OpenGL.hpp b/SFML-1.6/include/SFML/Window/OpenGL.hpp new file mode 100644 index 000000000..fcd486891 --- /dev/null +++ b/SFML-1.6/include/SFML/Window/OpenGL.hpp @@ -0,0 +1,59 @@ +//////////////////////////////////////////////////////////// +// +// 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_OPENGL_HPP +#define SFML_OPENGL_HPP + + +//////////////////////////////////////////////////////////// +/// Headers +//////////////////////////////////////////////////////////// +#include + + +//////////////////////////////////////////////////////////// +/// This file just includes the OpenGL (GL and GLU) headers, +/// which have actually different paths on each system +//////////////////////////////////////////////////////////// +#if defined(SFML_SYSTEM_WINDOWS) + + #include + #include + #include + +#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD) + + #include + #include + +#elif defined(SFML_SYSTEM_MACOS) + + #include + #include + +#endif + + +#endif // SFML_OPENGL_HPP + diff --git a/SFML-1.6/include/SFML/Window/VideoMode.hpp b/SFML-1.6/include/SFML/Window/VideoMode.hpp new file mode 100644 index 000000000..b439e648b --- /dev/null +++ b/SFML-1.6/include/SFML/Window/VideoMode.hpp @@ -0,0 +1,136 @@ +//////////////////////////////////////////////////////////// +// +// 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_VIDEOMODE_HPP +#define SFML_VIDEOMODE_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// VideoMode defines a video mode (width, height, bpp, frequency) +/// and provides static functions for getting modes supported +/// by the display device +//////////////////////////////////////////////////////////// +class SFML_API VideoMode +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + VideoMode(); + + //////////////////////////////////////////////////////////// + /// Construct the video mode with its attributes + /// + /// \param ModeWidth : Width in pixels + /// \param ModeHeight : Height in pixels + /// \param ModeBpp : Pixel depths in bits per pixel (32 by default) + /// + //////////////////////////////////////////////////////////// + VideoMode(unsigned int ModeWidth, unsigned int ModeHeight, unsigned int ModeBpp = 32); + + //////////////////////////////////////////////////////////// + /// Get the current desktop video mode + /// + /// \return Current desktop video mode + /// + //////////////////////////////////////////////////////////// + static VideoMode GetDesktopMode(); + + //////////////////////////////////////////////////////////// + /// Get a valid video mode + /// Index must be in range [0, GetModesCount()[ + /// Modes are sorted from best to worst + /// + /// \param Index : Index of video mode to get + /// + /// \return Corresponding video mode (invalid mode if index is out of range) + /// + //////////////////////////////////////////////////////////// + static VideoMode GetMode(std::size_t Index); + + //////////////////////////////////////////////////////////// + /// Get valid video modes count + /// + /// \return Number of valid video modes available + /// + //////////////////////////////////////////////////////////// + static std::size_t GetModesCount(); + + //////////////////////////////////////////////////////////// + /// Tell whether or not the video mode is supported + /// + /// \return True if video mode is supported, false otherwise + /// + //////////////////////////////////////////////////////////// + bool IsValid() const; + + //////////////////////////////////////////////////////////// + /// Comparison operator overload -- tell if two video modes are equal + /// + /// \param Other : Video mode to compare + /// + /// \return True if modes are equal + /// + //////////////////////////////////////////////////////////// + bool operator ==(const VideoMode& Other) const; + + //////////////////////////////////////////////////////////// + /// Comparison operator overload -- tell if two video modes are different + /// + /// \param Other : Video mode to compare + /// + /// \return True if modes are different + /// + //////////////////////////////////////////////////////////// + bool operator !=(const VideoMode& Other) const; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int Width; ///< Video mode width, in pixels + unsigned int Height; ///< Video mode height, in pixels + unsigned int BitsPerPixel; ///< Video mode pixel depth, in bits per pixels + +private : + + //////////////////////////////////////////////////////////// + /// Get and sort valid video modes + //////////////////////////////////////////////////////////// + static void InitializeModes(); +}; + +} // namespace sf + + +#endif // SFML_VIDEOMODE_HPP diff --git a/SFML-1.6/include/SFML/Window/Window.hpp b/SFML-1.6/include/SFML/Window/Window.hpp new file mode 100644 index 000000000..51990212f --- /dev/null +++ b/SFML-1.6/include/SFML/Window/Window.hpp @@ -0,0 +1,326 @@ +//////////////////////////////////////////////////////////// +// +// 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_WINDOW_HPP +#define SFML_WINDOW_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include +#include + + +namespace sf +{ +namespace priv +{ + class WindowImpl; +} + +//////////////////////////////////////////////////////////// +/// Window is a rendering window ; it can create a new window +/// or connect to an existing one +//////////////////////////////////////////////////////////// +class SFML_API Window : public WindowListener, NonCopyable +{ +public : + + //////////////////////////////////////////////////////////// + /// Default constructor + /// + //////////////////////////////////////////////////////////// + Window(); + + //////////////////////////////////////////////////////////// + /// Construct a new window + /// + /// \param Mode : Video mode to use + /// \param Title : Title of the window + /// \param WindowStyle : Window style, see sf::Style (Resize | Close by default) + /// \param Params : Creation parameters (see default constructor for default values) + /// + //////////////////////////////////////////////////////////// + Window(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings()); + + //////////////////////////////////////////////////////////// + /// Construct the window from an existing control + /// + /// \param Handle : Platform-specific handle of the control + /// \param Params : Creation parameters (see default constructor for default values) + /// + //////////////////////////////////////////////////////////// + Window(WindowHandle Handle, const WindowSettings& Params = WindowSettings()); + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + virtual ~Window(); + + //////////////////////////////////////////////////////////// + /// Create (or recreate) the window + /// + /// \param Mode : Video mode to use + /// \param Title : Title of the window + /// \param WindowStyle : Window style, see sf::Style (Resize | Close by default) + /// \param Params : Creation parameters (see default constructor for default values) + /// + //////////////////////////////////////////////////////////// + void Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle = Style::Resize | Style::Close, const WindowSettings& Params = WindowSettings()); + + //////////////////////////////////////////////////////////// + /// Create (or recreate) the window from an existing control + /// + /// \param Handle : Platform-specific handle of the control + /// \param Params : Creation parameters (see default constructor for default values) + /// + //////////////////////////////////////////////////////////// + void Create(WindowHandle Handle, const WindowSettings& Params = WindowSettings()); + + //////////////////////////////////////////////////////////// + /// Close (destroy) the window. + /// The sf::Window instance remains valid and you can call + /// Create to recreate the window + /// + //////////////////////////////////////////////////////////// + void Close(); + + //////////////////////////////////////////////////////////// + /// Tell whether or not the window is opened (ie. has been created). + /// Note that a hidden window (Show(false)) + /// will still return true + /// + /// \return True if the window is opened + /// + //////////////////////////////////////////////////////////// + bool IsOpened() const; + + //////////////////////////////////////////////////////////// + /// Get the width of the rendering region of the window + /// + /// \return Width in pixels + /// + //////////////////////////////////////////////////////////// + unsigned int GetWidth() const; + + //////////////////////////////////////////////////////////// + /// Get the height of the rendering region of the window + /// + /// \return Height in pixels + /// + //////////////////////////////////////////////////////////// + unsigned int GetHeight() const; + + //////////////////////////////////////////////////////////// + /// Get the creation settings of the window + /// + /// \return Structure containing the creation settings + /// + //////////////////////////////////////////////////////////// + const WindowSettings& GetSettings() const; + + //////////////////////////////////////////////////////////// + /// Get the event on top of events stack, if any, and pop it + /// + /// \param EventReceived : Event to fill, if any + /// + /// \return True if an event was returned, false if events stack was empty + /// + //////////////////////////////////////////////////////////// + bool GetEvent(Event& EventReceived); + + //////////////////////////////////////////////////////////// + /// Enable / disable vertical synchronization + /// + /// \param Enabled : True to enable v-sync, false to deactivate + /// + //////////////////////////////////////////////////////////// + void UseVerticalSync(bool Enabled); + + //////////////////////////////////////////////////////////// + /// Show or hide the mouse cursor + /// + /// \param Show : True to show, false to hide + /// + //////////////////////////////////////////////////////////// + void ShowMouseCursor(bool Show); + + //////////////////////////////////////////////////////////// + /// Change the position of the mouse cursor + /// + /// \param Left : Left coordinate of the cursor, relative to the window + /// \param Top : Top coordinate of the cursor, relative to the window + /// + //////////////////////////////////////////////////////////// + void SetCursorPosition(unsigned int Left, unsigned int Top); + + //////////////////////////////////////////////////////////// + /// Change the position of the window on screen. + /// Only works for top-level windows + /// + /// \param Left : Left position + /// \param Top : Top position + /// + //////////////////////////////////////////////////////////// + void SetPosition(int Left, int Top); + + //////////////////////////////////////////////////////////// + /// Change the size of the rendering region of the window + /// + /// \param Width : New width + /// \param Height : New height + /// + //////////////////////////////////////////////////////////// + void SetSize(unsigned int Width, unsigned int Height); + + //////////////////////////////////////////////////////////// + /// Show or hide the window + /// + /// \param State : True to show, false to hide + /// + //////////////////////////////////////////////////////////// + void Show(bool State); + + //////////////////////////////////////////////////////////// + /// Enable or disable automatic key-repeat. + /// Automatic key-repeat is enabled by default + /// + /// \param Enabled : True to enable, false to disable + /// + //////////////////////////////////////////////////////////// + void EnableKeyRepeat(bool Enabled); + + //////////////////////////////////////////////////////////// + /// Change the window's icon + /// + /// \param Width : Icon's width, in pixels + /// \param Height : Icon's height, in pixels + /// \param Pixels : Pointer to the pixels in memory, format must be RGBA 32 bits + /// + //////////////////////////////////////////////////////////// + void SetIcon(unsigned int Width, unsigned int Height, const Uint8* Pixels); + + //////////////////////////////////////////////////////////// + /// Activate of deactivate the window as the current target + /// for rendering + /// + /// \param Active : True to activate, false to deactivate (true by default) + /// + /// \return True if operation was successful, false otherwise + /// + //////////////////////////////////////////////////////////// + bool SetActive(bool Active = true) const; + + //////////////////////////////////////////////////////////// + /// Display the window on screen + /// + //////////////////////////////////////////////////////////// + void Display(); + + //////////////////////////////////////////////////////////// + /// Get the input manager of the window + /// + /// \return Reference to the input + /// + //////////////////////////////////////////////////////////// + const Input& GetInput() const; + + //////////////////////////////////////////////////////////// + /// Limit the framerate to a maximum fixed frequency + /// + /// \param Limit : Framerate limit, in frames per seconds (use 0 to disable limit) + /// + //////////////////////////////////////////////////////////// + void SetFramerateLimit(unsigned int Limit); + + //////////////////////////////////////////////////////////// + /// Get time elapsed since last frame + /// + /// \return Time elapsed, in seconds + /// + //////////////////////////////////////////////////////////// + float GetFrameTime() const; + + //////////////////////////////////////////////////////////// + /// Change the joystick threshold, ie. the value below which + /// no move event will be generated + /// + /// \param Threshold : New threshold, in range [0, 100] + /// + //////////////////////////////////////////////////////////// + void SetJoystickThreshold(float Threshold); + +private : + + //////////////////////////////////////////////////////////// + /// Called after the window has been created + /// + //////////////////////////////////////////////////////////// + virtual void OnCreate(); + + //////////////////////////////////////////////////////////// + /// /see WindowListener::OnEvent + /// + /// \param EventReceived : Event received + /// + //////////////////////////////////////////////////////////// + virtual void OnEvent(const Event& EventReceived); + + //////////////////////////////////////////////////////////// + /// Initialize internal window + /// + /// \param Impl : New internal window implementation + /// + //////////////////////////////////////////////////////////// + void Initialize(priv::WindowImpl* Impl); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + priv::WindowImpl* myWindow; ///< Platform-specific implementation of window + std::queue myEvents; ///< Queue of received events + Input myInput; ///< Input manager connected to window + Clock myClock; ///< Clock for measuring the elapsed time between frames + WindowSettings mySettings; ///< Creation settings of the window + float myLastFrameTime; ///< Time elapsed since last frame + bool myIsExternal; ///< Tell whether the window is internal or external (created by SFML or not) + unsigned int myFramerateLimit; ///< Current framerate limit + int mySetCursorPosX; ///< X coordinate passed to the last call to SetCursorPosition + int mySetCursorPosY; ///< Y coordinate passed to the last call to SetCursorPosition +}; + +} // namespace sf + + +#endif // SFML_WINDOW_HPP diff --git a/SFML-1.6/include/SFML/Window/WindowHandle.hpp b/SFML-1.6/include/SFML/Window/WindowHandle.hpp new file mode 100644 index 000000000..852036c00 --- /dev/null +++ b/SFML-1.6/include/SFML/Window/WindowHandle.hpp @@ -0,0 +1,60 @@ +//////////////////////////////////////////////////////////// +// +// 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 + + +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 diff --git a/SFML-1.6/include/SFML/Window/WindowListener.hpp b/SFML-1.6/include/SFML/Window/WindowListener.hpp new file mode 100644 index 000000000..e085880b3 --- /dev/null +++ b/SFML-1.6/include/SFML/Window/WindowListener.hpp @@ -0,0 +1,66 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_WINDOWLISTENER_HPP +#define SFML_WINDOWLISTENER_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +class Event; + +//////////////////////////////////////////////////////////// +/// Base class for classes that want to receive events +/// from a window (for internal use only) +//////////////////////////////////////////////////////////// +class SFML_API WindowListener +{ +public : + + //////////////////////////////////////////////////////////// + /// Called each time an event is received from attached window + /// + /// \param EventReceived : Event received + /// + //////////////////////////////////////////////////////////// + virtual void OnEvent(const Event& EventReceived) = 0; + +protected : + + //////////////////////////////////////////////////////////// + /// Destructor + /// + //////////////////////////////////////////////////////////// + virtual ~WindowListener() {} +}; + +} // namespace sf + + +#endif // SFML_WINDOWLISTENER_HPP diff --git a/SFML-1.6/include/SFML/Window/WindowSettings.hpp b/SFML-1.6/include/SFML/Window/WindowSettings.hpp new file mode 100644 index 000000000..78f9ecd27 --- /dev/null +++ b/SFML-1.6/include/SFML/Window/WindowSettings.hpp @@ -0,0 +1,62 @@ +//////////////////////////////////////////////////////////// +// +// 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_WINDOWSETTINGS_HPP +#define SFML_WINDOWSETTINGS_HPP + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// Structure defining the creation settings of windows +//////////////////////////////////////////////////////////// +struct WindowSettings +{ + //////////////////////////////////////////////////////////// + /// Default constructor + /// + /// \param Depth : Depth buffer bits (24 by default) + /// \param Stencil : Stencil buffer bits (8 by default) + /// \param Antialiasing : Antialiasing level (0 by default) + /// + //////////////////////////////////////////////////////////// + explicit WindowSettings(unsigned int Depth = 24, unsigned int Stencil = 8, unsigned int Antialiasing = 0) : + DepthBits (Depth), + StencilBits (Stencil), + AntialiasingLevel(Antialiasing) + { + } + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + unsigned int DepthBits; ///< Bits of the depth buffer + unsigned int StencilBits; ///< Bits of the stencil buffer + unsigned int AntialiasingLevel; ///< Level of antialiasing +}; + +} // namespace sf + + +#endif // SFML_WINDOWSETTINGS_HPP diff --git a/SFML-1.6/include/SFML/Window/WindowStyle.hpp b/SFML-1.6/include/SFML/Window/WindowStyle.hpp new file mode 100644 index 000000000..9fcc2e7a3 --- /dev/null +++ b/SFML-1.6/include/SFML/Window/WindowStyle.hpp @@ -0,0 +1,51 @@ +//////////////////////////////////////////////////////////// +// +// 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_WINDOWSTYLE_HPP +#define SFML_WINDOWSTYLE_HPP + + +namespace sf +{ + +//////////////////////////////////////////////////////////// +/// Enumeration of window creation styles +//////////////////////////////////////////////////////////// +namespace Style +{ + enum + { + None = 0, ///< No border / title bar (this flag and all others are mutually exclusive) + Titlebar = 1 << 0, ///< Title bar + fixed border + Resize = 1 << 1, ///< Titlebar + resizable border + maximize button + Close = 1 << 2, ///< Titlebar + close button + Fullscreen = 1 << 3 ///< Fullscreen mode (this flag and all others are mutually exclusive) + }; +} + + +} // namespace sf + + +#endif // SFML_WINDOWSTYLE_HPP -- 2.39.2