From 44670984afaf9bedbdc256f0df588bd2a2223500 Mon Sep 17 00:00:00 2001 From: Laurent Gomila Date: Sun, 29 Jan 2012 11:29:09 +0100 Subject: [PATCH] Updated to the new graphics API --- doc/mainpage.hpp | 2 +- include/SFML/Audio/Music.h | 2 +- include/SFML/Audio/SoundBuffer.h | 16 +- include/SFML/Audio/SoundStream.h | 18 +- include/SFML/Graphics/BlendMode.h | 3 +- include/SFML/Graphics/CircleShape.h | 402 +++++++++++++++ include/SFML/Graphics/ConvexShape.h | 402 +++++++++++++++ include/SFML/Graphics/Glyph.h | 6 +- include/SFML/Graphics/PrimitiveType.h | 54 ++ include/SFML/Graphics/RectangleShape.h | 394 +++++++++++++++ include/SFML/Graphics/RenderStates.h | 48 ++ include/SFML/Graphics/RenderTexture.h | 195 +++++--- include/SFML/Graphics/RenderWindow.h | 314 ++++++------ include/SFML/Graphics/Shader.h | 290 ++++++++--- include/SFML/Graphics/Shape.h | 464 ----------------- include/SFML/Graphics/Sprite.h | 347 +++++-------- include/SFML/Graphics/Text.h | 371 ++++++-------- include/SFML/Graphics/Texture.h | 151 +++--- include/SFML/Graphics/Transform.h | 222 +++++++++ include/SFML/Graphics/Types.h | 5 + include/SFML/Graphics/Vertex.h | 47 ++ include/SFML/Graphics/VertexArray.h | 167 +++++++ include/SFML/Window/Window.h | 19 +- src/SFML/Audio/Music.cpp | 4 +- src/SFML/Audio/SoundBuffer.cpp | 12 +- src/SFML/Audio/SoundRecorderStruct.h | 30 +- src/SFML/Audio/SoundStream.cpp | 8 +- src/SFML/Audio/SoundStreamStruct.h | 46 +- src/SFML/Graphics/CMakeLists.txt | 20 +- src/SFML/Graphics/CircleShape.cpp | 316 ++++++++++++ src/SFML/Graphics/CircleShapeStruct.h | 48 ++ src/SFML/Graphics/ConvertRenderStates.hpp | 60 +++ src/SFML/Graphics/ConvexShape.cpp | 306 ++++++++++++ src/SFML/Graphics/ConvexShapeStruct.h | 48 ++ src/SFML/Graphics/Font.cpp | 18 +- src/SFML/Graphics/RectangleShape.cpp | 312 ++++++++++++ src/SFML/Graphics/RectangleShapeStruct.h | 48 ++ src/SFML/Graphics/RenderTexture.cpp | 156 +++--- src/SFML/Graphics/RenderWindow.cpp | 208 +++----- src/SFML/Graphics/Shader.cpp | 142 ++++-- src/SFML/Graphics/Shape.cpp | 469 ------------------ src/SFML/Graphics/Sprite.cpp | 288 +++-------- src/SFML/Graphics/SpriteStruct.h | 7 +- src/SFML/Graphics/Text.cpp | 291 +++-------- src/SFML/Graphics/TextStruct.h | 4 +- src/SFML/Graphics/Texture.cpp | 53 +- src/SFML/Graphics/Transform.cpp | 158 ++++++ .../{ShapeStruct.h => TransformStruct.h} | 14 +- src/SFML/Graphics/VertexArray.cpp | 121 +++++ src/SFML/Graphics/VertexArrayStruct.h | 43 ++ src/SFML/Window/Window.cpp | 11 +- 51 files changed, 4607 insertions(+), 2573 deletions(-) create mode 100644 include/SFML/Graphics/CircleShape.h create mode 100644 include/SFML/Graphics/ConvexShape.h create mode 100644 include/SFML/Graphics/PrimitiveType.h create mode 100644 include/SFML/Graphics/RectangleShape.h create mode 100644 include/SFML/Graphics/RenderStates.h delete mode 100644 include/SFML/Graphics/Shape.h create mode 100644 include/SFML/Graphics/Transform.h create mode 100644 include/SFML/Graphics/Vertex.h create mode 100644 include/SFML/Graphics/VertexArray.h create mode 100644 src/SFML/Graphics/CircleShape.cpp create mode 100644 src/SFML/Graphics/CircleShapeStruct.h create mode 100644 src/SFML/Graphics/ConvertRenderStates.hpp create mode 100644 src/SFML/Graphics/ConvexShape.cpp create mode 100644 src/SFML/Graphics/ConvexShapeStruct.h create mode 100644 src/SFML/Graphics/RectangleShape.cpp create mode 100644 src/SFML/Graphics/RectangleShapeStruct.h delete mode 100644 src/SFML/Graphics/Shape.cpp create mode 100644 src/SFML/Graphics/Transform.cpp rename src/SFML/Graphics/{ShapeStruct.h => TransformStruct.h} (86%) create mode 100644 src/SFML/Graphics/VertexArray.cpp create mode 100644 src/SFML/Graphics/VertexArrayStruct.h diff --git a/doc/mainpage.hpp b/doc/mainpage.hpp index 56b96b4..3968ac8 100644 --- a/doc/mainpage.hpp +++ b/doc/mainpage.hpp @@ -57,7 +57,7 @@ /// sfMusic_Play(music); /// /// /* Start the game loop */ -/// while (sfRenderWindow_IsOpened(window)) +/// while (sfRenderWindow_IsOpen(window)) /// { /// /* Process events */ /// while (sfRenderWindow_GetEvent(window, &event)) diff --git a/include/SFML/Audio/Music.h b/include/SFML/Audio/Music.h index 3e03593..f981c28 100644 --- a/include/SFML/Audio/Music.h +++ b/include/SFML/Audio/Music.h @@ -173,7 +173,7 @@ CSFML_API void sfMusic_Stop(sfMusic* music); /// \return Number of channels /// //////////////////////////////////////////////////////////// -CSFML_API unsigned int sfMusic_GetChannelsCount(const sfMusic* music); +CSFML_API unsigned int sfMusic_GetChannelCount(const sfMusic* music); //////////////////////////////////////////////////////////// /// \brief Get the sample rate of a music diff --git a/include/SFML/Audio/SoundBuffer.h b/include/SFML/Audio/SoundBuffer.h index c2a57be..c948794 100644 --- a/include/SFML/Audio/SoundBuffer.h +++ b/include/SFML/Audio/SoundBuffer.h @@ -83,15 +83,15 @@ CSFML_API sfSoundBuffer* sfSoundBuffer_CreateFromStream(sfInputStream* stream); /// The assumed format of the audio samples is 16 bits signed integer /// (sfInt16). /// -/// \param samples Pointer to the array of samples in memory -/// \param samplesCount Number of samples in the array -/// \param channelsCount Number of channels (1 = mono, 2 = stereo, ...) -/// \param sampleRate Sample rate (number of samples to play per second) +/// \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 second) /// /// \return A new sfSoundBuffer object (NULL if failed) /// //////////////////////////////////////////////////////////// -CSFML_API sfSoundBuffer* sfSoundBuffer_CreateFromSamples(const sfInt16* samples, size_t samplesCount, unsigned int channelsCount, unsigned int sampleRate); +CSFML_API sfSoundBuffer* sfSoundBuffer_CreateFromSamples(const sfInt16* samples, size_t sampleCount, unsigned int channelsCount, unsigned int sampleRate); //////////////////////////////////////////////////////////// /// \brief Create a new sound buffer by copying an existing one @@ -131,7 +131,7 @@ CSFML_API sfBool sfSoundBuffer_SaveToFile(const sfSoundBuffer* soundBuffer, cons /// /// The format of the returned samples is 16 bits signed integer /// (sfInt16). The total number of samples in this array -/// is given by the sfSoundBuffer_GetSamplesCount function. +/// is given by the sfSoundBuffer_GetSampleCount function. /// /// \param soundBuffer Sound buffer object /// @@ -151,7 +151,7 @@ CSFML_API const sfInt16* sfSoundBuffer_GetSamples(const sfSoundBuffer* soundBuff /// \return Number of samples /// //////////////////////////////////////////////////////////// -CSFML_API size_t sfSoundBuffer_GetSamplesCount(const sfSoundBuffer* soundBuffer); +CSFML_API size_t sfSoundBuffer_GetSampleCount(const sfSoundBuffer* soundBuffer); //////////////////////////////////////////////////////////// /// \brief Get the sample rate of a sound buffer @@ -178,7 +178,7 @@ CSFML_API unsigned int sfSoundBuffer_GetSampleRate(const sfSoundBuffer* soundBuf /// \return Number of channels /// //////////////////////////////////////////////////////////// -CSFML_API unsigned int sfSoundBuffer_GetChannelsCount(const sfSoundBuffer* soundBuffer); +CSFML_API unsigned int sfSoundBuffer_GetChannelCount(const sfSoundBuffer* soundBuffer); //////////////////////////////////////////////////////////// /// \brief Get the total duration of a sound buffer diff --git a/include/SFML/Audio/SoundStream.h b/include/SFML/Audio/SoundStream.h index 4228c9a..a998a20 100644 --- a/include/SFML/Audio/SoundStream.h +++ b/include/SFML/Audio/SoundStream.h @@ -39,8 +39,8 @@ //////////////////////////////////////////////////////////// typedef struct { - sfInt16* Samples; ///< Pointer to the audio samples - unsigned int NbSamples; ///< Number of samples pointed by Samples + sfInt16* Samples; ///< Pointer to the audio samples + unsigned int SampleCount; ///< Number of samples pointed by Samples } sfSoundStreamChunk; typedef sfBool (*sfSoundStreamGetDataCallback)(sfSoundStreamChunk*, void*); ///< Type of the callback used to get a sound stream data @@ -50,18 +50,18 @@ typedef void (*sfSoundStreamSeekCallback)(sfUint32, void*); ///< //////////////////////////////////////////////////////////// /// \brief Create a new sound stream /// -/// \param onGetData Function called when the stream needs more data (can't be NULL) -/// \param onSeek Function called when the stream seeks (can't be NULL) -/// \param channelsCount Number of channels to use (1 = mono, 2 = stereo) -/// \param sampleRate Sample rate of the sound (44100 = CD quality) -/// \param userData Data to pass to the callback functions +/// \param onGetData Function called when the stream needs more data (can't be NULL) +/// \param onSeek Function called when the stream seeks (can't be NULL) +/// \param channelCount Number of channels to use (1 = mono, 2 = stereo) +/// \param sampleRate Sample rate of the sound (44100 = CD quality) +/// \param userData Data to pass to the callback functions /// /// \return A new sfSoundStream object /// //////////////////////////////////////////////////////////// CSFML_API sfSoundStream* sfSoundStream_Create(sfSoundStreamGetDataCallback onGetData, sfSoundStreamSeekCallback onSeek, - unsigned int channelsCount, + unsigned int channelCount, unsigned int sampleRate, void* userData); @@ -130,7 +130,7 @@ CSFML_API sfSoundStatus sfSoundStream_GetStatus(const sfSoundStream* soundStream /// \return Number of channels /// //////////////////////////////////////////////////////////// -CSFML_API unsigned int sfSoundStream_GetChannelsCount(const sfSoundStream* soundStream); +CSFML_API unsigned int sfSoundStream_GetChannelCount(const sfSoundStream* soundStream); //////////////////////////////////////////////////////////// /// \brief Get the sample rate of a sound stream diff --git a/include/SFML/Graphics/BlendMode.h b/include/SFML/Graphics/BlendMode.h index 9c9e5ce..e3ebfc7 100644 --- a/include/SFML/Graphics/BlendMode.h +++ b/include/SFML/Graphics/BlendMode.h @@ -32,7 +32,8 @@ //////////////////////////////////////////////////////////// -/// Enumerate the blending modes for drawable objects +/// \brief Available blending modes for drawing +/// //////////////////////////////////////////////////////////// typedef enum { diff --git a/include/SFML/Graphics/CircleShape.h b/include/SFML/Graphics/CircleShape.h new file mode 100644 index 0000000..2193e0e --- /dev/null +++ b/include/SFML/Graphics/CircleShape.h @@ -0,0 +1,402 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CIRCLESHAPE_H +#define SFML_CIRCLESHAPE_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +/// \brief Create a new circle shape +/// +/// \return A new sfCircleShape object, or NULL if it failed +/// +//////////////////////////////////////////////////////////// +CSFML_API sfCircleShape* sfCircleShape_Create(void); + +//////////////////////////////////////////////////////////// +/// \brief Copy an existing circle shape +/// +/// \param shape Shape to copy +/// +/// \return Copied object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfCircleShape* sfCircleShape_Copy(sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Destroy an existing circle Shape +/// +/// \param Shape Shape to delete +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_Destroy(sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Set the position of a circle shape +/// +/// This function completely overwrites the previous position. +/// See sfCircleShape_Move to apply an offset based on the previous position instead. +/// The default position of a circle Shape object is (0, 0). +/// +/// \param shape Shape object +/// \param x X coordinate of the new position +/// \param y Y coordinate of the new position +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetPosition(sfCircleShape* shape, float x, float y); + +//////////////////////////////////////////////////////////// +/// \brief Set the orientation of a circle shape +/// +/// This function completely overwrites the previous rotation. +/// See sfCircleShape_Rotate to add an angle based on the previous rotation instead. +/// The default rotation of a circle Shape object is 0. +/// +/// \param shape Shape object +/// \param angle New rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetRotation(sfCircleShape* shape, float angle); + +//////////////////////////////////////////////////////////// +/// \brief Set the scale factors of a circle shape +/// +/// This function completely overwrites the previous scale. +/// See sfCircleShape_Scale to add a factor based on the previous scale instead. +/// The default scale of a circle Shape object is (1, 1). +/// +/// \param shape Shape object +/// \param factorX New horizontal scale factor +/// \param factorY New vertical scale factor +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetScale(sfCircleShape* shape, float factorX, float factorY); + +//////////////////////////////////////////////////////////// +/// \brief Set the local origin of a circle shape +/// +/// The origin of an object defines the center point for +/// all transformations (position, scale, rotation). +/// The coordinates of this point must be relative to the +/// top-left corner of the object, and ignore all +/// transformations (position, scale, rotation). +/// The default origin of a circle Shape object is (0, 0). +/// +/// \param shape Shape object +/// \param x X coordinate of the new origin +/// \param y Y coordinate of the new origin +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetOrigin(sfCircleShape* shape, float x, float y); + +//////////////////////////////////////////////////////////// +/// \brief Get the position of a circle shape +/// +/// \param shape Shape object +/// +/// \return Current position +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_GetPosition(const sfCircleShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Get the orientation of a circle shape +/// +/// The rotation is always in the range [0, 360]. +/// +/// \param shape Shape object +/// +/// \return Current rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfCircleShape_GetRotation(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the current scale of a circle shape +/// +/// \param shape Shape object +/// +/// \return Current scale factors +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_GetScale(const sfCircleShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Get the local origin of a circle shape +/// +/// \param shape Shape object +/// +/// \return Current origin +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_GetOrigin(const sfCircleShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Move a circle shape by a given offset +/// +/// This function adds to the current position of the object, +/// unlike sfCircleShape_SetPosition which overwrites it. +/// +/// \param shape Shape object +/// \param offsetX X offset +/// \param offsetY Y offset +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_Move(sfCircleShape* shape, float offsetX, float offsetY); + +//////////////////////////////////////////////////////////// +/// \brief Rotate a circle shape +/// +/// This function adds to the current rotation of the object, +/// unlike sfCircleShape_SetRotation which overwrites it. +/// +/// \param shape Shape object +/// \param angle Angle of rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_Rotate(sfCircleShape* shape, float angle); + +//////////////////////////////////////////////////////////// +/// \brief Scale a circle shape +/// +/// This function multiplies the current scale of the object, +/// unlike sfCircleShape_SetScale which overwrites it. +/// +/// \param shape Shape object +/// \param factorX Horizontal scale factor +/// \param factorY Vertical scale factor +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_Scale(sfCircleShape* shape, float factorX, float factorY); + +//////////////////////////////////////////////////////////// +/// \brief Get the combined transform of a circle shape +/// +/// \param shape Shape object +/// +/// \return Transform combining the position/rotation/scale/origin of the object +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTransform* sfCircleShape_GetTransform(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the inverse of the combined transform of a circle shape +/// +/// \param shape Shape object +/// +/// \return Inverse of the combined transformations applied to the object +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTransform* sfCircleShape_GetInverseTransform(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Change the source texture of a circle shape +/// +/// The \a texture argument refers to a texture that must +/// exist as long as the shape uses it. Indeed, the shape +/// 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 shape Shape object +/// \param texture New texture +/// \param resetRect Should the texture rect be reset to the size of the new texture? +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetTexture(sfCircleShape* shape, const sfTexture* texture, sfBool resetRect); + +//////////////////////////////////////////////////////////// +/// \brief Set the sub-rectangle of the texture that a circle shape will display +/// +/// 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 shape Shape object +/// \param rect Rectangle defining the region of the texture to display +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetTextureRect(sfCircleShape* shape, sfIntRect rect); + +//////////////////////////////////////////////////////////// +/// \brief Set the fill color of a circle shape +/// +/// 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 shape Shape object +/// \param color New color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetFillColor(sfCircleShape* shape, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the outline color of a circle shape +/// +/// You can use sf::Color::Transparent to disable the outline. +/// By default, the shape's outline color is opaque white. +/// +/// \param shape Shape object +/// \param color New outline color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetOutlineColor(sfCircleShape* shape, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the thickness of a circle shape's outline +/// +/// This number cannot be negative. Using zero disables +/// the outline. +/// By default, the outline thickness is 0. +/// +/// \param shape Shape object +/// \param thickness New outline thickness +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetOutlineThickness(sfCircleShape* shape, float thickness); + +//////////////////////////////////////////////////////////// +/// \brief Get the source texture of a circle 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 shape Shape object +/// +/// \return Pointer to the shape's texture +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTexture* sfCircleShape_GetTexture(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the sub-rectangle of the texture displayed by a circle shape +/// +/// \param shape Shape object +/// +/// \return Texture rectangle of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfIntRect sfCircleShape_GetTextureRect(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the fill color of a circle shape +/// +/// \param shape Shape object +/// +/// \return Fill color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfColor sfCircleShape_GetFillColor(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline color of a circle shape +/// +/// \param shape Shape object +/// +/// \return Outline color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfColor sfCircleShape_GetOutlineColor(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline thickness of a circle shape +/// +/// \param shape Shape object +/// +/// \return Outline thickness of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfCircleShape_GetOutlineThickness(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the total number of points of a circle shape +/// +/// \param shape Shape object +/// +/// \return Number of points of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API unsigned int sfCircleShape_GetPointCount(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get a point of a circle shape +/// +/// The result is undefined if \a index is out of the valid range. +/// +/// \param shape Shape object +/// \param index Index of the point to get, in range [0 .. GetPointCount() - 1] +/// +/// \return Index-th point of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_GetPoint(const sfCircleShape* shape, unsigned int index, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Set the radius of a circle +/// +/// \param shape Shape object +/// \param radius New radius of the circle +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetRadius(sfCircleShape* shape, float radius); + +//////////////////////////////////////////////////////////// +/// \brief Get the radius of a circle +/// +/// \param shape Shape object +/// +/// \return Radius of the circle +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfCircleShape_GetRadius(const sfCircleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Set the number of points of a circle +/// +/// \param shape Shape object +/// \param count New number of points of the circle +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfCircleShape_SetPointCount(sfCircleShape* shape, unsigned int count); + + +#endif // SFML_CIRCLESHAPE_H diff --git a/include/SFML/Graphics/ConvexShape.h b/include/SFML/Graphics/ConvexShape.h new file mode 100644 index 0000000..21be1df --- /dev/null +++ b/include/SFML/Graphics/ConvexShape.h @@ -0,0 +1,402 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CONVEXSHAPE_H +#define SFML_CONVEXSHAPE_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +/// \brief Create a new convex shape +/// +/// \return A new sfConvexShape object, or NULL if it failed +/// +//////////////////////////////////////////////////////////// +CSFML_API sfConvexShape* sfConvexShape_Create(void); + +//////////////////////////////////////////////////////////// +/// \brief Copy an existing convex shape +/// +/// \param shape Shape to copy +/// +/// \return Copied object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfConvexShape* sfConvexShape_Copy(sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Destroy an existing convex Shape +/// +/// \param Shape Shape to delete +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_Destroy(sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Set the position of a convex shape +/// +/// This function completely overwrites the previous position. +/// See sfConvexShape_Move to apply an offset based on the previous position instead. +/// The default position of a convex shape object is (0, 0). +/// +/// \param shape Shape object +/// \param x X coordinate of the new position +/// \param y Y coordinate of the new position +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetPosition(sfConvexShape* shape, float x, float y); + +//////////////////////////////////////////////////////////// +/// \brief Set the orientation of a convex shape +/// +/// This function completely overwrites the previous rotation. +/// See sfConvexShape_Rotate to add an angle based on the previous rotation instead. +/// The default rotation of a convex shape object is 0. +/// +/// \param shape Shape object +/// \param angle New rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetRotation(sfConvexShape* shape, float angle); + +//////////////////////////////////////////////////////////// +/// \brief Set the scale factors of a convex shape +/// +/// This function completely overwrites the previous scale. +/// See sfConvexShape_Scale to add a factor based on the previous scale instead. +/// The default scale of a convex shape object is (1, 1). +/// +/// \param shape Shape object +/// \param factorX New horizontal scale factor +/// \param factorY New vertical scale factor +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetScale(sfConvexShape* shape, float factorX, float factorY); + +//////////////////////////////////////////////////////////// +/// \brief Set the local origin of a convex shape +/// +/// The origin of an object defines the center point for +/// all transformations (position, scale, rotation). +/// The coordinates of this point must be relative to the +/// top-left corner of the object, and ignore all +/// transformations (position, scale, rotation). +/// The default origin of a convex shape object is (0, 0). +/// +/// \param shape Shape object +/// \param x X coordinate of the new origin +/// \param y Y coordinate of the new origin +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetOrigin(sfConvexShape* shape, float x, float y); + +//////////////////////////////////////////////////////////// +/// \brief Get the position of a convex shape +/// +/// \param shape Shape object +/// +/// \return Current position +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_GetPosition(const sfConvexShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Get the orientation of a convex shape +/// +/// The rotation is always in the range [0, 360]. +/// +/// \param shape Shape object +/// +/// \return Current rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfConvexShape_GetRotation(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the current scale of a convex shape +/// +/// \param shape Shape object +/// +/// \return Current scale factors +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_GetScale(const sfConvexShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Get the local origin of a convex shape +/// +/// \param shape Shape object +/// +/// \return Current origin +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_GetOrigin(const sfConvexShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Move a convex shape by a given offset +/// +/// This function adds to the current position of the object, +/// unlike sfConvexShape_SetPosition which overwrites it. +/// +/// \param shape Shape object +/// \param offsetX X offset +/// \param offsetY Y offset +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_Move(sfConvexShape* shape, float offsetX, float offsetY); + +//////////////////////////////////////////////////////////// +/// \brief Rotate a convex shape +/// +/// This function adds to the current rotation of the object, +/// unlike sfConvexShape_SetRotation which overwrites it. +/// +/// \param shape Shape object +/// \param angle Angle of rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_Rotate(sfConvexShape* shape, float angle); + +//////////////////////////////////////////////////////////// +/// \brief Scale a convex shape +/// +/// This function multiplies the current scale of the object, +/// unlike sfConvexShape_SetScale which overwrites it. +/// +/// \param shape Shape object +/// \param factorX Horizontal scale factor +/// \param factorY Vertical scale factor +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_Scale(sfConvexShape* shape, float factorX, float factorY); + +//////////////////////////////////////////////////////////// +/// \brief Get the combined transform of a convex shape +/// +/// \param shape shape object +/// +/// \return Transform combining the position/rotation/scale/origin of the object +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTransform* sfConvexShape_GetTransform(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the inverse of the combined transform of a convex shape +/// +/// \param shape shape object +/// +/// \return Inverse of the combined transformations applied to the object +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTransform* sfConvexShape_GetInverseTransform(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Change the source texture of a convex shape +/// +/// The \a texture argument refers to a texture that must +/// exist as long as the shape uses it. Indeed, the shape +/// 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 shape Shape object +/// \param texture New texture +/// \param resetRect Should the texture rect be reset to the size of the new texture? +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetTexture(sfConvexShape* shape, const sfTexture* texture, sfBool resetRect); + +//////////////////////////////////////////////////////////// +/// \brief Set the sub-rectangle of the texture that a convex shape will display +/// +/// 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 shape Shape object +/// \param rect Rectangle defining the region of the texture to display +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetTextureRect(sfConvexShape* shape, sfIntRect rect); + +//////////////////////////////////////////////////////////// +/// \brief Set the fill color of a convex shape +/// +/// 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 shape Shape object +/// \param color New color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetFillColor(sfConvexShape* shape, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the outline color of a convex shape +/// +/// You can use sf::Color::Transparent to disable the outline. +/// By default, the shape's outline color is opaque white. +/// +/// \param shape Shape object +/// \param color New outline color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetOutlineColor(sfConvexShape* shape, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the thickness of a convex shape's outline +/// +/// This number cannot be negative. Using zero disables +/// the outline. +/// By default, the outline thickness is 0. +/// +/// \param shape Shape object +/// \param thickness New outline thickness +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetOutlineThickness(sfConvexShape* shape, float thickness); + +//////////////////////////////////////////////////////////// +/// \brief Get the source texture of a convex 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 shape Shape object +/// +/// \return Pointer to the shape's texture +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTexture* sfConvexShape_GetTexture(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the sub-rectangle of the texture displayed by a convex shape +/// +/// \param shape Shape object +/// +/// \return Texture rectangle of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfIntRect sfConvexShape_GetTextureRect(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the fill color of a convex shape +/// +/// \param shape Shape object +/// +/// \return Fill color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfColor sfConvexShape_GetFillColor(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline color of a convex shape +/// +/// \param shape Shape object +/// +/// \return Outline color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfColor sfConvexShape_GetOutlineColor(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline thickness of a convex shape +/// +/// \param shape Shape object +/// +/// \return Outline thickness of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfConvexShape_GetOutlineThickness(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the total number of points of a convex shape +/// +/// \param shape Shape object +/// +/// \return Number of points of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API unsigned int sfConvexShape_GetPointCount(const sfConvexShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get a point of a convex shape +/// +/// The result is undefined if \a index is out of the valid range. +/// +/// \param shape Shape object +/// \param index Index of the point to get, in range [0 .. GetPointCount() - 1] +/// +/// \return Index-th point of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_GetPoint(const sfConvexShape* shape, unsigned int index, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Set the number of points of a convex shap +/// +/// \a count must be greater than 2 to define a valid shape. +/// +/// \param shape Shape object +/// \param count New number of points of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetPointCount(sfConvexShape* shape, unsigned int count); + +//////////////////////////////////////////////////////////// +/// \brief Set the position of a point in a convex shape +/// +/// Don't forget that the polygon must remain convex, and +/// the points need to stay ordered! +/// SetPointCount must be called first in order to set the total +/// number of points. The result is undefined if \a index is out +/// of the valid range. +/// +/// \param shape Shape object +/// \param index Index of the point to change, in range [0 .. GetPointCount() - 1] +/// \param x New X coordinate of the point +/// \param y New Y coordinate of the point +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfConvexShape_SetPoint(sfConvexShape* shape, unsigned int index, float x, float y); + + +#endif // SFML_CONVEXSHAPE_H diff --git a/include/SFML/Graphics/Glyph.h b/include/SFML/Graphics/Glyph.h index 9a556b7..8e1e0f4 100644 --- a/include/SFML/Graphics/Glyph.h +++ b/include/SFML/Graphics/Glyph.h @@ -36,9 +36,9 @@ //////////////////////////////////////////////////////////// typedef struct { - int Advance; ///< Offset to move horizontically to the next character - sfIntRect Bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline - sfIntRect SubRect; ///< Texture coordinates of the glyph inside the font's image + int Advance; ///< Offset to move horizontically to the next character + sfIntRect Bounds; ///< Bounding rectangle of the glyph, in coordinates relative to the baseline + sfIntRect TextureRect; ///< Texture coordinates of the glyph inside the font's image } sfGlyph; diff --git a/include/SFML/Graphics/PrimitiveType.h b/include/SFML/Graphics/PrimitiveType.h new file mode 100644 index 0000000..70ac84f --- /dev/null +++ b/include/SFML/Graphics/PrimitiveType.h @@ -0,0 +1,54 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_PRIMITIVETYPE_H +#define SFML_PRIMITIVETYPE_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +//////////////////////////////////////////////////////////// +/// \brief Types of primitives that a sf::VertexArray can render +/// +/// Points and lines have no area, therefore their thickness +/// will always be 1 pixel, regarldess the current transform +/// and view. +/// +//////////////////////////////////////////////////////////// +typedef enum +{ + sfPoints, ///< List of individual points + sfLines, ///< List of individual lines + sfLinesStrip, ///< List of connected lines, a point uses the previous point to form a line + sfTriangles, ///< List of individual triangles + sfTrianglesStrip, ///< List of connected triangles, a point uses the two previous points to form a triangle + sfTrianglesFan, ///< List of connected triangles, a point uses the common center and the previous point to form a triangle + sfQuads ///< List of individual quads +} sfPrimitiveType; + + +#endif // SFML_BLENDMODE_H diff --git a/include/SFML/Graphics/RectangleShape.h b/include/SFML/Graphics/RectangleShape.h new file mode 100644 index 0000000..193ef4f --- /dev/null +++ b/include/SFML/Graphics/RectangleShape.h @@ -0,0 +1,394 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_RECTANGLESHAPE_H +#define SFML_RECTANGLESHAPE_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +/// \brief Create a new rectangle shape +/// +/// \return A new sfRectangleShape object, or NULL if it failed +/// +//////////////////////////////////////////////////////////// +CSFML_API sfRectangleShape* sfRectangleShape_Create(void); + +//////////////////////////////////////////////////////////// +/// \brief Copy an existing rectangle shape +/// +/// \param shape Shape to copy +/// +/// \return Copied object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfRectangleShape* sfRectangleShape_Copy(sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Destroy an existing rectangle Shape +/// +/// \param Shape Shape to delete +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_Destroy(sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Set the position of a rectangle shape +/// +/// This function completely overwrites the previous position. +/// See sfRectangleShape_Move to apply an offset based on the previous position instead. +/// The default position of a rectangle shape object is (0, 0). +/// +/// \param shape Shape object +/// \param x X coordinate of the new position +/// \param y Y coordinate of the new position +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetPosition(sfRectangleShape* shape, float x, float y); + +//////////////////////////////////////////////////////////// +/// \brief Set the orientation of a rectangle shape +/// +/// This function completely overwrites the previous rotation. +/// See sfRectangleShape_Rotate to add an angle based on the previous rotation instead. +/// The default rotation of a rectangle shape object is 0. +/// +/// \param shape Shape object +/// \param angle New rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetRotation(sfRectangleShape* shape, float angle); + +//////////////////////////////////////////////////////////// +/// \brief Set the scale factors of a rectangle shape +/// +/// This function completely overwrites the previous scale. +/// See sfRectangleShape_Scale to add a factor based on the previous scale instead. +/// The default scale of a rectangle shape object is (1, 1). +/// +/// \param shape Shape object +/// \param factorX New horizontal scale factor +/// \param factorY New vertical scale factor +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetScale(sfRectangleShape* shape, float factorX, float factorY); + +//////////////////////////////////////////////////////////// +/// \brief Set the local origin of a rectangle shape +/// +/// The origin of an object defines the center point for +/// all transformations (position, scale, rotation). +/// The coordinates of this point must be relative to the +/// top-left corner of the object, and ignore all +/// transformations (position, scale, rotation). +/// The default origin of a rectangle shape object is (0, 0). +/// +/// \param shape Shape object +/// \param x X coordinate of the new origin +/// \param y Y coordinate of the new origin +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetOrigin(sfRectangleShape* shape, float x, float y); + +//////////////////////////////////////////////////////////// +/// \brief Get the position of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Current position +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_GetPosition(const sfRectangleShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Get the orientation of a rectangle shape +/// +/// The rotation is always in the range [0, 360]. +/// +/// \param shape Shape object +/// +/// \return Current rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfRectangleShape_GetRotation(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the current scale of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Current scale factors +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_GetScale(const sfRectangleShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Get the local origin of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Current origin +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_GetOrigin(const sfRectangleShape* shape, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Move a rectangle shape by a given offset +/// +/// This function adds to the current position of the object, +/// unlike sfRectangleShape_SetPosition which overwrites it. +/// +/// \param shape Shape object +/// \param offsetX X offset +/// \param offsetY Y offset +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_Move(sfRectangleShape* shape, float offsetX, float offsetY); + +//////////////////////////////////////////////////////////// +/// \brief Rotate a rectangle shape +/// +/// This function adds to the current rotation of the object, +/// unlike sfRectangleShape_SetRotation which overwrites it. +/// +/// \param shape Shape object +/// \param angle Angle of rotation, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_Rotate(sfRectangleShape* shape, float angle); + +//////////////////////////////////////////////////////////// +/// \brief Scale a rectangle shape +/// +/// This function multiplies the current scale of the object, +/// unlike sfRectangleShape_SetScale which overwrites it. +/// +/// \param shape Shape object +/// \param factorX Horizontal scale factor +/// \param factorY Vertical scale factor +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_Scale(sfRectangleShape* shape, float factorX, float factorY); + +//////////////////////////////////////////////////////////// +/// \brief Get the combined transform of a rectangle shape +/// +/// \param shape shape object +/// +/// \return Transform combining the position/rotation/scale/origin of the object +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTransform* sfRectangleShape_GetTransform(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the inverse of the combined transform of a rectangle shape +/// +/// \param shape shape object +/// +/// \return Inverse of the combined transformations applied to the object +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTransform* sfRectangleShape_GetInverseTransform(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Change the source texture of a rectangle shape +/// +/// The \a texture argument refers to a texture that must +/// exist as long as the shape uses it. Indeed, the shape +/// 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 shape Shape object +/// \param texture New texture +/// \param resetRect Should the texture rect be reset to the size of the new texture? +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetTexture(sfRectangleShape* shape, const sfTexture* texture, sfBool resetRect); + +//////////////////////////////////////////////////////////// +/// \brief Set the sub-rectangle of the texture that a rectangle shape will display +/// +/// 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 shape Shape object +/// \param rect Rectangle defining the region of the texture to display +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetTextureRect(sfRectangleShape* shape, sfIntRect rect); + +//////////////////////////////////////////////////////////// +/// \brief Set the fill color of a rectangle shape +/// +/// 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 shape Shape object +/// \param color New color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetFillColor(sfRectangleShape* shape, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the outline color of a rectangle shape +/// +/// You can use sf::Color::Transparent to disable the outline. +/// By default, the shape's outline color is opaque white. +/// +/// \param shape Shape object +/// \param color New outline color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetOutlineColor(sfRectangleShape* shape, sfColor color); + +//////////////////////////////////////////////////////////// +/// \brief Set the thickness of a rectangle shape's outline +/// +/// This number cannot be negative. Using zero disables +/// the outline. +/// By default, the outline thickness is 0. +/// +/// \param shape Shape object +/// \param thickness New outline thickness +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetOutlineThickness(sfRectangleShape* shape, float thickness); + +//////////////////////////////////////////////////////////// +/// \brief Get the source texture of a rectangle 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 shape Shape object +/// +/// \return Pointer to the shape's texture +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTexture* sfRectangleShape_GetTexture(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the sub-rectangle of the texture displayed by a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Texture rectangle of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfIntRect sfRectangleShape_GetTextureRect(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the fill color of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Fill color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfColor sfRectangleShape_GetFillColor(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline color of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Outline color of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API sfColor sfRectangleShape_GetOutlineColor(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the outline thickness of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Outline thickness of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API float sfRectangleShape_GetOutlineThickness(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get the total number of points of a rectangle shape +/// +/// \param shape Shape object +/// +/// \return Number of points of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API unsigned int sfRectangleShape_GetPointCount(const sfRectangleShape* shape); + +//////////////////////////////////////////////////////////// +/// \brief Get a point of a rectangle shape +/// +/// The result is undefined if \a index is out of the valid range. +/// +/// \param shape Shape object +/// \param index Index of the point to get, in range [0 .. GetPointCount() - 1] +/// +/// \return Index-th point of the shape +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_GetPoint(const sfRectangleShape* shape, unsigned int index, float* x, float* y); + +//////////////////////////////////////////////////////////// +/// \brief Set the size of a rectangle shape +/// +/// \param shape Shape object +/// \param width New width of the rectangle +/// \param height New height of the rectangle +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_SetSize(sfRectangleShape* shape, float width, float height); + +//////////////////////////////////////////////////////////// +/// \brief Get the size of a rectangle shape +/// +/// \param shape Shape object +/// \param width Returned width of the rectangle +/// \param height Returned height of the rectangle +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRectangleShape_GetSize(const sfRectangleShape* shape, float* width, float* height); + + +#endif // SFML_RECTANGLESHAPE_H diff --git a/include/SFML/Graphics/RenderStates.h b/include/SFML/Graphics/RenderStates.h new file mode 100644 index 0000000..90bf8a6 --- /dev/null +++ b/include/SFML/Graphics/RenderStates.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_RENDERSTATES_H +#define SFML_RENDERSTATES_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +//////////////////////////////////////////////////////////// +/// \brief Define the states used for drawing to a RenderTarget +/// +//////////////////////////////////////////////////////////// +typedef struct +{ + sfBlendMode BlendMode; ///< Blending mode + sfTransform* Transform; ///< Transform + const sfTexture* Texture; ///< Texture + const sfShader* Shader; ///< Shader +} sfRenderStates; + + +#endif // SFML_RENDERSTATES_H diff --git a/include/SFML/Graphics/RenderTexture.h b/include/SFML/Graphics/RenderTexture.h index 28d3c90..02109e5 100644 --- a/include/SFML/Graphics/RenderTexture.h +++ b/include/SFML/Graphics/RenderTexture.h @@ -32,30 +32,35 @@ #include #include #include +#include +#include +#include //////////////////////////////////////////////////////////// -/// Construct a new rendertexture +/// \brief Construct a new render texture /// -/// \param width : Width of the rendertexture -/// \param height : Height of the rendertexture -/// \param depthBuffer : Do you want a depth-buffer attached? (useful only if you're doing 3D OpenGL on the rendertexture) +/// \param width Width of the render texture +/// \param height Height of the render texture +/// \param depthBuffer Do you want a depth-buffer attached? (useful only if you're doing 3D OpenGL on the rendertexture) +/// +/// \return A new sfRenderTexture object, or NULL if it failed /// //////////////////////////////////////////////////////////// CSFML_API sfRenderTexture* sfRenderTexture_Create(unsigned int width, unsigned int height, sfBool depthBuffer); //////////////////////////////////////////////////////////// -/// Destroy an existing rendertexture +/// \brief Destroy an existing render texture /// -/// \param renderTexture : rendertexture to destroy +/// \param renderTexture Render texture to destroy /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderTexture_Destroy(sfRenderTexture* renderTexture); //////////////////////////////////////////////////////////// -/// Get the width of the rendering region of a rendertexture +/// \brief Get the width of the rendering region of a render texture /// -/// \param renderTexture : Rendertexture object +/// \param renderTexture Render texture object /// /// \return Width in pixels /// @@ -63,9 +68,9 @@ CSFML_API void sfRenderTexture_Destroy(sfRenderTexture* renderTexture); CSFML_API unsigned int sfRenderTexture_GetWidth(const sfRenderTexture* renderTexture); //////////////////////////////////////////////////////////// -/// Get the height of the rendering region of a rendertexture +/// \brief Get the height of the rendering region of a render texture /// -/// \param renderTexture : Rendertexture object +/// \param renderTexture Render texture object /// /// \return Height in pixels /// @@ -73,10 +78,10 @@ CSFML_API unsigned int sfRenderTexture_GetWidth(const sfRenderTexture* renderTex CSFML_API unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTexture); //////////////////////////////////////////////////////////// -/// Activate or deactivate a rendertexture as the current target for rendering +/// \brief Activate or deactivate a render texture as the current target for rendering /// -/// \param renderTexture : Rendertexture object -/// \param active : sfTrue to activate, sfFalse to deactivate +/// \param renderTexture Render texture object +/// \param active sfTrue to activate, sfFalse to deactivate /// /// \return True if operation was successful, false otherwise /// @@ -84,74 +89,35 @@ CSFML_API unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTe CSFML_API sfBool sfRenderTexture_SetActive(sfRenderTexture* renderTexture, sfBool active); //////////////////////////////////////////////////////////// -/// Save the current OpenGL render states and matrices +/// \brief Update the contents of the target texture /// -/// \param renderWindow : Renderwindow object -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderTexture_SaveGLStates(sfRenderTexture* renderTexture); - -//////////////////////////////////////////////////////////// -/// Restore the previously saved OpenGL render states and matrices -/// -/// \param renderWindow : Renderwindow object -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderTexture_RestoreGLStates(sfRenderTexture* renderTexture); - -//////////////////////////////////////////////////////////// -/// Update the contents of the target texture -/// -/// \param renderTexture : Rendertexture object +/// \param renderTexture Render texture object /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderTexture_Display(sfRenderTexture* renderTexture); //////////////////////////////////////////////////////////// -/// Draw something on a rendertexture +/// \brief Clear the rendertexture with the given color /// -/// \param renderTexture : Rendertexture to draw in -/// \param sprite / text / shape : Object to draw -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* sprite); -CSFML_API void sfRenderTexture_DrawShape (sfRenderTexture* renderTexture, const sfShape* shape); -CSFML_API void sfRenderTexture_DrawText (sfRenderTexture* renderTexture, const sfText* text); - -//////////////////////////////////////////////////////////// -/// Draw something on a rendertexture with a shader -/// -/// \param renderTexture : Rendertexture to draw in -/// \param sprite / text / shape : Object to draw -/// \param shader : Shader to use -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderTexture_DrawSpriteWithShader(sfRenderTexture* renderTexture, const sfSprite* sprite, const sfShader* shader); -CSFML_API void sfRenderTexture_DrawShapeWithShader (sfRenderTexture* renderTexture, const sfShape* shape, const sfShader* shader); -CSFML_API void sfRenderTexture_DrawTextWithShader (sfRenderTexture* renderTexture, const sfText* text, const sfShader* shader); - -//////////////////////////////////////////////////////////// -/// Clear the rendertexture with the given color -/// -/// \param renderTexture : Rendertexture to modify -/// \param color : Fill color +/// \param renderTexture Render texture object +/// \param color Fill color /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderTexture_Clear(sfRenderTexture* renderTexture, sfColor color); //////////////////////////////////////////////////////////// -/// Change the current active view of a rendertexture +/// \brief Change the current active view of a render texture /// -/// \param renderTexture : Rendertexture to modify -/// \param view : Pointer to the new view +/// \param renderTexture Render texture object +/// \param view Pointer to the new view /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderTexture_SetView(sfRenderTexture* renderTexture, const sfView* view); //////////////////////////////////////////////////////////// -/// Get the current active view of a rendertexture +/// \brief Get the current active view of a render texture /// -/// \param renderTexture : Rendertexture +/// \param renderTexture Render texture object /// /// \return Current active view /// @@ -159,9 +125,9 @@ CSFML_API void sfRenderTexture_SetView(sfRenderTexture* renderTexture, const sfV CSFML_API const sfView* sfRenderTexture_GetView(const sfRenderTexture* renderTexture); //////////////////////////////////////////////////////////// -/// Get the default view of a rendertexture +/// \brief Get the default view of a render texture /// -/// \param renderTexture : Rendertexture +/// \param renderTexture Render texture object /// /// \return Default view of the rendertexture /// @@ -169,10 +135,10 @@ CSFML_API const sfView* sfRenderTexture_GetView(const sfRenderTexture* renderTex CSFML_API const sfView* sfRenderTexture_GetDefaultView(const sfRenderTexture* renderTexture); //////////////////////////////////////////////////////////// -/// Get the viewport of a view applied to this target +/// \brief Get the viewport of a view applied to this target /// -/// \param renderTexture : Rendertexture object -/// \param view : Target view +/// \param renderTexture Render texture object +/// \param view Target view /// /// \return Viewport rectangle, expressed in pixels in the current target /// @@ -180,22 +146,99 @@ CSFML_API const sfView* sfRenderTexture_GetDefaultView(const sfRenderTexture* re CSFML_API sfIntRect sfRenderTexture_GetViewport(const sfRenderTexture* renderTexture, const sfView* view); //////////////////////////////////////////////////////////// -/// Convert a point in texture coordinates into view coordinates +/// \brief Convert a point in texture coordinates into view coordinates /// -/// \param renderTexture : Rendertexture object -/// \param windowX : X coordinate of the point to convert, relative to the texture -/// \param windowY : Y coordinate of the point to convert, relative to the texture -/// \param viewX : Pointer to fill with the X coordinate of the converted point -/// \param viewY : Pointer to fill with the Y coordinate of the converted point -/// \param targetView : Target view to convert the point to (pass NULL to use the current view) +/// \param renderTexture Render texture object +/// \param windowX X coordinate of the point to convert, relative to the texture +/// \param windowY Y coordinate of the point to convert, relative to the texture +/// \param viewX Pointer to fill with the X coordinate of the converted point +/// \param viewY Pointer to fill with the Y coordinate of the converted point +/// \param targetView Target view to convert the point to (pass NULL to use the current view) /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderTexture_ConvertCoords(const sfRenderTexture* renderTexture, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView); //////////////////////////////////////////////////////////// -/// Get the target texture +/// \brief Draw a drawable object to the render-target /// -/// \param renderTexture : Render-texture object +/// \param renderTexture Render texture object +/// \param object Object to draw +/// \param states Render states to use for drawing (NULL to use the default states) +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* object, const sfRenderStates* states); +CSFML_API void sfRenderTexture_DrawText(sfRenderTexture* renderTexture, const sfText* object, const sfRenderStates* states); +CSFML_API void sfRenderTexture_DrawCircleShape(sfRenderTexture* renderTexture, const sfCircleShape* object, const sfRenderStates* states); +CSFML_API void sfRenderTexture_DrawConvexShape(sfRenderTexture* renderTexture, const sfConvexShape* object, const sfRenderStates* states); +CSFML_API void sfRenderTexture_DrawRectangleShape(sfRenderTexture* renderTexture, const sfRectangleShape* object, const sfRenderStates* states); +CSFML_API void sfRenderTexture_DrawVertexArray(sfRenderTexture* renderTexture, const sfVertexArray* object, const sfRenderStates* states); + +//////////////////////////////////////////////////////////// +/// \brief Draw primitives defined by an array of vertices to a render texture +/// +/// \param renderTexture Render texture object +/// \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 (NULL to use the default states) +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_DrawPrimitives(sfRenderTexture* renderTexture, + const sfVertex* vertices, unsigned int vertexCount, + sfPrimitiveType type, const sfRenderStates* states); + +//////////////////////////////////////////////////////////// +/// \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 function +/// +/// 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. +/// +/// \param renderTexture Render texture object +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_PushGLStates(sfRenderTexture* renderTexture); + +//////////////////////////////////////////////////////////// +/// \brief Restore the previously saved OpenGL render states and matrices +/// +/// See the description of PushGLStates to get a detailed +/// description of these functions. +/// +/// \param renderTexture Render texture object +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_PopGLStates(sfRenderTexture* renderTexture); + +//////////////////////////////////////////////////////////// +/// \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 sfRenderTexture_Draw*() +/// calls will work as expected. +/// +/// \param renderTexture Render texture object +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_ResetGLStates(sfRenderTexture* renderTexture); + +//////////////////////////////////////////////////////////// +/// \brief Get the target texture of a render texture +/// +/// \param renderTexture Render texture object /// /// \return Pointer to the target texture /// diff --git a/include/SFML/Graphics/RenderWindow.h b/include/SFML/Graphics/RenderWindow.h index 610da61..33b2879 100644 --- a/include/SFML/Graphics/RenderWindow.h +++ b/include/SFML/Graphics/RenderWindow.h @@ -32,6 +32,9 @@ #include #include #include +#include +#include +#include #include #include #include @@ -39,53 +42,53 @@ //////////////////////////////////////////////////////////// -/// Construct a new renderwindow +/// \brief Construct a new render window /// -/// \param mode : Video mode to use -/// \param title : Title of the window -/// \param style : Window style -/// \param settings : Creation settings (pass NULL to use default values) +/// \param mode Video mode to use +/// \param title Title of the window +/// \param style Window style +/// \param settings Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// CSFML_API sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, sfUint32 style, const sfContextSettings* settings); //////////////////////////////////////////////////////////// -/// Construct a renderwindow from an existing control +/// \brief Construct a render window from an existing control /// -/// \param handle : Platform-specific handle of the control -/// \param settings : Creation settings (pass NULL to use default values) +/// \param handle Platform-specific handle of the control +/// \param settings Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// CSFML_API sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, const sfContextSettings* settings); //////////////////////////////////////////////////////////// -/// Destroy an existing renderwindow +/// \brief Destroy an existing render window /// -/// \param renderWindow : Renderwindow to destroy +/// \param renderWindow Render window to destroy /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_Destroy(sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Close a renderwindow (but doesn't destroy the internal data) +/// \brief Close a render window (but doesn't destroy the internal data) /// -/// \param renderWindow : Renderwindow to close +/// \param renderWindow Render window to close /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_Close(sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Tell whether or not a renderwindow is opened +/// \brief Tell whether or not a render window is opened /// -/// \param renderWindow : Renderwindow object +/// \param renderWindow Render window object /// //////////////////////////////////////////////////////////// -CSFML_API sfBool sfRenderWindow_IsOpened(const sfRenderWindow* renderWindow); +CSFML_API sfBool sfRenderWindow_IsOpen(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Get the width of the rendering region of a window +/// \brief Get the width of the rendering region of a render window /// -/// \param renderWindow : Renderwindow object +/// \param renderWindow Render window object /// /// \return Width in pixels /// @@ -93,9 +96,9 @@ CSFML_API sfBool sfRenderWindow_IsOpened(const sfRenderWindow* renderWindow); CSFML_API unsigned int sfRenderWindow_GetWidth(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Get the height of the rendering region of a window +/// \brief Get the height of the rendering region of a render window /// -/// \param renderWindow : Renderwindow object +/// \param renderWindow Render window object /// /// \return Height in pixels /// @@ -103,9 +106,9 @@ CSFML_API unsigned int sfRenderWindow_GetWidth(const sfRenderWindow* renderWindo CSFML_API unsigned int sfRenderWindow_GetHeight(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Get the creation settings of a window +/// \brief Get the creation settings of a render window /// -/// \param renderWindow : Renderwindow object +/// \param renderWindow Render window object /// /// \return Settings used to create the window /// @@ -113,10 +116,10 @@ CSFML_API unsigned int sfRenderWindow_GetHeight(const sfRenderWindow* renderWind CSFML_API sfContextSettings sfRenderWindow_GetSettings(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Get the event on top of events stack of a window, if any, and pop it +/// \brief Get the event on top of events stack of a render window, if any, and pop it /// -/// \param renderWindow : Renderwindow object -/// \param event : Event to fill, if any +/// \param renderWindow Render window object +/// \param event Event to fill, if any /// /// \return sfTrue if an event was returned, sfFalse if events stack was empty /// @@ -124,10 +127,10 @@ CSFML_API sfContextSettings sfRenderWindow_GetSettings(const sfRenderWindow* ren CSFML_API sfBool sfRenderWindow_PollEvent(sfRenderWindow* renderWindow, sfEvent* event); //////////////////////////////////////////////////////////// -/// Wait for an event and return it +/// \brief Wait for an event and return it /// -/// \param renderWindow : Renderwindow object -/// \param event : Event to fill +/// \param renderWindow Render window object +/// \param event Event to fill /// /// \return sfFalse if an error occured /// @@ -135,88 +138,90 @@ CSFML_API sfBool sfRenderWindow_PollEvent(sfRenderWindow* renderWindow, sfEvent* CSFML_API sfBool sfRenderWindow_WaitEvent(sfRenderWindow* renderWindow, sfEvent* event); //////////////////////////////////////////////////////////// -/// Enable / disable vertical synchronization on a window +/// \brief Enable / disable vertical synchronization on a render window /// -/// \param renderWindow : Renderwindow object -/// \param enabled : sfTrue to enable v-sync, sfFalse to deactivate +/// \param renderWindow Render window object +/// \param enabled sfTrue to enable v-sync, sfFalse to deactivate /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_EnableVerticalSync(sfRenderWindow* renderWindow, sfBool enabled); //////////////////////////////////////////////////////////// -/// Show or hide the mouse cursor on a window +/// \brief Show or hide the mouse cursor on a render window /// -/// \param renderWindow : RenderWindow object -/// \param show : sfTrue to show, sfFalse to hide +/// \param renderWindow Render window object +/// \param show sfTrue to show, sfFalse to hide /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_ShowMouseCursor(sfRenderWindow* renderWindow, sfBool show); //////////////////////////////////////////////////////////// -/// Change the position of a window on screen. +/// \brief Change the position of a render window on screen +/// /// Only works for top-level windows /// -/// \param renderWindow : Renderwindow object -/// \param left : Left position -/// \param top : Top position +/// \param renderWindow Render window object +/// \param left Left position +/// \param top Top position /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_SetPosition(sfRenderWindow* renderWindow, int left, int top); //////////////////////////////////////////////////////////// -/// Change the size of the rendering region of a window +/// \brief Change the size of the rendering region of a render window /// -/// \param renderWindow : Renderwindow object -/// \param width : New Width -/// \param height : New Height +/// \param renderWindow Render window object +/// \param width New Width +/// \param height New Height /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_SetSize(sfRenderWindow* renderWindow, unsigned int width, unsigned int height); //////////////////////////////////////////////////////////// -/// Change the title of a window +/// \brief Change the title of a render window /// -/// \param renderWindow : Renderwindow object -/// \param title : New title +/// \param renderWindow Render window object +/// \param title New title /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_SetTitle(sfRenderWindow* renderWindow, const char* title); //////////////////////////////////////////////////////////// -/// Show or hide a window +/// \brief Show or hide a render window /// -/// \param renderWindow : Renderwindow object -/// \param show : sfTrue to show, sfFalse to hide +/// \param renderWindow Render window object +/// \param show sfTrue to show, sfFalse to hide /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_Show(sfRenderWindow* renderWindow, sfBool show); //////////////////////////////////////////////////////////// -/// Enable or disable automatic key-repeat for keydown events. +/// \brief Enable or disable automatic key-repeat for keydown events +/// /// Automatic key-repeat is enabled by default /// -/// \param renderWindow : Renderwindow object -/// \param enabled : sfTrue to enable, sfFalse to disable +/// \param renderWindow Render window object +/// \param enabled sfTrue to enable, sfFalse to disable /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_EnableKeyRepeat(sfRenderWindow* renderWindow, sfBool enabled); //////////////////////////////////////////////////////////// -/// Change the window's icon +/// \brief Change a render window's icon /// -/// \param renderWindow : Renderwindow object -/// \param width : Icon's width, in pixels -/// \param height : Icon's height, in pixels -/// \param pixels : Pointer to the pixels in memory, format must be RGBA 32 bits +/// \param renderWindow Renderw indow object +/// \param width Icon's width, in pixels +/// \param height Icon's height, in pixels +/// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_SetIcon(sfRenderWindow* renderWindow, unsigned int width, unsigned int height, const sfUint8* pixels); //////////////////////////////////////////////////////////// -/// Activate or deactivate a window as the current target for rendering +/// \brief Activate or deactivate a render window as the current target for rendering /// -/// \param renderWindow : Renderwindow object -/// \param active : sfTrue to activate, sfFalse to deactivate +/// \param renderWindow Render window object +/// \param active sfTrue to activate, sfFalse to deactivate /// /// \return True if operation was successful, false otherwise /// @@ -224,62 +229,35 @@ CSFML_API void sfRenderWindow_SetIcon(sfRenderWindow* renderWindow, unsigned int CSFML_API sfBool sfRenderWindow_SetActive(sfRenderWindow* renderWindow, sfBool active); //////////////////////////////////////////////////////////// -/// Save the current OpenGL render states and matrices +/// \brief Display a render window on screen /// -/// \param renderWindow : Renderwindow object -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderWindow_SaveGLStates(sfRenderWindow* renderWindow); - -//////////////////////////////////////////////////////////// -/// Restore the previously saved OpenGL render states and matrices -/// -/// \param renderWindow : Renderwindow object -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderWindow_RestoreGLStates(sfRenderWindow* renderWindow); - -//////////////////////////////////////////////////////////// -/// Display a window on screen -/// -/// \param renderWindow : Renderwindow object +/// \param renderWindow Render window object /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_Display(sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Limit the framerate to a maximum fixed frequency for a window +/// \brief Limit the framerate to a maximum fixed frequency for a render window /// -/// \param renderWindow : Renderwindow object -/// \param limit : Framerate limit, in frames per seconds (use 0 to disable limit) +/// \param renderWindow Render window object +/// \param limit Framerate limit, in frames per seconds (use 0 to disable limit) /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_SetFramerateLimit(sfRenderWindow* renderWindow, unsigned int limit); //////////////////////////////////////////////////////////// -/// Get time elapsed since last frame of a window +/// \brief Change the joystick threshold, ie. the value below which no move event will be generated /// -/// \param renderWindow : Renderwindow object -/// -/// \return Time elapsed, in milliseconds -/// -//////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow); - -//////////////////////////////////////////////////////////// -/// Change the joystick threshold, ie. the value below which -/// no move event will be generated -/// -/// \param renderWindow : Renderwindow object -/// \param threshold : New threshold, in range [0, 100] +/// \param renderWindow Render window object +/// \param threshold New threshold, in range [0, 100] /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_SetJoystickThreshold(sfRenderWindow* renderWindow, float threshold); //////////////////////////////////////////////////////////// -/// Retrieve the Os-specific handle of a window +/// \brief Retrieve the OS-specific handle of a render window /// -/// \param renderWindow : Renderwindow object +/// \param renderWindow Render window object /// /// \return Window handle /// @@ -287,50 +265,27 @@ CSFML_API void sfRenderWindow_SetJoystickThreshold(sfRenderWindow* renderWindow, CSFML_API sfWindowHandle sfRenderWindow_GetSystemHandle(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Draw something on a renderwindow +/// \brief Clear a render window with the given color /// -/// \param renderWindow : Renderwindow to draw in -/// \param sprite / text / shape : Object to draw -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, const sfSprite* sprite); -CSFML_API void sfRenderWindow_DrawShape (sfRenderWindow* renderWindow, const sfShape* shape); -CSFML_API void sfRenderWindow_DrawText (sfRenderWindow* renderWindow, const sfText* text); - -//////////////////////////////////////////////////////////// -/// Draw something on a renderwindow with a shader -/// -/// \param renderWindow : Renderwindow to draw in -/// \param sprite / text / shape : Object to draw -/// \param shader : Shader to use -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfRenderWindow_DrawSpriteWithShader(sfRenderWindow* renderWindow, const sfSprite* sprite, const sfShader* shader); -CSFML_API void sfRenderWindow_DrawShapeWithShader (sfRenderWindow* renderWindow, const sfShape* shape, const sfShader* shader); -CSFML_API void sfRenderWindow_DrawTextWithShader (sfRenderWindow* renderWindow, const sfText* text, const sfShader* shader); - -//////////////////////////////////////////////////////////// -/// Clear the screen with the given color -/// -/// \param renderWindow : Renderwindow to modify -/// \param color : Fill color +/// \param renderWindow Render window object +/// \param color Fill color /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_Clear(sfRenderWindow* renderWindow, sfColor color); //////////////////////////////////////////////////////////// -/// Change the current active view of a renderwindow +/// \brief Change the current active view of a render window /// -/// \param renderWindow : Renderwindow to modify -/// \param view : Pointer to the new view +/// \param renderWindow Render window object +/// \param view Pointer to the new view /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_SetView(sfRenderWindow* renderWindow, const sfView* view); //////////////////////////////////////////////////////////// -/// Get the current active view of a renderwindow +/// \brief Get the current active view of a render window /// -/// \param renderWindow : Renderwindow +/// \param renderWindow Render window object /// /// \return Current active view /// @@ -338,9 +293,9 @@ CSFML_API void sfRenderWindow_SetView(sfRenderWindow* renderWindow, const sfView CSFML_API const sfView* sfRenderWindow_GetView(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Get the default view of a renderwindow +/// \brief Get the default view of a render window /// -/// \param renderWindow : Renderwindow +/// \param renderWindow Render window object /// /// \return Default view of the render window /// @@ -348,10 +303,10 @@ CSFML_API const sfView* sfRenderWindow_GetView(const sfRenderWindow* renderWindo CSFML_API const sfView* sfRenderWindow_GetDefaultView(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// Get the viewport of a view applied to this target +/// \brief Get the viewport of a view applied to this target /// -/// \param renderWindow : Renderwindow -/// \param view : Target view +/// \param renderWindow Render window object +/// \param view Target view /// /// \return Viewport rectangle, expressed in pixels in the current target /// @@ -359,20 +314,97 @@ CSFML_API const sfView* sfRenderWindow_GetDefaultView(const sfRenderWindow* rend CSFML_API sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindow, const sfView* view); //////////////////////////////////////////////////////////// -/// Convert a point in window coordinates into view coordinates +/// \brief Convert a point in window coordinates into view coordinates /// -/// \param renderWindow : Target Renderwindow -/// \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 viewX : Pointer to fill with the X coordinate of the converted point -/// \param viewY : Pointer to fill with the Y coordinate of the converted point -/// \param targetView : Target view to convert the point to (pass NULL to use the current view) +/// \param renderWindow Render window object +/// \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 viewX Pointer to fill with the X coordinate of the converted point +/// \param viewY Pointer to fill with the Y coordinate of the converted point +/// \param targetView Target view to convert the point to (pass NULL to use the current view) /// //////////////////////////////////////////////////////////// CSFML_API void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView); //////////////////////////////////////////////////////////// -/// Copy the current contents of a window to an image +/// \brief Draw a drawable object to the render-target +/// +/// \param renderWindow render window object +/// \param object Object to draw +/// \param states Render states to use for drawing (NULL to use the default states) +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, const sfSprite* object, const sfRenderStates* states); +CSFML_API void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, const sfText* object, const sfRenderStates* states); +CSFML_API void sfRenderWindow_DrawCircleShape(sfRenderWindow* renderWindow, const sfCircleShape* object, const sfRenderStates* states); +CSFML_API void sfRenderWindow_DrawConvexShape(sfRenderWindow* renderWindow, const sfConvexShape* object, const sfRenderStates* states); +CSFML_API void sfRenderWindow_DrawRectangleShape(sfRenderWindow* renderWindow, const sfRectangleShape* object, const sfRenderStates* states); +CSFML_API void sfRenderWindow_DrawVertexArray(sfRenderWindow* renderWindow, const sfVertexArray* object, const sfRenderStates* states); + +//////////////////////////////////////////////////////////// +/// \brief Draw primitives defined by an array of vertices to a render window +/// +/// \param renderWindow render window object +/// \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 (NULL to use the default states) +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_DrawPrimitives(sfRenderWindow* renderWindow, + const sfVertex* vertices, unsigned int vertexCount, + sfPrimitiveType type, const sfRenderStates* states); + +//////////////////////////////////////////////////////////// +/// \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 function +/// +/// 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. +/// +/// \param renderWindow render window object +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_PushGLStates(sfRenderWindow* renderWindow); + +//////////////////////////////////////////////////////////// +/// \brief Restore the previously saved OpenGL render states and matrices +/// +/// See the description of PushGLStates to get a detailed +/// description of these functions. +/// +/// \param renderWindow render window object +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_PopGLStates(sfRenderWindow* renderWindow); + +//////////////////////////////////////////////////////////// +/// \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 sfRenderWindow_Draw*() +/// calls will work as expected. +/// +/// \param renderWindow render window object +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_ResetGLStates(sfRenderWindow* renderWindow); + +//////////////////////////////////////////////////////////// +/// \brief Copy the current contents of a render window to an image /// /// This is a slow operation, whose main purpose is to make /// screenshots of the application. If you want to update an @@ -380,9 +412,9 @@ CSFML_API void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, /// drawing, you should rather use a sfTexture and its /// Update(sfWindow*) function. /// You can also draw things directly to a texture with the -/// sfRenderTexture class. +/// sfRenderWindow class. /// -/// \param renderWindow : Render window to capture +/// \param renderWindow Render window object /// /// \return New image containing the captured contents /// diff --git a/include/SFML/Graphics/Shader.h b/include/SFML/Graphics/Shader.h index 774ef59..6fd9522 100644 --- a/include/SFML/Graphics/Shader.h +++ b/include/SFML/Graphics/Shader.h @@ -29,137 +29,315 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include //////////////////////////////////////////////////////////// -/// Create a new shader from a file +/// \brief Load both the vertex and fragment shaders from files /// -/// \param filename : File to load +/// This function can load both the vertex and the fragment +/// shaders, or only one of them: pass NULL if you don't want to load +/// either the vertex shader or the fragment shader. +/// The sources must be text files containing valid shaders +/// in GLSL language. GLSL is a C-like language dedicated to +/// OpenGL shaders; you'll probably need to read a good documentation +/// for it before writing your own shaders. +/// +/// \param vertexShaderFilename Path of the vertex shader file to load, or NULL to skip this shader +/// \param fragmentShaderFilename Path of the fragment shader file to load, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_API sfShader* sfShader_CreateFromFile(const char* filename); +CSFML_API sfShader* sfShader_CreateFromFile(const char* vertexShaderFilename, const char* fragmentShaderFilename); //////////////////////////////////////////////////////////// -/// Create a new shader from an effect source code +/// \brief Load both the vertex and fragment shaders from source codes in memory /// -/// \param effect : Source code of the effect +/// This function can load both the vertex and the fragment +/// shaders, or only one of them: pass NULL if you don't want to load +/// either the vertex shader or the fragment shader. +/// The sources must be valid shaders in GLSL language. GLSL is +/// a C-like language dedicated to OpenGL shaders; you'll +/// probably need to read a good documentation for it before +/// writing your own shaders. +/// +/// \param vertexShader String containing the source code of the vertex shader, or NULL to skip this shader +/// \param fragmentShader String containing the source code of the fragment shader, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_API sfShader* sfShader_CreateFromMemory(const char* effect); +CSFML_API sfShader* sfShader_CreateFromMemory(const char* vertexShader, const char* fragmentShader); //////////////////////////////////////////////////////////// -/// Create a new shader from a custom stream +/// \brief Load both the vertex and fragment shaders from custom streams /// -/// \param stream : Source stream to read from +/// This function can load both the vertex and the fragment +/// shaders, or only one of them: pass NULL if you don't want to load +/// either the vertex shader or the fragment shader. +/// The source codes must be valid shaders in GLSL language. +/// GLSL is a C-like language dedicated to OpenGL shaders; +/// you'll probably need to read a good documentation for +/// it before writing your own shaders. +/// +/// \param vertexShaderStream Source stream to read the vertex shader from, or NULL to skip this shader +/// \param fragmentShaderStream Source stream to read the fragment shader from, or NULL to skip this shader /// /// \return A new sfShader object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_API sfShader* sfShader_CreateFromStream(sfInputStream* stream); +CSFML_API sfShader* sfShader_CreateFromStream(sfInputStream* vertexShaderStream, sfInputStream* fragmentShaderStream); //////////////////////////////////////////////////////////// -/// Copy an existing shader +/// \brief Destroy an existing shader /// -/// \param shader : Shader to copy -/// -/// \return Copied object -/// -//////////////////////////////////////////////////////////// -CSFML_API sfShader* sfShader_Copy(sfShader* shader); - -//////////////////////////////////////////////////////////// -/// Destroy an existing shader -/// -/// \param shader : Shader to delete +/// \param shader Shader to delete /// //////////////////////////////////////////////////////////// CSFML_API void sfShader_Destroy(sfShader* shader); //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (1 float) +/// \brief Change a float parameter of a shader /// -/// \param shader : Shader to modify -/// \param name : Parameter name in the effect -/// \param x : Value to assign +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a float +/// (float GLSL type). +/// +/// Example: +/// \code +/// uniform float myparam; // this is the variable in the shader +/// \endcode +/// \code +/// sfShader_SetFloatParameter(shader, "myparam", 5.2f); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the parameter in the shader +/// \param x Value to assign /// //////////////////////////////////////////////////////////// -CSFML_API void sfShader_SetParameter1(sfShader* shader, const char* name, float x); +CSFML_API void sfShader_SetFloatParameter(sfShader* shader, const char* name, float x); //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (2 floats) +/// \brief Change a 2-components vector parameter of a shader /// -/// \param shader : Shader to modify -/// \param name : Parameter name in the effect -/// \param x, y : Values to assign +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a 2x1 vector +/// (vec2 GLSL type). +/// +/// Example: +/// \code +/// uniform vec2 myparam; // this is the variable in the shader +/// \endcode +/// \code +/// sfShader_SetFloat2Parameter(shader, "myparam", 5.2f, 6.0f); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the parameter in the shader +/// \param x First component of the value to assign +/// \param y Second component of the value to assign /// //////////////////////////////////////////////////////////// -CSFML_API void sfShader_SetParameter2(sfShader* shader, const char* name, float x, float y); +CSFML_API void sfShader_SetFloat2Parameter(sfShader* shader, const char* name, float x, float y); //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (3 floats) +/// \brief Change a 3-components vector parameter of a shader /// -/// \param shader : Shader to modify -/// \param name : Parameter name in the effect -/// \param x, y, z : Values to assign +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a 3x1 vector +/// (vec3 GLSL type). +/// +/// Example: +/// \code +/// uniform vec3 myparam; // this is the variable in the shader +/// \endcode +/// \code +/// sfShader_SetFloat3Parameter(shader, "myparam", 5.2f, 6.0f, -8.1f); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the parameter in the shader +/// \param x First component of the value to assign +/// \param y Second component of the value to assign +/// \param z Third component of the value to assign /// //////////////////////////////////////////////////////////// -CSFML_API void sfShader_SetParameter3(sfShader* shader, const char* name, float x, float y, float z); +CSFML_API void sfShader_SetFloat3Parameter(sfShader* shader, const char* name, float x, float y, float z); //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (4 floats) +/// \brief Change a 4-components vector parameter of a shader /// -/// \param shader : Shader to modify -/// \param name : Parameter name in the effect -/// \param x, y, z, w : Values to assign +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a 4x1 vector +/// (vec4 GLSL type). +/// +/// Example: +/// \code +/// uniform vec4 myparam; // this is the variable in the shader +/// \endcode +/// \code +/// sfShader_SetFloat4Parameter(shader, "myparam", 5.2f, 6.0f, -8.1f, 0.4f); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the parameter in the shader +/// \param x First component of the value to assign +/// \param y Second component of the value to assign +/// \param z Third component of the value to assign +/// \param w Fourth component of the value to assign /// //////////////////////////////////////////////////////////// -CSFML_API void sfShader_SetParameter4(sfShader* shader, const char* name, float x, float y, float z, float w); +CSFML_API void sfShader_SetFloat4Parameter(sfShader* shader, const char* name, float x, float y, float z, float w); //////////////////////////////////////////////////////////// -/// Set a texture parameter in a shader +/// \brief Change a color parameter of a shader /// -/// \param shader : Shader to modify -/// \param name : Texture name in the effect -/// \param texture : Texture to set +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a 4x1 vector +/// (vec4 GLSL type). +/// +/// It is important to note that the components of the color are +/// normalized before being passed to the shader. Therefore, +/// they are converted from range [0 .. 255] to range [0 .. 1]. +/// For example, a sf::Color(255, 125, 0, 255) will be transformed +/// to a vec4(1.0, 0.5, 0.0, 1.0) in the shader. +/// +/// Example: +/// \code +/// uniform vec4 color; // this is the variable in the shader +/// \endcode +/// \code +/// sfShader_SetColorParameter(shader, "color", sfColor_FromRGB(255, 128, 0)); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the parameter in the shader +/// \param color Color to assign /// //////////////////////////////////////////////////////////// -CSFML_API void sfShader_SetTexture(sfShader* shader, const char* name, const sfTexture* texture); +CSFML_API void sfShader_SetColorParameter(sfShader* shader, const char* name, sfColor color); //////////////////////////////////////////////////////////// -/// Set the current texture parameter in a shader +/// \brief Change a matrix parameter of a shader /// -/// \param shader : Shader to modify -/// \param name : Texture name in the effect +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a 4x4 matrix +/// (mat4 GLSL type). +/// +/// Example: +/// \code +/// uniform mat4 matrix; // this is the variable in the shader +/// \endcode +/// \code +/// @todo +/// sfShader_SetTransformParameter(shader, "matrix", transform); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the parameter in the shader +/// \param transform Transform to assign /// //////////////////////////////////////////////////////////// -CSFML_API void sfShader_SetCurrentTexture(sfShader* shader, const char* name); +CSFML_API void sfShader_SetTransformParameter(sfShader* shader, const char* name, const sfTransform* transform); //////////////////////////////////////////////////////////// -/// Bind a shader for rendering +/// \brief Change a texture parameter of a shader /// -/// \param shader : Shader to bind +/// \a name is the name of the variable to change in the shader. +/// The corresponding parameter in the shader must be a 2D texture +/// (sampler2D GLSL type). +/// +/// Example: +/// \code +/// uniform sampler2D the_texture; // this is the variable in the shader +/// \endcode +/// \code +/// sf::Texture texture; +/// ... +/// sfShader_SetTextureParameter(shader, "the_texture", texture); +/// \endcode +/// It is important to note that \a texture must remain alive as long +/// as the shader uses it, no copy is made internally. +/// +/// To use the texture of the object being draw, which cannot be +/// known in advance, you can use the special function +/// sfShader_SetCurrentTextureParameter: +/// \code +/// sfShader_SetCurrentTextureParameter(shader, "the_texture"). +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the texture in the shader +/// \param texture Texture to assign +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfShader_SetTextureParameter(sfShader* shader, const char* name, const sfTexture* texture); + +//////////////////////////////////////////////////////////// +/// \brief Change a texture parameter of a shader +/// +/// This function maps a shader texture variable to the +/// texture of the object being drawn, which cannot be +/// known in advance. +/// The corresponding parameter in the shader must be a 2D texture +/// (sampler2D GLSL type). +/// +/// Example: +/// \code +/// uniform sampler2D current; // this is the variable in the shader +/// \endcode +/// \code +/// sfShader_SetCurrentTextureParameter(shader, "current"); +/// \endcode +/// +/// \param shader Shader object +/// \param name Name of the texture in the shader +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfShader_SetCurrentTextureParameter(sfShader* shader, const char* name); + +//////////////////////////////////////////////////////////// +/// \brief Bind a shader for rendering (activate it) +/// +/// This function is normally for internal use only, unless +/// you want to use the shader with a custom OpenGL rendering +/// instead of a SFML drawable. +/// \code +/// sfWindow_SetActive(window, sfTrue); +/// sfShader_Bind(shader); +/// ... render OpenGL geometry ... +/// sfShader_Unbind(shader); +/// \endcode +/// +/// \param shader Shader to bind /// //////////////////////////////////////////////////////////// CSFML_API void sfShader_Bind(const sfShader* shader); //////////////////////////////////////////////////////////// -/// Unbind a shader +/// \brief Unbind a shader (deactivate it) /// -/// \param shader : Shader to unbind +/// This function is normally for internal use only, unless +/// you want to use the shader with a custom OpenGL rendering +/// instead of a SFML drawable. +/// +/// \param shader Shader to unbind /// //////////////////////////////////////////////////////////// CSFML_API void sfShader_Unbind(const sfShader* shader); //////////////////////////////////////////////////////////// -/// Tell whether or not the system supports shaders +/// \brief Tell whether or not the system supports shaders /// -/// \return sfTrue if the system can use shaders +/// This function should always be called before using +/// the shader features. If it returns false, then +/// any attempt to use sfShader will fail. +/// +/// \return sfTrue if the system can use shaders, sfFalse otherwise /// //////////////////////////////////////////////////////////// CSFML_API sfBool sfShader_IsAvailable(void); diff --git a/include/SFML/Graphics/Shape.h b/include/SFML/Graphics/Shape.h deleted file mode 100644 index f8d35a7..0000000 --- a/include/SFML/Graphics/Shape.h +++ /dev/null @@ -1,464 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_SHAPE_H -#define SFML_SHAPE_H - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include - - -//////////////////////////////////////////////////////////// -/// Create a new shape -/// -/// \return A new sfShape object, or NULL if it failed -/// -//////////////////////////////////////////////////////////// -CSFML_API sfShape* sfShape_Create(void); - -//////////////////////////////////////////////////////////// -/// Create a new shape made of a single line -/// -/// \param p1x, p1y : Position of the first point -/// \param p2x, p2y : Position second point -/// \param thickness : Line thickness -/// \param color : Color used to draw the line -/// \param outline : Outline thickness -/// \param outlineColor : Color used to draw the outline -/// -//////////////////////////////////////////////////////////// -CSFML_API sfShape* sfShape_CreateLine(float p1x, float p1y, float p2x, float p2y, float thickness, sfColor color, float outline, sfColor outlineColor); - -//////////////////////////////////////////////////////////// -/// Create a new shape made of a single rectangle -/// -/// \param left, top : Top-left corner of the rectangle -/// \param width, height : Size of the rectangle -/// \param color : Color used to fill the rectangle -/// \param outline : Outline thickness -/// \param outlineColor : Color used to draw the outline -/// -//////////////////////////////////////////////////////////// -CSFML_API sfShape* sfShape_CreateRectangle(float left, float top, float width, float height, sfColor color, float outline, sfColor outlineColor); - -//////////////////////////////////////////////////////////// -/// Create a new shape made of a single circle -/// -/// \param x, y : Position of the center -/// \param radius : Radius -/// \param color : Color used to fill the circle -/// \param outline : Outline thickness -/// \param outlineColor : Color used to draw the outline -/// -//////////////////////////////////////////////////////////// -CSFML_API sfShape* sfShape_CreateCircle(float x, float y, float radius, sfColor color, float outline, sfColor outlineColor); - -//////////////////////////////////////////////////////////// -/// Copy an existing shape -/// -/// \param shape : Shape to copy -/// -/// \return Copied object -/// -//////////////////////////////////////////////////////////// -CSFML_API sfShape* sfShape_Copy(sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Destroy an existing Shape -/// -/// \param Shape : Shape to delete -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_Destroy(sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Set the X position of a shape -/// -/// \param shape : Shape to modify -/// \param x : New X coordinate -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetX(sfShape* shape, float x); - -//////////////////////////////////////////////////////////// -/// Set the Y position of a shape -/// -/// \param shape : Shape to modify -/// \param y : New Y coordinate -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetY(sfShape* shape, float y); - -//////////////////////////////////////////////////////////// -/// Set the position of a shape -/// -/// \param shape : Shape to modify -/// \param x : New X coordinate -/// \param y : New Y coordinate -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetPosition(sfShape* shape, float x, float y); - -//////////////////////////////////////////////////////////// -/// Set the horizontal scale of a shape -/// -/// \param shape : Shape to modify -/// \param scale : New scale (must be strictly positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetScaleX(sfShape* shape, float scale); - -//////////////////////////////////////////////////////////// -/// Set the vertical scale of a shape -/// -/// \param shape : Shape to modify -/// \param scale : New scale (must be strictly positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetScaleY(sfShape* shape, float scale); - -//////////////////////////////////////////////////////////// -/// Set the scale of a shape -/// -/// \param shape : Shape to modify -/// \param scaleX : New horizontal scale (must be strictly positive) -/// \param scaleY : New vertical scale (must be strictly positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetScale(sfShape* shape, float scaleX, float scaleY); - -//////////////////////////////////////////////////////////// -/// Set the orientation of a shape -/// -/// \param shape : Shape to modify -/// \param rotation : Angle of rotation, in degrees -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetRotation(sfShape* shape, float rotation); - -//////////////////////////////////////////////////////////// -/// Set the local origin of a shape, in coordinates relative to -/// its left-top corner -/// -/// \param shape : Shape to modify -/// \param x : X coordinate of the origin -/// \param y : Y coordinate of the origin -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetOrigin(sfShape* shape, float x, float y); - -//////////////////////////////////////////////////////////// -/// Set the color of a shape -/// -/// \param shape : Shape to modify -/// \param color : New color -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetColor(sfShape* shape, sfColor color); - -//////////////////////////////////////////////////////////// -/// Set the blending mode for a shape -/// -/// \param shape : Shape to modify -/// \param mode : New blending mode -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetBlendMode(sfShape* shape, sfBlendMode mode); - -//////////////////////////////////////////////////////////// -/// Get the X position of a shape -/// -/// \param shape : Shape to read -/// -/// \return Current X position -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetX(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the Y position of a shape -/// -/// \param shape : Shape to read -/// -/// \return Current Y position -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetY(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the horizontal scale of a shape -/// -/// \param shape : Shape to read -/// -/// \return Current X scale factor (always positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetScaleX(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the vertical scale of a shape -/// -/// \param shape : Shape to read -/// -/// \return Current Y scale factor (always positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetScaleY(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the orientation of a shape -/// -/// \param shape : Shape to read -/// -/// \return Current rotation, in degrees -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetRotation(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the X position of the origin a shape -/// -/// \param shape : Shape to read -/// -/// \return Current X origin -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetOriginX(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the Y position of the origin a shape -/// -/// \param shape : Shape to read -/// -/// \return Current Y origin -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetOriginY(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the color of a shape -/// -/// \param shape : Shape to read -/// -/// \return Current color -/// -//////////////////////////////////////////////////////////// -CSFML_API sfColor sfShape_GetColor(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the current blending mode of a shape -/// -/// \param shape : Shape to read -/// -/// \return Current blending mode -/// -//////////////////////////////////////////////////////////// -CSFML_API sfBlendMode sfShape_GetBlendMode(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Move a shape -/// -/// \param shape : Shape to modify -/// \param offsetX : Offset on the X axis -/// \param offsetY : Offset on the Y axis -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_Move(sfShape* shape, float offsetX, float offsetY); - -//////////////////////////////////////////////////////////// -/// Scale a shape -/// -/// \param shape : Shape to modify -/// \param factorX : Horizontal scaling factor (must be strictly positive) -/// \param factorY : Vertical scaling factor (must be strictly positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_Scale(sfShape* shape, float factorX, float factorY); - -//////////////////////////////////////////////////////////// -/// Rotate a shape -/// -/// \param shape : Shape to modify -/// \param angle : Angle of rotation, in degrees -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_Rotate(sfShape* shape, float angle); - -//////////////////////////////////////////////////////////// -/// Transform a point from global coordinates into the shape's local coordinates -/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) -/// -/// \param shape : Shape object -/// \param pointX : X coordinate of the point to transform -/// \param pointY : Y coordinate of the point to transform -/// \param x : Value to fill with the X coordinate of the converted point -/// \param y : Value to fill with the y coordinate of the converted point -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_TransformToLocal(const sfShape* shape, float pointX, float pointY, float* x, float* y); - -//////////////////////////////////////////////////////////// -/// Transform a point from the shape's local coordinates into global coordinates -/// (ie it applies the object's origin, translation, rotation and scale to the point) -/// -/// \param shape : Shape object -/// \param pointX : X coordinate of the point to transform -/// \param pointY : Y coordinate of the point to transform -/// \param x : Value to fill with the X coordinate of the converted point -/// \param y : Value to fill with the y coordinate of the converted point -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_TransformToGlobal(const sfShape* shape, float pointX, float pointY, float* x, float* y); - -//////////////////////////////////////////////////////////// -/// Add a point to a shape -/// -/// \param shape : Shape to modify -/// \param x, y : Position of the point -/// \param color : Color of the point -/// \param outlineColor : Outline color of the point -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_AddPoint(sfShape* shape, float x, float y, sfColor color, sfColor outlineColor); - -//////////////////////////////////////////////////////////// -/// Enable or disable filling a shape. -/// Fill is enabled by default -/// -/// \param shape : Shape to modify -/// \param enable : True to enable, false to disable -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_EnableFill(sfShape* shape, sfBool enable); - -//////////////////////////////////////////////////////////// -/// Enable or disable drawing a shape outline. -/// Outline is enabled by default -/// -/// \param shape : Shape to modify -/// \param enable : True to enable, false to disable -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_EnableOutline(sfShape* shape, sfBool enable); - -//////////////////////////////////////////////////////////// -/// Change the thickness of a shape outline -/// -/// \param shape : Shape to modify -/// \param thickness : New thickness -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetOutlineThickness(sfShape* shape, float thickness); - -//////////////////////////////////////////////////////////// -/// Get the thickness of a shape outline -/// -/// \param shape : Shape to read -/// -/// \param return Current outline thickness -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfShape_GetOutlineThickness(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get the number of points composing a shape -/// -/// \param shape : Shape to read -/// -/// \return Total number of points -/// -//////////////////////////////////////////////////////////// -CSFML_API unsigned int sfShape_GetPointsCount(const sfShape* shape); - -//////////////////////////////////////////////////////////// -/// Get a the position of a shape's point -/// -/// \param shape : Shape to read -/// \param index : Index of the point to get -/// \param x : Variable to fill with the X coordinate of the point -/// \param y : Variable to fill with the Y coordinate of the point -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_GetPointPosition(const sfShape* shape, unsigned int index, float* x, float* y); - -//////////////////////////////////////////////////////////// -/// Get a the color of a shape's point -/// -/// \param shape : Shape to read -/// \param index : Index of the point to get -/// -/// \return Color of the point -/// -//////////////////////////////////////////////////////////// -CSFML_API sfColor sfShape_GetPointColor(const sfShape* shape, unsigned int index); - -//////////////////////////////////////////////////////////// -/// Get a the outline color of a shape's point -/// -/// \param shape : Shape to read -/// \param index : Index of the point to get -/// -/// \return Outline color of the point -/// -//////////////////////////////////////////////////////////// -CSFML_API sfColor sfShape_GetPointOutlineColor(const sfShape* shape, unsigned int index); - -//////////////////////////////////////////////////////////// -/// Set a the position of a shape's point -/// -/// \param shape : Shape to read -/// \param index : Index of the point to get -/// \param x : X coordinate of the point -/// \param y : Y coordinate of the point -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetPointPosition(sfShape* shape, unsigned int index, float x, float y); - -//////////////////////////////////////////////////////////// -/// Set a the color of a shape's point -/// -/// \param shape : Shape to read -/// \param index : Index of the point to get -/// \param color : Color of the point -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetPointColor(sfShape* shape, unsigned int index, sfColor color); - -//////////////////////////////////////////////////////////// -/// Set a the outline color of a shape's point -/// -/// \param shape : Shape to read -/// \param index : Index of the point to get -/// \param color : Outline color of the point -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfShape_SetPointOutlineColor(sfShape* shape, unsigned int index, sfColor color); - - -#endif // SFML_SHAPE_H diff --git a/include/SFML/Graphics/Sprite.h b/include/SFML/Graphics/Sprite.h index 846c225..1a6f25b 100644 --- a/include/SFML/Graphics/Sprite.h +++ b/include/SFML/Graphics/Sprite.h @@ -36,7 +36,7 @@ //////////////////////////////////////////////////////////// -/// Create a new sprite +/// \brief Create a new sprite /// /// \return A new sfSprite object, or NULL if it failed /// @@ -44,9 +44,9 @@ CSFML_API sfSprite* sfSprite_Create(void); //////////////////////////////////////////////////////////// -/// Copy an existing sprite +/// \brief Copy an existing sprite /// -/// \param sprite : Sprite to copy +/// \param sprite Sprite to copy /// /// \return Copied object /// @@ -54,151 +54,87 @@ CSFML_API sfSprite* sfSprite_Create(void); CSFML_API sfSprite* sfSprite_Copy(sfSprite* sprite); //////////////////////////////////////////////////////////// -/// Destroy an existing sprite +/// \brief Destroy an existing sprite /// -/// \param sprite : Sprite to delete +/// \param sprite Sprite to delete /// //////////////////////////////////////////////////////////// CSFML_API void sfSprite_Destroy(sfSprite* sprite); //////////////////////////////////////////////////////////// -/// Set the X position of a sprite +/// \brief Set the position of a sprite /// -/// \param sprite : Sprite to modify -/// \param x : New X coordinate +/// This function completely overwrites the previous position. +/// See sfSprite_Move to apply an offset based on the previous position instead. +/// The default position of a sprite object is (0, 0). /// -//////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetX(sfSprite* sprite, float x); - -//////////////////////////////////////////////////////////// -/// Set the T position of a sprite -/// -/// \param sprite : Sprite to modify -/// \param y : New Y coordinate -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetY(sfSprite* sprite, float y); - -//////////////////////////////////////////////////////////// -/// Set the position of a sprite -/// -/// \param sprite : Sprite to modify -/// \param x : New X coordinate -/// \param y : New Y coordinate +/// \param sprite Sprite object +/// \param x X coordinate of the new position +/// \param y Y coordinate of the new position /// //////////////////////////////////////////////////////////// CSFML_API void sfSprite_SetPosition(sfSprite* sprite, float x, float y); //////////////////////////////////////////////////////////// -/// Set the horizontal scale of a sprite +/// \brief Set the orientation of a sprite /// -/// \param sprite : Sprite to modify -/// \param scale : New scale (must be strictly positive) +/// This function completely overwrites the previous rotation. +/// See sfSprite_Rotate to add an angle based on the previous rotation instead. +/// The default rotation of a sprite object is 0. +/// +/// \param sprite Sprite object +/// \param angle New rotation, in degrees /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetScaleX(sfSprite* sprite, float scale); +CSFML_API void sfSprite_SetRotation(sfSprite* sprite, float angle); //////////////////////////////////////////////////////////// -/// Set the vertical scale of a sprite +/// \brief Set the scale factors of a sprite /// -/// \param sprite : Sprite to modify -/// \param scale : New scale (must be strictly positive) +/// This function completely overwrites the previous scale. +/// See sfSprite_Scale to add a factor based on the previous scale instead. +/// The default scale of a sprite object is (1, 1). +/// +/// \param sprite Sprite object +/// \param factorX New horizontal scale factor +/// \param factorY New vertical scale factor /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetScaleY(sfSprite* sprite, float scale); +CSFML_API void sfSprite_SetScale(sfSprite* sprite, float factorX, float factorY); //////////////////////////////////////////////////////////// -/// Set the scale of a sprite +/// \brief Set the local origin of a sprite /// -/// \param sprite : Sprite to modify -/// \param scaleX : New horizontal scale (must be strictly positive) -/// \param scaleY : New vertical scale (must be strictly positive) +/// The origin of an object defines the center point for +/// all transformations (position, scale, rotation). +/// The coordinates of this point must be relative to the +/// top-left corner of the object, and ignore all +/// transformations (position, scale, rotation). +/// The default origin of a sprite object is (0, 0). /// -//////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetScale(sfSprite* sprite, float scaleX, float scaleY); - -//////////////////////////////////////////////////////////// -/// Set the orientation of a sprite -/// -/// \param sprite : Sprite to modify -/// \param rotation : Angle of rotation, in degrees -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetRotation(sfSprite* sprite, float rotation); - -//////////////////////////////////////////////////////////// -/// Set the local origin of a sprite, in coordinates relative to -/// its left-top corner -/// -/// \param sprite : Sprite to modify -/// \param x : X coordinate of the origin -/// \param y : Y coordinate of the origin +/// \param sprite Sprite object +/// \param x X coordinate of the new origin +/// \param y Y coordinate of the new origin /// //////////////////////////////////////////////////////////// CSFML_API void sfSprite_SetOrigin(sfSprite* sprite, float x, float y); //////////////////////////////////////////////////////////// -/// Set the color of a sprite +/// \brief Get the position of a sprite /// -/// \param sprite : Sprite to modify -/// \param color : New color +/// \param sprite Sprite object +/// +/// \return Current position /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetColor(sfSprite* sprite, sfColor color); +CSFML_API void sfSprite_GetPosition(const sfSprite* sprite, float* x, float* y); //////////////////////////////////////////////////////////// -/// Set the blending mode for a sprite +/// \brief Get the orientation of a sprite /// -/// \param sprite : Sprite to modify -/// \param mode : New blending mode +/// The rotation is always in the range [0, 360]. /// -//////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetBlendMode(sfSprite* sprite, sfBlendMode mode); - -//////////////////////////////////////////////////////////// -/// Get the X position of a sprite -/// -/// \param sprite : Sprite to read -/// -/// \return Current X position -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetX(const sfSprite* sprite); - -//////////////////////////////////////////////////////////// -/// Get the Y position of a sprite -/// -/// \param sprite : Sprite to read -/// -/// \return Current Y position -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetY(const sfSprite* sprite); - -//////////////////////////////////////////////////////////// -/// Get the horizontal scale of a sprite -/// -/// \param sprite : Sprite to read -/// -/// \return Current X scale factor (always positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetScaleX(const sfSprite* sprite); - -//////////////////////////////////////////////////////////// -/// Get the vertical scale of a sprite -/// -/// \param sprite : Sprite to read -/// -/// \return Current Y scale factor (always positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetScaleY(const sfSprite* sprite); - -//////////////////////////////////////////////////////////// -/// Get the orientation of a sprite -/// -/// \param sprite : Sprite to read +/// \param sprite Sprite object /// /// \return Current rotation, in degrees /// @@ -206,186 +142,163 @@ CSFML_API float sfSprite_GetScaleY(const sfSprite* sprite); CSFML_API float sfSprite_GetRotation(const sfSprite* sprite); //////////////////////////////////////////////////////////// -/// Get the X position of the origin a sprite +/// \brief Get the current scale of a sprite /// -/// \param sprite : Sprite to read +/// \param sprite Sprite object /// -/// \return Current X origin +/// \return Current scale factors /// //////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetOriginX(const sfSprite* sprite); +CSFML_API void sfSprite_GetScale(const sfSprite* sprite, float* x, float* y); //////////////////////////////////////////////////////////// -/// Get the Y position of the origin a sprite +/// \brief Get the local origin of a sprite /// -/// \param sprite : Sprite to read +/// \param sprite Sprite object /// -/// \return Current Y origin +/// \return Current origin /// //////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetOriginY(const sfSprite* sprite); +CSFML_API void sfSprite_GetOrigin(const sfSprite* sprite, float* x, float* y); //////////////////////////////////////////////////////////// -/// Get the color of a sprite +/// \brief Move a sprite by a given offset /// -/// \param sprite : Sprite to read +/// This function adds to the current position of the object, +/// unlike sfSprite_SetPosition which overwrites it. /// -/// \return Current color -/// -//////////////////////////////////////////////////////////// -CSFML_API sfColor sfSprite_GetColor(const sfSprite* sprite); - -//////////////////////////////////////////////////////////// -/// Get the current blending mode of a sprite -/// -/// \param sprite : Sprite to read -/// -/// \return Current blending mode -/// -//////////////////////////////////////////////////////////// -CSFML_API sfBlendMode sfSprite_GetBlendMode(const sfSprite* sprite); - -//////////////////////////////////////////////////////////// -/// Move a sprite -/// -/// \param sprite : Sprite to modify -/// \param offsetX : Offset on the X axis -/// \param offsetY : Offset on the Y axis +/// \param sprite Sprite object +/// \param offsetX X offset +/// \param offsetY Y offset /// //////////////////////////////////////////////////////////// CSFML_API void sfSprite_Move(sfSprite* sprite, float offsetX, float offsetY); //////////////////////////////////////////////////////////// -/// Scale a sprite +/// \brief Rotate a sprite /// -/// \param sprite : Sprite to modify -/// \param factorX : Horizontal scaling factor (must be strictly positive) -/// \param factorY : Vertical scaling factor (must be strictly positive) +/// This function adds to the current rotation of the object, +/// unlike sfSprite_SetRotation which overwrites it. /// -//////////////////////////////////////////////////////////// -CSFML_API void sfSprite_Scale(sfSprite* sprite, float factorX, float factorY); - -//////////////////////////////////////////////////////////// -/// Rotate a sprite -/// -/// \param sprite : Sprite to modify -/// \param angle : Angle of rotation, in degrees +/// \param sprite Sprite object +/// \param angle Angle of rotation, in degrees /// //////////////////////////////////////////////////////////// CSFML_API void sfSprite_Rotate(sfSprite* sprite, float angle); //////////////////////////////////////////////////////////// -/// Transform a point from global coordinates into the sprite's local coordinates -/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) +/// \brief Scale a sprite /// -/// \param sprite : Sprite object -/// \param pointX : X coordinate of the point to transform -/// \param pointY : Y coordinate of the point to transform -/// \param x : Value to fill with the X coordinate of the converted point -/// \param y : Value to fill with the y coordinate of the converted point +/// This function multiplies the current scale of the object, +/// unlike sfSprite_SetScale which overwrites it. +/// +/// \param sprite Sprite object +/// \param factorX Horizontal scale factor +/// \param factorY Vertical scale factor /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_TransformToLocal(const sfSprite* sprite, float pointX, float pointY, float* x, float* y); +CSFML_API void sfSprite_Scale(sfSprite* sprite, float factorX, float factorY); //////////////////////////////////////////////////////////// -/// Transform a point from the sprite's local coordinates into global coordinates -/// (ie it applies the object's origin, translation, rotation and scale to the point) +/// \brief Get the combined transform of a sprite /// -/// \param sprite : Sprite object -/// \param pointX : X coordinate of the point to transform -/// \param pointY : Y coordinate of the point to transform -/// \param x : Value to fill with the X coordinate of the converted point -/// \param y : Value to fill with the y coordinate of the converted point +/// \param sprite Sprite object +/// +/// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_TransformToGlobal(const sfSprite* sprite, float pointX, float pointY, float* x, float* y); +CSFML_API const sfTransform* sfSprite_GetTransform(const sfSprite* sprite); //////////////////////////////////////////////////////////// -/// Change the texture of a sprite +/// \brief Get the inverse of the combined transform of a sprite /// -/// \param sprite : Sprite to modify -/// \param texture : New texture -/// \param adjustToNewSize : If true, the SubRect of the sprite will be adjusted to the size of the new texture +/// \param sprite Sprite object +/// +/// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool adjustToNewSize); +CSFML_API const sfTransform* sfSprite_GetInverseTransform(const sfSprite* sprite); //////////////////////////////////////////////////////////// -/// Set the sub-rectangle of a sprite inside the source image +/// \brief Change the source texture of a sprite /// -/// \param sprite : Sprite to modify -/// \param rectangle : New sub-rectangle +/// 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 sprite Sprite object +/// \param texture New texture +/// \param resetRect Should the texture rect be reset to the size of the new texture? /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_SetSubRect(sfSprite* sprite, sfIntRect rectangle); +CSFML_API void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool resetRect); //////////////////////////////////////////////////////////// -/// Resize a sprite (by changing its scale factors) +/// \brief Set the sub-rectangle of the texture that a sprite will display /// -/// \param sprite : Sprite to modify -/// \param width : New width (must be strictly positive) -/// \param height : New height (must be strictly positive) +/// 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 sprite Sprite object +/// \param rectangle Rectangle defining the region of the texture to display /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_Resize(sfSprite* sprite, float width, float height); +CSFML_API void sfSprite_SetTextureRect(sfSprite* sprite, sfIntRect rectangle); //////////////////////////////////////////////////////////// -/// Flip a sprite horizontally +/// \brief Set the global color of a sprite /// -/// \param sprite : Sprite to modify -/// \param flipped : sfTrue to flip the sprite +/// 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 sprite Sprite object +/// \param color New color of the sprite /// //////////////////////////////////////////////////////////// -CSFML_API void sfSprite_FlipX(sfSprite* sprite, sfBool flipped); +CSFML_API void sfSprite_SetColor(sfSprite* sprite, sfColor color); //////////////////////////////////////////////////////////// -/// Flip a sprite vertically +/// \brief Get the source texture of a sprite /// -/// \param sprite : Sprite to modify -/// \param flipped : sfTrue to flip 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. /// -//////////////////////////////////////////////////////////// -CSFML_API void sfSprite_FlipY(sfSprite* sprite, sfBool flipped); - -//////////////////////////////////////////////////////////// -/// Get the source texture of a sprite +/// \param sprite Sprite object /// -/// \param sprite : Sprite to read -/// -/// \return Pointer to the texture (can be NULL) +/// \return Pointer to the sprite's texture /// //////////////////////////////////////////////////////////// CSFML_API const sfTexture* sfSprite_GetTexture(const sfSprite* sprite); //////////////////////////////////////////////////////////// -/// Get the sub-rectangle of a sprite inside the source image +/// \brief Get the sub-rectangle of the texture displayed by a sprite /// -/// \param sprite : Sprite to read +/// \param sprite Sprite object /// -/// \return Sub-rectangle +/// \return Texture rectangle of the sprite /// //////////////////////////////////////////////////////////// -CSFML_API sfIntRect sfSprite_GetSubRect(const sfSprite* sprite); +CSFML_API sfIntRect sfSprite_GetTextureRect(const sfSprite* sprite); //////////////////////////////////////////////////////////// -/// Get a sprite width +/// \brief Get the global color of a sprite /// -/// \param sprite : Sprite to read +/// \param sprite Sprite object /// -/// \return Width of the sprite +/// \return Global color of the sprite /// //////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetWidth(const sfSprite* sprite); - -//////////////////////////////////////////////////////////// -/// Get a sprite height -/// -/// \param sprite : Sprite to read -/// -/// \return Height of the sprite -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfSprite_GetHeight(const sfSprite* sprite); +CSFML_API sfColor sfSprite_GetColor(const sfSprite* sprite); #endif // SFML_SPRITE_H diff --git a/include/SFML/Graphics/Text.h b/include/SFML/Graphics/Text.h index bd295a0..4124687 100644 --- a/include/SFML/Graphics/Text.h +++ b/include/SFML/Graphics/Text.h @@ -29,7 +29,6 @@ // Headers //////////////////////////////////////////////////////////// #include -#include #include #include #include @@ -49,7 +48,7 @@ typedef enum //////////////////////////////////////////////////////////// -/// Create a new text +/// \brief Create a new text /// /// \return A new sfText object, or NULL if it failed /// @@ -57,9 +56,9 @@ typedef enum CSFML_API sfText* sfText_Create(void); //////////////////////////////////////////////////////////// -/// Copy an existing text +/// \brief Copy an existing text /// -/// \param text : Text to copy +/// \param text Text to copy /// /// \return Copied object /// @@ -67,151 +66,87 @@ CSFML_API sfText* sfText_Create(void); CSFML_API sfText* sfText_Copy(sfText* text); //////////////////////////////////////////////////////////// -/// Destroy an existing text +/// \brief Destroy an existing text /// -/// \param text : Text to delete +/// \param text Text to delete /// //////////////////////////////////////////////////////////// CSFML_API void sfText_Destroy(sfText* text); //////////////////////////////////////////////////////////// -/// Set the X position of a text +/// \brief Set the position of a text /// -/// \param text : String to modify -/// \param x : New X coordinate +/// This function completely overwrites the previous position. +/// See sfText_Move to apply an offset based on the previous position instead. +/// The default position of a text object is (0, 0). /// -//////////////////////////////////////////////////////////// -CSFML_API void sfText_SetX(sfText* text, float x); - -//////////////////////////////////////////////////////////// -/// Set the Y position of a text -/// -/// \param text : String to modify -/// \param y : New Y coordinate -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfText_SetY(sfText* text, float y); - -//////////////////////////////////////////////////////////// -/// Set the position of a text -/// -/// \param text : String to modify -/// \param x : New X coordinate -/// \param y : New Y coordinate +/// \param text Text object +/// \param x X coordinate of the new position +/// \param y Y coordinate of the new position /// //////////////////////////////////////////////////////////// CSFML_API void sfText_SetPosition(sfText* text, float x, float y); //////////////////////////////////////////////////////////// -/// Set the horizontal scale of a text +/// \brief Set the orientation of a text /// -/// \param text : String to modify -/// \param scale : New scale (must be strictly positive) +/// This function completely overwrites the previous rotation. +/// See sfText_Rotate to add an angle based on the previous rotation instead. +/// The default rotation of a text object is 0. +/// +/// \param text Text object +/// \param angle New rotation, in degrees /// //////////////////////////////////////////////////////////// -CSFML_API void sfText_SetScaleX(sfText* text, float scale); +CSFML_API void sfText_SetRotation(sfText* text, float angle); //////////////////////////////////////////////////////////// -/// Set the vertical scale of a text +/// \brief Set the scale factors of a text /// -/// \param text : String to modify -/// \param scale : New scale (must be strictly positive) +/// This function completely overwrites the previous scale. +/// See sfText_Scale to add a factor based on the previous scale instead. +/// The default scale of a text object is (1, 1). +/// +/// \param text Text object +/// \param factorX New horizontal scale factor +/// \param factorY New vertical scale factor /// //////////////////////////////////////////////////////////// -CSFML_API void sfText_SetScaleY(sfText* text, float scale); +CSFML_API void sfText_SetScale(sfText* text, float factorX, float factorY); //////////////////////////////////////////////////////////// -/// Set the scale of a text +/// \brief Set the local origin of a text /// -/// \param text : String to modify -/// \param scaleX : New horizontal scale (must be strictly positive) -/// \param scaleY : New vertical scale (must be strictly positive) +/// The origin of an object defines the center point for +/// all transformations (position, scale, rotation). +/// The coordinates of this point must be relative to the +/// top-left corner of the object, and ignore all +/// transformations (position, scale, rotation). +/// The default origin of a text object is (0, 0). /// -//////////////////////////////////////////////////////////// -CSFML_API void sfText_SetScale(sfText* text, float scaleX, float scaleY); - -//////////////////////////////////////////////////////////// -/// Set the orientation of a text -/// -/// \param text : String to modify -/// \param rotation : Angle of rotation, in degrees -/// -//////////////////////////////////////////////////////////// -CSFML_API void sfText_SetRotation(sfText* text, float rotation); - -//////////////////////////////////////////////////////////// -/// Set the local origin of a text, in coordinates -/// relative to its left-top corner -/// -/// \param text : String to modify -/// \param x : X coordinate of the origin -/// \param y : Y coordinate of the origin +/// \param text Text object +/// \param x X coordinate of the new origin +/// \param y Y coordinate of the new origin /// //////////////////////////////////////////////////////////// CSFML_API void sfText_SetOrigin(sfText* text, float x, float y); //////////////////////////////////////////////////////////// -/// Set the color of a text +/// \brief Get the position of a text /// -/// \param text : String to modify -/// \param color : New color +/// \param text Text object +/// +/// \return Current position /// //////////////////////////////////////////////////////////// -CSFML_API void sfText_SetColor(sfText* text, sfColor color); +CSFML_API void sfText_GetPosition(const sfText* text, float* x, float* y); //////////////////////////////////////////////////////////// -/// Set the blending mode for a text +/// \brief Get the orientation of a text /// -/// \param text : String to modify -/// \param mode : New blending mode +/// The rotation is always in the range [0, 360]. /// -//////////////////////////////////////////////////////////// -CSFML_API void sfText_SetBlendMode(sfText* text, sfBlendMode mode); - -//////////////////////////////////////////////////////////// -/// Get the X position of a text -/// -/// \param text : String to read -/// -/// \return Current X position -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfText_GetX(const sfText* text); - -//////////////////////////////////////////////////////////// -/// Get the top Y of a text -/// -/// \param text : String to read -/// -/// \return Current Y position -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfText_GetY(const sfText* text); - -//////////////////////////////////////////////////////////// -/// Get the horizontal scale of a text -/// -/// \param text : String to read -/// -/// \return Current X scale factor (always positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfText_GetScaleX(const sfText* text); - -//////////////////////////////////////////////////////////// -/// Get the vertical scale of a text -/// -/// \param text : String to read -/// -/// \return Current Y scale factor (always positive) -/// -//////////////////////////////////////////////////////////// -CSFML_API float sfText_GetScaleY(const sfText* text); - -//////////////////////////////////////////////////////////// -/// Get the orientation of a text -/// -/// \param text : String to read +/// \param text Text object /// /// \return Current rotation, in degrees /// @@ -219,159 +154,160 @@ CSFML_API float sfText_GetScaleY(const sfText* text); CSFML_API float sfText_GetRotation(const sfText* text); //////////////////////////////////////////////////////////// -/// Get the X position of the origin a text +/// \brief Get the current scale of a text /// -/// \param text : String to read +/// \param text Text object /// -/// \return Current X origin position +/// \return Current scale factors /// //////////////////////////////////////////////////////////// -CSFML_API float sfText_GetOriginX(const sfText* text); +CSFML_API void sfText_GetScale(const sfText* text, float* x, float* y); //////////////////////////////////////////////////////////// -/// Get the top Y of the origin of a text +/// \brief Get the local origin of a text /// -/// \param text : String to read +/// \param text Text object /// -/// \return Current Y origin position +/// \return Current origin /// //////////////////////////////////////////////////////////// -CSFML_API float sfText_GetOriginY(const sfText* text); +CSFML_API void sfText_GetOrigin(const sfText* text, float* x, float* y); //////////////////////////////////////////////////////////// -/// Get the color of a text +/// \brief Move a text by a given offset /// -/// \param text : String to read +/// This function adds to the current position of the object, +/// unlike sfText_SetPosition which overwrites it. /// -/// \return Current color -/// -//////////////////////////////////////////////////////////// -CSFML_API sfColor sfText_GetColor(const sfText* text); - -//////////////////////////////////////////////////////////// -/// Get the current blending mode of a text -/// -/// \param text : String to read -/// -/// \return Current blending mode -/// -//////////////////////////////////////////////////////////// -CSFML_API sfBlendMode sfText_GetBlendMode(const sfText* text); - -//////////////////////////////////////////////////////////// -/// Move a text -/// -/// \param text : String to modify -/// \param offsetX : Offset on the X axis -/// \param offsetY : Offset on the Y axis +/// \param text Text object +/// \param offsetX X offset +/// \param offsetY Y offset /// //////////////////////////////////////////////////////////// CSFML_API void sfText_Move(sfText* text, float offsetX, float offsetY); //////////////////////////////////////////////////////////// -/// Scale a text +/// \brief Rotate a text /// -/// \param text : String to modify -/// \param factorX : Horizontal scaling factor (must be strictly positive) -/// \param factorY : Vertical scaling factor (must be strictly positive) +/// This function adds to the current rotation of the object, +/// unlike sfText_SetRotation which overwrites it. /// -//////////////////////////////////////////////////////////// -CSFML_API void sfText_Scale(sfText* text, float factorX, float factorY); - -//////////////////////////////////////////////////////////// -/// Rotate a text -/// -/// \param text : String to modify -/// \param angle : Angle of rotation, in degrees +/// \param text Text object +/// \param angle Angle of rotation, in degrees /// //////////////////////////////////////////////////////////// CSFML_API void sfText_Rotate(sfText* text, float angle); //////////////////////////////////////////////////////////// -/// Transform a point from global coordinates into the string's local coordinates -/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) +/// \brief Scale a text /// -/// \param text : String object -/// \param pointX : X coordinate of the point to transform -/// \param pointY : Y coordinate of the point to transform -/// \param x : Value to fill with the X coordinate of the converted point -/// \param y : Value to fill with the y coordinate of the converted point +/// This function multiplies the current scale of the object, +/// unlike sfText_SetScale which overwrites it. +/// +/// \param text Text object +/// \param factorX Horizontal scale factor +/// \param factorY Vertical scale factor /// //////////////////////////////////////////////////////////// -CSFML_API void sfText_TransformToLocal(const sfText* text, float pointX, float pointY, float* x, float* y); +CSFML_API void sfText_Scale(sfText* text, float factorX, float factorY); //////////////////////////////////////////////////////////// -/// Transform a point from the string's local coordinates into global coordinates -/// (ie it applies the object's origin, translation, rotation and scale to the point) +/// \brief Get the combined transform of a text /// -/// \param text : String object -/// \param pointX : X coordinate of the point to transform -/// \param pointY : Y coordinate of the point to transform -/// \param x : Value to fill with the X coordinate of the converted point -/// \param y : Value to fill with the y coordinate of the converted point +/// \param text Text object +/// +/// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_API void sfText_TransformToGlobal(const sfText* text, float pointX, float pointY, float* X, float* y); +CSFML_API const sfTransform* sfText_GetTransform(const sfText* text); //////////////////////////////////////////////////////////// -/// Set the string of a text (from a multibyte string) +/// \brief Get the inverse of the combined transform of a text /// -/// \param text : Text to modify -/// \param string : New string +/// \param text Text object +/// +/// \return Inverse of the combined transformations applied to the object +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfTransform* sfText_GetInverseTransform(const sfText* text); + +//////////////////////////////////////////////////////////// +/// \brief Set the string of a text (from an ANSI string) +/// +/// A text's string is empty by default. +/// +/// \param text Text object +/// \param string New string /// //////////////////////////////////////////////////////////// CSFML_API void sfText_SetString(sfText* text, const char* string); //////////////////////////////////////////////////////////// -/// Set the string of a text (from a unicode string) +/// \brief Set the string of a text (from a unicode string) /// -/// \param text : Text to modify -/// \param string : New string +/// \param text Text object +/// \param string New string /// //////////////////////////////////////////////////////////// CSFML_API void sfText_SetUnicodeString(sfText* text, const sfUint32* string); //////////////////////////////////////////////////////////// -/// Set the font of a text +/// \brief Set the font of a text /// -/// \param text : String to modify -/// \param font : Font to use +/// The \a font argument refers to a texture that must +/// exist as long as the text uses it. Indeed, the text +/// doesn't store its own copy of the font, but rather keeps +/// a pointer to the one that you passed to this function. +/// If the font is destroyed and the text tries to +/// use it, the behaviour is undefined. +/// Texts have a valid font by default, which the built-in +/// sfFont_GetDefaultFont(). +/// +/// \param text Text object +/// \param font New font /// //////////////////////////////////////////////////////////// CSFML_API void sfText_SetFont(sfText* text, const sfFont* font); //////////////////////////////////////////////////////////// -/// Set the size of a text +/// \brief Set the character size of a text /// -/// \param text : String to modify -/// \param size : New size, in pixels +/// The default size is 30. +/// +/// \param text Text object +/// \param size New character size, in pixels /// //////////////////////////////////////////////////////////// CSFML_API void sfText_SetCharacterSize(sfText* text, unsigned int size); //////////////////////////////////////////////////////////// -/// Set the style of a text +/// \brief Set the style of a text /// -/// \param text : String to modify -/// \param style : New style (see sfTextStyle enum) +/// You can pass a combination of one or more styles, for +/// example sfTextBold | sfTextItalic. +/// The default style is sfTextRegular. +/// +/// \param text Text object +/// \param style New style /// //////////////////////////////////////////////////////////// CSFML_API void sfText_SetStyle(sfText* text, sfUint32 style); //////////////////////////////////////////////////////////// -/// Get the string of a text (returns a unicode string) +/// \brief Set the global color of a text /// -/// \param text : String to read +/// By default, the text's color is opaque white. /// -/// \return String as UTF-32 +/// \param text Text object +/// \param color New color of the text /// //////////////////////////////////////////////////////////// -CSFML_API const sfUint32* sfText_GetUnicodeString(const sfText* text); +CSFML_API void sfText_SetColor(sfText* text, sfColor color); //////////////////////////////////////////////////////////// -/// Get the text of a text (returns an ANSI string) +/// \brief Get the text of a text (returns an ANSI string) /// -/// \param text : String to read +/// \param text Text object /// /// \return String an a locale-dependant ANSI string /// @@ -379,9 +315,19 @@ CSFML_API const sfUint32* sfText_GetUnicodeString(const sfText* text); CSFML_API const char* sfText_GetString(const sfText* text); //////////////////////////////////////////////////////////// -/// Get the font used by a text +/// \brief Get the string of a text (returns a unicode string) /// -/// \param text : String to read +/// \param text Text object +/// +/// \return String as UTF-32 +/// +//////////////////////////////////////////////////////////// +CSFML_API const sfUint32* sfText_GetUnicodeString(const sfText* text); + +//////////////////////////////////////////////////////////// +/// \brief Get the font used by a text +/// +/// \param text Text object /// /// \return Pointer to the font /// @@ -389,9 +335,9 @@ CSFML_API const char* sfText_GetString(const sfText* text); CSFML_API const sfFont* sfText_GetFont(const sfText* text); //////////////////////////////////////////////////////////// -/// Get the size of the characters of a text +/// \brief Get the size of the characters of a text /// -/// \param text : String to read +/// \param text Text object /// /// \return Size of the characters /// @@ -399,9 +345,9 @@ CSFML_API const sfFont* sfText_GetFont(const sfText* text); CSFML_API unsigned int sfText_GetCharacterSize(const sfText* text); //////////////////////////////////////////////////////////// -/// Get the style of a text +/// \brief Get the style of a text /// -/// \param text : String to read +/// \param text Text object /// /// \return Current string style (see sfTextStyle enum) /// @@ -409,27 +355,32 @@ CSFML_API unsigned int sfText_GetCharacterSize(const sfText* text); CSFML_API sfUint32 sfText_GetStyle(const sfText* text); //////////////////////////////////////////////////////////// -/// Return the visual position of the Index-th character of the text, -/// in coordinates relative to the string -/// (note : translation, origin, rotation and scale are not applied) +/// \brief Get the global color of a text /// -/// \param text : String to read -/// \param index : Index of the character -/// \param x : Value to fill with the X coordinate of the position -/// \param y : Value to fill with the y coordinate of the position +/// \param text Text object +/// +/// \return Global color of the text /// //////////////////////////////////////////////////////////// -CSFML_API void sfText_GetCharacterPos(const sfText* text, size_t index, float* x, float* y); +CSFML_API sfColor sfText_GetColor(const sfText* text); //////////////////////////////////////////////////////////// -/// Get the bounding rectangle of a text on screen +/// \brief Return the position of the \a index-th character in a text /// -/// \param text : String to read +/// This function computes the visual position of a character +/// from its index in the string. The returned position is +/// in global coordinates (translation, rotation, scale and +/// origin are applied). +/// If \a index is out of range, the position of the end of +/// the string is returned. /// -/// \return Rectangle contaning the string in screen coordinates +/// \param text Text object +/// \param index Index of the character +/// \param x The returned x position of the character +/// \param y The returned y position of the character /// //////////////////////////////////////////////////////////// -CSFML_API sfFloatRect sfText_GetRect(const sfText* text); +CSFML_API void sfText_FindCharacterPos(const sfText* text, size_t index, float* x, float* y); #endif // SFML_TEXT_H diff --git a/include/SFML/Graphics/Texture.h b/include/SFML/Graphics/Texture.h index 5720912..b30e43b 100644 --- a/include/SFML/Graphics/Texture.h +++ b/include/SFML/Graphics/Texture.h @@ -37,10 +37,10 @@ //////////////////////////////////////////////////////////// -/// Create a new texture +/// \brief Create a new texture /// -/// \param width : Texture width -/// \param height : Texture height +/// \param width Texture width +/// \param height Texture height /// /// \return A new sfTexture object, or NULL if it failed /// @@ -48,10 +48,10 @@ CSFML_API sfTexture* sfTexture_Create(unsigned int width, unsigned int height); //////////////////////////////////////////////////////////// -/// Create a new texture from a file +/// \brief Create a new texture from a file /// -/// \param filename : Path of the image file to load -/// \param area : Area of the source image to load (NULL to load the entire image) +/// \param filename Path of the image file to load +/// \param area Area of the source image to load (NULL to load the entire image) /// /// \return A new sfTexture object, or NULL if it failed /// @@ -59,11 +59,11 @@ CSFML_API sfTexture* sfTexture_Create(unsigned int width, unsigned int height); CSFML_API sfTexture* sfTexture_CreateFromFile(const char* filename, const sfIntRect* area); //////////////////////////////////////////////////////////// -/// Create a new texture from a file in memory +/// \brief Create a new texture from a file in memory /// -/// \param data : Pointer to the file data in memory -/// \param sizeInBytes : Size of the data to load, in bytes -/// \param area : Area of the source image to load (NULL to load the entire image) +/// \param data Pointer to the file data in memory +/// \param sizeInBytes Size of the data to load, in bytes +/// \param area Area of the source image to load (NULL to load the entire image) /// /// \return A new sfTexture object, or NULL if it failed /// @@ -71,10 +71,10 @@ CSFML_API sfTexture* sfTexture_CreateFromFile(const char* filename, const sfIntR CSFML_API sfTexture* sfTexture_CreateFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area); //////////////////////////////////////////////////////////// -/// Create a new texture from a custom stream +/// \brief Create a new texture from a custom stream /// -/// \param stream : Source stream to read from -/// \param area : Area of the source image to load (NULL to load the entire image) +/// \param stream Source stream to read from +/// \param area Area of the source image to load (NULL to load the entire image) /// /// \return A new sfTexture object, or NULL if it failed /// @@ -82,10 +82,10 @@ CSFML_API sfTexture* sfTexture_CreateFromMemory(const void* data, size_t sizeInB CSFML_API sfTexture* sfTexture_CreateFromStream(sfInputStream* stream, const sfIntRect* area); //////////////////////////////////////////////////////////// -/// Create a new texture from an image +/// \brief Create a new texture from an image /// -/// \param image : Image to upload to the texture -/// \param area : Area of the source image to load (NULL to load the entire image) +/// \param image Image to upload to the texture +/// \param area Area of the source image to load (NULL to load the entire image) /// /// \return A new sfTexture object, or NULL if it failed /// @@ -93,9 +93,9 @@ CSFML_API sfTexture* sfTexture_CreateFromStream(sfInputStream* stream, const sfI CSFML_API sfTexture* sfTexture_CreateFromImage(const sfImage* image, const sfIntRect* area); //////////////////////////////////////////////////////////// -/// Copy an existing texture +/// \brief Copy an existing texture /// -/// \param texture : Texture to copy +/// \param texture Texture to copy /// /// \return Copied object /// @@ -103,17 +103,17 @@ CSFML_API sfTexture* sfTexture_CreateFromImage(const sfImage* image, const sfInt CSFML_API sfTexture* sfTexture_Copy(sfTexture* texture); //////////////////////////////////////////////////////////// -/// Destroy an existing texture +/// \brief Destroy an existing texture /// -/// \param texture : Texture to delete +/// \param texture Texture to delete /// //////////////////////////////////////////////////////////// CSFML_API void sfTexture_Destroy(sfTexture* texture); //////////////////////////////////////////////////////////// -/// Return the width of the texture +/// \brief Return the width of the texture /// -/// \param texture : Texture to read +/// \param texture Texture to read /// /// \return Width in pixels /// @@ -121,9 +121,9 @@ CSFML_API void sfTexture_Destroy(sfTexture* texture); CSFML_API unsigned int sfTexture_GetWidth(const sfTexture* texture); //////////////////////////////////////////////////////////// -/// Return the height of the texture +/// \brief Return the height of the texture /// -/// \param texture : Texture to read +/// \param texture Texture to read /// /// \return Height in pixels /// @@ -131,9 +131,9 @@ CSFML_API unsigned int sfTexture_GetWidth(const sfTexture* texture); CSFML_API unsigned int sfTexture_GetHeight(const sfTexture* texture); //////////////////////////////////////////////////////////// -/// Copy a texture's pixels to an image +/// \brief Copy a texture's pixels to an image /// -/// \param texture : Texture to copy +/// \param texture Texture to copy /// /// \return Image containing the texture's pixels /// @@ -141,72 +141,72 @@ CSFML_API unsigned int sfTexture_GetHeight(const sfTexture* texture); CSFML_API sfImage* sfTexture_CopyToImage(const sfTexture* texture); //////////////////////////////////////////////////////////// -/// Update a texture from an array of pixels +/// \brief Update a texture from an array of pixels /// -/// \param texture : Texture to update -/// \param pixels : Array of pixels to copy to the texture -/// \param width : Width of the pixel region contained in \a pixels -/// \param height : Height of the pixel region contained in \a pixels -/// \param x : X offset in the texture where to copy the source pixels -/// \param y : Y offset in the texture where to copy the source pixels +/// \param texture Texture to update +/// \param pixels Array of pixels to copy to the texture +/// \param width Width of the pixel region contained in \a pixels +/// \param height Height of the pixel region contained in \a pixels +/// \param x X offset in the texture where to copy the source pixels +/// \param y Y offset in the texture where to copy the source pixels /// //////////////////////////////////////////////////////////// CSFML_API void sfTexture_UpdateFromPixels(sfTexture* texture, const sfUint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y); //////////////////////////////////////////////////////////// -/// Update a texture from an image +/// \brief Update a texture from an image /// -/// \param texture : Texture to update -/// \param image : Image to copy to the texture -/// \param x : X offset in the texture where to copy the source pixels -/// \param y : Y offset in the texture where to copy the source pixels +/// \param texture Texture to update +/// \param image Image to copy to the texture +/// \param x X offset in the texture where to copy the source pixels +/// \param y Y offset in the texture where to copy the source pixels /// //////////////////////////////////////////////////////////// CSFML_API void sfTexture_UpdateFromImage(sfTexture* texture, const sfImage* image, unsigned int x, unsigned int y); //////////////////////////////////////////////////////////// -/// Update a texture from the contents of a window +/// \brief Update a texture from the contents of a window /// -/// \param texture : Texture to update -/// \param window : Window to copy to the texture -/// \param x : X offset in the texture where to copy the source pixels -/// \param y : Y offset in the texture where to copy the source pixels +/// \param texture Texture to update +/// \param window Window to copy to the texture +/// \param x X offset in the texture where to copy the source pixels +/// \param y Y offset in the texture where to copy the source pixels /// //////////////////////////////////////////////////////////// CSFML_API void sfTexture_UpdateFromWindow(sfTexture* texture, const sfWindow* window, unsigned int x, unsigned int y); //////////////////////////////////////////////////////////// -/// Update a texture from the contents of a render-window +/// \brief Update a texture from the contents of a render-window /// -/// \param texture : Texture to update -/// \param renderWindow : Render-window to copy to the texture -/// \param x : X offset in the texture where to copy the source pixels -/// \param y : Y offset in the texture where to copy the source pixels +/// \param texture Texture to update +/// \param renderWindow Render-window to copy to the texture +/// \param x X offset in the texture where to copy the source pixels +/// \param y Y offset in the texture where to copy the source pixels /// //////////////////////////////////////////////////////////// CSFML_API void sfTexture_UpdateFromRenderWindow(sfTexture* texture, const sfRenderWindow* renderWindow, unsigned int x, unsigned int y); //////////////////////////////////////////////////////////// -/// Activate a texture for rendering +/// \brief Activate a texture for rendering /// -/// \param texture : Texture to bind +/// \param texture Texture to bind /// //////////////////////////////////////////////////////////// CSFML_API void sfTexture_Bind(const sfTexture* texture); //////////////////////////////////////////////////////////// -/// Enable or disable the smooth filter on a texture +/// \brief Enable or disable the smooth filter on a texture /// -/// \param texture : The texture object -/// \param smooth : sfTrue to enable smoothing, sfFalse to disable it +/// \param texture The texture object +/// \param smooth sfTrue to enable smoothing, sfFalse to disable it /// //////////////////////////////////////////////////////////// CSFML_API void sfTexture_SetSmooth(sfTexture* texture, sfBool smooth); //////////////////////////////////////////////////////////// -/// Tell whether the smooth filter is enabled or not for a texture +/// \brief Tell whether the smooth filter is enabled or not for a texture /// -/// \param texture : The texture object +/// \param texture The texture object /// /// \return sfTrue if smoothing is enabled, sfFalse if it is disabled /// @@ -214,10 +214,43 @@ CSFML_API void sfTexture_SetSmooth(sfTexture* texture, sfBool smooth); CSFML_API sfBool sfTexture_IsSmooth(const sfTexture* texture); //////////////////////////////////////////////////////////// -/// Convert a rectangle of pixels into texture coordinates +/// \brief Enable or disable repeating for a texture /// -/// \param texture : Texture to use for conversion -/// \param rectangle : Rectangle to convert +/// Repeating is involved when using texture coordinates +/// outside the texture rectangle [0, 0, width, height]. +/// In this case, if repeat mode is enabled, the whole texture +/// will be repeated as many times as needed to reach the +/// coordinate (for example, if the X texture coordinate is +/// 3 * width, the texture will be repeated 3 times). +/// If repeat mode is disabled, the "extra space" will instead +/// be filled with border pixels. +/// Warning: on very old graphics cards, white pixels may appear +/// when the texture is repeated. With such cards, repeat mode +/// can be used reliably only if the texture has power-of-two +/// dimensions (such as 256x128). +/// Repeating is disabled by default. +/// +/// \param texture The texture object +/// \param repeated True to repeat the texture, false to disable repeating +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfTexture_SetRepeated(sfTexture* texture, sfBool repeated); + +//////////////////////////////////////////////////////////// +/// \brief Tell whether a texture is repeated or not +/// +/// \param texture The texture object +/// +/// \return sfTrue if repeat mode is enabled, sfFalse if it is disabled +/// +//////////////////////////////////////////////////////////// +CSFML_API sfBool sfTexture_IsRepeated(const sfTexture* texture); + +//////////////////////////////////////////////////////////// +/// \brief Convert a rectangle of pixels into texture coordinates +/// +/// \param texture Texture to use for conversion +/// \param rectangle Rectangle to convert /// /// \return Texture coordinates corresponding to \a rectangle /// @@ -225,7 +258,7 @@ CSFML_API sfBool sfTexture_IsSmooth(const sfTexture* texture); CSFML_API sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle); //////////////////////////////////////////////////////////// -/// Get the maximum texture size allowed +/// \brief Get the maximum texture size allowed /// /// \return Maximum size allowed for textures, in pixels /// diff --git a/include/SFML/Graphics/Transform.h b/include/SFML/Graphics/Transform.h new file mode 100644 index 0000000..e3343b5 --- /dev/null +++ b/include/SFML/Graphics/Transform.h @@ -0,0 +1,222 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_TRANSFORM_H +#define SFML_TRANSFORM_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +//////////////////////////////////////////////////////////// +/// \brief Create a new transform +/// +/// This function creates an identity transform. +/// +/// \return A new sfTransform object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfTransform* sfTransform_Create(void); + +//////////////////////////////////////////////////////////// +/// \brief Create a new transform from a matrix +/// +/// +/// \param a00 Element (0, 0) of the matrix +/// \param a01 Element (0, 1) of the matrix +/// \param a02 Element (0, 2) of the matrix +/// \param a10 Element (1, 0) of the matrix +/// \param a11 Element (1, 1) of the matrix +/// \param a12 Element (1, 2) of the matrix +/// \param a20 Element (2, 0) of the matrix +/// \param a21 Element (2, 1) of the matrix +/// \param a22 Element (2, 2) of the matrix +/// +/// \return A new sfTransform object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfTransform* sfTransform_CreateFromMatrix(float a00, float a01, float a02, + float a10, float a11, float a12, + float a20, float a21, float a22); + +//////////////////////////////////////////////////////////// +/// \brief Copy an existing transform +/// +/// \param transform Transform to copy +/// +/// \return Copied object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfTransform* sfTransform_Copy(sfTransform* transform); + +//////////////////////////////////////////////////////////// +/// \brief Destroy an existing transform +/// +/// \param transform Transform to delete +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfTransform_Destroy(sfTransform* transform); + +//////////////////////////////////////////////////////////// +/// \brief Return the 4x4 matrix of a transform +/// +/// This function returns a pointer to an array of 16 floats +/// containing the transform elements as a 4x4 matrix, which +/// is directly compatible with OpenGL functions. +/// +/// \code +/// sfTransform* transform = ...; +/// glLoadMatrixf(sfTransform_GetMatrix(transform)); +/// \endcode +/// +/// \param transform Transform object +/// +/// \return Pointer to a 4x4 matrix +/// +//////////////////////////////////////////////////////////// +const float* sfTransform_GetMatrix(const sfTransform* transform); + +//////////////////////////////////////////////////////////// +/// \brief Return the inverse of a transform +/// +/// If the inverse cannot be computed, a new identity transform +/// is returned. +/// +/// \param transform Transform object +/// +/// \return A new transform which is the inverse of self +/// +//////////////////////////////////////////////////////////// +sfTransform* sfTransform_GetInverse(const sfTransform* transform); + +//////////////////////////////////////////////////////////// +/// \brief Apply a transform to a 2D point +/// +/// \param transform Transform object +/// \param x X coordinate of the point to transform +/// \param y Y coordinate of the point to transform +/// \param transformedX X coordinate of the transformed point +/// \param transformedY Y coordinate of the transformed point +/// +//////////////////////////////////////////////////////////// +void sfTransform_TransformPoint(const sfTransform* transform, float x, float y, float* transformedX, float* transformedY); + +//////////////////////////////////////////////////////////// +/// \brief Apply a transform to a rectangle +/// +/// Since SFML doesn't provide support for oriented rectangles, +/// the result of this function is always an axis-aligned +/// rectangle. Which means that if the transform contains a +/// rotation, the bounding rectangle of the transformed rectangle +/// is returned. +/// +/// \param transform Transform object +/// \param rectangle Rectangle to transform +/// \param transformedRectangle Transformed rectangle +/// +//////////////////////////////////////////////////////////// +void sfTransform_TransformRect(const sfTransform* transform, sfFloatRect rectangle, sfFloatRect* transformedRectangle); + +//////////////////////////////////////////////////////////// +/// \brief Combine two transforms +/// +/// The result is a transform that is equivalent to applying +/// \a left followed by \a right. Mathematically, it is +/// equivalent to a matrix multiplication. +/// +/// \param left First transform to combine +/// \param right Second transform to combine +/// \param result Result of the operation (must point to a valid sfTransform instance) +/// +//////////////////////////////////////////////////////////// +void sfTransform_Combine(const sfTransform* left, const sfTransform* right, sfTransform* result); + +//////////////////////////////////////////////////////////// +/// \brief Combine a transform with a translation +/// +/// \param transform Transform object +/// \param x Offset to apply on X axis +/// \param y Offset to apply on Y axis +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfTransform_Translate(sfTransform* transform, float x, float y); + +//////////////////////////////////////////////////////////// +/// \brief Combine the current transform with a rotation +/// +/// \param transform Transform object +/// \param angle Rotation angle, in degrees +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfTransform_Rotate(sfTransform* transform, float angle); + +//////////////////////////////////////////////////////////// +/// \brief Combine the current transform with a rotation +/// +/// The center of rotation is provided for convenience as a second +/// argument, so that you can build rotations around arbitrary points +/// more easily (and efficiently) than the usual +/// [Translate(-center), Rotate(angle), Translate(center)]. +/// +/// \param transform Transform object +/// \param angle Rotation angle, in degrees +/// \param centerX X coordinate of the center of rotation +/// \param centerY Y coordinate of the center of rotation +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfTransform_RotateWithCenter(sfTransform* transform, float angle, float centerX, float centerY); + +//////////////////////////////////////////////////////////// +/// \brief Combine the current transform with a scaling +/// +/// \param transform Transform object +/// \param scaleX Scaling factor on the X axis +/// \param scaleY Scaling factor on the Y axis +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfTransform_Scale(sfTransform* transform, float scaleX, float scaleY); + +//////////////////////////////////////////////////////////// +/// \brief Combine the current transform with a scaling +/// +/// The center of scaling is provided for convenience as a second +/// argument, so that you can build scaling around arbitrary points +/// more easily (and efficiently) than the usual +/// [Translate(-center), Scale(factors), Translate(center)] +/// +/// \param transform Transform object +/// \param scaleX Scaling factor on X axis +/// \param scaleY Scaling factor on Y axis +/// \param centerX X coordinate of the center of scaling +/// \param centerY Y coordinate of the center of scaling +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfTransform_ScaleWithCenter(sfTransform* transform, float scaleX, float scaleY, float centerX, float centerY); + + +#endif // SFML_TEXTURE_H diff --git a/include/SFML/Graphics/Types.h b/include/SFML/Graphics/Types.h index e1f725a..81c55b2 100644 --- a/include/SFML/Graphics/Types.h +++ b/include/SFML/Graphics/Types.h @@ -26,15 +26,20 @@ #define SFML_GRAPHICS_TYPES_H +typedef struct sfCircleShape sfCircleShape; +typedef struct sfConvexShape sfConvexShape; typedef struct sfFont sfFont; typedef struct sfImage sfImage; typedef struct sfShader sfShader; +typedef struct sfRectangleShape sfRectangleShape; typedef struct sfRenderTexture sfRenderTexture; typedef struct sfRenderWindow sfRenderWindow; typedef struct sfShape sfShape; typedef struct sfSprite sfSprite; typedef struct sfText sfText; typedef struct sfTexture sfTexture; +typedef struct sfTransform sfTransform; +typedef struct sfVertexArray sfVertexArray; typedef struct sfView sfView; diff --git a/include/SFML/Graphics/Vertex.h b/include/SFML/Graphics/Vertex.h new file mode 100644 index 0000000..d43dd3c --- /dev/null +++ b/include/SFML/Graphics/Vertex.h @@ -0,0 +1,47 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_VERTEX_H +#define SFML_VERTEX_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +//////////////////////////////////////////////////////////// +/// Define a point with color and texture coordinates +//////////////////////////////////////////////////////////// +typedef struct +{ + float X; ///< X coordinate of the position of the vertex + float Y; ///< Y coordinate of the position of the vertex + sfColor Color; ///< Color of the vertex + float TexCoordX; ///< X coordinate of the texture's pixel to map to the vertex + float TexCoordY; ///< Y coordinate of the texture's pixel to map to the vertex +} sfVertex; + + +#endif // SFML_VERTEX_H diff --git a/include/SFML/Graphics/VertexArray.h b/include/SFML/Graphics/VertexArray.h new file mode 100644 index 0000000..bf3f56c --- /dev/null +++ b/include/SFML/Graphics/VertexArray.h @@ -0,0 +1,167 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_VERTEXARRAY_H +#define SFML_VERTEXARRAY_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +/// \brief Create a new vertex array +/// +/// \return A new sfVertexArray object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfVertexArray* sfVertexArray_Create(void); + +//////////////////////////////////////////////////////////// +/// \brief Copy an existing vertex array +/// +/// \param vertexArray Vertex array to copy +/// +/// \return Copied object +/// +//////////////////////////////////////////////////////////// +CSFML_API sfVertexArray* sfTransform_Copy(sfVertexArray* vertexArray); + +//////////////////////////////////////////////////////////// +/// \brief Destroy an existing vertex array +/// +/// \param vertexArray Vertex array to delete +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfVertexArray_Destroy(sfVertexArray* vertexArray); + +//////////////////////////////////////////////////////////// +/// \brief Return the vertex count of a vertex array +/// +/// \param vertexArray Vertex array object +/// +/// \return Number of vertices in the array +/// +//////////////////////////////////////////////////////////// +CSFML_API unsigned int sfVertexArray_GetVertexCount(const sfVertexArray* vertexArray); + +//////////////////////////////////////////////////////////// +/// \brief Get access to a vertex by its index +/// +/// This function doesn't check \a index, it must be in range +/// [0, vertex count - 1]. The behaviour is undefined +/// otherwise. +/// +/// \param vertexArray Vertex array object +/// \param index Index of the vertex to get +/// +/// \return Pointer to the index-th vertex +/// +//////////////////////////////////////////////////////////// +CSFML_API sfVertex* sfVertexArray_At(sfVertexArray* vertexArray, unsigned int index); + +//////////////////////////////////////////////////////////// +/// \brief Clear a vertex array +/// +/// This function removes all the vertices from the array. +/// It doesn't deallocate the corresponding memory, so that +/// adding new vertices after clearing doesn't involve +/// reallocating all the memory. +/// +/// \param vertexArray Vertex array object +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfVertexArray_Clear(sfVertexArray* vertexArray); + +//////////////////////////////////////////////////////////// +/// \brief Resize the vertex array +/// +/// If \a vertexCount is greater than the current size, the previous +/// vertices are kept and new (default-constructed) vertices are +/// added. +/// If \a vertexCount is less than the current size, existing vertices +/// are removed from the array. +/// +/// \param vertexArray Vertex array objet +/// \param vertexCount New size of the array (number of vertices) +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfVertexArray_Resize(sfVertexArray* vertexArray, unsigned int vertexCount); + +//////////////////////////////////////////////////////////// +/// \brief Add a vertex to a vertex array array +/// +/// \param vertexArray Vertex array objet +/// \param vertex Vertex to add +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfVertexArray_Append(sfVertexArray* vertexArray, sfVertex vertex); + +//////////////////////////////////////////////////////////// +/// \brief Set the type of primitives of a vertex array +/// +/// This function defines how the vertices must be interpreted +/// when it's time to draw them: +/// \li As points +/// \li As lines +/// \li As triangles +/// \li As quads +/// The default primitive type is sfPoints. +/// +/// \param vertexArray Vertex array objet +/// \param type Type of primitive +/// +//////////////////////////////////////////////////////////// +CSFML_API void sfVertexArray_SetPrimitiveType(sfVertexArray* vertexArray, sfPrimitiveType type); + +//////////////////////////////////////////////////////////// +/// \brief Get the type of primitives drawn by a vertex array +/// +/// \param vertexArray Vertex array objet +/// +/// \return Primitive type +/// +//////////////////////////////////////////////////////////// +CSFML_API sfPrimitiveType sfVertexArray_GetPrimitiveType(sfVertexArray* vertexArray); + +//////////////////////////////////////////////////////////// +/// \brief Compute the bounding rectangle of a vertex array +/// +/// This function returns the axis-aligned rectangle that +/// contains all the vertices of the array. +/// +/// \param vertexArray Vertex array objet +/// +/// \return Bounding rectangle of the vertex array +/// +//////////////////////////////////////////////////////////// +CSFML_API sfFloatRect sfVertexArray_GetBounds(sfVertexArray* vertexArray); + + +#endif // SFML_VERTEXARRAY_H diff --git a/include/SFML/Window/Window.h b/include/SFML/Window/Window.h index 3495f9f..30a153c 100644 --- a/include/SFML/Window/Window.h +++ b/include/SFML/Window/Window.h @@ -119,7 +119,7 @@ CSFML_API void sfWindow_Destroy(sfWindow* window); /// After calling this function, the sfWindow object remains /// valid, you must call sfWindow_Destroy to actually delete it. /// All other functions such as sfWindow_PollEvent or sfWindow_Display -/// will still work (i.e. you don't have to test sfWindow_IsOpened +/// will still work (i.e. you don't have to test sfWindow_IsOpen /// every time), and will have no effect on closed windows. /// /// \param window Window object @@ -139,7 +139,7 @@ CSFML_API void sfWindow_Close(sfWindow* window); /// \return sfTrue if the window is opened, sfFalse if it has been closed /// //////////////////////////////////////////////////////////// -CSFML_API sfBool sfWindow_IsOpened(const sfWindow* window); +CSFML_API sfBool sfWindow_IsOpen(const sfWindow* window); //////////////////////////////////////////////////////////// /// \brief Get the width of the rendering region of a window @@ -356,21 +356,6 @@ CSFML_API void sfWindow_Display(sfWindow* window); //////////////////////////////////////////////////////////// CSFML_API void sfWindow_SetFramerateLimit(sfWindow* window, unsigned int limit); -//////////////////////////////////////////////////////////// -/// \brief Get the duration of the last frame -/// -/// This function returns the time elapsed between the last -/// two calls to sfWindow_Display. -/// This can be useful for calculating the framerate, or for -/// updating the application's objects. -/// -/// \param window Window object -/// -/// \return Time elapsed in last frame, in milliseconds -/// -//////////////////////////////////////////////////////////// -CSFML_API sfUint32 sfWindow_GetFrameTime(const sfWindow* window); - //////////////////////////////////////////////////////////// /// \brief Change the joystick threshold /// diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index 07c6883..e71ea08 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -125,9 +125,9 @@ void sfMusic_Stop(sfMusic* music) //////////////////////////////////////////////////////////// -unsigned int sfMusic_GetChannelsCount(const sfMusic* music) +unsigned int sfMusic_GetChannelCount(const sfMusic* music) { - CSFML_CALL_RETURN(music, GetChannelsCount(), 0); + CSFML_CALL_RETURN(music, GetChannelCount(), 0); } diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index de43ac4..528ed93 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -80,11 +80,11 @@ CSFML_API sfSoundBuffer* sfSoundBuffer_CreateFromStream(sfInputStream* stream) //////////////////////////////////////////////////////////// -sfSoundBuffer* sfSoundBuffer_CreateFromSamples(const sfInt16* samples, size_t samplesCount, unsigned int channelsCount, unsigned int sampleRate) +sfSoundBuffer* sfSoundBuffer_CreateFromSamples(const sfInt16* samples, size_t sampleCount, unsigned int channelsCount, unsigned int sampleRate) { sfSoundBuffer* buffer = new sfSoundBuffer; - if (!buffer->This.LoadFromSamples(samples, samplesCount, channelsCount, sampleRate)) + if (!buffer->This.LoadFromSamples(samples, sampleCount, channelsCount, sampleRate)) { delete buffer; buffer = NULL; @@ -125,9 +125,9 @@ const sfInt16* sfSoundBuffer_GetSamples(const sfSoundBuffer* soundBuffer) //////////////////////////////////////////////////////////// -size_t sfSoundBuffer_GetSamplesCount(const sfSoundBuffer* soundBuffer) +size_t sfSoundBuffer_GetSampleCount(const sfSoundBuffer* soundBuffer) { - CSFML_CALL_RETURN(soundBuffer, GetSamplesCount(), 0) + CSFML_CALL_RETURN(soundBuffer, GetSampleCount(), 0) } @@ -139,9 +139,9 @@ unsigned int sfSoundBuffer_GetSampleRate(const sfSoundBuffer* soundBuffer) //////////////////////////////////////////////////////////// -unsigned int sfSoundBuffer_GetChannelsCount(const sfSoundBuffer* soundBuffer) +unsigned int sfSoundBuffer_GetChannelCount(const sfSoundBuffer* soundBuffer) { - CSFML_CALL_RETURN(soundBuffer, GetChannelsCount(), 0) + CSFML_CALL_RETURN(soundBuffer, GetChannelCount(), 0) } diff --git a/src/SFML/Audio/SoundRecorderStruct.h b/src/SFML/Audio/SoundRecorderStruct.h index 9bf5b13..a596f84 100644 --- a/src/SFML/Audio/SoundRecorderStruct.h +++ b/src/SFML/Audio/SoundRecorderStruct.h @@ -40,14 +40,14 @@ class sfSoundRecorderImpl : public sf::SoundRecorder { public : - sfSoundRecorderImpl(sfSoundRecorderStartCallback OnStart, - sfSoundRecorderProcessCallback OnProcess, - sfSoundRecorderStopCallback OnStop, - void* UserData) : - myStartCallback (OnStart), - myProcessCallback(OnProcess), - myStopCallback (OnStop), - myUserData (UserData) + sfSoundRecorderImpl(sfSoundRecorderStartCallback onStart, + sfSoundRecorderProcessCallback onProcess, + sfSoundRecorderStopCallback onStop, + void* userData) : + myStartCallback (onStart), + myProcessCallback(onProcess), + myStopCallback (onStop), + myUserData (userData) { } @@ -61,10 +61,10 @@ private : return true; } - virtual bool OnProcessSamples(const sf::Int16* Samples, std::size_t SamplesCount) + virtual bool OnProcessSamples(const sf::Int16* samples, std::size_t sampleCount) { if (myProcessCallback) - return myProcessCallback(Samples, SamplesCount, myUserData) == sfTrue; + return myProcessCallback(samples, sampleCount, myUserData) == sfTrue; else return true; } @@ -87,11 +87,11 @@ private : //////////////////////////////////////////////////////////// struct sfSoundRecorder { - sfSoundRecorder(sfSoundRecorderStartCallback OnStart, - sfSoundRecorderProcessCallback OnProcess, - sfSoundRecorderStopCallback OnStop, - void* UserData) : - This(OnStart, OnProcess, OnStop, UserData) + sfSoundRecorder(sfSoundRecorderStartCallback onStart, + sfSoundRecorderProcessCallback onProcess, + sfSoundRecorderStopCallback onStop, + void* userData) : + This(onStart, onProcess, onStop, userData) { } diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 932867e..c0f6b1f 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -33,11 +33,11 @@ //////////////////////////////////////////////////////////// sfSoundStream* sfSoundStream_Create(sfSoundStreamGetDataCallback onGetData, sfSoundStreamSeekCallback onSeek, - unsigned int channelsCount, + unsigned int channelCount, unsigned int sampleRate, void* userData) { - return new sfSoundStream(onGetData, onSeek, channelsCount, sampleRate, userData); + return new sfSoundStream(onGetData, onSeek, channelCount, sampleRate, userData); } @@ -79,9 +79,9 @@ sfSoundStatus sfSoundStream_GetStatus(const sfSoundStream* soundStream) //////////////////////////////////////////////////////////// -unsigned int sfSoundStream_GetChannelsCount(const sfSoundStream* soundStream) +unsigned int sfSoundStream_GetChannelCount(const sfSoundStream* soundStream) { - CSFML_CALL_RETURN(soundStream, GetChannelsCount(), 0); + CSFML_CALL_RETURN(soundStream, GetChannelCount(), 0); } diff --git a/src/SFML/Audio/SoundStreamStruct.h b/src/SFML/Audio/SoundStreamStruct.h index a5a1828..cbafcac 100644 --- a/src/SFML/Audio/SoundStreamStruct.h +++ b/src/SFML/Audio/SoundStreamStruct.h @@ -39,35 +39,35 @@ class sfSoundStreamImpl : public sf::SoundStream { public : - sfSoundStreamImpl(sfSoundStreamGetDataCallback OnGetData, - sfSoundStreamSeekCallback OnSeek, - unsigned int ChannelsCount, - unsigned int SampleRate, - void* UserData) : - myGetDataCallback(OnGetData), - mySeekCallback (OnSeek), - myUserData (UserData) + sfSoundStreamImpl(sfSoundStreamGetDataCallback onGetData, + sfSoundStreamSeekCallback onSeek, + unsigned int channelCount, + unsigned int sampleRate, + void* userData) : + myGetDataCallback(onGetData), + mySeekCallback (onSeek), + myUserData (userData) { - Initialize(ChannelsCount, SampleRate); + Initialize(channelCount, sampleRate); } private : - virtual bool OnGetData(Chunk& Data) + virtual bool OnGetData(Chunk& data) { - sfSoundStreamChunk Chunk = {NULL, 0}; - bool Continue = (myGetDataCallback(&Chunk, myUserData) == sfTrue); + sfSoundStreamChunk chunk = {NULL, 0}; + bool ok = (myGetDataCallback(&chunk, myUserData) == sfTrue); - Data.Samples = Chunk.Samples; - Data.NbSamples = Chunk.NbSamples; + data.Samples = chunk.Samples; + data.SampleCount = chunk.SampleCount; - return Continue; + return ok; } - virtual void OnSeek(sfUint32 TimeOffset) + virtual void OnSeek(sfUint32 timeOffset) { if (mySeekCallback) - mySeekCallback(TimeOffset, myUserData); + mySeekCallback(timeOffset, myUserData); } sfSoundStreamGetDataCallback myGetDataCallback; @@ -81,12 +81,12 @@ private : //////////////////////////////////////////////////////////// struct sfSoundStream { - sfSoundStream(sfSoundStreamGetDataCallback OnGetData, - sfSoundStreamSeekCallback OnSeek, - unsigned int ChannelsCount, - unsigned int SampleRate, - void* UserData) : - This(OnGetData, OnSeek, ChannelsCount, SampleRate, UserData) + sfSoundStream(sfSoundStreamGetDataCallback onGetData, + sfSoundStreamSeekCallback onSeek, + unsigned int channelCount, + unsigned int sampleRate, + void* userData) : + This(onGetData, onSeek, channelCount, sampleRate, userData) { } diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index 01fb7b8..58933ef 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -5,8 +5,15 @@ set(SRCROOT ${CMAKE_SOURCE_DIR}/src/SFML/Graphics) # all source files set(SRC ${INCROOT}/BlendMode.h + ${SRCROOT}/CircleShape.cpp + ${SRCROOT}/CircleShapeStruct.h + ${INCROOT}/CircleShape.h ${SRCROOT}/Color.cpp ${INCROOT}/Color.h + ${SRCROOT}/ConvertRenderStates.hpp + ${SRCROOT}/ConvexShape.cpp + ${SRCROOT}/ConvexShapeStruct.h + ${INCROOT}/ConvexShape.h ${SRCROOT}/Font.cpp ${SRCROOT}/FontStruct.h ${INCROOT}/Font.h @@ -16,6 +23,9 @@ set(SRC ${INCROOT}/Image.h ${SRCROOT}/Rect.cpp ${INCROOT}/Rect.h + ${SRCROOT}/RectangleShape.cpp + ${SRCROOT}/RectangleShapeStruct.h + ${INCROOT}/RectangleShape.h ${SRCROOT}/RenderTexture.cpp ${SRCROOT}/RenderTextureStruct.h ${INCROOT}/RenderTexture.h @@ -25,9 +35,6 @@ set(SRC ${SRCROOT}/Shader.cpp ${SRCROOT}/ShaderStruct.h ${INCROOT}/Shader.h - ${SRCROOT}/Shape.cpp - ${SRCROOT}/ShapeStruct.h - ${INCROOT}/Shape.h ${SRCROOT}/Sprite.cpp ${SRCROOT}/SpriteStruct.h ${INCROOT}/Sprite.h @@ -37,7 +44,14 @@ set(SRC ${SRCROOT}/Texture.cpp ${SRCROOT}/TextureStruct.h ${INCROOT}/Texture.h + ${SRCROOT}/Transform.cpp + ${SRCROOT}/TransformStruct.h + ${INCROOT}/Transform.h ${INCROOT}/Types.h + ${INCROOT}/Vertex.h + ${SRCROOT}/VertexArray.cpp + ${SRCROOT}/VertexArrayStruct.h + ${INCROOT}/VertexArray.h ${SRCROOT}/View.cpp ${SRCROOT}/ViewStruct.h ${INCROOT}/View.h diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp new file mode 100644 index 0000000..857ec26 --- /dev/null +++ b/src/SFML/Graphics/CircleShape.cpp @@ -0,0 +1,316 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +sfCircleShape* sfCircleShape_Create(void) +{ + sfCircleShape* shape = new sfCircleShape; + shape->Texture = NULL; + + return shape; +} + + +//////////////////////////////////////////////////////////// +sfCircleShape* sfCircleShape_Copy(sfCircleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + return new sfCircleShape(*shape); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_Destroy(sfCircleShape* shape) +{ + delete shape; +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetPosition(sfCircleShape* shape, float x, float y) +{ + CSFML_CALL(shape, SetPosition(x, y)); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetRotation(sfCircleShape* shape, float angle) +{ + CSFML_CALL(shape, SetRotation(angle)); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetScale(sfCircleShape* shape, float factorX, float factorY) +{ + CSFML_CALL(shape, SetScale(factorX, factorY)); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetOrigin(sfCircleShape* shape, float x, float y) +{ + CSFML_CALL(shape, SetOrigin(x, y)); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_GetPosition(const sfCircleShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetPosition(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +float sfCircleShape_GetRotation(const sfCircleShape* shape) +{ + CSFML_CALL_RETURN(shape, GetRotation(), 0.f); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_GetScale(const sfCircleShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetScale(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_GetOrigin(const sfCircleShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetOrigin(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_Move(sfCircleShape* shape, float offsetX, float offsetY) +{ + CSFML_CALL(shape, Move(offsetX, offsetY)); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_Rotate(sfCircleShape* shape, float angle) +{ + CSFML_CALL(shape, Rotate(angle)); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_Scale(sfCircleShape* shape, float factorX, float factorY) +{ + CSFML_CALL(shape, Scale(factorX, factorY)); +} + + +//////////////////////////////////////////////////////////// +const sfTransform* sfCircleShape_GetTransform(const sfCircleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + shape->Transform.This = shape->This.GetTransform(); + return &shape->Transform; +} + + +//////////////////////////////////////////////////////////// +const sfTransform* sfCircleShape_GetInverseTransform(const sfCircleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + shape->InverseTransform.This = shape->This.GetInverseTransform(); + return &shape->InverseTransform; +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetTexture(sfCircleShape* shape, const sfTexture* texture, sfBool resetRect) +{ + CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue)) + shape->Texture = texture; +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetTextureRect(sfCircleShape* shape, sfIntRect rect) +{ + CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height))) +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetFillColor(sfCircleShape* shape, sfColor color) +{ + CSFML_CALL(shape, SetFillColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetOutlineColor(sfCircleShape* shape, sfColor color) +{ + CSFML_CALL(shape, SetOutlineColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetOutlineThickness(sfCircleShape* shape, float thickness) +{ + CSFML_CALL(shape, SetOutlineThickness(thickness)); +} + + +//////////////////////////////////////////////////////////// +const sfTexture* sfCircleShape_GetTexture(const sfCircleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL) + + return shape->Texture; +} + + +//////////////////////////////////////////////////////////// +sfIntRect sfCircleShape_GetTextureRect(const sfCircleShape* shape) +{ + sfIntRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(sprite, rect) + + sf::IntRect sfmlRect = shape->This.GetTextureRect(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfColor sfCircleShape_GetFillColor(const sfCircleShape* shape) +{ + sfColor color = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, color); + + sf::Color sfmlColor = shape->This.GetFillColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; + + return color; +} + + +//////////////////////////////////////////////////////////// +sfColor sfCircleShape_GetOutlineColor(const sfCircleShape* shape) +{ + sfColor color = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, color); + + sf::Color sfmlColor = shape->This.GetOutlineColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; + + return color; +} + + +//////////////////////////////////////////////////////////// +float sfCircleShape_GetOutlineThickness(const sfCircleShape* shape) +{ + CSFML_CALL_RETURN(shape, GetOutlineThickness(), 0.f); +} + + +//////////////////////////////////////////////////////////// +unsigned int sfCircleShape_GetPointCount(const sfCircleShape* shape) +{ + CSFML_CALL_RETURN(shape, GetPointCount(), 0); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_GetPoint(const sfCircleShape* shape, unsigned int index, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetPoint(index); + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetRadius(sfCircleShape* shape, float radius) +{ + CSFML_CALL(shape, SetRadius(radius)); +} + + +//////////////////////////////////////////////////////////// +float sfCircleShape_GetRadius(const sfCircleShape* shape) +{ + CSFML_CALL_RETURN(shape, GetRadius(), 0.f); +} + + +//////////////////////////////////////////////////////////// +void sfCircleShape_SetPointCount(sfCircleShape* shape, unsigned int count) +{ + CSFML_CALL(shape, SetPointCount(count)); +} diff --git a/src/SFML/Graphics/CircleShapeStruct.h b/src/SFML/Graphics/CircleShapeStruct.h new file mode 100644 index 0000000..a08e8e8 --- /dev/null +++ b/src/SFML/Graphics/CircleShapeStruct.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CIRCLESHAPESTRUCT_H +#define SFML_CIRCLESHAPESTRUCT_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +//////////////////////////////////////////////////////////// +// Internal structure of sfCircleShape +//////////////////////////////////////////////////////////// +struct sfCircleShape +{ + sf::CircleShape This; + const sfTexture* Texture; + mutable sfTransform Transform; + mutable sfTransform InverseTransform; +}; + + +#endif // SFML_CIRCLESHAPESTRUCT_H diff --git a/src/SFML/Graphics/ConvertRenderStates.hpp b/src/SFML/Graphics/ConvertRenderStates.hpp new file mode 100644 index 0000000..a7cddde --- /dev/null +++ b/src/SFML/Graphics/ConvertRenderStates.hpp @@ -0,0 +1,60 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CONVERTRENDERSTATES_H +#define SFML_CONVERTRENDERSTATES_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +// Convert sfRenderStates* to sf::RenderStates +//////////////////////////////////////////////////////////// +inline sf::RenderStates ConvertRenderStates(const sfRenderStates* states) +{ + if (!states) + { + return sf::RenderStates::Default; + } + else + { + sf::RenderStates sfmlStates; + sfmlStates.BlendMode = static_cast(states->BlendMode); + sfmlStates.Transform = states->Transform ? states->Transform->This : sf::Transform::Identity; + sfmlStates.Texture = states->Texture ? states->Texture->This : NULL; + sfmlStates.Shader = states->Shader ? &states->Shader->This : NULL; + + return sfmlStates; + } +} + + +#endif // SFML_CONVERTRENDERSTATES_H diff --git a/src/SFML/Graphics/ConvexShape.cpp b/src/SFML/Graphics/ConvexShape.cpp new file mode 100644 index 0000000..79a1bae --- /dev/null +++ b/src/SFML/Graphics/ConvexShape.cpp @@ -0,0 +1,306 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +sfConvexShape* sfConvexShape_Create(void) +{ + return new sfConvexShape; +} + + +//////////////////////////////////////////////////////////// +sfConvexShape* sfConvexShape_Copy(sfConvexShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + return new sfConvexShape(*shape); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_Destroy(sfConvexShape* shape) +{ + delete shape; +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetPosition(sfConvexShape* shape, float x, float y) +{ + CSFML_CALL(shape, SetPosition(x, y)); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetRotation(sfConvexShape* shape, float angle) +{ + CSFML_CALL(shape, SetRotation(angle)); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetScale(sfConvexShape* shape, float factorX, float factorY) +{ + CSFML_CALL(shape, SetScale(factorX, factorY)); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetOrigin(sfConvexShape* shape, float x, float y) +{ + CSFML_CALL(shape, SetOrigin(x, y)); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_GetPosition(const sfConvexShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetPosition(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +float sfConvexShape_GetRotation(const sfConvexShape* shape) +{ + CSFML_CALL_RETURN(shape, GetRotation(), 0.f); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_GetScale(const sfConvexShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetScale(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_GetOrigin(const sfConvexShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetOrigin(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_Move(sfConvexShape* shape, float offsetX, float offsetY) +{ + CSFML_CALL(shape, Move(offsetX, offsetY)); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_Rotate(sfConvexShape* shape, float angle) +{ + CSFML_CALL(shape, Rotate(angle)); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_Scale(sfConvexShape* shape, float factorX, float factorY) +{ + CSFML_CALL(shape, Scale(factorX, factorY)); +} + + +//////////////////////////////////////////////////////////// +const sfTransform* sfConvexShape_GetTransform(const sfConvexShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + shape->Transform.This = shape->This.GetTransform(); + return &shape->Transform; +} + + +//////////////////////////////////////////////////////////// +const sfTransform* sfConvexShape_GetInverseTransform(const sfConvexShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + shape->InverseTransform.This = shape->This.GetInverseTransform(); + return &shape->InverseTransform; +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetTexture(sfConvexShape* shape, const sfTexture* texture, sfBool resetRect) +{ + CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue)) + shape->Texture = texture; +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetTextureRect(sfConvexShape* shape, sfIntRect rect) +{ + CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height))) +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetFillColor(sfConvexShape* shape, sfColor color) +{ + CSFML_CALL(shape, SetFillColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetOutlineColor(sfConvexShape* shape, sfColor color) +{ + CSFML_CALL(shape, SetOutlineColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetOutlineThickness(sfConvexShape* shape, float thickness) +{ + CSFML_CALL(shape, SetOutlineThickness(thickness)); +} + + +//////////////////////////////////////////////////////////// +const sfTexture* sfConvexShape_GetTexture(const sfConvexShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL) + + return shape->Texture; +} + + +//////////////////////////////////////////////////////////// +sfIntRect sfConvexShape_GetTextureRect(const sfConvexShape* shape) +{ + sfIntRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(sprite, rect) + + sf::IntRect sfmlRect = shape->This.GetTextureRect(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfColor sfConvexShape_GetFillColor(const sfConvexShape* shape) +{ + sfColor color = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, color); + + sf::Color sfmlColor = shape->This.GetFillColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; + + return color; +} + + +//////////////////////////////////////////////////////////// +sfColor sfConvexShape_GetOutlineColor(const sfConvexShape* shape) +{ + sfColor color = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, color); + + sf::Color sfmlColor = shape->This.GetOutlineColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; + + return color; +} + + +//////////////////////////////////////////////////////////// +float sfConvexShape_GetOutlineThickness(const sfConvexShape* shape) +{ + CSFML_CALL_RETURN(shape, GetOutlineThickness(), 0.f); +} + + +//////////////////////////////////////////////////////////// +unsigned int sfConvexShape_GetPointCount(const sfConvexShape* shape) +{ + CSFML_CALL_RETURN(shape, GetPointCount(), 0); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_GetPoint(const sfConvexShape* shape, unsigned int index, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetPoint(index); + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetPointCount(sfConvexShape* shape, unsigned int count) +{ + CSFML_CALL(shape, SetPointCount(count)); +} + + +//////////////////////////////////////////////////////////// +void sfConvexShape_SetPoint(sfConvexShape* shape, unsigned int index, float x, float y) +{ + CSFML_CALL(shape, SetPoint(index, sf::Vector2f(x, y))); +} diff --git a/src/SFML/Graphics/ConvexShapeStruct.h b/src/SFML/Graphics/ConvexShapeStruct.h new file mode 100644 index 0000000..6de9963 --- /dev/null +++ b/src/SFML/Graphics/ConvexShapeStruct.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_CONVEXSHAPESTRUCT_H +#define SFML_CONVEXSHAPESTRUCT_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +//////////////////////////////////////////////////////////// +// Internal structure of sfConvexShape +//////////////////////////////////////////////////////////// +struct sfConvexShape +{ + sf::ConvexShape This; + const sfTexture* Texture; + mutable sfTransform Transform; + mutable sfTransform InverseTransform; +}; + + +#endif // SFML_CONVEXSHAPESTRUCT_H diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 1c54e25..a4b4cf9 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -112,15 +112,15 @@ sfGlyph sfFont_GetGlyph(sfFont* font, sfUint32 codePoint, unsigned int character sf::Glyph SFMLGlyph = font->This.GetGlyph(codePoint, characterSize, bold == sfTrue); - glyph.Advance = SFMLGlyph.Advance; - glyph.Bounds.Left = SFMLGlyph.Bounds.Left; - glyph.Bounds.Top = SFMLGlyph.Bounds.Top; - glyph.Bounds.Width = SFMLGlyph.Bounds.Width; - glyph.Bounds.Height = SFMLGlyph.Bounds.Height; - glyph.SubRect.Left = SFMLGlyph.SubRect.Left; - glyph.SubRect.Top = SFMLGlyph.SubRect.Top; - glyph.SubRect.Width = SFMLGlyph.SubRect.Width; - glyph.SubRect.Height = SFMLGlyph.SubRect.Height; + glyph.Advance = SFMLGlyph.Advance; + glyph.Bounds.Left = SFMLGlyph.Bounds.Left; + glyph.Bounds.Top = SFMLGlyph.Bounds.Top; + glyph.Bounds.Width = SFMLGlyph.Bounds.Width; + glyph.Bounds.Height = SFMLGlyph.Bounds.Height; + glyph.TextureRect.Left = SFMLGlyph.TextureRect.Left; + glyph.TextureRect.Top = SFMLGlyph.TextureRect.Top; + glyph.TextureRect.Width = SFMLGlyph.TextureRect.Width; + glyph.TextureRect.Height = SFMLGlyph.TextureRect.Height; return glyph; } diff --git a/src/SFML/Graphics/RectangleShape.cpp b/src/SFML/Graphics/RectangleShape.cpp new file mode 100644 index 0000000..7d4a85e --- /dev/null +++ b/src/SFML/Graphics/RectangleShape.cpp @@ -0,0 +1,312 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + + +//////////////////////////////////////////////////////////// +sfRectangleShape* sfRectangleShape_Create(void) +{ + return new sfRectangleShape; +} + + +//////////////////////////////////////////////////////////// +sfRectangleShape* sfRectangleShape_Copy(sfRectangleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + return new sfRectangleShape(*shape); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_Destroy(sfRectangleShape* shape) +{ + delete shape; +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetPosition(sfRectangleShape* shape, float x, float y) +{ + CSFML_CALL(shape, SetPosition(x, y)); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetRotation(sfRectangleShape* shape, float angle) +{ + CSFML_CALL(shape, SetRotation(angle)); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetScale(sfRectangleShape* shape, float factorX, float factorY) +{ + CSFML_CALL(shape, SetScale(factorX, factorY)); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetOrigin(sfRectangleShape* shape, float x, float y) +{ + CSFML_CALL(shape, SetOrigin(x, y)); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_GetPosition(const sfRectangleShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetPosition(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +float sfRectangleShape_GetRotation(const sfRectangleShape* shape) +{ + CSFML_CALL_RETURN(shape, GetRotation(), 0.f); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_GetScale(const sfRectangleShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetScale(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_GetOrigin(const sfRectangleShape* shape, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetOrigin(); + + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_Move(sfRectangleShape* shape, float offsetX, float offsetY) +{ + CSFML_CALL(shape, Move(offsetX, offsetY)); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_Rotate(sfRectangleShape* shape, float angle) +{ + CSFML_CALL(shape, Rotate(angle)); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_Scale(sfRectangleShape* shape, float factorX, float factorY) +{ + CSFML_CALL(shape, Scale(factorX, factorY)); +} + + +//////////////////////////////////////////////////////////// +const sfTransform* sfRectangleShape_GetTransform(const sfRectangleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + shape->Transform.This = shape->This.GetTransform(); + return &shape->Transform; +} + + +//////////////////////////////////////////////////////////// +const sfTransform* sfRectangleShape_GetInverseTransform(const sfRectangleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL); + + shape->InverseTransform.This = shape->This.GetInverseTransform(); + return &shape->InverseTransform; +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetTexture(sfRectangleShape* shape, const sfTexture* texture, sfBool resetRect) +{ + CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue)) + shape->Texture = texture; +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetTextureRect(sfRectangleShape* shape, sfIntRect rect) +{ + CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height))) +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetFillColor(sfRectangleShape* shape, sfColor color) +{ + CSFML_CALL(shape, SetFillColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetOutlineColor(sfRectangleShape* shape, sfColor color) +{ + CSFML_CALL(shape, SetOutlineColor(sf::Color(color.r, color.g, color.b, color.a))); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetOutlineThickness(sfRectangleShape* shape, float thickness) +{ + CSFML_CALL(shape, SetOutlineThickness(thickness)); +} + + +//////////////////////////////////////////////////////////// +const sfTexture* sfRectangleShape_GetTexture(const sfRectangleShape* shape) +{ + CSFML_CHECK_RETURN(shape, NULL) + + return shape->Texture; +} + + +//////////////////////////////////////////////////////////// +sfIntRect sfRectangleShape_GetTextureRect(const sfRectangleShape* shape) +{ + sfIntRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(sprite, rect) + + sf::IntRect sfmlRect = shape->This.GetTextureRect(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; + + return rect; +} + + +//////////////////////////////////////////////////////////// +sfColor sfRectangleShape_GetFillColor(const sfRectangleShape* shape) +{ + sfColor color = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, color); + + sf::Color sfmlColor = shape->This.GetFillColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; + + return color; +} + + +//////////////////////////////////////////////////////////// +sfColor sfRectangleShape_GetOutlineColor(const sfRectangleShape* shape) +{ + sfColor color = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(shape, color); + + sf::Color sfmlColor = shape->This.GetOutlineColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; + + return color; +} + + +//////////////////////////////////////////////////////////// +float sfRectangleShape_GetOutlineThickness(const sfRectangleShape* shape) +{ + CSFML_CALL_RETURN(shape, GetOutlineThickness(), 0.f); +} + + +//////////////////////////////////////////////////////////// +unsigned int sfRectangleShape_GetPointCount(const sfRectangleShape* shape) +{ + CSFML_CALL_RETURN(shape, GetPointCount(), 0); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_GetPoint(const sfRectangleShape* shape, unsigned int index, float* x, float* y) +{ + CSFML_CHECK(shape); + + sf::Vector2f point = shape->This.GetPoint(index); + if (x) + *x = point.x; + if (y) + *y = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_SetSize(sfRectangleShape* shape, float width, float height) +{ + CSFML_CALL(shape, SetSize(sf::Vector2f(width, height))); +} + + +//////////////////////////////////////////////////////////// +void sfRectangleShape_GetSize(const sfRectangleShape* shape, float* width, float* height) +{ + CSFML_CHECK(shape); + + sf::Vector2f size = shape->This.GetSize(); + if (width) + *width = size.x; + if (height) + *height = size.y; +} diff --git a/src/SFML/Graphics/RectangleShapeStruct.h b/src/SFML/Graphics/RectangleShapeStruct.h new file mode 100644 index 0000000..e91fc5c --- /dev/null +++ b/src/SFML/Graphics/RectangleShapeStruct.h @@ -0,0 +1,48 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_RECTANGLESHAPESTRUCT_H +#define SFML_RECTANGLESHAPESTRUCT_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +//////////////////////////////////////////////////////////// +// Internal structure of sfRectangleShape +//////////////////////////////////////////////////////////// +struct sfRectangleShape +{ + sf::RectangleShape This; + const sfTexture* Texture; + mutable sfTransform Transform; + mutable sfTransform InverseTransform; +}; + + +#endif // SFML_RECTANGLESHAPESTRUCT_H diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index 751c005..4b8963d 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -27,15 +27,16 @@ //////////////////////////////////////////////////////////// #include #include -#include -#include #include #include +#include +#include +#include +#include +#include #include -//////////////////////////////////////////////////////////// -/// Construct a new rendertexture //////////////////////////////////////////////////////////// sfRenderTexture* sfRenderTexture_Create(unsigned int width, unsigned int height, sfBool depthBuffer) { @@ -49,8 +50,6 @@ sfRenderTexture* sfRenderTexture_Create(unsigned int width, unsigned int height, } -//////////////////////////////////////////////////////////// -/// Destroy an existing rendertexture //////////////////////////////////////////////////////////// void sfRenderTexture_Destroy(sfRenderTexture* renderTexture) { @@ -59,8 +58,6 @@ void sfRenderTexture_Destroy(sfRenderTexture* renderTexture) } -//////////////////////////////////////////////////////////// -/// Get the width of the rendering region of a rendertexture //////////////////////////////////////////////////////////// unsigned int sfRenderTexture_GetWidth(const sfRenderTexture* renderTexture) { @@ -68,8 +65,6 @@ unsigned int sfRenderTexture_GetWidth(const sfRenderTexture* renderTexture) } -//////////////////////////////////////////////////////////// -/// Get the height of the rendering region of a rendertexture //////////////////////////////////////////////////////////// unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTexture) { @@ -77,8 +72,6 @@ unsigned int sfRenderTexture_GetHeight(const sfRenderTexture* renderTexture) } -//////////////////////////////////////////////////////////// -/// Set a rendertexture as the current target for rendering //////////////////////////////////////////////////////////// sfBool sfRenderTexture_SetActive(sfRenderTexture* renderTexture, sfBool active) { @@ -86,26 +79,6 @@ sfBool sfRenderTexture_SetActive(sfRenderTexture* renderTexture, sfBool active) } -//////////////////////////////////////////////////////////// -/// Save the current OpenGL render states and matrices -//////////////////////////////////////////////////////////// -void sfRenderTexture_SaveGLStates(sfRenderTexture* renderTexture) -{ - CSFML_CALL(renderTexture, SaveGLStates()); -} - - -//////////////////////////////////////////////////////////// -/// Restore the previously saved OpenGL render states and matrices -//////////////////////////////////////////////////////////// -void sfRenderTexture_RestoreGLStates(sfRenderTexture* renderTexture) -{ - CSFML_CALL(renderTexture, RestoreGLStates()); -} - - -//////////////////////////////////////////////////////////// -/// Update the contents of the target texture //////////////////////////////////////////////////////////// void sfRenderTexture_Display(sfRenderTexture* renderTexture) { @@ -113,51 +86,6 @@ void sfRenderTexture_Display(sfRenderTexture* renderTexture) } -//////////////////////////////////////////////////////////// -/// Draw something on a rendertexture -//////////////////////////////////////////////////////////// -void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* sprite) -{ - CSFML_CHECK(sprite); - CSFML_CALL(renderTexture, Draw(sprite->This)); -} -void sfRenderTexture_DrawShape(sfRenderTexture* renderTexture, const sfShape* shape) -{ - CSFML_CHECK(shape); - CSFML_CALL(renderTexture, Draw(shape->This)); -} -void sfRenderTexture_DrawText(sfRenderTexture* renderTexture, const sfText* text) -{ - CSFML_CHECK(text); - CSFML_CALL(renderTexture, Draw(text->This)); -} - - -//////////////////////////////////////////////////////////// -/// Draw something on a rendertexture with a shader -//////////////////////////////////////////////////////////// -void sfRenderTexture_DrawSpriteWithShader(sfRenderTexture* renderTexture, const sfSprite* sprite, const sfShader* shader) -{ - CSFML_CHECK(sprite); - CSFML_CHECK(shader); - CSFML_CALL(renderTexture, Draw(sprite->This, shader->This)); -} -void sfRenderTexture_DrawShapeWithShader(sfRenderTexture* renderTexture, const sfShape* shape, const sfShader* shader) -{ - CSFML_CHECK(shape); - CSFML_CHECK(shader); - CSFML_CALL(renderTexture, Draw(shape->This, shader->This)); -} -void sfRenderTexture_DrawTextWithShader(sfRenderTexture* renderTexture, const sfText* text, const sfShader* shader) -{ - CSFML_CHECK(text); - CSFML_CHECK(shader); - CSFML_CALL(renderTexture, Draw(text->This, shader->This)); -} - - -//////////////////////////////////////////////////////////// -/// Clear the rendertexture with the given color //////////////////////////////////////////////////////////// void sfRenderTexture_Clear(sfRenderTexture* renderTexture, sfColor color) { @@ -167,8 +95,6 @@ void sfRenderTexture_Clear(sfRenderTexture* renderTexture, sfColor color) } -//////////////////////////////////////////////////////////// -/// Change the current active view of a rendertexture //////////////////////////////////////////////////////////// void sfRenderTexture_SetView(sfRenderTexture* renderTexture, const sfView* view) { @@ -178,8 +104,6 @@ void sfRenderTexture_SetView(sfRenderTexture* renderTexture, const sfView* view) } -//////////////////////////////////////////////////////////// -/// Get the current active view of a rendertexture //////////////////////////////////////////////////////////// const sfView* sfRenderTexture_GetView(const sfRenderTexture* renderTexture) { @@ -189,8 +113,6 @@ const sfView* sfRenderTexture_GetView(const sfRenderTexture* renderTexture) } -//////////////////////////////////////////////////////////// -/// Get the default view of a rendertexture //////////////////////////////////////////////////////////// const sfView* sfRenderTexture_GetDefaultView(const sfRenderTexture* renderTexture) { @@ -200,8 +122,6 @@ const sfView* sfRenderTexture_GetDefaultView(const sfRenderTexture* renderTextur } -//////////////////////////////////////////////////////////// -/// Get the viewport of a view applied to this target //////////////////////////////////////////////////////////// sfIntRect sfRenderTexture_GetViewport(const sfRenderTexture* renderTexture, const sfView* view) { @@ -219,8 +139,6 @@ sfIntRect sfRenderTexture_GetViewport(const sfRenderTexture* renderTexture, cons } -//////////////////////////////////////////////////////////// -/// Convert a point in texture coordinates into view coordinates //////////////////////////////////////////////////////////// void sfRenderTexture_ConvertCoords(const sfRenderTexture* renderTexture, unsigned int textureX, unsigned int textureY, float* viewX, float* viewY, const sfView* targetView) { @@ -238,7 +156,69 @@ void sfRenderTexture_ConvertCoords(const sfRenderTexture* renderTexture, unsigne //////////////////////////////////////////////////////////// -/// Get the target texture +void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderTexture, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderTexture_DrawText(sfRenderTexture* renderTexture, const sfText* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderTexture, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderTexture_DrawCircleShape(sfRenderTexture* renderTexture, const sfCircleShape* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderTexture, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderTexture_DrawConvexShape(sfRenderTexture* renderTexture, const sfConvexShape* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderTexture, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderTexture_DrawRectangleShape(sfRenderTexture* renderTexture, const sfRectangleShape* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderTexture, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderTexture_DrawVertexArray(sfRenderTexture* renderTexture, const sfVertexArray* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderTexture, Draw(object->This, ConvertRenderStates(states))); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_DrawPrimitives(sfRenderTexture* renderTexture, + const sfVertex* vertices, unsigned int vertexCount, + sfPrimitiveType type, const sfRenderStates* states) +{ + CSFML_CALL(renderTexture, Draw(reinterpret_cast(vertices), vertexCount, + static_cast(type), ConvertRenderStates(states))); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_PushGLStates(sfRenderTexture* renderTexture) +{ + CSFML_CALL(renderTexture, PushGLStates()); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_PopGLStates(sfRenderTexture* renderTexture) +{ + CSFML_CALL(renderTexture, PopGLStates()); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderTexture_ResetGLStates(sfRenderTexture* renderTexture) +{ + CSFML_CALL(renderTexture, ResetGLStates()); +} + + //////////////////////////////////////////////////////////// const sfTexture* sfRenderTexture_GetTexture(const sfRenderTexture* renderTexture) { diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index 4f3ab11..7ebec8c 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -27,17 +27,18 @@ //////////////////////////////////////////////////////////// #include #include -#include -#include #include #include #include +#include +#include +#include +#include +#include #include #include -//////////////////////////////////////////////////////////// -/// Construct a new renderwindow //////////////////////////////////////////////////////////// sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, sfUint32 style, const sfContextSettings* settings) { @@ -65,8 +66,6 @@ sfRenderWindow* sfRenderWindow_Create(sfVideoMode mode, const char* title, sfUin } -//////////////////////////////////////////////////////////// -/// Construct a renderwindow from an existing control //////////////////////////////////////////////////////////// sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, const sfContextSettings* settings) { @@ -91,16 +90,13 @@ sfRenderWindow* sfRenderWindow_CreateFromHandle(sfWindowHandle handle, const sfC } -//////////////////////////////////////////////////////////// -/// Destroy an existing renderwindow //////////////////////////////////////////////////////////// void sfRenderWindow_Destroy(sfRenderWindow* renderWindow) { delete renderWindow; } -//////////////////////////////////////////////////////////// -/// Close a renderwindow (but doesn't destroy the internal data) + //////////////////////////////////////////////////////////// void sfRenderWindow_Close(sfRenderWindow* renderWindow) { @@ -109,16 +105,12 @@ void sfRenderWindow_Close(sfRenderWindow* renderWindow) //////////////////////////////////////////////////////////// -/// Tell whether or not a renderwindow is opened -//////////////////////////////////////////////////////////// -sfBool sfRenderWindow_IsOpened(const sfRenderWindow* renderWindow) +sfBool sfRenderWindow_IsOpen(const sfRenderWindow* renderWindow) { - CSFML_CALL_RETURN(renderWindow, IsOpened(), sfFalse); + CSFML_CALL_RETURN(renderWindow, IsOpen(), sfFalse); } -//////////////////////////////////////////////////////////// -/// Get the width of the rendering region of a window //////////////////////////////////////////////////////////// unsigned int sfRenderWindow_GetWidth(const sfRenderWindow* renderWindow) { @@ -126,8 +118,6 @@ unsigned int sfRenderWindow_GetWidth(const sfRenderWindow* renderWindow) } -//////////////////////////////////////////////////////////// -/// Get the height of the rendering region of a window //////////////////////////////////////////////////////////// unsigned int sfRenderWindow_GetHeight(const sfRenderWindow* renderWindow) { @@ -135,8 +125,6 @@ unsigned int sfRenderWindow_GetHeight(const sfRenderWindow* renderWindow) } -//////////////////////////////////////////////////////////// -/// Get the creation settings of a window //////////////////////////////////////////////////////////// sfContextSettings sfRenderWindow_GetSettings(const sfRenderWindow* renderWindow) { @@ -152,9 +140,6 @@ sfContextSettings sfRenderWindow_GetSettings(const sfRenderWindow* renderWindow) } - -//////////////////////////////////////////////////////////// -/// Get the event on top of events stack of a window, if any, and pop it //////////////////////////////////////////////////////////// sfBool sfRenderWindow_PollEvent(sfRenderWindow* renderWindow, sfEvent* event) { @@ -176,8 +161,6 @@ sfBool sfRenderWindow_PollEvent(sfRenderWindow* renderWindow, sfEvent* event) } -//////////////////////////////////////////////////////////// -/// Wait for an event and return it //////////////////////////////////////////////////////////// sfBool sfRenderWindow_WaitEvent(sfRenderWindow* renderWindow, sfEvent* event) { @@ -199,8 +182,6 @@ sfBool sfRenderWindow_WaitEvent(sfRenderWindow* renderWindow, sfEvent* event) } -//////////////////////////////////////////////////////////// -/// Enable / disable vertical synchronization on a window //////////////////////////////////////////////////////////// void sfRenderWindow_EnableVerticalSync(sfRenderWindow* renderWindow, sfBool enabled) { @@ -208,8 +189,6 @@ void sfRenderWindow_EnableVerticalSync(sfRenderWindow* renderWindow, sfBool enab } -//////////////////////////////////////////////////////////// -/// Show or hide the mouse cursor on a window //////////////////////////////////////////////////////////// void sfRenderWindow_ShowMouseCursor(sfRenderWindow* renderWindow, sfBool show) { @@ -217,9 +196,6 @@ void sfRenderWindow_ShowMouseCursor(sfRenderWindow* renderWindow, sfBool show) } -//////////////////////////////////////////////////////////// -/// Change the position of a window on screen. -/// Only works for top-level windows //////////////////////////////////////////////////////////// void sfRenderWindow_SetPosition(sfRenderWindow* renderWindow, int left, int top) { @@ -227,8 +203,6 @@ void sfRenderWindow_SetPosition(sfRenderWindow* renderWindow, int left, int top) } -//////////////////////////////////////////////////////////// -/// Change the size of the rendering region of a window //////////////////////////////////////////////////////////// void sfRenderWindow_SetSize(sfRenderWindow* renderWindow, unsigned int width, unsigned int height) { @@ -236,8 +210,6 @@ void sfRenderWindow_SetSize(sfRenderWindow* renderWindow, unsigned int width, un } -//////////////////////////////////////////////////////////// -/// Change the title of a window //////////////////////////////////////////////////////////// void sfRenderWindow_SetTitle(sfRenderWindow* renderWindow, const char* title) { @@ -245,8 +217,6 @@ void sfRenderWindow_SetTitle(sfRenderWindow* renderWindow, const char* title) } -//////////////////////////////////////////////////////////// -/// Show or hide a window //////////////////////////////////////////////////////////// void sfRenderWindow_Show(sfRenderWindow* renderWindow, sfBool show) { @@ -254,9 +224,6 @@ void sfRenderWindow_Show(sfRenderWindow* renderWindow, sfBool show) } -//////////////////////////////////////////////////////////// -/// Enable or disable automatic key-repeat for keydown events. -/// Automatic key-repeat is enabled by default //////////////////////////////////////////////////////////// void sfRenderWindow_EnableKeyRepeat(sfRenderWindow* renderWindow, sfBool enabled) { @@ -264,8 +231,6 @@ void sfRenderWindow_EnableKeyRepeat(sfRenderWindow* renderWindow, sfBool enabled } -//////////////////////////////////////////////////////////// -/// Change the window's icon //////////////////////////////////////////////////////////// void sfRenderWindow_SetIcon(sfRenderWindow* renderWindow, unsigned int width, unsigned int height, const sfUint8* pixels) { @@ -273,8 +238,6 @@ void sfRenderWindow_SetIcon(sfRenderWindow* renderWindow, unsigned int width, un } -//////////////////////////////////////////////////////////// -/// Set a window as the current target for rendering //////////////////////////////////////////////////////////// sfBool sfRenderWindow_SetActive(sfRenderWindow* renderWindow, sfBool active) { @@ -282,26 +245,6 @@ sfBool sfRenderWindow_SetActive(sfRenderWindow* renderWindow, sfBool active) } -//////////////////////////////////////////////////////////// -/// Save the current OpenGL render states and matrices -//////////////////////////////////////////////////////////// -void sfRenderWindow_SaveGLStates(sfRenderWindow* renderWindow) -{ - CSFML_CALL(renderWindow, SaveGLStates()); -} - - -//////////////////////////////////////////////////////////// -/// Restore the previously saved OpenGL render states and matrices -//////////////////////////////////////////////////////////// -void sfRenderWindow_RestoreGLStates(sfRenderWindow* renderWindow) -{ - CSFML_CALL(renderWindow, RestoreGLStates()); -} - - -//////////////////////////////////////////////////////////// -/// Display a window on screen //////////////////////////////////////////////////////////// void sfRenderWindow_Display(sfRenderWindow* renderWindow) { @@ -309,8 +252,6 @@ void sfRenderWindow_Display(sfRenderWindow* renderWindow) } -//////////////////////////////////////////////////////////// -/// Limit the framerate to a maximum fixed frequency for a window //////////////////////////////////////////////////////////// void sfRenderWindow_SetFramerateLimit(sfRenderWindow* renderWindow, unsigned int limit) { @@ -318,18 +259,6 @@ void sfRenderWindow_SetFramerateLimit(sfRenderWindow* renderWindow, unsigned int } -//////////////////////////////////////////////////////////// -/// Get time elapsed since last frame of a window -//////////////////////////////////////////////////////////// -sfUint32 sfRenderWindow_GetFrameTime(const sfRenderWindow* renderWindow) -{ - CSFML_CALL_RETURN(renderWindow, GetFrameTime(), 0); -} - - -//////////////////////////////////////////////////////////// -/// Change the joystick threshold, ie. the value below which -/// no move event will be generated //////////////////////////////////////////////////////////// void sfRenderWindow_SetJoystickThreshold(sfRenderWindow* renderWindow, float threshold) { @@ -337,8 +266,6 @@ void sfRenderWindow_SetJoystickThreshold(sfRenderWindow* renderWindow, float thr } -//////////////////////////////////////////////////////////// -/// Retrieve the Os-specific handle of a window //////////////////////////////////////////////////////////// sfWindowHandle sfRenderWindow_GetSystemHandle(const sfRenderWindow* renderWindow) { @@ -348,51 +275,6 @@ sfWindowHandle sfRenderWindow_GetSystemHandle(const sfRenderWindow* renderWindow } -//////////////////////////////////////////////////////////// -/// Draw something on a renderwindow -//////////////////////////////////////////////////////////// -void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, const sfSprite* sprite) -{ - CSFML_CHECK(sprite); - CSFML_CALL(renderWindow, Draw(sprite->This)); -} -void sfRenderWindow_DrawShape(sfRenderWindow* renderWindow, const sfShape* shape) -{ - CSFML_CHECK(shape); - CSFML_CALL(renderWindow, Draw(shape->This)); -} -void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, const sfText* text) -{ - CSFML_CHECK(text); - CSFML_CALL(renderWindow, Draw(text->This)); -} - - -//////////////////////////////////////////////////////////// -/// Draw something on a renderwindow with a shader -//////////////////////////////////////////////////////////// -void sfRenderWindow_DrawSpriteWithShader(sfRenderWindow* renderWindow, const sfSprite* sprite, const sfShader* shader) -{ - CSFML_CHECK(sprite); - CSFML_CHECK(shader); - CSFML_CALL(renderWindow, Draw(sprite->This, shader->This)); -} -void sfRenderWindow_DrawShapeWithShader(sfRenderWindow* renderWindow, const sfShape* shape, const sfShader* shader) -{ - CSFML_CHECK(shape); - CSFML_CHECK(shader); - CSFML_CALL(renderWindow, Draw(shape->This, shader->This)); -} -void sfRenderWindow_DrawTextWithShader(sfRenderWindow* renderWindow, const sfText* text, const sfShader* shader) -{ - CSFML_CHECK(text); - CSFML_CHECK(shader); - CSFML_CALL(renderWindow, Draw(text->This, shader->This)); -} - - -//////////////////////////////////////////////////////////// -/// Clear the screen with the given color //////////////////////////////////////////////////////////// void sfRenderWindow_Clear(sfRenderWindow* renderWindow, sfColor color) { @@ -402,8 +284,6 @@ void sfRenderWindow_Clear(sfRenderWindow* renderWindow, sfColor color) } -//////////////////////////////////////////////////////////// -/// Change the current active view of a renderwindow //////////////////////////////////////////////////////////// void sfRenderWindow_SetView(sfRenderWindow* renderWindow, const sfView* view) { @@ -413,8 +293,6 @@ void sfRenderWindow_SetView(sfRenderWindow* renderWindow, const sfView* view) } -//////////////////////////////////////////////////////////// -/// Get the current active view of a renderwindow //////////////////////////////////////////////////////////// const sfView* sfRenderWindow_GetView(const sfRenderWindow* renderWindow) { @@ -424,8 +302,6 @@ const sfView* sfRenderWindow_GetView(const sfRenderWindow* renderWindow) } -//////////////////////////////////////////////////////////// -/// Get the default view of a renderwindow //////////////////////////////////////////////////////////// const sfView* sfRenderWindow_GetDefaultView(const sfRenderWindow* renderWindow) { @@ -435,8 +311,6 @@ const sfView* sfRenderWindow_GetDefaultView(const sfRenderWindow* renderWindow) } -//////////////////////////////////////////////////////////// -/// Get the viewport of a view applied to this target //////////////////////////////////////////////////////////// sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindow, const sfView* view) { @@ -454,8 +328,6 @@ sfIntRect sfRenderWindow_GetViewport(const sfRenderWindow* renderWindow, const s } -//////////////////////////////////////////////////////////// -/// Convert a point in window coordinates into view coordinates //////////////////////////////////////////////////////////// void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned int windowX, unsigned int windowY, float* viewX, float* viewY, const sfView* targetView) { @@ -472,6 +344,70 @@ void sfRenderWindow_ConvertCoords(const sfRenderWindow* renderWindow, unsigned i } +//////////////////////////////////////////////////////////// +void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, const sfSprite* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderWindow, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, const sfText* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderWindow, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderWindow_DrawCircleShape(sfRenderWindow* renderWindow, const sfCircleShape* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderWindow, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderWindow_DrawConvexShape(sfRenderWindow* renderWindow, const sfConvexShape* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderWindow, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderWindow_DrawRectangleShape(sfRenderWindow* renderWindow, const sfRectangleShape* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderWindow, Draw(object->This, ConvertRenderStates(states))); +} +void sfRenderWindow_DrawVertexArray(sfRenderWindow* renderWindow, const sfVertexArray* object, const sfRenderStates* states) +{ + CSFML_CHECK(object); + CSFML_CALL(renderWindow, Draw(object->This, ConvertRenderStates(states))); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_DrawPrimitives(sfRenderWindow* renderWindow, + const sfVertex* vertices, unsigned int vertexCount, + sfPrimitiveType type, const sfRenderStates* states) +{ + CSFML_CALL(renderWindow, Draw(reinterpret_cast(vertices), vertexCount, + static_cast(type), ConvertRenderStates(states))); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_PushGLStates(sfRenderWindow* renderWindow) +{ + CSFML_CALL(renderWindow, PushGLStates()); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_PopGLStates(sfRenderWindow* renderWindow) +{ + CSFML_CALL(renderWindow, PopGLStates()); +} + + +//////////////////////////////////////////////////////////// +CSFML_API void sfRenderWindow_ResetGLStates(sfRenderWindow* renderWindow) +{ + CSFML_CALL(renderWindow, ResetGLStates()); +} + + //////////////////////////////////////////////////////////// /// Copy the current contents of a window to an image //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index eef3a4d..2516832 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -28,18 +28,36 @@ #include #include #include +#include #include #include //////////////////////////////////////////////////////////// -/// Create a new shader from a file -//////////////////////////////////////////////////////////// -sfShader* sfShader_CreateFromFile(const char* filename) +sfShader* sfShader_CreateFromFile(const char* vertexShaderFilename, const char* fragmentShaderFilename) { + bool success = false; sfShader* shader = new sfShader; + if (vertexShaderFilename || fragmentShaderFilename) + { + if (!vertexShaderFilename) + { + // fragment shader only + success = shader->This.LoadFromFile(fragmentShaderFilename, sf::Shader::Fragment); + } + else if (!fragmentShaderFilename) + { + // vertex shader only + success = shader->This.LoadFromFile(vertexShaderFilename, sf::Shader::Vertex); + } + else + { + // vertex + fragment shaders + success = shader->This.LoadFromFile(vertexShaderFilename, fragmentShaderFilename); + } + } - if (!shader->This.LoadFromFile(filename)) + if (!success) { delete shader; shader = NULL; @@ -50,13 +68,30 @@ sfShader* sfShader_CreateFromFile(const char* filename) //////////////////////////////////////////////////////////// -/// Create a new shader from an effect source code -//////////////////////////////////////////////////////////// -sfShader* sfShader_CreateFromMemory(const char* effect) +sfShader* sfShader_CreateFromMemory(const char* vertexShader, const char* fragmentShader) { + bool success = false; sfShader* shader = new sfShader; + if (vertexShader || fragmentShader) + { + if (!vertexShader) + { + // fragment shader only + success = shader->This.LoadFromMemory(fragmentShader, sf::Shader::Fragment); + } + else if (!fragmentShader) + { + // vertex shader only + success = shader->This.LoadFromMemory(vertexShader, sf::Shader::Vertex); + } + else + { + // vertex + fragment shaders + success = shader->This.LoadFromMemory(vertexShader, fragmentShader); + } + } - if (!shader->This.LoadFromMemory(effect)) + if (!success) { delete shader; shader = NULL; @@ -67,16 +102,34 @@ sfShader* sfShader_CreateFromMemory(const char* effect) //////////////////////////////////////////////////////////// -/// Create a new shader from a custom stream -//////////////////////////////////////////////////////////// -sfShader* sfShader_CreateFromStream(sfInputStream* stream) +sfShader* sfShader_CreateFromStream(sfInputStream* vertexShaderStream, sfInputStream* fragmentShaderStream) { - CSFML_CHECK_RETURN(stream, NULL); - + bool success = false; sfShader* shader = new sfShader; + if (vertexShaderStream || fragmentShaderStream) + { + if (!vertexShaderStream) + { + // fragment shader only + CallbackStream stream(fragmentShaderStream); + success = shader->This.LoadFromStream(stream, sf::Shader::Fragment); + } + else if (!fragmentShaderStream) + { + // vertex shader only + CallbackStream stream(vertexShaderStream); + success = shader->This.LoadFromStream(stream, sf::Shader::Vertex); + } + else + { + // vertex + fragment shaders + CallbackStream vertexStream(vertexShaderStream); + CallbackStream fragmentStream(fragmentShaderStream); + success = shader->This.LoadFromStream(vertexStream, fragmentStream); + } + } - CallbackStream sfmlStream(stream); - if (!shader->This.LoadFromStream(sfmlStream)) + if (!success) { delete shader; shader = NULL; @@ -86,19 +139,6 @@ sfShader* sfShader_CreateFromStream(sfInputStream* stream) } -//////////////////////////////////////////////////////////// -/// Copy an existing clock -//////////////////////////////////////////////////////////// -sfShader* sfShader_Copy(sfShader* shader) -{ - CSFML_CHECK_RETURN(shader, NULL); - - return new sfShader(*shader); -} - - -//////////////////////////////////////////////////////////// -/// Destroy an existing shader //////////////////////////////////////////////////////////// void sfShader_Destroy(sfShader* shader) { @@ -107,62 +147,62 @@ void sfShader_Destroy(sfShader* shader) //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (1 float) -//////////////////////////////////////////////////////////// -void sfShader_SetParameter1(sfShader* shader, const char* name, float x) +void sfShader_SetFloatParameter(sfShader* shader, const char* name, float x) { CSFML_CALL(shader, SetParameter(name, x)) } //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (2 floats) -//////////////////////////////////////////////////////////// -void sfShader_SetParameter2(sfShader* shader, const char* name, float x, float y) +void sfShader_SetFloat2Parameter(sfShader* shader, const char* name, float x, float y) { CSFML_CALL(shader, SetParameter(name, x, y)) } //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (3 floats) -//////////////////////////////////////////////////////////// -void sfShader_SetParameter3(sfShader* shader, const char* name, float x, float y, float z) +void sfShader_SetFloat3Parameter(sfShader* shader, const char* name, float x, float y, float z) { CSFML_CALL(shader, SetParameter(name, x, y, z)) } //////////////////////////////////////////////////////////// -/// Change a parameter of a shader (4 floats) -//////////////////////////////////////////////////////////// -void sfShader_SetParameter4(sfShader* shader, const char* name, float x, float y, float z, float w) +void sfShader_SetFloat4Parameter(sfShader* shader, const char* name, float x, float y, float z, float w) { CSFML_CALL(shader, SetParameter(name, x, y, z, w)) } //////////////////////////////////////////////////////////// -/// Set a texture parameter in a shader +void sfShader_SetColorParameter(sfShader* shader, const char* name, sfColor color) +{ + CSFML_CALL(shader, SetParameter(name, sf::Color(color.r, color.g, color.b, color.a))) +} + + //////////////////////////////////////////////////////////// -void sfShader_SetTexture(sfShader* shader, const char* name, const sfTexture* texture) +void sfShader_SetTransformParameter(sfShader* shader, const char* name, const sfTransform* transform) +{ + CSFML_CALL(shader, SetParameter(name, transform ? transform->This : sf::Transform::Identity)) +} + + +//////////////////////////////////////////////////////////// +void sfShader_SetTextureParameter(sfShader* shader, const char* name, const sfTexture* texture) { CSFML_CHECK(texture); - CSFML_CALL(shader, SetTexture(name, *texture->This)) + CSFML_CALL(shader, SetParameter(name, *texture->This)) } //////////////////////////////////////////////////////////// -/// Set the current texture parameter in a shader -//////////////////////////////////////////////////////////// -void sfShader_SetCurrentTexture(sfShader* shader, const char* name) +void sfShader_SetCurrentTextureParameter(sfShader* shader, const char* name) { - CSFML_CALL(shader, SetCurrentTexture(name)) + CSFML_CALL(shader, SetParameter(name, sf::Shader::CurrentTexture)) } -//////////////////////////////////////////////////////////// -/// Bind a shader for rendering //////////////////////////////////////////////////////////// void sfShader_Bind(const sfShader* shader) { @@ -170,8 +210,6 @@ void sfShader_Bind(const sfShader* shader) } -//////////////////////////////////////////////////////////// -/// Unbind a shader //////////////////////////////////////////////////////////// void sfShader_Unbind(const sfShader* shader) { @@ -179,8 +217,6 @@ void sfShader_Unbind(const sfShader* shader) } -//////////////////////////////////////////////////////////// -/// Tell whether or not the system supports shaders //////////////////////////////////////////////////////////// sfBool sfShader_IsAvailable(void) { diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp deleted file mode 100644 index ab7bde6..0000000 --- a/src/SFML/Graphics/Shape.cpp +++ /dev/null @@ -1,469 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include -#include - - -//////////////////////////////////////////////////////////// -/// Create a new shape -//////////////////////////////////////////////////////////// -sfShape* sfShape_Create(void) -{ - return new sfShape; -} - - -//////////////////////////////////////////////////////////// -/// Create a new shape made of a single line -//////////////////////////////////////////////////////////// -sfShape* sfShape_CreateLine(float p1x, float p1y, float p2x, float p2y, float thickness, sfColor color, float outline, sfColor outlineColor) -{ - sf::Color SFMLColor(color.r, color.g, color.b, color.a); - sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a); - - sfShape* shape = new sfShape; - shape->This = sf::Shape::Line(p1x, p1y, p2x, p2y, thickness, SFMLColor, outline, SFMLOutlineColor); - return shape; -} - - -//////////////////////////////////////////////////////////// -/// Create a new shape made of a single rectangle -//////////////////////////////////////////////////////////// -sfShape* sfShape_CreateRectangle(float left, float top, float width, float height, sfColor color, float outline, sfColor outlineColor) -{ - sf::Color SFMLColor(color.r, color.g, color.b, color.a); - sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a); - - sfShape* shape = new sfShape; - shape->This = sf::Shape::Rectangle(left, top, width, height, SFMLColor, outline, SFMLOutlineColor); - return shape; -} - - -//////////////////////////////////////////////////////////// -/// Create a new shape made of a single circle -//////////////////////////////////////////////////////////// -sfShape* sfShape_CreateCircle(float x, float y, float radius, sfColor color, float outline, sfColor outlineColor) -{ - sf::Color SFMLColor(color.r, color.g, color.b, color.a); - sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a); - - sfShape* shape = new sfShape; - shape->This = sf::Shape::Circle(x, y, radius, SFMLColor, outline, SFMLOutlineColor); - return shape; -} - - -//////////////////////////////////////////////////////////// -/// Copy an existing shape -//////////////////////////////////////////////////////////// -sfShape* sfShape_Copy(sfShape* shape) -{ - CSFML_CHECK_RETURN(shape, NULL); - - return new sfShape(*shape); -} - - -//////////////////////////////////////////////////////////// -/// Destroy an existing shape -//////////////////////////////////////////////////////////// -void sfShape_Destroy(sfShape* shape) -{ - delete shape; -} - - -//////////////////////////////////////////////////////////// -/// Set the X position of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetX(sfShape* shape, float x) -{ - CSFML_CALL(shape, SetX(x)) -} - - -//////////////////////////////////////////////////////////// -/// Set the Y position of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetY(sfShape* shape, float y) -{ - CSFML_CALL(shape, SetY(y)) -} - - -//////////////////////////////////////////////////////////// -/// Set the position of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetPosition(sfShape* shape, float x, float y) -{ - CSFML_CALL(shape, SetPosition(sf::Vector2f(x, y))) -} - - -//////////////////////////////////////////////////////////// -/// Set the horizontal scale of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetScaleX(sfShape* shape, float scale) -{ - CSFML_CALL(shape, SetScaleX(scale)) -} - - -//////////////////////////////////////////////////////////// -/// Set the vertical scale of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetScaleY(sfShape* shape, float scale) -{ - CSFML_CALL(shape, SetScaleY(scale)) -} - - -//////////////////////////////////////////////////////////// -/// Set the scale of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetScale(sfShape* shape, float scaleX, float scaleY) -{ - CSFML_CALL(shape, SetScale(sf::Vector2f(scaleX, scaleY))) -} - - -//////////////////////////////////////////////////////////// -/// Set the orientation of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetRotation(sfShape* shape, float rotation) -{ - CSFML_CALL(shape, SetRotation(rotation)) -} - - -//////////////////////////////////////////////////////////// -/// Set the local origin of a shape, in coordinates -/// relative to its left-top corner -//////////////////////////////////////////////////////////// -void sfShape_SetOrigin(sfShape* shape, float x, float y) -{ - CSFML_CALL(shape, SetOrigin(sf::Vector2f(x, y))) -} - - -//////////////////////////////////////////////////////////// -/// Set the color of a shape -//////////////////////////////////////////////////////////// -void sfShape_SetColor(sfShape* shape, sfColor color) -{ - CSFML_CALL(shape, SetColor(sf::Color(color.r, color.g, color.b, color.a))) -} - - -//////////////////////////////////////////////////////////// -/// Set the blending mode for a shape -//////////////////////////////////////////////////////////// -void sfShape_SetBlendMode(sfShape* shape, sfBlendMode mode) -{ - CSFML_CALL(shape, SetBlendMode(static_cast(mode))) -} - - -//////////////////////////////////////////////////////////// -/// Get the X position of a shape -//////////////////////////////////////////////////////////// -float sfShape_GetX(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetPosition().x, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the Y position of a shape -//////////////////////////////////////////////////////////// -float sfShape_GetY(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetPosition().y, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the horizontal scale of a shape -//////////////////////////////////////////////////////////// -float sfShape_GetScaleX(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetScale().x, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the vertical scale of a shape -//////////////////////////////////////////////////////////// -float sfShape_GetScaleY(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetScale().y, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the orientation of a shape -//////////////////////////////////////////////////////////// -float sfShape_GetRotation(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetRotation(), 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the X position of the origin a shape -//////////////////////////////////////////////////////////// -float sfShape_GetOriginX(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetOrigin().x, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the Y position of the origin a shape -//////////////////////////////////////////////////////////// -float sfShape_GetOriginY(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetOrigin().y, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the color of a shape -//////////////////////////////////////////////////////////// -sfColor sfShape_GetColor(const sfShape* shape) -{ - sfColor color = {0, 0, 0, 0}; - CSFML_CHECK_RETURN(shape, color) - - sf::Color SFMLColor = shape->This.GetColor(); - return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a); -} - - -//////////////////////////////////////////////////////////// -/// Get the current blending mode of a shape -//////////////////////////////////////////////////////////// -sfBlendMode sfShape_GetBlendMode(const sfShape* shape) -{ - CSFML_CHECK_RETURN(shape, sfBlendNone) - - return static_cast(shape->This.GetBlendMode()); -} - - -//////////////////////////////////////////////////////////// -/// Move a shape -//////////////////////////////////////////////////////////// -void sfShape_Move(sfShape* shape, float offsetX, float offsetY) -{ - CSFML_CALL(shape, Move(sf::Vector2f(offsetX, offsetY))) -} - - -//////////////////////////////////////////////////////////// -/// Scale a shape -//////////////////////////////////////////////////////////// -void sfShape_Scale(sfShape* shape, float factorX, float factorY) -{ - CSFML_CALL(shape, Scale(sf::Vector2f(factorX, factorY))) -} - - -//////////////////////////////////////////////////////////// -/// Rotate a shape -//////////////////////////////////////////////////////////// -void sfShape_Rotate(sfShape* shape, float angle) -{ - CSFML_CALL(shape, Rotate(angle)) -} - - -//////////////////////////////////////////////////////////// -/// Transform a point from global coordinates into the shape's local coordinates -/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) -//////////////////////////////////////////////////////////// -void sfShape_TransformToLocal(const sfShape* shape, float pointX, float pointY, float* x, float* y) -{ - CSFML_CHECK(shape) - - sf::Vector2f point = shape->This.TransformToLocal(sf::Vector2f(pointX, pointY)); - if (x) *x = point.x; - if (y) *y = point.y; -} - - -//////////////////////////////////////////////////////////// -/// Transform a point from the shape's local coordinates into global coordinates -/// (ie it applies the object's origin, translation, rotation and scale to the point) -//////////////////////////////////////////////////////////// -void sfShape_TransformToGlobal(const sfShape* shape, float pointX, float pointY, float* x, float* y) -{ - CSFML_CHECK(shape) - - sf::Vector2f point = shape->This.TransformToGlobal(sf::Vector2f(pointX, pointY)); - if (x) *x = point.x; - if (y) *y = point.y; -} - - -//////////////////////////////////////////////////////////// -/// Add a point to a shape -//////////////////////////////////////////////////////////// -void sfShape_AddPoint(sfShape* shape, float x, float y, sfColor color, sfColor outlineColor) -{ - sf::Color SFMLColor(color.r, color.g, color.b, color.a); - sf::Color SFMLOutlineColor(outlineColor.r, outlineColor.g, outlineColor.b, outlineColor.a); - - CSFML_CALL(shape, AddPoint(x, y, SFMLColor, SFMLOutlineColor)) -} - - -//////////////////////////////////////////////////////////// -/// Enable or disable filling a shape. -/// Fill is enabled by default -//////////////////////////////////////////////////////////// -void sfShape_EnableFill(sfShape* shape, sfBool enable) -{ - CSFML_CALL(shape, EnableFill(enable == sfTrue)) -} - - -//////////////////////////////////////////////////////////// -/// Enable or disable drawing a shape outline. -/// Outline is enabled by default -//////////////////////////////////////////////////////////// -void sfShape_EnableOutline(sfShape* shape, sfBool enable) -{ - CSFML_CALL(shape, EnableOutline(enable == sfTrue)) -} - - -//////////////////////////////////////////////////////////// -/// Change the thickness of a shape outline -//////////////////////////////////////////////////////////// -void sfShape_SetOutlineThickness(sfShape* shape, float thickness) -{ - CSFML_CALL(shape, SetOutlineThickness(thickness)) -} - - -//////////////////////////////////////////////////////////// -/// Get the thickness of a shape outline -//////////////////////////////////////////////////////////// -float sfShape_GetOutlineThickness(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetOutlineThickness(), 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the number of points composing a shape -//////////////////////////////////////////////////////////// -unsigned int sfShape_GetPointsCount(const sfShape* shape) -{ - CSFML_CALL_RETURN(shape, GetPointsCount(), 0) -} - - -//////////////////////////////////////////////////////////// -/// Get a point of a shape -//////////////////////////////////////////////////////////// -void sfShape_GetPointPosition(const sfShape* shape, unsigned int index, float* x, float* y) -{ - CSFML_CHECK(shape) - - sf::Vector2f point = shape->This.GetPointPosition(index); - if (x) *x = point.x; - if (y) *y = point.y; -} - - -//////////////////////////////////////////////////////////// -/// Get a the color of a shape's point -//////////////////////////////////////////////////////////// -sfColor sfShape_GetPointColor(const sfShape* shape, unsigned int index) -{ - sfColor color = {255, 255, 255, 255}; - CSFML_CHECK_RETURN(shape, color) - - const sf::Color& SFMLColor = shape->This.GetPointColor(index); - color.r = SFMLColor.r; - color.g = SFMLColor.g; - color.b = SFMLColor.b; - color.a = SFMLColor.a; - - return color; -} - - -//////////////////////////////////////////////////////////// -/// Get a the outline color of a shape's point -//////////////////////////////////////////////////////////// -sfColor sfShape_GetPointOutlineColor(const sfShape* shape, unsigned int index) -{ - sfColor color = {255, 255, 255, 255}; - CSFML_CHECK_RETURN(shape, color) - - const sf::Color& SFMLColor = shape->This.GetPointOutlineColor(index); - color.r = SFMLColor.r; - color.g = SFMLColor.g; - color.b = SFMLColor.b; - color.a = SFMLColor.a; - - return color; -} - -//////////////////////////////////////////////////////////// -/// Set a the position of a shape's point -//////////////////////////////////////////////////////////// -void sfShape_SetPointPosition(sfShape* shape, unsigned int index, float x, float y) -{ - CSFML_CALL(shape, SetPointPosition(index, x, y)); -} - - -//////////////////////////////////////////////////////////// -/// Set a the color of a shape's point -//////////////////////////////////////////////////////////// -void sfShape_SetPointColor(sfShape* shape, unsigned int index, sfColor color) -{ - CSFML_CALL(shape, SetPointColor(index, sf::Color(color.r, color.g, color.b, color.a))); -} - - -//////////////////////////////////////////////////////////// -/// Set a the outline color of a shape's point -//////////////////////////////////////////////////////////// -void sfShape_SetPointOutlineColor(sfShape* shape, unsigned int index, sfColor color) -{ - CSFML_CALL(shape, SetPointOutlineColor(index, sf::Color(color.r, color.g, color.b, color.a))); -} diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index abf1dfa..88d1d70 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -32,8 +32,6 @@ #include -//////////////////////////////////////////////////////////// -/// Create a new sprite //////////////////////////////////////////////////////////// sfSprite* sfSprite_Create(void) { @@ -44,8 +42,6 @@ sfSprite* sfSprite_Create(void) } -//////////////////////////////////////////////////////////// -/// Copy an existing sprite //////////////////////////////////////////////////////////// sfSprite* sfSprite_Copy(sfSprite* sprite) { @@ -55,8 +51,6 @@ sfSprite* sfSprite_Copy(sfSprite* sprite) } -//////////////////////////////////////////////////////////// -/// Destroy an existing sprite //////////////////////////////////////////////////////////// void sfSprite_Destroy(sfSprite* sprite) { @@ -64,290 +58,149 @@ void sfSprite_Destroy(sfSprite* sprite) } -//////////////////////////////////////////////////////////// -/// Set the X position of a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetX(sfSprite* sprite, float x) -{ - CSFML_CALL(sprite, SetX(x)) -} - - -//////////////////////////////////////////////////////////// -/// Set the Y position of a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetY(sfSprite* sprite, float y) -{ - CSFML_CALL(sprite, SetY(y)) -} - - -//////////////////////////////////////////////////////////// -/// Set the position of a sprite //////////////////////////////////////////////////////////// void sfSprite_SetPosition(sfSprite* sprite, float x, float y) { - CSFML_CALL(sprite, SetPosition(sf::Vector2f(x, y))) + CSFML_CALL(sprite, SetPosition(x, y)); } //////////////////////////////////////////////////////////// -/// Set the horizontal scale of a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetScaleX(sfSprite* sprite, float scale) +void sfSprite_SetRotation(sfSprite* sprite, float angle) { - CSFML_CALL(sprite, SetScaleX(scale)) + CSFML_CALL(sprite, SetRotation(angle)); } //////////////////////////////////////////////////////////// -/// Set the vertical scale of a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetScaleY(sfSprite* sprite, float scale) +void sfSprite_SetScale(sfSprite* sprite, float factorX, float factorY) { - CSFML_CALL(sprite, SetScaleY(scale)) + CSFML_CALL(sprite, SetScale(factorX, factorY)); } -//////////////////////////////////////////////////////////// -/// Set the scale of a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetScale(sfSprite* sprite, float scaleX, float scaleY) -{ - CSFML_CALL(sprite, SetScale(sf::Vector2f(scaleX, scaleY))) -} - - -//////////////////////////////////////////////////////////// -/// Set the orientation of a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetRotation(sfSprite* sprite, float rotation) -{ - CSFML_CALL(sprite, SetRotation(rotation)) -} - - -//////////////////////////////////////////////////////////// -/// Set the local origin of a sprite, in coordinates -/// relative to its left-top corner //////////////////////////////////////////////////////////// void sfSprite_SetOrigin(sfSprite* sprite, float x, float y) { - CSFML_CALL(sprite, SetOrigin(sf::Vector2f(x, y))) + CSFML_CALL(sprite, SetOrigin(x, y)); } //////////////////////////////////////////////////////////// -/// Set the color of a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetColor(sfSprite* sprite, sfColor color) +void sfSprite_GetPosition(const sfSprite* sprite, float* x, float* y) { - CSFML_CALL(sprite, SetColor(sf::Color(color.r, color.g, color.b, color.a))) + CSFML_CHECK(sprite); + + sf::Vector2f point = sprite->This.GetPosition(); + + if (x) + *x = point.x; + if (y) + *y = point.y; } -//////////////////////////////////////////////////////////// -/// Set the blending mode for a sprite -//////////////////////////////////////////////////////////// -void sfSprite_SetBlendMode(sfSprite* sprite, sfBlendMode mode) -{ - CSFML_CALL(sprite, SetBlendMode(static_cast(mode))) -} - - -//////////////////////////////////////////////////////////// -/// Get the X position of a sprite -//////////////////////////////////////////////////////////// -float sfSprite_GetX(const sfSprite* sprite) -{ - CSFML_CALL_RETURN(sprite, GetPosition().x, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the Y position of a sprite -//////////////////////////////////////////////////////////// -float sfSprite_GetY(const sfSprite* sprite) -{ - CSFML_CALL_RETURN(sprite, GetPosition().y, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the horizontal scale of a sprite -//////////////////////////////////////////////////////////// -float sfSprite_GetScaleX(const sfSprite* sprite) -{ - CSFML_CALL_RETURN(sprite, GetScale().x, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the vertical scale of a sprite -//////////////////////////////////////////////////////////// -float sfSprite_GetScaleY(const sfSprite* sprite) -{ - CSFML_CALL_RETURN(sprite, GetScale().y, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the orientation of a sprite //////////////////////////////////////////////////////////// float sfSprite_GetRotation(const sfSprite* sprite) { - CSFML_CALL_RETURN(sprite, GetRotation(), 0.f) + CSFML_CALL_RETURN(sprite, GetRotation(), 0.f); } //////////////////////////////////////////////////////////// -/// Get the X position of the origin a sprite -//////////////////////////////////////////////////////////// -float sfSprite_GetOriginX(const sfSprite* sprite) +void sfSprite_GetScale(const sfSprite* sprite, float* x, float* y) { - CSFML_CALL_RETURN(sprite, GetOrigin().x, 0.f) + CSFML_CHECK(sprite); + + sf::Vector2f point = sprite->This.GetScale(); + + if (x) + *x = point.x; + if (y) + *y = point.y; } //////////////////////////////////////////////////////////// -/// Get the Y position of the origin a sprite -//////////////////////////////////////////////////////////// -float sfSprite_GetOriginY(const sfSprite* sprite) +void sfSprite_GetOrigin(const sfSprite* sprite, float* x, float* y) { - CSFML_CALL_RETURN(sprite, GetOrigin().y, 0.f) + CSFML_CHECK(sprite); + + sf::Vector2f point = sprite->This.GetOrigin(); + + if (x) + *x = point.x; + if (y) + *y = point.y; } -//////////////////////////////////////////////////////////// -/// Get the color of a sprite -//////////////////////////////////////////////////////////// -sfColor sfSprite_GetColor(const sfSprite* sprite) -{ - sfColor color = {0, 0, 0, 0}; - CSFML_CHECK_RETURN(sprite, color) - - sf::Color SFMLColor = sprite->This.GetColor(); - return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a); -} - - -//////////////////////////////////////////////////////////// -/// Get the current blending mode of a sprite -//////////////////////////////////////////////////////////// -sfBlendMode sfSprite_GetBlendMode(const sfSprite* sprite) -{ - CSFML_CHECK_RETURN(sprite, sfBlendNone) - - return static_cast(sprite->This.GetBlendMode()); -} - - -//////////////////////////////////////////////////////////// -/// Move a sprite //////////////////////////////////////////////////////////// void sfSprite_Move(sfSprite* sprite, float offsetX, float offsetY) { - CSFML_CALL(sprite, Move(sf::Vector2f(offsetX, offsetY))) + CSFML_CALL(sprite, Move(offsetX, offsetY)); } -//////////////////////////////////////////////////////////// -/// Scale a sprite -//////////////////////////////////////////////////////////// -void sfSprite_Scale(sfSprite* sprite, float factorX, float factorY) -{ - CSFML_CALL(sprite, Scale(sf::Vector2f(factorX, factorY))) -} - - -//////////////////////////////////////////////////////////// -/// Rotate a sprite //////////////////////////////////////////////////////////// void sfSprite_Rotate(sfSprite* sprite, float angle) { - CSFML_CALL(sprite, Rotate(angle)) + CSFML_CALL(sprite, Rotate(angle)); } //////////////////////////////////////////////////////////// -/// Transform a point from global coordinates into the sprite's local coordinates -/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) -//////////////////////////////////////////////////////////// -void sfSprite_TransformToLocal(const sfSprite* sprite, float pointX, float pointY, float* x, float* y) +void sfSprite_Scale(sfSprite* sprite, float factorX, float factorY) { - CSFML_CHECK(sprite) - - sf::Vector2f point = sprite->This.TransformToLocal(sf::Vector2f(pointX, pointY)); - if (x) *x = point.x; - if (y) *y = point.y; + CSFML_CALL(sprite, Scale(factorX, factorY)); } //////////////////////////////////////////////////////////// -/// Transform a point from the sprite's local coordinates into global coordinates -/// (ie it applies the object's origin, translation, rotation and scale to the point) -//////////////////////////////////////////////////////////// -void sfSprite_TransformToGlobal(const sfSprite* sprite, float pointX, float pointY, float* x, float* y) +const sfTransform* sfSprite_GetTransform(const sfSprite* sprite) { - CSFML_CHECK(sprite) + CSFML_CHECK_RETURN(sprite, NULL); - sf::Vector2f point = sprite->This.TransformToGlobal(sf::Vector2f(pointX, pointY)); - if (x) *x = point.x; - if (y) *y = point.y; + sprite->Transform.This = sprite->This.GetTransform(); + return &sprite->Transform; } //////////////////////////////////////////////////////////// -/// Change the texture of a sprite +const sfTransform* sfSprite_GetInverseTransform(const sfSprite* sprite) +{ + CSFML_CHECK_RETURN(sprite, NULL); + + sprite->InverseTransform.This = sprite->This.GetInverseTransform(); + return &sprite->InverseTransform; +} + + //////////////////////////////////////////////////////////// -void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool adjustToNewSize) +void sfSprite_SetTexture(sfSprite* sprite, const sfTexture* texture, sfBool resetRect) { if (texture && texture->This) { - CSFML_CALL(sprite, SetTexture(*texture->This, adjustToNewSize == sfTrue)) + CSFML_CALL(sprite, SetTexture(*texture->This, resetRect == sfTrue)) sprite->Texture = texture; } } //////////////////////////////////////////////////////////// -/// Set the sub-rectangle of a sprite inside the source image -//////////////////////////////////////////////////////////// -void sfSprite_SetSubRect(sfSprite* sprite, sfIntRect rectangle) +void sfSprite_SetTextureRect(sfSprite* sprite, sfIntRect rectangle) { - CSFML_CALL(sprite, SetSubRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height))) + CSFML_CALL(sprite, SetTextureRect(sf::IntRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height))) } //////////////////////////////////////////////////////////// -/// Resize a sprite (by changing its scale factors) -//////////////////////////////////////////////////////////// -void sfSprite_Resize(sfSprite* sprite, float width, float height) +void sfSprite_SetColor(sfSprite* sprite, sfColor color) { - CSFML_CALL(sprite, Resize(sf::Vector2f(width, height))) + CSFML_CALL(sprite, SetColor(sf::Color(color.r, color.g, color.b, color.a))); } -//////////////////////////////////////////////////////////// -/// Flip a sprite horizontally -//////////////////////////////////////////////////////////// -void sfSprite_FlipX(sfSprite* sprite, sfBool flipped) -{ - CSFML_CALL(sprite, FlipX(flipped == sfTrue)) -} - - -//////////////////////////////////////////////////////////// -/// Flip a sprite vertically -//////////////////////////////////////////////////////////// -void sfSprite_FlipY(sfSprite* sprite, sfBool flipped) -{ - CSFML_CALL(sprite, FlipY(flipped == sfTrue)) -} - - -//////////////////////////////////////////////////////////// -/// Get the source texture of a sprite //////////////////////////////////////////////////////////// const sfTexture* sfSprite_GetTexture(const sfSprite* sprite) { @@ -358,15 +211,12 @@ const sfTexture* sfSprite_GetTexture(const sfSprite* sprite) //////////////////////////////////////////////////////////// -/// Get the sub-rectangle of a sprite inside the source image -//////////////////////////////////////////////////////////// -sfIntRect sfSprite_GetSubRect(const sfSprite* sprite) +sfIntRect sfSprite_GetTextureRect(const sfSprite* sprite) { sfIntRect rect = {0, 0, 0, 0}; CSFML_CHECK_RETURN(sprite, rect) - sf::IntRect sfmlRect = sprite->This.GetSubRect(); - + sf::IntRect sfmlRect = sprite->This.GetTextureRect(); rect.Left = sfmlRect.Left; rect.Top = sfmlRect.Top; rect.Width = sfmlRect.Width; @@ -377,18 +227,16 @@ sfIntRect sfSprite_GetSubRect(const sfSprite* sprite) //////////////////////////////////////////////////////////// -/// Get a sprite width -//////////////////////////////////////////////////////////// -float sfSprite_GetWidth(const sfSprite* sprite) +sfColor sfSprite_GetColor(const sfSprite* sprite) { - CSFML_CALL_RETURN(sprite, GetSize().x, 0.f) -} + sfColor color = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(sprite, color); + sf::Color sfmlColor = sprite->This.GetColor(); + color.r = sfmlColor.r; + color.g = sfmlColor.g; + color.b = sfmlColor.b; + color.a = sfmlColor.a; -//////////////////////////////////////////////////////////// -/// Get a sprite height -//////////////////////////////////////////////////////////// -float sfSprite_GetHeight(const sfSprite* sprite) -{ - CSFML_CALL_RETURN(sprite, GetSize().y, 0.f) + return color; } diff --git a/src/SFML/Graphics/SpriteStruct.h b/src/SFML/Graphics/SpriteStruct.h index ea07a2d..4d7bac0 100644 --- a/src/SFML/Graphics/SpriteStruct.h +++ b/src/SFML/Graphics/SpriteStruct.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include //////////////////////////////////////////////////////////// @@ -37,8 +38,10 @@ //////////////////////////////////////////////////////////// struct sfSprite { - sf::Sprite This; - const sfTexture* Texture; + sf::Sprite This; + const sfTexture* Texture; + mutable sfTransform Transform; + mutable sfTransform InverseTransform; }; diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index eb6e7ef..3aceb0c 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -32,8 +32,6 @@ #include -//////////////////////////////////////////////////////////// -/// Create a new text //////////////////////////////////////////////////////////// sfText* sfText_Create(void) { @@ -44,8 +42,6 @@ sfText* sfText_Create(void) } -//////////////////////////////////////////////////////////// -/// Copy an existing text //////////////////////////////////////////////////////////// sfText* sfText_Copy(sfText* text) { @@ -55,8 +51,6 @@ sfText* sfText_Copy(sfText* text) } -//////////////////////////////////////////////////////////// -/// Destroy an existing text //////////////////////////////////////////////////////////// void sfText_Destroy(sfText* text) { @@ -64,241 +58,124 @@ void sfText_Destroy(sfText* text) } -//////////////////////////////////////////////////////////// -/// Set the X position of a text -//////////////////////////////////////////////////////////// -void sfText_SetX(sfText* text, float x) -{ - CSFML_CALL(text, SetX(x)) -} - - -//////////////////////////////////////////////////////////// -/// Set the Y position of a text -//////////////////////////////////////////////////////////// -void sfText_SetY(sfText* text, float y) -{ - CSFML_CALL(text, SetY(y)) -} - - -//////////////////////////////////////////////////////////// -/// Set the position of a text //////////////////////////////////////////////////////////// void sfText_SetPosition(sfText* text, float x, float y) { - CSFML_CALL(text, SetPosition(sf::Vector2f(x, y))) + CSFML_CALL(text, SetPosition(x, y)); } //////////////////////////////////////////////////////////// -/// Set the horizontal scale of a text -//////////////////////////////////////////////////////////// -void sfText_SetScaleX(sfText* text, float scale) +void sfText_SetRotation(sfText* text, float angle) { - CSFML_CALL(text, SetScaleX(scale)) + CSFML_CALL(text, SetRotation(angle)); } //////////////////////////////////////////////////////////// -/// Set the vertical scale of a text -//////////////////////////////////////////////////////////// -void sfText_SetScaleY(sfText* text, float scale) +void sfText_SetScale(sfText* text, float factorX, float factorY) { - CSFML_CALL(text, SetScaleY(scale)) + CSFML_CALL(text, SetScale(factorX, factorY)); } -//////////////////////////////////////////////////////////// -/// Set the scale of a text -//////////////////////////////////////////////////////////// -void sfText_SetScale(sfText* text, float scaleX, float scaleY) -{ - CSFML_CALL(text, SetScale(sf::Vector2f(scaleX, scaleY))) -} - - -//////////////////////////////////////////////////////////// -/// Set the orientation of a text -//////////////////////////////////////////////////////////// -void sfText_SetRotation(sfText* text, float rotation) -{ - CSFML_CALL(text, SetRotation(rotation)) -} - - -//////////////////////////////////////////////////////////// -/// Set the local origin of a text, in coordinates -/// relative to its left-top corner //////////////////////////////////////////////////////////// void sfText_SetOrigin(sfText* text, float x, float y) { - CSFML_CALL(text, SetOrigin(sf::Vector2f(x, y))) + CSFML_CALL(text, SetOrigin(x, y)); } //////////////////////////////////////////////////////////// -/// Set the color of a text -//////////////////////////////////////////////////////////// -void sfText_SetColor(sfText* text, sfColor color) +void sfText_GetPosition(const sfText* text, float* x, float* y) { - CSFML_CALL(text, SetColor(sf::Color(color.r, color.g, color.b, color.a))) + CSFML_CHECK(text); + + sf::Vector2f point = text->This.GetPosition(); + + if (x) + *x = point.x; + if (y) + *y = point.y; } -//////////////////////////////////////////////////////////// -/// Set the blending mode for a text -//////////////////////////////////////////////////////////// -void sfText_SetBlendMode(sfText* text, sfBlendMode mode) -{ - CSFML_CALL(text, SetBlendMode(static_cast(mode))) -} - - -//////////////////////////////////////////////////////////// -/// Get the X position of a text -//////////////////////////////////////////////////////////// -float sfText_GetX(const sfText* text) -{ - CSFML_CALL_RETURN(text, GetPosition().x, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the Y position of a text -//////////////////////////////////////////////////////////// -float sfText_GetY(const sfText* text) -{ - CSFML_CALL_RETURN(text, GetPosition().y, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the horizontal scale of a text -//////////////////////////////////////////////////////////// -float sfText_GetScaleX(const sfText* text) -{ - CSFML_CALL_RETURN(text, GetScale().x, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the vertical scale of a text -//////////////////////////////////////////////////////////// -float sfText_GetScaleY(const sfText* text) -{ - CSFML_CALL_RETURN(text, GetScale().y, 0.f) -} - - -//////////////////////////////////////////////////////////// -/// Get the orientation of a text //////////////////////////////////////////////////////////// float sfText_GetRotation(const sfText* text) { - CSFML_CALL_RETURN(text, GetRotation(), 0.f) + CSFML_CALL_RETURN(text, GetRotation(), 0.f); } //////////////////////////////////////////////////////////// -/// Get the X position of the origin a text -//////////////////////////////////////////////////////////// -float sfText_GetOriginX(const sfText* text) +void sfText_GetScale(const sfText* text, float* x, float* y) { - CSFML_CALL_RETURN(text, GetOrigin().x, 0.f) + CSFML_CHECK(text); + + sf::Vector2f point = text->This.GetScale(); + + if (x) + *x = point.x; + if (y) + *y = point.y; } //////////////////////////////////////////////////////////// -/// Get the top Y of the origin of a text -//////////////////////////////////////////////////////////// -float sfText_GetOriginY(const sfText* text) +void sfText_GetOrigin(const sfText* text, float* x, float* y) { - CSFML_CALL_RETURN(text, GetOrigin().y, 0.f) + CSFML_CHECK(text); + + sf::Vector2f point = text->This.GetOrigin(); + + if (x) + *x = point.x; + if (y) + *y = point.y; } -//////////////////////////////////////////////////////////// -/// Get the color of a text -//////////////////////////////////////////////////////////// -sfColor sfText_GetColor(const sfText* text) -{ - sfColor color = {0, 0, 0, 0}; - CSFML_CHECK_RETURN(text, color) - - sf::Color SFMLColor = text->This.GetColor(); - return sfColor_FromRGBA(SFMLColor.r, SFMLColor.g, SFMLColor.b, SFMLColor.a); -} - - -//////////////////////////////////////////////////////////// -/// Get the current blending mode of a text -//////////////////////////////////////////////////////////// -sfBlendMode sfText_GetBlendMode(const sfText* text) -{ - CSFML_CHECK_RETURN(text, sfBlendNone) - - return static_cast(text->This.GetBlendMode()); -} - - -//////////////////////////////////////////////////////////// -/// Move a text //////////////////////////////////////////////////////////// void sfText_Move(sfText* text, float offsetX, float offsetY) { - CSFML_CALL(text, Move(sf::Vector2f(offsetX, offsetY))) + CSFML_CALL(text, Move(offsetX, offsetY)); } -//////////////////////////////////////////////////////////// -/// Scale a text -//////////////////////////////////////////////////////////// -void sfText_Scale(sfText* text, float factorX, float factorY) -{ - CSFML_CALL(text, Scale(sf::Vector2f(factorX, factorY))) -} - - -//////////////////////////////////////////////////////////// -/// Rotate a text //////////////////////////////////////////////////////////// void sfText_Rotate(sfText* text, float angle) { - CSFML_CALL(text, Rotate(angle)) + CSFML_CALL(text, Rotate(angle)); } //////////////////////////////////////////////////////////// -/// Transform a point from global coordinates into the text's local coordinates -/// (ie it applies the inverse of object's origin, translation, rotation and scale to the point) -//////////////////////////////////////////////////////////// -void sfText_TransformToLocal(const sfText* text, float pointX, float pointY, float* x, float* y) +void sfText_Scale(sfText* text, float factorX, float factorY) { - CSFML_CHECK(text) - - sf::Vector2f point = text->This.TransformToLocal(sf::Vector2f(pointX, pointY)); - if (x) *x = point.x; - if (y) *y = point.y; + CSFML_CALL(text, Scale(factorX, factorY)); } //////////////////////////////////////////////////////////// -/// Transform a point from the text's local coordinates into global coordinates -/// (ie it applies the object's origin, translation, rotation and scale to the point) -//////////////////////////////////////////////////////////// -void sfText_TransformToGlobal(const sfText* text, float pointX, float pointY, float* x, float* y) +const sfTransform* sfText_GetTransform(const sfText* text) { - CSFML_CHECK(text) + CSFML_CHECK_RETURN(text, NULL); - sf::Vector2f point = text->This.TransformToGlobal(sf::Vector2f(pointX, pointY)); - if (x) *x = point.x; - if (y) *y = point.y; + text->Transform.This = text->This.GetTransform(); + return &text->Transform; } //////////////////////////////////////////////////////////// -/// Set the string of a text (from a multibyte string) +const sfTransform* sfText_GetInverseTransform(const sfText* text) +{ + CSFML_CHECK_RETURN(text, NULL); + + text->InverseTransform.This = text->This.GetInverseTransform(); + return &text->InverseTransform; +} + + //////////////////////////////////////////////////////////// void sfText_SetString(sfText* text, const char* string) { @@ -306,8 +183,6 @@ void sfText_SetString(sfText* text, const char* string) } -//////////////////////////////////////////////////////////// -/// Set the string of a text (from a unicode string) //////////////////////////////////////////////////////////// void sfText_SetUnicodeString(sfText* text, const sfUint32* string) { @@ -316,8 +191,6 @@ void sfText_SetUnicodeString(sfText* text, const sfUint32* string) } -//////////////////////////////////////////////////////////// -/// Set the font of a string //////////////////////////////////////////////////////////// void sfText_SetFont(sfText* text, const sfFont* font) { @@ -328,8 +201,6 @@ void sfText_SetFont(sfText* text, const sfFont* font) } -//////////////////////////////////////////////////////////// -/// Set the size of a string //////////////////////////////////////////////////////////// void sfText_SetCharacterSize(sfText* text, unsigned int size) { @@ -337,8 +208,6 @@ void sfText_SetCharacterSize(sfText* text, unsigned int size) } -//////////////////////////////////////////////////////////// -/// Set the style of a string //////////////////////////////////////////////////////////// void sfText_SetStyle(sfText* text, sfUint32 style) { @@ -346,19 +215,6 @@ void sfText_SetStyle(sfText* text, sfUint32 style) } -//////////////////////////////////////////////////////////// -/// Get the string of a text (returns a unicode string) -//////////////////////////////////////////////////////////// -const sfUint32* sfText_GetUnicodeString(const sfText* text) -{ - CSFML_CHECK_RETURN(text, NULL) - - return text->This.GetString().GetData(); -} - - -//////////////////////////////////////////////////////////// -/// Get the string of a text (returns an ANSI string) //////////////////////////////////////////////////////////// const char* sfText_GetString(const sfText* text) { @@ -371,7 +227,14 @@ const char* sfText_GetString(const sfText* text) //////////////////////////////////////////////////////////// -/// Get the font used by a text +const sfUint32* sfText_GetUnicodeString(const sfText* text) +{ + CSFML_CHECK_RETURN(text, NULL) + + return text->This.GetString().GetData(); +} + + //////////////////////////////////////////////////////////// const sfFont* sfText_GetFont(const sfText* text) { @@ -381,8 +244,6 @@ const sfFont* sfText_GetFont(const sfText* text) } -//////////////////////////////////////////////////////////// -/// Get the size of the characters of a text //////////////////////////////////////////////////////////// unsigned int sfText_GetCharacterSize(const sfText* text) { @@ -390,8 +251,6 @@ unsigned int sfText_GetCharacterSize(const sfText* text) } -//////////////////////////////////////////////////////////// -/// Get the style of a text //////////////////////////////////////////////////////////// sfUint32 sfText_GetStyle(const sfText* text) { @@ -400,33 +259,13 @@ sfUint32 sfText_GetStyle(const sfText* text) //////////////////////////////////////////////////////////// -/// Return the visual position of the Index-th character of the text, -/// in coordinates relative to the text -/// (note : translation, origin, rotation and scale are not applied) -//////////////////////////////////////////////////////////// -void sfText_GetCharacterPos(const sfText* text, size_t index, float* x, float* y) +void sfText_FindCharacterPos(const sfText* text, size_t index, float* x, float* y) { CSFML_CHECK(text); - sf::Vector2f pos = text->This.GetCharacterPos(index); - if (x) *x = pos.x; - if (y) *y = pos.y; -} - - -//////////////////////////////////////////////////////////// -/// Get the bounding rectangle of a text on screen -//////////////////////////////////////////////////////////// -sfFloatRect sfText_GetRect(const sfText* text) -{ - sfFloatRect rect = {0.f, 0.f, 0.f, 0.f}; - CSFML_CHECK_RETURN(text, rect) - - sf::FloatRect SFMLRect = text->This.GetRect(); - text->Rect.Left = SFMLRect.Left; - text->Rect.Top = SFMLRect.Top; - text->Rect.Width = SFMLRect.Width; - text->Rect.Height = SFMLRect.Height; - - return text->Rect; + sf::Vector2f pos = text->This.FindCharacterPos(index); + if (x) + *x = pos.x; + if (y) + *y = pos.y; } diff --git a/src/SFML/Graphics/TextStruct.h b/src/SFML/Graphics/TextStruct.h index 161507c..3b982f9 100644 --- a/src/SFML/Graphics/TextStruct.h +++ b/src/SFML/Graphics/TextStruct.h @@ -31,6 +31,7 @@ #include #include #include +#include #include @@ -42,7 +43,8 @@ struct sfText sf::Text This; const sfFont* Font; mutable std::string String; - mutable sfFloatRect Rect; + mutable sfTransform Transform; + mutable sfTransform InverseTransform; }; diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 8050652..8589e2b 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -34,8 +34,6 @@ #include -//////////////////////////////////////////////////////////// -/// Create a new texture //////////////////////////////////////////////////////////// sfTexture* sfTexture_Create(unsigned int width, unsigned int height) { @@ -51,8 +49,6 @@ sfTexture* sfTexture_Create(unsigned int width, unsigned int height) } -//////////////////////////////////////////////////////////// -/// Create a new texture from a file //////////////////////////////////////////////////////////// sfTexture* sfTexture_CreateFromFile(const char* filename, const sfIntRect* area) { @@ -72,8 +68,6 @@ sfTexture* sfTexture_CreateFromFile(const char* filename, const sfIntRect* area) } -//////////////////////////////////////////////////////////// -/// Create a new texture from a file in memory //////////////////////////////////////////////////////////// sfTexture* sfTexture_CreateFromMemory(const void* data, size_t sizeInBytes, const sfIntRect* area) { @@ -93,8 +87,6 @@ sfTexture* sfTexture_CreateFromMemory(const void* data, size_t sizeInBytes, cons } -//////////////////////////////////////////////////////////// -/// Create a new texture from a custom stream //////////////////////////////////////////////////////////// sfTexture* sfTexture_CreateFromStream(sfInputStream* stream, const sfIntRect* area) { @@ -117,8 +109,6 @@ sfTexture* sfTexture_CreateFromStream(sfInputStream* stream, const sfIntRect* ar } -//////////////////////////////////////////////////////////// -/// Create a new texture from an image //////////////////////////////////////////////////////////// sfTexture* sfTexture_CreateFromImage(const sfImage* image, const sfIntRect* area) { @@ -140,8 +130,6 @@ sfTexture* sfTexture_CreateFromImage(const sfImage* image, const sfIntRect* area } -//////////////////////////////////////////////////////////// -/// Copy an existing texture //////////////////////////////////////////////////////////// sfTexture* sfTexture_Copy(sfTexture* texture) { @@ -151,8 +139,6 @@ sfTexture* sfTexture_Copy(sfTexture* texture) } -//////////////////////////////////////////////////////////// -/// Destroy an existing texture //////////////////////////////////////////////////////////// void sfTexture_Destroy(sfTexture* texture) { @@ -160,8 +146,6 @@ void sfTexture_Destroy(sfTexture* texture) } -//////////////////////////////////////////////////////////// -/// Return the width of the texture //////////////////////////////////////////////////////////// unsigned int sfTexture_GetWidth(const sfTexture* texture) { @@ -169,8 +153,6 @@ unsigned int sfTexture_GetWidth(const sfTexture* texture) } -//////////////////////////////////////////////////////////// -/// Return the height of the texture //////////////////////////////////////////////////////////// unsigned int sfTexture_GetHeight(const sfTexture* texture) { @@ -178,8 +160,6 @@ unsigned int sfTexture_GetHeight(const sfTexture* texture) } -//////////////////////////////////////////////////////////// -/// Copy a texture's pixels to an image //////////////////////////////////////////////////////////// sfImage* sfTexture_CopyToImage(const sfTexture* texture) { @@ -193,8 +173,6 @@ sfImage* sfTexture_CopyToImage(const sfTexture* texture) } -//////////////////////////////////////////////////////////// -/// Update a texture from an array of pixels //////////////////////////////////////////////////////////// void sfTexture_UpdateFromPixels(sfTexture* texture, const sfUint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y) { @@ -202,8 +180,6 @@ void sfTexture_UpdateFromPixels(sfTexture* texture, const sfUint8* pixels, unsig } -//////////////////////////////////////////////////////////// -/// Update a texture from an image //////////////////////////////////////////////////////////// void sfTexture_UpdateFromImage(sfTexture* texture, const sfImage* image, unsigned int x, unsigned int y) { @@ -213,8 +189,6 @@ void sfTexture_UpdateFromImage(sfTexture* texture, const sfImage* image, unsigne } -//////////////////////////////////////////////////////////// -/// Update a texture from the contents of a window //////////////////////////////////////////////////////////// void sfTexture_UpdateFromWindow(sfTexture* texture, const sfWindow* window, unsigned int x, unsigned int y) { @@ -224,8 +198,6 @@ void sfTexture_UpdateFromWindow(sfTexture* texture, const sfWindow* window, unsi } -//////////////////////////////////////////////////////////// -/// Update a texture from the contents of a render-window //////////////////////////////////////////////////////////// void sfTexture_UpdateFromRenderWindow(sfTexture* texture, const sfRenderWindow* renderWindow, unsigned int x, unsigned int y) { @@ -235,8 +207,6 @@ void sfTexture_UpdateFromRenderWindow(sfTexture* texture, const sfRenderWindow* } -//////////////////////////////////////////////////////////// -/// Activate a texture for rendering //////////////////////////////////////////////////////////// void sfTexture_Bind(const sfTexture* texture) { @@ -244,8 +214,6 @@ void sfTexture_Bind(const sfTexture* texture) } -//////////////////////////////////////////////////////////// -/// Enable or disable the smooth filter on a texture //////////////////////////////////////////////////////////// void sfTexture_SetSmooth(sfTexture* texture, sfBool smooth) { @@ -253,8 +221,6 @@ void sfTexture_SetSmooth(sfTexture* texture, sfBool smooth) } -//////////////////////////////////////////////////////////// -/// Tell whether the smooth filter is enabled or not for a texture //////////////////////////////////////////////////////////// sfBool sfTexture_IsSmooth(const sfTexture* texture) { @@ -266,7 +232,22 @@ sfBool sfTexture_IsSmooth(const sfTexture* texture) //////////////////////////////////////////////////////////// -/// Convert a rectangle of pixels into texture coordinates +void sfTexture_SetRepeated(sfTexture* texture, sfBool repeated) +{ + CSFML_CALL_PTR(texture, SetRepeated(repeated == sfTrue)); +} + + +//////////////////////////////////////////////////////////// +sfBool sfTexture_IsRepeated(const sfTexture* texture) +{ + CSFML_CHECK_RETURN(texture, sfFalse); + CSFML_CHECK_RETURN(texture->This, sfFalse); + + return texture->This->IsRepeated(); +} + + //////////////////////////////////////////////////////////// sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle) { @@ -286,8 +267,6 @@ sfFloatRect sfTexture_GetTexCoords(const sfTexture* texture, sfIntRect rectangle } -//////////////////////////////////////////////////////////// -/// Get the maximum texture size allowed //////////////////////////////////////////////////////////// unsigned int sfTexture_GetMaximumSize() { diff --git a/src/SFML/Graphics/Transform.cpp b/src/SFML/Graphics/Transform.cpp new file mode 100644 index 0000000..3bed72b --- /dev/null +++ b/src/SFML/Graphics/Transform.cpp @@ -0,0 +1,158 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +//////////////////////////////////////////////////////////// +sfTransform* sfTransform_Create(void) +{ + return new sfTransform; +} + + +//////////////////////////////////////////////////////////// +sfTransform* sfTransform_CreateFromMatrix(float a00, float a01, float a02, + float a10, float a11, float a12, + float a20, float a21, float a22) +{ + sfTransform* transform = new sfTransform; + transform->This = sf::Transform(a00, a01, a02, a10, a11, a12, a20, a21, a22); + return transform; +} + + +//////////////////////////////////////////////////////////// +sfTransform* sfTransform_Copy(sfTransform* transform) +{ + CSFML_CHECK_RETURN(transform, NULL); + + return new sfTransform(*transform); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_Destroy(sfTransform* transform) +{ + delete transform; +} + + +//////////////////////////////////////////////////////////// +const float* sfTransform_GetMatrix(const sfTransform* transform) +{ + CSFML_CALL_RETURN(transform, GetMatrix(), NULL); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_GetInverse(const sfTransform* transform, sfTransform* result) +{ + CSFML_CHECK(transform); + + if (result) + result->This = transform->This.GetInverse(); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_TransformPoint(const sfTransform* transform, float x, float y, float* transformedX, float* transformedY) +{ + CSFML_CHECK(transform); + + sf::Vector2f point = transform->This.TransformPoint(x, y); + + if (transformedX) + *transformedX = point.x; + if (transformedY) + *transformedY = point.y; +} + + +//////////////////////////////////////////////////////////// +void sfTransform_TransformRect(const sfTransform* transform, sfFloatRect rectangle, sfFloatRect* transformedRectangle) +{ + CSFML_CHECK(transform); + + sf::FloatRect rect = transform->This.TransformRect(sf::FloatRect(rectangle.Left, rectangle.Top, rectangle.Width, rectangle.Height)); + + if (transformedRectangle) + { + transformedRectangle->Left = rect.Left; + transformedRectangle->Top = rect.Top; + transformedRectangle->Width = rect.Width; + transformedRectangle->Height = rect.Height; + } +} + + +//////////////////////////////////////////////////////////// +void sfTransform_Combine(const sfTransform* left, const sfTransform* right, sfTransform* result) +{ + CSFML_CHECK(left); + CSFML_CHECK(right); + + if (result) + result->This = left->This.Combine(right->This); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_Translate(sfTransform* transform, float x, float y) +{ + CSFML_CALL(transform, Translate(x, y)); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_Rotate(sfTransform* transform, float angle) +{ + CSFML_CALL(transform, Rotate(angle)); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_RotateWithCenter(sfTransform* transform, float angle, float centerX, float centerY) +{ + CSFML_CALL(transform, Rotate(angle, centerX, centerY)); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_Scale(sfTransform* transform, float scaleX, float scaleY) +{ + CSFML_CALL(transform, Scale(scaleX, scaleY)); +} + + +//////////////////////////////////////////////////////////// +void sfTransform_ScaleWithCenter(sfTransform* transform, float scaleX, float scaleY, float centerX, float centerY) +{ + CSFML_CALL(transform, Scale(scaleX, scaleY, centerX, centerY)); +} diff --git a/src/SFML/Graphics/ShapeStruct.h b/src/SFML/Graphics/TransformStruct.h similarity index 86% rename from src/SFML/Graphics/ShapeStruct.h rename to src/SFML/Graphics/TransformStruct.h index 1eb54c3..faaaada 100644 --- a/src/SFML/Graphics/ShapeStruct.h +++ b/src/SFML/Graphics/TransformStruct.h @@ -22,22 +22,22 @@ // //////////////////////////////////////////////////////////// -#ifndef SFML_SHAPESTRUCT_H -#define SFML_SHAPESTRUCT_H +#ifndef SFML_TRANSFORMSTRUCT_H +#define SFML_TRANSFORMSTRUCT_H //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include +#include //////////////////////////////////////////////////////////// -// Internal structure of sfShape +// Internal structure of sfTransform //////////////////////////////////////////////////////////// -struct sfShape +struct sfTransform { - sf::Shape This; + sf::Transform This; }; -#endif // SFML_SHAPESTRUCT_H +#endif // SFML_TRANSFORMSTRUCT_H diff --git a/src/SFML/Graphics/VertexArray.cpp b/src/SFML/Graphics/VertexArray.cpp new file mode 100644 index 0000000..ef447e0 --- /dev/null +++ b/src/SFML/Graphics/VertexArray.cpp @@ -0,0 +1,121 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + + +//////////////////////////////////////////////////////////// +sfVertexArray* sfVertexArray_Create(void) +{ + return new sfVertexArray; +} + + +//////////////////////////////////////////////////////////// +sfVertexArray* sfTransform_Copy(sfVertexArray* vertexArray) +{ + CSFML_CHECK_RETURN(vertexArray, NULL); + + return new sfVertexArray(*vertexArray); +} + + +//////////////////////////////////////////////////////////// +void sfVertexArray_Destroy(sfVertexArray* vertexArray) +{ + delete vertexArray; +} + + +//////////////////////////////////////////////////////////// +unsigned int sfVertexArray_GetVertexCount(const sfVertexArray* vertexArray) +{ + CSFML_CALL_RETURN(vertexArray, GetVertexCount(), 0); +} + + +//////////////////////////////////////////////////////////// +sfVertex* sfVertexArray_At(sfVertexArray* vertexArray, unsigned int index) +{ + CSFML_CHECK_RETURN(vertexArray, NULL); + + // the cast is safe, sfVertex has to be binary compatible with sf::Vertex + return reinterpret_cast(&vertexArray->This[index]); +} + + +//////////////////////////////////////////////////////////// +void sfVertexArray_Clear(sfVertexArray* vertexArray) +{ + CSFML_CALL(vertexArray, Clear()); +} + + +//////////////////////////////////////////////////////////// +void sfVertexArray_Resize(sfVertexArray* vertexArray, unsigned int vertexCount) +{ + CSFML_CALL(vertexArray, Resize(vertexCount)); +} + + +//////////////////////////////////////////////////////////// +void sfVertexArray_Append(sfVertexArray* vertexArray, sfVertex vertex) +{ + // the cast is safe, sfVertex has to be binary compatible with sf::Vertex + CSFML_CALL(vertexArray, Append(reinterpret_cast(vertex))); +} + + +//////////////////////////////////////////////////////////// +void sfVertexArray_SetPrimitiveType(sfVertexArray* vertexArray, sfPrimitiveType type) +{ + CSFML_CALL(vertexArray, SetPrimitiveType(static_cast(type))); +} + + +//////////////////////////////////////////////////////////// +sfPrimitiveType sfVertexArray_GetPrimitiveType(sfVertexArray* vertexArray) +{ + CSFML_CHECK_RETURN(vertexArray, sfPoints); + return static_cast(vertexArray->This.GetPrimitiveType()); +} + + +//////////////////////////////////////////////////////////// +sfFloatRect sfVertexArray_GetBounds(sfVertexArray* vertexArray) +{ + sfFloatRect rect = {0, 0, 0, 0}; + CSFML_CHECK_RETURN(vertexArray, rect); + + sf::FloatRect sfmlRect = vertexArray->This.GetBounds(); + rect.Left = sfmlRect.Left; + rect.Top = sfmlRect.Top; + rect.Width = sfmlRect.Width; + rect.Height = sfmlRect.Height; +} diff --git a/src/SFML/Graphics/VertexArrayStruct.h b/src/SFML/Graphics/VertexArrayStruct.h new file mode 100644 index 0000000..38889be --- /dev/null +++ b/src/SFML/Graphics/VertexArrayStruct.h @@ -0,0 +1,43 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_VERTEXARRAYSTRUCT_H +#define SFML_VERTEXARRAYSTRUCT_H + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +//////////////////////////////////////////////////////////// +// Internal structure of sfVertexArray +//////////////////////////////////////////////////////////// +struct sfVertexArray +{ + sf::VertexArray This; +}; + + +#endif // SFML_VERTEXARRAYSTRUCT_H diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 30f3696..f12828d 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -92,9 +92,9 @@ void sfWindow_Close(sfWindow* window) //////////////////////////////////////////////////////////// -sfBool sfWindow_IsOpened(const sfWindow* window) +sfBool sfWindow_IsOpen(const sfWindow* window) { - CSFML_CALL_RETURN(window, IsOpened(), sfFalse); + CSFML_CALL_RETURN(window, IsOpen(), sfFalse); } @@ -248,13 +248,6 @@ void sfWindow_SetFramerateLimit(sfWindow* window, unsigned int limit) } -//////////////////////////////////////////////////////////// -sfUint32 sfWindow_GetFrameTime(const sfWindow* window) -{ - CSFML_CALL_RETURN(window, GetFrameTime(), 0) -} - - //////////////////////////////////////////////////////////// void sfWindow_SetJoystickThreshold(sfWindow* window, float threshold) {