mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-26 13:06:13 +01:00
Added a binding for the sfShape abstract class
This commit is contained in:
1 parent
44c5f2d00a
commit
0b2a231121
9 files changed
+852
-1
No files matched your search
@@ -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
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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());
|
||||
}
|
||||
@@ -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
|
||||
Reference in new issue
Block a user