| Color.hpp | | Color.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_COLOR_HPP | | #ifndef SFML_COLOR_HPP | |
| #define SFML_COLOR_HPP | | #define SFML_COLOR_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Config.hpp> | | #include <SFML/Graphics/Export.hpp> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Color is an utility class for manipulating | | /// \brief Utility class for manpulating RGBA colors | |
| /// 32-bits RGBA colors | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Color | | class SFML_GRAPHICS_API Color | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief 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 | | /// Constructs an opaque black color. It is equivalent to | |
| | | /// sf::Color(0, 0, 0, 255). | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Color& operator +=(const Color& Other); | | Color(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// 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) | | /// \brief Construct the color from its 4 RGBA components | |
| /// | | | |
| /// \param Other : Color to compare | | | |
| /// | | /// | |
|
| /// \return True if colors are different | | /// \param red Red component (in the range [0, 255]) | |
| | | /// \param green Green component (in the range [0, 255]) | |
| | | /// \param blue Blue component (in the range [0, 255]) | |
| | | /// \param alpha Alpha (opacity) component (in the range [0, 255]) | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool operator !=(const Color& Other) const; | | Color(Uint8 red, Uint8 green, Uint8 blue, Uint8 alpha = 255); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Static member data | | // Static member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static const Color Black; ///< Black predefined color | | static const Color Black; ///< Black predefined color | |
| static const Color White; ///< White predefined color | | static const Color White; ///< White predefined color | |
| static const Color Red; ///< Red predefined color | | static const Color Red; ///< Red predefined color | |
| static const Color Green; ///< Green predefined color | | static const Color Green; ///< Green predefined color | |
| static const Color Blue; ///< Blue predefined color | | static const Color Blue; ///< Blue predefined color | |
| static const Color Yellow; ///< Yellow predefined color | | static const Color Yellow; ///< Yellow predefined color | |
| static const Color Magenta; ///< Magenta predefined color | | static const Color Magenta; ///< Magenta predefined color | |
| static const Color Cyan; ///< Cyan predefined color | | static const Color Cyan; ///< Cyan predefined color | |
| | | static const Color Transparent; ///< Transparent (black) predefined col | |
| | | or | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Uint8 r; ///< Red component | | Uint8 r; ///< Red component | |
| Uint8 g; ///< Green component | | Uint8 g; ///< Green component | |
| Uint8 b; ///< Blue component | | Uint8 b; ///< Blue component | |
|
| Uint8 a; ///< Alpha (transparency) component | | Uint8 a; ///< Alpha (opacity) component | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator + overload to add two colors | | /// \relates Color | |
| | | /// \brief Overload of the == operator | |
| | | /// | |
| | | /// This operator compares two colors and check if they are equal. | |
| | | /// | |
| | | /// \param left Left operand | |
| | | /// \param right Right operand | |
| | | /// | |
| | | /// \return True if colors are equal, false if they are different | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_GRAPHICS_API bool operator ==(const Color& left, const Color& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates Color | |
| | | /// \brief Overload of the != operator | |
| | | /// | |
| | | /// This operator compares two colors and check if they are different. | |
| | | /// | |
| | | /// \param left Left operand | |
| | | /// \param right Right operand | |
| | | /// | |
| | | /// \return True if colors are different, false if they are equal | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_GRAPHICS_API bool operator !=(const Color& left, const Color& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates Color | |
| | | /// \brief Overload of the binary + operator | |
| | | /// | |
| | | /// This operator returns the component-wise sum of two colors. | |
| | | /// Components that exceed 255 are clamped to 255. | |
| /// | | /// | |
|
| /// \param Color1 : First color | | /// \param left Left operand | |
| /// \param Color2 : Second color | | /// \param right Right operand | |
| /// | | /// | |
|
| /// \return Component-wise saturated addition of the two colors | | /// \return Result of \a left + \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| SFML_API Color operator +(const Color& Color1, const Color& Color2); | | SFML_GRAPHICS_API Color operator +(const Color& left, const Color& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload to modulate two colors | | /// \relates Color | |
| | | /// \brief Overload of the binary * operator | |
| /// | | /// | |
|
| /// \param Color1 : First color | | /// This operator returns the component-wise multiplication | |
| /// \param Color2 : Second color | | /// (also called "modulation") of two colors. | |
| | | /// Components are then divided by 255 so that the result is | |
| | | /// still in the range [0, 255]. | |
| /// | | /// | |
|
| /// \return Component-wise multiplication of the two colors | | /// \param left Left operand | |
| | | /// \param right Right operand | |
| | | /// | |
| | | /// \return Result of \a left * \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| SFML_API Color operator *(const Color& Color1, const Color& Color2); | | SFML_GRAPHICS_API Color operator *(const Color& left, const Color& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates Color | |
| | | /// \brief Overload of the binary += operator | |
| | | /// | |
| | | /// This operator computes the component-wise sum of two colors, | |
| | | /// and assigns the result to the left operand. | |
| | | /// Components that exceed 255 are clamped to 255. | |
| | | /// | |
| | | /// \param left Left operand | |
| | | /// \param right Right operand | |
| | | /// | |
| | | /// \return Reference to \a left | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_GRAPHICS_API Color& operator +=(Color& left, const Color& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates Color | |
| | | /// \brief Overload of the binary *= operator | |
| | | /// | |
| | | /// This operator returns the component-wise multiplication | |
| | | /// (also called "modulation") of two colors, and assigns | |
| | | /// the result to the left operand. | |
| | | /// Components are then divided by 255 so that the result is | |
| | | /// still in the range [0, 255]. | |
| | | /// | |
| | | /// \param left Left operand | |
| | | /// \param right Right operand | |
| | | /// | |
| | | /// \return Reference to \a left | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_GRAPHICS_API Color& operator *=(Color& left, const Color& right); | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_COLOR_HPP | | #endif // SFML_COLOR_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Color | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::Color is a simple color class composed of 4 components: | |
| | | /// \li Red | |
| | | /// \li Green | |
| | | /// \li Blue | |
| | | /// \li Alpha (opacity) | |
| | | /// | |
| | | /// Each component is a public member, an unsigned integer in | |
| | | /// the range [0, 255]. Thus, colors can be constructed and | |
| | | /// manipulated very easily: | |
| | | /// | |
| | | /// \code | |
| | | /// sf::Color color(255, 0, 0); // red | |
| | | /// color.r = 0; // make it black | |
| | | /// color.b = 128; // make it dark blue | |
| | | /// \endcode | |
| | | /// | |
| | | /// The fourth component of colors, named "alpha", represents | |
| | | /// the opacity of the color. A color with an alpha value of | |
| | | /// 255 will be fully opaque, while an alpha value of 0 will | |
| | | /// make a color fully transparent, whatever the value of the | |
| | | /// other components is. | |
| | | /// | |
| | | /// The most common colors are already defined as static variables: | |
| | | /// \code | |
| | | /// sf::Color black = sf::Color::Black; | |
| | | /// sf::Color white = sf::Color::White; | |
| | | /// sf::Color red = sf::Color::Red; | |
| | | /// sf::Color green = sf::Color::Green; | |
| | | /// sf::Color blue = sf::Color::Blue; | |
| | | /// sf::Color yellow = sf::Color::Yellow; | |
| | | /// sf::Color magenta = sf::Color::Magenta; | |
| | | /// sf::Color cyan = sf::Color::Cyan; | |
| | | /// sf::Color transparent = sf::Color::Transparent; | |
| | | /// \endcode | |
| | | /// | |
| | | /// Colors can also be added and modulated (multiplied) using the | |
| | | /// overloaded operators + and *. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 21 change blocks. |
| 71 lines changed or deleted | | 108 lines changed or added | |
|
| Config.hpp | | Config.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 29 | | skipping to change at line 29 | |
| // and must not be misrepresented as being the original software. | | // and must not be misrepresented as being the original software. | |
| // | | // | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_CONFIG_HPP | | #ifndef SFML_CONFIG_HPP | |
| #define SFML_CONFIG_HPP | | #define SFML_CONFIG_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | // Define the SFML version | |
| | | //////////////////////////////////////////////////////////// | |
| | | #define SFML_VERSION_MAJOR 2 | |
| | | #define SFML_VERSION_MINOR 0 | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| // Identify the operating system | | // Identify the operating system | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| #if defined(_WIN32) || defined(__WIN32__) | | #if defined(_WIN32) || defined(__WIN32__) | |
| | | | |
| // Windows | | // Windows | |
| #define SFML_SYSTEM_WINDOWS | | #define SFML_SYSTEM_WINDOWS | |
|
| #ifndef WIN32_LEAN_AND_MEAN | | | |
| #define WIN32_LEAN_AND_MEAN | | | |
| #endif | | | |
| #ifndef NOMINMAX | | #ifndef NOMINMAX | |
| #define NOMINMAX | | #define NOMINMAX | |
| #endif | | #endif | |
| | | | |
| #elif defined(linux) || defined(__linux) | | #elif defined(linux) || defined(__linux) | |
| | | | |
| // Linux | | // Linux | |
| #define SFML_SYSTEM_LINUX | | #define SFML_SYSTEM_LINUX | |
| | | | |
| #elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || define
d(Macintosh) | | #elif defined(__APPLE__) || defined(MACOSX) || defined(macintosh) || define
d(Macintosh) | |
| | | | |
| skipping to change at line 74 | | skipping to change at line 77 | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Define a portable debug macro | | // Define a portable debug macro | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| #if !defined(NDEBUG) | | #if !defined(NDEBUG) | |
| | | | |
| #define SFML_DEBUG | | #define SFML_DEBUG | |
| | | | |
| #endif | | #endif | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| // Define portable import / export macros | | // Define helpers to create portable import / export macros for each module | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #if defined(SFML_SYSTEM_WINDOWS) | | #if !defined(SFML_STATIC) | |
| | | | |
| #ifdef SFML_DYNAMIC | | | |
| | | | |
|
| // Windows platforms | | #if defined(SFML_SYSTEM_WINDOWS) | |
| #ifdef SFML_EXPORTS | | | |
| | | | |
|
| // From DLL side, we must export | | // Windows compilers need specific (and different) keywords for exp | |
| #define SFML_API __declspec(dllexport) | | ort and import | |
| | | #define SFML_API_EXPORT __declspec(dllexport) | |
| | | #define SFML_API_IMPORT __declspec(dllimport) | |
| | | | |
|
| #else | | // For Visual C++ compilers, we also need to turn off this annoying | |
| | | C4251 warning | |
| | | #ifdef _MSC_VER | |
| | | | |
|
| // From client application side, we must import | | #pragma warning(disable : 4251) | |
| #define SFML_API __declspec(dllimport) | | | |
| | | | |
| #endif | | #endif | |
| | | | |
|
| // For Visual C++ compilers, we also need to turn off this annoying | | #else // Linux, FreeBSD, Mac OS X | |
| C4251 warning. | | | |
| // You can read lots ot different things about it, but the point is | | | |
| the code will | | | |
| // just work fine, and so the simplest way to get rid of this warni | | | |
| ng is to disable it | | | |
| #ifdef _MSC_VER | | | |
| | | | |
|
| #pragma warning(disable : 4251) | | #if __GNUC__ >= 4 | |
| | | | |
|
| #endif | | // GCC 4 has special keywords for showing/hidding symbols, | |
| | | // the same keyword is used for both importing and exporting | |
| | | #define SFML_API_EXPORT __attribute__ ((__visibility__ ("defaul | |
| | | t"))) | |
| | | #define SFML_API_IMPORT __attribute__ ((__visibility__ ("defaul | |
| | | t"))) | |
| | | | |
|
| #else | | #else | |
| | | | |
| | | // GCC < 4 has no mechanism to explicitely hide symbols, everyt | |
| | | hing's exported | |
| | | #define SFML_API_EXPORT | |
| | | #define SFML_API_IMPORT | |
| | | | |
|
| // No specific directive needed for static build | | #endif | |
| #define SFML_API | | | |
| | | | |
| #endif | | #endif | |
| | | | |
| #else | | #else | |
| | | | |
|
| // Other platforms don't need to define anything | | // Static build doesn't need import/export macros | |
| #define SFML_API | | #define SFML_API_EXPORT | |
| | | #define SFML_API_IMPORT | |
| | | | |
| #endif | | #endif | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Define portable fixed-size types | | // Define portable fixed-size types | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <climits> | | | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| | | // All "common" platforms use the same size for char, short and int | |
| | | // (basically there are 3 types for 3 sizes, so no other match is possi | |
| | | ble), | |
| | | // we can use them without doing any kind of check | |
| | | | |
| // 8 bits integer types | | // 8 bits integer types | |
|
| #if UCHAR_MAX == 0xFF | | typedef signed char Int8; | |
| typedef signed char Int8; | | typedef unsigned char Uint8; | |
| typedef unsigned char Uint8; | | | |
| #else | | | |
| #error No 8 bits integer type for this platform | | | |
| #endif | | | |
| | | | |
| // 16 bits integer types | | // 16 bits integer types | |
|
| #if USHRT_MAX == 0xFFFF | | typedef signed short Int16; | |
| typedef signed short Int16; | | typedef unsigned short Uint16; | |
| typedef unsigned short Uint16; | | | |
| #elif UINT_MAX == 0xFFFF | | | |
| typedef signed int Int16; | | | |
| typedef unsigned int Uint16; | | | |
| #elif ULONG_MAX == 0xFFFF | | | |
| typedef signed long Int16; | | | |
| typedef unsigned long Uint16; | | | |
| #else | | | |
| #error No 16 bits integer type for this platform | | | |
| #endif | | | |
| | | | |
| // 32 bits integer types | | // 32 bits integer types | |
|
| #if USHRT_MAX == 0xFFFFFFFF | | typedef signed int Int32; | |
| typedef signed short Int32; | | typedef unsigned int Uint32; | |
| typedef unsigned short Uint32; | | | |
| #elif UINT_MAX == 0xFFFFFFFF | | // 64 bits integer types | |
| typedef signed int Int32; | | #if defined(_MSC_VER) | |
| typedef unsigned int Uint32; | | typedef signed __int64 Int64; | |
| #elif ULONG_MAX == 0xFFFFFFFF | | typedef unsigned __int64 Uint64; | |
| typedef signed long Int32; | | | |
| typedef unsigned long Uint32; | | | |
| #else | | #else | |
|
| #error No 32 bits integer type for this platform | | typedef signed long long Int64; | |
| | | typedef unsigned long long Uint64; | |
| #endif | | #endif | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_CONFIG_HPP | | #endif // SFML_CONFIG_HPP | |
| | | | |
End of changes. 21 change blocks. |
| 59 lines changed or deleted | | 54 lines changed or added | |
|
| Context.hpp | | Context.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_CONTEXT_HPP | | #ifndef SFML_CONTEXT_HPP | |
| #define SFML_CONTEXT_HPP | | #define SFML_CONTEXT_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Config.hpp> | | #include <SFML/Window/Export.hpp> | |
| | | #include <SFML/Window/GlResource.hpp> | |
| | | #include <SFML/Window/ContextSettings.hpp> | |
| #include <SFML/System/NonCopyable.hpp> | | #include <SFML/System/NonCopyable.hpp> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| namespace priv | | namespace priv | |
| { | | { | |
|
| class WindowImpl; | | class GlContext; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Class wrapping an OpenGL context. | | /// \brief Class holding a valid drawing 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 | | class SFML_WINDOW_API Context : GlResource, NonCopyable | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor, create the context | | /// \brief Default constructor | |
| | | /// | |
| | | /// The constructor creates and activates the context | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Context(); | | Context(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor, destroy the context | | /// \brief Destructor | |
| | | /// | |
| | | /// The desctructor deactivates and destroys the context | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| ~Context(); | | ~Context(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Activate or deactivate the context | | /// \brief Activate or deactivate explicitely the context | |
| /// | | | |
| /// \param Active : True to activate the context, false to deactivate i | | | |
| t | | | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param active True to activate, false to deactivate | |
| 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 | | /// \return True on success, false on failure | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static bool IsContextActive(); | | bool setActive(bool active); | |
| | | | |
| | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the global context | | /// \brief Construct a in-memory context | |
| | | /// | |
| | | /// This constructor is for internal use, you don't need | |
| | | /// to bother with it. | |
| /// | | /// | |
|
| /// \return Reference to the global context | | /// \param settings Creation parameters | |
| | | /// \param width Back buffer width | |
| | | /// \param height Back buffer height | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Context& GetGlobal(); | | Context(const ContextSettings& settings, unsigned int width, unsigned i
nt height); | |
| | | | |
| private : | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| priv::WindowImpl* myDummyWindow; ///< Dummy window holding the context | | priv::GlContext* m_context; ///< Internal OpenGL context | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_CONTEXT_HPP | | #endif // SFML_CONTEXT_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Context | |
| | | /// \ingroup window | |
| | | /// | |
| | | /// If you need to make OpenGL calls without having an | |
| | | /// active window (like in a thread), you can use an | |
| | | /// instance of this class to get a valid context. | |
| | | /// | |
| | | /// Having a valid context is necessary for *every* OpenGL call. | |
| | | /// | |
| | | /// Note that a context is only active in its current thread, | |
| | | /// if you create a new thread it will have no valid context | |
| | | /// by default. | |
| | | /// | |
| | | /// To use a sf::Context instance, just construct it and let it | |
| | | /// live as long as you need a valid context. No explicit activation | |
| | | /// is needed, all it has to do is to exist. Its destructor | |
| | | /// will take care of deactivating and freeing all the attached | |
| | | /// resources. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// void threadFunction(void*) | |
| | | /// { | |
| | | /// sf::Context context; | |
| | | /// // from now on, you have a valid context | |
| | | /// | |
| | | /// // you can make OpenGL calls | |
| | | /// glClear(GL_DEPTH_BUFFER_BIT); | |
| | | /// } | |
| | | /// // the context is automatically deactivated and destroyed | |
| | | /// // by the sf::Context destructor | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 16 change blocks. |
| 26 lines changed or deleted | | 29 lines changed or added | |
|
| Drawable.hpp | | Drawable.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_DRAWABLE_HPP | | #ifndef SFML_DRAWABLE_HPP | |
| #define SFML_DRAWABLE_HPP | | #define SFML_DRAWABLE_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/System/Vector2.hpp> | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/Graphics/Color.hpp> | | #include <SFML/Graphics/RenderStates.hpp> | |
| #include <SFML/Graphics/Matrix3.hpp> | | | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| class RenderTarget; | | class RenderTarget; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumerate the blending modes for drawable objects | | /// \brief Abstract base class for objects that can be drawn | |
| | | /// to a render target | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| namespace Blend | | class SFML_GRAPHICS_API Drawable | |
| { | | | |
| 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 : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Virtual destructor | |
| /// | | | |
| /// \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& Sca | | | |
| le = Vector2f(1, 1), float Rotation = 0.f, const Color& Col = Color(255, 25 | | | |
| 5, 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; | | virtual ~Drawable() {} | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// 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 posit | | | |
| ive) | | | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| 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, rotatio | | | |
| n 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 : | | 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; | | friend class RenderTarget; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Draw the object into the specified window | | /// \brief Draw the object to a render target | |
| /// | | /// | |
|
| /// \param Target : Target into which render the object | | /// This is a pure virtual function that has to be implemented | |
| | | /// by the derived class to define how the drawable should be | |
| | | /// drawn. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param target Render target to draw to | |
| void Draw(RenderTarget& Target) const; | | /// \param states Current render states | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// 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 | | virtual void draw(RenderTarget& target, RenderStates states) const = 0; | |
| Vector2f myScale; ///< Scale of the object | | | |
| Vector2f myCenter; ///< Origin of translation / rotation | | | |
| / scaling of the object | | | |
| float myRotation; ///< Orientation of the object, in deg | | | |
| rees | | | |
| Color myColor; ///< Overlay color of the object | | | |
| Blend::Mode myBlendMode; ///< Blending mode | | | |
| mutable bool myNeedUpdate; ///< Do we need to recompute the trans | | | |
| form matrix ? | | | |
| mutable bool myInvNeedUpdate; ///< Do we need to recompute the inver | | | |
| se transform matrix ? | | | |
| mutable Matrix3 myMatrix; ///< Precomputed transform matrix gath | | | |
| ering the translation / rotation / scale / center | | | |
| mutable Matrix3 myInvMatrix; ///< Precomputed inverse transform mat | | | |
| rix gathering the translation / rotation / scale / center | | | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_DRAWABLE_HPP | | #endif // SFML_DRAWABLE_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Drawable | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::Drawable is a very simple base class that allows objects | |
| | | /// of derived classes to be drawn to a sf::RenderTarget. | |
| | | /// | |
| | | /// All you have to do in your derived class is to override the | |
| | | /// draw virtual function. | |
| | | /// | |
| | | /// Note that inheriting from sf::Drawable is not mandatory, | |
| | | /// but it allows this nice syntax "window.draw(object)" rather | |
| | | /// than "object.draw(window)", which is more consistent with other | |
| | | /// SFML classes. | |
| | | /// | |
| | | /// Example: | |
| | | /// \code | |
| | | /// class MyDrawable : public sf::Drawable | |
| | | /// { | |
| | | /// public : | |
| | | /// | |
| | | /// ... | |
| | | /// | |
| | | /// private : | |
| | | /// | |
| | | /// virtual void draw(sf::RenderTarget& target, sf::RenderStates states | |
| | | ) const | |
| | | /// { | |
| | | /// // You can draw other high-level objects | |
| | | /// target.draw(m_sprite, states); | |
| | | /// | |
| | | /// // ... or use the low-level API | |
| | | /// states.texture = &m_texture; | |
| | | /// target.draw(m_vertices, states); | |
| | | /// | |
| | | /// // ... or draw with OpenGL directly | |
| | | /// glBegin(GL_QUADS); | |
| | | /// ... | |
| | | /// glEnd(); | |
| | | /// } | |
| | | /// | |
| | | /// sf::Sprite m_sprite; | |
| | | /// sf::Texture m_texture; | |
| | | /// sf::VertexArray m_vertices; | |
| | | /// }; | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::RenderTarget | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 13 change blocks. |
| 313 lines changed or deleted | | 16 lines changed or added | |
|
| Event.hpp | | Event.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 32 | | skipping to change at line 32 | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_EVENT_HPP | | #ifndef SFML_EVENT_HPP | |
| #define SFML_EVENT_HPP | | #define SFML_EVENT_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| #include <SFML/Config.hpp> | | #include <SFML/Config.hpp> | |
|
| | | #include <SFML/Window/Joystick.hpp> | |
| | | #include <SFML/Window/Keyboard.hpp> | |
| | | #include <SFML/Window/Mouse.hpp> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Definition of key codes for keyboard events | | /// \brief Defines a system event and its parameters | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| namespace Key | | class Event | |
| { | | | |
| 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 L | | | |
| inux), 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 | | public : | |
| { | | | |
| AxisX, | | | |
| AxisY, | | | |
| AxisZ, | | | |
| AxisR, | | | |
| AxisU, | | | |
| AxisV, | | | |
| AxisPOV, | | | |
| | | | |
| AxisCount // Keep last -- total number of joystick axis | | | |
| }; | | | |
| | | | |
|
| enum | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Size events parameters (Resized) | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | struct SizeEvent | |
| { | | { | |
|
| Count = 4, ///< Total number of supported joysticks | | unsigned int width; ///< New width, in pixels | |
| ButtonCount = 32 ///< Total number of supported joystick buttons | | unsigned int height; ///< New height, in pixels | |
| }; | | }; | |
|
| } | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Event defines a system event and its parameters | | | |
| //////////////////////////////////////////////////////////// | | | |
| class Event | | | |
| { | | | |
| public : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Keyboard event parameters | | /// \brief Keyboard event parameters (KeyPressed, KeyReleased) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| struct KeyEvent | | struct KeyEvent | |
| { | | { | |
|
| Key::Code Code; | | Keyboard::Key code; ///< Code of the key that has been pressed | |
| bool Alt; | | bool alt; ///< Is the Alt key pressed? | |
| bool Control; | | bool control; ///< Is the Control key pressed? | |
| bool Shift; | | bool shift; ///< Is the Shift key pressed? | |
| | | bool system; ///< Is the System key pressed? | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Text event parameters | | /// \brief Text event parameters (TextEntered) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| struct TextEvent | | struct TextEvent | |
| { | | { | |
|
| Uint32 Unicode; | | Uint32 unicode; ///< UTF-32 unicode value of the character | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Mouse move event parameters | | /// \brief Mouse move event parameters (MouseMoved) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| struct MouseMoveEvent | | struct MouseMoveEvent | |
| { | | { | |
|
| int X; | | int x; ///< X position of the mouse pointer, relative to the left o | |
| int Y; | | f the owner window | |
| | | int y; ///< Y position of the mouse pointer, relative to the top of | |
| | | the owner window | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Mouse buttons events parameters | | /// \brief Mouse buttons events parameters | |
| | | /// (MouseButtonPressed, MouseButtonReleased) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| struct MouseButtonEvent | | struct MouseButtonEvent | |
| { | | { | |
|
| Mouse::Button Button; | | Mouse::Button button; ///< Code of the button that has been pressed | |
| int X; | | int x; ///< X position of the mouse pointer, relativ | |
| int Y; | | e to the left of the owner window | |
| | | int y; ///< Y position of the mouse pointer, relativ | |
| | | e to the top of the owner window | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Mouse wheel events parameters | | /// \brief Mouse wheel events parameters (MouseWheelMoved) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| struct MouseWheelEvent | | struct MouseWheelEvent | |
| { | | { | |
|
| int Delta; | | int delta; ///< Number of ticks the wheel has moved (positive is up | |
| | | , negative is down) | |
| | | int x; ///< X position of the mouse pointer, relative to the le | |
| | | ft of the owner window | |
| | | int y; ///< Y position of the mouse pointer, relative to the to | |
| | | p of the owner window | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Joystick axis move event parameters | | /// \brief Joystick connection events parameters | |
| | | /// (JoystickConnected, JoystickDisconnected) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| struct JoyMoveEvent | | struct JoystickConnectEvent | |
| { | | { | |
|
| unsigned int JoystickId; | | unsigned int joystickId; ///< Index of the joystick (in range [0 .. | |
| Joy::Axis Axis; | | Joystick::Count - 1]) | |
| float Position; | | | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Joystick buttons events parameters | | /// \brief Joystick axis move event parameters (JoystickMoved) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| struct JoyButtonEvent | | struct JoystickMoveEvent | |
| { | | { | |
|
| unsigned int JoystickId; | | unsigned int joystickId; ///< Index of the joystick (in range [0 | |
| unsigned int Button; | | .. Joystick::Count - 1]) | |
| | | Joystick::Axis axis; ///< Axis on which the joystick moved | |
| | | float position; ///< New position on the axis (in range | |
| | | [-100 .. 100]) | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Size events parameters | | /// \brief Joystick buttons events parameters | |
| | | /// (JoystickButtonPressed, JoystickButtonReleased) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| struct SizeEvent | | struct JoystickButtonEvent | |
| { | | { | |
|
| unsigned int Width; | | unsigned int joystickId; ///< Index of the joystick (in range [0 .. | |
| unsigned int Height; | | Joystick::Count - 1]) | |
| | | unsigned int button; ///< Index of the button that has been pre | |
| | | ssed (in range [0 .. Joystick::ButtonCount - 1]) | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumeration of the different types of events | | /// \brief Enumeration of the different types of events | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| enum EventType | | enum EventType | |
| { | | { | |
|
| Closed, | | Closed, ///< The window requested to be closed (no | |
| Resized, | | data) | |
| LostFocus, | | Resized, ///< The window was resized (data in event. | |
| GainedFocus, | | size) | |
| TextEntered, | | LostFocus, ///< The window lost the focus (no data) | |
| KeyPressed, | | GainedFocus, ///< The window gained the focus (no data) | |
| KeyReleased, | | TextEntered, ///< A character was entered (data in event | |
| MouseWheelMoved, | | .text) | |
| MouseButtonPressed, | | KeyPressed, ///< A key was pressed (data in event.key) | |
| MouseButtonReleased, | | KeyReleased, ///< A key was released (data in event.key) | |
| MouseMoved, | | MouseWheelMoved, ///< The mouse wheel was scrolled (data in | |
| MouseEntered, | | event.mouseWheel) | |
| MouseLeft, | | MouseButtonPressed, ///< A mouse button was pressed (data in ev | |
| JoyButtonPressed, | | ent.mouseButton) | |
| JoyButtonReleased, | | MouseButtonReleased, ///< A mouse button was released (data in e | |
| JoyMoved, | | vent.mouseButton) | |
| | | MouseMoved, ///< The mouse cursor moved (data in event. | |
| | | mouseMove) | |
| | | MouseEntered, ///< The mouse cursor entered the area of t | |
| | | he window (no data) | |
| | | MouseLeft, ///< The mouse cursor left the area of the | |
| | | window (no data) | |
| | | JoystickButtonPressed, ///< A joystick button was pressed (data in | |
| | | event.joystickButton) | |
| | | JoystickButtonReleased, ///< A joystick button was released (data i | |
| | | n event.joystickButton) | |
| | | JoystickMoved, ///< The joystick moved along an axis (data | |
| | | in event.joystickMove) | |
| | | JoystickConnected, ///< A joystick was connected (data in even | |
| | | t.joystickConnect) | |
| | | JoystickDisconnected, ///< A joystick was disconnected (data in e | |
| | | vent.joystickConnect) | |
| | | | |
|
| Count // Keep last -- total number of event types | | Count ///< Keep last -- the total number of event
types | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| EventType Type; ///< Type of the event | | EventType type; ///< Type of the event | |
| | | | |
| union | | union | |
| { | | { | |
|
| KeyEvent Key; | | SizeEvent size; ///< Size event parameters (E | |
| TextEvent Text; | | vent::Resized) | |
| MouseMoveEvent MouseMove; | | KeyEvent key; ///< Key event parameters (Ev | |
| MouseButtonEvent MouseButton; | | ent::KeyPressed, Event::KeyReleased) | |
| MouseWheelEvent MouseWheel; | | TextEvent text; ///< Text event parameters (E | |
| JoyMoveEvent JoyMove; | | vent::TextEntered) | |
| JoyButtonEvent JoyButton; | | MouseMoveEvent mouseMove; ///< Mouse move event paramet | |
| SizeEvent Size; | | ers (Event::MouseMoved) | |
| | | MouseButtonEvent mouseButton; ///< Mouse button event param | |
| | | eters (Event::MouseButtonPressed, Event::MouseButtonReleased) | |
| | | MouseWheelEvent mouseWheel; ///< Mouse wheel event parame | |
| | | ters (Event::MouseWheelMoved) | |
| | | JoystickMoveEvent joystickMove; ///< Joystick move event para | |
| | | meters (Event::JoystickMoved) | |
| | | JoystickButtonEvent joystickButton; ///< Joystick button event pa | |
| | | rameters (Event::JoystickButtonPressed, Event::JoystickButtonReleased) | |
| | | JoystickConnectEvent joystickConnect; ///< Joystick (dis)connect ev | |
| | | ent parameters (Event::JoystickConnected, Event::JoystickDisconnected) | |
| }; | | }; | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_EVENT_HPP | | #endif // SFML_EVENT_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Event | |
| | | /// \ingroup window | |
| | | /// | |
| | | /// sf::Event holds all the informations about a system event | |
| | | /// that just happened. Events are retrieved using the | |
| | | /// sf::Window::pollEvent and sf::Window::waitEvent functions. | |
| | | /// | |
| | | /// A sf::Event instance contains the type of the event | |
| | | /// (mouse moved, key pressed, window closed, ...) as well | |
| | | /// as the details about this particular event. Please note that | |
| | | /// the event parameters are defined in a union, which means that | |
| | | /// only the member matching the type of the event will be properly | |
| | | /// filled; all other members will have undefined values and must not | |
| | | /// be read if the type of the event doesn't match. For example, | |
| | | /// if you received a KeyPressed event, then you must read the | |
| | | /// event.key member, all other members such as event.MouseMove | |
| | | /// or event.text will have undefined values. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// sf::Event event; | |
| | | /// while (window.pollEvent(event)) | |
| | | /// { | |
| | | /// // Request for closing the window | |
| | | /// if (event.type == sf::Event::Closed) | |
| | | /// window.close(); | |
| | | /// | |
| | | /// // The escape key was pressed | |
| | | /// if ((event.type == sf::Event::KeyPressed) && (event.key.code == sf: | |
| | | :Keyboard::Escape)) | |
| | | /// window.close(); | |
| | | /// | |
| | | /// // The window was resized | |
| | | /// if (event.type == sf::Event::Resized) | |
| | | /// doSomethingWithTheNewSize(event.size.width, event.size.height); | |
| | | /// | |
| | | /// // etc ... | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 33 change blocks. |
| 214 lines changed or deleted | | 123 lines changed or added | |
|
| Font.hpp | | Font.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_FONT_HPP | | #ifndef SFML_FONT_HPP | |
| #define SFML_FONT_HPP | | #define SFML_FONT_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/System/Resource.hpp> | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/System/Vector2.hpp> | | | |
| #include <SFML/System/Unicode.hpp> | | | |
| #include <SFML/Graphics/Glyph.hpp> | | #include <SFML/Graphics/Glyph.hpp> | |
|
| #include <SFML/Graphics/Image.hpp> | | #include <SFML/Graphics/Texture.hpp> | |
| #include <SFML/Graphics/Rect.hpp> | | #include <SFML/Graphics/Rect.hpp> | |
|
| | | #include <SFML/System/Vector2.hpp> | |
| | | #include <SFML/System/String.hpp> | |
| #include <map> | | #include <map> | |
| #include <string> | | #include <string> | |
|
| | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| class String; | | class InputStream; | |
| | | | |
|
| namespace priv | | | |
| { | | | |
| class FontLoader; | | | |
| } | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Font is the low-level class for loading and | | /// \brief Class for loading and manipulating character fonts | |
| /// manipulating character fonts. This class is meant to | | /// | |
| /// be used by sf::String | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Font : public Resource<Font> | | class SFML_GRAPHICS_API Font | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// This constructor defines an empty font | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Font(); | | Font(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Load the font from a file | | /// \brief Copy constructor | |
| | | /// | |
| | | /// \param copy Instance to copy | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Font(const Font& copy); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Destructor | |
| | | /// | |
| | | /// Cleans up all the internal resources used by the font | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | ~Font(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Load the font from a file | |
| | | /// | |
| | | /// The supported font formats are: TrueType, Type 1, CFF, | |
| | | /// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42. | |
| | | /// Note that this function know nothing about the standard | |
| | | /// fonts installed on the user's system, thus you can't | |
| | | /// load them directly. | |
| | | /// | |
| | | /// \param filename Path of the font file to load | |
| | | /// | |
| | | /// \return True if loading succeeded, false if it failed | |
| | | /// | |
| | | /// \see loadFromMemory, loadFromStream | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | bool loadFromFile(const std::string& filename); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Load the font from a file in memory | |
| | | /// | |
| | | /// The supported font formats are: TrueType, Type 1, CFF, | |
| | | /// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42. | |
| | | /// Warning: SFML cannot preload all the font data in this | |
| | | /// function, so the buffer pointed by \a data has to remain | |
| | | /// valid as long as the font is used. | |
| | | /// | |
| | | /// \param data Pointer to the file data in memory | |
| | | /// \param sizeInBytes Size of the data to load, in bytes | |
| /// | | /// | |
|
| /// \param Filename : Font file to load | | /// \return True if loading succeeded, false if it failed | |
| /// \param CharSize : Size of characters in bitmap - the bigger, the hi | | | |
| gher 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 | | /// \see loadFromFile, loadFromStream | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool LoadFromFile(const std::string& Filename, unsigned int CharSize =
30, const Unicode::Text& Charset = ourDefaultCharset); | | bool loadFromMemory(const void* data, std::size_t sizeInBytes); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Load the font from a file in memory | | /// \brief Load the font from a custom stream | |
| /// | | /// | |
|
| /// \param Data : Pointer to the data to load | | /// The supported font formats are: TrueType, Type 1, CFF, | |
| /// \param SizeInBytes : Size of the data, in bytes | | /// OpenType, SFNT, X11 PCF, Windows FNT, BDF, PFR and Type 42. | |
| /// \param CharSize : Size of characters in bitmap - the bigger, the | | /// Warning: SFML cannot preload all the font data in this | |
| higher quality (30 by default) | | /// function, so the contents of \a stream have to remain | |
| /// \param Charset : Characters set to generate (by default, contai | | /// valid as long as the font is used. | |
| ns the ISO-8859-1 printable characters) | | | |
| /// | | /// | |
|
| /// \return True if loading was successful | | /// \param stream Source stream to read from | |
| | | /// | |
| | | /// \return True if loading succeeded, false if it failed | |
| | | /// | |
| | | /// \see loadFromFile, loadFromMemory | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool LoadFromMemory(const char* Data, std::size_t SizeInBytes, unsigned
int CharSize = 30, const Unicode::Text& Charset = ourDefaultCharset); | | bool loadFromStream(InputStream& stream); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the base size of characters in the font; | | /// \brief Retrieve a glyph of the font | |
| /// All glyphs dimensions are based on this value | | /// | |
| | | /// \param codePoint Unicode code point of the character to get | |
| | | /// \param characterSize Reference character size | |
| | | /// \param bold Retrieve the bold version or the regular one? | |
| /// | | /// | |
|
| /// \return Base size of characters | | /// \return The glyph corresponding to \a codePoint and \a characterSiz
e | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetCharacterSize() const; | | const Glyph& getGlyph(Uint32 codePoint, unsigned int characterSize, boo
l bold) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the description of a glyph (character) | | /// \brief Get the kerning offset of two glyphs | |
| /// given by its unicode value | | | |
| /// | | /// | |
|
| /// \param CodePoint : Unicode value of the character to get | | /// The kerning is an extra offset (negative) to apply between two | |
| | | /// glyphs when rendering them, to make the pair look more "natural". | |
| | | /// For example, the pair "AV" have a special kerning to make them | |
| | | /// closer than other characters. Most of the glyphs pairs have a | |
| | | /// kerning offset of zero, though. | |
| /// | | /// | |
|
| /// \return Glyph's visual settings, or an invalid glyph if character n | | /// \param first Unicode code point of the first character | |
| ot found | | /// \param second Unicode code point of the second character | |
| | | /// \param characterSize Reference character size | |
| | | /// | |
| | | /// \return Kerning value for \a first and \a second, in pixels | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Glyph& GetGlyph(Uint32 CodePoint) const; | | int getKerning(Uint32 first, Uint32 second, unsigned int characterSize)
const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the image containing the rendered characters (glyphs) | | /// \brief Get the line spacing | |
| | | /// | |
| | | /// Line spacing is the vertical offset to apply between two | |
| | | /// consecutive lines of text. | |
| /// | | /// | |
|
| /// \return Image containing glyphs | | /// \param characterSize Reference character size | |
| | | /// | |
| | | /// \return Line spacing, in pixels | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Image& GetImage() const; | | int getLineSpacing(unsigned int characterSize) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the SFML default built-in font (Arial) | | /// \brief Retrieve the texture containing the loaded glyphs of a certa | |
| | | in size | |
| | | /// | |
| | | /// The contents of the returned texture changes as more glyphs | |
| | | /// are requested, thus it is not very relevant. It is mainly | |
| | | /// used internally by sf::Text. | |
| | | /// | |
| | | /// \param characterSize Reference character size | |
| | | /// | |
| | | /// \return Texture containing the glyphs of the requested size | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | const Texture& getTexture(unsigned int characterSize) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Overload of assignment operator | |
| | | /// | |
| | | /// \param right Instance to assign | |
| /// | | /// | |
|
| /// \return Instance of the default font | | /// \return Reference to self | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static const Font& GetDefaultFont(); | | Font& operator =(const Font& right); | |
| | | | |
| private : | | private : | |
| | | | |
|
| friend class priv::FontLoader; | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Structure defining a row of glyphs | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | struct Row | |
| | | { | |
| | | Row(unsigned int rowTop, unsigned int rowHeight) : width(0), top(ro | |
| | | wTop), height(rowHeight) {} | |
| | | | |
| | | unsigned int width; ///< Current width of the row | |
| | | unsigned int top; ///< Y position of the row into the texture | |
| | | unsigned int height; ///< Height of the row | |
| | | }; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | // Types | |
| | | //////////////////////////////////////////////////////////// | |
| | | typedef std::map<Uint32, Glyph> GlyphTable; ///< Table mapping a codepo | |
| | | int to its glyph | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| // Static member data | | /// \brief Structure defining a page of glyphs | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | struct Page | |
| | | { | |
| | | Page(); | |
| | | | |
| | | GlyphTable glyphs; ///< Table mapping code points to their c | |
| | | orresponding glyph | |
| | | sf::Texture texture; ///< Texture containing the pixels of the | |
| | | glyphs | |
| | | unsigned int nextRow; ///< Y position of the next new row in th | |
| | | e texture | |
| | | std::vector<Row> rows; ///< List containing the position of all | |
| | | the existing rows | |
| | | }; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Free all the internal resources | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void cleanup(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Load a new glyph and store it in the cache | |
| | | /// | |
| | | /// \param codePoint Unicode code point of the character to load | |
| | | /// \param characterSize Reference character size | |
| | | /// \param bold Retrieve the bold version or the regular one? | |
| | | /// | |
| | | /// \return The glyph corresponding to \a codePoint and \a characterSiz | |
| | | e | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Uint32 ourDefaultCharset[]; ///< The default charset (all printa | | Glyph loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold | |
| ble ISO-8859-1 characters) | | ) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Find a suitable rectangle within the texture for a glyph | |
| | | /// | |
| | | /// \param page Page of glyphs to search in | |
| | | /// \param width Width of the rectangle | |
| | | /// \param height Height of the rectangle | |
| | | /// | |
| | | /// \return Found rectangle within the texture | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | IntRect findGlyphRect(Page& page, unsigned int width, unsigned int heig | |
| | | ht) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Make sure that the given size is the current one | |
| | | /// | |
| | | /// \param characterSize Reference character size | |
| | | /// | |
| | | /// \return True on success, false if any error happened | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | bool setCurrentSize(unsigned int characterSize) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | // Types | |
| | | //////////////////////////////////////////////////////////// | |
| | | typedef std::map<unsigned int, Page> PageTable; ///< Table mapping a ch | |
| | | aracter size to its page (texture) | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Image myTexture; ///< Texture holding the bitmap fon | | void* m_library; ///< Pointer to the internal | |
| t | | library interface (it is typeless to avoid exposing implementation details) | |
| unsigned int myCharSize; ///< Size of characters in the bitm | | void* m_face; ///< Pointer to the internal | |
| ap font | | font face (it is typeless to avoid exposing implementation details) | |
| std::map<Uint32, Glyph> myGlyphs; ///< Rendering settings of each cha | | void* m_streamRec; ///< Pointer to the stream re | |
| racter (glyph) | | c instance (it is typeless to avoid exposing implementation details) | |
| | | int* m_refCount; ///< Reference counter used b | |
| | | y implicit sharing | |
| | | mutable PageTable m_pages; ///< Table containing the gly | |
| | | phs pages by character size | |
| | | mutable std::vector<Uint8> m_pixelBuffer; ///< Pixel buffer holding a g | |
| | | lyph's pixels before being written to the texture | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_FONT_HPP | | #endif // SFML_FONT_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Font | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// Fonts can be loaded from a file, from memory or from a custom | |
| | | /// stream, and supports the most common types of fonts. See | |
| | | /// the loadFromFile function for the complete list of supported formats. | |
| | | /// | |
| | | /// Once it is loaded, a sf::Font instance provides three | |
| | | /// types of information about the font: | |
| | | /// \li Global metrics, such as the line spacing | |
| | | /// \li Per-glyph metrics, such as bounding box or kerning | |
| | | /// \li Pixel representation of glyphs | |
| | | /// | |
| | | /// Fonts alone are not very useful: they hold the font data | |
| | | /// but cannot make anything useful of it. To do so you need to | |
| | | /// use the sf::Text class, which is able to properly output text | |
| | | /// with several options such as character size, style, color, | |
| | | /// position, rotation, etc. | |
| | | /// This separation allows more flexibility and better performances: | |
| | | /// indeed a sf::Font is a heavy resource, and any operation on it | |
| | | /// is slow (often too slow for real-time applications). On the other | |
| | | /// side, a sf::Text is a lightweight object which can combine the | |
| | | /// glyphs data and metrics of a sf::Font to display any text on a | |
| | | /// render target. | |
| | | /// Note that it is also possible to bind several sf::Text instances | |
| | | /// to the same sf::Font. | |
| | | /// | |
| | | /// It is important to note that the sf::Text instance doesn't | |
| | | /// copy the font that it uses, it only keeps a reference to it. | |
| | | /// Thus, a sf::Font must not be destructed while it is | |
| | | /// used by a sf::Text (i.e. never write a function that | |
| | | /// uses a local sf::Font instance for creating a text). | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Declare a new font | |
| | | /// sf::Font font; | |
| | | /// | |
| | | /// // Load it from a file | |
| | | /// if (!font.loadFromFile("arial.ttf")) | |
| | | /// { | |
| | | /// // error... | |
| | | /// } | |
| | | /// | |
| | | /// // Create a text which uses our font | |
| | | /// sf::Text text1; | |
| | | /// text1.setFont(font); | |
| | | /// text1.setCharacterSize(30); | |
| | | /// text1.setStyle(sf::Text::Regular); | |
| | | /// | |
| | | /// // Create another text using the same font, but with different paramete | |
| | | rs | |
| | | /// sf::Text text2; | |
| | | /// text2.setFont(font); | |
| | | /// text2.setCharacterSize(50); | |
| | | /// text1.setStyle(sf::Text::Italic); | |
| | | /// \endcode | |
| | | /// | |
| | | /// Apart from loading font files, and passing them to instances | |
| | | /// of sf::Text, you should normally not have to deal directly | |
| | | /// with this class. However, it may be useful to access the | |
| | | /// font metrics or rasterized glyphs for advanced usage. | |
| | | /// | |
| | | /// \see sf::Text | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 36 change blocks. |
| 58 lines changed or deleted | | 214 lines changed or added | |
|
| Ftp.hpp | | Ftp.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_FTP_HPP | | #ifndef SFML_FTP_HPP | |
| #define SFML_FTP_HPP | | #define SFML_FTP_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/Network/Export.hpp> | |
| | | #include <SFML/Network/TcpSocket.hpp> | |
| #include <SFML/System/NonCopyable.hpp> | | #include <SFML/System/NonCopyable.hpp> | |
|
| #include <SFML/Network/SocketTCP.hpp> | | #include <SFML/System/Time.hpp> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| class IPAddress; | | class IpAddress; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// This class provides methods for manipulating the FTP | | /// \brief A FTP client | |
| /// 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 | | class SFML_NETWORK_API Ftp : NonCopyable | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumeration of transfer modes | | /// \brief Enumeration of transfer modes | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| enum TransferMode | | enum TransferMode | |
| { | | { | |
| Binary, ///< Binary mode (file is transfered as a sequence of bytes
) | | Binary, ///< Binary mode (file is transfered as a sequence of bytes
) | |
| Ascii, ///< Text mode using ASCII encoding | | Ascii, ///< Text mode using ASCII encoding | |
| Ebcdic ///< Text mode using EBCDIC encoding | | Ebcdic ///< Text mode using EBCDIC encoding | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// This class wraps a FTP response, which is basically : | | /// \brief Define a FTP response | |
| /// - a status code | | /// | |
| /// - a message | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Response | | class SFML_NETWORK_API Response | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumerate all the valid status codes returned in | | /// \brief Status codes possibly returned by a FTP response | |
| /// a FTP response | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| enum Status | | enum Status | |
| { | | { | |
| // 1xx: the requested action is being initiated, | | // 1xx: the requested action is being initiated, | |
| // expect another reply before proceeding with a new command | | // expect another reply before proceeding with a new command | |
| RestartMarkerReply = 110, ///< Restart marker reply | | RestartMarkerReply = 110, ///< Restart marker reply | |
| ServiceReadySoon = 120, ///< Service ready in N minu
tes | | ServiceReadySoon = 120, ///< Service ready in N minu
tes | |
| DataConnectionAlreadyOpened = 125, ///< Data connection already
opened, transfer starting | | DataConnectionAlreadyOpened = 125, ///< Data connection already
opened, transfer starting | |
| OpeningDataConnection = 150, ///< File status ok, about t
o open data connection | | OpeningDataConnection = 150, ///< File status ok, about t
o open data connection | |
| | | | |
| | | | |
| skipping to change at line 136 | | skipping to change at line 136 | |
| FilenameNotAllowed = 553, ///< Requested action not taken,
file name not allowed | | FilenameNotAllowed = 553, ///< Requested action not taken,
file name not allowed | |
| | | | |
| // 10xx: SFML custom codes | | // 10xx: SFML custom codes | |
| InvalidResponse = 1000, ///< Response is not a valid FTP one | | InvalidResponse = 1000, ///< Response is not a valid FTP one | |
| ConnectionFailed = 1001, ///< Connection with server failed | | ConnectionFailed = 1001, ///< Connection with server failed | |
| ConnectionClosed = 1002, ///< Connection with server closed | | ConnectionClosed = 1002, ///< Connection with server closed | |
| InvalidFile = 1003 ///< Invalid file to upload / download | | InvalidFile = 1003 ///< Invalid file to upload / download | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| /// | | /// | |
|
| /// \param Code : Response status code (InvalidResponse by defau | | /// This constructor is used by the FTP client to build | |
| lt) | | /// the response. | |
| /// \param Message : Response message (empty by default) | | /// | |
| | | /// \param code Response status code | |
| | | /// \param message Response message | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response(Status Code = InvalidResponse, const std::string& Message
= ""); | | explicit Response(Status code = InvalidResponse, const std::string&
message = ""); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Convenience function to check if the response status code | | /// \brief Check if the status code means a success | |
| /// means a success | | /// | |
| | | /// This function is defined for convenience, it is | |
| | | /// equivalent to testing if the status code is < 400. | |
| /// | | /// | |
|
| /// \return True if status is success (code < 400) | | /// \return True if the status is a success, false if it is a failu
re | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool IsOk() const; | | bool isOk() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the response status code | | /// \brief Get the status code of the response | |
| /// | | /// | |
| /// \return Status code | | /// \return Status code | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Status GetStatus() const; | | Status getStatus() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the full message contained in the response | | /// \brief Get the full message contained in the response | |
| /// | | /// | |
| /// \return The response message | | /// \return The response message | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const std::string& GetMessage() const; | | const std::string& getMessage() const; | |
| | | | |
| private : | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Status myStatus; ///< Status code returned from the server | | Status m_status; ///< Status code returned from the server | |
| std::string myMessage; ///< Last message received from the server | | std::string m_message; ///< Last message received from the server | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Specialization of FTP response returning a directory | | /// \brief Specialization of FTP response returning a directory | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API DirectoryResponse : public Response | | class SFML_NETWORK_API DirectoryResponse : public Response | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| /// | | /// | |
|
| /// \param Resp : Source response | | /// \param response Source response | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| DirectoryResponse(Response Resp); | | DirectoryResponse(const Response& response); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the directory returned in the response | | /// \brief Get the directory returned in the response | |
| /// | | /// | |
| /// \return Directory name | | /// \return Directory name | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const std::string& GetDirectory() const; | | const std::string& getDirectory() const; | |
| | | | |
| private : | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::string myDirectory; ///< Directory extracted from the response
message | | std::string m_directory; ///< Directory extracted from the response
message | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Specialization of FTP response returning a filename lisiting | | /// \brief Specialization of FTP response returning a | |
| | | /// filename lisiting | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API ListingResponse : public Response | | class SFML_NETWORK_API ListingResponse : public Response | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| /// | | | |
| /// \param Resp : Source response | | | |
| /// \param Data : Data containing the raw listing | | | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| ListingResponse(Response Resp, const std::vector<char>& Data); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Get the number of filenames in the listing | | | |
| /// | | /// | |
|
| /// \return Total number of filenames | | /// \param response Source response | |
| | | /// \param data Data containing the raw listing | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::size_t GetCount() const; | | ListingResponse(const Response& response, const std::vector<char>&
data); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the Index-th filename in the directory | | /// \brief Return the array of directory/file names | |
| /// | | /// | |
|
| /// \param Index : Index of the filename to get | | /// \return Array containing the requested listing | |
| /// | | | |
| /// \return Index-th filename | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const std::string& GetFilename(std::size_t Index) const; | | const std::vector<std::string>& getListing() const; | |
| | | | |
| private : | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::vector<std::string> myFilenames; ///< Filenames extracted from
the data | | std::vector<std::string> m_listing; ///< Directory/file names extra
cted from the data | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor -- close the connection with the server | | /// \brief Destructor | |
| | | /// | |
| | | /// Automatically closes the connection with the server if | |
| | | /// it is still opened. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| ~Ftp(); | | ~Ftp(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Connect to the specified FTP server | | /// \brief Connect to the specified FTP server | |
| | | /// | |
| | | /// The port has a default value of 21, which is the standard | |
| | | /// port used by the FTP protocol. You shouldn't use a different | |
| | | /// value, unless you really know what you do. | |
| | | /// This function tries to connect to the server so it may take | |
| | | /// a while to complete, especially if the server is not | |
| | | /// reachable. To avoid blocking your application for too long, | |
| | | /// you can use a timeout. The default value, Time::Zero, means that th | |
| | | e | |
| | | /// system timeout will be used (which is usually pretty long). | |
| /// | | /// | |
|
| /// \param Server : FTP server to connect to | | /// \param server Name or address of the FTP server to connect to | |
| /// \param Port : Port used for connection (21 by default, standard | | /// \param port Port used for the connection | |
| FTP port) | | /// \param timeout Maximum time to wait | |
| /// \param Timeout : Maximum time to wait, in seconds (0 by default, me | | | |
| ans no timeout) | | | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see disconnect | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response Connect(const IPAddress& Server, unsigned short Port = 21, flo
at Timeout = 0.f); | | Response connect(const IpAddress& server, unsigned short port = 21, Tim
e timeout = Time::Zero); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Log in using anonymous account | | /// \brief Close the connection with the server | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see connect | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response Login(); | | Response disconnect(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Log in using a username and a password | | /// \brief Log in using an anonymous account | |
| /// | | /// | |
|
| /// \param UserName : User name | | /// Logging in is mandatory after connecting to the server. | |
| /// \param Password : Password | | /// Users that are not logged in cannot perform any operation. | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response Login(const std::string& UserName, const std::string& Password
); | | Response login(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Close the connection with FTP server | | /// \brief Log in using a username and a password | |
| | | /// | |
| | | /// Logging in is mandatory after connecting to the server. | |
| | | /// Users that are not logged in cannot perform any operation. | |
| | | /// | |
| | | /// \param name User name | |
| | | /// \param password Password | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response Disconnect(); | | Response login(const std::string& name, const std::string& password); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Send a null command just to prevent from being disconnected | | /// \brief Send a null command to keep the connection alive | |
| | | /// | |
| | | /// This command is useful because the server may close the | |
| | | /// connection automatically if no command is sent. | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response KeepAlive(); | | Response keepAlive(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the current working directory | | /// \brief Get the current working directory | |
| | | /// | |
| | | /// The working directory is the root path for subsequent | |
| | | /// operations involving directories and/or filenames. | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see getDirectoryListing, changeDirectory, parentDirectory | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| DirectoryResponse GetWorkingDirectory(); | | DirectoryResponse getWorkingDirectory(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the contents of the given directory | | /// \brief Get the contents of the given directory | |
| /// (subdirectories and files) | | /// | |
| | | /// This function retrieves the sub-directories and files | |
| | | /// contained in the given directory. It is not recursive. | |
| | | /// The \a directory parameter is relative to the current | |
| | | /// working directory. | |
| /// | | /// | |
|
| /// \param Directory : Directory to list ("" by default, the current on
e) | | /// \param directory Directory to list | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see getWorkingDirectory, changeDirectory, parentDirectory | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| ListingResponse GetDirectoryListing(const std::string& Directory = ""); | | ListingResponse getDirectoryListing(const std::string& directory = ""); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the current working directory | | /// \brief Change the current working directory | |
| | | /// | |
| | | /// The new directory must be relative to the current one. | |
| /// | | /// | |
|
| /// \param Directory : New directory, relative to the current one | | /// \param directory New working directory | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see getWorkingDirectory, getDirectoryListing, parentDirectory | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response ChangeDirectory(const std::string& Directory); | | Response changeDirectory(const std::string& directory); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Go to the parent directory of the current one | | /// \brief Go to the parent directory of the current one | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see getWorkingDirectory, getDirectoryListing, changeDirectory | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response ParentDirectory(); | | Response parentDirectory(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create a new directory | | /// \brief Create a new directory | |
| | | /// | |
| | | /// The new directory is created as a child of the current | |
| | | /// working directory. | |
| /// | | /// | |
|
| /// \param Name : Name of the directory to create | | /// \param name Name of the directory to create | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see deleteDirectory | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response MakeDirectory(const std::string& Name); | | Response createDirectory(const std::string& name); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Remove an existing directory | | /// \brief Remove an existing directory | |
| /// | | /// | |
|
| /// \param Name : Name of the directory to remove | | /// The directory to remove must be relative to the | |
| | | /// current working directory. | |
| | | /// Use this function with caution, the directory will | |
| | | /// be removed permanently! | |
| | | /// | |
| | | /// \param name Name of the directory to remove | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see createDirectory | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response DeleteDirectory(const std::string& Name); | | Response deleteDirectory(const std::string& name); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Rename a file | | /// \brief Rename an existing file | |
| | | /// | |
| | | /// The filenames must be relative to the current working | |
| | | /// directory. | |
| /// | | /// | |
|
| /// \param File : File to rename | | /// \param file File to rename | |
| /// \param NewName : New name | | /// \param newName New name of the file | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see deleteFile | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response RenameFile(const std::string& File, const std::string& NewName
); | | Response renameFile(const std::string& file, const std::string& newName
); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Remove an existing file | | /// \brief Remove an existing file | |
| | | /// | |
| | | /// The file name must be relative to the current working | |
| | | /// directory. | |
| | | /// Use this function with caution, the file will be | |
| | | /// removed permanently! | |
| /// | | /// | |
|
| /// \param Name : File to remove | | /// \param name File to remove | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see renameFile | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response DeleteFile(const std::string& Name); | | Response deleteFile(const std::string& name); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Download a file from the server | | /// \brief Download a file from the server | |
| | | /// | |
| | | /// The filename of the distant file is relative to the | |
| | | /// current working directory of the server, and the local | |
| | | /// destination path is relative to the current directory | |
| | | /// of your application. | |
| /// | | /// | |
|
| /// \param DistantFile : Path of the distant file to download | | /// \param remoteFile Filename of the distant file to download | |
| /// \param DestPath : Where to put to file on the local computer | | /// \param localPath Where to put to file on the local computer | |
| /// \param Mode : Transfer mode (binary by default) | | /// \param mode Transfer mode | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see upload | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response Download(const std::string& DistantFile, const std::string& De
stPath, TransferMode Mode = Binary); | | Response download(const std::string& remoteFile, const std::string& loc
alPath, TransferMode mode = Binary); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Upload a file to the server | | /// \brief Upload a file to the server | |
| /// | | /// | |
|
| /// \param LocalFile : Path of the local file to upload | | /// The name of the local file is relative to the current | |
| /// \param DestPath : Where to put to file on the server | | /// working directory of your application, and the | |
| /// \param Mode : Transfer mode (binary by default) | | /// remote path is relative to the current directory of the | |
| | | /// FTP server. | |
| | | /// | |
| | | /// \param localFile Path of the local file to upload | |
| | | /// \param remotePath Where to put to file on the server | |
| | | /// \param mode Transfer mode | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
|
| | | /// \see download | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response Upload(const std::string& LocalFile, const std::string& DestPa
th, TransferMode Mode = Binary); | | Response upload(const std::string& localFile, const std::string& remote
Path, TransferMode mode = Binary); | |
| | | | |
| private : | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Send a command to the FTP server | | /// \brief Send a command to the FTP server | |
| /// | | /// | |
|
| /// \param Command : Command to send | | /// \param command Command to send | |
| /// \param Parameter : Command parameter ("" by default) | | /// \param parameter Command parameter | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response SendCommand(const std::string& Command, const std::string& Par
ameter = ""); | | Response sendCommand(const std::string& command, const std::string& par
ameter = ""); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Receive a response from the server | | /// \brief Receive a response from the server | |
| /// (usually after a command has been sent) | | /// | |
| | | /// This function must be called after each call to | |
| | | /// SendCommand that expects a response. | |
| /// | | /// | |
| /// \return Server response to the request | | /// \return Server response to the request | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response GetResponse(); | | Response getResponse(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Utility class for exchanging datas with the server | | /// \brief Utility class for exchanging datas with the server | |
| /// on the data channel | | /// on the data channel | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| class DataChannel; | | class DataChannel; | |
| | | | |
| friend class DataChannel; | | friend class DataChannel; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| SocketTCP myCommandSocket; ///< Socket holding the control connection w
ith the server | | TcpSocket m_commandSocket; ///< Socket holding the control connection w
ith the server | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_FTP_HPP | | #endif // SFML_FTP_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Ftp | |
| | | /// \ingroup network | |
| | | /// | |
| | | /// sf::Ftp is a very simple FTP client that allows you | |
| | | /// to communicate with a FTP server. The FTP protocol allows | |
| | | /// you to manipulate a remote file system (list files, | |
| | | /// upload, download, create, remove, ...). | |
| | | /// | |
| | | /// Using the FTP client consists of 4 parts: | |
| | | /// \li Connecting to the FTP server | |
| | | /// \li Logging in (either as a registered user or anonymously) | |
| | | /// \li Sending commands to the server | |
| | | /// \li Disconnecting (this part can be done implicitely by the destructor) | |
| | | /// | |
| | | /// Every command returns a FTP response, which contains the | |
| | | /// status code as well as a message from the server. Some | |
| | | /// commands such as getWorkingDirectory and getDirectoryListing | |
| | | /// return additional data, and use a class derived from | |
| | | /// sf::Ftp::Response to provide this data. | |
| | | /// | |
| | | /// All commands, especially upload and download, may take some | |
| | | /// time to complete. This is important to know if you don't want | |
| | | /// to block your application while the server is completing | |
| | | /// the task. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Create a new FTP client | |
| | | /// sf::Ftp ftp; | |
| | | /// | |
| | | /// // Connect to the server | |
| | | /// sf::Ftp::Response response = ftp.connect("ftp://ftp.myserver.com"); | |
| | | /// if (response.isOk()) | |
| | | /// std::cout << "Connected" << std::endl; | |
| | | /// | |
| | | /// // Log in | |
| | | /// response = ftp.login("laurent", "dF6Zm89D"); | |
| | | /// if (response.isOk()) | |
| | | /// std::cout << "Logged in" << std::endl; | |
| | | /// | |
| | | /// // Print the working directory | |
| | | /// sf::Ftp::DirectoryResponse directory = ftp.getWorkingDirectory(); | |
| | | /// if (directory.isOk()) | |
| | | /// std::cout << "Working directory: " << directory.getDirectory() << s | |
| | | td::endl; | |
| | | /// | |
| | | /// // Create a new directory | |
| | | /// response = ftp.createDirectory("files"); | |
| | | /// if (response.isOk()) | |
| | | /// std::cout << "Created new directory" << std::endl; | |
| | | /// | |
| | | /// // Upload a file to this new directory | |
| | | /// response = ftp.upload("local-path/file.txt", "files", sf::Ftp::Ascii); | |
| | | /// if (response.isOk()) | |
| | | /// std::cout << "File uploaded" << std::endl; | |
| | | /// | |
| | | /// // Disconnect from the server (optional) | |
| | | /// ftp.disconnect(); | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 99 change blocks. |
| 120 lines changed or deleted | | 198 lines changed or added | |
|
| Http.hpp | | Http.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_HTTP_HPP | | #ifndef SFML_HTTP_HPP | |
| #define SFML_HTTP_HPP | | #define SFML_HTTP_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/Network/Export.hpp> | |
| | | #include <SFML/Network/IpAddress.hpp> | |
| | | #include <SFML/Network/TcpSocket.hpp> | |
| #include <SFML/System/NonCopyable.hpp> | | #include <SFML/System/NonCopyable.hpp> | |
|
| #include <SFML/Network/IPAddress.hpp> | | #include <SFML/System/Time.hpp> | |
| #include <SFML/Network/SocketTCP.hpp> | | | |
| #include <map> | | #include <map> | |
| #include <string> | | #include <string> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// This class provides methods for manipulating the HTTP | | /// \brief A HTTP client | |
| /// protocol (described in RFC 1945). | | /// | |
| /// It can connect to a website, get its files, send requests, etc. | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Http : NonCopyable | | class SFML_NETWORK_API Http : NonCopyable | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// This class wraps an HTTP request, which is basically : | | /// \brief Define a HTTP request | |
| /// - a header with a method, a target URI, and a set of field/value pa | | /// | |
| irs | | | |
| /// - an optional body (for POST requests) | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Request | | class SFML_NETWORK_API Request | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumerate the available HTTP methods for a request | | /// \brief Enumerate the available HTTP methods for a request | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| enum Method | | enum Method | |
| { | | { | |
| Get, ///< Request in get mode, standard method to retrieve a p
age | | Get, ///< Request in get mode, standard method to retrieve a p
age | |
| Post, ///< Request in post mode, usually to send data to a page | | Post, ///< Request in post mode, usually to send data to a page | |
| Head ///< Request a page's header only | | Head ///< Request a page's header only | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| /// | | /// | |
|
| /// \param RequestMethod : Method to use for the request (Get by de | | /// This constructor creates a GET request, with the root | |
| fault) | | /// URI ("/") and an empty body. | |
| /// \param URI : Target URI ("/" by default -- index page | | /// | |
| ) | | /// \param uri Target URI | |
| /// \param Body : Content of the request's body (empty by | | /// \param method Method to use for the request | |
| default) | | /// \param body Content of the request's body | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Request(Method RequestMethod = Get, const std::string& URI = "/", c
onst std::string& Body = ""); | | Request(const std::string& uri = "/", Method method = Get, const st
d::string& body = ""); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the value of a field; the field is added if it doesn't exis | | /// \brief Set the value of a field | |
| t | | /// | |
| | | /// The field is created if it doesn't exist. The name of | |
| | | /// the field is case insensitive. | |
| | | /// By default, a request doesn't contain any field (but the | |
| | | /// mandatory fields are added later by the HTTP client when | |
| | | /// sending the request). | |
| /// | | /// | |
|
| /// \param Field : Name of the field to set (case-insensitive) | | /// \param field Name of the field to set | |
| /// \param Value : Value of the field | | /// \param value Value of the field | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetField(const std::string& Field, const std::string& Value); | | void setField(const std::string& field, const std::string& value); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the request method. | | /// \brief Set the request method | |
| /// This parameter is Http::Request::Get by default | | | |
| /// | | /// | |
|
| /// \param RequestMethod : Method to use for the request | | /// See the Method enumeration for a complete list of all | |
| | | /// the availale methods. | |
| | | /// The method is Http::Request::Get by default. | |
| | | /// | |
| | | /// \param method Method to use for the request | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetMethod(Method RequestMethod); | | void setMethod(Method method); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the target URI of the request. | | /// \brief Set the requested URI | |
| /// This parameter is "/" by default | | /// | |
| | | /// The URI is the resource (usually a web page or a file) | |
| | | /// that you want to get or post. | |
| | | /// The URI is "/" (the root page) by default. | |
| /// | | /// | |
|
| /// \param URI : URI to request, local to the host | | /// \param uri URI to request, relative to the host | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetURI(const std::string& URI); | | void setUri(const std::string& uri); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the HTTP version of the request. | | /// \brief Set the HTTP version for the request | |
| /// This parameter is 1.0 by default | | /// | |
| | | /// The HTTP version is 1.0 by default. | |
| /// | | /// | |
|
| /// \param Major : Major version number | | /// \param major Major HTTP version number | |
| /// \param Minor : Minor version number | | /// \param minor Minor HTTP version number | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetHttpVersion(unsigned int Major, unsigned int Minor); | | void setHttpVersion(unsigned int major, unsigned int minor); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the body of the request. This parameter is optional and | | /// \brief Set the body of the request | |
| /// makes sense only for POST requests. | | | |
| /// This parameter is empty by default | | | |
| /// | | /// | |
|
| /// \param Body : Content of the request body | | /// The body of a request is optional and only makes sense | |
| | | /// for POST requests. It is ignored for all other methods. | |
| | | /// The body is empty by default. | |
| | | /// | |
| | | /// \param body Content of the body | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetBody(const std::string& Body); | | void setBody(const std::string& body); | |
| | | | |
| private : | | private : | |
| | | | |
| friend class Http; | | friend class Http; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the string representation of the request header | | /// \brief Prepare the final request to send to the server | |
| | | /// | |
| | | /// This is used internally by Http before sending the | |
| | | /// request to the web server. | |
| /// | | /// | |
|
| /// \return String containing the request | | /// \return String containing the request, ready to be sent | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::string ToString() const; | | std::string prepare() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Check if the given field has been defined | | /// \brief Check if the request defines a field | |
| | | /// | |
| | | /// This function uses case-insensitive comparisons. | |
| /// | | /// | |
|
| /// \param Field : Name of the field to check (case-insensitive) | | /// \param field Name of the field to test | |
| /// | | /// | |
|
| /// \return True if the field exists | | /// \return True if the field exists, false otherwise | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool HasField(const std::string& Field) const; | | bool hasField(const std::string& field) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Types | | // Types | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| typedef std::map<std::string, std::string> FieldTable; | | typedef std::map<std::string, std::string> FieldTable; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| FieldTable myFields; ///< Fields of the header | | FieldTable m_fields; ///< Fields of the header associated t | |
| Method myMethod; ///< Method to use for the request | | o their value | |
| std::string myURI; ///< Target URI of the request | | Method m_method; ///< Method to use for the request | |
| unsigned int myMajorVersion; ///< Major HTTP version | | std::string m_uri; ///< Target URI of the request | |
| unsigned int myMinorVersion; ///< Minor HTTP version | | unsigned int m_majorVersion; ///< Major HTTP version | |
| std::string myBody; ///< Body of the request | | unsigned int m_minorVersion; ///< Minor HTTP version | |
| | | std::string m_body; ///< Body of the request | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// This class wraps an HTTP response, which is basically : | | /// \brief Define a HTTP response | |
| /// - 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 | | class SFML_NETWORK_API Response | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumerate all the valid status codes returned in | | /// \brief Enumerate all the valid status codes for a response | |
| /// a HTTP response | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| enum Status | | enum Status | |
| { | | { | |
| // 2xx: success | | // 2xx: success | |
|
| Ok = 200, ///< Most common code returned when operation | | Ok = 200, ///< Most common code returned when opera | |
| was successful | | tion was successful | |
| Created = 201, ///< The resource has successfully been create | | Created = 201, ///< The resource has successfully been c | |
| d | | reated | |
| Accepted = 202, ///< The request has been accepted, but will b | | Accepted = 202, ///< The request has been accepted, but w | |
| e processed later by the server | | ill be processed later by the server | |
| NoContent = 204, ///< Sent when the server didn't send any data | | NoContent = 204, ///< The server didn't send any data in r | |
| in return | | eturn | |
| | | ResetContent = 205, ///< The server informs the client that i | |
| | | t should clear the view (form) that caused the request to be sent | |
| | | PartialContent = 206, ///< The server has sent a part of the re | |
| | | source, as a response to a partial GET request | |
| | | | |
| // 3xx: redirection | | // 3xx: redirection | |
| MultipleChoices = 300, ///< The requested page can be accessed
from several locations | | MultipleChoices = 300, ///< The requested page can be accessed
from several locations | |
| MovedPermanently = 301, ///< The requested page has permanently
moved to a new location | | MovedPermanently = 301, ///< The requested page has permanently
moved to a new location | |
| MovedTemporarily = 302, ///< The requested page has temporarily
moved to a new location | | MovedTemporarily = 302, ///< The requested page has temporarily
moved to a new location | |
| NotModified = 304, ///< For conditionnal requests, means t
he requested page hasn't changed and doesn't need to be refreshed | | NotModified = 304, ///< For conditionnal requests, means t
he requested page hasn't changed and doesn't need to be refreshed | |
| | | | |
| // 4xx: client error | | // 4xx: client error | |
|
| BadRequest = 400, ///< The server couldn't understand the req | | BadRequest = 400, ///< The server couldn't understand | |
| uest (syntax error) | | the request (syntax error) | |
| Unauthorized = 401, ///< The requested page needs an authentifi | | Unauthorized = 401, ///< The requested page needs an aut | |
| cation to be accessed | | hentification to be accessed | |
| Forbidden = 403, ///< The requested page cannot be accessed | | Forbidden = 403, ///< The requested page cannot be ac | |
| at all, even with authentification | | cessed at all, even with authentification | |
| NotFound = 404, ///< The requested page doesn't exist | | NotFound = 404, ///< The requested page doesn't exis | |
| | | t | |
| | | RangeNotSatisfiable = 407, ///< The server can't satisfy the pa | |
| | | rtial GET request (with a "Range" header field) | |
| | | | |
| // 5xx: server error | | // 5xx: server error | |
| InternalServerError = 500, ///< The server encountered an unexp
ected error | | InternalServerError = 500, ///< The server encountered an unexp
ected error | |
| NotImplemented = 501, ///< The server doesn't implement a
requested feature | | NotImplemented = 501, ///< The server doesn't implement a
requested feature | |
| BadGateway = 502, ///< The gateway server has received
an error from the source server | | BadGateway = 502, ///< The gateway server has received
an error from the source server | |
| ServiceNotAvailable = 503, ///< The server is temporarily unava
ilable (overloaded, in maintenance, ...) | | ServiceNotAvailable = 503, ///< The server is temporarily unava
ilable (overloaded, in maintenance, ...) | |
|
| | | GatewayTimeout = 504, ///< The gateway server couldn't rec | |
| | | eive a response from the source server | |
| | | VersionNotSupported = 505, ///< The server doesn't support the | |
| | | requested HTTP version | |
| | | | |
| // 10xx: SFML custom codes | | // 10xx: SFML custom codes | |
| InvalidResponse = 1000, ///< Response is not a valid HTTP one | | InvalidResponse = 1000, ///< Response is not a valid HTTP one | |
| ConnectionFailed = 1001 ///< Connection with server failed | | ConnectionFailed = 1001 ///< Connection with server failed | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// Constructs an empty response. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Response(); | | Response(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the value of a field | | /// \brief Get the value of a field | |
| /// | | /// | |
|
| /// \param Field : Name of the field to get (case-insensitive) | | /// If the field \a field is not found in the response header, | |
| | | /// the empty string is returned. This function uses | |
| | | /// case-insensitive comparisons. | |
| | | /// | |
| | | /// \param field Name of the field to get | |
| /// | | /// | |
| /// \return Value of the field, or empty string if not found | | /// \return Value of the field, or empty string if not found | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const std::string& GetField(const std::string& Field) const; | | const std::string& getField(const std::string& field) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the header's status code | | /// \brief Get the response status code | |
| | | /// | |
| | | /// The status code should be the first thing to be checked | |
| | | /// after receiving a response, it defines whether it is a | |
| | | /// success, a failure or anything else (see the Status | |
| | | /// enumeration). | |
| /// | | /// | |
|
| /// \return Header's status code | | /// \return Status code of the response | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Status GetStatus() const; | | Status getStatus() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the major HTTP version number of the response | | /// \brief Get the major HTTP version number of the response | |
| | | /// | |
| | | /// \return Major HTTP version number | |
| /// | | /// | |
|
| /// \return Major version number | | /// \see getMinorHttpVersion | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetMajorHttpVersion() const; | | unsigned int getMajorHttpVersion() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the major HTTP version number of the response | | /// \brief Get the minor HTTP version number of the response | |
| /// | | /// | |
|
| /// \return Major version number | | /// \return Minor HTTP version number | |
| | | /// | |
| | | /// \see getMajorHttpVersion | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetMinorHttpVersion() const; | | unsigned int getMinorHttpVersion() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the body of the response. The body can contain : | | /// \brief Get the body of the response | |
| /// - the requested page (for GET requests) | | /// | |
| /// - a response from the server (for POST requests) | | /// The body of a response may contain: | |
| /// - nothing (for HEAD requests) | | /// \li the requested page (for GET requests) | |
| /// - an error message (in case of an error) | | /// \li a response from the server (for POST requests) | |
| | | /// \li nothing (for HEAD requests) | |
| | | /// \li an error message (in case of an error) | |
| /// | | /// | |
| /// \return The response body | | /// \return The response body | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const std::string& GetBody() const; | | const std::string& getBody() const; | |
| | | | |
| private : | | private : | |
| | | | |
| friend class Http; | | friend class Http; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the header from a response string | | /// \brief Construct the header from a response string | |
| | | /// | |
| | | /// This function is used by Http to build the response | |
| | | /// of a request. | |
| /// | | /// | |
|
| /// \param Data : Content of the response's header to parse | | /// \param data Content of the response to parse | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void FromString(const std::string& Data); | | void parse(const std::string& data); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Types | | // Types | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| typedef std::map<std::string, std::string> FieldTable; | | typedef std::map<std::string, std::string> FieldTable; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| FieldTable myFields; ///< Fields of the header | | FieldTable m_fields; ///< Fields of the header | |
| Status myStatus; ///< Status code | | Status m_status; ///< Status code | |
| unsigned int myMajorVersion; ///< Major HTTP version | | unsigned int m_majorVersion; ///< Major HTTP version | |
| unsigned int myMinorVersion; ///< Minor HTTP version | | unsigned int m_minorVersion; ///< Minor HTTP version | |
| std::string myBody; ///< Body of the response | | std::string m_body; ///< Body of the response | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Http(); | | Http(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the Http instance with the target host | | /// \brief Construct the HTTP client with the target host | |
| /// | | /// | |
|
| /// \param Host : Web server to connect to | | /// This is equivalent to calling setHost(host, port). | |
| /// \param Port : Port to use for connection (0 by default -- use the s | | /// The port has a default value of 0, which means that the | |
| tandard port of the protocol used) | | /// HTTP client will use the right port according to the | |
| | | /// protocol used (80 for HTTP, 443 for HTTPS). You should | |
| | | /// leave it like this unless you really need a port other | |
| | | /// than the standard one, or use an unknown protocol. | |
| | | /// | |
| | | /// \param host Web server to connect to | |
| | | /// \param port Port to use for connection | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Http(const std::string& Host, unsigned short Port = 0); | | Http(const std::string& host, unsigned short port = 0); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the target host | | /// \brief Set the target host | |
| | | /// | |
| | | /// This function just stores the host address and port, it | |
| | | /// doesn't actually connect to it until you send a request. | |
| | | /// The port has a default value of 0, which means that the | |
| | | /// HTTP client will use the right port according to the | |
| | | /// protocol used (80 for HTTP, 443 for HTTPS). You should | |
| | | /// leave it like this unless you really need a port other | |
| | | /// than the standard one, or use an unknown protocol. | |
| /// | | /// | |
|
| /// \param Host : Web server to connect to | | /// \param host Web server to connect to | |
| /// \param Port : Port to use for connection (0 by default -- use the s | | /// \param port Port to use for connection | |
| tandard port of the protocol used) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetHost(const std::string& Host, unsigned short Port = 0); | | void setHost(const std::string& host, unsigned short port = 0); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Send a HTTP request and return the server's response. | | /// \brief 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 appropriat | | /// You must have a valid host before sending a request (see setHost). | |
| e value. | | /// Any missing mandatory header field in the request will be added | |
| /// Warning : this function waits for the server's response and may | | /// 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 | | /// not return instantly; use a thread if you don't want to block your | |
|
| /// application. | | /// application, or use a timeout to limit the time to wait. A value | |
| | | /// of Time::Zero means that the client will use the system defaut time | |
| | | out | |
| | | /// (which is usually pretty long). | |
| /// | | /// | |
|
| /// \param Req : Request to send | | /// \param request Request to send | |
| /// \param Timeout : Maximum time to wait, in seconds (0 by default, me | | /// \param timeout Maximum time to wait | |
| ans no timeout) | | | |
| /// | | /// | |
| /// \return Server's response | | /// \return Server's response | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Response SendRequest(const Request& Req, float Timeout = 0.f); | | Response sendRequest(const Request& request, Time timeout = Time::Zero)
; | |
| | | | |
| private : | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| SocketTCP myConnection; ///< Connection to the host | | TcpSocket m_connection; ///< Connection to the host | |
| IPAddress myHost; ///< Web host address | | IpAddress m_host; ///< Web host address | |
| std::string myHostName; ///< Web host name | | std::string m_hostName; ///< Web host name | |
| unsigned short myPort; ///< Port used for connection with host | | unsigned short m_port; ///< Port used for connection with host | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_HTTP_HPP | | #endif // SFML_HTTP_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Http | |
| | | /// \ingroup network | |
| | | /// | |
| | | /// sf::Http is a very simple HTTP client that allows you | |
| | | /// to communicate with a web server. You can retrieve | |
| | | /// web pages, send data to an interactive resource, | |
| | | /// download a remote file, etc. | |
| | | /// | |
| | | /// The HTTP client is split into 3 classes: | |
| | | /// \li sf::Http::Request | |
| | | /// \li sf::Http::Response | |
| | | /// \li sf::Http | |
| | | /// | |
| | | /// sf::Http::Request builds the request that will be | |
| | | /// sent to the server. A request is made of: | |
| | | /// \li a method (what you want to do) | |
| | | /// \li a target URI (usually the name of the web page or file) | |
| | | /// \li one or more header fields (options that you can pass to the server) | |
| | | /// \li an optional body (for POST requests) | |
| | | /// | |
| | | /// sf::Http::Response parse the response from the web server | |
| | | /// and provides getters to read them. The response contains: | |
| | | /// \li a status code | |
| | | /// \li header fields (that may be answers to the ones that you requested) | |
| | | /// \li a body, which contains the contents of the requested resource | |
| | | /// | |
| | | /// sf::Http provides a simple function, SendRequest, to send a | |
| | | /// sf::Http::Request and return the corresponding sf::Http::Response | |
| | | /// from the server. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Create a new HTTP client | |
| | | /// sf::Http http; | |
| | | /// | |
| | | /// // We'll work on http://www.sfml-dev.org | |
| | | /// http.setHost("http://www.sfml-dev.org"); | |
| | | /// | |
| | | /// // Prepare a request to get the 'features.php' page | |
| | | /// sf::Http::Request request("features.php"); | |
| | | /// | |
| | | /// // Send the request | |
| | | /// sf::Http::Response response = http.sendRequest(request); | |
| | | /// | |
| | | /// // Check the status code and display the result | |
| | | /// sf::Http::Response::Status status = response.getStatus(); | |
| | | /// if (status == sf::Http::Response::Ok) | |
| | | /// { | |
| | | /// std::cout << response.getBody() << std::endl; | |
| | | /// } | |
| | | /// else | |
| | | /// { | |
| | | /// std::cout << "Error " << status << std::endl; | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 72 change blocks. |
| 130 lines changed or deleted | | 196 lines changed or added | |
|
| Image.hpp | | Image.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_IMAGE_HPP | | #ifndef SFML_IMAGE_HPP | |
| #define SFML_IMAGE_HPP | | #define SFML_IMAGE_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/System/Resource.hpp> | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/Graphics/Color.hpp> | | #include <SFML/Graphics/Color.hpp> | |
| #include <SFML/Graphics/Rect.hpp> | | #include <SFML/Graphics/Rect.hpp> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| class RenderWindow; | | class InputStream; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Image is the low-level class for loading and | | /// \brief Class for loading, manipulating and saving images | |
| /// manipulating images | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Image : public Resource<Image> | | class SFML_GRAPHICS_API Image | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// Creates an empty image. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Image(); | | Image(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Copy constructor | | /// \brief Create the image and fill it with a unique color | |
| /// | | /// | |
|
| /// \param Copy : instance to copy | | /// \param width Width of the image | |
| | | /// \param height Height of the image | |
| | | /// \param color Fill color | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Image(const Image& Copy); | | void create(unsigned int width, unsigned int height, const Color& color
= Color(0, 0, 0)); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct an empty image | | /// \brief Create the image from an array of pixels | |
| /// | | | |
| /// \param Width : Image width | | | |
| /// \param Height : Image height | | | |
| /// \param Col : Image color (black by default) | | | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// The \a pixel array is assumed to contain 32-bits RGBA pixels, | |
| Image(unsigned int Width, unsigned int Height, const Color& Col = Color | | /// and have the given \a width and \a height. If not, this is | |
| (0, 0, 0, 255)); | | /// an undefined behaviour. | |
| | | /// If \a pixels is null, an empty image is created. | |
| //////////////////////////////////////////////////////////// | | | |
| /// Construct the image from pixels in memory | | | |
| /// | | /// | |
|
| /// \param Width : Image width | | /// \param width Width of the image | |
| /// \param Height : Image height | | /// \param height Height of the image | |
| /// \param Data : Pointer to the pixels in memory (assumed format is | | /// \param pixels Array of pixels to copy to the image | |
| RGBA) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Image(unsigned int Width, unsigned int Height, const Uint8* Data); | | void create(unsigned int width, unsigned int height, const Uint8* pixel
s); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor | | /// \brief Load the image from a file on disk | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// The supported image formats are bmp, png, tga, jpg, gif, | |
| ~Image(); | | /// psd, hdr and pic. Some format options are not supported, | |
| | | /// like progressive jpeg. | |
| //////////////////////////////////////////////////////////// | | /// If this function fails, the image is left unchanged. | |
| /// Load the image from a file | | | |
| /// | | /// | |
|
| /// \param Filename : Path of the image file to load | | /// \param filename Path of the image file to load | |
| /// | | /// | |
| /// \return True if loading was successful | | /// \return True if loading was successful | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \see loadFromMemory, loadFromStream, saveToFile | |
| 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); | | bool loadFromFile(const std::string& filename); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Load the image directly from an array of pixels | | /// \brief Load the image from a file in memory | |
| /// | | /// | |
|
| /// \param Width : Image width | | /// The supported image formats are bmp, png, tga, jpg, gif, | |
| /// \param Height : Image height | | /// psd, hdr and pic. Some format options are not supported, | |
| /// \param Data : Pointer to the pixels in memory (assumed format is | | /// like progressive jpeg. | |
| RGBA) | | /// If this function fails, the image is left unchanged. | |
| /// | | | |
| /// \return True if loading was successful | | | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param data Pointer to the file data in memory | |
| bool LoadFromPixels(unsigned int Width, unsigned int Height, const Uint | | /// \param size Size of the data to load, in bytes | |
| 8* 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 loading was successful | |
| /// | | /// | |
|
| /// \return True if saving was successful | | /// \see loadFromFile, loadFromStream | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool SaveToFile(const std::string& Filename) const; | | bool loadFromMemory(const void* data, std::size_t size); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create an empty image | | /// \brief Load the image from a custom stream | |
| /// | | | |
| /// \param Width : Image width | | | |
| /// \param Height : Image height | | | |
| /// \param Col : Image color (black by default) | | | |
| /// | | /// | |
|
| /// \return True if creation was successful | | /// The supported image formats are bmp, png, tga, jpg, gif, | |
| /// | | /// psd, hdr and pic. Some format options are not supported, | |
| //////////////////////////////////////////////////////////// | | /// like progressive jpeg. | |
| bool Create(unsigned int Width, unsigned int Height, Color Col = Color( | | /// If this function fails, the image is left unchanged. | |
| 0, 0, 0, 255)); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Create transparency mask from a specified colorkey | | | |
| /// | | /// | |
|
| /// \param ColorKey : Color to become transparent | | /// \param stream Source stream to read from | |
| /// \param Alpha : Alpha value to use for transparent pixels (0 by d | | | |
| efault) | | | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \return True if loading was successful | |
| 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 | | /// \see loadFromFile, loadFromMemory | |
| /// \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 (empt | | | |
| y by default - entire image) | | | |
| /// \param ApplyAlpha : Should the copy take in account the source tran | | | |
| sparency? (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); | | bool loadFromStream(InputStream& stream); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create the image from the current contents of the | | /// \brief Save the image to a file on disk | |
| /// given window | | | |
| /// | | /// | |
|
| /// \param Window : Window to capture | | /// The format of the image is automatically deduced from | |
| /// \param SourceRect : Sub-rectangle of the screen to copy (empty by d | | /// the extension. The supported image formats are bmp, png, | |
| efault - entire image) | | /// tga and jpg. The destination file is overwritten | |
| | | /// if it already exists. This function fails if the image is empty. | |
| /// | | /// | |
|
| /// \return True if copy was successful | | /// \param filename Path of the file to save | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \return True if saving was successful | |
| bool CopyScreen(RenderWindow& Window, const IntRect& SourceRect = IntRe | | | |
| ct(0, 0, 0, 0)); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Change the color of a pixel | | | |
| /// | | /// | |
|
| /// \param X : X coordinate of pixel in the image | | /// \see create, loadFromFile, loadFromMemory | |
| /// \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); | | bool saveToFile(const std::string& filename) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get a pixel from the image | | /// \brief Return the size (width and height) of the image | |
| /// | | /// | |
|
| /// \param X : X coordinate of pixel in the image | | /// \return Size of the image, in pixels | |
| /// \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; | | Vector2u getSize() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get a read-only pointer to the array of pixels (RGBA 8 bits integer | | /// \brief Create a transparency mask from a specified color-key | |
| s 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 | | /// This function sets the alpha value of every pixel matching | |
| | | /// the given color to \a alpha (0 by default), so that they | |
| | | /// become transparent. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param color Color to make transparent | |
| const Uint8* GetPixelsPtr() const; | | /// \param alpha Alpha value to assign to transparent pixels | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Bind the image for rendering | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Bind() const; | | void createMaskFromColor(const Color& color, Uint8 alpha = 0); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enable or disable image smooth filter. | | /// \brief Copy pixels from another image onto this one | |
| /// This parameter is enabled by default | | | |
| /// | | /// | |
|
| /// \param Smooth : True to enable smoothing filter, false to disable i | | /// This function does a slow pixel copy and should not be | |
| t | | /// used intensively. It can be used to prepare a complex | |
| | | /// static image from several others, but if you need this | |
| | | /// kind of feature in real-time you'd better use sf::RenderTexture. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// If \a sourceRect is empty, the whole image is copied. | |
| void SetSmooth(bool Smooth); | | /// If \a applyAlpha is set to true, the transparency of | |
| | | /// source pixels is applied. If it is false, the pixels are | |
| //////////////////////////////////////////////////////////// | | /// copied unchanged with their alpha value. | |
| /// Return the width of the image | | | |
| /// | | /// | |
|
| /// \return Width in pixels | | /// \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 | |
| | | /// \param applyAlpha Should the copy take in account the source transp | |
| | | arency? | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetWidth() const; | | void copy(const Image& source, unsigned int destX, unsigned int destY,
const IntRect& sourceRect = IntRect(0, 0, 0, 0), bool applyAlpha = false); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Return the height of the image | | /// \brief Change the color of a pixel | |
| /// | | /// | |
|
| /// \return Height in pixels | | /// This function doesn't check the validity of the pixel | |
| | | /// coordinates, using out-of-range values will result in | |
| | | /// an undefined behaviour. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param x X coordinate of pixel to change | |
| unsigned int GetHeight() const; | | /// \param y Y coordinate of pixel to change | |
| | | /// \param color New color of the pixel | |
| //////////////////////////////////////////////////////////// | | | |
| /// Tells whether the smooth filtering is enabled or not | | | |
| /// | | /// | |
|
| /// \return True if image smoothing is enabled | | /// \see getPixel | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool IsSmooth() const; | | void setPixel(unsigned int x, unsigned int y, const Color& color); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Convert a subrect expressed in pixels, into float | | /// \brief Get the color of a pixel | |
| /// texture coordinates | | | |
| /// | | /// | |
|
| /// \param Rect : Sub-rectangle of image to convert | | /// This function doesn't check the validity of the pixel | |
| | | /// coordinates, using out-of-range values will result in | |
| | | /// an undefined behaviour. | |
| /// | | /// | |
|
| /// \return Texture coordinates corresponding to the sub-rectangle | | /// \param x X coordinate of pixel to get | |
| /// | | /// \param y Y coordinate of pixel to get | |
| //////////////////////////////////////////////////////////// | | | |
| FloatRect GetTexCoords(const IntRect& Rect) const; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Get a valid texture size according to hardware support | | | |
| /// | | /// | |
|
| /// \param Size : Size to convert | | /// \return Color of the pixel at coordinates (x, y) | |
| /// | | /// | |
|
| /// \return Valid nearest size (greater than or equal to specified size
) | | /// \see setPixel | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static unsigned int GetValidTextureSize(unsigned int Size); | | Color getPixel(unsigned int x, unsigned int y) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Assignment operator | | /// \brief Get a read-only pointer to the array of pixels | |
| /// | | /// | |
|
| /// \param Other : instance to assign | | /// The returned value points to an array of RGBA pixels made of | |
| | | /// 8 bits integers components. The size of the array is | |
| | | /// width * height * 4 (getSize().x * getSize().y * 4). | |
| | | /// Warning: the returned pointer may become invalid if you | |
| | | /// modify the image, so you should never store it for too long. | |
| | | /// If the image is empty, a null pointer is returned. | |
| /// | | /// | |
|
| /// \return Reference to the image | | /// \return Read-only pointer to the array of pixels | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Image& operator =(const Image& Other); | | const Uint8* getPixelsPtr() const; | |
| | | | |
| private : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create the OpenGL texture | | /// \brief Flip the image horizontally (left <-> right) | |
| /// | | /// | |
|
| /// \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 | | void flipHorizontally(); | |
| /// texture in video memory | | | |
| //////////////////////////////////////////////////////////// | | | |
| void EnsureArrayUpdate() const; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Reset the image attributes | | /// \brief Flip the image vertically (top <-> bottom) | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Reset(); | | void flipVertically(); | |
| | | | |
|
| //////////////////////////////////////////////////////////// | | private : | |
| /// Destroy the OpenGL texture | | | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| void DestroyTexture(); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int myWidth; ///< Image width | | Vector2u m_size; ///< Image size | |
| unsigned int myHeight; ///< Image Height | | std::vector<Uint8> m_pixels; ///< Pixels of the image | |
| unsigned int myTextureWidth; ///< Actual texture wid | | | |
| th (can be greater than image width because of padding) | | | |
| unsigned int myTextureHeight; ///< Actual texture hei | | | |
| ght (can be greater than image height because of padding) | | | |
| unsigned int myTexture; ///< Internal texture i | | | |
| dentifier | | | |
| bool myIsSmooth; ///< Status of the smoo | | | |
| th filter | | | |
| mutable std::vector<Color> myPixels; ///< Pixels of the imag | | | |
| e | | | |
| mutable bool myNeedTextureUpdate; ///< Status of synchron | | | |
| ization between pixels in central memory and the internal texture un video | | | |
| memory | | | |
| mutable bool myNeedArrayUpdate; ///< Status of synchron | | | |
| ization between pixels in central memory and the internal texture un video | | | |
| memory | | | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_IMAGE_HPP | | #endif // SFML_IMAGE_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Image | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::Image is an abstraction to manipulate images | |
| | | /// as bidimensional arrays of pixels. The class provides | |
| | | /// functions to load, read, write and save pixels, as well | |
| | | /// as many other useful functions. | |
| | | /// | |
| | | /// sf::Image can handle a unique internal representation of | |
| | | /// pixels, which is RGBA 32 bits. This means that a pixel | |
| | | /// must be composed of 8 bits red, green, blue and alpha | |
| | | /// channels -- just like a sf::Color. | |
| | | /// All the functions that return an array of pixels follow | |
| | | /// this rule, and all parameters that you pass to sf::Image | |
| | | /// functions (such as loadFromPixels) must use this | |
| | | /// representation as well. | |
| | | /// | |
| | | /// A sf::Image can be copied, but it is a heavy resource and | |
| | | /// if possible you should always use [const] references to | |
| | | /// pass or return them to avoid useless copies. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Load an image file from a file | |
| | | /// sf::Image background; | |
| | | /// if (!background.loadFromFile("background.jpg")) | |
| | | /// return -1; | |
| | | /// | |
| | | /// // Create a 20x20 image filled with black color | |
| | | /// sf::Image image; | |
| | | /// if (!image.create(20, 20, sf::Color::Black)) | |
| | | /// return -1; | |
| | | /// | |
| | | /// // Copy image1 on image2 at position (10, 10) | |
| | | /// image.copy(background, 10, 10); | |
| | | /// | |
| | | /// // Make the top-left pixel transparent | |
| | | /// sf::Color color = image.getPixel(0, 0); | |
| | | /// color.a = 0; | |
| | | /// image.setPixel(0, 0, color); | |
| | | /// | |
| | | /// // Save the image to a file | |
| | | /// if (!image.saveToFile("result.png")) | |
| | | /// return -1; | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::Texture | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 71 change blocks. |
| 204 lines changed or deleted | | 119 lines changed or added | |
|
| Listener.hpp | | Listener.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_LISTENER_HPP | | #ifndef SFML_LISTENER_HPP | |
| #define SFML_LISTENER_HPP | | #define SFML_LISTENER_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Config.hpp> | | #include <SFML/Audio/Export.hpp> | |
| #include <SFML/System/Vector3.hpp> | | #include <SFML/System/Vector3.hpp> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Listener is a global interface for defining the audio | | /// \brief The audio listener is the point in the scene | |
| /// listener properties ; the audio listener is the point in | | /// from where all the sounds are heard | |
| /// the scene from where all the sounds are heard | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Listener | | class SFML_AUDIO_API Listener | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the global volume of all the sounds. | | /// \brief Change the global volume of all the sounds and musics | |
| /// The default volume is 100 | | | |
| /// | | /// | |
|
| /// \param Volume : New global volume, in the range [0, 100] | | /// The volume is a number between 0 and 100; it is combined with | |
| | | /// the individual volume of each sound / music. | |
| | | /// The default value for the volume is 100 (maximum). | |
| | | /// | |
| | | /// \param volume New global volume, in the range [0, 100] | |
| | | /// | |
| | | /// \see getGlobalVolume | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static void SetGlobalVolume(float Volume); | | static void setGlobalVolume(float volume); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the current value of the global volume of all the sounds | | /// \brief Get the current value of the global volume | |
| /// | | /// | |
| /// \return Current global volume, in the range [0, 100] | | /// \return Current global volume, in the range [0, 100] | |
| /// | | /// | |
|
| | | /// \see setGlobalVolume | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static float GetGlobalVolume(); | | static float getGlobalVolume(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the position of the listener (take 3 values). | | /// \brief Set the position of the listener in the scene | |
| /// The default position is (0, 0, 0) | | /// | |
| | | /// The default listener's position is (0, 0, 0). | |
| /// | | /// | |
|
| /// \param X, Y, Z : Position of the listener in the world | | /// \param x X coordinate of the listener's position | |
| | | /// \param y Y coordinate of the listener's position | |
| | | /// \param z Z coordinate of the listener's position | |
| | | /// | |
| | | /// \see getPosition, setDirection | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static void SetPosition(float X, float Y, float Z); | | static void setPosition(float x, float y, float z); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the position of the listener (take a 3D vector). | | /// \brief Set the position of the listener in the scene | |
| /// The default position is (0, 0, 0) | | /// | |
| | | /// The default listener's position is (0, 0, 0). | |
| /// | | /// | |
|
| /// \param Position : Position of the listener in the world | | /// \param position New listener's position | |
| | | /// | |
| | | /// \see getPosition, setDirection | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static void SetPosition(const Vector3f& Position); | | static void setPosition(const Vector3f& position); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the current position of the listener | | /// \brief Get the current position of the listener in the scene | |
| | | /// | |
| | | /// \return Listener's position | |
| /// | | /// | |
|
| /// \return Position of the listener in the world | | /// \see setPosition | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Vector3f GetPosition(); | | static Vector3f getPosition(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the orientation of the listener (the point | | /// \brief Set the orientation of the listener in the scene | |
| /// 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 | | /// The orientation defines the 3D axes of the listener | |
| | | /// (left, up, front) in the scene. The orientation vector | |
| | | /// doesn't have to be normalized. | |
| | | /// The default listener's orientation is (0, 0, -1). | |
| | | /// | |
| | | /// \param x X coordinate of the listener's orientation | |
| | | /// \param y Y coordinate of the listener's orientation | |
| | | /// \param z Z coordinate of the listener's orientation | |
| | | /// | |
| | | /// \see getDirection, setPosition | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static void SetTarget(float X, float Y, float Z); | | static void setDirection(float x, float y, float z); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the orientation of the listener (the point | | /// \brief Set the orientation of the listener in the scene | |
| /// he must look at) (take a 3D vector). | | /// | |
| /// The default target is (0, 0, -1) | | /// The orientation defines the 3D axes of the listener | |
| | | /// (left, up, front) in the scene. The orientation vector | |
| | | /// doesn't have to be normalized. | |
| | | /// The default listener's orientation is (0, 0, -1). | |
| | | /// | |
| | | /// \param direction New listener's orientation | |
| /// | | /// | |
|
| /// \param Target : Position of the point the listener must look at | | /// \see getDirection, setPosition | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static void SetTarget(const Vector3f& Target); | | static void setDirection(const Vector3f& direction); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the current orientation of the listener (the point | | /// \brief Get the current orientation of the listener in the scene | |
| /// he's looking at) | | | |
| /// | | /// | |
|
| /// \return : Position of the point the listener is looking at | | /// \return Listener's orientation | |
| | | /// | |
| | | /// \see setDirection | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Vector3f GetTarget(); | | static Vector3f getDirection(); | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_LISTENER_HPP | | #endif // SFML_LISTENER_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Listener | |
| | | /// \ingroup audio | |
| | | /// | |
| | | /// The audio listener defines the global properties of the | |
| | | /// audio environment, it defines where and how sounds and musics | |
| | | /// are heard. If sf::View is the eyes of the user, then sf::Listener | |
| | | /// is his ears (by the way, they are often linked together -- | |
| | | /// same position, orientation, etc.). | |
| | | /// | |
| | | /// sf::Listener is a simple interface, which allows to setup the | |
| | | /// listener in the 3D audio environment (position and direction), | |
| | | /// and to adjust the global volume. | |
| | | /// | |
| | | /// Because the listener is unique in the scene, sf::Listener only | |
| | | /// contains static functions and doesn't have to be instanciated. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Move the listener to the position (1, 0, -5) | |
| | | /// sf::Listener::setPosition(1, 0, -5); | |
| | | /// | |
| | | /// // Make it face the right axis (1, 0, 0) | |
| | | /// sf::Listener::setDirection(1, 0, 0); | |
| | | /// | |
| | | /// // Reduce the global volume | |
| | | /// sf::Listener::setGlobalVolume(50); | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 29 change blocks. |
| 37 lines changed or deleted | | 67 lines changed or added | |
|
| Music.hpp | | Music.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_MUSIC_HPP | | #ifndef SFML_MUSIC_HPP | |
| #define SFML_MUSIC_HPP | | #define SFML_MUSIC_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/Audio/Export.hpp> | |
| #include <SFML/Audio/SoundStream.hpp> | | #include <SFML/Audio/SoundStream.hpp> | |
|
| | | #include <SFML/System/Mutex.hpp> | |
| | | #include <SFML/System/Time.hpp> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| namespace priv | | namespace priv | |
| { | | { | |
| class SoundFile; | | class SoundFile; | |
| } | | } | |
| | | | |
|
| | | class InputStream; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Music defines a big sound played using streaming, | | /// \brief Streamed music played from an audio file | |
| /// so usually what we call a music :) | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Music : public SoundStream | | class SFML_AUDIO_API Music : public SoundStream | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the music with a buffer size | | /// \brief Default constructor | |
| /// | | | |
| /// \param BufferSize : Size of the internal buffer, expressed in numbe | | | |
| r of samples | | | |
| /// (ie. size taken by the music in memory) (44100 | | | |
| by default) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| explicit Music(std::size_t BufferSize = 44100); | | Music(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor | | /// \brief Destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| ~Music(); | | ~Music(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Open a music file (doesn't play it -- call Play() for that) | | /// \brief Open a music from an audio file | |
| | | /// | |
| | | /// This function doesn't start playing the music (call play() | |
| | | /// to do so). | |
| | | /// Here is a complete list of all the supported audio formats: | |
| | | /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, | |
| | | /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. | |
| | | /// | |
| | | /// \param filename Path of the music file to open | |
| /// | | /// | |
|
| /// \param Filename : Path of the music file to open | | /// \return True if loading succeeded, false if it failed | |
| /// | | /// | |
|
| /// \return True if loading has been successful | | /// \see openFromMemory, openFromStream | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool OpenFromFile(const std::string& Filename); | | bool openFromFile(const std::string& filename); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Open a music file from memory (doesn't play it -- call Play() for t
hat) | | /// \brief Open a music from an audio file in memory | |
| /// | | /// | |
|
| /// \param Data : Pointer to the file data in memory | | /// This function doesn't start playing the music (call play() | |
| /// \param SizeInBytes : Size of the data to load, in bytes | | /// to do so). | |
| | | /// Here is a complete list of all the supported audio formats: | |
| | | /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, | |
| | | /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. | |
| | | /// Since the music is not loaded completely but rather streamed | |
| | | /// continuously, the \a data must remain available as long as the | |
| | | /// music is playing (ie. you can't deallocate it right after calling | |
| | | /// this function). | |
| /// | | /// | |
|
| /// \return True if loading has been successful | | /// \param data Pointer to the file data in memory | |
| | | /// \param sizeInBytes Size of the data to load, in bytes | |
| | | /// | |
| | | /// \return True if loading succeeded, false if it failed | |
| | | /// | |
| | | /// \see openFromFile, openFromStream | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool OpenFromMemory(const char* Data, std::size_t SizeInBytes); | | bool openFromMemory(const void* data, std::size_t sizeInBytes); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the music duration | | /// \brief Open a music from an audio file in a custom stream | |
| | | /// | |
| | | /// This function doesn't start playing the music (call play() | |
| | | /// to do so). | |
| | | /// Here is a complete list of all the supported audio formats: | |
| | | /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, | |
| | | /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. | |
| | | /// Since the music is not loaded completely but rather streamed | |
| | | /// continuously, the \a stream must remain alive as long as the | |
| | | /// music is playing (ie. you can't destroy it right after calling | |
| | | /// this function). | |
| /// | | /// | |
|
| /// \return Music duration, in seconds | | /// \param stream Source stream to read from | |
| | | /// | |
| | | /// \return True if loading succeeded, false if it failed | |
| | | /// | |
| | | /// \see openFromFile, openFromMemory | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| float GetDuration() const; | | bool openFromStream(InputStream& stream); | |
| | | | |
|
| private : | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Get the total duration of the music | |
| | | /// | |
| | | /// \return Music duration | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Time getDuration() const; | |
| | | | |
| | | protected : | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Request a new chunk of audio samples from the stream source | |
| | | /// | |
| | | /// This function fills the chunk from the next samples | |
| | | /// to read from the audio file. | |
| | | /// | |
| | | /// \param data Chunk of data to fill | |
| | | /// | |
| | | /// \return True to continue playback, false to stop | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | virtual bool onGetData(Chunk& data); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see SoundStream::OnStart | | /// \brief Change the current playing position in the stream source | |
| | | /// | |
| | | /// \param timeOffset New playing position, from the beginning of the m | |
| | | usic | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnStart(); | | virtual void onSeek(Time timeOffset); | |
| | | | |
| | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see SoundStream::OnGetData | | /// \brief Initialize the internal state after loading a new music | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnGetData(Chunk& Data); | | void initialize(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| priv::SoundFile* myFile; ///< Sound file | | priv::SoundFile* m_file; ///< Sound file | |
| float myDuration; ///< Music duration, in seconds | | Time m_duration; ///< Music duration | |
| std::vector<Int16> mySamples; ///< Temporary buffer of samples | | std::vector<Int16> m_samples; ///< Temporary buffer of samples | |
| | | Mutex m_mutex; ///< Mutex protecting the data | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_MUSIC_HPP | | #endif // SFML_MUSIC_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Music | |
| | | /// \ingroup audio | |
| | | /// | |
| | | /// Musics are sounds that are streamed rather than completely | |
| | | /// loaded in memory. This is especially useful for compressed | |
| | | /// musics that usually take hundreds of MB when they are | |
| | | /// uncompressed: by streaming it instead of loading it entirely, | |
| | | /// you avoid saturating the memory and have almost no loading delay. | |
| | | /// | |
| | | /// Apart from that, a sf::Music has almost the same features as | |
| | | /// the sf::SoundBuffer / sf::Sound pair: you can play/pause/stop | |
| | | /// it, request its parameters (channels, sample rate), change | |
| | | /// the way it is played (pitch, volume, 3D position, ...), etc. | |
| | | /// | |
| | | /// As a sound stream, a music is played in its own thread in order | |
| | | /// not to block the rest of the program. This means that you can | |
| | | /// leave the music alone after calling play(), it will manage itself | |
| | | /// very well. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Declare a new music | |
| | | /// sf::Music music; | |
| | | /// | |
| | | /// // Open it from an audio file | |
| | | /// if (!music.openFromFile("music.ogg")) | |
| | | /// { | |
| | | /// // error... | |
| | | /// } | |
| | | /// | |
| | | /// // Change some parameters | |
| | | /// music.setPosition(0, 1, 10); // change its 3D position | |
| | | /// music.setPitch(2); // increase the pitch | |
| | | /// music.setVolume(50); // reduce the volume | |
| | | /// music.setLoop(true); // make it loop | |
| | | /// | |
| | | /// // Play it | |
| | | /// music.play(); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::Sound, sf::SoundStream | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 27 change blocks. |
| 32 lines changed or deleted | | 93 lines changed or added | |
|
| Packet.hpp | | Packet.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_PACKET_HPP | | #ifndef SFML_PACKET_HPP | |
| #define SFML_PACKET_HPP | | #define SFML_PACKET_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Config.hpp> | | #include <SFML/Network/Export.hpp> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| | | class String; | |
| | | class TcpSocket; | |
| | | class UdpSocket; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Packet wraps data to send / to receive through the network | | /// \brief Utility class to build blocks of data to transfer | |
| | | /// over the network | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Packet | | class SFML_NETWORK_API Packet | |
| { | | { | |
|
| | | // A bool-like type that cannot be converted to integer or pointer type | |
| | | s | |
| | | typedef bool (Packet::*BoolType)(std::size_t); | |
| | | | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// Creates an empty packet. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Packet(); | | Packet(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Virtual destructor | | /// \brief Virtual destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| virtual ~Packet(); | | virtual ~Packet(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Append data to the end of the packet | | /// \brief Append data to the end of the packet | |
| /// | | /// | |
|
| /// \param Data : Pointer to the bytes to append | | /// \param data Pointer to the sequence of bytes to append | |
| /// \param SizeInBytes : Number of bytes to append | | /// \param sizeInBytes Number of bytes to append | |
| | | /// | |
| | | /// \see clear | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Append(const void* Data, std::size_t SizeInBytes); | | void append(const void* data, std::size_t sizeInBytes); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Clear the packet data | | /// \brief Clear the packet | |
| | | /// | |
| | | /// After calling Clear, the packet is empty. | |
| | | /// | |
| | | /// \see append | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Clear(); | | void clear(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get a pointer to the data contained in the packet | | /// \brief Get a pointer to the data contained in the packet | |
| /// Warning : the returned pointer may be invalid after you | | /// | |
| /// append data to the packet | | /// Warning: the returned pointer may become invalid after | |
| | | /// you append data to the packet, therefore it should never | |
| | | /// be stored. | |
| | | /// The return pointer is NULL if the packet is empty. | |
| /// | | /// | |
| /// \return Pointer to the data | | /// \return Pointer to the data | |
| /// | | /// | |
|
| | | /// \see getDataSize | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const char* GetData() const; | | const void* getData() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the size of the data contained in the packet | | /// \brief Get the size of the data contained in the packet | |
| | | /// | |
| | | /// This function returns the number of bytes pointed to by | |
| | | /// what getData returns. | |
| /// | | /// | |
| /// \return Data size, in bytes | | /// \return Data size, in bytes | |
| /// | | /// | |
|
| | | /// \see getData | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::size_t GetDataSize() const; | | std::size_t getDataSize() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Tell if the reading position has reached the end of the packet | | /// \brief Tell if the reading position has reached the | |
| | | /// end of the packet | |
| | | /// | |
| | | /// This function is useful to know if there is some data | |
| | | /// left to be read, without actually reading it. | |
| /// | | /// | |
|
| /// \return True if all data have been read into the packet | | /// \return True if all data was read, false otherwise | |
| | | /// | |
| | | /// \see operator bool | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool EndOfPacket() const; | | bool endOfPacket() const; | |
| | | | |
| | | public: | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Return the validity of packet | | /// \brief Test the validity of the packet, for reading | |
| | | /// | |
| | | /// This operator allows to test the packet as a boolean | |
| | | /// variable, to check if a reading operation was successful. | |
| | | /// | |
| | | /// A packet will be in an invalid state if it has no more | |
| | | /// data to read. | |
| | | /// | |
| | | /// This behaviour is the same as standard C++ streams. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// float x; | |
| | | /// packet >> x; | |
| | | /// if (packet) | |
| | | /// { | |
| | | /// // ok, x was extracted successfully | |
| | | /// } | |
| | | /// | |
| | | /// // -- or -- | |
| | | /// | |
| | | /// float x; | |
| | | /// if (packet >> x) | |
| | | /// { | |
| | | /// // ok, x was extracted successfully | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | /// Don't focus on the return type, it's equivalent to bool but | |
| | | /// it disallows unwanted implicit conversions to integer or | |
| | | /// pointer types. | |
| /// | | /// | |
| /// \return True if last data extraction from packet was successful | | /// \return True if last data extraction from packet was successful | |
| /// | | /// | |
|
| | | /// \see endOfPacket | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| operator bool() const; | | operator BoolType() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator >> overloads to extract data from the packet | | /// Overloads of operator >> to read data from the packet | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Packet& operator >>(bool& Data); | | Packet& operator >>(bool& data); | |
| Packet& operator >>(Int8& Data); | | Packet& operator >>(Int8& data); | |
| Packet& operator >>(Uint8& Data); | | Packet& operator >>(Uint8& data); | |
| Packet& operator >>(Int16& Data); | | Packet& operator >>(Int16& data); | |
| Packet& operator >>(Uint16& Data); | | Packet& operator >>(Uint16& data); | |
| Packet& operator >>(Int32& Data); | | Packet& operator >>(Int32& data); | |
| Packet& operator >>(Uint32& Data); | | Packet& operator >>(Uint32& data); | |
| Packet& operator >>(float& Data); | | Packet& operator >>(float& data); | |
| Packet& operator >>(double& Data); | | Packet& operator >>(double& data); | |
| Packet& operator >>(char* Data); | | Packet& operator >>(char* data); | |
| Packet& operator >>(std::string& Data); | | Packet& operator >>(std::string& data); | |
| Packet& operator >>(wchar_t* Data); | | Packet& operator >>(wchar_t* data); | |
| Packet& operator >>(std::wstring& Data); | | Packet& operator >>(std::wstring& data); | |
| | | Packet& operator >>(String& 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 : | | //////////////////////////////////////////////////////////// | |
| | | /// Overloads of operator << to write 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); | |
| | | Packet& operator <<(const String& data); | |
| | | | |
| | | protected: | |
| | | | |
|
| friend class SocketTCP; | | friend class TcpSocket; | |
| friend class SocketUDP; | | friend class UdpSocket; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Check if the packet can extract a given size of bytes | | /// \brief Called before the packet is sent over the network | |
| /// | | /// | |
|
| /// \param Size : Size to check | | /// This function can be defined by derived classes to | |
| | | /// transform the data before it is sent; this can be | |
| | | /// used for compression, encryption, etc. | |
| | | /// The function must return a pointer to the modified data, | |
| | | /// as well as the number of bytes pointed. | |
| | | /// The default implementation provides the packet's data | |
| | | /// without transforming it. | |
| /// | | /// | |
|
| /// \return True if Size bytes can be read from the packet's data | | /// \param size Variable to fill with the size of data to send | |
| | | /// | |
| | | /// \return Pointer to the array of bytes to send | |
| | | /// | |
| | | /// \see onReceive | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool CheckSize(std::size_t Size); | | virtual const void* onSend(std::size_t& size); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Called before the packet is sent to the network | | /// \brief Called after the packet is received over the network | |
| /// | | /// | |
|
| /// \param DataSize : Variable to fill with the size of data to send | | /// This function can be defined by derived classes to | |
| | | /// transform the data after it is received; this can be | |
| | | /// used for uncompression, decryption, etc. | |
| | | /// The function receives a pointer to the received data, | |
| | | /// and must fill the packet with the transformed bytes. | |
| | | /// The default implementation fills the packet directly | |
| | | /// without transforming the data. | |
| /// | | /// | |
|
| /// \return Pointer to the array of bytes to send | | /// \param data Pointer to the received bytes | |
| | | /// \param size Number of bytes | |
| | | /// | |
| | | /// \see onSend | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual const char* OnSend(std::size_t& DataSize); | | virtual void onReceive(const void* data, std::size_t size); | |
| | | | |
| | | private : | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// Disallow comparisons between packets | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | bool operator ==(const Packet& right) const; | |
| | | bool operator !=(const Packet& right) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Called after the packet has been received from the network | | /// \brief Check if the packet can extract a given number of bytes | |
| /// | | /// | |
|
| /// \param Data : Pointer to the array of received bytes | | /// This function updates accordingly the state of the packet. | |
| /// \param DataSize : Size of the array of bytes | | /// | |
| | | /// \param size Size to check | |
| | | /// | |
| | | /// \return True if \a size bytes can be read from the packet | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void OnReceive(const char* Data, std::size_t DataSize); | | bool checkSize(std::size_t size); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::vector<char> myData; ///< Data stored in the packet | | std::vector<char> m_data; ///< Data stored in the packet | |
| std::size_t myReadPos; ///< Current reading position in the packe | | std::size_t m_readPos; ///< Current reading position in the packe | |
| t | | t | |
| bool myIsValid; ///< Reading state of the packet | | bool m_isValid; ///< Reading state of the packet | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_PACKET_HPP | | #endif // SFML_PACKET_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Packet | |
| | | /// \ingroup network | |
| | | /// | |
| | | /// Packets provide a safe and easy way to serialize data, | |
| | | /// in order to send it over the network using sockets | |
| | | /// (sf::TcpSocket, sf::UdpSocket). | |
| | | /// | |
| | | /// Packets solve 2 fundamental problems that arise when | |
| | | /// transfering data over the network: | |
| | | /// \li data is interpreted correctly according to the endianness | |
| | | /// \li the bounds of the packet are preserved (one send == one receive) | |
| | | /// | |
| | | /// The sf::Packet class provides both input and output modes. | |
| | | /// It is designed to follow the behaviour of standard C++ streams, | |
| | | /// using operators >> and << to extract and insert data. | |
| | | /// | |
| | | /// It is recommended to use only fixed-size types (like sf::Int32, etc.), | |
| | | /// to avoid possible differences between the sender and the receiver. | |
| | | /// Indeed, the native C++ types may have different sizes on two platforms | |
| | | /// and your data may be corrupted if that happens. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// sf::Uint32 x = 24; | |
| | | /// std::string s = "hello"; | |
| | | /// double d = 5.89; | |
| | | /// | |
| | | /// // Group the variables to send into a packet | |
| | | /// sf::Packet packet; | |
| | | /// packet << x << s << d; | |
| | | /// | |
| | | /// // Send it over the network (socket is a valid sf::TcpSocket) | |
| | | /// socket.send(packet); | |
| | | /// | |
| | | /// ----------------------------------------------------------------- | |
| | | /// | |
| | | /// // Receive the packet at the other end | |
| | | /// sf::Packet packet; | |
| | | /// socket.receive(packet); | |
| | | /// | |
| | | /// // Extract the variables contained in the packet | |
| | | /// sf::Uint32 x; | |
| | | /// std::string s; | |
| | | /// double d; | |
| | | /// if (packet >> x >> s >> d) | |
| | | /// { | |
| | | /// // Data extracted successfully... | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | /// Packets have built-in operator >> and << overloads for | |
| | | /// standard types: | |
| | | /// \li bool | |
| | | /// \li fixed-size integer types (sf::Int8/16/32, sf::Uint8/16/32) | |
| | | /// \li floating point numbers (float, double) | |
| | | /// \li string types (char*, wchar_t*, std::string, std::wstring, sf::Strin | |
| | | g) | |
| | | /// | |
| | | /// Like standard streams, it is also possible to define your own | |
| | | /// overloads of operators >> and << in order to handle your | |
| | | /// custom types. | |
| | | /// | |
| | | /// \code | |
| | | /// struct MyStruct | |
| | | /// { | |
| | | /// float number; | |
| | | /// sf::Int8 integer; | |
| | | /// std::string str; | |
| | | /// }; | |
| | | /// | |
| | | /// sf::Packet& operator <<(sf::Packet& packet, const MyStruct& m) | |
| | | /// { | |
| | | /// return packet << m.number << m.integer << m.str; | |
| | | /// } | |
| | | /// | |
| | | /// sf::Packet& operator >>(sf::Packet& packet, MyStruct& m) | |
| | | /// { | |
| | | /// return packet >> m.number >> m.integer >> m.str; | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | /// Packets also provide an extra feature that allows to apply | |
| | | /// custom transformations to the data before it is sent, | |
| | | /// and after it is received. This is typically used to | |
| | | /// handle automatic compression or encryption of the data. | |
| | | /// This is achieved by inheriting from sf::Packet, and overriding | |
| | | /// the onSend and onReceive functions. | |
| | | /// | |
| | | /// Here is an example: | |
| | | /// \code | |
| | | /// class ZipPacket : public sf::Packet | |
| | | /// { | |
| | | /// virtual const void* onSend(std::size_t& size) | |
| | | /// { | |
| | | /// const void* srcData = getData(); | |
| | | /// std::size_t srcSize = getDataSize(); | |
| | | /// | |
| | | /// return MySuperZipFunction(srcData, srcSize, &size); | |
| | | /// } | |
| | | /// | |
| | | /// virtual void onReceive(const void* data, std::size_t size) | |
| | | /// { | |
| | | /// std::size_t dstSize; | |
| | | /// const void* dstData = MySuperUnzipFunction(data, size, &dstSize | |
| | | ); | |
| | | /// | |
| | | /// append(dstData, dstSize); | |
| | | /// } | |
| | | /// }; | |
| | | /// | |
| | | /// // Use like regular packets: | |
| | | /// ZipPacket packet; | |
| | | /// packet << x << s << d; | |
| | | /// ... | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::TcpSocket, sf::UdpSocket | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 42 change blocks. |
| 74 lines changed or deleted | | 175 lines changed or added | |
|
| Rect.hpp | | Rect.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_RECT_HPP | | #ifndef SFML_RECT_HPP | |
| #define SFML_RECT_HPP | | #define SFML_RECT_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/System/Vector2.hpp> | |
| #include <algorithm> | | #include <algorithm> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Rect is an utility class for manipulating rectangles. | | /// \brief Utility class for manipulating 2D axis aligned rectangles | |
| /// Template parameter defines the type of coordinates (integer, float, ... | | /// | |
| ) | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
| class Rect | | class Rect | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// Creates an empty rectangle (it is equivalent to calling | |
| | | /// Rect(0, 0, 0, 0)). | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Rect(); | | Rect(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the rectangle from its coordinates | | /// \brief Construct the rectangle from its coordinates | |
| | | /// | |
| | | /// Be careful, the last two parameters are the width | |
| | | /// and height, not the right and bottom coordinates! | |
| /// | | /// | |
|
| /// \param LeftCoord : Left coordinate of the rectangle | | /// \param rectLeft Left coordinate of the rectangle | |
| /// \param TopCoord : Top coordinate of the rectangle | | /// \param rectTop Top coordinate of the rectangle | |
| /// \param RightCoord : Right coordinate of the rectangle | | /// \param rectWidth Width of the rectangle | |
| /// \param BottomCoord : Bottom coordinate of the rectangle | | /// \param rectHeight Height of the rectangle | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord); | | Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the width of the rectangle | | /// \brief Construct the rectangle from position and size | |
| /// | | /// | |
|
| /// \return Width of rectangle | | /// Be careful, the last parameter is the size, | |
| | | /// not the bottom-right corner! | |
| | | /// | |
| | | /// \param position Position of the top-left corner of the rectangle | |
| | | /// \param size Size of the rectangle | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| T GetWidth() const; | | Rect(const Vector2<T>& position, const Vector2<T>& size); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the height of the rectangle | | /// \brief Construct the rectangle from another type of rectangle | |
| | | /// | |
| | | /// This constructor doesn't replace the copy constructor, | |
| | | /// it's called only when U != T. | |
| | | /// A call to this constructor will fail to compile if U | |
| | | /// is not convertible to T. | |
| /// | | /// | |
|
| /// \return Height of rectangle | | /// \param rectangle Rectangle to convert | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| T GetHeight() const; | | template <typename U> | |
| | | explicit Rect(const Rect<U>& rectangle); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Move the whole rectangle by the given offset | | /// \brief Check if a point is inside the rectangle's area | |
| /// | | /// | |
|
| /// \param OffsetX : Horizontal offset | | /// \param x X coordinate of the point to test | |
| /// \param OffsetY : Vertical offset | | /// \param y Y coordinate of the point to test | |
| | | /// | |
| | | /// \return True if the point is inside, false otherwise | |
| | | /// | |
| | | /// \see intersects | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Offset(T OffsetX, T OffsetY); | | bool contains(T x, T y) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Check if a point is inside the rectangle's area | | /// \brief Check if a point is inside the rectangle's area | |
| | | /// | |
| | | /// \param point Point to test | |
| /// | | /// | |
|
| /// \param X : X coordinate of the point to test | | /// \return True if the point is inside, false otherwise | |
| /// \param Y : Y coordinate of the point to test | | | |
| /// | | /// | |
|
| /// \return True if the point is inside | | /// \see intersects | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool Contains(T X, T Y) const; | | bool contains(const Vector2<T>& point) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Check intersection between two rectangles | | /// \brief Check the intersection between two rectangles | |
| /// | | /// | |
|
| /// \param Rectangle : Rectangle to test | | /// \param rectangle Rectangle to test | |
| /// \param OverlappingRect : Rectangle to be filled with overlapping re | | | |
| ct (NULL by default) | | | |
| /// | | /// | |
|
| /// \return True if rectangles overlap | | /// \return True if rectangles overlap, false otherwise | |
| | | /// | |
| | | /// \see contains | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect = NU | | bool intersects(const Rect<T>& rectangle) const; | |
| LL) const; | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Check the intersection between two rectangles | |
| | | /// | |
| | | /// This overload returns the overlapped rectangle in the | |
| | | /// \a intersection parameter. | |
| | | /// | |
| | | /// \param rectangle Rectangle to test | |
| | | /// \param intersection Rectangle to be filled with the intersection | |
| | | /// | |
| | | /// \return True if rectangles overlap, false otherwise | |
| | | /// | |
| | | /// \see contains | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | bool intersects(const Rect<T>& rectangle, Rect<T>& intersection) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| T Left; ///< Left coordinate of the rectangle | | T left; ///< Left coordinate of the rectangle | |
| T Top; ///< Top coordinate of the rectangle | | T top; ///< Top coordinate of the rectangle | |
| T Right; ///< Right coordinate of the rectangle | | T width; ///< Width of the rectangle | |
| T Bottom; ///< Bottom coordinate of the rectangle | | T height; ///< Height of the rectangle | |
| }; | | }; | |
| | | | |
|
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates Rect | |
| | | /// \brief Overload of binary operator == | |
| | | /// | |
| | | /// This operator compares strict equality between two rectangles. | |
| | | /// | |
| | | /// \param left Left operand (a rectangle) | |
| | | /// \param right Right operand (a rectangle) | |
| | | /// | |
| | | /// \return True if \a left is equal to \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename T> | |
| | | bool operator ==(const Rect<T>& left, const Rect<T>& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates Rect | |
| | | /// \brief Overload of binary operator != | |
| | | /// | |
| | | /// This operator compares strict difference between two rectangles. | |
| | | /// | |
| | | /// \param left Left operand (a rectangle) | |
| | | /// \param right Right operand (a rectangle) | |
| | | /// | |
| | | /// \return True if \a left is not equal to \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename T> | |
| | | bool operator !=(const Rect<T>& left, const Rect<T>& right); | |
| | | | |
| #include <SFML/Graphics/Rect.inl> | | #include <SFML/Graphics/Rect.inl> | |
| | | | |
|
| // Define the most common types | | // Create typedefs for the most common types | |
| typedef Rect<int> IntRect; | | typedef Rect<int> IntRect; | |
| typedef Rect<float> FloatRect; | | typedef Rect<float> FloatRect; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_RECT_HPP | | #endif // SFML_RECT_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Rect | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// A rectangle is defined by its top-left corner and its size. | |
| | | /// It is a very simple class defined for convenience, so | |
| | | /// its member variables (left, top, width and height) are public | |
| | | /// and can be accessed directly, just like the vector classes | |
| | | /// (Vector2 and Vector3). | |
| | | /// | |
| | | /// To keep things simple, sf::Rect doesn't define | |
| | | /// functions to emulate the properties that are not directly | |
| | | /// members (such as right, bottom, center, etc.), it rather | |
| | | /// only provides intersection functions. | |
| | | /// | |
| | | /// sf::Rect uses the usual rules for its boundaries: | |
| | | /// \li The left and top edges are included in the rectangle's area | |
| | | /// \li The right (left + width) and bottom (top + height) edges are exclud | |
| | | ed from the rectangle's area | |
| | | /// | |
| | | /// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1) | |
| | | /// don't intersect. | |
| | | /// | |
| | | /// sf::Rect is a template and may be used with any numeric type, but | |
| | | /// for simplicity the instanciations used by SFML are typedefed: | |
| | | /// \li sf::Rect<int> is sf::IntRect | |
| | | /// \li sf::Rect<float> is sf::FloatRect | |
| | | /// | |
| | | /// So that you don't have to care about the template syntax. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Define a rectangle, located at (0, 0) with a size of 20x5 | |
| | | /// sf::IntRect r1(0, 0, 20, 5); | |
| | | /// | |
| | | /// // Define another rectangle, located at (4, 2) with a size of 18x10 | |
| | | /// sf::Vector2i position(4, 2); | |
| | | /// sf::Vector2i size(18, 10); | |
| | | /// sf::IntRect r2(position, size); | |
| | | /// | |
| | | /// // Test intersections with the point (3, 1) | |
| | | /// bool b1 = r1.contains(3, 1); // true | |
| | | /// bool b2 = r2.contains(3, 1); // false | |
| | | /// | |
| | | /// // Test the intersection between r1 and r2 | |
| | | /// sf::IntRect result; | |
| | | /// bool b3 = r1.intersects(r2, result); // true | |
| | | /// // result == (4, 2, 16, 3) | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 28 change blocks. |
| 38 lines changed or deleted | | 104 lines changed or added | |
|
| Rect.inl | | Rect.inl | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2012 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 26 | | skipping to change at line 26 | |
| // in the product documentation would be appreciated but is not required
. | | // in the product documentation would be appreciated but is not required
. | |
| // | | // | |
| // 2. Altered source versions must be plainly marked as such, | | // 2. Altered source versions must be plainly marked as such, | |
| // and must not be misrepresented as being the original software. | | // and must not be misrepresented as being the original software. | |
| // | | // | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
| Rect<T>::Rect() : | | Rect<T>::Rect() : | |
|
| Left (0), | | left (0), | |
| Top (0), | | top (0), | |
| Right (0), | | width (0), | |
| Bottom(0) | | height(0) | |
| { | | { | |
| | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the color from its coordinates | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Rect<T>::Rect(T LeftCoord, T TopCoord, T RightCoord, T BottomCoord) : | | Rect<T>::Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight) : | |
| Left (LeftCoord), | | left (rectLeft), | |
| Top (TopCoord), | | top (rectTop), | |
| Right (RightCoord), | | width (rectWidth), | |
| Bottom(BottomCoord) | | height(rectHeight) | |
| { | | { | |
| | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the width of the rectangle | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| T Rect<T>::GetWidth() const | | Rect<T>::Rect(const Vector2<T>& position, const Vector2<T>& size) : | |
| | | left (position.x), | |
| | | top (position.y), | |
| | | width (size.x), | |
| | | height(size.y) | |
| { | | { | |
|
| return Right - Left; | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the height of the rectangle | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| T Rect<T>::GetHeight() const | | template <typename U> | |
| | | Rect<T>::Rect(const Rect<U>& rectangle) : | |
| | | left (static_cast<T>(rectangle.left)), | |
| | | top (static_cast<T>(rectangle.top)), | |
| | | width (static_cast<T>(rectangle.width)), | |
| | | height(static_cast<T>(rectangle.height)) | |
| { | | { | |
|
| return Bottom - Top; | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Move the whole rectangle by the given offset | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| void Rect<T>::Offset(T OffsetX, T OffsetY) | | bool Rect<T>::contains(T x, T y) const | |
| { | | { | |
|
| Left += OffsetX; | | return (x >= left) && (x < left + width) && (y >= top) && (y < top + he | |
| Right += OffsetX; | | ight); | |
| Top += OffsetY; | | | |
| Bottom += OffsetY; | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Check if a point is inside the rectangle's area | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| bool Rect<T>::Contains(T X, T Y) const | | bool Rect<T>::contains(const Vector2<T>& point) const | |
| { | | { | |
|
| return (X >= Left) && (X <= Right) && (Y >= Top) && (Y <= Bottom); | | return contains(point.x, point.y); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Check intersection between two rectangles | | template <typename T> | |
| | | bool Rect<T>::intersects(const Rect<T>& rectangle) const | |
| | | { | |
| | | Rect<T> intersection; | |
| | | return intersects(rectangle, intersection); | |
| | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| bool Rect<T>::Intersects(const Rect<T>& Rectangle, Rect<T>* OverlappingRect
) const | | bool Rect<T>::intersects(const Rect<T>& rectangle, Rect<T>& intersection) c
onst | |
| { | | { | |
|
| // Compute overlapping rect | | // Compute the intersection boundaries | |
| Rect Overlapping(std::max(Left, Rectangle.Left), | | T interLeft = std::max(left, rectangle.left); | |
| std::max(Top, Rectangle.Top), | | T interTop = std::max(top, rectangle.top); | |
| std::min(Right, Rectangle.Right), | | T interRight = std::min(left + width, rectangle.left + rectangle.width | |
| std::min(Bottom, Rectangle.Bottom)); | | ); | |
| | | T interBottom = std::min(top + height, rectangle.top + rectangle.height | |
| | | ); | |
| | | | |
|
| // If overlapping rect is valid, then there is intersection | | // If the intersection is valid (positive non zero area), then there is | |
| if ((Overlapping.Left < Overlapping.Right) && (Overlapping.Top < Overla | | an intersection | |
| pping.Bottom)) | | if ((interLeft < interRight) && (interTop < interBottom)) | |
| { | | { | |
|
| if (OverlappingRect) | | intersection = Rect<T>(interLeft, interTop, interRight - interLeft, | |
| *OverlappingRect = Overlapping; | | interBottom - interTop); | |
| return true; | | return true; | |
| } | | } | |
| else | | else | |
| { | | { | |
|
| if (OverlappingRect) | | intersection = Rect<T>(0, 0, 0, 0); | |
| *OverlappingRect = Rect(0, 0, 0, 0); | | | |
| return false; | | return false; | |
| } | | } | |
| } | | } | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename T> | |
| | | inline bool operator ==(const Rect<T>& left, const Rect<T>& right) | |
| | | { | |
| | | return (left.left == right.left) && (left.width == right.width) && | |
| | | (left.top == right.top) && (left.height == right.height); | |
| | | } | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename T> | |
| | | inline bool operator !=(const Rect<T>& left, const Rect<T>& right) | |
| | | { | |
| | | return !(left == right); | |
| | | } | |
| | | | |
End of changes. 24 change blocks. |
| 47 lines changed or deleted | | 48 lines changed or added | |
|
| RenderTarget.hpp | | RenderTarget.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_RENDERTARGET_HPP | | #ifndef SFML_RENDERTARGET_HPP | |
| #define SFML_RENDERTARGET_HPP | | #define SFML_RENDERTARGET_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/Graphics/Color.hpp> | | #include <SFML/Graphics/Color.hpp> | |
|
| #include <SFML/Graphics/View.hpp> | | | |
| #include <SFML/Graphics/Rect.hpp> | | #include <SFML/Graphics/Rect.hpp> | |
|
| | | #include <SFML/Graphics/View.hpp> | |
| | | #include <SFML/Graphics/Transform.hpp> | |
| | | #include <SFML/Graphics/BlendMode.hpp> | |
| | | #include <SFML/Graphics/RenderStates.hpp> | |
| | | #include <SFML/Graphics/PrimitiveType.hpp> | |
| | | #include <SFML/Graphics/Vertex.hpp> | |
| | | #include <SFML/System/NonCopyable.hpp> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| class Drawable; | | class Drawable; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Base class for all render targets (window, image, ...) | | /// \brief Base class for all render targets (window, texture, ...) | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API RenderTarget | | class SFML_GRAPHICS_API RenderTarget : NonCopyable | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor | | /// \brief Destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| virtual ~RenderTarget(); | | virtual ~RenderTarget(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Clear the entire target with a single color | | /// \brief Clear the entire target with a single color | |
| /// | | /// | |
|
| /// \param FillColor : Color to use to clear the render target | | /// This function is usually called once every frame, | |
| | | /// to clear the previous contents of the target. | |
| | | /// | |
| | | /// \param color Fill color to use to clear the render target | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Clear(const Color& FillColor = Color(0, 0, 0)); | | void clear(const Color& color = Color(0, 0, 0, 255)); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Draw something into the target | | /// \brief Change the current active view | |
| | | /// | |
| | | /// The view is like a 2D camera, it controls which part of | |
| | | /// the 2D scene is visible, and how it is viewed in the | |
| | | /// render-target. | |
| | | /// The new view will affect everything that is drawn, until | |
| | | /// another view is set. | |
| | | /// The render target keeps its own copy of the view object, | |
| | | /// so it is not necessary to keep the original one alive | |
| | | /// after calling this function. | |
| | | /// To restore the original view of the target, you can pass | |
| | | /// the result of getDefaultView() to this function. | |
| /// | | /// | |
|
| /// \param Object : Object to draw | | /// \param view New view to use | |
| | | /// | |
| | | /// \see getView, getDefaultView | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void Draw(const Drawable& Object); | | void setView(const View& view); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the width of the rendering region of the target | | /// \brief Get the view currently in use in the render target | |
| | | /// | |
| | | /// \return The view object that is currently used | |
| /// | | /// | |
|
| /// \return Width in pixels | | /// \see setView, getDefaultView | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual unsigned int GetWidth() const = 0; | | const View& getView() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the height of the rendering region of the target | | /// \brief Get the default view of the render target | |
| | | /// | |
| | | /// The default view has the initial size of the render target, | |
| | | /// and never changes after the target has been created. | |
| /// | | /// | |
|
| /// \return Height in pixels | | /// \return The default view of the render target | |
| | | /// | |
| | | /// \see setView, getView | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual unsigned int GetHeight() const = 0; | | const View& getDefaultView() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the current active view. | | /// \brief Get the viewport of a view, applied to this render target | |
| | | /// | |
| | | /// The viewport is defined in the view as a ratio, this function | |
| | | /// simply applies this ratio to the current dimensions of the | |
| | | /// render target to calculate the pixels rectangle that the viewport | |
| | | /// actually covers in the target. | |
| | | /// | |
| | | /// \param view The view for which we want to compute the viewport | |
| /// | | /// | |
|
| /// \param NewView : New view to use (pass GetDefaultView() to set the
default view) | | /// \return Viewport rectangle, expressed in pixels | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetView(const View& NewView); | | IntRect getViewport(const View& view) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the current view | | /// \brief Convert a point from target coordinates to world | |
| | | /// coordinates, using the current view | |
| | | /// | |
| | | /// This function is an overload of the mapPixelToCoords | |
| | | /// function that implicitely uses the current view. | |
| | | /// It is equivalent to: | |
| | | /// \code | |
| | | /// target.mapPixelToCoords(point, target.getView()); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \param point Pixel to convert | |
| | | /// | |
| | | /// \return The converted point, in "world" coordinates | |
| /// | | /// | |
|
| /// \return Current view active in the window | | /// \see mapCoordsToPixel | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const View& GetView() const; | | Vector2f mapPixelToCoords(const Vector2i& point) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the default view of the window for read / write | | /// \brief Convert a point from target coordinates to world coordinates | |
| /// | | /// | |
|
| /// \return Default view | | /// This function finds the 2D position that matches the | |
| | | /// given pixel of the render-target. In other words, it does | |
| | | /// the inverse of what the graphics card does, to find the | |
| | | /// initial position of a rendered pixel. | |
| | | /// | |
| | | /// Initially, both coordinate systems (world units and target pixels) | |
| | | /// match perfectly. But if you define a custom view or resize your | |
| | | /// render-target, this assertion is not true anymore, ie. a point | |
| | | /// located at (10, 50) in your render-target may map to the point | |
| | | /// (150, 75) in your 2D world -- if the view is translated by (140, 25 | |
| | | ). | |
| | | /// | |
| | | /// For render-windows, this function is typically used to find | |
| | | /// which point (or object) is located below the mouse cursor. | |
| | | /// | |
| | | /// This version uses a custom view for calculations, see the other | |
| | | /// overload of the function if you want to use the current view of the | |
| | | /// render-target. | |
| | | /// | |
| | | /// \param point Pixel to convert | |
| | | /// \param view The view to use for converting the point | |
| | | /// | |
| | | /// \return The converted point, in "world" units | |
| | | /// | |
| | | /// \see mapCoordsToPixel | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| View& GetDefaultView(); | | Vector2f mapPixelToCoords(const Vector2i& point, const View& view) cons
t; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Tell SFML to preserve external OpenGL states, at the expense of | | /// \brief Convert a point from world coordinates to target | |
| /// more CPU charge. Use this function if you don't want SFML | | /// coordinates, using the current view | |
| /// 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 | | /// This function is an overload of the mapCoordsToPixel | |
| optimize | | /// function that implicitely uses the current view. | |
| | | /// It is equivalent to: | |
| | | /// \code | |
| | | /// target.mapCoordsToPixel(point, target.getView()); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \param point Point to convert | |
| | | /// | |
| | | /// \return The converted point, in target coordinates (pixels) | |
| | | /// | |
| | | /// \see mapPixelToCoords | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void PreserveOpenGLStates(bool Preserve); | | Vector2i mapCoordsToPixel(const Vector2f& point) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Convert a point from world coordinates to target coordinates | |
| | | /// | |
| | | /// This function finds the pixel of the render-target that matches | |
| | | /// the given 2D point. In other words, it goes through the same proces | |
| | | s | |
| | | /// as the graphics card, to compute the final position of a rendered p | |
| | | oint. | |
| | | /// | |
| | | /// Initially, both coordinate systems (world units and target pixels) | |
| | | /// match perfectly. But if you define a custom view or resize your | |
| | | /// render-target, this assertion is not true anymore, ie. a point | |
| | | /// located at (150, 75) in your 2D world may map to the pixel | |
| | | /// (10, 50) of your render-target -- if the view is translated by (140 | |
| | | , 25). | |
| | | /// | |
| | | /// This version uses a custom view for calculations, see the other | |
| | | /// overload of the function if you want to use the current view of the | |
| | | /// render-target. | |
| | | /// | |
| | | /// \param point Point to convert | |
| | | /// \param view The view to use for converting the point | |
| | | /// | |
| | | /// \return The converted point, in target coordinates (pixels) | |
| | | /// | |
| | | /// \see mapPixelToCoords | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Vector2i mapCoordsToPixel(const Vector2f& point, const View& view) cons | |
| | | t; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Draw a drawable object to the render-target | |
| | | /// | |
| | | /// \param drawable Object to draw | |
| | | /// \param states Render states to use for drawing | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void draw(const Drawable& drawable, const RenderStates& states = Render | |
| | | States::Default); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Draw primitives defined by an array of vertices | |
| | | /// | |
| | | /// \param vertices Pointer to the vertices | |
| | | /// \param vertexCount Number of vertices in the array | |
| | | /// \param type Type of primitives to draw | |
| | | /// \param states Render states to use for drawing | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void draw(const Vertex* vertices, unsigned int vertexCount, | |
| | | PrimitiveType type, const RenderStates& states = RenderStates | |
| | | ::Default); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Return the size of the rendering region of the target | |
| | | /// | |
| | | /// \return Size in pixels | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | virtual Vector2u getSize() const = 0; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Save the current OpenGL render states and matrices | |
| | | /// | |
| | | /// This function can be used when you mix SFML drawing | |
| | | /// and direct OpenGL rendering. Combined with PopGLStates, | |
| | | /// it ensures that: | |
| | | /// \li SFML's internal states are not messed up by your OpenGL code | |
| | | /// \li your OpenGL states are not modified by a call to a SFML functio | |
| | | n | |
| | | /// | |
| | | /// More specifically, it must be used around code that | |
| | | /// calls Draw functions. Example: | |
| | | /// \code | |
| | | /// // OpenGL code here... | |
| | | /// window.pushGLStates(); | |
| | | /// window.draw(...); | |
| | | /// window.draw(...); | |
| | | /// window.popGLStates(); | |
| | | /// // OpenGL code here... | |
| | | /// \endcode | |
| | | /// | |
| | | /// Note that this function is quite expensive: it saves all the | |
| | | /// possible OpenGL states and matrices, even the ones you | |
| | | /// don't care about. Therefore it should be used wisely. | |
| | | /// It is provided for convenience, but the best results will | |
| | | /// be achieved if you handle OpenGL states yourself (because | |
| | | /// you know which states have really changed, and need to be | |
| | | /// saved and restored). Take a look at the ResetGLStates | |
| | | /// function if you do so. | |
| | | /// | |
| | | /// \see popGLStates | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void pushGLStates(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Restore the previously saved OpenGL render states and matric | |
| | | es | |
| | | /// | |
| | | /// See the description of pushGLStates to get a detailed | |
| | | /// description of these functions. | |
| | | /// | |
| | | /// \see pushGLStates | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void popGLStates(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Reset the internal OpenGL states so that the target is ready | |
| | | for drawing | |
| | | /// | |
| | | /// This function can be used when you mix SFML drawing | |
| | | /// and direct OpenGL rendering, if you choose not to use | |
| | | /// pushGLStates/popGLStates. It makes sure that all OpenGL | |
| | | /// states needed by SFML are set, so that subsequent draw() | |
| | | /// calls will work as expected. | |
| | | /// | |
| | | /// Example: | |
| | | /// \code | |
| | | /// // OpenGL code here... | |
| | | /// glPushAttrib(...); | |
| | | /// window.resetGLStates(); | |
| | | /// window.draw(...); | |
| | | /// window.draw(...); | |
| | | /// glPopAttrib(...); | |
| | | /// // OpenGL code here... | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void resetGLStates(); | |
| | | | |
| protected : | | protected : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| RenderTarget(); | | RenderTarget(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Called by the derived class when it's ready to be initialized | | /// \brief Performs the common initialization step after creation | |
| | | /// | |
| | | /// The derived classes must call this function after the | |
| | | /// target is created and ready for drawing. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void initialize(); | |
| | | | |
| | | private: | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Apply the current view | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Initialize(); | | void applyCurrentView(); | |
| | | | |
|
| private : | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Apply a new blending mode | |
| | | /// | |
| | | /// \param mode Blending mode to apply | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void applyBlendMode(BlendMode mode); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Apply a new transform | |
| | | /// | |
| | | /// \param transform Transform to apply | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void applyTransform(const Transform& transform); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Apply a new texture | |
| | | /// | |
| | | /// \param texture Texture to apply | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void applyTexture(const Texture* texture); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Apply a new shader | |
| | | /// | |
| | | /// \param shader Shader to apply | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void applyShader(const Shader* shader); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Activate the target for rendering | | /// \brief Activate the target for rendering | |
| | | /// | |
| | | /// This function must be implemented by derived classes to make | |
| | | /// their OpenGL context current; it is called by the base class | |
| | | /// everytime it's going to use OpenGL calls. | |
| /// | | /// | |
|
| /// \param Active : True to activate rendering, false to deactivate | | /// \param active True to make the target active, false to deactivate i
t | |
| /// | | /// | |
|
| /// \return True if activation succeeded | | /// \return True if the function succeeded | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool Activate(bool Active) = 0; | | virtual bool activate(bool active) = 0; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the OpenGL render states needed for the SFML rendering | | /// \brief Render states cache | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetRenderStates(); | | struct StatesCache | |
| | | { | |
| | | enum {VertexCacheSize = 4}; | |
| | | | |
| | | bool glStatesSet; ///< Are our internal GL states set yet? | |
| | | bool viewChanged; ///< Has the current view changed since l | |
| | | ast draw? | |
| | | BlendMode lastBlendMode; ///< Cached blending mode | |
| | | Uint64 lastTextureId; ///< Cached texture | |
| | | bool useVertexCache; ///< Did we previously use the vertex cac | |
| | | he? | |
| | | Vertex vertexCache[VertexCacheSize]; ///< Pre-transformed vertic | |
| | | es cache | |
| | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| View myDefaultView; ///< Default view | | View m_defaultView; ///< Default view | |
| const View* myCurrentView; ///< Current active view | | View m_view; ///< Current view | |
| bool myPreserveStates; ///< Should we preserve external OpenGL s | | StatesCache m_cache; ///< Render states cache | |
| tates ? | | | |
| bool myIsDrawing; ///< True when Draw is called from inside | | | |
| , to allow some renderstates optimizations | | | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_RENDERTARGET_HPP | | #endif // SFML_RENDERTARGET_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::RenderTarget | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::RenderTarget defines the common behaviour of all the | |
| | | /// 2D render targets usable in the graphics module. It makes | |
| | | /// it possible to draw 2D entities like sprites, shapes, text | |
| | | /// without using any OpenGL command directly. | |
| | | /// | |
| | | /// A sf::RenderTarget is also able to use views (sf::View), | |
| | | /// which are a kind of 2D cameras. With views you can globally | |
| | | /// scroll, rotate or zoom everything that is drawn, | |
| | | /// without having to transform every single entity. See the | |
| | | /// documentation of sf::View for more details and sample pieces of | |
| | | /// code about this class. | |
| | | /// | |
| | | /// On top of that, render targets are still able to render direct | |
| | | /// OpenGL stuff. It is even possible to mix together OpenGL calls | |
| | | /// and regular SFML drawing commands. When doing so, make sure that | |
| | | /// OpenGL states are not messed up by calling the | |
| | | /// pushGLStates/popGLStates functions. | |
| | | /// | |
| | | /// \see sf::RenderWindow, sf::RenderTexture, sf::View | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 43 change blocks. |
| 51 lines changed or deleted | | 319 lines changed or added | |
|
| RenderWindow.hpp | | RenderWindow.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_RENDERWINDOW_HPP | | #ifndef SFML_RENDERWINDOW_HPP | |
| #define SFML_RENDERWINDOW_HPP | | #define SFML_RENDERWINDOW_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Graphics/Image.hpp> | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/Graphics/RenderTarget.hpp> | | #include <SFML/Graphics/RenderTarget.hpp> | |
|
| | | #include <SFML/Graphics/Image.hpp> | |
| #include <SFML/Window/Window.hpp> | | #include <SFML/Window/Window.hpp> | |
| #include <string> | | #include <string> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| class Drawable; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Simple wrapper for sf::Window that allows easy | | /// \brief Window that can serve as a target for 2D drawing | |
| /// 2D rendering | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API RenderWindow : public Window, public RenderTarget | | class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// This constructor doesn't actually create the window, | |
| | | /// use the other constructors or call "create" to do so. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| RenderWindow(); | | RenderWindow(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the window | | /// \brief Construct a new window | |
| | | /// | |
| | | /// This constructor creates the window with the size and pixel | |
| | | /// depth defined in \a mode. An optional style can be passed to | |
| | | /// customize the look and behaviour of the window (borders, | |
| | | /// title bar, resizable, closable, ...). | |
| /// | | /// | |
|
| /// \param Mode : Video mode to use | | /// The fourth parameter is an optional structure specifying | |
| /// \param Title : Title of the window | | /// advanced OpenGL context settings such as antialiasing, | |
| /// \param WindowStyle : Window style, see sf::Style (Resize | Close by | | /// depth-buffer bits, etc. You shouldn't care about these | |
| default) | | /// parameters for a regular usage of the graphics module. | |
| /// \param Params : Creation parameters (see default constructor f | | /// | |
| or default values) | | /// \param mode Video mode to use (defines the width, height and de | |
| | | pth of the rendering area of the window) | |
| | | /// \param title Title of the window | |
| | | /// \param style Window style | |
| | | /// \param settings Additional settings for the underlying OpenGL conte | |
| | | xt | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| RenderWindow(VideoMode Mode, const std::string& Title, unsigned long Wi
ndowStyle = Style::Resize | Style::Close, const WindowSettings& Params = Wi
ndowSettings()); | | RenderWindow(VideoMode mode, const String& title, Uint32 style = Style:
:Default, const ContextSettings& settings = ContextSettings()); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the window from an existing control | | /// \brief Construct the window from an existing control | |
| | | /// | |
| | | /// Use this constructor if you want to create an SFML | |
| | | /// rendering area into an already existing control. | |
| | | /// | |
| | | /// The fourth parameter is an optional structure specifying | |
| | | /// advanced OpenGL context settings such as antialiasing, | |
| | | /// depth-buffer bits, etc. You shouldn't care about these | |
| | | /// parameters for a regular usage of the graphics module. | |
| /// | | /// | |
|
| /// \param Handle : Platform-specific handle of the control | | /// \param handle Platform-specific handle of the control | |
| /// \param Params : Creation parameters (see default constructor for de | | /// \param settings Additional settings for the underlying OpenGL conte | |
| fault values) | | xt | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| RenderWindow(WindowHandle Handle, const WindowSettings& Params = Window
Settings()); | | explicit RenderWindow(WindowHandle handle, const ContextSettings& setti
ngs = ContextSettings()); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor | | /// \brief Destructor | |
| | | /// | |
| | | /// Closes the window and free all the resources attached to it. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| virtual ~RenderWindow(); | | virtual ~RenderWindow(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the width of the rendering region of the window | | /// \brief Get the size of the rendering region of the window | |
| | | /// | |
| | | /// The size doesn't include the titlebar and borders | |
| | | /// of the window. | |
| /// | | /// | |
|
| /// \return Width in pixels | | /// \return Size in pixels | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual unsigned int GetWidth() const; | | virtual Vector2u getSize() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the height of the rendering region of the window | | /// \brief Copy the current contents of the window to an image | |
| /// | | /// | |
|
| /// \return Height in pixels | | /// This is a slow operation, whose main purpose is to make | |
| | | /// screenshots of the application. If you want to update an | |
| | | /// image with the contents of the window and then use it for | |
| | | /// drawing, you should rather use a sf::Texture and its | |
| | | /// update(Window&) function. | |
| | | /// You can also draw things directly to a texture with the | |
| | | /// sf::RenderTexture class. | |
| | | /// | |
| | | /// \return Image containing the captured contents | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual unsigned int GetHeight() const; | | Image capture() const; | |
| | | | |
| | | protected: | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Save the content of the window to an image | | /// \brief Function called after the window has been created | |
| /// | | /// | |
|
| /// \return Image instance containing the contents of the screen | | /// This function is called so that derived classes can | |
| | | /// perform their own specific initialization as soon as | |
| | | /// the window is created. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Image Capture() const; | | virtual void onCreate(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Convert a point in window coordinates into view coordinates | | /// \brief Function called after the window has been resized | |
| /// | | | |
| /// \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 de | | | |
| fault -- uses the current view) | | | |
| /// | | /// | |
|
| /// \return Converted point | | /// This function is called so that derived classes can | |
| | | /// perform custom actions when the size of the window changes. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| sf::Vector2f ConvertCoords(unsigned int WindowX, unsigned int WindowY,
const View* TargetView = NULL) const; | | virtual void onResize(); | |
| | | | |
| private : | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see Window::OnCreate | | /// \brief Activate the target for rendering | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param active True to make the target active, false to deactivate i | |
| virtual void OnCreate(); | | t | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | /// \return True if the function succeeded | |
| /// /see RenderTarget::Activate | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool Activate(bool Active); | | virtual bool activate(bool active); | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_RENDERWINDOW_HPP | | #endif // SFML_RENDERWINDOW_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::RenderWindow | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::RenderWindow is the main class of the Graphics module. | |
| | | /// It defines an OS window that can be painted using the other | |
| | | /// classes of the graphics module. | |
| | | /// | |
| | | /// sf::RenderWindow is derived from sf::Window, thus it inherits | |
| | | /// all its features: events, window management, OpenGL rendering, | |
| | | /// etc. See the documentation of sf::Window for a more complete | |
| | | /// description of all these features, as well as code examples. | |
| | | /// | |
| | | /// On top of that, sf::RenderWindow adds more features related to | |
| | | /// 2D drawing with the graphics module (see its base class | |
| | | /// sf::RenderTarget for more details). | |
| | | /// Here is a typical rendering and event loop with a sf::RenderWindow: | |
| | | /// | |
| | | /// \code | |
| | | /// // Declare and create a new render-window | |
| | | /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML window"); | |
| | | /// | |
| | | /// // Limit the framerate to 60 frames per second (this step is optional) | |
| | | /// window.setFramerateLimit(60); | |
| | | /// | |
| | | /// // The main loop - ends as soon as the window is closed | |
| | | /// while (window.isOpen()) | |
| | | /// { | |
| | | /// // Event processing | |
| | | /// sf::Event event; | |
| | | /// while (window.pollEvent(event)) | |
| | | /// { | |
| | | /// // Request for closing the window | |
| | | /// if (event.type == sf::Event::Closed) | |
| | | /// window.close(); | |
| | | /// } | |
| | | /// | |
| | | /// // Clear the whole window before rendering a new frame | |
| | | /// window.clear(); | |
| | | /// | |
| | | /// // Draw some graphical entities | |
| | | /// window.draw(sprite); | |
| | | /// window.draw(circle); | |
| | | /// window.draw(text); | |
| | | /// | |
| | | /// // End the current frame and display its contents on screen | |
| | | /// window.display(); | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | /// Like sf::Window, sf::RenderWindow is still able to render direct | |
| | | /// OpenGL stuff. It is even possible to mix together OpenGL calls | |
| | | /// and regular SFML drawing commands. | |
| | | /// | |
| | | /// \code | |
| | | /// // Create the render window | |
| | | /// sf::RenderWindow window(sf::VideoMode(800, 600), "SFML OpenGL"); | |
| | | /// | |
| | | /// // Create a sprite and a text to display | |
| | | /// sf::Sprite sprite; | |
| | | /// sf::Text text; | |
| | | /// ... | |
| | | /// | |
| | | /// // Perform OpenGL initializations | |
| | | /// glMatrixMode(GL_PROJECTION); | |
| | | /// ... | |
| | | /// | |
| | | /// // Start the rendering loop | |
| | | /// while (window.isOpen()) | |
| | | /// { | |
| | | /// // Process events | |
| | | /// ... | |
| | | /// | |
| | | /// // Draw a background sprite | |
| | | /// window.pushGLStates(); | |
| | | /// window.draw(sprite); | |
| | | /// window.popGLStates(); | |
| | | /// | |
| | | /// // Draw a 3D object using OpenGL | |
| | | /// glBegin(GL_QUADS); | |
| | | /// glVertex3f(...); | |
| | | /// ... | |
| | | /// glEnd(); | |
| | | /// | |
| | | /// // Draw text on top of the 3D object | |
| | | /// window.pushGLStates(); | |
| | | /// window.draw(text); | |
| | | /// window.popGLStates(); | |
| | | /// | |
| | | /// // Finally, display the rendered frame on screen | |
| | | /// window.display(); | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::Window, sf::RenderTarget, sf::RenderTexture, sf::View | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 30 change blocks. |
| 48 lines changed or deleted | | 78 lines changed or added | |
|
| Shape.hpp | | Shape.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_SHAPE_HPP | | #ifndef SFML_SHAPE_HPP | |
| #define SFML_SHAPE_HPP | | #define SFML_SHAPE_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/Graphics/Drawable.hpp> | | #include <SFML/Graphics/Drawable.hpp> | |
|
| | | #include <SFML/Graphics/Transformable.hpp> | |
| | | #include <SFML/Graphics/VertexArray.hpp> | |
| #include <SFML/System/Vector2.hpp> | | #include <SFML/System/Vector2.hpp> | |
|
| #include <vector> | | | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Shape defines a drawable convex shape ; it also defines | | /// \brief Base class for textured shapes with outline | |
| /// helper functions to draw simple shapes like | | /// | |
| /// lines, rectangles, circles, etc. | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Shape : public sf::Drawable | | class SFML_GRAPHICS_API Shape : public Drawable, public Transformable | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Virtual destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Shape(); | | virtual ~Shape(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Add a point to the shape | | /// \brief Change the source texture of the shape | |
| /// | | /// | |
|
| /// \param X, Y : Position of the point | | /// The \a texture argument refers to a texture that must | |
| /// \param Col : Color of the point (white by default) | | /// exist as long as the shape uses it. Indeed, the shape | |
| /// \param OutlineCol : Outline color of the point (black by default) | | /// doesn't store its own copy of the texture, but rather keeps | |
| | | /// a pointer to the one that you passed to this function. | |
| | | /// If the source texture is destroyed and the shape tries to | |
| | | /// use it, the behaviour is undefined. | |
| | | /// \a texture can be NULL to disable texturing. | |
| | | /// If \a resetRect is true, the TextureRect property of | |
| | | /// the shape is automatically adjusted to the size of the new | |
| | | /// texture. If it is false, the texture rect is left unchanged. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param texture New texture | |
| void AddPoint(float X, float Y, const Color& Col = Color(255, 255, 255) | | /// \param resetRect Should the texture rect be reset to the size of th | |
| , const Color& OutlineCol = Color(0, 0, 0)); | | e new texture? | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Add a point to the shape | | | |
| /// | | /// | |
|
| /// \param Position : Position of the point | | /// \see getTexture, setTextureRect | |
| /// \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, 2
55, 255), const Color& OutlineCol = Color(0, 0, 0)); | | void setTexture(const Texture* texture, bool resetRect = false); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the number of points composing the shape | | /// \brief Set the sub-rectangle of the texture that the shape will dis
play | |
| /// | | /// | |
|
| /// \param Total number of points | | /// The texture rect is useful when you don't want to display | |
| | | /// the whole texture, but rather a part of it. | |
| | | /// By default, the texture rect covers the entire texture. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param rect Rectangle defining the region of the texture to display | |
| unsigned int GetNbPoints() const; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Enable or disable filling the shape. | | | |
| /// Fill is enabled by default | | | |
| /// | | /// | |
|
| /// \param Enable : True to enable, false to disable | | /// \see getTextureRect, setTexture | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void EnableFill(bool Enable); | | void setTextureRect(const IntRect& rect); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enable or disable drawing the shape outline. | | /// \brief Set the fill color of the shape | |
| /// Outline is enabled by default | | | |
| /// | | /// | |
|
| /// \param Enable : True to enable, false to disable | | /// This color is modulated (multiplied) with the shape's | |
| | | /// texture if any. It can be used to colorize the shape, | |
| | | /// or change its global opacity. | |
| | | /// You can use sf::Color::Transparent to make the inside of | |
| | | /// the shape transparent, and have the outline alone. | |
| | | /// By default, the shape's fill color is opaque white. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param color New color of the shape | |
| void EnableOutline(bool Enable); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Set the position of a point | | | |
| /// | | /// | |
|
| /// \param Index : Index of the point, in range [0, GetNbPoints() - | | /// \see getFillColor, setOutlineColor | |
| 1] | | | |
| /// \param Position : New position of the Index-th point | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetPointPosition(unsigned int Index, const Vector2f& Position); | | void setFillColor(const Color& color); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the position of a point | | /// \brief Set the outline color of the shape | |
| /// | | /// | |
|
| /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] | | /// By default, the shape's outline color is opaque white. | |
| /// \param X : New X coordinate of the Index-th point | | /// | |
| /// \param Y : New Y coordinate of the Index-th point | | /// \param color New outline color of the shape | |
| | | /// | |
| | | /// \see getOutlineColor, setFillColor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetPointPosition(unsigned int Index, float X, float Y); | | void setOutlineColor(const Color& color); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the color of a point | | /// \brief Set the thickness of the shape's outline | |
| | | /// | |
| | | /// Note that negative values are allowed (so that the outline | |
| | | /// expands towards the center of the shape), and using zero | |
| | | /// disables the outline. | |
| | | /// By default, the outline thickness is 0. | |
| /// | | /// | |
|
| /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] | | /// \param thickness New outline thickness | |
| /// \param Col : New color of the Index-th point | | /// | |
| | | /// \see getOutlineThickness | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetPointColor(unsigned int Index, const Color& Col); | | void setOutlineThickness(float thickness); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the outline color of a point | | /// \brief Get the source texture of the shape | |
| | | /// | |
| | | /// If the shape has no source texture, a NULL pointer is returned. | |
| | | /// The returned pointer is const, which means that you can't | |
| | | /// modify the texture when you retrieve it with this function. | |
| /// | | /// | |
|
| /// \param Index : Index of the point, in range [0, GetNbPoints() | | /// \return Pointer to the shape's texture | |
| - 1] | | /// | |
| /// \param OutlineCol : New outline color of the Index-th point | | /// \see setTexture | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetPointOutlineColor(unsigned int Index, const Color& OutlineCol); | | const Texture* getTexture() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the width of the shape outline | | /// \brief Get the sub-rectangle of the texture displayed by the shape | |
| | | /// | |
| | | /// \return Texture rectangle of the shape | |
| /// | | /// | |
|
| /// \param Width : New width | | /// \see setTextureRect | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetOutlineWidth(float Width); | | const IntRect& getTextureRect() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the position of a point | | /// \brief Get the fill color of the shape | |
| /// | | /// | |
|
| /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] | | /// \return Fill color of the shape | |
| /// | | /// | |
|
| /// \return Position of the Index-th point | | /// \see setFillColor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Vector2f& GetPointPosition(unsigned int Index) const; | | const Color& getFillColor() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the color of a point | | /// \brief Get the outline color of the shape | |
| /// | | /// | |
|
| /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] | | /// \return Outline color of the shape | |
| /// | | /// | |
|
| /// \return Color of the Index-th point | | /// \see setOutlineColor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Color& GetPointColor(unsigned int Index) const; | | const Color& getOutlineColor() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the outline color of a point | | /// \brief Get the outline thickness of the shape | |
| /// | | /// | |
|
| /// \param Index : Index of the point, in range [0, GetNbPoints() - 1] | | /// \return Outline thickness of the shape | |
| /// | | /// | |
|
| /// \return Outline color of the Index-th point | | /// \see setOutlineThickness | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Color& GetPointOutlineColor(unsigned int Index) const; | | float getOutlineThickness() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the width of the shape outline | | /// \brief Get the total number of points of the shape | |
| | | /// | |
| | | /// \return Number of points of the shape | |
| /// | | /// | |
|
| /// \return Current outline width | | /// \see getPoint | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| float GetOutlineWidth() const; | | virtual unsigned int getPointCount() const = 0; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create a shape made of a single line (use floats) | | /// \brief Get a point of the shape | |
| | | /// | |
| | | /// The result is undefined if \a index is out of the valid range. | |
| | | /// | |
| | | /// \param index Index of the point to get, in range [0 .. getPointCoun | |
| | | t() - 1] | |
| /// | | /// | |
|
| /// \param P1X, P1Y : Position of the first point | | /// \return Index-th point of the shape | |
| /// \param P2X, P2Y : Position second point | | /// | |
| /// \param Thickness : Line thickness | | /// \see getPointCount | |
| /// \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 defaul | | | |
| t) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Shape Line(float P1X, float P1Y, float P2X, float P2Y, float Thi
ckness, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf
::Color(0, 0, 0)); | | virtual Vector2f getPoint(unsigned int index) const = 0; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create a shape made of a single line (use vectors) | | /// \brief Get the local bounding rectangle of the entity | |
| | | /// | |
| | | /// The returned rectangle is in local coordinates, which means | |
| | | /// that it ignores the transformations (translation, rotation, | |
| | | /// scale, ...) that are applied to the entity. | |
| | | /// In other words, this function returns the bounds of the | |
| | | /// entity in the entity's coordinate system. | |
| /// | | /// | |
|
| /// \param P1X, P1Y : Position of the first point | | /// \return Local bounding rectangle of the entity | |
| /// \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 defaul | | | |
| t) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Shape Line(const Vector2f& P1, const Vector2f& P2, float Thickne
ss, const Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Co
lor(0, 0, 0)); | | FloatRect getLocalBounds() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create a shape made of a single rectangle (use floats) | | /// \brief Get the global bounding rectangle of the entity | |
| | | /// | |
| | | /// The returned rectangle is in global coordinates, which means | |
| | | /// that it takes in account the transformations (translation, | |
| | | /// rotation, scale, ...) that are applied to the entity. | |
| | | /// In other words, this function returns the bounds of the | |
| | | /// sprite in the global 2D world's coordinate system. | |
| /// | | /// | |
|
| /// \param P1X, P1Y : Position of the first point | | /// \return Global bounding rectangle of the entity | |
| /// \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 defaul | | | |
| t) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Shape Rectangle(float P1X, float P1Y, float P2X, float P2Y, cons | | FloatRect getGlobalBounds() const; | |
| t Color& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0 | | | |
| , 0)); | | protected : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create a shape made of a single rectangle (use vectors) | | /// \brief Default constructor | |
| /// | | | |
| /// \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 defaul | | | |
| t) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Shape Rectangle(const Vector2f& P1, const Vector2f& P2, const Co
lor& Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0)
); | | Shape(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create a shape made of a single circle (use floats) | | /// \brief Recompute the internal geometry of the shape | |
| /// | | /// | |
|
| /// \param X, Y : Position of the center | | /// This function must be called by the derived class everytime | |
| /// \param Radius : Radius | | /// the shape's points change (ie. the result of either | |
| /// \param Col : Color used to fill the circle | | /// getPointCount or getPoint is different). | |
| /// \param Outline : Outline width (0 by default) | | | |
| /// \param OutlineCol : Color used to draw the outline (black by defaul | | | |
| t) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Shape Circle(float X, float Y, float Radius, const Color& Col, f | | void update(); | |
| loat Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0)); | | | |
| | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Create a shape made of a single circle (use vectors) | | /// \brief Draw the shape to a render target | |
| /// | | /// | |
|
| /// \param Center : Position of the center | | /// \param target Render target to draw to | |
| /// \param Radius : Radius | | /// \param states Current render states | |
| /// \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 defaul | | | |
| t) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static Shape Circle(const Vector2f& Center, float Radius, const Color& | | virtual void draw(RenderTarget& target, RenderStates states) const; | |
| Col, float Outline = 0.f, const Color& OutlineCol = sf::Color(0, 0, 0)); | | | |
| | | | |
| protected : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see Drawable::Render | | /// \brief Update the fill vertices' color | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void Render(RenderTarget& Target) const; | | void updateFillColors(); | |
| | | | |
| private : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Compile the shape : compute its center and its outline | | /// \brief Update the fill vertices' texture coordinates | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Compile(); | | void updateTexCoords(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Compute the normal of a given 2D segment | | /// \brief Update the outline vertices' position | |
| /// | | | |
| /// \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, Vecto
r2f& Normal); | | void updateOutline(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Defines a simple 2D point | | /// \brief Update the outline vertices' color | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| struct Point | | void updateOutlineColors(); | |
| { | | | |
| Point(const Vector2f& Pos = Vector2f(0, 0), const Color& C = Color( | | | |
| 255, 255, 255), const Color& OutlineC = Color(255, 255, 255)); | | | |
| | | | |
|
| Vector2f Position; ///< Position | | private : | |
| Vector2f Normal; ///< Extruded normal | | | |
| Color Col; ///< Color of the point | | | |
| Color OutlineCol; ///< Outline color of the point | | | |
| }; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::vector<Point> myPoints; ///< Points composing the shape | | const Texture* m_texture; ///< Texture of the shape | |
| float myOutline; ///< Outline width | | IntRect m_textureRect; ///< Rectangle defining the area of | |
| bool myIsFillEnabled; ///< Should we draw the inside i | | the source texture to display | |
| f the shape ? | | Color m_fillColor; ///< Fill color | |
| bool myIsOutlineEnabled; ///< Should we draw the outline | | Color m_outlineColor; ///< Outline color | |
| if the shape ? | | float m_outlineThickness; ///< Thickness of the shape's outlin | |
| bool myIsCompiled; ///< Compiled state of the shape | | e | |
| | | VertexArray m_vertices; ///< Vertex array containing the fil | |
| | | l geometry | |
| | | VertexArray m_outlineVertices; ///< Vertex array containing the out | |
| | | line geometry | |
| | | FloatRect m_insideBounds; ///< Bounding rectangle of the insid | |
| | | e (fill) | |
| | | FloatRect m_bounds; ///< Bounding rectangle of the whole | |
| | | shape (outline + fill) | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_SHAPE_HPP | | #endif // SFML_SHAPE_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Shape | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::Shape is a drawable class that allows to define and | |
| | | /// display a custom convex shape on a render target. | |
| | | /// It's only an abstract base, it needs to be specialized for | |
| | | /// concrete types of shapes (circle, rectangle, convex polygon, | |
| | | /// star, ...). | |
| | | /// | |
| | | /// In addition to the attributes provided by the specialized | |
| | | /// shape classes, a shape always has the following attributes: | |
| | | /// \li a texture | |
| | | /// \li a texture rectangle | |
| | | /// \li a fill color | |
| | | /// \li an outline color | |
| | | /// \li an outline thickness | |
| | | /// | |
| | | /// Each feature is optional, and can be disabled easily: | |
| | | /// \li the texture can be null | |
| | | /// \li the fill/outline colors can be sf::Color::Transparent | |
| | | /// \li the outline thickness can be zero | |
| | | /// | |
| | | /// You can write your own derived shape class, there are only | |
| | | /// two virtual functions to override: | |
| | | /// \li getPointCount must return the number of points of the shape | |
| | | /// \li getPoint must return the points of the shape | |
| | | /// | |
| | | /// \see sf::RectangleShape, sf::CircleShape, sf::ConvexShape, sf::Transfor | |
| | | mable | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 78 change blocks. |
| 165 lines changed or deleted | | 158 lines changed or added | |
|
| Sound.hpp | | Sound.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_SOUND_HPP | | #ifndef SFML_SOUND_HPP | |
| #define SFML_SOUND_HPP | | #define SFML_SOUND_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/System/Resource.hpp> | | #include <SFML/Audio/Export.hpp> | |
| #include <SFML/System/Vector3.hpp> | | #include <SFML/Audio/SoundSource.hpp> | |
| #include <SFML/Audio/AudioResource.hpp> | | #include <SFML/System/Time.hpp> | |
| #include <cstdlib> | | #include <cstdlib> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| class SoundBuffer; | | class SoundBuffer; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Sound defines the properties of a sound such as position, | | /// \brief Regular sound that can be played in the audio environment | |
| /// volume, pitch, etc. | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Sound : public AudioResource | | class SFML_AUDIO_API Sound : public SoundSource | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumeration of the sound states | | /// \brief Default constructor | |
| //////////////////////////////////////////////////////////// | | | |
| enum Status | | | |
| { | | | |
| Stopped, ///< Sound is not playing | | | |
| Paused, ///< Sound is paused | | | |
| Playing ///< Sound is playing | | | |
| }; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Default constructor | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Sound(); | | Sound(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the sound from its parameters | | /// \brief Construct the sound with a buffer | |
| /// | | /// | |
|
| /// \param Buffer : Sound buffer to play (NULL by default) | | /// \param buffer Sound buffer containing the audio data to play with t | |
| /// \param Loop : Loop flag (false by default) | | he sound | |
| /// \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 Pitc
h = 1.f, float Volume = 100.f, const Vector3f& Position = Vector3f(0, 0, 0)
); | | explicit Sound(const SoundBuffer& buffer); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Copy constructor | | /// \brief Copy constructor | |
| /// | | /// | |
|
| /// \param Copy : Instance to copy | | /// \param copy Instance to copy | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Sound(const Sound& Copy); | | Sound(const Sound& copy); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor | | /// \brief Destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| ~Sound(); | | ~Sound(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Play the sound | | /// \brief Start or resume playing the sound | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// This function starts the stream if it was stopped, resumes | |
| void Play(); | | /// it if it was paused, and restarts it from beginning if it | |
| | | /// was it already playing. | |
| //////////////////////////////////////////////////////////// | | /// This function uses its own thread so that it doesn't block | |
| /// Pause the sound | | /// the rest of the program while the sound is played. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \see pause, stop | |
| void Pause(); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Stop the sound | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Stop(); | | void play(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the source buffer | | /// \brief Pause the sound | |
| /// | | /// | |
|
| /// \param Buffer : New sound buffer to bind to the sound | | /// This function pauses the sound if it was playing, | |
| | | /// otherwise (sound already paused or stopped) it has no effect. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \see play, stop | |
| 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); | | void pause(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the sound pitch. | | /// \brief stop playing the sound | |
| /// The default pitch is 1 | | | |
| /// | | /// | |
|
| /// \param Pitch : New pitch | | /// This function stops the sound if it was playing or paused, | |
| | | /// and does nothing if it was already stopped. | |
| | | /// It also resets the playing position (unlike pause()). | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \see play, pause | |
| void SetPitch(float Pitch); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Set the sound volume. | | | |
| /// The default volume is 100 | | | |
| /// | | | |
| /// \param Volume : Volume (in range [0, 100]) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetVolume(float Volume); | | void stop(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the sound position (take 3 values). | | /// \brief Set the source buffer containing the audio data to play | |
| /// The default position is (0, 0, 0) | | | |
| /// | | /// | |
|
| /// \param X, Y, Z : Position of the sound in the world | | /// It is important to note that the sound buffer is not copied, | |
| | | /// thus the sf::SoundBuffer instance must remain alive as long | |
| | | /// as it is attached to the sound. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param buffer Sound buffer to attach to the sound | |
| 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 | | /// \see getBuffer | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetPosition(const Vector3f& Position); | | void setBuffer(const SoundBuffer& buffer); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Make the sound's position relative to the listener's | | /// \brief Set whether or not the sound should loop after reaching the | |
| /// position, or absolute. | | end | |
| /// The default value is false (absolute) | | | |
| /// | | /// | |
|
| /// \param Relative : True to set the position relative, false to set i | | /// If set, the sound will restart from beginning after | |
| t absolute | | /// reaching the end and so on, until it is stopped or | |
| | | /// setLoop(false) is called. | |
| | | /// The default looping state for sound is false. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param loop True to play in loop, false to play once | |
| 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 | | /// \see getLoop | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetMinDistance(float MinDistance); | | void setLoop(bool loop); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the attenuation factor - the higher the attenuation, the | | /// \brief Change the current playing position of the sound | |
| /// more the sound will be attenuated with distance from listener. | | | |
| /// The default attenuation factor 1.0 | | | |
| /// | | /// | |
|
| /// \param Attenuation : New attenuation factor for the sound | | /// The playing position can be changed when the sound is | |
| | | /// either paused or playing. | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \param timeOffset New playing position, from the beginning of the s | |
| void SetAttenuation(float Attenuation); | | ound | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Set the current playing position of the sound | | | |
| /// | | /// | |
|
| /// \param TimeOffset : New playing position, expressed in seconds | | /// \see getPlayingOffset | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetPlayingOffset(float TimeOffset); | | void setPlayingOffset(Time timeOffset); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the source buffer | | /// \brief Get the audio buffer attached to the sound | |
| /// | | /// | |
|
| /// \return Sound buffer bound to the sound (can be NULL) | | /// \return Sound buffer attached to the sound (can be NULL) | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const SoundBuffer* GetBuffer() const; | | const SoundBuffer* getBuffer() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Tell whether or not the sound is looping | | /// \brief Tell whether or not the sound is in loop mode | |
| /// | | /// | |
| /// \return True if the sound is looping, false otherwise | | /// \return True if the sound is looping, false otherwise | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \see setLoop | |
| 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; | | bool getLoop() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the sound position | | /// \brief Get the current playing position of the sound | |
| /// | | /// | |
|
| /// \return Position of the sound in the world | | /// \return Current playing position, from the beginning of the sound | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| 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 | | /// \see setPlayingOffset | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| float GetMinDistance() const; | | Time getPlayingOffset() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the attenuation factor | | /// \brief Get the current status of the sound (stopped, paused, playin | |
| /// | | g) | |
| /// \return Attenuation factor of the sound | | | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| float GetAttenuation() const; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Get the status of the sound (stopped, paused, playing) | | | |
| /// | | /// | |
| /// \return Current status of the sound | | /// \return Current status of the sound | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Status GetStatus() const; | | Status getStatus() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Get the current playing position of the sound | | | |
| /// | | | |
| /// \return Current playing position, expressed in seconds | | | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| float GetPlayingOffset() const; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Assignment operator | | /// \brief Overload of assignment operator | |
| /// | | /// | |
|
| /// \param Other : Instance to assign | | /// \param right Instance to assign | |
| /// | | /// | |
|
| /// \return Reference to the sound | | /// \return Reference to self | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Sound& operator =(const Sound& Other); | | Sound& operator =(const Sound& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Reset the internal buffer | | /// \brief Reset the internal buffer of the sound | |
| /// | | /// | |
| /// This function is for internal use only, you don't have | | /// This function is for internal use only, you don't have | |
|
| /// to use it. | | /// to use it. It is called by the sf::SoundBuffer that | |
| | | /// this sound uses, when it is destroyed in order to prevent | |
| | | /// the sound from using a dead buffer. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void ResetBuffer(); | | void resetBuffer(); | |
| | | | |
| private : | | private : | |
| | | | |
|
| friend class SoundStream; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int mySource; ///< OpenAL source identifier | | const SoundBuffer* m_buffer; ///< Sound buffer bound to the source | |
| ResourcePtr<SoundBuffer> myBuffer; ///< Sound buffer bound to the sourc | | | |
| e | | | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_SOUND_HPP | | #endif // SFML_SOUND_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Sound | |
| | | /// \ingroup audio | |
| | | /// | |
| | | /// sf::Sound is the class to use to play sounds. | |
| | | /// It provides: | |
| | | /// \li Control (play, pause, stop) | |
| | | /// \li Ability to modify output parameters in real-time (pitch, volume, .. | |
| | | .) | |
| | | /// \li 3D spatial features (position, attenuation, ...). | |
| | | /// | |
| | | /// sf::Sound is perfect for playing short sounds that can | |
| | | /// fit in memory and require no latency, like foot steps or | |
| | | /// gun shots. For longer sounds, like background musics | |
| | | /// or long speeches, rather see sf::Music (which is based | |
| | | /// on streaming). | |
| | | /// | |
| | | /// In order to work, a sound must be given a buffer of audio | |
| | | /// data to play. Audio data (samples) is stored in sf::SoundBuffer, | |
| | | /// and attached to a sound with the setBuffer() function. | |
| | | /// The buffer object attached to a sound must remain alive | |
| | | /// as long as the sound uses it. Note that multiple sounds | |
| | | /// can use the same sound buffer at the same time. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// sf::SoundBuffer buffer; | |
| | | /// buffer.loadFromFile("sound.wav"); | |
| | | /// | |
| | | /// sf::Sound sound; | |
| | | /// sound.setBuffer(buffer); | |
| | | /// sound.play(); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::SoundBuffer, sf::Music | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 61 change blocks. |
| 169 lines changed or deleted | | 81 lines changed or added | |
|
| SoundBuffer.hpp | | SoundBuffer.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_SOUNDBUFFER_HPP | | #ifndef SFML_SOUNDBUFFER_HPP | |
| #define SFML_SOUNDBUFFER_HPP | | #define SFML_SOUNDBUFFER_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/System/Resource.hpp> | | #include <SFML/Audio/Export.hpp> | |
| #include <SFML/Audio/AudioResource.hpp> | | #include <SFML/System/Time.hpp> | |
| #include <string> | | #include <string> | |
| #include <vector> | | #include <vector> | |
| #include <set> | | #include <set> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| | | namespace priv | |
| | | { | |
| | | class SoundFile; | |
| | | } | |
| | | | |
| class Sound; | | class Sound; | |
|
| | | class InputStream; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// SoundBuffer is the low-level for loading and manipulating | | /// \brief Storage for audio samples defining a sound | |
| /// sound buffers | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API SoundBuffer : public AudioResource, public Resource<SoundBuf
fer> | | class SFML_AUDIO_API SoundBuffer | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| SoundBuffer(); | | SoundBuffer(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Copy constructor | | /// \brief Copy constructor | |
| /// | | /// | |
|
| /// \param Copy : Instance to copy | | /// \param copy Instance to copy | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| SoundBuffer(const SoundBuffer& Copy); | | SoundBuffer(const SoundBuffer& copy); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Destructor | | /// \brief Destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| ~SoundBuffer(); | | ~SoundBuffer(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Load the sound buffer from a file | | /// \brief Load the sound buffer from a file | |
| | | /// | |
| | | /// Here is a complete list of all the supported audio formats: | |
| | | /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, | |
| | | /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. | |
| | | /// | |
| | | /// \param filename Path of the sound file to load | |
| | | /// | |
| | | /// \return True if loading succeeded, false if it failed | |
| | | /// | |
| | | /// \see loadFromMemory, loadFromStream, loadFromSamples, saveToFile | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | bool loadFromFile(const std::string& filename); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Load the sound buffer from a file in memory | |
| | | /// | |
| | | /// Here is a complete list of all the supported audio formats: | |
| | | /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, | |
| | | /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. | |
| | | /// | |
| | | /// \param data Pointer to the file data in memory | |
| | | /// \param sizeInBytes Size of the data to load, in bytes | |
| /// | | /// | |
|
| /// \param Filename : Path of the sound file to load | | /// \return True if loading succeeded, false if it failed | |
| /// | | /// | |
|
| /// \return True if loading has been successful | | /// \see loadFromFile, loadFromStream, loadFromSamples | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool LoadFromFile(const std::string& Filename); | | bool loadFromMemory(const void* data, std::size_t sizeInBytes); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Load the sound buffer from a file in memory | | /// \brief Load the sound buffer from a custom stream | |
| | | /// | |
| | | /// Here is a complete list of all the supported audio formats: | |
| | | /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, | |
| | | /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. | |
| | | /// | |
| | | /// \param stream Source stream to read from | |
| /// | | /// | |
|
| /// \param Data : Pointer to the file data in memory | | /// \return True if loading succeeded, false if it failed | |
| /// \param SizeInBytes : Size of the data to load, in bytes | | | |
| /// | | /// | |
|
| /// \return True if loading has been successful | | /// \see loadFromFile, loadFromMemory, loadFromSamples | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool LoadFromMemory(const char* Data, std::size_t SizeInBytes); | | bool loadFromStream(InputStream& stream); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Load the sound buffer from an array of samples - assumed format for | | /// \brief Load the sound buffer from an array of audio samples | |
| /// samples is 16 bits signed integer | | | |
| /// | | /// | |
|
| /// \param Samples : Pointer to the samples in memory | | /// The assumed format of the audio samples is 16 bits signed integer | |
| /// \param SamplesCount : Number of samples pointed by Samples | | /// (sf::Int16). | |
| /// \param ChannelsCount : Number of channels (1 = mono, 2 = stereo, .. | | | |
| .) | | | |
| /// \param SampleRate : Frequency (number of samples to play per sec | | | |
| ond) | | | |
| /// | | /// | |
|
| /// \return True if loading has been successful | | /// \param samples Pointer to the array of samples in memory | |
| | | /// \param sampleCount Number of samples in the array | |
| | | /// \param channelCount Number of channels (1 = mono, 2 = stereo, ...) | |
| | | /// \param sampleRate Sample rate (number of samples to play per seco | |
| | | nd) | |
| | | /// | |
| | | /// \return True if loading succeeded, false if it failed | |
| | | /// | |
| | | /// \see loadFromFile, loadFromMemory, saveToFile | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool LoadFromSamples(const Int16* Samples, std::size_t SamplesCount, un
signed int ChannelsCount, unsigned int SampleRate); | | bool loadFromSamples(const Int16* samples, std::size_t sampleCount, uns
igned int channelCount, unsigned int sampleRate); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Save the sound buffer to a file | | /// \brief Save the sound buffer to an audio file | |
| | | /// | |
| | | /// Here is a complete list of all the supported audio formats: | |
| | | /// ogg, wav, flac, aiff, au, raw, paf, svx, nist, voc, ircam, | |
| | | /// w64, mat4, mat5 pvf, htk, sds, avr, sd2, caf, wve, mpc2k, rf64. | |
| | | /// | |
| | | /// \param filename Path of the sound file to write | |
| /// | | /// | |
|
| /// \param Filename : Path of the sound file to write | | /// \return True if saving succeeded, false if it failed | |
| /// | | /// | |
|
| /// \return True if saving has been successful | | /// \see loadFromFile, loadFromMemory, loadFromSamples | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool SaveToFile(const std::string& Filename) const; | | bool saveToFile(const std::string& filename) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Return the sound samples | | /// \brief Get the array of audio samples stored in the buffer | |
| /// | | /// | |
|
| /// \return Pointer to the array of sound samples, in 16 bits signed in | | /// The format of the returned samples is 16 bits signed integer | |
| teger format | | /// (sf::Int16). The total number of samples in this array | |
| | | /// is given by the getSampleCount() function. | |
| | | /// | |
| | | /// \return Read-only pointer to the array of sound samples | |
| | | /// | |
| | | /// \see getSampleCount | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Int16* GetSamples() const; | | const Int16* getSamples() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Return the samples count | | /// \brief Get the number of samples stored in the buffer | |
| | | /// | |
| | | /// The array of samples can be accessed with the getSamples() | |
| | | /// function. | |
| /// | | /// | |
| /// \return Number of samples | | /// \return Number of samples | |
| /// | | /// | |
|
| | | /// \see getSamples | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::size_t GetSamplesCount() const; | | std::size_t getSampleCount() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the sample rate | | /// \brief Get the sample rate of the sound | |
| | | /// | |
| | | /// The sample rate is the number of samples played per second. | |
| | | /// The higher, the better the quality (for example, 44100 | |
| | | /// samples/s is CD quality). | |
| /// | | /// | |
|
| /// \return Sound frequency (number of samples per second) | | /// \return Sample rate (number of samples per second) | |
| | | /// | |
| | | /// \see getChannelCount, getDuration | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetSampleRate() const; | | unsigned int getSampleRate() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Return the number of channels (1 = mono, 2 = stereo, ...) | | /// \brief Get the number of channels used by the sound | |
| | | /// | |
| | | /// If the sound is mono then the number of channels will | |
| | | /// be 1, 2 for stereo, etc. | |
| /// | | /// | |
| /// \return Number of channels | | /// \return Number of channels | |
| /// | | /// | |
|
| | | /// \see getSampleRate, getDuration | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetChannelsCount() const; | | unsigned int getChannelCount() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the sound duration | | /// \brief Get the total duration of the sound | |
| | | /// | |
| | | /// \return Sound duration | |
| /// | | /// | |
|
| /// \return Sound duration, in seconds | | /// \see getSampleRate, getChannelCount | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| float GetDuration() const; | | Time getDuration() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Assignment operator | | /// \brief Overload of assignment operator | |
| /// | | /// | |
|
| /// \param Other : Instance to assign | | /// \param right Instance to assign | |
| /// | | /// | |
|
| /// \return Reference to the sound buffer | | /// \return Reference to self | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| SoundBuffer& operator =(const SoundBuffer& Other); | | SoundBuffer& operator =(const SoundBuffer& right); | |
| | | | |
| private : | | private : | |
| | | | |
| friend class Sound; | | friend class Sound; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Update the internal buffer with the audio samples | | /// \brief Initialize the internal state after loading a new sound | |
| /// | | /// | |
|
| /// \param ChannelsCount : Number of channels | | /// \param file Sound file providing access to the new loaded sound | |
| /// \param SampleRate : Sample rate | | | |
| /// | | /// | |
|
| /// \return True on success | | /// \return True on succesful initialization, false on failure | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool Update(unsigned int ChannelsCount, unsigned int SampleRate); | | bool initialize(priv::SoundFile& file); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Add a sound to the list of sounds that use this buffer | | /// \brief Update the internal buffer with the cached audio samples | |
| /// | | /// | |
|
| /// \param Instance : Sound object to attach | | /// \param channelCount Number of channels | |
| | | /// \param sampleRate Sample rate (number of samples per second) | |
| | | /// | |
| | | /// \return True on success, false if any error happened | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void AttachSound(Sound* Instance) const; | | bool update(unsigned int channelCount, unsigned int sampleRate); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Remove a sound from the list of sounds that use this buffer | | /// \brief Add a sound to the list of sounds that use this buffer | |
| /// | | /// | |
|
| /// \param Instance : Sound object to detach | | /// \param sound Sound instance to attach | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void DetachSound(Sound* Instance) const; | | void attachSound(Sound* sound) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Remove a sound from the list of sounds that use this buffer | |
| | | /// | |
| | | /// \param sound Sound instance to detach | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void detachSound(Sound* sound) const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Types | | // Types | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| typedef std::set<Sound*> SoundList; ///< Set of unique sound instances | | typedef std::set<Sound*> SoundList; ///< Set of unique sound instances | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int myBuffer; ///< OpenAL buffer identifier | | unsigned int m_buffer; ///< OpenAL buffer identifier | |
| std::vector<Int16> mySamples; ///< Samples buffer | | std::vector<Int16> m_samples; ///< Samples buffer | |
| float myDuration; ///< Sound duration, in seconds | | Time m_duration; ///< Sound duration | |
| mutable SoundList mySounds; ///< List of sounds that are using this | | mutable SoundList m_sounds; ///< List of sounds that are using this | |
| buffer | | buffer | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_SOUNDBUFFER_HPP | | #endif // SFML_SOUNDBUFFER_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::SoundBuffer | |
| | | /// \ingroup audio | |
| | | /// | |
| | | /// A sound buffer holds the data of a sound, which is | |
| | | /// an array of audio samples. A sample is a 16 bits signed integer | |
| | | /// that defines the amplitude of the sound at a given time. | |
| | | /// The sound is then restituted by playing these samples at | |
| | | /// a high rate (for example, 44100 samples per second is the | |
| | | /// standard rate used for playing CDs). In short, audio samples | |
| | | /// are like texture pixels, and a sf::SoundBuffer is similar to | |
| | | /// a sf::Texture. | |
| | | /// | |
| | | /// A sound buffer can be loaded from a file (see loadFromFile() | |
| | | /// for the complete list of supported formats), from memory, from | |
| | | /// a custom stream (see sf::InputStream) or directly from an array | |
| | | /// of samples. It can also be saved back to a file. | |
| | | /// | |
| | | /// Sound buffers alone are not very useful: they hold the audio data | |
| | | /// but cannot be played. To do so, you need to use the sf::Sound class, | |
| | | /// which provides functions to play/pause/stop the sound as well as | |
| | | /// changing the way it is outputted (volume, pitch, 3D position, ...). | |
| | | /// This separation allows more flexibility and better performances: | |
| | | /// indeed a sf::SoundBuffer is a heavy resource, and any operation on it | |
| | | /// is slow (often too slow for real-time applications). On the other | |
| | | /// side, a sf::Sound is a lightweight object, which can use the audio data | |
| | | /// of a sound buffer and change the way it is played without actually | |
| | | /// modifying that data. Note that it is also possible to bind | |
| | | /// several sf::Sound instances to the same sf::SoundBuffer. | |
| | | /// | |
| | | /// It is important to note that the sf::Sound instance doesn't | |
| | | /// copy the buffer that it uses, it only keeps a reference to it. | |
| | | /// Thus, a sf::SoundBuffer must not be destructed while it is | |
| | | /// used by a sf::Sound (i.e. never write a function that | |
| | | /// uses a local sf::SoundBuffer instance for loading a sound). | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Declare a new sound buffer | |
| | | /// sf::SoundBuffer buffer; | |
| | | /// | |
| | | /// // Load it from a file | |
| | | /// if (!buffer.loadFromFile("sound.wav")) | |
| | | /// { | |
| | | /// // error... | |
| | | /// } | |
| | | /// | |
| | | /// // Create a sound source and bind it to the buffer | |
| | | /// sf::Sound sound1; | |
| | | /// sound1.setBuffer(buffer); | |
| | | /// | |
| | | /// // Play the sound | |
| | | /// sound1.play(); | |
| | | /// | |
| | | /// // Create another sound source bound to the same buffer | |
| | | /// sf::Sound sound2; | |
| | | /// sound2.setBuffer(buffer); | |
| | | /// | |
| | | /// // Play it with a higher pitch -- the first sound remains unchanged | |
| | | /// sound2.setPitch(2); | |
| | | /// sound2.play(); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::Sound, sf::SoundBufferRecorder | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 58 change blocks. |
| 68 lines changed or deleted | | 144 lines changed or added | |
|
| SoundBufferRecorder.hpp | | SoundBufferRecorder.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_SOUNDBUFFERRECORDER_HPP | | #ifndef SFML_SOUNDBUFFERRECORDER_HPP | |
| #define SFML_SOUNDBUFFERRECORDER_HPP | | #define SFML_SOUNDBUFFERRECORDER_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/Audio/Export.hpp> | |
| #include <SFML/Audio/SoundBuffer.hpp> | | #include <SFML/Audio/SoundBuffer.hpp> | |
| #include <SFML/Audio/SoundRecorder.hpp> | | #include <SFML/Audio/SoundRecorder.hpp> | |
| #include <vector> | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Specialized SoundRecorder which saves the captured | | /// \brief Specialized SoundRecorder which stores the captured | |
| /// audio data into a sound buffer | | /// audio data into a sound buffer | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API SoundBufferRecorder : public SoundRecorder | | class SFML_AUDIO_API SoundBufferRecorder : public SoundRecorder | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the sound buffer containing the captured audio data | | /// \brief Get the sound buffer containing the captured audio data | |
| /// | | /// | |
|
| /// \return Constant reference to the sound buffer | | /// The sound buffer is valid only after the capture has ended. | |
| | | /// This function provides a read-only access to the internal | |
| | | /// sound buffer, but it can be copied if you need to | |
| | | /// make any modification to it. | |
| | | /// | |
| | | /// \return Read-only access to the sound buffer | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const SoundBuffer& GetBuffer() const; | | const SoundBuffer& getBuffer() const; | |
| | | | |
|
| private : | | protected: | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see SoundBuffer::OnStart | | /// \brief Start capturing audio data | |
| | | /// | |
| | | /// \return True to start the capture, or false to abort it | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnStart(); | | virtual bool onStart(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see SoundBuffer::OnProcessSamples | | /// \brief Process a new chunk of recorded samples | |
| | | /// | |
| | | /// \param samples Pointer to the new chunk of recorded samples | |
| | | /// \param sampleCount Number of samples pointed by \a samples | |
| | | /// | |
| | | /// \return True to continue the capture, or false to stop it | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnProcessSamples(const Int16* Samples, std::size_t Samples
Count); | | virtual bool onProcessSamples(const Int16* samples, std::size_t sampleC
ount); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see SoundBuffer::OnStop | | /// \brief Stop capturing audio data | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void OnStop(); | | virtual void onStop(); | |
| | | | |
| | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::vector<Int16> mySamples; ///< Temporary sample buffer to hold the | | std::vector<Int16> m_samples; ///< Temporary sample buffer to hold the | |
| recorded data | | recorded data | |
| SoundBuffer myBuffer; ///< Sound buffer that will contain the r | | SoundBuffer m_buffer; ///< Sound buffer that will contain the r | |
| ecorded data | | ecorded data | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_SOUNDBUFFERRECORDER_HPP | | #endif // SFML_SOUNDBUFFERRECORDER_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::SoundBufferRecorder | |
| | | /// \ingroup audio | |
| | | /// | |
| | | /// sf::SoundBufferRecorder allows to access a recorded sound | |
| | | /// through a sf::SoundBuffer, so that it can be played, saved | |
| | | /// to a file, etc. | |
| | | /// | |
| | | /// It has the same simple interface as its base class (start(), stop()) | |
| | | /// and adds a function to retrieve the recorded sound buffer | |
| | | /// (getBuffer()). | |
| | | /// | |
| | | /// As usual, don't forget to call the isAvailable() function | |
| | | /// before using this class (see sf::SoundRecorder for more details | |
| | | /// about this). | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// if (sf::SoundBufferRecorder::isAvailable()) | |
| | | /// { | |
| | | /// // Record some audio data | |
| | | /// sf::SoundBufferRecorder recorder; | |
| | | /// recorder.start(); | |
| | | /// ... | |
| | | /// recorder.stop(); | |
| | | /// | |
| | | /// // Get the buffer containing the captured audio data | |
| | | /// const sf::SoundBuffer& buffer = recorder.getBuffer(); | |
| | | /// | |
| | | /// // Save it to a file (for example...) | |
| | | /// buffer.saveToFile("my_record.ogg"); | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::SoundRecorder | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 16 change blocks. |
| 18 lines changed or deleted | | 34 lines changed or added | |
|
| SoundRecorder.hpp | | SoundRecorder.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_SOUNDRECORDER_HPP | | #ifndef SFML_SOUNDRECORDER_HPP | |
| #define SFML_SOUNDRECORDER_HPP | | #define SFML_SOUNDRECORDER_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | #include <SFML/Audio/Export.hpp> | |
| #include <SFML/System/Thread.hpp> | | #include <SFML/System/Thread.hpp> | |
| #include <vector> | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// SoundRecorder is an interface for capturing sound data, | | /// \brief Abstract base class for capturing sound data | |
| /// it is meant to be used as a base class | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API SoundRecorder : private Thread | | class SFML_AUDIO_API SoundRecorder | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Virtual destructor | | /// \brief destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| virtual ~SoundRecorder(); | | virtual ~SoundRecorder(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Start the capture. | | /// \brief Start the capture | |
| /// Warning : only one capture can happen at the same time | | | |
| /// | | /// | |
|
| /// \param SampleRate : Sound frequency (the more samples, the higher t | | /// The \a sampleRate parameter defines the number of audio samples | |
| he quality) | | /// captured per second. The higher, the better the quality | |
| /// (44100 by default = CD quality) | | /// (for example, 44100 samples/sec is CD quality). | |
| | | /// This function uses its own thread so that it doesn't block | |
| | | /// the rest of the program while the capture runs. | |
| | | /// Please note that only one capture can happen at the same time. | |
| | | /// | |
| | | /// \param sampleRate Desired capture rate, in number of samples per se | |
| | | cond | |
| | | /// | |
| | | /// \see stop | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Start(unsigned int SampleRate = 44100); | | void start(unsigned int sampleRate = 44100); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Stop the capture | | /// \brief Stop the capture | |
| | | /// | |
| | | /// \see start | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Stop(); | | void stop(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the sample rate | | /// \brief Get the sample rate | |
| /// | | /// | |
|
| /// \return Frequency, in samples per second | | /// The sample rate defines the number of audio samples | |
| | | /// captured per second. The higher, the better the quality | |
| | | /// (for example, 44100 samples/sec is CD quality). | |
| | | /// | |
| | | /// \return Sample rate, in samples per second | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetSampleRate() const; | | unsigned int getSampleRate() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Tell if the system supports sound capture. | | /// \brief Check if the system supports audio capture | |
| /// If not, this class won't be usable | | /// | |
| | | /// This function should always be called before using | |
| | | /// the audio capture features. If it returns false, then | |
| | | /// any attempt to use sf::SoundRecorder or one of its derived | |
| | | /// classes will fail. | |
| /// | | /// | |
|
| /// \return True if audio capture is supported | | /// \return True if audio capture is supported, false otherwise | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static bool CanCapture(); | | static bool isAvailable(); | |
| | | | |
| protected : | | protected : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// This constructor is only meant to be called by derived classes. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| SoundRecorder(); | | SoundRecorder(); | |
| | | | |
|
| private : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Start recording audio data | | /// \brief Start capturing audio data | |
| /// | | /// | |
|
| /// \return False to abort recording audio data, true to start | | /// This virtual function may be overriden by a derived class | |
| | | /// if something has to be done every time a new capture | |
| | | /// starts. If not, this function can be ignored; the default | |
| | | /// implementation does nothing. | |
| | | /// | |
| | | /// \return True to start the capture, or false to abort it | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnStart(); | | virtual bool onStart(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Process a new chunk of recorded samples | | /// \brief Process a new chunk of recorded samples | |
| | | /// | |
| | | /// This virtual function is called every time a new chunk of | |
| | | /// recorded data is available. The derived class can then do | |
| | | /// whatever it wants with it (storing it, playing it, sending | |
| | | /// it over the network, etc.). | |
| /// | | /// | |
|
| /// \param Samples : Pointer to the new chunk of recorded samples | | /// \param samples Pointer to the new chunk of recorded samples | |
| /// \param SamplesCount : Number of samples pointed by Samples | | /// \param sampleCount Number of samples pointed by \a samples | |
| /// | | /// | |
|
| /// \return False to stop recording audio data, true to continue | | /// \return True to continue the capture, or false to stop it | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnProcessSamples(const Int16* Samples, std::size_t Samples
Count) = 0; | | virtual bool onProcessSamples(const Int16* samples, std::size_t sampleC
ount) = 0; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Stop recording audio data | | /// \brief Stop capturing audio data | |
| | | /// | |
| | | /// This virtual function may be overriden by a derived class | |
| | | /// if something has to be done every time the capture | |
| | | /// ends. If not, this function can be ignored; the default | |
| | | /// implementation does nothing. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void OnStop(); | | virtual void onStop(); | |
| | | | |
| | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see Thread::Run | | /// \brief Function called as the entry point of the thread | |
| | | /// | |
| | | /// This function starts the recording loop, and returns | |
| | | /// only when the capture is stopped. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void Run(); | | void record(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the available captured samples and process them | | /// \brief Get the new available audio samples and process them | |
| | | /// | |
| | | /// This function is called continuously during the | |
| | | /// capture loop. It retrieves the captured samples and | |
| | | /// forwards them to the derived class. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void ProcessCapturedSamples(); | | void processCapturedSamples(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Clean up the recorder internal resources | | /// \brief Clean up the recorder's internal resources | |
| | | /// | |
| | | /// This function is called when the capture stops. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void CleanUp(); | | void cleanup(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| std::vector<Int16> mySamples; ///< Buffer to store captured samples | | Thread m_thread; ///< Thread running the background re | |
| unsigned int mySampleRate; ///< Sample rate | | cording task | |
| bool myIsCapturing; ///< Capturing state | | std::vector<Int16> m_samples; ///< Buffer to store captured samples | |
| | | unsigned int m_sampleRate; ///< Sample rate | |
| | | bool m_isCapturing; ///< Capturing state | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_SOUNDRECORDER_HPP | | #endif // SFML_SOUNDRECORDER_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::SoundRecorder | |
| | | /// \ingroup audio | |
| | | /// | |
| | | /// sf::SoundBuffer provides a simple interface to access | |
| | | /// the audio recording capabilities of the computer | |
| | | /// (the microphone). As an abstract base class, it only cares | |
| | | /// about capturing sound samples, the task of making something | |
| | | /// useful with them is left to the derived class. Note that | |
| | | /// SFML provides a built-in specialization for saving the | |
| | | /// captured data to a sound buffer (see sf::SoundBufferRecorder). | |
| | | /// | |
| | | /// A derived class has only one virtual function to override: | |
| | | /// \li onProcessSamples provides the new chunks of audio samples while the | |
| | | capture happens | |
| | | /// | |
| | | /// Moreover, two additionnal virtual functions can be overriden | |
| | | /// as well if necessary: | |
| | | /// \li onStart is called before the capture happens, to perform custom ini | |
| | | tializations | |
| | | /// \li onStop is called after the capture ends, to perform custom cleanup | |
| | | /// | |
| | | /// The audio capture feature may not be supported or activated | |
| | | /// on every platform, thus it is recommended to check its | |
| | | /// availability with the isAvailable() function. If it returns | |
| | | /// false, then any attempt to use an audio recorder will fail. | |
| | | /// | |
| | | /// It is important to note that the audio capture happens in a | |
| | | /// separate thread, so that it doesn't block the rest of the | |
| | | /// program. In particular, the onProcessSamples and onStop | |
| | | /// virtual functions (but not onStart) will be called | |
| | | /// from this separate thread. It is important to keep this in | |
| | | /// mind, because you may have to take care of synchronization | |
| | | /// issues if you share data between threads. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// class CustomRecorder : public sf::SoundRecorder | |
| | | /// { | |
| | | /// virtual bool onStart() // optional | |
| | | /// { | |
| | | /// // Initialize whatever has to be done before the capture starts | |
| | | /// ... | |
| | | /// | |
| | | /// // Return true to start playing | |
| | | /// return true; | |
| | | /// } | |
| | | /// | |
| | | /// virtual bool onProcessSamples(const Int16* samples, std::size_t sam | |
| | | pleCount) | |
| | | /// { | |
| | | /// // Do something with the new chunk of samples (store them, send | |
| | | them, ...) | |
| | | /// ... | |
| | | /// | |
| | | /// // Return true to continue playing | |
| | | /// return true; | |
| | | /// } | |
| | | /// | |
| | | /// virtual void onStop() // optional | |
| | | /// { | |
| | | /// // Clean up whatever has to be done after the capture ends | |
| | | /// ... | |
| | | /// } | |
| | | /// } | |
| | | /// | |
| | | /// // Usage | |
| | | /// if (CustomRecorder::isAvailable()) | |
| | | /// { | |
| | | /// CustomRecorder recorder; | |
| | | /// recorder.start(); | |
| | | /// ... | |
| | | /// recorder.stop(); | |
| | | /// } | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::SoundBufferRecorder | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 35 change blocks. |
| 42 lines changed or deleted | | 88 lines changed or added | |
|
| SoundStream.hpp | | SoundStream.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_SOUNDSTREAM_HPP | | #ifndef SFML_SOUNDSTREAM_HPP | |
| #define SFML_SOUNDSTREAM_HPP | | #define SFML_SOUNDSTREAM_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Audio/Sound.hpp> | | #include <SFML/Audio/Export.hpp> | |
| | | #include <SFML/Audio/SoundSource.hpp> | |
| #include <SFML/System/Thread.hpp> | | #include <SFML/System/Thread.hpp> | |
|
| | | #include <SFML/System/Time.hpp> | |
| #include <cstdlib> | | #include <cstdlib> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// SoundStream is a streamed sound, ie samples are acquired | | /// \brief Abstract base class for streamed audio sources | |
| /// 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 | | class SFML_AUDIO_API SoundStream : public SoundSource | |
| { | | { | |
| public : | | 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 | | /// \brief Structure defining a chunk of audio data to stream | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| struct Chunk | | struct Chunk | |
| { | | { | |
|
| const Int16* Samples; ///< Pointer to the audio samples | | const Int16* samples; ///< Pointer to the audio samples | |
| std::size_t NbSamples; ///< Number of samples pointed by Samples | | std::size_t sampleCount; ///< Number of samples pointed by Samples | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Virtual destructor | | /// \brief Destructor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| virtual ~SoundStream(); | | virtual ~SoundStream(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Start playing the audio stream | | /// \brief Start or resume playing the audio stream | |
| | | /// | |
| | | /// This function starts the stream if it was stopped, resumes | |
| | | /// it if it was paused, and restarts it from beginning if it | |
| | | /// was it already playing. | |
| | | /// This function uses its own thread so that it doesn't block | |
| | | /// the rest of the program while the stream is played. | |
| | | /// | |
| | | /// \see pause, stop | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void play(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Pause the audio stream | |
| | | /// | |
| | | /// This function pauses the stream if it was playing, | |
| | | /// otherwise (stream already paused or stopped) it has no effect. | |
| | | /// | |
| | | /// \see play, stop | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Play(); | | void pause(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Stop playing the audio stream | | /// \brief Stop playing the audio stream | |
| | | /// | |
| | | /// This function stops the stream if it was playing or paused, | |
| | | /// and does nothing if it was already stopped. | |
| | | /// It also resets the playing position (unlike pause()). | |
| | | /// | |
| | | /// \see play, pause | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Stop(); | | void stop(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Return the number of channels (1 = mono, 2 = stereo) | | /// \brief Return the number of channels of the stream | |
| | | /// | |
| | | /// 1 channel means a mono sound, 2 means stereo, etc. | |
| /// | | /// | |
| /// \return Number of channels | | /// \return Number of channels | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetChannelsCount() const; | | unsigned int getChannelCount() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the stream sample rate | | /// \brief Get the stream sample rate of the stream | |
| | | /// | |
| | | /// The sample rate is the number of audio samples played per | |
| | | /// second. The higher, the better the quality. | |
| /// | | /// | |
|
| /// \return Stream frequency (number of samples per second) | | /// \return Sample rate, in number of samples per second | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int GetSampleRate() const; | | unsigned int getSampleRate() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the status of the stream (stopped, paused, playing) | | /// \brief Get the current status of the stream (stopped, paused, playi
ng) | |
| /// | | /// | |
|
| /// \return Current status of the sound | | /// \return Current status | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Status GetStatus() const; | | Status getStatus() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the current playing position of the stream | | /// \brief Change the current playing position of the stream | |
| | | /// | |
| | | /// The playing position can be changed when the stream is | |
| | | /// either paused or playing. | |
| /// | | /// | |
|
| /// \return Current playing position, expressed in seconds | | /// \param timeOffset New playing position, from the beginning of the s | |
| | | tream | |
| | | /// | |
| | | /// \see getPlayingOffset | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| float GetPlayingOffset() const; | | void setPlayingOffset(Time timeOffset); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the stream loop state. | | /// \brief Get the current playing position of the stream | |
| /// This parameter is disabled by default | | /// | |
| | | /// \return Current playing position, from the beginning of the stream | |
| | | /// | |
| | | /// \see setPlayingOffset | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Time getPlayingOffset() const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Set whether or not the stream should loop after reaching the | |
| | | end | |
| | | /// | |
| | | /// If set, the stream will restart from beginning after | |
| | | /// reaching the end and so on, until it is stopped or | |
| | | /// setLoop(false) is called. | |
| | | /// The default looping state for streams is false. | |
| /// | | /// | |
|
| /// \param Loop : True to play in loop, false to play once | | /// \param loop True to play in loop, false to play once | |
| | | /// | |
| | | /// \see getLoop | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetLoop(bool Loop); | | void setLoop(bool loop); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Tell whether or not the stream is looping | | /// \brief Tell whether or not the stream is in loop mode | |
| | | /// | |
| | | /// \return True if the stream is looping, false otherwise | |
| /// | | /// | |
|
| /// \return True if the music is looping, false otherwise | | /// \see setLoop | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool GetLoop() const; | | bool getLoop() const; | |
| | | | |
| protected : | | protected : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// This constructor is only meant to be called by derived classes. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| SoundStream(); | | SoundStream(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the audio stream parameters, you must call it before Play() | | /// \brief Define the audio stream parameters | |
| /// | | /// | |
|
| /// \param ChannelsCount : Number of channels | | /// This function must be called by derived classes as soon | |
| /// \param SampleRate : Sample rate | | /// as they know the audio settings of the stream to play. | |
| | | /// Any attempt to manipulate the stream (play(), ...) before | |
| | | /// calling this function will fail. | |
| | | /// It can be called multiple times if the settings of the | |
| | | /// audio stream change, but only when the stream is stopped. | |
| | | /// | |
| | | /// \param channelCount Number of channels of the stream | |
| | | /// \param sampleRate Sample rate, in samples per second | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Initialize(unsigned int ChannelsCount, unsigned int SampleRate); | | void initialize(unsigned int channelCount, unsigned int sampleRate); | |
| | | | |
| private : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see Thread::Run | | /// \brief Request a new chunk of audio samples from the stream source | |
| | | /// | |
| | | /// This function must be overriden by derived classes to provide | |
| | | /// the audio samples to play. It is called continuously by the | |
| | | /// streaming loop, in a separate thread. | |
| | | /// The source can choose to stop the streaming loop at any time, by | |
| | | /// returning false to the caller. | |
| | | /// | |
| | | /// \param data Chunk of data to fill | |
| | | /// | |
| | | /// \return True to continue playback, false to stop | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void Run(); | | virtual bool onGetData(Chunk& data) = 0; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Called when the sound restarts | | /// \brief Change the current playing position in the stream source | |
| | | /// | |
| | | /// This function must be overriden by derived classes to | |
| | | /// allow random seeking into the stream source. | |
| /// | | /// | |
|
| /// \return If false is returned, the playback is aborted | | /// \param timeOffset New playing position, relative to the beginning o
f the stream | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnStart(); | | virtual void onSeek(Time timeOffset) = 0; | |
| | | | |
| | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Called each time new audio data is needed to feed the stream | | /// \brief Function called as the entry point of the thread | |
| /// | | | |
| /// \param Data : New chunk of data to stream | | | |
| /// | | /// | |
|
| /// \return True to continue playback, false to stop | | /// This function starts the streaming loop, and returns | |
| | | /// only when the sound is stopped. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual bool OnGetData(Chunk& Data) = 0; | | void streamData(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Fill a new buffer with audio data, and push it to the | | /// \brief Fill a new buffer with audio samples, and append | |
| /// playing queue | | /// it to the playing queue | |
| /// | | /// | |
|
| /// \param Buffer : Number of the buffer to fill (in [0, BuffersCount]) | | /// This function is called as soon as a buffer has been fully | |
| | | /// consumed; it fills it again and inserts it back into the | |
| | | /// playing queue. | |
| /// | | /// | |
|
| /// \return True if the derived class has requested to stop | | /// \param buffer Number of the buffer to fill (in [0, BufferCount]) | |
| | | /// | |
| | | /// \return True if the stream source has requested to stop, false othe | |
| | | rwise | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool FillAndPushBuffer(unsigned int BufferNum); | | bool fillAndPushBuffer(unsigned int bufferNum); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Fill the buffers queue with all available buffers | | /// \brief Fill the audio buffers and put them all into the playing que | |
| | | ue | |
| | | /// | |
| | | /// This function is called when playing starts and the | |
| | | /// playing queue is empty. | |
| /// | | /// | |
|
| /// \return True if the derived class has requested to stop | | /// \return True if the derived class has requested to stop, false othe
rwise | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool FillQueue(); | | bool fillQueue(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Clear the queue of any remaining buffers | | /// \brief Clear all the audio buffers and empty the playing queue | |
| | | /// | |
| | | /// This function is called when the stream is stopped. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void ClearQueue(); | | void clearQueue(); | |
| | | | |
|
| enum {BuffersCount = 3}; | | enum | |
| | | { | |
| | | BufferCount = 3 ///< Number of audio buffers used by the streaming | |
| | | loop | |
| | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool myIsStreaming; ///< Streaming state (true = | | Thread m_thread; ///< Thread running the backgr | |
| playing, false = stopped) | | ound tasks | |
| unsigned int myBuffers[BuffersCount]; ///< Sound buffers used to st | | bool m_isStreaming; ///< Streaming state (true = p | |
| ore temporary audio data | | laying, false = stopped) | |
| unsigned int myChannelsCount; ///< Number of channels (1 = | | unsigned int m_buffers[BufferCount]; ///< Sound buffers used to sto | |
| mono, 2 = stereo, ...) | | re temporary audio data | |
| unsigned int mySampleRate; ///< Frequency (samples / sec | | unsigned int m_channelCount; ///< Number of channels (1 = m | |
| ond) | | ono, 2 = stereo, ...) | |
| unsigned long myFormat; ///< Format of the internal s | | unsigned int m_sampleRate; ///< Frequency (samples / seco | |
| ound buffers | | nd) | |
| bool myLoop; ///< Loop flag (true to loop, | | Uint32 m_format; ///< Format of the internal so | |
| false to play once) | | und buffers | |
| unsigned int mySamplesProcessed; ///< Number of buffers proces | | bool m_loop; ///< Loop flag (true to loop, | |
| sed since beginning of the stream | | false to play once) | |
| bool myEndBuffers[BuffersCount]; ///< Each buffer is marked as | | Uint64 m_samplesProcessed; ///< Number of buffers process | |
| "end buffer" or not, for proper duration calculation | | ed since beginning of the stream | |
| | | bool m_endBuffers[BufferCount]; ///< Each buffer is marked as | |
| | | "end buffer" or not, for proper duration calculation | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_SOUNDSTREAM_HPP | | #endif // SFML_SOUNDSTREAM_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::SoundStream | |
| | | /// \ingroup audio | |
| | | /// | |
| | | /// Unlike audio buffers (see sf::SoundBuffer), audio streams | |
| | | /// are never completely loaded in memory. Instead, the audio | |
| | | /// data is acquired continuously while the stream is playing. | |
| | | /// This behaviour allows to play a sound with no loading delay, | |
| | | /// and keeps the memory consumption very low. | |
| | | /// | |
| | | /// Sound sources that need to be streamed are usually big files | |
| | | /// (compressed audio musics that would eat hundreds of MB in memory) | |
| | | /// or files that would take a lot of time to be received | |
| | | /// (sounds played over the network). | |
| | | /// | |
| | | /// sf::SoundStream is a base class that doesn't care about the | |
| | | /// stream source, which is left to the derived class. SFML provides | |
| | | /// a built-in specialization for big files (see sf::Music). | |
| | | /// No network stream source is provided, but you can write your own | |
| | | /// by combining this class with the network module. | |
| | | /// | |
| | | /// A derived class has to override two virtual functions: | |
| | | /// \li onGetData fills a new chunk of audio data to be played | |
| | | /// \li onSeek changes the current playing position in the source | |
| | | /// | |
| | | /// It is important to note that each SoundStream is played in its | |
| | | /// own separate thread, so that the streaming loop doesn't block the | |
| | | /// rest of the program. In particular, the OnGetData and OnSeek | |
| | | /// virtual functions may sometimes be called from this separate thread. | |
| | | /// It is important to keep this in mind, because you may have to take | |
| | | /// care of synchronization issues if you share data between threads. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// class CustomStream : public sf::SoundStream | |
| | | /// { | |
| | | /// public : | |
| | | /// | |
| | | /// bool open(const std::string& location) | |
| | | /// { | |
| | | /// // Open the source and get audio settings | |
| | | /// ... | |
| | | /// unsigned int channelCount = ...; | |
| | | /// unsigned int sampleRate = ...; | |
| | | /// | |
| | | /// // Initialize the stream -- important! | |
| | | /// initialize(channelCount, sampleRate); | |
| | | /// } | |
| | | /// | |
| | | /// private : | |
| | | /// | |
| | | /// virtual bool onGetData(Chunk& data) | |
| | | /// { | |
| | | /// // Fill the chunk with audio data from the stream source | |
| | | /// data.samples = ...; | |
| | | /// data.sampleCount = ...; | |
| | | /// | |
| | | /// // Return true to continue playing | |
| | | /// return true; | |
| | | /// } | |
| | | /// | |
| | | /// virtual void onSeek(Uint32 timeOffset) | |
| | | /// { | |
| | | /// // Change the current position in the stream source | |
| | | /// ... | |
| | | /// } | |
| | | /// } | |
| | | /// | |
| | | /// // Usage | |
| | | /// CustomStream stream; | |
| | | /// stream.open("path/to/stream"); | |
| | | /// stream.play(); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::Music | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 54 change blocks. |
| 95 lines changed or deleted | | 171 lines changed or added | |
|
| Sprite.hpp | | Sprite.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_SPRITE_HPP | | #ifndef SFML_SPRITE_HPP | |
| #define SFML_SPRITE_HPP | | #define SFML_SPRITE_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/System/Resource.hpp> | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/Graphics/Drawable.hpp> | | #include <SFML/Graphics/Drawable.hpp> | |
|
| | | #include <SFML/Graphics/Transformable.hpp> | |
| | | #include <SFML/Graphics/Vertex.hpp> | |
| #include <SFML/Graphics/Rect.hpp> | | #include <SFML/Graphics/Rect.hpp> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| class Image; | | class Texture; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Sprite defines a sprite : texture, transformations, | | /// \brief Drawable representation of a texture, with its | |
| /// color, and draw on screen | | /// own transformations, color, etc. | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API Sprite : public Drawable | | class SFML_GRAPHICS_API Sprite : public Drawable, public Transformable | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// Creates an empty sprite with no source texture. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Sprite(); | | Sprite(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the sprite from a source image | | /// \brief Construct the sprite from a source texture | |
| | | /// | |
| | | /// \param texture Source texture | |
| /// | | /// | |
|
| /// \param Img : Image of the sprite | | /// \see setTexture | |
| /// \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 C
olor& Col = Color(255, 255, 255, 255)); | | explicit Sprite(const Texture& texture); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the image of the sprite | | /// \brief Construct the sprite from a sub-rectangle of a source textur
e | |
| /// | | /// | |
|
| /// \param Img : New image | | /// \param texture Source texture | |
| | | /// \param rectangle Sub-rectangle of the texture to assign to the spri | |
| | | te | |
| | | /// | |
| | | /// \see setTexture, setTextureRect | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetImage(const Image& Img); | | Sprite(const Texture& texture, const IntRect& rectangle); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the sub-rectangle of the sprite inside the source image. | | /// \brief Change the source texture of the sprite | |
| /// By default, the subrect covers the entire source image | | /// | |
| | | /// The \a texture argument refers to a texture that must | |
| | | /// exist as long as the sprite uses it. Indeed, the sprite | |
| | | /// doesn't store its own copy of the texture, but rather keeps | |
| | | /// a pointer to the one that you passed to this function. | |
| | | /// If the source texture is destroyed and the sprite tries to | |
| | | /// use it, the behaviour is undefined. | |
| | | /// If \a resetRect is true, the TextureRect property of | |
| | | /// the sprite is automatically adjusted to the size of the new | |
| | | /// texture. If it is false, the texture rect is left unchanged. | |
| /// | | /// | |
|
| /// \param SubRect : New sub-rectangle | | /// \param texture New texture | |
| | | /// \param resetRect Should the texture rect be reset to the size of th | |
| | | e new texture? | |
| | | /// | |
| | | /// \see getTexture, setTextureRect | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetSubRect(const IntRect& SubRect); | | void setTexture(const Texture& texture, bool resetRect = false); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Resize the sprite (by changing its scale factors) (take 2 values). | | /// \brief Set the sub-rectangle of the texture that the sprite will di | |
| /// The default size is defined by the subrect | | splay | |
| | | /// | |
| | | /// The texture rect is useful when you don't want to display | |
| | | /// the whole texture, but rather a part of it. | |
| | | /// By default, the texture rect covers the entire texture. | |
| | | /// | |
| | | /// \param rectangle Rectangle defining the region of the texture to di | |
| | | splay | |
| /// | | /// | |
|
| /// \param Width : New width (must be strictly positive) | | /// \see getTextureRect, setTexture | |
| /// \param Height : New height (must be strictly positive) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Resize(float Width, float Height); | | void setTextureRect(const IntRect& rectangle); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Resize the sprite (by changing its scale factors) (take a 2D vector | | /// \brief Set the global color of the sprite | |
| ). | | | |
| /// The default size is defined by the subrect | | | |
| /// | | /// | |
|
| /// \param Size : New size (both coordinates must be strictly positive) | | /// This color is modulated (multiplied) with the sprite's | |
| | | /// texture. It can be used to colorize the sprite, or change | |
| | | /// its global opacity. | |
| | | /// By default, the sprite's color is opaque white. | |
| | | /// | |
| | | /// \param color New color of the sprite | |
| | | /// | |
| | | /// \see getColor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Resize(const Vector2f& Size); | | void setColor(const Color& color); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Flip the sprite horizontally | | /// \brief Get the source texture of the sprite | |
| | | /// | |
| | | /// If the sprite has no source texture, a NULL pointer is returned. | |
| | | /// The returned pointer is const, which means that you can't | |
| | | /// modify the texture when you retrieve it with this function. | |
| /// | | /// | |
|
| /// \param Flipped : True to flip the sprite | | /// \return Pointer to the sprite's texture | |
| | | /// | |
| | | /// \see setTexture | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void FlipX(bool Flipped); | | const Texture* getTexture() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Flip the sprite vertically | | /// \brief Get the sub-rectangle of the texture displayed by the sprite | |
| | | /// | |
| | | /// \return Texture rectangle of the sprite | |
| /// | | /// | |
|
| /// \param Flipped : True to flip the sprite | | /// \see setTextureRect | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void FlipY(bool Flipped); | | const IntRect& getTextureRect() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the source image of the sprite | | /// \brief Get the global color of the sprite | |
| | | /// | |
| | | /// \return Global color of the sprite | |
| /// | | /// | |
|
| /// \return Pointer to the image (can be NULL) | | /// \see setColor | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Image* GetImage() const; | | const Color& getColor() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the sub-rectangle of the sprite inside the source image | | /// \brief Get the local bounding rectangle of the entity | |
| /// | | /// | |
|
| /// \return Sub-rectangle | | /// The returned rectangle is in local coordinates, which means | |
| | | /// that it ignores the transformations (translation, rotation, | |
| | | /// scale, ...) that are applied to the entity. | |
| | | /// In other words, this function returns the bounds of the | |
| | | /// entity in the entity's coordinate system. | |
| | | /// | |
| | | /// \return Local bounding rectangle of the entity | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const IntRect& GetSubRect() const; | | FloatRect getLocalBounds() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the sprite size | | /// \brief Get the global bounding rectangle of the entity | |
| | | /// | |
| | | /// The returned rectangle is in global coordinates, which means | |
| | | /// that it takes in account the transformations (translation, | |
| | | /// rotation, scale, ...) that are applied to the entity. | |
| | | /// In other words, this function returns the bounds of the | |
| | | /// sprite in the global 2D world's coordinate system. | |
| /// | | /// | |
|
| /// \return Size of the sprite | | /// \return Global bounding rectangle of the entity | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Vector2f GetSize() const; | | FloatRect getGlobalBounds() const; | |
| | | | |
| | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the color of a given pixel in the sprite | | /// \brief Draw the sprite to a render target | |
| /// (point is in local coordinates) | | | |
| /// | | /// | |
|
| /// \param X : X coordinate of the pixel to get | | /// \param target Render target to draw to | |
| /// \param Y : Y coordinate of the pixel to get | | /// \param states Current render states | |
| /// | | | |
| /// \return Color of pixel (X, Y) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Color GetPixel(unsigned int X, unsigned int Y) const; | | virtual void draw(RenderTarget& target, RenderStates states) const; | |
| | | | |
| protected : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see Drawable::Render | | /// \brief Update the vertices' positions | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void Render(RenderTarget& Target) const; | | void updatePositions(); | |
| | | | |
|
| private : | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Update the vertices' texture coordinates | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void updateTexCoords(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| ResourcePtr<Image> myImage; ///< Image used to draw the sprite | | Vertex m_vertices[4]; ///< Vertices defining the sprite's geome | |
| IntRect mySubRect; ///< Sub-rectangle of source image to | | try | |
| assign to the sprite | | const Texture* m_texture; ///< Texture of the sprite | |
| bool myIsFlippedX; ///< Is the sprite flipped on the X ax | | IntRect m_textureRect; ///< Rectangle defining the area of the s | |
| is ? | | ource texture to display | |
| bool myIsFlippedY; ///< Is the sprite flipped on the Y ax | | | |
| is ? | | | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_SPRITE_HPP | | #endif // SFML_SPRITE_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Sprite | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::Sprite is a drawable class that allows to easily display | |
| | | /// a texture (or a part of it) on a render target. | |
| | | /// | |
| | | /// It inherits all the functions from sf::Transformable: | |
| | | /// position, rotation, scale, origin. It also adds sprite-specific | |
| | | /// properties such as the texture to use, the part of it to display, | |
| | | /// and some convenience functions to change the overall color of the | |
| | | /// sprite, or to get its bounding rectangle. | |
| | | /// | |
| | | /// sf::Sprite works in combination with the sf::Texture class, which | |
| | | /// loads and provides the pixel data of a given texture. | |
| | | /// | |
| | | /// The separation of sf::Sprite and sf::Texture allows more flexibility | |
| | | /// and better performances: indeed a sf::Texture is a heavy resource, | |
| | | /// and any operation on it is slow (often too slow for real-time | |
| | | /// applications). On the other side, a sf::Sprite is a lightweight | |
| | | /// object which can use the pixel data of a sf::Texture and draw | |
| | | /// it with its own transformation/color/blending attributes. | |
| | | /// | |
| | | /// It is important to note that the sf::Sprite instance doesn't | |
| | | /// copy the texture that it uses, it only keeps a reference to it. | |
| | | /// Thus, a sf::Texture must not be destroyed while it is | |
| | | /// used by a sf::Sprite (i.e. never write a function that | |
| | | /// uses a local sf::Texture instance for creating a sprite). | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Declare and load a texture | |
| | | /// sf::Texture texture; | |
| | | /// texture.loadFromFile("texture.png"); | |
| | | /// | |
| | | /// // Create a sprite | |
| | | /// sf::Sprite sprite; | |
| | | /// sprite.setTexture(texture); | |
| | | /// sprite.setTextureRect(sf::IntRect(10, 10, 50, 30)); | |
| | | /// sprite.setColor(sf::Color(255, 255, 255, 200)); | |
| | | /// sprite.setPosition(100, 25); | |
| | | /// | |
| | | /// // Draw it | |
| | | /// window.draw(sprite); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::Texture, sf::Transformable | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 45 change blocks. |
| 65 lines changed or deleted | | 117 lines changed or added | |
|
| String.hpp | | String.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_STRING_HPP | | #ifndef SFML_STRING_HPP | |
| #define SFML_STRING_HPP | | #define SFML_STRING_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/System/Resource.hpp> | | #include <SFML/System/Export.hpp> | |
| #include <SFML/System/Unicode.hpp> | | #include <locale> | |
| #include <SFML/Graphics/Drawable.hpp> | | | |
| #include <SFML/Graphics/Font.hpp> | | | |
| #include <SFML/Graphics/Rect.hpp> | | | |
| #include <string> | | #include <string> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// String defines a graphical 2D text, that can be drawn on screen | | /// \brief Utility string class that automatically handles | |
| | | /// conversions between types and encodings | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API String : public Drawable | | class SFML_SYSTEM_API String | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Enumerate the string drawing styles | | // Types | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| enum Style | | typedef std::basic_string<Uint32>::iterator Iterator; ///< I | |
| { | | terator type | |
| Regular = 0, ///< Regular characters, no style | | typedef std::basic_string<Uint32>::const_iterator ConstIterator; ///< C | |
| Bold = 1 << 0, ///< Characters are bold | | onstant iterator type | |
| Italic = 1 << 1, ///< Characters are in italic | | | |
| Underlined = 1 << 2 ///< Characters are underlined | | | |
| }; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | // Static member data | |
| | | //////////////////////////////////////////////////////////// | |
| | | static const std::size_t InvalidPos; ///< Represents an invalid positio | |
| | | n in the string | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Default constructor | |
| | | /// | |
| | | /// This constructor creates an empty string. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| String(); | | String(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the string from any kind of text | | /// \brief Construct from a single ANSI character and a locale | |
| | | /// | |
| | | /// The source character is converted to UTF-32 according | |
| | | /// to the given locale. | |
| | | /// | |
| | | /// \param ansiChar ANSI character to convert | |
| | | /// \param locale Locale to use for conversion | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | String(char ansiChar, const std::locale& locale = std::locale()); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Construct from single wide character | |
| /// | | /// | |
|
| /// \param Text : Text assigned to the string | | /// \param wideChar Wide character to convert | |
| /// \param Font : Font used to draw the string (SFML built-in font by d | | | |
| efault) | | | |
| /// \param Size : Characters size (30 by default) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| explicit String(const Unicode::Text& Text, const Font& CharFont = Font:
:GetDefaultFont(), float Size = 30.f); | | String(wchar_t wideChar); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the text (from any kind of string) | | /// \brief Construct from single UTF-32 character | |
| /// | | /// | |
|
| /// \param Text : New text | | /// \param utf32Char UTF-32 character to convert | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetText(const Unicode::Text& Text); | | String(Uint32 utf32Char); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the font of the string | | /// \brief Construct from a null-terminated C-style ANSI string and a l | |
| | | ocale | |
| | | /// | |
| | | /// The source string is converted to UTF-32 according | |
| | | /// to the given locale. | |
| /// | | /// | |
|
| /// \param Font : Font to use | | /// \param ansiString ANSI string to convert | |
| | | /// \param locale Locale to use for conversion | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetFont(const Font& CharFont); | | String(const char* ansiString, const std::locale& locale = std::locale(
)); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the size of the string | | /// \brief Construct from an ANSI string and a locale | |
| /// The default size is 30 | | /// | |
| | | /// The source string is converted to UTF-32 according | |
| | | /// to the given locale. | |
| /// | | /// | |
|
| /// \param Size : New size, in pixels | | /// \param ansiString ANSI string to convert | |
| | | /// \param locale Locale to use for conversion | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetSize(float Size); | | String(const std::string& ansiString, const std::locale& locale = std::
locale()); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Set the style of the text | | /// \brief Construct from null-terminated C-style wide string | |
| /// The default style is Regular | | | |
| /// | | /// | |
|
| /// \param TextStyle : New text style, (combination of Style enum value
s) | | /// \param wideString Wide string to convert | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetStyle(unsigned long TextStyle); | | String(const wchar_t* wideString); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the text (the returned text can be converted implicitely to any
kind of string) | | /// \brief Construct from a wide string | |
| /// | | /// | |
|
| /// \return String's text | | /// \param wideString Wide string to convert | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Unicode::Text& GetText() const; | | String(const std::wstring& wideString); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the font used by the string | | /// \brief Construct from a null-terminated C-style UTF-32 string | |
| /// | | /// | |
|
| /// \return Font used | | /// \param utf32String UTF-32 string to assign | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Font& GetFont() const; | | String(const Uint32* utf32String); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the size of the characters | | /// \brief Construct from an UTF-32 string | |
| /// | | /// | |
|
| /// \return Size of the characters | | /// \param utf32String UTF-32 string to assign | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| float GetSize() const; | | String(const std::basic_string<Uint32>& utf32String); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the style of the text | | /// \brief Copy constructor | |
| | | /// | |
| | | /// \param copy Instance to copy | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | String(const String& copy); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Implicit cast operator to std::string (ANSI string) | |
| | | /// | |
| | | /// The current global locale is used for conversion. If you | |
| | | /// want to explicitely specify a locale, see toAnsiString. | |
| | | /// Characters that do not fit in the target encoding are | |
| | | /// discarded from the returned string. | |
| | | /// This operator is defined for convenience, and is equivalent | |
| | | /// to calling toAnsiString(). | |
| /// | | /// | |
|
| /// \return Current string style (combination of Style enum values) | | /// \return Converted ANSI string | |
| | | /// | |
| | | /// \see toAnsiString, operator std::wstring | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned long GetStyle() const; | | operator std::string() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Return the visual position of the Index-th character of the string, | | /// \brief Implicit cast operator to std::wstring (wide string) | |
| /// in coordinates relative to the string | | /// | |
| /// (note : translation, center, rotation and scale are not applied) | | /// Characters that do not fit in the target encoding are | |
| | | /// discarded from the returned string. | |
| | | /// This operator is defined for convenience, and is equivalent | |
| | | /// to calling toWideString(). | |
| /// | | /// | |
|
| /// \param Index : Index of the character | | /// \return Converted wide string | |
| /// | | /// | |
|
| /// \return Position of the Index-th character (end of string if Index
is out of range) | | /// \see toWideString, operator std::string | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| sf::Vector2f GetCharacterPos(std::size_t Index) const; | | operator std::wstring() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the string rectangle on screen | | /// \brief Convert the unicode string to an ANSI string | |
| | | /// | |
| | | /// The UTF-32 string is converted to an ANSI string in | |
| | | /// the encoding defined by \a locale. | |
| | | /// Characters that do not fit in the target encoding are | |
| | | /// discarded from the returned string. | |
| | | /// | |
| | | /// \param locale Locale to use for conversion | |
| | | /// | |
| | | /// \return Converted ANSI string | |
| /// | | /// | |
|
| /// \return Rectangle contaning the string in screen coordinates | | /// \see toWideString, operator std::string | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| FloatRect GetRect() const; | | std::string toAnsiString(const std::locale& locale = std::locale()) con
st; | |
| | | | |
|
| protected : | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Convert the unicode string to a wide string | |
| | | /// | |
| | | /// Characters that do not fit in the target encoding are | |
| | | /// discarded from the returned string. | |
| | | /// | |
| | | /// \return Converted wide string | |
| | | /// | |
| | | /// \see toAnsiString, operator std::wstring | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | std::wstring toWideString() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// /see Drawable::Render | | /// \brief Overload of assignment operator | |
| | | /// | |
| | | /// \param right Instance to assign | |
| | | /// | |
| | | /// \return Reference to self | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| virtual void Render(RenderTarget& Target) const; | | String& operator =(const String& right); | |
| | | | |
|
| private : | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Overload of += operator to append an UTF-32 string | |
| | | /// | |
| | | /// \param right String to append | |
| | | /// | |
| | | /// \return Reference to self | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | String& operator +=(const String& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Overload of [] operator to access a character by its positio | |
| | | n | |
| | | /// | |
| | | /// This function provides read-only access to characters. | |
| | | /// Note: this function doesn't throw if \a index is out of range. | |
| | | /// | |
| | | /// \param index Index of the character to get | |
| | | /// | |
| | | /// \return Character at position \a index | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Uint32 operator [](std::size_t index) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Overload of [] operator to access a character by its positio | |
| | | n | |
| | | /// | |
| | | /// This function provides read and write access to characters. | |
| | | /// Note: this function doesn't throw if \a index is out of range. | |
| | | /// | |
| | | /// \param index Index of the character to get | |
| | | /// | |
| | | /// \return Reference to the character at position \a index | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Uint32& operator [](std::size_t index); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Clear the string | |
| | | /// | |
| | | /// This function removes all the characters from the string. | |
| | | /// | |
| | | /// \see isEmpty, erase | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void clear(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Get the size of the string | |
| | | /// | |
| | | /// \return Number of characters in the string | |
| | | /// | |
| | | /// \see isEmpty | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | std::size_t getSize() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Recompute the bounding rectangle of the text | | /// \brief Check whether the string is empty or not | |
| | | /// | |
| | | /// \return True if the string is empty (i.e. contains no character) | |
| | | /// | |
| | | /// \see clear, getSize | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void RecomputeRect(); | | bool isEmpty() const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Erase one or more characters from the string | |
| | | /// | |
| | | /// This function removes a sequence of \a count characters | |
| | | /// starting from \a position. | |
| | | /// | |
| | | /// \param position Position of the first character to erase | |
| | | /// \param count Number of characters to erase | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void erase(std::size_t position, std::size_t count = 1); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Insert one or more characters into the string | |
| | | /// | |
| | | /// This function inserts the characters of \a str | |
| | | /// into the string, starting from \a position. | |
| | | /// | |
| | | /// \param position Position of insertion | |
| | | /// \param str Characters to insert | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void insert(std::size_t position, const String& str); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Find a sequence of one or more characters in the string | |
| | | /// | |
| | | /// This function searches for the characters of \a str | |
| | | /// into the string, starting from \a start. | |
| | | /// | |
| | | /// \param str Characters to find | |
| | | /// \param start Where to begin searching | |
| | | /// | |
| | | /// \return Position of \a str in the string, or String::InvalidPos if | |
| | | not found | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | std::size_t find(const String& str, std::size_t start = 0) const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Get a pointer to the C-style array of characters | |
| | | /// | |
| | | /// This functions provides a read-only access to a | |
| | | /// null-terminated C-style representation of the string. | |
| | | /// The returned pointer is temporary and is meant only for | |
| | | /// immediate use, thus it is not recommended to store it. | |
| | | /// | |
| | | /// \return Read-only pointer to the array of characters | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | const Uint32* getData() const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Return an iterator to the beginning of the string | |
| | | /// | |
| | | /// \return Read-write iterator to the beginning of the string characte | |
| | | rs | |
| | | /// | |
| | | /// \see end | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Iterator begin(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Return an iterator to the beginning of the string | |
| | | /// | |
| | | /// \return Read-only iterator to the beginning of the string character | |
| | | s | |
| | | /// | |
| | | /// \see end | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | ConstIterator begin() const; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Return an iterator to the beginning of the string | |
| | | /// | |
| | | /// The end iterator refers to 1 position past the last character; | |
| | | /// thus it represents an invalid character and should never be | |
| | | /// accessed. | |
| | | /// | |
| | | /// \return Read-write iterator to the end of the string characters | |
| | | /// | |
| | | /// \see begin | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | Iterator end(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Return an iterator to the beginning of the string | |
| | | /// | |
| | | /// The end iterator refers to 1 position past the last character; | |
| | | /// thus it represents an invalid character and should never be | |
| | | /// accessed. | |
| | | /// | |
| | | /// \return Read-only iterator to the end of the string characters | |
| | | /// | |
| | | /// \see begin | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | ConstIterator end() const; | |
| | | | |
| | | private : | |
| | | | |
| | | friend SFML_SYSTEM_API bool operator ==(const String& left, const Strin | |
| | | g& right); | |
| | | friend SFML_SYSTEM_API bool operator <(const String& left, const String | |
| | | & right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| Unicode::Text myText; ///< Text to display | | std::basic_string<Uint32> m_string; ///< Internal string of UTF-32 char | |
| ResourcePtr<Font> myFont; ///< Font used to display the strin | | acters | |
| g | | | |
| 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 ? | | | |
| }; | | }; | |
| | | | |
|
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates String | |
| | | /// \brief Overload of == operator to compare two UTF-32 strings | |
| | | /// | |
| | | /// \param left Left operand (a string) | |
| | | /// \param right Right operand (a string) | |
| | | /// | |
| | | /// \return True if both strings are equal | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_SYSTEM_API bool operator ==(const String& left, const String& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates String | |
| | | /// \brief Overload of != operator to compare two UTF-32 strings | |
| | | /// | |
| | | /// \param left Left operand (a string) | |
| | | /// \param right Right operand (a string) | |
| | | /// | |
| | | /// \return True if both strings are different | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_SYSTEM_API bool operator !=(const String& left, const String& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates String | |
| | | /// \brief Overload of < operator to compare two UTF-32 strings | |
| | | /// | |
| | | /// \param left Left operand (a string) | |
| | | /// \param right Right operand (a string) | |
| | | /// | |
| | | /// \return True if \a left is alphabetically lesser than \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_SYSTEM_API bool operator <(const String& left, const String& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates String | |
| | | /// \brief Overload of > operator to compare two UTF-32 strings | |
| | | /// | |
| | | /// \param left Left operand (a string) | |
| | | /// \param right Right operand (a string) | |
| | | /// | |
| | | /// \return True if \a left is alphabetically greater than \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_SYSTEM_API bool operator >(const String& left, const String& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates String | |
| | | /// \brief Overload of <= operator to compare two UTF-32 strings | |
| | | /// | |
| | | /// \param left Left operand (a string) | |
| | | /// \param right Right operand (a string) | |
| | | /// | |
| | | /// \return True if \a left is alphabetically lesser or equal than \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_SYSTEM_API bool operator <=(const String& left, const String& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates String | |
| | | /// \brief Overload of >= operator to compare two UTF-32 strings | |
| | | /// | |
| | | /// \param left Left operand (a string) | |
| | | /// \param right Right operand (a string) | |
| | | /// | |
| | | /// \return True if \a left is alphabetically greater or equal than \a righ | |
| | | t | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_SYSTEM_API bool operator >=(const String& left, const String& right); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates String | |
| | | /// \brief Overload of binary + operator to concatenate two strings | |
| | | /// | |
| | | /// \param left Left operand (a string) | |
| | | /// \param right Right operand (a string) | |
| | | /// | |
| | | /// \return Concatenated string | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_SYSTEM_API String operator +(const String& left, const String& right); | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_STRING_HPP | | #endif // SFML_STRING_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::String | |
| | | /// \ingroup system | |
| | | /// | |
| | | /// sf::String is a utility string class defined mainly for | |
| | | /// convenience. It is a Unicode string (implemented using | |
| | | /// UTF-32), thus it can store any character in the world | |
| | | /// (european, chinese, arabic, hebrew, etc.). | |
| | | /// | |
| | | /// It automatically handles conversions from/to ANSI and | |
| | | /// wide strings, so that you can work with standard string | |
| | | /// classes and still be compatible with functions taking a | |
| | | /// sf::String. | |
| | | /// | |
| | | /// \code | |
| | | /// sf::String s; | |
| | | /// | |
| | | /// std::string s1 = s; // automatically converted to ANSI string | |
| | | /// std::wstring s2 = s; // automatically converted to wide string | |
| | | /// s = "hello"; // automatically converted from ANSI string | |
| | | /// s = L"hello"; // automatically converted from wide string | |
| | | /// s += 'a'; // automatically converted from ANSI string | |
| | | /// s += L'a'; // automatically converted from wide string | |
| | | /// \endcode | |
| | | /// | |
| | | /// Conversions involving ANSI strings use the default user locale. However | |
| | | /// it is possible to use a custom locale if necessary: | |
| | | /// \code | |
| | | /// std::locale locale; | |
| | | /// sf::String s; | |
| | | /// ... | |
| | | /// std::string s1 = s.toAnsiString(locale); | |
| | | /// s = sf::String("hello", locale); | |
| | | /// \endcode | |
| | | /// | |
| | | /// sf::String defines the most important functions of the | |
| | | /// standard std::string class: removing, random access, iterating, | |
| | | /// appending, comparing, etc. However it is a simple class | |
| | | /// provided for convenience, and you may have to consider using | |
| | | /// a more optimized class if your program requires complex string | |
| | | /// handling. The automatic conversion functions will then take | |
| | | /// care of converting your string to sf::String whenever SFML | |
| | | /// requires it. | |
| | | /// | |
| | | /// Please note that SFML also defines a low-level, generic | |
| | | /// interface for Unicode handling, see the sf::Utf classes. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 50 change blocks. |
| 73 lines changed or deleted | | 384 lines changed or added | |
|
| Thread.hpp | | Thread.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_THREAD_HPP | | #ifndef SFML_THREAD_HPP | |
| #define SFML_THREAD_HPP | | #define SFML_THREAD_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Config.hpp> | | #include <SFML/System/Export.hpp> | |
| | | #include <SFML/System/NonCopyable.hpp> | |
| | | #include <cstdlib> | |
| | | | |
|
| #ifdef SFML_SYSTEM_WINDOWS | | namespace sf | |
| | | { | |
| | | namespace priv | |
| | | { | |
| | | class ThreadImpl; | |
| | | struct ThreadFunc; | |
| | | } | |
| | | | |
|
| #include <SFML/System/Win32/Thread.hpp> | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Utility class to manipulate threads | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | class SFML_SYSTEM_API Thread : NonCopyable | |
| | | { | |
| | | public : | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Construct the thread from a functor with no argument | |
| | | /// | |
| | | /// This constructor works for function objects, as well | |
| | | /// as free function. | |
| | | /// | |
| | | /// Use this constructor for this kind of function: | |
| | | /// \code | |
| | | /// void function(); | |
| | | /// | |
| | | /// // --- or ---- | |
| | | /// | |
| | | /// struct Functor | |
| | | /// { | |
| | | /// void operator()(); | |
| | | /// }; | |
| | | /// \endcode | |
| | | /// Note: this does *not* run the thread, use Launch(). | |
| | | /// | |
| | | /// \param function Functor or free function to use as the entry point | |
| | | of the thread | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename F> | |
| | | Thread(F function); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Construct the thread from a functor with an argument | |
| | | /// | |
| | | /// This constructor works for function objects, as well | |
| | | /// as free function. | |
| | | /// It is a template, which means that the argument can | |
| | | /// have any type (int, std::string, void*, Toto, ...). | |
| | | /// | |
| | | /// Use this constructor for this kind of function: | |
| | | /// \code | |
| | | /// void function(int arg); | |
| | | /// | |
| | | /// // --- or ---- | |
| | | /// | |
| | | /// struct Functor | |
| | | /// { | |
| | | /// void operator()(std::string arg); | |
| | | /// }; | |
| | | /// \endcode | |
| | | /// Note: this does *not* run the thread, use Launch(). | |
| | | /// | |
| | | /// \param function Functor or free function to use as the entry point | |
| | | of the thread | |
| | | /// \param argument argument to forward to the function | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename F, typename A> | |
| | | Thread(F function, A argument); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Construct the thread from a member function and an object | |
| | | /// | |
| | | /// This constructor is template, which means that you can | |
| | | /// use it with any class. | |
| | | /// Use this constructor for this kind of function: | |
| | | /// \code | |
| | | /// class MyClass | |
| | | /// { | |
| | | /// public : | |
| | | /// | |
| | | /// void function(); | |
| | | /// }; | |
| | | /// \endcode | |
| | | /// Note: this does *not* run the thread, use Launch(). | |
| | | /// | |
| | | /// \param function Entry point of the thread | |
| | | /// \param object Pointer to the object to use | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename C> | |
| | | Thread(void(C::*function)(), C* object); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Destructor | |
| | | /// | |
| | | /// This destructor calls Wait(), so that the internal thread | |
| | | /// cannot survive after its sf::Thread instance is destroyed. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | ~Thread(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Run the thread | |
| | | /// | |
| | | /// This function starts the entry point passed to the | |
| | | /// thread's constructor, and returns immediately. | |
| | | /// After this function returns, the thread's function is | |
| | | /// running in parallel to the calling code. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void launch(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Wait until the thread finishes | |
| | | /// | |
| | | /// This function will block the execution until the | |
| | | /// thread's function ends. | |
| | | /// Warning: if the thread function never ends, the calling | |
| | | /// thread will block forever. | |
| | | /// If this function is called from its owner thread, it | |
| | | /// returns without doing anything. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void wait(); | |
| | | | |
|
| #else | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Terminate the thread | |
| | | /// | |
| | | /// This function immediately stops the thread, without waiting | |
| | | /// for its function to finish. | |
| | | /// Terminating a thread with this function is not safe, | |
| | | /// and can lead to local variables not being destroyed | |
| | | /// on some operating systems. You should rather try to make | |
| | | /// the thread function terminate by itself. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void terminate(); | |
| | | | |
|
| #include <SFML/System/Unix/Thread.hpp> | | private : | |
| | | | |
|
| #endif | | friend class priv::ThreadImpl; | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Internal entry point of the thread | |
| | | /// | |
| | | /// This function is called by the thread implementation. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void run(); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | // Member data | |
| | | //////////////////////////////////////////////////////////// | |
| | | priv::ThreadImpl* m_impl; ///< OS-specific implementation of the | |
| | | thread | |
| | | priv::ThreadFunc* m_entryPoint; ///< Abstraction of the function to run | |
| | | }; | |
| | | | |
| | | #include <SFML/System/Thread.inl> | |
| | | | |
| | | } // namespace sf | |
| | | | |
| #endif // SFML_THREAD_HPP | | #endif // SFML_THREAD_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Thread | |
| | | /// \ingroup system | |
| | | /// | |
| | | /// Threads provide a way to run multiple parts of the code | |
| | | /// in parallel. When you launch a new thread, the execution | |
| | | /// is split and both the new thread and the caller run | |
| | | /// in parallel. | |
| | | /// | |
| | | /// To use a sf::Thread, you construct it directly with the | |
| | | /// function to execute as the entry point of the thread. | |
| | | /// sf::Thread has multiple template constructors, which means | |
| | | /// that you can use several types of entry points: | |
| | | /// \li non-member functions with no argument | |
| | | /// \li non-member functions with one argument of any type | |
| | | /// \li functors with no argument (this one is particularly useful for comp | |
| | | atibility with boost/std::bind) | |
| | | /// \li functors with one argument of any type | |
| | | /// \li member functions from any class with no argument | |
| | | /// | |
| | | /// The function argument, if any, is copied in the sf::Thread | |
| | | /// instance, as well as the functor (if the corresponding | |
| | | /// constructor is used). Class instances, however, are passed | |
| | | /// by pointer so you must make sure that the object won't be | |
| | | /// destroyed while the thread is still using it. | |
| | | /// | |
| | | /// The thread ends when its function is terminated. If the | |
| | | /// owner sf::Thread instance is destroyed before the | |
| | | /// thread is finished, the destructor will wait (see wait()) | |
| | | /// | |
| | | /// Usage examples: | |
| | | /// \code | |
| | | /// // example 1: non member function with one argument | |
| | | /// | |
| | | /// void threadFunc(int argument) | |
| | | /// { | |
| | | /// ... | |
| | | /// } | |
| | | /// | |
| | | /// sf::Thread thread(&threadFunc, 5); | |
| | | /// thread.launch(); // start the thread (internally calls threadFunc(5)) | |
| | | /// \endcode | |
| | | /// | |
| | | /// \code | |
| | | /// // example 2: member function | |
| | | /// | |
| | | /// class Task | |
| | | /// { | |
| | | /// public : | |
| | | /// void run() | |
| | | /// { | |
| | | /// ... | |
| | | /// } | |
| | | /// }; | |
| | | /// | |
| | | /// Task task; | |
| | | /// sf::Thread thread(&Task::run, &task); | |
| | | /// thread.launch(); // start the thread (internally calls task.run()) | |
| | | /// \endcode | |
| | | /// | |
| | | /// \code | |
| | | /// // example 3: functor | |
| | | /// | |
| | | /// struct Task | |
| | | /// { | |
| | | /// void operator()() | |
| | | /// { | |
| | | /// ... | |
| | | /// } | |
| | | /// }; | |
| | | /// | |
| | | /// sf::Thread thread(Task()); | |
| | | /// thread.launch(); // start the thread (internally calls operator() on th | |
| | | e Task instance) | |
| | | /// \endcode | |
| | | /// | |
| | | /// Creating parallel threads of execution can be dangerous: | |
| | | /// all threads inside the same process share the same memory space, | |
| | | /// which means that you may end up accessing the same variable | |
| | | /// from multiple threads at the same time. To prevent this | |
| | | /// kind of situations, you can use mutexes (see sf::Mutex). | |
| | | /// | |
| | | /// \see sf::Mutex | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 8 change blocks. |
| 7 lines changed or deleted | | 163 lines changed or added | |
|
| Vector2.hpp | | Vector2.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_VECTOR2_HPP | | #ifndef SFML_VECTOR2_HPP | |
| #define SFML_VECTOR2_HPP | | #define SFML_VECTOR2_HPP | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Vector2 is an utility class for manipulating 2 dimensional | | /// \brief Utility template class for manipulating | |
| /// vectors. Template parameter defines the type of coordinates | | /// 2-dimensional vectors | |
| /// (integer, float, ...) | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
| class Vector2 | | class Vector2 | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// Creates a Vector2(0, 0). | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Vector2(); | | Vector2(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the vector from its coordinates | | /// \brief Construct the vector from its coordinates | |
| /// | | /// | |
|
| /// \param X : X coordinate | | /// \param X X coordinate | |
| /// \param Y : Y coordinate | | /// \param Y Y coordinate | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Vector2(T X, T Y); | | Vector2(T X, T Y); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | /// \brief Construct the vector from another type of vector | |
| | | /// | |
| | | /// This constructor doesn't replace the copy constructor, | |
| | | /// it's called only when U != T. | |
| | | /// A call to this constructor will fail to compile if U | |
| | | /// is not convertible to T. | |
| | | /// | |
| | | /// \param vector Vector to convert | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename U> | |
| | | explicit Vector2(const Vector2<U>& vector); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| T x; ///< X coordinate of the vector | | T x; ///< X coordinate of the vector | |
| T y; ///< Y coordinate of the vector | | T y; ///< Y coordinate of the vector | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; returns the opposite of a vector | | /// \relates Vector2 | |
| | | /// \brief Overload of unary operator - | |
| /// | | /// | |
|
| /// \param V : Vector to negate | | /// \param right Vector to negate | |
| /// | | /// | |
|
| /// \return -V | | /// \return Memberwise opposite of the vector | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator -(const Vector2<T>& V); | | Vector2<T> operator -(const Vector2<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator += overload ; add two vectors and assign to the first op | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator += | |
| | | /// | |
| | | /// This operator performs a memberwise addition of both vectors, | |
| | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return V1 + V2 | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2); | | Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator -= overload ; subtract two vectors and assign to the first op | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator -= | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// This operator performs a memberwise subtraction of both vectors, | |
| /// \param V2 : Second vector | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \return V1 - V2 | | /// \param left Left operand (a vector) | |
| | | /// \param right Right operand (a vector) | |
| | | /// | |
| | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2); | | Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator + overload ; adds two vectors | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator + | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return V1 + V2 | | /// \return Memberwise addition of both vectors | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2); | | Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; subtracts two vectors | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator - | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return V1 - V2 | | /// \return Memberwise subtraction of both vectors | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2); | | Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a vector by a scalar value | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator * | |
| /// | | /// | |
|
| /// \param V : Vector | | /// \param left Left operand (a vector) | |
| /// \param X : Scalar value | | /// \param right Right operand (a scalar value) | |
| /// | | /// | |
|
| /// \return V * X | | /// \return Memberwise multiplication by \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator *(const Vector2<T>& V, T X); | | Vector2<T> operator *(const Vector2<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a scalar value by a vector | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator * | |
| /// | | /// | |
|
| /// \param X : Scalar value | | /// \param left Left operand (a scalar value) | |
| /// \param V : Vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return X * V | | /// \return Memberwise multiplication by \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator *(T X, const Vector2<T>& V); | | Vector2<T> operator *(T left, const Vector2<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator *= overload ; multiply-assign a vector by a scalar value | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator *= | |
| | | /// | |
| | | /// This operator performs a memberwise multiplication by \a right, | |
| | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \param V : Vector | | /// \param left Left operand (a vector) | |
| /// \param X : Scalar value | | /// \param right Right operand (a scalar value) | |
| /// | | /// | |
|
| /// \return V * X | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator *=(Vector2<T>& V, T X); | | Vector2<T>& operator *=(Vector2<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator / overload ; divide a vector by a scalar value | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator / | |
| /// | | /// | |
|
| /// \param V : Vector | | /// \param left Left operand (a vector) | |
| /// \param X : Scalar value | | /// \param right Right operand (a scalar value) | |
| /// | | /// | |
|
| /// \return V / X | | /// \return Memberwise division by \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator /(const Vector2<T>& V, T X); | | Vector2<T> operator /(const Vector2<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator /= overload ; divide-assign a vector by a scalar value | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator /= | |
| /// | | /// | |
|
| /// \param V : Vector | | /// This operator performs a memberwise division by \a right, | |
| /// \param X : Scalar value | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \return V / X | | /// \param left Left operand (a vector) | |
| | | /// \param right Right operand (a scalar value) | |
| | | /// | |
| | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator /=(Vector2<T>& V, T X); | | Vector2<T>& operator /=(Vector2<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator == overload ; compares the equality of two vectors | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator == | |
| | | /// | |
| | | /// This operator compares strict equality between two vectors. | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return True if V1 is equal to V2 | | /// \return True if \a left is equal to \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2); | | bool operator ==(const Vector2<T>& left, const Vector2<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator != overload ; compares the difference of two vectors | | /// \relates Vector2 | |
| | | /// \brief Overload of binary operator != | |
| | | /// | |
| | | /// This operator compares strict difference between two vectors. | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return True if V1 is different than V2 | | /// \return True if \a left is not equal to \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2); | | bool operator !=(const Vector2<T>& left, const Vector2<T>& right); | |
| | | | |
| #include <SFML/System/Vector2.inl> | | #include <SFML/System/Vector2.inl> | |
| | | | |
| // Define the most common types | | // Define the most common types | |
|
| typedef Vector2<int> Vector2i; | | typedef Vector2<int> Vector2i; | |
| typedef Vector2<float> Vector2f; | | typedef Vector2<unsigned int> Vector2u; | |
| | | typedef Vector2<float> Vector2f; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_VECTOR2_HPP | | #endif // SFML_VECTOR2_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Vector2 | |
| | | /// \ingroup system | |
| | | /// | |
| | | /// sf::Vector2 is a simple class that defines a mathematical | |
| | | /// vector with two coordinates (x and y). It can be used to | |
| | | /// represent anything that has two dimensions: a size, a point, | |
| | | /// a velocity, etc. | |
| | | /// | |
| | | /// The template parameter T is the type of the coordinates. It | |
| | | /// can be any type that supports arithmetic operations (+, -, /, *) | |
| | | /// and comparisons (==, !=), for example int or float. | |
| | | /// | |
| | | /// You generally don't have to care about the templated form (sf::Vector2< | |
| | | T>), | |
| | | /// the most common specializations have special typedefs: | |
| | | /// \li sf::Vector2<float> is sf::Vector2f | |
| | | /// \li sf::Vector2<int> is sf::Vector2i | |
| | | /// \li sf::Vector2<unsigned int> is sf::Vector2u | |
| | | /// | |
| | | /// The sf::Vector2 class has a small and simple interface, its x and y mem | |
| | | bers | |
| | | /// can be accessed directly (there's no accessor like setX(), getX()) and | |
| | | it | |
| | | /// contains no mathematical function like dot product, cross product, leng | |
| | | th, etc. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// sf::Vector2f v1(16.5f, 24.f); | |
| | | /// v1.x = 18.2f; | |
| | | /// float y = v1.y; | |
| | | /// | |
| | | /// sf::Vector2f v2 = v1 * 5.f; | |
| | | /// sf::Vector2f v3; | |
| | | /// v3 = v1 + v2; | |
| | | /// | |
| | | /// bool different = (v2 != v3); | |
| | | /// \endcode | |
| | | /// | |
| | | /// Note: for 3-dimensional vectors, see sf::Vector3. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 56 change blocks. |
| 69 lines changed or deleted | | 114 lines changed or added | |
|
| Vector2.inl | | Vector2.inl | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2012 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 26 | | skipping to change at line 26 | |
| // in the product documentation would be appreciated but is not required
. | | // in the product documentation would be appreciated but is not required
. | |
| // | | // | |
| // 2. Altered source versions must be plainly marked as such, | | // 2. Altered source versions must be plainly marked as such, | |
| // and must not be misrepresented as being the original software. | | // and must not be misrepresented as being the original software. | |
| // | | // | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>::Vector2() : | | inline Vector2<T>::Vector2() : | |
| x(0), | | x(0), | |
| y(0) | | y(0) | |
| { | | { | |
| | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the color from its coordinates | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>::Vector2(T X, T Y) : | | inline Vector2<T>::Vector2(T X, T Y) : | |
| x(X), | | x(X), | |
| y(Y) | | y(Y) | |
| { | | { | |
| | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; returns the opposite of a vector | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator -(const Vector2<T>& V) | | template <typename U> | |
| | | inline Vector2<T>::Vector2(const Vector2<U>& vector) : | |
| | | x(static_cast<T>(vector.x)), | |
| | | y(static_cast<T>(vector.y)) | |
| { | | { | |
|
| return Vector2<T>(-V.x, -V.y); | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator += overload ; add two vectors and assign to the first op | | template <typename T> | |
| | | inline Vector2<T> operator -(const Vector2<T>& right) | |
| | | { | |
| | | return Vector2<T>(-right.x, -right.y); | |
| | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator +=(Vector2<T>& V1, const Vector2<T>& V2) | | inline Vector2<T>& operator +=(Vector2<T>& left, const Vector2<T>& right) | |
| { | | { | |
|
| V1.x += V2.x; | | left.x += right.x; | |
| V1.y += V2.y; | | left.y += right.y; | |
| | | | |
|
| return V1; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator -= overload ; subtract two vectors and assign to the first op | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator -=(Vector2<T>& V1, const Vector2<T>& V2) | | inline Vector2<T>& operator -=(Vector2<T>& left, const Vector2<T>& right) | |
| { | | { | |
|
| V1.x -= V2.x; | | left.x -= right.x; | |
| V1.y -= V2.y; | | left.y -= right.y; | |
| | | | |
|
| return V1; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator + overload ; adds two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator +(const Vector2<T>& V1, const Vector2<T>& V2) | | inline Vector2<T> operator +(const Vector2<T>& left, const Vector2<T>& righ
t) | |
| { | | { | |
|
| return Vector2<T>(V1.x + V2.x, V1.y + V2.y); | | return Vector2<T>(left.x + right.x, left.y + right.y); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; subtracts two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator -(const Vector2<T>& V1, const Vector2<T>& V2) | | inline Vector2<T> operator -(const Vector2<T>& left, const Vector2<T>& righ
t) | |
| { | | { | |
|
| return Vector2<T>(V1.x - V2.x, V1.y - V2.y); | | return Vector2<T>(left.x - right.x, left.y - right.y); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator *(const Vector2<T>& V, T X) | | inline Vector2<T> operator *(const Vector2<T>& left, T right) | |
| { | | { | |
|
| return Vector2<T>(V.x * X, V.y * X); | | return Vector2<T>(left.x * right, left.y * right); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a scalar value by a vector | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator *(T X, const Vector2<T>& V) | | inline Vector2<T> operator *(T left, const Vector2<T>& right) | |
| { | | { | |
|
| return Vector2<T>(V.x * X, V.y * X); | | return Vector2<T>(right.x * left, right.y * left); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator *= overload ; multiply-assign a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator *=(Vector2<T>& V, T X) | | inline Vector2<T>& operator *=(Vector2<T>& left, T right) | |
| { | | { | |
|
| V.x *= X; | | left.x *= right; | |
| V.y *= X; | | left.y *= right; | |
| | | | |
|
| return V; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator / overload ; divide a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T> operator /(const Vector2<T>& V, T X) | | inline Vector2<T> operator /(const Vector2<T>& left, T right) | |
| { | | { | |
|
| return Vector2<T>(V.x / X, V.y / X); | | return Vector2<T>(left.x / right, left.y / right); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator /= overload ; divide-assign a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector2<T>& operator /=(Vector2<T>& V, T X) | | inline Vector2<T>& operator /=(Vector2<T>& left, T right) | |
| { | | { | |
|
| V.x /= X; | | left.x /= right; | |
| V.y /= X; | | left.y /= right; | |
| | | | |
|
| return V; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator == overload ; compares the equality of two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| bool operator ==(const Vector2<T>& V1, const Vector2<T>& V2) | | inline bool operator ==(const Vector2<T>& left, const Vector2<T>& right) | |
| { | | { | |
|
| return (V1.x == V2.x) && (V1.y == V2.y); | | return (left.x == right.x) && (left.y == right.y); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator != overload ; compares the difference of two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| bool operator !=(const Vector2<T>& V1, const Vector2<T>& V2) | | inline bool operator !=(const Vector2<T>& left, const Vector2<T>& right) | |
| { | | { | |
|
| return (V1.x != V2.x) || (V1.y != V2.y); | | return (left.x != right.x) || (left.y != right.y); | |
| } | | } | |
| | | | |
End of changes. 45 change blocks. |
| 62 lines changed or deleted | | 43 lines changed or added | |
|
| Vector3.hpp | | Vector3.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_VECTOR3_HPP | | #ifndef SFML_VECTOR3_HPP | |
| #define SFML_VECTOR3_HPP | | #define SFML_VECTOR3_HPP | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Vector3 is an utility class for manipulating 3 dimensional | | /// \brief Utility template class for manipulating | |
| /// vectors. Template parameter defines the type of coordinates | | /// 3-dimensional vectors | |
| /// (integer, float, ...) | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
| class Vector3 | | class Vector3 | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// Creates a Vector3(0, 0, 0). | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Vector3(); | | Vector3(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the vector from its coordinates | | /// \brief Construct the vector from its coordinates | |
| /// | | /// | |
|
| /// \param X : X coordinate | | /// \param X X coordinate | |
| /// \param Y : Y coordinate | | /// \param Y Y coordinate | |
| /// \param Z : Z coordinate | | /// \param Z Z coordinate | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| Vector3(T X, T Y, T Z); | | Vector3(T X, T Y, T Z); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| | | /// \brief Construct the vector from another type of vector | |
| | | /// | |
| | | /// This constructor doesn't replace the copy constructor, | |
| | | /// it's called only when U != T. | |
| | | /// A call to this constructor will fail to compile if U | |
| | | /// is not convertible to T. | |
| | | /// | |
| | | /// \param vector Vector to convert | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | template <typename U> | |
| | | explicit Vector3(const Vector3<U>& vector); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| T x; ///< X coordinate of the vector | | T x; ///< X coordinate of the vector | |
| T y; ///< Y coordinate of the vector | | T y; ///< Y coordinate of the vector | |
| T z; ///< Z coordinate of the vector | | T z; ///< Z coordinate of the vector | |
| }; | | }; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; returns the opposite of a vector | | /// \relates Vector3 | |
| | | /// \brief Overload of unary operator - | |
| /// | | /// | |
|
| /// \param V : Vector to negate | | /// \param left Vector to negate | |
| /// | | /// | |
|
| /// \return -V | | /// \return Memberwise opposite of the vector | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator -(const Vector3<T>& V); | | Vector3<T> operator -(const Vector3<T>& left); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator += overload ; add two vectors and assign to the first op | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator += | |
| | | /// | |
| | | /// This operator performs a memberwise addition of both vectors, | |
| | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return V1 + V2 | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2); | | Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator -= overload ; subtract two vectors and assign to the first op | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator -= | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// This operator performs a memberwise subtraction of both vectors, | |
| /// \param V2 : Second vector | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \return V1 - V2 | | /// \param left Left operand (a vector) | |
| | | /// \param right Right operand (a vector) | |
| | | /// | |
| | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2); | | Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator + overload ; adds two vectors | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator + | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return V1 + V2 | | /// \return Memberwise addition of both vectors | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2); | | Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; subtracts two vectors | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator - | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return V1 - V2 | | /// \return Memberwise subtraction of both vectors | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2); | | Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a vector by a scalar value | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator * | |
| /// | | /// | |
|
| /// \param V : Vector | | /// \param left Left operand (a vector) | |
| /// \param X : Scalar value | | /// \param right Right operand (a scalar value) | |
| /// | | /// | |
|
| /// \return V * X | | /// \return Memberwise multiplication by \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator *(const Vector3<T>& V, T X); | | Vector3<T> operator *(const Vector3<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a scalar value by a vector | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator * | |
| /// | | /// | |
|
| /// \param X : Scalar value | | /// \param left Left operand (a scalar value) | |
| /// \param V : Vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return X * V | | /// \return Memberwise multiplication by \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator *(T X, const Vector3<T>& V); | | Vector3<T> operator *(T left, const Vector3<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator *= overload ; multiply-assign a vector by a scalar value | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator *= | |
| | | /// | |
| | | /// This operator performs a memberwise multiplication by \a right, | |
| | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \param V : Vector | | /// \param left Left operand (a vector) | |
| /// \param X : Scalar value | | /// \param right Right operand (a scalar value) | |
| /// | | /// | |
|
| /// \return V * X | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator *=(Vector3<T>& V, T X); | | Vector3<T>& operator *=(Vector3<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator / overload ; divide a vector by a scalar value | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator / | |
| /// | | /// | |
|
| /// \param V : Vector | | /// \param left Left operand (a vector) | |
| /// \param X : Scalar value | | /// \param right Right operand (a scalar value) | |
| /// | | /// | |
|
| /// \return V / X | | /// \return Memberwise division by \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator /(const Vector3<T>& V, T X); | | Vector3<T> operator /(const Vector3<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator /= overload ; divide-assign a vector by a scalar value | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator /= | |
| /// | | /// | |
|
| /// \param V : Vector | | /// This operator performs a memberwise division by \a right, | |
| /// \param X : Scalar value | | /// and assigns the result to \a left. | |
| /// | | /// | |
|
| /// \return V / X | | /// \param left Left operand (a vector) | |
| | | /// \param right Right operand (a scalar value) | |
| | | /// | |
| | | /// \return Reference to \a left | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator /=(Vector3<T>& V, T X); | | Vector3<T>& operator /=(Vector3<T>& left, T right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator == overload ; compares the equality of two vectors | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator == | |
| | | /// | |
| | | /// This operator compares strict equality between two vectors. | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return True if V1 is equal to V2 | | /// \return True if \a left is equal to \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2); | | bool operator ==(const Vector3<T>& left, const Vector3<T>& right); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator != overload ; compares the difference of two vectors | | /// \relates Vector3 | |
| | | /// \brief Overload of binary operator != | |
| | | /// | |
| | | /// This operator compares strict difference between two vectors. | |
| /// | | /// | |
|
| /// \param V1 : First vector | | /// \param left Left operand (a vector) | |
| /// \param V2 : Second vector | | /// \param right Right operand (a vector) | |
| /// | | /// | |
|
| /// \return True if V1 is different than V2 | | /// \return True if \a left is not equal to \a right | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2); | | bool operator !=(const Vector3<T>& left, const Vector3<T>& right); | |
| | | | |
| #include <SFML/System/Vector3.inl> | | #include <SFML/System/Vector3.inl> | |
| | | | |
| // Define the most common types | | // Define the most common types | |
| typedef Vector3<int> Vector3i; | | typedef Vector3<int> Vector3i; | |
| typedef Vector3<float> Vector3f; | | typedef Vector3<float> Vector3f; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_VECTOR3_HPP | | #endif // SFML_VECTOR3_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::Vector3 | |
| | | /// \ingroup system | |
| | | /// | |
| | | /// sf::Vector3 is a simple class that defines a mathematical | |
| | | /// vector with three coordinates (x, y and z). It can be used to | |
| | | /// represent anything that has three dimensions: a size, a point, | |
| | | /// a velocity, etc. | |
| | | /// | |
| | | /// The template parameter T is the type of the coordinates. It | |
| | | /// can be any type that supports arithmetic operations (+, -, /, *) | |
| | | /// and comparisons (==, !=), for example int or float. | |
| | | /// | |
| | | /// You generally don't have to care about the templated form (sf::Vector3< | |
| | | T>), | |
| | | /// the most common specializations have special typedefs: | |
| | | /// \li sf::Vector3<float> is sf::Vector3f | |
| | | /// \li sf::Vector3<int> is sf::Vector3i | |
| | | /// | |
| | | /// The sf::Vector3 class has a small and simple interface, its x and y mem | |
| | | bers | |
| | | /// can be accessed directly (there's no accessor like setX(), getX()) and | |
| | | it | |
| | | /// contains no mathematical function like dot product, cross product, leng | |
| | | th, etc. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// sf::Vector3f v1(16.5f, 24.f, -8.2f); | |
| | | /// v1.x = 18.2f; | |
| | | /// float y = v1.y; | |
| | | /// float z = v1.z; | |
| | | /// | |
| | | /// sf::Vector3f v2 = v1 * 5.f; | |
| | | /// sf::Vector3f v3; | |
| | | /// v3 = v1 + v2; | |
| | | /// | |
| | | /// bool different = (v2 != v3); | |
| | | /// \endcode | |
| | | /// | |
| | | /// Note: for 2-dimensional vectors, see sf::Vector2. | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 55 change blocks. |
| 68 lines changed or deleted | | 112 lines changed or added | |
|
| Vector3.inl | | Vector3.inl | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2012 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 26 | | skipping to change at line 26 | |
| // in the product documentation would be appreciated but is not required
. | | // in the product documentation would be appreciated but is not required
. | |
| // | | // | |
| // 2. Altered source versions must be plainly marked as such, | | // 2. Altered source versions must be plainly marked as such, | |
| // and must not be misrepresented as being the original software. | | // and must not be misrepresented as being the original software. | |
| // | | // | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>::Vector3() : | | inline Vector3<T>::Vector3() : | |
| x(0), | | x(0), | |
| y(0), | | y(0), | |
| z(0) | | z(0) | |
| { | | { | |
| | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the color from its coordinates | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>::Vector3(T X, T Y, T Z) : | | inline Vector3<T>::Vector3(T X, T Y, T Z) : | |
| x(X), | | x(X), | |
| y(Y), | | y(Y), | |
| z(Z) | | z(Z) | |
| { | | { | |
| | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; returns the opposite of a vector | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator -(const Vector3<T>& V) | | template <typename U> | |
| | | inline Vector3<T>::Vector3(const Vector3<U>& vector) : | |
| | | x(static_cast<T>(vector.x)), | |
| | | y(static_cast<T>(vector.y)), | |
| | | z(static_cast<T>(vector.z)) | |
| { | | { | |
|
| return Vector3<T>(-V.x, -V.y, -V.z); | | | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator += overload ; add two vectors and assign to the first op | | template <typename T> | |
| | | inline Vector3<T> operator -(const Vector3<T>& left) | |
| | | { | |
| | | return Vector3<T>(-left.x, -left.y, -left.z); | |
| | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator +=(Vector3<T>& V1, const Vector3<T>& V2) | | inline Vector3<T>& operator +=(Vector3<T>& left, const Vector3<T>& right) | |
| { | | { | |
|
| V1.x += V2.x; | | left.x += right.x; | |
| V1.y += V2.y; | | left.y += right.y; | |
| V1.z += V2.z; | | left.z += right.z; | |
| | | | |
|
| return V1; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator -= overload ; subtract two vectors and assign to the first op | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator -=(Vector3<T>& V1, const Vector3<T>& V2) | | inline Vector3<T>& operator -=(Vector3<T>& left, const Vector3<T>& right) | |
| { | | { | |
|
| V1.x -= V2.x; | | left.x -= right.x; | |
| V1.y -= V2.y; | | left.y -= right.y; | |
| V1.z -= V2.z; | | left.z -= right.z; | |
| | | | |
|
| return V1; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator + overload ; adds two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator +(const Vector3<T>& V1, const Vector3<T>& V2) | | inline Vector3<T> operator +(const Vector3<T>& left, const Vector3<T>& righ
t) | |
| { | | { | |
|
| return Vector3<T>(V1.x + V2.x, V1.y + V2.y, V1.z + V2.z); | | return Vector3<T>(left.x + right.x, left.y + right.y, left.z + right.z)
; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator - overload ; subtracts two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator -(const Vector3<T>& V1, const Vector3<T>& V2) | | inline Vector3<T> operator -(const Vector3<T>& left, const Vector3<T>& righ
t) | |
| { | | { | |
|
| return Vector3<T>(V1.x - V2.x, V1.y - V2.y, V1.z - V2.z); | | return Vector3<T>(left.x - right.x, left.y - right.y, left.z - right.z)
; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator *(const Vector3<T>& V, T X) | | inline Vector3<T> operator *(const Vector3<T>& left, T right) | |
| { | | { | |
|
| return Vector3<T>(V.x * X, V.y * X, V.z * X); | | return Vector3<T>(left.x * right, left.y * right, left.z * right); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator * overload ; multiply a scalar value by a vector | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator *(T X, const Vector3<T>& V) | | inline Vector3<T> operator *(T left, const Vector3<T>& right) | |
| { | | { | |
|
| return Vector3<T>(V.x * X, V.y * X, V.z * X); | | return Vector3<T>(right.x * left, right.y * left, right.z * left); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator *= overload ; multiply-assign a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator *=(Vector3<T>& V, T X) | | inline Vector3<T>& operator *=(Vector3<T>& left, T right) | |
| { | | { | |
|
| V.x *= X; | | left.x *= right; | |
| V.y *= X; | | left.y *= right; | |
| V.z *= X; | | left.z *= right; | |
| | | | |
|
| return V; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator / overload ; divide a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T> operator /(const Vector3<T>& V, T X) | | inline Vector3<T> operator /(const Vector3<T>& left, T right) | |
| { | | { | |
|
| return Vector3<T>(V.x / X, V.y / X, V.z / X); | | return Vector3<T>(left.x / right, left.y / right, left.z / right); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator /= overload ; divide-assign a vector by a scalar value | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| Vector3<T>& operator /=(Vector3<T>& V, T X) | | inline Vector3<T>& operator /=(Vector3<T>& left, T right) | |
| { | | { | |
|
| V.x /= X; | | left.x /= right; | |
| V.y /= X; | | left.y /= right; | |
| V.z /= X; | | left.z /= right; | |
| | | | |
|
| return V; | | return left; | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator == overload ; compares the equality of two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| bool operator ==(const Vector3<T>& V1, const Vector3<T>& V2) | | inline bool operator ==(const Vector3<T>& left, const Vector3<T>& right) | |
| { | | { | |
|
| return (V1.x == V2.x) && (V1.y == V2.y) && (V1.z == V2.z); | | return (left.x == right.x) && (left.y == right.y) && (left.z == right.z
); | |
| } | | } | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Operator != overload ; compares the difference of two vectors | | | |
| //////////////////////////////////////////////////////////// | | | |
| template <typename T> | | template <typename T> | |
|
| bool operator !=(const Vector3<T>& V1, const Vector3<T>& V2) | | inline bool operator !=(const Vector3<T>& left, const Vector3<T>& right) | |
| { | | { | |
|
| return (V1.x != V2.x) || (V1.y != V2.y) || (V1.z != V2.z); | | return (left.x != right.x) || (left.y != right.y) || (left.z != right.z
); | |
| } | | } | |
| | | | |
End of changes. 45 change blocks. |
| 66 lines changed or deleted | | 48 lines changed or added | |
|
| VideoMode.hpp | | VideoMode.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_VIDEOMODE_HPP | | #ifndef SFML_VIDEOMODE_HPP | |
| #define SFML_VIDEOMODE_HPP | | #define SFML_VIDEOMODE_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Config.hpp> | | #include <SFML/Window/Export.hpp> | |
| #include <cstdlib> | | #include <vector> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// VideoMode defines a video mode (width, height, bpp, frequency) | | /// \brief VideoMode defines a video mode (width, height, bpp) | |
| /// and provides static functions for getting modes supported | | /// | |
| /// by the display device | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API VideoMode | | class SFML_WINDOW_API VideoMode | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Default constructor | | /// \brief Default constructor | |
| | | /// | |
| | | /// This constructors initializes all members to 0. | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| VideoMode(); | | VideoMode(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the video mode with its attributes | | /// \brief Construct the video mode with its attributes | |
| /// | | /// | |
|
| /// \param ModeWidth : Width in pixels | | /// \param modeWidth Width in pixels | |
| /// \param ModeHeight : Height in pixels | | /// \param modeHeight Height in pixels | |
| /// \param ModeBpp : Pixel depths in bits per pixel (32 by default) | | /// \param modeBitsPerPixel Pixel depths in bits per pixel | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| VideoMode(unsigned int ModeWidth, unsigned int ModeHeight, unsigned int
ModeBpp = 32); | | VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int
modeBitsPerPixel = 32); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the current desktop video mode | | /// \brief Get the current desktop video mode | |
| /// | | /// | |
| /// \return Current desktop video mode | | /// \return Current desktop video mode | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| static VideoMode GetDesktopMode(); | | 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 r | | | |
| ange) | | | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| static VideoMode GetMode(std::size_t Index); | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get valid video modes count | | /// \brief Retrieve all the video modes supported in fullscreen mode | |
| /// | | /// | |
|
| /// \return Number of valid video modes available | | /// When creating a fullscreen window, the video mode is restricted | |
| | | /// to be compatible with what the graphics driver and monitor | |
| | | /// support. This function returns the complete list of all video | |
| | | /// modes that can be used in fullscreen mode. | |
| | | /// The returned array is sorted from best to worst, so that | |
| | | /// the first element will always give the best mode (higher | |
| | | /// width, height and bits-per-pixel). | |
| /// | | /// | |
|
| //////////////////////////////////////////////////////////// | | /// \return Array containing all the supported fullscreen modes | |
| 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; | | static const std::vector<VideoMode>& getFullscreenModes(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Comparison operator overload -- tell if two video modes are equal | | /// \brief Tell whether or not the video mode is valid | |
| /// | | /// | |
|
| /// \param Other : Video mode to compare | | /// The validity of video modes is only relevant when using | |
| | | /// fullscreen windows; otherwise any video mode can be used | |
| | | /// with no restriction. | |
| /// | | /// | |
|
| /// \return True if modes are equal | | /// \return True if the video mode is valid for fullscreen mode | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| bool operator ==(const VideoMode& Other) const; | | bool isValid() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Comparison operator overload -- tell if two video modes are differe | | | |
| nt | | | |
| /// | | | |
| /// \param Other : Video mode to compare | | | |
| /// | | | |
| /// \return True if modes are different | | | |
| /// | | | |
| //////////////////////////////////////////////////////////// | | | |
| bool operator !=(const VideoMode& Other) const; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| unsigned int Width; ///< Video mode width, in pixels | | unsigned int width; ///< Video mode width, in pixels | |
| unsigned int Height; ///< Video mode height, in pixels | | unsigned int height; ///< Video mode height, in pixels | |
| unsigned int BitsPerPixel; ///< Video mode pixel depth, in bits per pix | | unsigned int bitsPerPixel; ///< Video mode pixel depth, in bits per pix | |
| els | | els | |
| | | | |
| private : | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | | |
| /// Get and sort valid video modes | | | |
| //////////////////////////////////////////////////////////// | | | |
| static void InitializeModes(); | | | |
| }; | | }; | |
| | | | |
|
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates VideoMode | |
| | | /// \brief Overload of == operator to compare two video modes | |
| | | /// | |
| | | /// \param left Left operand (a video mode) | |
| | | /// \param right Right operand (a video mode) | |
| | | /// | |
| | | /// \return True if modes are equal | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_WINDOW_API bool operator ==(const VideoMode& left, const VideoMode& ri | |
| | | ght); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates VideoMode | |
| | | /// \brief Overload of != operator to compare two video modes | |
| | | /// | |
| | | /// \param left Left operand (a video mode) | |
| | | /// \param right Right operand (a video mode) | |
| | | /// | |
| | | /// \return True if modes are different | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_WINDOW_API bool operator !=(const VideoMode& left, const VideoMode& ri | |
| | | ght); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates VideoMode | |
| | | /// \brief Overload of < operator to compare video modes | |
| | | /// | |
| | | /// \param left Left operand (a video mode) | |
| | | /// \param right Right operand (a video mode) | |
| | | /// | |
| | | /// \return True if \a left is lesser than \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_WINDOW_API bool operator <(const VideoMode& left, const VideoMode& rig | |
| | | ht); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates VideoMode | |
| | | /// \brief Overload of > operator to compare video modes | |
| | | /// | |
| | | /// \param left Left operand (a video mode) | |
| | | /// \param right Right operand (a video mode) | |
| | | /// | |
| | | /// \return True if \a left is greater than \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_WINDOW_API bool operator >(const VideoMode& left, const VideoMode& rig | |
| | | ht); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates VideoMode | |
| | | /// \brief Overload of <= operator to compare video modes | |
| | | /// | |
| | | /// \param left Left operand (a video mode) | |
| | | /// \param right Right operand (a video mode) | |
| | | /// | |
| | | /// \return True if \a left is lesser or equal than \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_WINDOW_API bool operator <=(const VideoMode& left, const VideoMode& ri | |
| | | ght); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \relates VideoMode | |
| | | /// \brief Overload of >= operator to compare video modes | |
| | | /// | |
| | | /// \param left Left operand (a video mode) | |
| | | /// \param right Right operand (a video mode) | |
| | | /// | |
| | | /// \return True if \a left is greater or equal than \a right | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | SFML_WINDOW_API bool operator >=(const VideoMode& left, const VideoMode& ri | |
| | | ght); | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_VIDEOMODE_HPP | | #endif // SFML_VIDEOMODE_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::VideoMode | |
| | | /// \ingroup window | |
| | | /// | |
| | | /// A video mode is defined by a width and a height (in pixels) | |
| | | /// and a depth (in bits per pixel). Video modes are used to | |
| | | /// setup windows (sf::Window) at creation time. | |
| | | /// | |
| | | /// The main usage of video modes is for fullscreen mode: | |
| | | /// indeed you must use one of the valid video modes | |
| | | /// allowed by the OS (which are defined by what the monitor | |
| | | /// and the graphics card support), otherwise your window | |
| | | /// creation will just fail. | |
| | | /// | |
| | | /// sf::VideoMode provides a static function for retrieving | |
| | | /// the list of all the video modes supported by the system: | |
| | | /// getFullscreenModes(). | |
| | | /// | |
| | | /// A custom video mode can also be checked directly for | |
| | | /// fullscreen compatibility with its isValid() function. | |
| | | /// | |
| | | /// Additionnally, sf::VideoMode provides a static function | |
| | | /// to get the mode currently used by the desktop: getDesktopMode(). | |
| | | /// This allows to build windows with the same size or pixel | |
| | | /// depth as the current resolution. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// // Display the list of all the video modes available for fullscreen | |
| | | /// std::vector<sf::VideoMode> modes = sf::VideoMode::getFullscreenModes(); | |
| | | /// for (std::size_t i = 0; i < modes.size(); ++i) | |
| | | /// { | |
| | | /// sf::VideoMode mode = modes[i]; | |
| | | /// std::cout << "Mode #" << i << ": " | |
| | | /// << mode.width << "x" << mode.height << " - " | |
| | | /// << mode.bitsPerPixel << " bpp" << std::endl; | |
| | | /// } | |
| | | /// | |
| | | /// // Create a window with the same pixel depth as the desktop | |
| | | /// sf::VideoMode desktop = sf::VideoMode::getDesktopMode(); | |
| | | /// window.create(sf::VideoMode(1024, 768, desktop.bitsPerPixel), "SFML win | |
| | | dow"); | |
| | | /// \endcode | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 21 change blocks. |
| 64 lines changed or deleted | | 114 lines changed or added | |
|
| View.hpp | | View.hpp | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // | | // | |
| // SFML - Simple and Fast Multimedia Library | | // SFML - Simple and Fast Multimedia Library | |
|
| // Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) | | // Copyright (C) 2007-2013 Laurent Gomila (laurent.gom@gmail.com) | |
| // | | // | |
| // This software is provided 'as-is', without any express or implied warran
ty. | | // This software is provided 'as-is', without any express or implied warran
ty. | |
| // In no event will the authors be held liable for any damages arising from
the use of this software. | | // 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, | | // Permission is granted to anyone to use this software for any purpose, | |
| // including commercial applications, and to alter it and redistribute it f
reely, | | // including commercial applications, and to alter it and redistribute it f
reely, | |
| // subject to the following restrictions: | | // subject to the following restrictions: | |
| // | | // | |
| // 1. The origin of this software must not be misrepresented; | | // 1. The origin of this software must not be misrepresented; | |
| // you must not claim that you wrote the original software. | | // you must not claim that you wrote the original software. | |
| | | | |
| skipping to change at line 31 | | skipping to change at line 31 | |
| // 3. This notice may not be removed or altered from any source distributio
n. | | // 3. This notice may not be removed or altered from any source distributio
n. | |
| // | | // | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| | | | |
| #ifndef SFML_VIEW_HPP | | #ifndef SFML_VIEW_HPP | |
| #define SFML_VIEW_HPP | | #define SFML_VIEW_HPP | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Headers | | // Headers | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| #include <SFML/Config.hpp> | | #include <SFML/Graphics/Export.hpp> | |
| #include <SFML/Graphics/Rect.hpp> | | #include <SFML/Graphics/Rect.hpp> | |
|
| #include <SFML/Graphics/Matrix3.hpp> | | #include <SFML/Graphics/Transform.hpp> | |
| #include <SFML/System/Vector2.hpp> | | #include <SFML/System/Vector2.hpp> | |
| | | | |
| namespace sf | | namespace sf | |
| { | | { | |
|
| class RenderTarget; | | | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// This class defines a view (position, size, etc.) ; | | /// \brief 2D camera that defines what region is shown on screen | |
| /// you can consider it as a 2D camera | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| class SFML_API View | | class SFML_GRAPHICS_API View | |
| { | | { | |
| public : | | public : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the view from a rectangle | | /// \brief Default constructor | |
| /// | | /// | |
|
| /// \param ViewRect : Rectangle defining the position and size of the v
iew (1000x1000 by default) | | /// This constructor creates a default view of (0, 0, 1000, 1000) | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| explicit View(const FloatRect& ViewRect = FloatRect(0, 0, 1000, 1000)); | | View(); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Construct the view from its center and half-size | | /// \brief Construct the view from a rectangle | |
| /// | | /// | |
|
| /// \param Center : Center of the view | | /// \param rectangle Rectangle defining the zone to display | |
| /// \param HalfSize : Half-size of the view (from center to corner) | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| View(const sf::Vector2f& Center, const sf::Vector2f& HalfSize); | | explicit View(const FloatRect& rectangle); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the center of the view (take 2 values) | | /// \brief Construct the view from its center and size | |
| | | /// | |
| | | /// \param center Center of the zone to display | |
| | | /// \param size Size of zone to display | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | View(const Vector2f& center, const Vector2f& size); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Set the center of the view | |
| | | /// | |
| | | /// \param x X coordinate of the new center | |
| | | /// \param y Y coordinate of the new center | |
| /// | | /// | |
|
| /// \param X : X coordinate of the new center | | /// \see setSize, getCenter | |
| /// \param Y : Y coordinate of the new center | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetCenter(float X, float Y); | | void setCenter(float x, float y); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the center of the view (take a vector) | | /// \brief Set the center of the view | |
| /// | | /// | |
|
| /// \param Center : New center | | /// \param center New center | |
| | | /// | |
| | | /// \see setSize, getCenter | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetCenter(const sf::Vector2f& Center); | | void setCenter(const Vector2f& center); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the half-size of the view (take 2 values) | | /// \brief Set the size of the view | |
| | | /// | |
| | | /// \param width New width of the view | |
| | | /// \param height New height of the view | |
| /// | | /// | |
|
| /// \param HalfWidth : New half-width | | /// \see setCenter, getCenter | |
| /// \param HalfHeight : New half-height | | | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetHalfSize(float HalfWidth, float HalfHeight); | | void setSize(float width, float height); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Change the half-size of the view (take a vector) | | /// \brief Set the size of the view | |
| /// | | /// | |
|
| /// \param HalfSize : New half-size | | /// \param size New size | |
| | | /// | |
| | | /// \see setCenter, getCenter | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetHalfSize(const sf::Vector2f& HalfSize); | | void setSize(const Vector2f& size); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Rebuild the view from a rectangle | | /// \brief Set the orientation of the view | |
| | | /// | |
| | | /// The default rotation of a view is 0 degree. | |
| /// | | /// | |
|
| /// \param ViewRect : Rectangle defining the position and size of the v | | /// \param angle New angle, in degrees | |
| iew | | /// | |
| | | /// \see getRotation | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void SetFromRect(const FloatRect& ViewRect); | | void setRotation(float angle); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the center of the view | | /// \brief Set the target viewport | |
| | | /// | |
| | | /// The viewport is the rectangle into which the contents of the | |
| | | /// view are displayed, expressed as a factor (between 0 and 1) | |
| | | /// of the size of the RenderTarget to which the view is applied. | |
| | | /// For example, a view which takes the left side of the target would | |
| | | /// be defined with View.setViewport(sf::FloatRect(0, 0, 0.5, 1)). | |
| | | /// By default, a view has a viewport which covers the entire target. | |
| | | /// | |
| | | /// \param viewport New viewport rectangle | |
| | | /// | |
| | | /// \see getViewport | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void setViewport(const FloatRect& viewport); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Reset the view to the given rectangle | |
| | | /// | |
| | | /// Note that this function resets the rotation angle to 0. | |
| | | /// | |
| | | /// \param rectangle Rectangle defining the zone to display | |
| | | /// | |
| | | /// \see setCenter, setSize, setRotation | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void reset(const FloatRect& rectangle); | |
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Get the center of the view | |
| /// | | /// | |
| /// \return Center of the view | | /// \return Center of the view | |
| /// | | /// | |
|
| | | /// \see getSize, setCenter | |
| | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const sf::Vector2f& GetCenter() const; | | const Vector2f& getCenter() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the half-size of the view | | /// \brief Get the size of the view | |
| /// | | /// | |
|
| /// \return Half-size of the view | | /// \return Size of the view | |
| | | /// | |
| | | /// \see getCenter, setSize | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const sf::Vector2f& GetHalfSize() const; | | const Vector2f& getSize() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the bounding rectangle of the view | | /// \brief Get the current orientation of the view | |
| | | /// | |
| | | /// \return Rotation angle of the view, in degrees | |
| /// | | /// | |
|
| /// \return Bounding rectangle of the view | | /// \see setRotation | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const sf::FloatRect& GetRect() const; | | float getRotation() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Move the view (take 2 values) | | /// \brief Get the target viewport rectangle of the view | |
| /// | | /// | |
|
| /// \param OffsetX : Offset to move the view, on X axis | | /// \return Viewport rectangle, expressed as a factor of the target siz | |
| /// \param OffsetY : Offset to move the view, on Y axis | | e | |
| | | /// | |
| | | /// \see setViewport | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Move(float OffsetX, float OffsetY); | | const FloatRect& getViewport() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Move the view (take a vector) | | /// \brief Move the view relatively to its current position | |
| | | /// | |
| | | /// \param offsetX X coordinate of the move offset | |
| | | /// \param offsetY Y coordinate of the move offset | |
| /// | | /// | |
|
| /// \param Offset : Offset to move the view | | /// \see setCenter, rotate, zoom | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Move(const sf::Vector2f& Offset); | | void move(float offsetX, float offsetY); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Resize the view rectangle to simulate a zoom / unzoom effect | | /// \brief Move the view relatively to its current position | |
| /// | | /// | |
|
| /// \param Factor : Zoom factor to apply, relative to the current zoom | | /// \param offset Move offset | |
| | | /// | |
| | | /// \see setCenter, rotate, zoom | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void Zoom(float Factor); | | void move(const Vector2f& offset); | |
| | | | |
|
| private : | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Rotate the view relatively to its current orientation | |
| | | /// | |
| | | /// \param angle Angle to rotate, in degrees | |
| | | /// | |
| | | /// \see setRotation, move, zoom | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void rotate(float angle); | |
| | | | |
|
| friend class RenderTarget; | | //////////////////////////////////////////////////////////// | |
| | | /// \brief Resize the view rectangle relatively to its current size | |
| | | /// | |
| | | /// Resizing the view simulates a zoom, as the zone displayed on | |
| | | /// screen grows or shrinks. | |
| | | /// \a factor is a multiplier: | |
| | | /// \li 1 keeps the size unchanged | |
| | | /// \li > 1 makes the view bigger (objects appear smaller) | |
| | | /// \li < 1 makes the view smaller (objects appear bigger) | |
| | | /// | |
| | | /// \param factor Zoom factor to apply | |
| | | /// | |
| | | /// \see setSize, move, rotate | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | void zoom(float factor); | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Get the projection matrix of the view | | /// \brief Get the projection transform of the view | |
| | | /// | |
| | | /// This function is meant for internal use only. | |
| /// | | /// | |
|
| /// \return Projection matrix containing the view settings | | /// \return Projection transform defining the view | |
| | | /// | |
| | | /// \see getInverseTransform | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| const Matrix3& GetMatrix() const; | | const Transform& getTransform() const; | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| /// Recompute the view rectangle and the projection matrix | | /// \brief Get the inverse projection transform of the view | |
| | | /// | |
| | | /// This function is meant for internal use only. | |
| | | /// | |
| | | /// \return Inverse of the projection transform defining the view | |
| | | /// | |
| | | /// \see getTransform | |
| /// | | /// | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| void RecomputeMatrix(); | | const Transform& getInverseTransform() const; | |
| | | | |
| | | private : | |
| | | | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
| // Member data | | // Member data | |
| //////////////////////////////////////////////////////////// | | //////////////////////////////////////////////////////////// | |
|
| sf::Vector2f myCenter; ///< Center of the view | | Vector2f m_center; ///< Center of the view, in sc | |
| sf::Vector2f myHalfSize; ///< Half-size of the view | | ene coordinates | |
| FloatRect myRect; ///< Rectangle defining the bounds of the vi | | Vector2f m_size; ///< Size of the view, in scen | |
| ew | | e coordinates | |
| Matrix3 myMatrix; ///< Precomputed projection matrix correspon | | float m_rotation; ///< Angle of rotation of the | |
| ding to the view | | view rectangle, in degrees | |
| bool myNeedUpdate; ///< Internal state telling if the matrix ne | | FloatRect m_viewport; ///< Viewport rectangle, expre | |
| eds to be updated | | ssed as a factor of the render-target's size | |
| | | mutable Transform m_transform; ///< Precomputed projection tr | |
| | | ansform corresponding to the view | |
| | | mutable Transform m_inverseTransform; ///< Precomputed inverse proje | |
| | | ction transform corresponding to the view | |
| | | mutable bool m_transformUpdated; ///< Internal state telling if | |
| | | the transform needs to be updated | |
| | | mutable bool m_invTransformUpdated; ///< Internal state telling if | |
| | | the inverse transform needs to be updated | |
| }; | | }; | |
| | | | |
| } // namespace sf | | } // namespace sf | |
| | | | |
| #endif // SFML_VIEW_HPP | | #endif // SFML_VIEW_HPP | |
|
| | | | |
| | | //////////////////////////////////////////////////////////// | |
| | | /// \class sf::View | |
| | | /// \ingroup graphics | |
| | | /// | |
| | | /// sf::View defines a camera in the 2D scene. This is a | |
| | | /// very powerful concept: you can scroll, rotate or zoom | |
| | | /// the entire scene without altering the way that your | |
| | | /// drawable objects are drawn. | |
| | | /// | |
| | | /// A view is composed of a source rectangle, which defines | |
| | | /// what part of the 2D scene is shown, and a target viewport, | |
| | | /// which defines where the contents of the source rectangle | |
| | | /// will be displayed on the render target (window or texture). | |
| | | /// | |
| | | /// The viewport allows to map the scene to a custom part | |
| | | /// of the render target, and can be used for split-screen | |
| | | /// or for displaying a minimap, for example. If the source | |
| | | /// rectangle has not the same size as the viewport, its | |
| | | /// contents will be stretched to fit in. | |
| | | /// | |
| | | /// To apply a view, you have to assign it to the render target. | |
| | | /// Then, every objects drawn in this render target will be | |
| | | /// affected by the view until you use another view. | |
| | | /// | |
| | | /// Usage example: | |
| | | /// \code | |
| | | /// sf::RenderWindow window; | |
| | | /// sf::View view; | |
| | | /// | |
| | | /// // Initialize the view to a rectangle located at (100, 100) and with a | |
| | | size of 400x200 | |
| | | /// view.reset(sf::FloatRect(100, 100, 400, 200)); | |
| | | /// | |
| | | /// // Rotate it by 45 degrees | |
| | | /// view.rotate(45); | |
| | | /// | |
| | | /// // Set its target viewport to be half of the window | |
| | | /// view.setViewport(sf::FloatRect(0.f, 0.f, 0.5f, 1.f)); | |
| | | /// | |
| | | /// // Apply it | |
| | | /// window.setView(view); | |
| | | /// | |
| | | /// // Render stuff | |
| | | /// window.draw(someSprite); | |
| | | /// | |
| | | /// // Set the default view back | |
| | | /// window.setView(window.getDefaultView()); | |
| | | /// | |
| | | /// // Render stuff not affected by the view | |
| | | /// window.draw(someText); | |
| | | /// \endcode | |
| | | /// | |
| | | /// \see sf::RenderWindow, sf::RenderTexture | |
| | | /// | |
| | | //////////////////////////////////////////////////////////// | |
| | | | |
End of changes. 54 change blocks. |
| 66 lines changed or deleted | | 168 lines changed or added | |
|