mirror of
https://github.com/SFML/CSFML.git
synced 2026-10-25 21:06:12 +01:00
326 lines
8.5 KiB
C++
326 lines
8.5 KiB
C++
////////////////////////////////////////////////////////////
|
|
//
|
|
// 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, sfVector2f position)
|
|
{
|
|
CSFML_CALL(shape, SetPosition(position.x, position.y));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
void sfShape_SetRotation(sfShape* shape, float angle)
|
|
{
|
|
CSFML_CALL(shape, SetRotation(angle));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
void sfShape_SetScale(sfShape* shape, sfVector2f scale)
|
|
{
|
|
CSFML_CALL(shape, SetScale(scale.x, scale.y));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
void sfShape_SetOrigin(sfShape* shape, sfVector2f origin)
|
|
{
|
|
CSFML_CALL(shape, SetOrigin(origin.x, origin.y));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
sfVector2f sfShape_GetPosition(const sfShape* shape)
|
|
{
|
|
sfVector2f position = {0, 0};
|
|
CSFML_CHECK_RETURN(shape, position);
|
|
|
|
sf::Vector2f sfmlPos = shape->This.GetPosition();
|
|
position.x = sfmlPos.x;
|
|
position.y = sfmlPos.y;
|
|
|
|
return position;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
float sfShape_GetRotation(const sfShape* shape)
|
|
{
|
|
CSFML_CALL_RETURN(shape, GetRotation(), 0.f);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
sfVector2f sfShape_GetScale(const sfShape* shape)
|
|
{
|
|
sfVector2f scale = {0, 0};
|
|
CSFML_CHECK_RETURN(shape, scale);
|
|
|
|
sf::Vector2f sfmlScale = shape->This.GetScale();
|
|
scale.x = sfmlScale.x;
|
|
scale.y = sfmlScale.y;
|
|
|
|
return scale;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
sfVector2f sfShape_GetOrigin(const sfShape* shape)
|
|
{
|
|
sfVector2f origin = {0, 0};
|
|
CSFML_CHECK_RETURN(shape, origin);
|
|
|
|
sf::Vector2f sfmlOrigin = shape->This.GetOrigin();
|
|
origin.x = sfmlOrigin.x;
|
|
origin.y = sfmlOrigin.y;
|
|
|
|
return origin;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
void sfShape_Move(sfShape* shape, sfVector2f offset)
|
|
{
|
|
CSFML_CALL(shape, Move(offset.x, offset.y));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
void sfShape_Rotate(sfShape* shape, float angle)
|
|
{
|
|
CSFML_CALL(shape, Rotate(angle));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
void sfShape_Scale(sfShape* shape, sfVector2f factors)
|
|
{
|
|
CSFML_CALL(shape, Scale(factors.x, factors.y));
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
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);
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
sfVector2f sfShape_GetPoint(const sfShape* shape, unsigned int index)
|
|
{
|
|
sfVector2f point = {0, 0};
|
|
CSFML_CHECK_RETURN(shape, point);
|
|
|
|
sf::Vector2f sfmlPoint = shape->This.GetPoint(index);
|
|
point.x = sfmlPoint.x;
|
|
point.y = sfmlPoint.y;
|
|
|
|
return point;
|
|
}
|
|
|
|
|
|
////////////////////////////////////////////////////////////
|
|
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());
|
|
}
|