Added a binding for the sfShape abstract class

This commit is contained in:
Laurent Gomila committed 2012-03-04 14:56:28 +01:00
1 parent 44c5f2d00a
commit 0b2a231121
9 files changed
+852 -1

No files matched your search

+1 -1
View File
@@ -53,7 +53,7 @@ CSFML_GRAPHICS_API sfRectangleShape* sfRectangleShape_Create(void);
CSFML_GRAPHICS_API sfRectangleShape* sfRectangleShape_Copy(sfRectangleShape* shape);
////////////////////////////////////////////////////////////
/// \brief Destroy an existing rectangle Shape
/// \brief Destroy an existing rectangle shape
///
/// \param Shape Shape to delete
///
+1
View File
@@ -168,6 +168,7 @@ CSFML_GRAPHICS_API void sfRenderTexture_ConvertCoords(const sfRenderTexture* ren
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderTexture_DrawSprite(sfRenderTexture* renderTexture, const sfSprite* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderTexture_DrawText(sfRenderTexture* renderTexture, const sfText* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderTexture_DrawShape(sfRenderTexture* renderTexture, const sfShape* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderTexture_DrawCircleShape(sfRenderTexture* renderTexture, const sfCircleShape* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderTexture_DrawConvexShape(sfRenderTexture* renderTexture, const sfConvexShape* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderTexture_DrawRectangleShape(sfRenderTexture* renderTexture, const sfRectangleShape* object, const sfRenderStates* states);
+1
View File
@@ -336,6 +336,7 @@ CSFML_GRAPHICS_API void sfRenderWindow_ConvertCoords(const sfRenderWindow* rende
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfRenderWindow_DrawSprite(sfRenderWindow* renderWindow, const sfSprite* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, const sfText* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderWindow_DrawShape(sfRenderWindow* renderWindow, const sfShape* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderWindow_DrawCircleShape(sfRenderWindow* renderWindow, const sfCircleShape* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderWindow_DrawConvexShape(sfRenderWindow* renderWindow, const sfConvexShape* object, const sfRenderStates* states);
CSFML_GRAPHICS_API void sfRenderWindow_DrawRectangleShape(sfRenderWindow* renderWindow, const sfRectangleShape* object, const sfRenderStates* states);
+415
View File
@@ -0,0 +1,415 @@
////////////////////////////////////////////////////////////
//
// 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 <SFML/Graphics/Export.h>
#include <SFML/Graphics/Color.h>
#include <SFML/Graphics/Rect.h>
#include <SFML/Graphics/Types.h>
typedef unsigned int (*sfShapeGetPointCountCallback)(void*); ///< Type of the callback used to get the number of points in a shape
typedef void (*sfShapeGetPointCallback)(unsigned int, float*, float*, void*); ///< Type of the callback used to get a point of a shape
////////////////////////////////////////////////////////////
/// \brief Create a new shape
///
/// \param getPointCount Callback that provides the point count of the shape
/// \param getPoint Callback that provides the points of the shape
/// \param userData Data to pass to the callback functions
///
/// \return A new sfShape object
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfShape* sfShape_Create(sfShapeGetPointCountCallback getPointCount,
sfShapeGetPointCallback getPoint,
void* userData);
////////////////////////////////////////////////////////////
/// \brief Destroy an existing shape
///
/// \param Shape Shape to delete
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_Destroy(sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Set the position of a shape
///
/// This function completely overwrites the previous position.
/// See sfShape_Move to apply an offset based on the previous position instead.
/// The default position of a 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_GRAPHICS_API void sfShape_SetPosition(sfShape* shape, float x, float y);
////////////////////////////////////////////////////////////
/// \brief Set the orientation of a shape
///
/// This function completely overwrites the previous rotation.
/// See sfShape_Rotate to add an angle based on the previous rotation instead.
/// The default rotation of a shape object is 0.
///
/// \param shape Shape object
/// \param angle New rotation, in degrees
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_SetRotation(sfShape* shape, float angle);
////////////////////////////////////////////////////////////
/// \brief Set the scale factors of a shape
///
/// This function completely overwrites the previous scale.
/// See sfShape_Scale to add a factor based on the previous scale instead.
/// The default scale of a shape object is (1, 1).
///
/// \param shape Shape object
/// \param factorX New horizontal scale factor
/// \param factorY New vertical scale factor
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_SetScale(sfShape* shape, float factorX, float factorY);
////////////////////////////////////////////////////////////
/// \brief Set the local origin of a 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 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_GRAPHICS_API void sfShape_SetOrigin(sfShape* shape, float x, float y);
////////////////////////////////////////////////////////////
/// \brief Get the position of a shape
///
/// \param shape Shape object
///
/// \return Current position
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_GetPosition(const sfShape* shape, float* x, float* y);
////////////////////////////////////////////////////////////
/// \brief Get the orientation of a shape
///
/// The rotation is always in the range [0, 360].
///
/// \param shape Shape object
///
/// \return Current rotation, in degrees
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API float sfShape_GetRotation(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the current scale of a shape
///
/// \param shape Shape object
///
/// \return Current scale factors
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_GetScale(const sfShape* shape, float* x, float* y);
////////////////////////////////////////////////////////////
/// \brief Get the local origin of a shape
///
/// \param shape Shape object
///
/// \return Current origin
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_GetOrigin(const sfShape* shape, float* x, float* y);
////////////////////////////////////////////////////////////
/// \brief Move a shape by a given offset
///
/// This function adds to the current position of the object,
/// unlike sfShape_SetPosition which overwrites it.
///
/// \param shape Shape object
/// \param offsetX X offset
/// \param offsetY Y offset
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_Move(sfShape* shape, float offsetX, float offsetY);
////////////////////////////////////////////////////////////
/// \brief Rotate a shape
///
/// This function adds to the current rotation of the object,
/// unlike sfShape_SetRotation which overwrites it.
///
/// \param shape Shape object
/// \param angle Angle of rotation, in degrees
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_Rotate(sfShape* shape, float angle);
////////////////////////////////////////////////////////////
/// \brief Scale a shape
///
/// This function multiplies the current scale of the object,
/// unlike sfShape_SetScale which overwrites it.
///
/// \param shape Shape object
/// \param factorX Horizontal scale factor
/// \param factorY Vertical scale factor
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_Scale(sfShape* shape, float factorX, float factorY);
////////////////////////////////////////////////////////////
/// \brief Get the combined transform of a shape
///
/// \param shape shape object
///
/// \return Transform combining the position/rotation/scale/origin of the object
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API const sfTransform* sfShape_GetTransform(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the inverse of the combined transform of a shape
///
/// \param shape shape object
///
/// \return Inverse of the combined transformations applied to the object
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API const sfTransform* sfShape_GetInverseTransform(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Change the source texture of a 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_GRAPHICS_API void sfShape_SetTexture(sfShape* shape, const sfTexture* texture, sfBool resetRect);
////////////////////////////////////////////////////////////
/// \brief Set the sub-rectangle of the texture that a 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_GRAPHICS_API void sfShape_SetTextureRect(sfShape* shape, sfIntRect rect);
////////////////////////////////////////////////////////////
/// \brief Set the fill color of a 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_GRAPHICS_API void sfShape_SetFillColor(sfShape* shape, sfColor color);
////////////////////////////////////////////////////////////
/// \brief Set the outline color of a 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_GRAPHICS_API void sfShape_SetOutlineColor(sfShape* shape, sfColor color);
////////////////////////////////////////////////////////////
/// \brief Set the thickness of a 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_GRAPHICS_API void sfShape_SetOutlineThickness(sfShape* shape, float thickness);
////////////////////////////////////////////////////////////
/// \brief Get the source texture of a 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_GRAPHICS_API const sfTexture* sfShape_GetTexture(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the sub-rectangle of the texture displayed by a shape
///
/// \param shape Shape object
///
/// \return Texture rectangle of the shape
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfIntRect sfShape_GetTextureRect(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the fill color of a shape
///
/// \param shape Shape object
///
/// \return Fill color of the shape
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfColor sfShape_GetFillColor(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the outline color of a shape
///
/// \param shape Shape object
///
/// \return Outline color of the shape
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfColor sfShape_GetOutlineColor(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the outline thickness of a shape
///
/// \param shape Shape object
///
/// \return Outline thickness of the shape
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API float sfShape_GetOutlineThickness(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the total number of points of a shape
///
/// \param shape Shape object
///
/// \return Number of points of the shape
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API unsigned int sfShape_GetPointCount(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get a point of a 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_GRAPHICS_API void sfShape_GetPoint(const sfShape* shape, unsigned int index, float* x, float* y);
////////////////////////////////////////////////////////////
/// \brief Get the local bounding rectangle of a shape
///
/// The returned rectangle is in local coordinates, which means
/// that it ignores the transformations (translation, rotation,
/// scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// entity in the entity's coordinate system.
///
/// \param shape Shape object
///
/// \return Local bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfFloatRect sfShape_GetLocalBounds(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Get the global bounding rectangle of a shape
///
/// The returned rectangle is in global coordinates, which means
/// that it takes in account the transformations (translation,
/// rotation, scale, ...) that are applied to the entity.
/// In other words, this function returns the bounds of the
/// sprite in the global 2D world's coordinate system.
///
/// \param shape Shape object
///
/// \return Global bounding rectangle of the entity
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfFloatRect sfShape_GetGlobalBounds(const sfShape* shape);
////////////////////////////////////////////////////////////
/// \brief Recompute the internal geometry of a shape
///
/// This function must be called by specialized shape objects
/// everytime their points change (ie. the result of either
/// the GetPointCount or GetPoint callbacks is different).
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfShape_Update(sfShape* shape);
#endif // SFML_SHAPE_H
+3
View File
@@ -36,6 +36,9 @@ 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
+6
View File
@@ -29,6 +29,7 @@
#include <SFML/Graphics/RenderTextureStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/CircleShapeStruct.h>
#include <SFML/Graphics/ConvexShapeStruct.h>
#include <SFML/Graphics/RectangleShapeStruct.h>
@@ -166,6 +167,11 @@ void sfRenderTexture_DrawText(sfRenderTexture* renderTexture, const sfText* obje
CSFML_CHECK(object);
CSFML_CALL(renderTexture, Draw(object->This, ConvertRenderStates(states)));
}
void sfRenderTexture_DrawShape(sfRenderTexture* renderTexture, const sfShape* 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);
+6
View File
@@ -30,6 +30,7 @@
#include <SFML/Graphics/ImageStruct.h>
#include <SFML/Graphics/SpriteStruct.h>
#include <SFML/Graphics/TextStruct.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/CircleShapeStruct.h>
#include <SFML/Graphics/ConvexShapeStruct.h>
#include <SFML/Graphics/RectangleShapeStruct.h>
@@ -355,6 +356,11 @@ void sfRenderWindow_DrawText(sfRenderWindow* renderWindow, const sfText* object,
CSFML_CHECK(object);
CSFML_CALL(renderWindow, Draw(object->This, ConvertRenderStates(states)));
}
void sfRenderWindow_DrawShape(sfRenderWindow* renderWindow, const sfShape* 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);
+324
View File
@@ -0,0 +1,324 @@
////////////////////////////////////////////////////////////
//
// 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 <SFML/Graphics/Shape.h>
#include <SFML/Graphics/ShapeStruct.h>
#include <SFML/Graphics/Color.hpp>
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
sfShape* sfShape_Create(sfShapeGetPointCountCallback getPointCount,
sfShapeGetPointCallback getPoint,
void* userData)
{
return new sfShape(getPointCount, getPoint, userData);
}
////////////////////////////////////////////////////////////
void sfShape_Destroy(sfShape* shape)
{
delete shape;
}
////////////////////////////////////////////////////////////
void sfShape_SetPosition(sfShape* shape, float x, float y)
{
CSFML_CALL(shape, SetPosition(x, y));
}
////////////////////////////////////////////////////////////
void sfShape_SetRotation(sfShape* shape, float angle)
{
CSFML_CALL(shape, SetRotation(angle));
}
////////////////////////////////////////////////////////////
void sfShape_SetScale(sfShape* shape, float factorX, float factorY)
{
CSFML_CALL(shape, SetScale(factorX, factorY));
}
////////////////////////////////////////////////////////////
void sfShape_SetOrigin(sfShape* shape, float x, float y)
{
CSFML_CALL(shape, SetOrigin(x, y));
}
////////////////////////////////////////////////////////////
void sfShape_GetPosition(const sfShape* 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 sfShape_GetRotation(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetRotation(), 0.f);
}
////////////////////////////////////////////////////////////
void sfShape_GetScale(const sfShape* 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 sfShape_GetOrigin(const sfShape* 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 sfShape_Move(sfShape* shape, float offsetX, float offsetY)
{
CSFML_CALL(shape, Move(offsetX, offsetY));
}
////////////////////////////////////////////////////////////
void sfShape_Rotate(sfShape* shape, float angle)
{
CSFML_CALL(shape, Rotate(angle));
}
////////////////////////////////////////////////////////////
void sfShape_Scale(sfShape* shape, float factorX, float factorY)
{
CSFML_CALL(shape, Scale(factorX, factorY));
}
////////////////////////////////////////////////////////////
const sfTransform* sfShape_GetTransform(const sfShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->Transform.This = shape->This.GetTransform();
return &shape->Transform;
}
////////////////////////////////////////////////////////////
const sfTransform* sfShape_GetInverseTransform(const sfShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
shape->InverseTransform.This = shape->This.GetInverseTransform();
return &shape->InverseTransform;
}
////////////////////////////////////////////////////////////
void sfShape_SetTexture(sfShape* shape, const sfTexture* texture, sfBool resetRect)
{
CSFML_CALL(shape, SetTexture(texture ? texture->This : NULL, resetRect == sfTrue));
shape->Texture = texture;
}
////////////////////////////////////////////////////////////
void sfShape_SetTextureRect(sfShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, SetTextureRect(sf::IntRect(rect.Left, rect.Top, rect.Width, rect.Height)));
}
////////////////////////////////////////////////////////////
void sfShape_SetFillColor(sfShape* shape, sfColor color)
{
CSFML_CALL(shape, SetFillColor(sf::Color(color.r, color.g, color.b, color.a)));
}
////////////////////////////////////////////////////////////
void sfShape_SetOutlineColor(sfShape* shape, sfColor color)
{
CSFML_CALL(shape, SetOutlineColor(sf::Color(color.r, color.g, color.b, color.a)));
}
////////////////////////////////////////////////////////////
void sfShape_SetOutlineThickness(sfShape* shape, float thickness)
{
CSFML_CALL(shape, SetOutlineThickness(thickness));
}
////////////////////////////////////////////////////////////
const sfTexture* sfShape_GetTexture(const sfShape* shape)
{
CSFML_CHECK_RETURN(shape, NULL);
return shape->Texture;
}
////////////////////////////////////////////////////////////
sfIntRect sfShape_GetTextureRect(const sfShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, 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 sfShape_GetFillColor(const sfShape* 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 sfShape_GetOutlineColor(const sfShape* 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 sfShape_GetOutlineThickness(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetOutlineThickness(), 0.f);
}
////////////////////////////////////////////////////////////
unsigned int sfShape_GetPointCount(const sfShape* shape)
{
CSFML_CALL_RETURN(shape, GetPointCount(), 0);
}
////////////////////////////////////////////////////////////
void sfShape_GetPoint(const sfShape* 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;
}
////////////////////////////////////////////////////////////
sfFloatRect sfShape_GetLocalBounds(const sfShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.GetLocalBounds();
rect.Left = sfmlRect.Left;
rect.Top = sfmlRect.Top;
rect.Width = sfmlRect.Width;
rect.Height = sfmlRect.Height;
return rect;
}
////////////////////////////////////////////////////////////
sfFloatRect sfShape_GetGlobalBounds(const sfShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.GetGlobalBounds();
rect.Left = sfmlRect.Left;
rect.Top = sfmlRect.Top;
rect.Width = sfmlRect.Width;
rect.Height = sfmlRect.Height;
return rect;
}
////////////////////////////////////////////////////////////
void sfShape_Update(sfShape* shape)
{
CSFML_CALL(shape, Update());
}
+95
View File
@@ -0,0 +1,95 @@
////////////////////////////////////////////////////////////
//
// 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_SHAPESTRUCT_H
#define SFML_SHAPESTRUCT_H
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Shape.h>
#include <SFML/Graphics/Shape.hpp>
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/Graphics/TransformStruct.h>
////////////////////////////////////////////////////////////
// Helper class implementing the callback forwarding from
// C++ to C in sfShape
////////////////////////////////////////////////////////////
class sfShapeImpl : public sf::Shape
{
public :
sfShapeImpl(sfShapeGetPointCountCallback getPointCount,
sfShapeGetPointCallback getPoint,
void* userData) :
myGetPointCountCallback(getPointCount),
myGetPointCallback (getPoint),
myUserData (userData)
{
}
virtual unsigned int GetPointCount() const
{
return myGetPointCountCallback(myUserData);
}
virtual sf::Vector2f GetPoint(unsigned int index) const
{
sf::Vector2f point;
myGetPointCallback(index, &point.x, &point.y, myUserData);
return point;
}
using sf::Shape::Update;
private:
sfShapeGetPointCountCallback myGetPointCountCallback;
sfShapeGetPointCallback myGetPointCallback;
void* myUserData;
};
////////////////////////////////////////////////////////////
// Internal structure of sfShape
////////////////////////////////////////////////////////////
struct sfShape
{
sfShape(sfShapeGetPointCountCallback getPointCount,
sfShapeGetPointCallback getPoint,
void* userData) :
This(getPointCount, getPoint, userData)
{
}
sfShapeImpl This;
const sfTexture* Texture;
mutable sfTransform Transform;
mutable sfTransform InverseTransform;
};
#endif // SFML_SHAPESTRUCT_H