diff --git a/include/SFML/Graphics/CircleShape.h b/include/SFML/Graphics/CircleShape.h index a211c05..8a26298 100644 --- a/include/SFML/Graphics/CircleShape.h +++ b/include/SFML/Graphics/CircleShape.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -202,7 +203,7 @@ CSFML_GRAPHICS_API void sfCircleShape_scale(sfCircleShape* shape, sfVector2f fac /// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfCircleShape_getTransform(const sfCircleShape* shape); +CSFML_GRAPHICS_API sfTransform sfCircleShape_getTransform(const sfCircleShape* shape); //////////////////////////////////////////////////////////// /// \brief Get the inverse of the combined transform of a circle shape @@ -212,7 +213,7 @@ CSFML_GRAPHICS_API const sfTransform* sfCircleShape_getTransform(const sfCircleS /// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfCircleShape_getInverseTransform(const sfCircleShape* shape); +CSFML_GRAPHICS_API sfTransform sfCircleShape_getInverseTransform(const sfCircleShape* shape); //////////////////////////////////////////////////////////// /// \brief Change the source texture of a circle shape diff --git a/include/SFML/Graphics/ConvexShape.h b/include/SFML/Graphics/ConvexShape.h index 301bb60..293e948 100644 --- a/include/SFML/Graphics/ConvexShape.h +++ b/include/SFML/Graphics/ConvexShape.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -202,7 +203,7 @@ CSFML_GRAPHICS_API void sfConvexShape_scale(sfConvexShape* shape, sfVector2f fac /// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfConvexShape_getTransform(const sfConvexShape* shape); +CSFML_GRAPHICS_API sfTransform sfConvexShape_getTransform(const sfConvexShape* shape); //////////////////////////////////////////////////////////// /// \brief Get the inverse of the combined transform of a convex shape @@ -212,7 +213,7 @@ CSFML_GRAPHICS_API const sfTransform* sfConvexShape_getTransform(const sfConvexS /// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfConvexShape_getInverseTransform(const sfConvexShape* shape); +CSFML_GRAPHICS_API sfTransform sfConvexShape_getInverseTransform(const sfConvexShape* shape); //////////////////////////////////////////////////////////// /// \brief Change the source texture of a convex shape diff --git a/include/SFML/Graphics/RectangleShape.h b/include/SFML/Graphics/RectangleShape.h index 8327c82..f33699e 100644 --- a/include/SFML/Graphics/RectangleShape.h +++ b/include/SFML/Graphics/RectangleShape.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -202,7 +203,7 @@ CSFML_GRAPHICS_API void sfRectangleShape_scale(sfRectangleShape* shape, sfVector /// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfRectangleShape_getTransform(const sfRectangleShape* shape); +CSFML_GRAPHICS_API sfTransform sfRectangleShape_getTransform(const sfRectangleShape* shape); //////////////////////////////////////////////////////////// /// \brief Get the inverse of the combined transform of a rectangle shape @@ -212,7 +213,7 @@ CSFML_GRAPHICS_API const sfTransform* sfRectangleShape_getTransform(const sfRect /// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfRectangleShape_getInverseTransform(const sfRectangleShape* shape); +CSFML_GRAPHICS_API sfTransform sfRectangleShape_getInverseTransform(const sfRectangleShape* shape); //////////////////////////////////////////////////////////// /// \brief Change the source texture of a rectangle shape diff --git a/include/SFML/Graphics/RenderStates.h b/include/SFML/Graphics/RenderStates.h index 070b1e8..4bf4785 100644 --- a/include/SFML/Graphics/RenderStates.h +++ b/include/SFML/Graphics/RenderStates.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include @@ -40,7 +41,7 @@ typedef struct { sfBlendMode blendMode; ///< Blending mode - sfTransform* transform; ///< Transform + sfTransform transform; ///< Transform const sfTexture* texture; ///< Texture const sfShader* shader; ///< Shader } sfRenderStates; diff --git a/include/SFML/Graphics/Shader.h b/include/SFML/Graphics/Shader.h index da61070..8643f6c 100644 --- a/include/SFML/Graphics/Shader.h +++ b/include/SFML/Graphics/Shader.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include #include #include @@ -290,7 +291,7 @@ CSFML_GRAPHICS_API void sfShader_setColorParameter(sfShader* shader, const char* /// \param transform Transform to assign /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfShader_setTransformParameter(sfShader* shader, const char* name, const sfTransform* transform); +CSFML_GRAPHICS_API void sfShader_setTransformParameter(sfShader* shader, const char* name, sfTransform transform); //////////////////////////////////////////////////////////// /// \brief Change a texture parameter of a shader diff --git a/include/SFML/Graphics/Shape.h b/include/SFML/Graphics/Shape.h index 11e2354..b5e5b50 100644 --- a/include/SFML/Graphics/Shape.h +++ b/include/SFML/Graphics/Shape.h @@ -31,6 +31,7 @@ #include #include #include +#include #include #include @@ -201,7 +202,7 @@ CSFML_GRAPHICS_API void sfShape_scale(sfShape* shape, sfVector2f factors); /// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfShape_getTransform(const sfShape* shape); +CSFML_GRAPHICS_API sfTransform sfShape_getTransform(const sfShape* shape); //////////////////////////////////////////////////////////// /// \brief Get the inverse of the combined transform of a shape @@ -211,7 +212,7 @@ CSFML_GRAPHICS_API const sfTransform* sfShape_getTransform(const sfShape* shape) /// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfShape_getInverseTransform(const sfShape* shape); +CSFML_GRAPHICS_API sfTransform sfShape_getInverseTransform(const sfShape* shape); //////////////////////////////////////////////////////////// /// \brief Change the source texture of a shape diff --git a/include/SFML/Graphics/Sprite.h b/include/SFML/Graphics/Sprite.h index 9d60ef7..7b4a548 100644 --- a/include/SFML/Graphics/Sprite.h +++ b/include/SFML/Graphics/Sprite.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -203,7 +204,7 @@ CSFML_GRAPHICS_API void sfSprite_scale(sfSprite* sprite, sfVector2f factors); /// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfSprite_getTransform(const sfSprite* sprite); +CSFML_GRAPHICS_API sfTransform sfSprite_getTransform(const sfSprite* sprite); //////////////////////////////////////////////////////////// /// \brief Get the inverse of the combined transform of a sprite @@ -213,7 +214,7 @@ CSFML_GRAPHICS_API const sfTransform* sfSprite_getTransform(const sfSprite* spri /// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfSprite_getInverseTransform(const sfSprite* sprite); +CSFML_GRAPHICS_API sfTransform sfSprite_getInverseTransform(const sfSprite* sprite); //////////////////////////////////////////////////////////// /// \brief Change the source texture of a sprite diff --git a/include/SFML/Graphics/Text.h b/include/SFML/Graphics/Text.h index 172cd4a..74d8183 100644 --- a/include/SFML/Graphics/Text.h +++ b/include/SFML/Graphics/Text.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include @@ -215,7 +216,7 @@ CSFML_GRAPHICS_API void sfText_scale(sfText* text, sfVector2f factors); /// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfText_getTransform(const sfText* text); +CSFML_GRAPHICS_API sfTransform sfText_getTransform(const sfText* text); //////////////////////////////////////////////////////////// /// \brief Get the inverse of the combined transform of a text @@ -225,7 +226,7 @@ CSFML_GRAPHICS_API const sfTransform* sfText_getTransform(const sfText* text); /// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfText_getInverseTransform(const sfText* text); +CSFML_GRAPHICS_API sfTransform sfText_getInverseTransform(const sfText* text); //////////////////////////////////////////////////////////// /// \brief Set the string of a text (from an ANSI string) diff --git a/include/SFML/Graphics/Transform.h b/include/SFML/Graphics/Transform.h index 374296e..783b7fc 100644 --- a/include/SFML/Graphics/Transform.h +++ b/include/SFML/Graphics/Transform.h @@ -34,15 +34,22 @@ #include + //////////////////////////////////////////////////////////// -/// \brief Create a new transform -/// -/// This function creates an identity transform. -/// -/// \return A new sfTransform object +/// \brief Encapsulate a 3x3 transform matrix /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfTransform* sfTransform_create(void); +typedef struct +{ + float matrix[9]; +} sfTransform; + + +//////////////////////////////////////////////////////////// +/// \brief Identity transform (does nothing) +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfTransform sfTransform_Identity; //////////////////////////////////////////////////////////// /// \brief Create a new transform from a matrix @@ -60,46 +67,29 @@ CSFML_GRAPHICS_API sfTransform* sfTransform_create(void); /// \return A new sfTransform object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_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_GRAPHICS_API sfTransform* sfTransform_copy(sfTransform* transform); - -//////////////////////////////////////////////////////////// -/// \brief Destroy an existing transform -/// -/// \param transform Transform to delete -/// -//////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfTransform_destroy(sfTransform* transform); +CSFML_GRAPHICS_API sfTransform sfTransform_fromMatrix(float a00, float a01, float a02, + float a10, float a11, float a12, + float a20, float a21, float a22); //////////////////////////////////////////////////////////// /// \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. +/// This function fills an array of 16 floats with the transform +/// converted as a 4x4 matrix, which is directly compatible with +/// OpenGL functions. /// /// \code -/// sfTransform* transform = ...; -/// glLoadMatrixf(sfTransform_getMatrix(transform)); +/// sfTransform transform = ...; +/// float matrix[16]; +/// sfTransform_getMatrix(&transform, matrix) +/// glLoadMatrixf(matrix); /// \endcode /// /// \param transform Transform object -/// -/// \return Pointer to a 4x4 matrix +/// \param matrix Pointer to the 16-element array to fill with the matrix /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const float* sfTransform_getMatrix(const sfTransform* transform); +CSFML_GRAPHICS_API void sfTransform_getMatrix(const sfTransform* transform, float* matrix); //////////////////////////////////////////////////////////// /// \brief Return the inverse of a transform @@ -108,10 +98,10 @@ CSFML_GRAPHICS_API const float* sfTransform_getMatrix(const sfTransform* transfo /// is returned. /// /// \param transform Transform object -/// \param result Returned inverse matrix +/// \return The inverse matrix /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfTransform_getInverse(const sfTransform* transform, sfTransform* result); +CSFML_GRAPHICS_API sfTransform sfTransform_getInverse(const sfTransform* transform); //////////////////////////////////////////////////////////// /// \brief Apply a transform to a 2D point diff --git a/include/SFML/Graphics/Transformable.h b/include/SFML/Graphics/Transformable.h index 1b2f0fe..df41030 100644 --- a/include/SFML/Graphics/Transformable.h +++ b/include/SFML/Graphics/Transformable.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include @@ -200,7 +201,7 @@ CSFML_GRAPHICS_API void sfTransformable_scale(sfTransformable* transformable, sf /// \return Transform combining the position/rotation/scale/origin of the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfTransformable_getTransform(const sfTransformable* transformable); +CSFML_GRAPHICS_API sfTransform sfTransformable_getTransform(const sfTransformable* transformable); //////////////////////////////////////////////////////////// /// \brief Get the inverse of the combined transform of a transformable @@ -210,7 +211,7 @@ CSFML_GRAPHICS_API const sfTransform* sfTransformable_getTransform(const sfTrans /// \return Inverse of the combined transformations applied to the object /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const sfTransform* sfTransformable_getInverseTransform(const sfTransformable* transformable); +CSFML_GRAPHICS_API sfTransform sfTransformable_getInverseTransform(const sfTransformable* transformable); #endif // SFML_TRANSFORMABLE_H diff --git a/include/SFML/Graphics/Types.h b/include/SFML/Graphics/Types.h index 908c8f9..5b5ac59 100644 --- a/include/SFML/Graphics/Types.h +++ b/include/SFML/Graphics/Types.h @@ -38,7 +38,6 @@ typedef struct sfShape sfShape; typedef struct sfSprite sfSprite; typedef struct sfText sfText; typedef struct sfTexture sfTexture; -typedef struct sfTransform sfTransform; typedef struct sfTransformable sfTransformable; typedef struct sfVertexArray sfVertexArray; typedef struct sfView sfView; diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index 07c6250..b6ec32a 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -12,6 +12,7 @@ set(SRC ${SRCROOT}/Color.cpp ${INCROOT}/Color.h ${SRCROOT}/ConvertRenderStates.hpp + ${SRCROOT}/ConvertTransform.hpp ${SRCROOT}/ConvexShape.cpp ${SRCROOT}/ConvexShapeStruct.h ${INCROOT}/ConvexShape.h @@ -49,7 +50,6 @@ set(SRC ${SRCROOT}/TextureStruct.h ${INCROOT}/Texture.h ${SRCROOT}/Transform.cpp - ${SRCROOT}/TransformStruct.h ${INCROOT}/Transform.h ${SRCROOT}/Transformable.cpp ${SRCROOT}/TransformableStruct.h diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp index dd43ba1..edb2fe4 100644 --- a/src/SFML/Graphics/CircleShape.cpp +++ b/src/SFML/Graphics/CircleShape.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -156,22 +157,22 @@ void sfCircleShape_scale(sfCircleShape* shape, sfVector2f factors) //////////////////////////////////////////////////////////// -const sfTransform* sfCircleShape_getTransform(const sfCircleShape* shape) +sfTransform sfCircleShape_getTransform(const sfCircleShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->Transform.This = shape->This.getTransform(); - return &shape->Transform; + shape->Transform = convertTransform(shape->This.getTransform()); + return shape->Transform; } //////////////////////////////////////////////////////////// -const sfTransform* sfCircleShape_getInverseTransform(const sfCircleShape* shape) +sfTransform sfCircleShape_getInverseTransform(const sfCircleShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->InverseTransform.This = shape->This.getInverseTransform(); - return &shape->InverseTransform; + shape->InverseTransform = convertTransform(shape->This.getInverseTransform()); + return shape->InverseTransform; } diff --git a/src/SFML/Graphics/CircleShapeStruct.h b/src/SFML/Graphics/CircleShapeStruct.h index edffd13..dffbcae 100644 --- a/src/SFML/Graphics/CircleShapeStruct.h +++ b/src/SFML/Graphics/CircleShapeStruct.h @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/ConvertRenderStates.hpp b/src/SFML/Graphics/ConvertRenderStates.hpp index 39b4836..c7e1649 100644 --- a/src/SFML/Graphics/ConvertRenderStates.hpp +++ b/src/SFML/Graphics/ConvertRenderStates.hpp @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include #include #include @@ -45,7 +45,7 @@ inline sf::RenderStates convertRenderStates(const sfRenderStates* states) if (states) { sfmlStates.blendMode = static_cast(states->blendMode); - sfmlStates.transform = states->transform ? states->transform->This : sf::Transform::Identity; + sfmlStates.transform = convertTransform(states->transform); sfmlStates.texture = states->texture ? states->texture->This : NULL; sfmlStates.shader = states->shader ? &states->shader->This : NULL; } diff --git a/src/SFML/Graphics/TransformStruct.h b/src/SFML/Graphics/ConvertTransform.hpp similarity index 63% rename from src/SFML/Graphics/TransformStruct.h rename to src/SFML/Graphics/ConvertTransform.hpp index 7e8c806..f81178c 100644 --- a/src/SFML/Graphics/TransformStruct.h +++ b/src/SFML/Graphics/ConvertTransform.hpp @@ -22,22 +22,37 @@ // //////////////////////////////////////////////////////////// -#ifndef SFML_TRANSFORMSTRUCT_H -#define SFML_TRANSFORMSTRUCT_H +#ifndef SFML_CONVERTTRANSFORM_H +#define SFML_CONVERTTRANSFORM_H //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include #include //////////////////////////////////////////////////////////// -// Internal structure of sfTransform +// Convert sf::Transform to sfTransform //////////////////////////////////////////////////////////// -struct sfTransform +inline sfTransform convertTransform(const sf::Transform& transform) { - sf::Transform This; -}; + const float* m = transform.getMatrix(); + sfTransform converted = {m[0], m[4], m[12], m[1], m[5], m[13], m[3], m[7], m[15]}; + return converted; +} -#endif // SFML_TRANSFORMSTRUCT_H +//////////////////////////////////////////////////////////// +// Convert sfTransform to sf::Transform +//////////////////////////////////////////////////////////// +inline sf::Transform convertTransform(const sfTransform& transform) +{ + const float* m = transform.matrix; + return sf::Transform(m[0], m[1], m[2], + m[3], m[4], m[5], + m[6], m[7], m[8]); +} + + +#endif // SFML_CONVERTTRANSFORM_H diff --git a/src/SFML/Graphics/ConvexShape.cpp b/src/SFML/Graphics/ConvexShape.cpp index a1d4831..dacb465 100644 --- a/src/SFML/Graphics/ConvexShape.cpp +++ b/src/SFML/Graphics/ConvexShape.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -153,22 +154,22 @@ void sfConvexShape_scale(sfConvexShape* shape, sfVector2f factors) //////////////////////////////////////////////////////////// -const sfTransform* sfConvexShape_getTransform(const sfConvexShape* shape) +sfTransform sfConvexShape_getTransform(const sfConvexShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->Transform.This = shape->This.getTransform(); - return &shape->Transform; + shape->Transform = convertTransform(shape->This.getTransform()); + return shape->Transform; } //////////////////////////////////////////////////////////// -const sfTransform* sfConvexShape_getInverseTransform(const sfConvexShape* shape) +sfTransform sfConvexShape_getInverseTransform(const sfConvexShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->InverseTransform.This = shape->This.getInverseTransform(); - return &shape->InverseTransform; + shape->InverseTransform = convertTransform(shape->This.getInverseTransform()); + return shape->InverseTransform; } diff --git a/src/SFML/Graphics/ConvexShapeStruct.h b/src/SFML/Graphics/ConvexShapeStruct.h index 35a5fe6..e1de254 100644 --- a/src/SFML/Graphics/ConvexShapeStruct.h +++ b/src/SFML/Graphics/ConvexShapeStruct.h @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/RectangleShape.cpp b/src/SFML/Graphics/RectangleShape.cpp index 462c2d6..7c86c24 100644 --- a/src/SFML/Graphics/RectangleShape.cpp +++ b/src/SFML/Graphics/RectangleShape.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -153,22 +154,22 @@ void sfRectangleShape_scale(sfRectangleShape* shape, sfVector2f factors) //////////////////////////////////////////////////////////// -const sfTransform* sfRectangleShape_getTransform(const sfRectangleShape* shape) +sfTransform sfRectangleShape_getTransform(const sfRectangleShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->Transform.This = shape->This.getTransform(); - return &shape->Transform; + shape->Transform = convertTransform(shape->This.getTransform()); + return shape->Transform; } //////////////////////////////////////////////////////////// -const sfTransform* sfRectangleShape_getInverseTransform(const sfRectangleShape* shape) +sfTransform sfRectangleShape_getInverseTransform(const sfRectangleShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->InverseTransform.This = shape->This.getInverseTransform(); - return &shape->InverseTransform; + shape->InverseTransform = convertTransform(shape->This.getInverseTransform()); + return shape->InverseTransform; } diff --git a/src/SFML/Graphics/RectangleShapeStruct.h b/src/SFML/Graphics/RectangleShapeStruct.h index ddfa53e..b6affd7 100644 --- a/src/SFML/Graphics/RectangleShapeStruct.h +++ b/src/SFML/Graphics/RectangleShapeStruct.h @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index c8c998a..da943d6 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include #include #include @@ -196,9 +196,9 @@ void sfShader_setColorParameter(sfShader* shader, const char* name, sfColor colo //////////////////////////////////////////////////////////// -void sfShader_setTransformParameter(sfShader* shader, const char* name, const sfTransform* transform) +void sfShader_setTransformParameter(sfShader* shader, const char* name, sfTransform transform) { - CSFML_CALL(shader, setParameter(name, transform ? transform->This : sf::Transform::Identity)); + CSFML_CALL(shader, setParameter(name, convertTransform(transform))); } diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 88583a3..0cc8f82 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -28,6 +28,7 @@ #include #include #include +#include #include @@ -146,22 +147,22 @@ void sfShape_scale(sfShape* shape, sfVector2f factors) //////////////////////////////////////////////////////////// -const sfTransform* sfShape_getTransform(const sfShape* shape) +sfTransform sfShape_getTransform(const sfShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->Transform.This = shape->This.getTransform(); - return &shape->Transform; + shape->Transform = convertTransform(shape->This.getTransform()); + return shape->Transform; } //////////////////////////////////////////////////////////// -const sfTransform* sfShape_getInverseTransform(const sfShape* shape) +sfTransform sfShape_getInverseTransform(const sfShape* shape) { CSFML_CHECK_RETURN(shape, NULL); - shape->InverseTransform.This = shape->This.getInverseTransform(); - return &shape->InverseTransform; + shape->InverseTransform = convertTransform(shape->This.getInverseTransform()); + return shape->InverseTransform; } diff --git a/src/SFML/Graphics/ShapeStruct.h b/src/SFML/Graphics/ShapeStruct.h index 12ca31e..fabc41a 100644 --- a/src/SFML/Graphics/ShapeStruct.h +++ b/src/SFML/Graphics/ShapeStruct.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 2605fe1..7b56c94 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -157,22 +158,22 @@ void sfSprite_scale(sfSprite* sprite, sfVector2f factors) //////////////////////////////////////////////////////////// -const sfTransform* sfSprite_getTransform(const sfSprite* sprite) +sfTransform sfSprite_getTransform(const sfSprite* sprite) { CSFML_CHECK_RETURN(sprite, NULL); - sprite->Transform.This = sprite->This.getTransform(); - return &sprite->Transform; + sprite->Transform = convertTransform(sprite->This.getTransform()); + return sprite->Transform; } //////////////////////////////////////////////////////////// -const sfTransform* sfSprite_getInverseTransform(const sfSprite* sprite) +sfTransform sfSprite_getInverseTransform(const sfSprite* sprite) { CSFML_CHECK_RETURN(sprite, NULL); - sprite->InverseTransform.This = sprite->This.getInverseTransform(); - return &sprite->InverseTransform; + sprite->InverseTransform = convertTransform(sprite->This.getInverseTransform()); + return sprite->InverseTransform; } diff --git a/src/SFML/Graphics/SpriteStruct.h b/src/SFML/Graphics/SpriteStruct.h index af4ba2f..d7ae66e 100644 --- a/src/SFML/Graphics/SpriteStruct.h +++ b/src/SFML/Graphics/SpriteStruct.h @@ -30,7 +30,7 @@ //////////////////////////////////////////////////////////// #include #include -#include +#include //////////////////////////////////////////////////////////// diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index 96ec742..23ad554 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -157,22 +158,22 @@ void sfText_scale(sfText* text, sfVector2f factors) //////////////////////////////////////////////////////////// -const sfTransform* sfText_getTransform(const sfText* text) +sfTransform sfText_getTransform(const sfText* text) { CSFML_CHECK_RETURN(text, NULL); - text->Transform.This = text->This.getTransform(); - return &text->Transform; + text->Transform = convertTransform(text->This.getTransform()); + return text->Transform; } //////////////////////////////////////////////////////////// -const sfTransform* sfText_getInverseTransform(const sfText* text) +sfTransform sfText_getInverseTransform(const sfText* text) { CSFML_CHECK_RETURN(text, NULL); - text->InverseTransform.This = text->This.getInverseTransform(); - return &text->InverseTransform; + text->InverseTransform = convertTransform(text->This.getInverseTransform()); + return text->InverseTransform; } diff --git a/src/SFML/Graphics/TextStruct.h b/src/SFML/Graphics/TextStruct.h index 59c572a..746d664 100644 --- a/src/SFML/Graphics/TextStruct.h +++ b/src/SFML/Graphics/TextStruct.h @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include diff --git a/src/SFML/Graphics/Transform.cpp b/src/SFML/Graphics/Transform.cpp index 287f624..3e20efa 100644 --- a/src/SFML/Graphics/Transform.cpp +++ b/src/SFML/Graphics/Transform.cpp @@ -26,58 +26,47 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include +#include #include //////////////////////////////////////////////////////////// -sfTransform* sfTransform_create(void) +sfTransform sfTransform_Identity = { - return new sfTransform; -} + 1, 0, 0, + 0, 1, 0, + 0, 0, 1, +}; //////////////////////////////////////////////////////////// -sfTransform* sfTransform_createFromMatrix(float a00, float a01, float a02, - float a10, float a11, float a12, - float a20, float a21, float a22) +sfTransform sfTransform_fromMatrix(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); + sfTransform 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) +void sfTransform_getMatrix(const sfTransform* transform, float* matrix) { CSFML_CHECK(transform); - if (result) - result->This = transform->This.getInverse(); + sf::Transform converted = convertTransform(*transform); + if (matrix) + std::memcpy(matrix, converted.getMatrix(), 16 * sizeof(float)); +} + + +//////////////////////////////////////////////////////////// +sfTransform sfTransform_getInverse(const sfTransform* transform) +{ + CSFML_CHECK(transform); + + return convertTransform(convertTransform(*transform).getInverse()); } @@ -87,7 +76,7 @@ sfVector2f sfTransform_transformPoint(const sfTransform* transform, sfVector2f p sfVector2f p = {0, 0}; CSFML_CHECK_RETURN(transform, p); - sf::Vector2f sfmlPoint = transform->This.transformPoint(point.x, point.y); + sf::Vector2f sfmlPoint = convertTransform(*transform).transformPoint(point.x, point.y); p.x = sfmlPoint.x; p.y = sfmlPoint.y; @@ -102,7 +91,7 @@ sfFloatRect sfTransform_transformRect(const sfTransform* transform, sfFloatRect sfFloatRect rect = {0, 0, 0, 0}; CSFML_CHECK_RETURN(transform, rect); - sf::FloatRect sfmlRect = transform->This.transformRect(sf::FloatRect(rectangle.left, rectangle.top, rectangle.width, rectangle.height)); + sf::FloatRect sfmlRect = convertTransform(*transform).transformRect(sf::FloatRect(rectangle.left, rectangle.top, rectangle.width, rectangle.height)); rect.left = sfmlRect.left; rect.top = sfmlRect.top; @@ -116,42 +105,53 @@ sfFloatRect sfTransform_transformRect(const sfTransform* transform, sfFloatRect //////////////////////////////////////////////////////////// void sfTransform_combine(sfTransform* transform, const sfTransform* other) { + CSFML_CHECK(transform); CSFML_CHECK(other); - CSFML_CALL(transform, combine(other->This)); + *transform = convertTransform(convertTransform(*transform).combine(convertTransform(*other))); } //////////////////////////////////////////////////////////// void sfTransform_translate(sfTransform* transform, float x, float y) { - CSFML_CALL(transform, translate(x, y)); + CSFML_CHECK(transform); + + *transform = convertTransform(convertTransform(*transform).translate(x, y)); } //////////////////////////////////////////////////////////// void sfTransform_rotate(sfTransform* transform, float angle) { - CSFML_CALL(transform, rotate(angle)); + CSFML_CHECK(transform); + + *transform = convertTransform(convertTransform(*transform).rotate(angle)); } //////////////////////////////////////////////////////////// void sfTransform_rotateWithCenter(sfTransform* transform, float angle, float centerX, float centerY) { - CSFML_CALL(transform, rotate(angle, centerX, centerY)); + CSFML_CHECK(transform); + + *transform = convertTransform(convertTransform(*transform).rotate(angle, centerX, centerY)); } //////////////////////////////////////////////////////////// void sfTransform_scale(sfTransform* transform, float scaleX, float scaleY) { - CSFML_CALL(transform, scale(scaleX, scaleY)); + CSFML_CHECK(transform); + + *transform = convertTransform(convertTransform(*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)); + CSFML_CHECK(transform); + + *transform = convertTransform(convertTransform(*transform).scale(scaleX, scaleY, centerX, centerY)); } diff --git a/src/SFML/Graphics/Transformable.cpp b/src/SFML/Graphics/Transformable.cpp index c047041..d420ed7 100644 --- a/src/SFML/Graphics/Transformable.cpp +++ b/src/SFML/Graphics/Transformable.cpp @@ -27,6 +27,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include @@ -154,20 +155,20 @@ void sfTransformable_scale(sfTransformable* transformable, sfVector2f factors) //////////////////////////////////////////////////////////// -const sfTransform* sfTransformable_getTransform(const sfTransformable* transformable) +sfTransform sfTransformable_getTransform(const sfTransformable* transformable) { CSFML_CHECK_RETURN(transformable, NULL); - transformable->Transform.This = transformable->This.getTransform(); - return &transformable->Transform; + transformable->Transform = convertTransform(transformable->This.getTransform()); + return transformable->Transform; } //////////////////////////////////////////////////////////// -const sfTransform* sfTransformable_getInverseTransform(const sfTransformable* transformable) +sfTransform sfTransformable_getInverseTransform(const sfTransformable* transformable) { CSFML_CHECK_RETURN(transformable, NULL); - transformable->InverseTransform.This = transformable->This.getInverseTransform(); - return &transformable->InverseTransform; + transformable->InverseTransform = convertTransform(transformable->This.getInverseTransform()); + return transformable->InverseTransform; } diff --git a/src/SFML/Graphics/TransformableStruct.h b/src/SFML/Graphics/TransformableStruct.h index a1b4631..e3dd54e 100644 --- a/src/SFML/Graphics/TransformableStruct.h +++ b/src/SFML/Graphics/TransformableStruct.h @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include ////////////////////////////////////////////////////////////