Add convenience functions for converting between SFML and CSFML types

This commit is contained in:
Chris Thrasher committed 2024-08-26 16:04:44 -06:00
1 parent 3316223629
commit caabd98100
41 files changed
+637 -872

No files matched your search

+7 -12
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Audio/Listener.h>
#include <SFML/Audio/Listener.hpp>
#include <CSFML/System/ConvertVector3.hpp>
@@ -47,46 +48,40 @@ float sfListener_getGlobalVolume()
////////////////////////////////////////////////////////////
void sfListener_setPosition(sfVector3f position)
{
sf::Listener::setPosition({ position.x, position.y, position.z });
sf::Listener::setPosition(convertVector3(position));
}
////////////////////////////////////////////////////////////
sfVector3f sfListener_getPosition()
{
sf::Vector3f sfmlPos = sf::Listener::getPosition();
sfVector3f position = {sfmlPos.x, sfmlPos.y, sfmlPos.z};
return position;
return convertVector3(sf::Listener::getPosition());
}
////////////////////////////////////////////////////////////
void sfListener_setDirection(sfVector3f direction)
{
sf::Listener::setDirection({ direction.x, direction.y, direction.z });
sf::Listener::setDirection(convertVector3(direction));
}
////////////////////////////////////////////////////////////
sfVector3f sfListener_getDirection()
{
sf::Vector3f sfmlDirection = sf::Listener::getDirection();
sfVector3f direction = {sfmlDirection.x, sfmlDirection.y, sfmlDirection.z};
return direction;
return convertVector3(sf::Listener::getDirection());
}
////////////////////////////////////////////////////////////
void sfListener_setUpVector(sfVector3f upVector)
{
sf::Listener::setUpVector({ upVector.x, upVector.y, upVector.z });
sf::Listener::setUpVector(convertVector3(upVector));
}
////////////////////////////////////////////////////////////
sfVector3f sfListener_getUpVector()
{
sf::Vector3f sfmlUpVector = sf::Listener::getUpVector();
sfVector3f upVector = {sfmlUpVector.x, sfmlUpVector.y, sfmlUpVector.z};
return upVector;
return convertVector3(sf::Listener::getUpVector());
}
+3 -7
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Audio/Music.h>
#include <CSFML/Audio/MusicStruct.hpp>
#include <CSFML/System/ConvertVector3.hpp>
#include <CSFML/Internal.hpp>
@@ -202,7 +203,7 @@ void sfMusic_setVolume(sfMusic* music, float volume)
////////////////////////////////////////////////////////////
void sfMusic_setPosition(sfMusic* music, sfVector3f position)
{
CSFML_CALL(music, setPosition(sf::Vector3f(position.x, position.y, position.z)));
CSFML_CALL(music, setPosition(convertVector3(position)));
}
@@ -254,12 +255,7 @@ sfVector3f sfMusic_getPosition(const sfMusic* music)
sfVector3f position = {0, 0, 0};
CSFML_CHECK_RETURN(music, position);
sf::Vector3f sfmlPos = music->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
position.z = sfmlPos.z;
return position;
return convertVector3(music->This.getPosition());
}
+3 -7
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Audio/Sound.h>
#include <CSFML/Audio/SoundStruct.hpp>
#include <CSFML/System/ConvertVector3.hpp>
#include <CSFML/Internal.hpp>
@@ -136,7 +137,7 @@ void sfSound_setVolume(sfSound* sound, float volume)
////////////////////////////////////////////////////////////
void sfSound_setPosition(sfSound* sound, sfVector3f position)
{
CSFML_CALL(sound, setPosition(sf::Vector3f(position.x, position.y, position.z)));
CSFML_CALL(sound, setPosition(convertVector3(position)));
}
@@ -188,12 +189,7 @@ sfVector3f sfSound_getPosition(const sfSound* sound)
sfVector3f position = {0, 0, 0};
CSFML_CHECK_RETURN(sound, position);
sf::Vector3f sfmlPos = sound->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
position.z = sfmlPos.z;
return position;
return convertVector3(sound->This.getPosition());
}
+3 -7
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Audio/SoundStream.h>
#include <CSFML/Audio/SoundStreamStruct.hpp>
#include <CSFML/System/ConvertVector3.hpp>
#include <CSFML/Internal.hpp>
@@ -111,7 +112,7 @@ void sfSoundStream_setVolume(sfSoundStream* soundStream, float volume)
////////////////////////////////////////////////////////////
void sfSoundStream_setPosition(sfSoundStream* soundStream, sfVector3f position)
{
CSFML_CALL(soundStream, setPosition({ position.x, position.y, position.z }));
CSFML_CALL(soundStream, setPosition(convertVector3(position)));
}
@@ -170,12 +171,7 @@ sfVector3f sfSoundStream_getPosition(const sfSoundStream* soundStream)
sfVector3f position = {0, 0, 0};
CSFML_CHECK_RETURN(soundStream, position);
sf::Vector3f sfmlPos = soundStream->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
position.z = sfmlPos.z;
return position;
return convertVector3(soundStream->This.getPosition());
}
+2
View File
@@ -12,6 +12,8 @@ set(SRC
${INCROOT}/CircleShape.h
${SRCROOT}/Color.cpp
${INCROOT}/Color.h
${SRCROOT}/ConvertColor.hpp
${SRCROOT}/ConvertRect.hpp
${SRCROOT}/ConvertRenderStates.hpp
${SRCROOT}/ConvertTransform.hpp
${SRCROOT}/ConvexShape.cpp
+20 -63
View File
@@ -27,6 +27,9 @@
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/CircleShape.h>
#include <CSFML/Graphics/CircleShapeStruct.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <SFML/Graphics/Color.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/Internal.hpp>
@@ -61,7 +64,7 @@ void sfCircleShape_destroy(sfCircleShape* shape)
////////////////////////////////////////////////////////////
void sfCircleShape_setPosition(sfCircleShape* shape, sfVector2f position)
{
CSFML_CALL(shape, setPosition({ position.x, position.y }));
CSFML_CALL(shape, setPosition(convertVector2(position)));
}
@@ -75,14 +78,14 @@ void sfCircleShape_setRotation(sfCircleShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfCircleShape_setScale(sfCircleShape* shape, sfVector2f scale)
{
CSFML_CALL(shape, setScale({ scale.x, scale.y }));
CSFML_CALL(shape, setScale(convertVector2(scale)));
}
////////////////////////////////////////////////////////////
void sfCircleShape_setOrigin(sfCircleShape* shape, sfVector2f origin)
{
CSFML_CALL(shape, setOrigin({ origin.x, origin.y }));
CSFML_CALL(shape, setOrigin(convertVector2(origin)));
}
@@ -92,11 +95,7 @@ sfVector2f sfCircleShape_getPosition(const sfCircleShape* 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;
return convertVector2(shape->This.getPosition());
}
@@ -113,11 +112,7 @@ sfVector2f sfCircleShape_getScale(const sfCircleShape* 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;
return convertVector2(shape->This.getScale());
}
@@ -127,18 +122,14 @@ sfVector2f sfCircleShape_getOrigin(const sfCircleShape* 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;
return convertVector2(shape->This.getOrigin());
}
////////////////////////////////////////////////////////////
void sfCircleShape_move(sfCircleShape* shape, sfVector2f offset)
{
CSFML_CALL(shape, move({ offset.x, offset.y }));
CSFML_CALL(shape, move(convertVector2(offset)));
}
@@ -152,7 +143,7 @@ void sfCircleShape_rotate(sfCircleShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfCircleShape_scale(sfCircleShape* shape, sfVector2f factors)
{
CSFML_CALL(shape, scale({ factors.x, factors.y }));
CSFML_CALL(shape, scale(convertVector2(factors)));
}
@@ -187,21 +178,21 @@ void sfCircleShape_setTexture(sfCircleShape* shape, const sfTexture* texture, bo
////////////////////////////////////////////////////////////
void sfCircleShape_setTextureRect(sfCircleShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
CSFML_CALL(shape, setTextureRect(convertRect(rect)));
}
////////////////////////////////////////////////////////////
void sfCircleShape_setFillColor(sfCircleShape* shape, sfColor color)
{
CSFML_CALL(shape, setFillColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setFillColor(convertColor(color)));
}
////////////////////////////////////////////////////////////
void sfCircleShape_setOutlineColor(sfCircleShape* shape, sfColor color)
{
CSFML_CALL(shape, setOutlineColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setOutlineColor(convertColor(color)));
}
@@ -227,13 +218,7 @@ sfIntRect sfCircleShape_getTextureRect(const sfCircleShape* shape)
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getTextureRect());
}
@@ -243,13 +228,7 @@ sfColor sfCircleShape_getFillColor(const sfCircleShape* shape)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
sf::Color sfmlColor = shape->This.getFillColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(shape->This.getFillColor());
}
@@ -259,13 +238,7 @@ sfColor sfCircleShape_getOutlineColor(const sfCircleShape* shape)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
sf::Color sfmlColor = shape->This.getOutlineColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(shape->This.getOutlineColor());
}
@@ -289,11 +262,7 @@ sfVector2f sfCircleShape_getPoint(const sfCircleShape* shape, size_t 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;
return convertVector2(shape->This.getPoint(index));
}
@@ -324,13 +293,7 @@ sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getLocalBounds());
}
@@ -340,11 +303,5 @@ sfFloatRect sfCircleShape_getGlobalBounds(const sfCircleShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getGlobalBounds());
}
+49
View File
@@ -0,0 +1,49 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Color.hpp>
#include <CSFML/Graphics/Color.h>
////////////////////////////////////////////////////////////
// Convert sf::Color to sfColor
////////////////////////////////////////////////////////////
[[nodiscard]] inline sfColor convertColor(const sf::Color color)
{
return {color.r, color.g, color.b, color.a};
}
////////////////////////////////////////////////////////////
// Convert sfColor to sf::Color
////////////////////////////////////////////////////////////
[[nodiscard]] inline sf::Color convertColor(const sfColor color)
{
return {color.r, color.g, color.b, color.a};
}
+57
View File
@@ -0,0 +1,57 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Graphics/Rect.hpp>
#include <CSFML/Graphics/Rect.h>
////////////////////////////////////////////////////////////
// Convert sf::Rect<T> to CSFML Rect
////////////////////////////////////////////////////////////
[[nodiscard]] inline sfFloatRect convertRect(const sf::FloatRect& rect)
{
return {{rect.position.x, rect.position.y}, {rect.size.x, rect.size.y}};
}
[[nodiscard]] inline sfIntRect convertRect(const sf::IntRect& rect)
{
return {{rect.position.x, rect.position.y}, {rect.size.x, rect.size.y}};
}
////////////////////////////////////////////////////////////
// Convert CSFML Rect to sf::Rect<T>
////////////////////////////////////////////////////////////
[[nodiscard]] inline sf::FloatRect convertRect(const sfFloatRect& rect)
{
return {{rect.position.x, rect.position.y}, {rect.size.x, rect.size.y}};
}
[[nodiscard]] inline sf::IntRect convertRect(const sfIntRect& rect)
{
return {{rect.position.x, rect.position.y}, {rect.size.x, rect.size.y}};
}
+14 -16
View File
@@ -37,22 +37,20 @@
////////////////////////////////////////////////////////////
// Convert sfRenderStates* to sf::RenderStates
////////////////////////////////////////////////////////////
inline sf::RenderStates convertRenderStates(const sfRenderStates* states)
[[nodiscard]] inline sf::RenderStates convertRenderStates(const sfRenderStates* states)
{
sf::RenderStates sfmlStates;
if (!states)
return {};
if (states)
{
sfmlStates.blendMode.colorSrcFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.colorSrcFactor);
sfmlStates.blendMode.colorDstFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.colorDstFactor);
sfmlStates.blendMode.colorEquation = static_cast<sf::BlendMode::Equation>(states->blendMode.colorEquation);
sfmlStates.blendMode.alphaSrcFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.alphaSrcFactor);
sfmlStates.blendMode.alphaDstFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.alphaDstFactor);
sfmlStates.blendMode.alphaEquation = static_cast<sf::BlendMode::Equation>(states->blendMode.alphaEquation);
sfmlStates.transform = convertTransform(states->transform);
sfmlStates.texture = states->texture ? states->texture->This : nullptr;
sfmlStates.shader = states->shader ? &states->shader->This : nullptr;
}
return sfmlStates;
sf::RenderStates renderStates;
renderStates.blendMode.colorSrcFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.colorSrcFactor);
renderStates.blendMode.colorDstFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.colorDstFactor);
renderStates.blendMode.colorEquation = static_cast<sf::BlendMode::Equation>(states->blendMode.colorEquation);
renderStates.blendMode.alphaSrcFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.alphaSrcFactor);
renderStates.blendMode.alphaDstFactor = static_cast<sf::BlendMode::Factor>(states->blendMode.alphaDstFactor);
renderStates.blendMode.alphaEquation = static_cast<sf::BlendMode::Equation>(states->blendMode.alphaEquation);
renderStates.transform = convertTransform(states->transform);
renderStates.texture = states->texture ? states->texture->This : nullptr;
renderStates.shader = states->shader ? &states->shader->This : nullptr;
return renderStates;
}
+6 -7
View File
@@ -34,21 +34,20 @@
////////////////////////////////////////////////////////////
// Convert sf::Transform to sfTransform
////////////////////////////////////////////////////////////
inline sfTransform convertTransform(const sf::Transform& transform)
[[nodiscard]] inline sfTransform convertTransform(const sf::Transform& transform)
{
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;
return {m[0], m[4], m[12], m[1], m[5], m[13], m[3], m[7], m[15]};
}
////////////////////////////////////////////////////////////
// Convert sfTransform to sf::Transform
////////////////////////////////////////////////////////////
inline sf::Transform convertTransform(const sfTransform& transform)
[[nodiscard]] 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]);
return {m[0], m[1], m[2],
m[3], m[4], m[5],
m[6], m[7], m[8]};
}
+21 -64
View File
@@ -29,6 +29,9 @@
#include <CSFML/Graphics/ConvexShapeStruct.hpp>
#include <SFML/Graphics/Color.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -58,7 +61,7 @@ void sfConvexShape_destroy(sfConvexShape* shape)
////////////////////////////////////////////////////////////
void sfConvexShape_setPosition(sfConvexShape* shape, sfVector2f position)
{
CSFML_CALL(shape, setPosition({ position.x, position.y }));
CSFML_CALL(shape, setPosition(convertVector2(position)));
}
@@ -72,14 +75,14 @@ void sfConvexShape_setRotation(sfConvexShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfConvexShape_setScale(sfConvexShape* shape, sfVector2f scale)
{
CSFML_CALL(shape, setScale({ scale.x, scale.y }));
CSFML_CALL(shape, setScale(convertVector2(scale)));
}
////////////////////////////////////////////////////////////
void sfConvexShape_setOrigin(sfConvexShape* shape, sfVector2f origin)
{
CSFML_CALL(shape, setOrigin({ origin.x, origin.y }));
CSFML_CALL(shape, setOrigin(convertVector2(origin)));
}
@@ -89,11 +92,7 @@ sfVector2f sfConvexShape_getPosition(const sfConvexShape* 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;
return convertVector2(shape->This.getPosition());
}
@@ -110,11 +109,7 @@ sfVector2f sfConvexShape_getScale(const sfConvexShape* 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;
return convertVector2(shape->This.getScale());
}
@@ -124,18 +119,14 @@ sfVector2f sfConvexShape_getOrigin(const sfConvexShape* 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;
return convertVector2(shape->This.getOrigin());
}
////////////////////////////////////////////////////////////
void sfConvexShape_move(sfConvexShape* shape, sfVector2f offset)
{
CSFML_CALL(shape, move({ offset.x, offset.y }));
CSFML_CALL(shape, move(convertVector2(offset)));
}
@@ -149,7 +140,7 @@ void sfConvexShape_rotate(sfConvexShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfConvexShape_scale(sfConvexShape* shape, sfVector2f factors)
{
CSFML_CALL(shape, scale({ factors.x, factors.y }));
CSFML_CALL(shape, scale(convertVector2(factors)));
}
@@ -184,21 +175,21 @@ void sfConvexShape_setTexture(sfConvexShape* shape, const sfTexture* texture, bo
////////////////////////////////////////////////////////////
void sfConvexShape_setTextureRect(sfConvexShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
CSFML_CALL(shape, setTextureRect(convertRect(rect)));
}
////////////////////////////////////////////////////////////
void sfConvexShape_setFillColor(sfConvexShape* shape, sfColor color)
{
CSFML_CALL(shape, setFillColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setFillColor(convertColor(color)));
}
////////////////////////////////////////////////////////////
void sfConvexShape_setOutlineColor(sfConvexShape* shape, sfColor color)
{
CSFML_CALL(shape, setOutlineColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setOutlineColor(convertColor(color)));
}
@@ -224,13 +215,7 @@ sfIntRect sfConvexShape_getTextureRect(const sfConvexShape* shape)
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getTextureRect());
}
@@ -240,13 +225,7 @@ sfColor sfConvexShape_getFillColor(const sfConvexShape* shape)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
sf::Color sfmlColor = shape->This.getFillColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(shape->This.getFillColor());
}
@@ -256,13 +235,7 @@ sfColor sfConvexShape_getOutlineColor(const sfConvexShape* shape)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
sf::Color sfmlColor = shape->This.getOutlineColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(shape->This.getOutlineColor());
}
@@ -286,11 +259,7 @@ sfVector2f sfConvexShape_getPoint(const sfConvexShape* shape, size_t 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;
return convertVector2(shape->This.getPoint(index));
}
@@ -304,7 +273,7 @@ void sfConvexShape_setPointCount(sfConvexShape* shape, size_t count)
////////////////////////////////////////////////////////////
void sfConvexShape_setPoint(sfConvexShape* shape, size_t index, sfVector2f point)
{
CSFML_CALL(shape, setPoint(index, sf::Vector2f(point.x, point.y)));
CSFML_CALL(shape, setPoint(index, convertVector2(point)));
}
@@ -314,13 +283,7 @@ sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getLocalBounds());
}
@@ -330,11 +293,5 @@ sfFloatRect sfConvexShape_getGlobalBounds(const sfConvexShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getGlobalBounds());
}
+4 -9
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/Font.h>
#include <CSFML/Graphics/FontStruct.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/CallbackStream.hpp>
@@ -94,15 +95,9 @@ sfGlyph sfFont_getGlyph(const sfFont* font, uint32_t codePoint, unsigned int cha
sf::Glyph SFMLGlyph = font->This.getGlyph(codePoint, characterSize, bold, outlineThickness);
glyph.advance = SFMLGlyph.advance;
glyph.bounds.position.x = SFMLGlyph.bounds.position.x;
glyph.bounds.position.y = SFMLGlyph.bounds.position.y;
glyph.bounds.size.x = SFMLGlyph.bounds.size.x;
glyph.bounds.size.y = SFMLGlyph.bounds.size.y;
glyph.textureRect.position.x = SFMLGlyph.textureRect.position.x;
glyph.textureRect.position.y = SFMLGlyph.textureRect.position.y;
glyph.textureRect.size.x = SFMLGlyph.textureRect.size.x;
glyph.textureRect.size.y = SFMLGlyph.textureRect.size.y;
glyph.advance = SFMLGlyph.advance;
glyph.bounds = convertRect(SFMLGlyph.bounds);
glyph.textureRect = convertRect(SFMLGlyph.textureRect);
return glyph;
}
+9 -15
View File
@@ -27,6 +27,9 @@
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/Image.h>
#include <CSFML/Graphics/ImageStruct.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/System/BufferStruct.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/CallbackStream.hpp>
@@ -42,7 +45,7 @@ sfImage* sfImage_create(unsigned int width, unsigned int height)
////////////////////////////////////////////////////////////
sfImage* sfImage_createFromColor(unsigned int width, unsigned int height, sfColor color)
{
return new sfImage{sf::Image({ width, height }, sf::Color(color.r, color.g, color.b, color.a))};
return new sfImage{sf::Image({ width, height }, convertColor(color))};
}
@@ -133,7 +136,7 @@ bool sfImage_saveToMemory(const sfImage* image, sfBuffer* output, const char* fo
////////////////////////////////////////////////////////////
void sfImage_createMaskFromColor(sfImage* image, sfColor colorKey, uint8_t alpha)
{
CSFML_CALL(image, createMaskFromColor(sf::Color(colorKey.r, colorKey.g, colorKey.b, colorKey.a), alpha));
CSFML_CALL(image, createMaskFromColor(convertColor(colorKey), alpha));
}
@@ -143,16 +146,14 @@ bool sfImage_copyImage(sfImage* image, const sfImage* source, unsigned int destX
CSFML_CHECK_RETURN(image, false);
CSFML_CHECK_RETURN(source, false);
sf::IntRect sfmlRect({ sourceRect.position.x, sourceRect.position.y }, { sourceRect.size.x, sourceRect.size.y });
return image->This.copy(source->This, { destX, destY }, sfmlRect, applyAlpha);
return image->This.copy(source->This, { destX, destY }, convertRect(sourceRect), applyAlpha);
}
////////////////////////////////////////////////////////////
void sfImage_setPixel(sfImage* image, unsigned int x, unsigned int y, sfColor color)
{
CSFML_CALL(image, setPixel({ x, y }, sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(image, setPixel({ x, y }, convertColor(color)));
}
@@ -162,9 +163,7 @@ sfColor sfImage_getPixel(const sfImage* image, unsigned int x, unsigned int y)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(image, color);
sf::Color sfmlColor = image->This.getPixel({ x, y });
return sfColor_fromRGBA(sfmlColor.r, sfmlColor.g, sfmlColor.b, sfmlColor.a);
return convertColor(image->This.getPixel({ x, y }));
}
@@ -181,12 +180,7 @@ sfVector2u sfImage_getSize(const sfImage* image)
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(image, size);
sf::Vector2u sfmlSize = image->This.getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(image->This.getSize());
}
+9 -18
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/Rect.h>
#include <SFML/Graphics/Rect.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/Internal.hpp>
@@ -36,12 +37,12 @@
bool sfFloatRect_contains(const sfFloatRect* rect, float x, float y)
{
CSFML_CHECK_RETURN(rect, false);
return sf::FloatRect({ rect->position.x, rect->position.y }, { rect->size.x, rect->size.y }).contains({ x, y });
return convertRect(*rect).contains({ x, y });
}
bool sfIntRect_contains(const sfIntRect* rect, int x, int y)
{
CSFML_CHECK_RETURN(rect, false);
return sf::IntRect({ rect->position.x, rect->position.y }, { rect->size.x, rect->size.y }).contains({ x, y });
return convertRect(*rect).contains({ x, y });
}
@@ -53,20 +54,15 @@ bool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2,
CSFML_CHECK_RETURN(rect1, false);
CSFML_CHECK_RETURN(rect2, false);
sf::FloatRect SFMLRect1({ rect1->position.x, rect1->position.y }, { rect1->size.x, rect1->size.y });
sf::FloatRect SFMLRect2({ rect2->position.x, rect2->position.y }, { rect2->size.x, rect2->size.y });
sf::FloatRect SFMLRect1 = convertRect(*rect1);
sf::FloatRect SFMLRect2 = convertRect(*rect2);
if (intersection)
{
std::optional<sf::FloatRect> overlap = SFMLRect1.findIntersection(SFMLRect2);
if (overlap)
{
intersection->position.x = overlap->position.x;
intersection->position.y = overlap->position.y;
intersection->size.x = overlap->size.x;
intersection->size.y = overlap->size.y;
}
*intersection = convertRect(*overlap);
return overlap.has_value();
}
@@ -80,20 +76,15 @@ bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntR
CSFML_CHECK_RETURN(rect1, false);
CSFML_CHECK_RETURN(rect2, false);
sf::IntRect SFMLRect1({ rect1->position.x, rect1->position.y }, { rect1->size.x, rect1->size.y });
sf::IntRect SFMLRect2({ rect2->position.x, rect2->position.y }, { rect2->size.x, rect2->size.y });
sf::IntRect SFMLRect1 = convertRect(*rect1);
sf::IntRect SFMLRect2 = convertRect(*rect2);
if (intersection)
{
std::optional<sf::IntRect> overlap = SFMLRect1.findIntersection(SFMLRect2);
if (overlap)
{
intersection->position.x = overlap->position.x;
intersection->position.y = overlap->position.y;
intersection->size.x = overlap->size.x;
intersection->size.y = overlap->size.y;
}
*intersection = convertRect(*overlap);
return overlap.has_value();
}
+22 -69
View File
@@ -27,8 +27,11 @@
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/RectangleShape.h>
#include <CSFML/Graphics/RectangleShapeStruct.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <SFML/Graphics/Color.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -58,7 +61,7 @@ void sfRectangleShape_destroy(sfRectangleShape* shape)
////////////////////////////////////////////////////////////
void sfRectangleShape_setPosition(sfRectangleShape* shape, sfVector2f position)
{
CSFML_CALL(shape, setPosition({ position.x, position.y }));
CSFML_CALL(shape, setPosition(convertVector2(position)));
}
@@ -72,14 +75,14 @@ void sfRectangleShape_setRotation(sfRectangleShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfRectangleShape_setScale(sfRectangleShape* shape, sfVector2f scale)
{
CSFML_CALL(shape, setScale({ scale.x, scale.y }));
CSFML_CALL(shape, setScale(convertVector2(scale)));
}
////////////////////////////////////////////////////////////
void sfRectangleShape_setOrigin(sfRectangleShape* shape, sfVector2f origin)
{
CSFML_CALL(shape, setOrigin({ origin.x, origin.y }));
CSFML_CALL(shape, setOrigin(convertVector2(origin)));
}
@@ -89,11 +92,7 @@ sfVector2f sfRectangleShape_getPosition(const sfRectangleShape* 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;
return convertVector2(shape->This.getPosition());
}
@@ -110,11 +109,7 @@ sfVector2f sfRectangleShape_getScale(const sfRectangleShape* 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;
return convertVector2(shape->This.getScale());
}
@@ -124,18 +119,14 @@ sfVector2f sfRectangleShape_getOrigin(const sfRectangleShape* 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;
return convertVector2(shape->This.getOrigin());
}
////////////////////////////////////////////////////////////
void sfRectangleShape_move(sfRectangleShape* shape, sfVector2f offset)
{
CSFML_CALL(shape, move({ offset.x, offset.y }));
CSFML_CALL(shape, move(convertVector2(offset)));
}
@@ -149,7 +140,7 @@ void sfRectangleShape_rotate(sfRectangleShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfRectangleShape_scale(sfRectangleShape* shape, sfVector2f factors)
{
CSFML_CALL(shape, scale({ factors.x, factors.y }));
CSFML_CALL(shape, scale(convertVector2(factors)));
}
@@ -184,21 +175,21 @@ void sfRectangleShape_setTexture(sfRectangleShape* shape, const sfTexture* textu
////////////////////////////////////////////////////////////
void sfRectangleShape_setTextureRect(sfRectangleShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
CSFML_CALL(shape, setTextureRect(convertRect(rect)));
}
////////////////////////////////////////////////////////////
void sfRectangleShape_setFillColor(sfRectangleShape* shape, sfColor color)
{
CSFML_CALL(shape, setFillColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setFillColor(convertColor(color)));
}
////////////////////////////////////////////////////////////
void sfRectangleShape_setOutlineColor(sfRectangleShape* shape, sfColor color)
{
CSFML_CALL(shape, setOutlineColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setOutlineColor(convertColor(color)));
}
@@ -224,13 +215,7 @@ sfIntRect sfRectangleShape_getTextureRect(const sfRectangleShape* shape)
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getTextureRect());
}
@@ -240,13 +225,7 @@ sfColor sfRectangleShape_getFillColor(const sfRectangleShape* shape)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
sf::Color sfmlColor = shape->This.getFillColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(shape->This.getFillColor());
}
@@ -256,13 +235,7 @@ sfColor sfRectangleShape_getOutlineColor(const sfRectangleShape* shape)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(shape, color);
sf::Color sfmlColor = shape->This.getOutlineColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(shape->This.getOutlineColor());
}
@@ -286,18 +259,14 @@ sfVector2f sfRectangleShape_getPoint(const sfRectangleShape* shape, size_t 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;
return convertVector2(shape->This.getPoint(index));
}
////////////////////////////////////////////////////////////
void sfRectangleShape_setSize(sfRectangleShape* shape, sfVector2f size)
{
CSFML_CALL(shape, setSize(sf::Vector2f(size.x, size.y)));
CSFML_CALL(shape, setSize(convertVector2(size)));
}
@@ -307,11 +276,7 @@ sfVector2f sfRectangleShape_getSize(const sfRectangleShape* shape)
sfVector2f size = {0, 0};
CSFML_CHECK_RETURN(shape, size);
sf::Vector2f sfmlSize = shape->This.getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(shape->This.getSize());
}
@@ -321,13 +286,7 @@ sfFloatRect sfRectangleShape_getLocalBounds(const sfRectangleShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getLocalBounds());
}
@@ -337,11 +296,5 @@ sfFloatRect sfRectangleShape_getGlobalBounds(const sfRectangleShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getGlobalBounds());
}
+12 -37
View File
@@ -36,19 +36,18 @@
#include <CSFML/Graphics/VertexArrayStruct.hpp>
#include <CSFML/Graphics/VertexBufferStruct.hpp>
#include <CSFML/Graphics/ConvertRenderStates.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/Window/ContextSettingsInternal.hpp>
#include <CSFML/Window/ConvertContextSettings.hpp>
////////////////////////////////////////////////////////////
sfRenderTexture* sfRenderTexture_create(unsigned int width, unsigned int height, const sfContextSettings* settings)
{
// Convert context settings
sf::ContextSettings params;
if (settings)
{
priv::sfContextSettings_writeToCpp(*settings, params);
}
const sf::ContextSettings params = settings ? convertContextSettings(*settings) : sf::ContextSettings();
// Create the render texture
sf::RenderTexture renderTexture;
@@ -77,11 +76,7 @@ sfVector2u sfRenderTexture_getSize(const sfRenderTexture* renderTexture)
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(renderTexture, size);
sf::Vector2u sfmlSize = renderTexture->This.getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(renderTexture->This.getSize());
}
@@ -110,9 +105,7 @@ void sfRenderTexture_display(sfRenderTexture* renderTexture)
////////////////////////////////////////////////////////////
void sfRenderTexture_clear(sfRenderTexture* renderTexture, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderTexture, clear(SFMLColor));
CSFML_CALL(renderTexture, clear(convertColor(color)));
}
@@ -150,13 +143,7 @@ sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, cons
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderTexture, rect);
sf::IntRect SFMLrect = renderTexture->This.getViewport(view->This);
rect.position.x = SFMLrect.position.x;
rect.position.y = SFMLrect.position.y;
rect.size.x = SFMLrect.size.x;
rect.size.y = SFMLrect.size.y;
return rect;
return convertRect(renderTexture->This.getViewport(view->This));
}
@@ -166,16 +153,10 @@ sfVector2f sfRenderTexture_mapPixelToCoords(const sfRenderTexture* renderTexture
sfVector2f result = {0, 0};
CSFML_CHECK_RETURN(renderTexture, result);
sf::Vector2f sfmlPoint;
if (targetView)
sfmlPoint = renderTexture->This.mapPixelToCoords(sf::Vector2i(point.x, point.y), targetView->This);
else
sfmlPoint = renderTexture->This.mapPixelToCoords(sf::Vector2i(point.x, point.y));
return convertVector2(renderTexture->This.mapPixelToCoords(convertVector2(point), targetView->This));
result.x = sfmlPoint.x;
result.y = sfmlPoint.y;
return result;
return convertVector2(renderTexture->This.mapPixelToCoords(convertVector2(point)));
}
@@ -185,16 +166,10 @@ sfVector2i sfRenderTexture_mapCoordsToPixel(const sfRenderTexture* renderTexture
sfVector2i result = {0, 0};
CSFML_CHECK_RETURN(renderTexture, result);
sf::Vector2i sfmlPoint;
if (targetView)
sfmlPoint = renderTexture->This.mapCoordsToPixel(sf::Vector2f(point.x, point.y), targetView->This);
else
sfmlPoint = renderTexture->This.mapCoordsToPixel(sf::Vector2f(point.x, point.y));
return convertVector2(renderTexture->This.mapCoordsToPixel(convertVector2(point), targetView->This));
result.x = sfmlPoint.x;
result.y = sfmlPoint.y;
return result;
return convertVector2(renderTexture->This.mapCoordsToPixel(convertVector2(point)));
}
+28 -83
View File
@@ -29,6 +29,8 @@
#include <CSFML/Graphics/CircleShapeStruct.hpp>
#include <CSFML/Graphics/ConvertRenderStates.hpp>
#include <CSFML/Graphics/ConvexShapeStruct.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/Graphics/ImageStruct.hpp>
#include <CSFML/Graphics/RectangleShapeStruct.hpp>
#include <CSFML/Graphics/RenderWindow.h>
@@ -39,27 +41,22 @@
#include <CSFML/Graphics/VertexArrayStruct.hpp>
#include <CSFML/Graphics/VertexBufferStruct.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/Window/ContextSettingsInternal.hpp>
#include <CSFML/Window/ConvertContextSettings.hpp>
#include <CSFML/Window/CursorStruct.hpp>
#include <CSFML/Window/ConvertVideoMode.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <SFML/Window/Touch.hpp>
////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint32_t style, sfWindowState state, const sfContextSettings* settings)
{
// Convert video mode
sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
priv::sfContextSettings_writeToCpp(*settings, params);
}
const sf::ContextSettings params = settings ? convertContextSettings(*settings) : sf::ContextSettings();
// Create the window
sfRenderWindow* renderWindow = new sfRenderWindow;
renderWindow->This.create(videoMode, title, style, static_cast<sf::State>(state), params);
renderWindow->This.create(convertVideoMode(mode), title, style, static_cast<sf::State>(state), params);
renderWindow->DefaultView.This = renderWindow->This.getDefaultView();
renderWindow->CurrentView.This = renderWindow->This.getView();
@@ -69,19 +66,12 @@ sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint3
////////////////////////////////////////////////////////////
sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style, sfWindowState state, const sfContextSettings* settings)
{
// Convert video mode
sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
priv::sfContextSettings_writeToCpp(*settings, params);
}
const sf::ContextSettings params = settings ? convertContextSettings(*settings) : sf::ContextSettings();
// Create the window
sfRenderWindow* renderWindow = new sfRenderWindow;
renderWindow->This.create(videoMode, reinterpret_cast<const char32_t*>(title), style, static_cast<sf::State>(state), params);
renderWindow->This.create(convertVideoMode(mode), reinterpret_cast<const char32_t*>(title), style, static_cast<sf::State>(state), params);
renderWindow->DefaultView.This = renderWindow->This.getDefaultView();
renderWindow->CurrentView.This = renderWindow->This.getView();
@@ -93,11 +83,7 @@ sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const sfChar32* t
sfRenderWindow* sfRenderWindow_createFromHandle(sfWindowHandle handle, const sfContextSettings* settings)
{
// Convert context settings
sf::ContextSettings params;
if (settings)
{
priv::sfContextSettings_writeToCpp(*settings, params);
}
const sf::ContextSettings params = settings ? convertContextSettings(*settings) : sf::ContextSettings();
// Create the window
sfRenderWindow* renderWindow = new sfRenderWindow;
@@ -133,13 +119,9 @@ bool sfRenderWindow_isOpen(const sfRenderWindow* renderWindow)
////////////////////////////////////////////////////////////
sfContextSettings sfRenderWindow_getSettings(const sfRenderWindow* renderWindow)
{
sfContextSettings settings = priv::sfContextSettings_null();
CSFML_CHECK_RETURN(renderWindow, settings);
CSFML_CHECK_RETURN(renderWindow, sfContextSettings{});
const sf::ContextSettings& params = renderWindow->This.getSettings();
priv::sfContextSettings_readFromCpp(params, settings);
return settings;
return convertContextSettings(renderWindow->This.getSettings());
}
@@ -189,18 +171,14 @@ sfVector2i sfRenderWindow_getPosition(const sfRenderWindow* renderWindow)
sfVector2i position = {0, 0};
CSFML_CHECK_RETURN(renderWindow, position);
sf::Vector2i sfmlPos = renderWindow->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
return position;
return convertVector2(renderWindow->This.getPosition());;
}
////////////////////////////////////////////////////////////
void sfRenderWindow_setPosition(sfRenderWindow* renderWindow, sfVector2i position)
{
CSFML_CALL(renderWindow, setPosition(sf::Vector2i(position.x, position.y)));
CSFML_CALL(renderWindow, setPosition(convertVector2(position)));
}
@@ -210,11 +188,7 @@ sfVector2u sfRenderWindow_getSize(const sfRenderWindow* renderWindow)
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(renderWindow, size);
sf::Vector2u sfmlSize = renderWindow->This.getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(renderWindow->This.getSize());
}
@@ -229,7 +203,7 @@ bool sfRenderWindow_isSrgb(const sfRenderWindow* renderWindow)
////////////////////////////////////////////////////////////
void sfRenderWindow_setSize(sfRenderWindow* renderWindow, sfVector2u size)
{
CSFML_CALL(renderWindow, setSize(sf::Vector2u(size.x, size.y)));
CSFML_CALL(renderWindow, setSize(convertVector2(size)));
}
@@ -352,9 +326,7 @@ sfWindowHandle sfRenderWindow_getNativeHandle(const sfRenderWindow* renderWindow
////////////////////////////////////////////////////////////
void sfRenderWindow_clear(sfRenderWindow* renderWindow, sfColor color)
{
sf::Color SFMLColor(color.r, color.g, color.b, color.a);
CSFML_CALL(renderWindow, clear(SFMLColor));
CSFML_CALL(renderWindow, clear(convertColor(color)));
}
@@ -392,13 +364,7 @@ sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const s
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderWindow, rect);
sf::IntRect SFMLrect = renderWindow->This.getViewport(view->This);
rect.position.x = SFMLrect.position.x;
rect.position.y = SFMLrect.position.y;
rect.size.x = SFMLrect.size.x;
rect.size.y = SFMLrect.size.y;
return rect;
return convertRect(renderWindow->This.getViewport(view->This));
}
@@ -408,16 +374,10 @@ sfVector2f sfRenderWindow_mapPixelToCoords(const sfRenderWindow* renderWindow, s
sfVector2f result = {0, 0};
CSFML_CHECK_RETURN(renderWindow, result);
sf::Vector2f sfmlPoint;
if (targetView)
sfmlPoint = renderWindow->This.mapPixelToCoords(sf::Vector2i(point.x, point.y), targetView->This);
else
sfmlPoint = renderWindow->This.mapPixelToCoords(sf::Vector2i(point.x, point.y));
return convertVector2(renderWindow->This.mapPixelToCoords(convertVector2(point), targetView->This));
result.x = sfmlPoint.x;
result.y = sfmlPoint.y;
return result;
return convertVector2(renderWindow->This.mapPixelToCoords(convertVector2(point)));
}
@@ -427,16 +387,10 @@ sfVector2i sfRenderWindow_mapCoordsToPixel(const sfRenderWindow* renderWindow, s
sfVector2i result = {0, 0};
CSFML_CHECK_RETURN(renderWindow, result);
sf::Vector2i sfmlPoint;
if (targetView)
sfmlPoint = renderWindow->This.mapCoordsToPixel(sf::Vector2f(point.x, point.y), targetView->This);
else
sfmlPoint = renderWindow->This.mapCoordsToPixel(sf::Vector2f(point.x, point.y));
return convertVector2(renderWindow->This.mapCoordsToPixel(convertVector2(point), targetView->This));
result.x = sfmlPoint.x;
result.y = sfmlPoint.y;
return result;
return convertVector2(renderWindow->This.mapCoordsToPixel(convertVector2(point)));
}
@@ -527,14 +481,10 @@ void sfRenderWindow_resetGLStates(sfRenderWindow* renderWindow)
////////////////////////////////////////////////////////////
sfVector2i sfMouse_getPositionRenderWindow(const sfRenderWindow* relativeTo)
{
sf::Vector2i sfmlPos;
if (relativeTo)
sfmlPos = sf::Mouse::getPosition(relativeTo->This);
else
sfmlPos = sf::Mouse::getPosition();
return convertVector2(sf::Mouse::getPosition(relativeTo->This));
sfVector2i position = {sfmlPos.x, sfmlPos.y};
return position;
return convertVector2(sf::Mouse::getPosition());
}
@@ -542,24 +492,19 @@ sfVector2i sfMouse_getPositionRenderWindow(const sfRenderWindow* relativeTo)
void sfMouse_setPositionRenderWindow(sfVector2i position, const sfRenderWindow* relativeTo)
{
if (relativeTo)
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y), relativeTo->This);
sf::Mouse::setPosition(convertVector2(position), relativeTo->This);
else
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y));
sf::Mouse::setPosition(convertVector2(position));
}
////////////////////////////////////////////////////////////
sfVector2i sfTouch_getPositionRenderWindow(unsigned int finger, const sfRenderWindow* relativeTo)
{
sf::Vector2i sfmlPosition;
if (relativeTo)
sfmlPosition = sf::Touch::getPosition(finger, relativeTo->This);
else
sfmlPosition = sf::Touch::getPosition(finger);
return convertVector2(sf::Touch::getPosition(finger, relativeTo->This));
sfVector2i position = { sfmlPosition.x, sfmlPosition.y };
return position;
return convertVector2(sf::Touch::getPosition(finger));
}
+20 -63
View File
@@ -29,6 +29,9 @@
#include <CSFML/Graphics/ShapeStruct.hpp>
#include <SFML/Graphics/Color.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -51,7 +54,7 @@ void sfShape_destroy(sfShape* shape)
////////////////////////////////////////////////////////////
void sfShape_setPosition(sfShape* shape, sfVector2f position)
{
CSFML_CALL(shape, setPosition({ position.x, position.y }));
CSFML_CALL(shape, setPosition(convertVector2(position)));
}
@@ -65,14 +68,14 @@ void sfShape_setRotation(sfShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfShape_setScale(sfShape* shape, sfVector2f scale)
{
CSFML_CALL(shape, setScale({ scale.x, scale.y }));
CSFML_CALL(shape, setScale(convertVector2(scale)));
}
////////////////////////////////////////////////////////////
void sfShape_setOrigin(sfShape* shape, sfVector2f origin)
{
CSFML_CALL(shape, setOrigin({ origin.x, origin.y }));
CSFML_CALL(shape, setOrigin(convertVector2(origin)));
}
@@ -82,11 +85,7 @@ 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;
return convertVector2(shape->This.getPosition());
}
@@ -103,11 +102,7 @@ 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;
return convertVector2(shape->This.getScale());
}
@@ -117,18 +112,14 @@ 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;
return convertVector2(shape->This.getOrigin());
}
////////////////////////////////////////////////////////////
void sfShape_move(sfShape* shape, sfVector2f offset)
{
CSFML_CALL(shape, move({ offset.x, offset.y }));
CSFML_CALL(shape, move(convertVector2(offset)));
}
@@ -142,7 +133,7 @@ void sfShape_rotate(sfShape* shape, float angle)
////////////////////////////////////////////////////////////
void sfShape_scale(sfShape* shape, sfVector2f factors)
{
CSFML_CALL(shape, scale({ factors.x, factors.y }));
CSFML_CALL(shape, scale(convertVector2(factors)));
}
@@ -177,21 +168,21 @@ void sfShape_setTexture(sfShape* shape, const sfTexture* texture, bool resetRect
////////////////////////////////////////////////////////////
void sfShape_setTextureRect(sfShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
CSFML_CALL(shape, setTextureRect(convertRect(rect)));
}
////////////////////////////////////////////////////////////
void sfShape_setFillColor(sfShape* shape, sfColor color)
{
CSFML_CALL(shape, setFillColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setFillColor(convertColor(color)));
}
////////////////////////////////////////////////////////////
void sfShape_setOutlineColor(sfShape* shape, sfColor color)
{
CSFML_CALL(shape, setOutlineColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(shape, setOutlineColor(convertColor(color)));
}
@@ -217,13 +208,7 @@ sfIntRect sfShape_getTextureRect(const sfShape* shape)
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getTextureRect());
}
@@ -233,13 +218,7 @@ 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;
return convertColor(shape->This.getFillColor());
}
@@ -249,13 +228,7 @@ 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;
return convertColor(shape->This.getOutlineColor());
}
@@ -279,11 +252,7 @@ sfVector2f sfShape_getPoint(const sfShape* shape, size_t 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;
return convertVector2(shape->This.getPoint(index));
}
@@ -293,13 +262,7 @@ sfFloatRect sfShape_getLocalBounds(const sfShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getLocalBounds());
}
@@ -309,13 +272,7 @@ sfFloatRect sfShape_getGlobalBounds(const sfShape* shape)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(shape->This.getGlobalBounds());
}
+2 -2
View File
@@ -31,6 +31,7 @@
#include <SFML/Graphics/Shape.hpp>
#include <CSFML/Graphics/TextureStruct.hpp>
#include <CSFML/Graphics/Transform.h>
#include <CSFML/System/ConvertVector2.hpp>
////////////////////////////////////////////////////////////
@@ -57,8 +58,7 @@ public :
sf::Vector2f getPoint(std::size_t index) const override
{
sfVector2f point = myGetPointCallback(index, myUserData);
return sf::Vector2f(point.x, point.y);
return convertVector2(myGetPointCallback(index, myUserData));
}
using sf::Shape::update;
+17 -50
View File
@@ -30,6 +30,9 @@
#include <SFML/Graphics/Color.hpp>
#include <SFML/Graphics/Image.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -62,7 +65,7 @@ void sfSprite_destroy(sfSprite* sprite)
////////////////////////////////////////////////////////////
void sfSprite_setPosition(sfSprite* sprite, sfVector2f position)
{
CSFML_CALL(sprite, setPosition({ position.x, position.y }));
CSFML_CALL(sprite, setPosition(convertVector2(position)));
}
@@ -76,14 +79,14 @@ void sfSprite_setRotation(sfSprite* sprite, float angle)
////////////////////////////////////////////////////////////
void sfSprite_setScale(sfSprite* sprite, sfVector2f scale)
{
CSFML_CALL(sprite, setScale({ scale.x, scale.y }));
CSFML_CALL(sprite, setScale(convertVector2(scale)));
}
////////////////////////////////////////////////////////////
void sfSprite_setOrigin(sfSprite* sprite, sfVector2f origin)
{
CSFML_CALL(sprite, setOrigin({ origin.x, origin.y }));
CSFML_CALL(sprite, setOrigin(convertVector2(origin)));
}
@@ -93,11 +96,7 @@ sfVector2f sfSprite_getPosition(const sfSprite* sprite)
sfVector2f position = {0, 0};
CSFML_CHECK_RETURN(sprite, position);
sf::Vector2f sfmlPos = sprite->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
return position;
return convertVector2(sprite->This.getPosition());
}
@@ -114,11 +113,7 @@ sfVector2f sfSprite_getScale(const sfSprite* sprite)
sfVector2f scale = {0, 0};
CSFML_CHECK_RETURN(sprite, scale);
sf::Vector2f sfmlScale = sprite->This.getScale();
scale.x = sfmlScale.x;
scale.y = sfmlScale.y;
return scale;
return convertVector2(sprite->This.getScale());
}
@@ -128,18 +123,14 @@ sfVector2f sfSprite_getOrigin(const sfSprite* sprite)
sfVector2f origin = {0, 0};
CSFML_CHECK_RETURN(sprite, origin);
sf::Vector2f sfmlOrigin = sprite->This.getOrigin();
origin.x = sfmlOrigin.x;
origin.y = sfmlOrigin.y;
return origin;
return convertVector2(sprite->This.getOrigin());
}
////////////////////////////////////////////////////////////
void sfSprite_move(sfSprite* sprite, sfVector2f offset)
{
CSFML_CALL(sprite, move({ offset.x, offset.y }));
CSFML_CALL(sprite, move(convertVector2(offset)));
}
@@ -153,7 +144,7 @@ void sfSprite_rotate(sfSprite* sprite, float angle)
////////////////////////////////////////////////////////////
void sfSprite_scale(sfSprite* sprite, sfVector2f factors)
{
CSFML_CALL(sprite, scale({ factors.x, factors.y }));
CSFML_CALL(sprite, scale(convertVector2(factors)));
}
@@ -191,14 +182,14 @@ void sfSprite_setTexture(sfSprite* sprite, const sfTexture* texture, bool resetR
////////////////////////////////////////////////////////////
void sfSprite_setTextureRect(sfSprite* sprite, sfIntRect rectangle)
{
CSFML_CALL(sprite, setTextureRect(sf::IntRect({ rectangle.position.x, rectangle.position.y }, { rectangle.size.x, rectangle.size.y })));
CSFML_CALL(sprite, setTextureRect(convertRect(rectangle)));
}
////////////////////////////////////////////////////////////
void sfSprite_setColor(sfSprite* sprite, sfColor color)
{
CSFML_CALL(sprite, setColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(sprite, setColor(convertColor(color)));
}
@@ -217,13 +208,7 @@ sfIntRect sfSprite_getTextureRect(const sfSprite* sprite)
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(sprite, rect);
sf::IntRect sfmlRect = sprite->This.getTextureRect();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(sprite->This.getTextureRect());
}
@@ -233,13 +218,7 @@ sfColor sfSprite_getColor(const sfSprite* sprite)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(sprite, color);
sf::Color sfmlColor = sprite->This.getColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(sprite->This.getColor());
}
@@ -249,13 +228,7 @@ sfFloatRect sfSprite_getLocalBounds(const sfSprite* sprite)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(sprite, rect);
sf::FloatRect sfmlRect = sprite->This.getLocalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(sprite->This.getLocalBounds());
}
@@ -265,11 +238,5 @@ sfFloatRect sfSprite_getGlobalBounds(const sfSprite* sprite)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(sprite, rect);
sf::FloatRect sfmlRect = sprite->This.getGlobalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(sprite->This.getGlobalBounds());
}
+18 -55
View File
@@ -30,6 +30,9 @@
#include <CSFML/Graphics/Font.h>
#include <SFML/Graphics/Color.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/Graphics/ConvertColor.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -61,7 +64,7 @@ void sfText_destroy(sfText* text)
////////////////////////////////////////////////////////////
void sfText_setPosition(sfText* text, sfVector2f position)
{
CSFML_CALL(text, setPosition({ position.x, position.y }));
CSFML_CALL(text, setPosition(convertVector2(position)));
}
@@ -75,14 +78,14 @@ void sfText_setRotation(sfText* text, float angle)
////////////////////////////////////////////////////////////
void sfText_setScale(sfText* text, sfVector2f scale)
{
CSFML_CALL(text, setScale({ scale.x, scale.y }));
CSFML_CALL(text, setScale(convertVector2(scale)));
}
////////////////////////////////////////////////////////////
void sfText_setOrigin(sfText* text, sfVector2f origin)
{
CSFML_CALL(text, setOrigin({ origin.x, origin.y }));
CSFML_CALL(text, setOrigin(convertVector2(origin)));
}
@@ -92,11 +95,7 @@ sfVector2f sfText_getPosition(const sfText* text)
sfVector2f position = {0, 0};
CSFML_CHECK_RETURN(text, position);
sf::Vector2f sfmlPos = text->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
return position;
return convertVector2(text->This.getPosition());
}
@@ -113,11 +112,7 @@ sfVector2f sfText_getScale(const sfText* text)
sfVector2f scale = {0, 0};
CSFML_CHECK_RETURN(text, scale);
sf::Vector2f sfmlScale = text->This.getScale();
scale.x = sfmlScale.x;
scale.y = sfmlScale.y;
return scale;
return convertVector2(text->This.getScale());
}
@@ -127,18 +122,14 @@ sfVector2f sfText_getOrigin(const sfText* text)
sfVector2f origin = {0, 0};
CSFML_CHECK_RETURN(text, origin);
sf::Vector2f sfmlOrigin = text->This.getOrigin();
origin.x = sfmlOrigin.x;
origin.y = sfmlOrigin.y;
return origin;
return convertVector2(text->This.getOrigin());
}
////////////////////////////////////////////////////////////
void sfText_move(sfText* text, sfVector2f offset)
{
CSFML_CALL(text, move({ offset.x, offset.y }));
CSFML_CALL(text, move(convertVector2(offset)));
}
@@ -152,7 +143,7 @@ void sfText_rotate(sfText* text, float angle)
////////////////////////////////////////////////////////////
void sfText_scale(sfText* text, sfVector2f factors)
{
CSFML_CALL(text, scale({ factors.x, factors.y }));
CSFML_CALL(text, scale(convertVector2(factors)));
}
@@ -232,14 +223,14 @@ void sfText_setStyle(sfText* text, uint32_t style)
////////////////////////////////////////////////////////////
void sfText_setFillColor(sfText* text, sfColor color)
{
CSFML_CALL(text, setFillColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(text, setFillColor(convertColor(color)));
}
////////////////////////////////////////////////////////////
void sfText_setOutlineColor(sfText* text, sfColor color)
{
CSFML_CALL(text, setOutlineColor(sf::Color(color.r, color.g, color.b, color.a)));
CSFML_CALL(text, setOutlineColor(convertColor(color)));
}
@@ -314,13 +305,7 @@ sfColor sfText_getFillColor(const sfText* text)
sfColor color = {0, 0, 0, 0};
CSFML_CHECK_RETURN(text, color);
sf::Color sfmlColor = text->This.getFillColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(text->This.getFillColor());
}
@@ -330,13 +315,7 @@ sfColor sfText_getOutlineColor(const sfText* text)
sfColor color = { 0, 0, 0, 0 };
CSFML_CHECK_RETURN(text, color);
sf::Color sfmlColor = text->This.getOutlineColor();
color.r = sfmlColor.r;
color.g = sfmlColor.g;
color.b = sfmlColor.b;
color.a = sfmlColor.a;
return color;
return convertColor(text->This.getOutlineColor());
}
@@ -353,11 +332,7 @@ sfVector2f sfText_findCharacterPos(const sfText* text, size_t index)
sfVector2f position = {0, 0};
CSFML_CHECK_RETURN(text, position);
sf::Vector2f sfmlPos = text->This.findCharacterPos(index);
position.x = sfmlPos.x;
position.y = sfmlPos.y;
return position;
return convertVector2(text->This.findCharacterPos(index));
}
@@ -367,13 +342,7 @@ sfFloatRect sfText_getLocalBounds(const sfText* text)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(text, rect);
sf::FloatRect sfmlRect = text->This.getLocalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(text->This.getLocalBounds());
}
@@ -383,11 +352,5 @@ sfFloatRect sfText_getGlobalBounds(const sfText* text)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(text, rect);
sf::FloatRect sfmlRect = text->This.getGlobalBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(text->This.getGlobalBounds());
}
+11 -30
View File
@@ -29,7 +29,9 @@
#include <CSFML/Graphics/TextureStruct.hpp>
#include <CSFML/Graphics/ImageStruct.hpp>
#include <CSFML/Graphics/RenderWindowStruct.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/Window/WindowStruct.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/CallbackStream.hpp>
@@ -54,9 +56,7 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
if (!texture->This->loadFromFile(filename, false, rect))
{
@@ -72,9 +72,7 @@ sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* a
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
if (!texture->This->loadFromFile(filename, true, rect))
{
@@ -90,9 +88,7 @@ sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, cons
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
if (!texture->This->loadFromMemory(data, sizeInBytes, false, rect))
{
@@ -108,9 +104,7 @@ sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes,
{
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
if (!texture->This->loadFromMemory(data, sizeInBytes, true, rect))
{
@@ -129,9 +123,7 @@ sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* ar
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
CallbackStream sfmlStream(stream);
if (!texture->This->loadFromStream(sfmlStream, false, rect))
@@ -150,9 +142,7 @@ sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
CallbackStream sfmlStream(stream);
if (!texture->This->loadFromStream(sfmlStream, true, rect))
@@ -172,9 +162,7 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
if (!texture->This->loadFromImage(image->This, false, rect))
{
@@ -192,9 +180,7 @@ sfTexture* sfTexture_createSrgbFromImage(const sfImage* image, const sfIntRect*
sfTexture* texture = new sfTexture;
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
const sf::IntRect rect = area ? convertRect(*area) : sf::IntRect();
if (!texture->This->loadFromImage(image->This, true, rect))
{
@@ -227,12 +213,7 @@ sfVector2u sfTexture_getSize(const sfTexture* texture)
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(texture, size);
sf::Vector2u sfmlSize = texture->This->getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(texture->This->getSize());
}
+4 -14
View File
@@ -28,6 +28,8 @@
#include <CSFML/Graphics/Transform.h>
#include <SFML/Graphics/Transform.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
#include <cstring>
@@ -77,12 +79,7 @@ sfVector2f sfTransform_transformPoint(const sfTransform* transform, sfVector2f p
sfVector2f p = {0, 0};
CSFML_CHECK_RETURN(transform, p);
sf::Vector2f sfmlPoint = convertTransform(*transform).transformPoint({ point.x, point.y });
p.x = sfmlPoint.x;
p.y = sfmlPoint.y;
return p;
return convertVector2(convertTransform(*transform).transformPoint(convertVector2(point)));
}
@@ -92,14 +89,7 @@ sfFloatRect sfTransform_transformRect(const sfTransform* transform, sfFloatRect
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(transform, rect);
sf::FloatRect sfmlRect = convertTransform(*transform).transformRect(sf::FloatRect({ rectangle.position.x, rectangle.position.y }, { rectangle.size.x, rectangle.size.y }));
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(convertTransform(*transform).transformRect(convertRect(rectangle)));
}
+9 -20
View File
@@ -28,6 +28,7 @@
#include <CSFML/Graphics/Transformable.h>
#include <CSFML/Graphics/TransformableStruct.hpp>
#include <CSFML/Graphics/ConvertTransform.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -59,7 +60,7 @@ void sfTransformable_destroy(sfTransformable* transformable)
////////////////////////////////////////////////////////////
void sfTransformable_setPosition(sfTransformable* transformable, sfVector2f position)
{
CSFML_CALL(transformable, setPosition({ position.x, position.y }));
CSFML_CALL(transformable, setPosition(convertVector2(position)));
}
@@ -73,14 +74,14 @@ void sfTransformable_setRotation(sfTransformable* transformable, float angle)
////////////////////////////////////////////////////////////
void sfTransformable_setScale(sfTransformable* transformable, sfVector2f scale)
{
CSFML_CALL(transformable, setScale({ scale.x, scale.y }));
CSFML_CALL(transformable, setScale(convertVector2(scale)));
}
////////////////////////////////////////////////////////////
void sfTransformable_setOrigin(sfTransformable* transformable, sfVector2f origin)
{
CSFML_CALL(transformable, setOrigin({ origin.x, origin.y }));
CSFML_CALL(transformable, setOrigin(convertVector2(origin)));
}
@@ -90,11 +91,7 @@ sfVector2f sfTransformable_getPosition(const sfTransformable* transformable)
sfVector2f position = {0, 0};
CSFML_CHECK_RETURN(transformable, position);
sf::Vector2f sfmlPos = transformable->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
return position;
return convertVector2(transformable->This.getPosition());
}
@@ -111,11 +108,7 @@ sfVector2f sfTransformable_getScale(const sfTransformable* transformable)
sfVector2f scale = {0, 0};
CSFML_CHECK_RETURN(transformable, scale);
sf::Vector2f sfmlScale = transformable->This.getScale();
scale.x = sfmlScale.x;
scale.y = sfmlScale.y;
return scale;
return convertVector2(transformable->This.getScale());
}
@@ -125,18 +118,14 @@ sfVector2f sfTransformable_getOrigin(const sfTransformable* transformable)
sfVector2f origin = {0, 0};
CSFML_CHECK_RETURN(transformable, origin);
sf::Vector2f sfmlOrigin = transformable->This.getOrigin();
origin.x = sfmlOrigin.x;
origin.y = sfmlOrigin.y;
return origin;
return convertVector2(transformable->This.getOrigin());
}
////////////////////////////////////////////////////////////
void sfTransformable_move(sfTransformable* transformable, sfVector2f offset)
{
CSFML_CALL(transformable, move({ offset.x, offset.y }));
CSFML_CALL(transformable, move(convertVector2(offset)));
}
@@ -150,7 +139,7 @@ void sfTransformable_rotate(sfTransformable* transformable, float angle)
////////////////////////////////////////////////////////////
void sfTransformable_scale(sfTransformable* transformable, sfVector2f factors)
{
CSFML_CALL(transformable, scale({ factors.x, factors.y }));
CSFML_CALL(transformable, scale(convertVector2(factors)));
}
+2 -7
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/VertexArray.h>
#include <CSFML/Graphics/VertexArrayStruct.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/Internal.hpp>
@@ -113,11 +114,5 @@ sfFloatRect sfVertexArray_getBounds(sfVertexArray* vertexArray)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(vertexArray, rect);
sf::FloatRect sfmlRect = vertexArray->This.getBounds();
rect.position.x = sfmlRect.position.x;
rect.position.y = sfmlRect.position.y;
rect.size.x = sfmlRect.size.x;
rect.size.y = sfmlRect.size.y;
return rect;
return convertRect(vertexArray->This.getBounds());
}
+10 -22
View File
@@ -27,6 +27,8 @@
////////////////////////////////////////////////////////////
#include <CSFML/Graphics/View.h>
#include <CSFML/Graphics/ViewStruct.hpp>
#include <CSFML/Graphics/ConvertRect.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -40,7 +42,7 @@ sfView* sfView_create()
////////////////////////////////////////////////////////////
sfView* sfView_createFromRect(sfFloatRect rectangle)
{
return new sfView{sf::View(sf::FloatRect({rectangle.position.x, rectangle.position.y}, {rectangle.size.x, rectangle.size.y}))};
return new sfView{sf::View(convertRect(rectangle))};
}
@@ -63,14 +65,14 @@ void sfView_destroy(sfView* view)
////////////////////////////////////////////////////////////
void sfView_setCenter(sfView* view, sfVector2f center)
{
CSFML_CALL(view, setCenter({ center.x, center.y }));
CSFML_CALL(view, setCenter(convertVector2(center)));
}
////////////////////////////////////////////////////////////
void sfView_setSize(sfView* view, sfVector2f size)
{
CSFML_CALL(view, setSize({ size.x, size.y }));
CSFML_CALL(view, setSize(convertVector2(size)));
}
@@ -84,7 +86,7 @@ void sfView_setRotation(sfView* view, float angle)
////////////////////////////////////////////////////////////
void sfView_setViewport(sfView* view, sfFloatRect viewport)
{
CSFML_CALL(view, setViewport(sf::FloatRect({ viewport.position.x, viewport.position.y }, { viewport.size.x, viewport.size.y })));
CSFML_CALL(view, setViewport(convertRect(viewport)));
}
@@ -94,11 +96,7 @@ sfVector2f sfView_getCenter(const sfView* view)
sfVector2f center = {0, 0};
CSFML_CHECK_RETURN(view, center);
sf::Vector2f sfmlCenter = view->This.getCenter();
center.x = sfmlCenter.x;
center.y = sfmlCenter.y;
return center;
return convertVector2(view->This.getCenter());
}
@@ -108,11 +106,7 @@ sfVector2f sfView_getSize(const sfView* view)
sfVector2f size = {0, 0};
CSFML_CHECK_RETURN(view, size);
sf::Vector2f sfmlSize = view->This.getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(view->This.getSize());
}
@@ -129,20 +123,14 @@ sfFloatRect sfView_getViewport(const sfView* view)
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(view, rect);
sf::FloatRect SFMLRect = view->This.getViewport();
rect.position.x = SFMLRect.position.x;
rect.position.y = SFMLRect.position.y;
rect.size.x = SFMLRect.size.x;
rect.size.y = SFMLRect.size.y;
return rect;
return convertRect(view->This.getViewport());
}
////////////////////////////////////////////////////////////
void sfView_move(sfView* view, sfVector2f offset)
{
CSFML_CALL(view, move({ offset.x, offset.y }));
CSFML_CALL(view, move(convertVector2(offset)));
}
+2
View File
@@ -14,6 +14,8 @@ set(SRC
${SRCROOT}/Clock.cpp
${SRCROOT}/ClockStruct.hpp
${INCROOT}/Clock.h
${SRCROOT}/ConvertVector2.hpp
${SRCROOT}/ConvertVector3.hpp
${INCROOT}/InputStream.h
${SRCROOT}/Sleep.cpp
${INCROOT}/Sleep.h
+65
View File
@@ -0,0 +1,65 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Vector2.hpp>
#include <CSFML/System/Vector2.h>
////////////////////////////////////////////////////////////
// Convert sf::Vector2 to sfVector2
////////////////////////////////////////////////////////////
[[nodiscard]] inline sfVector2i convertVector2(const sf::Vector2i vector)
{
return {vector.x, vector.y};
}
[[nodiscard]] inline sfVector2u convertVector2(const sf::Vector2u vector)
{
return {vector.x, vector.y};
}
[[nodiscard]] inline sfVector2f convertVector2(const sf::Vector2f vector)
{
return {vector.x, vector.y};
}
////////////////////////////////////////////////////////////
// Convert sfVector2 to sf::Vector2
////////////////////////////////////////////////////////////
[[nodiscard]] inline sf::Vector2i convertVector2(const sfVector2i vector)
{
return {vector.x, vector.y};
}
[[nodiscard]] inline sf::Vector2u convertVector2(const sfVector2u vector)
{
return {vector.x, vector.y};
}
[[nodiscard]] inline sf::Vector2f convertVector2(const sfVector2f vector)
{
return {vector.x, vector.y};
}
+49
View File
@@ -0,0 +1,49 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Vector3.hpp>
#include <CSFML/System/Vector3.h>
////////////////////////////////////////////////////////////
// Convert sf::Vector3f to sfVector3f
////////////////////////////////////////////////////////////
[[nodiscard]] inline sfVector3f convertVector3(const sf::Vector3f vector)
{
return {vector.x, vector.y, vector.z};
}
////////////////////////////////////////////////////////////
// Convert sfVector3f to sf::Vector3f
////////////////////////////////////////////////////////////
[[nodiscard]] inline sf::Vector3f convertVector3(const sfVector3f vector)
{
return {vector.x, vector.y, vector.z};
}
+2 -1
View File
@@ -11,9 +11,10 @@ set(SRC
${SRCROOT}/Cursor.cpp
${SRCROOT}/CursorStruct.hpp
${SRCROOT}/Context.cpp
${SRCROOT}/ContextSettingsInternal.hpp
${SRCROOT}/ContextStruct.hpp
${INCROOT}/Context.h
${SRCROOT}/ConvertContextSettings.hpp
${SRCROOT}/ConvertVideoMode.hpp
${INCROOT}/Event.h
${SRCROOT}/Joystick.cpp
${INCROOT}/Joystick.h
+3 -7
View File
@@ -28,7 +28,7 @@
#include <CSFML/Window/Context.h>
#include <CSFML/Window/ContextStruct.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/Window/ContextSettingsInternal.hpp>
#include <CSFML/Window/ConvertContextSettings.hpp>
////////////////////////////////////////////////////////////
@@ -69,13 +69,9 @@ GlFunctionPointer sfContext_getFunction(const char* name)
////////////////////////////////////////////////////////////
sfContextSettings sfContext_getSettings(const sfContext* context)
{
sfContextSettings settings = priv::sfContextSettings_null();
CSFML_CHECK_RETURN(context, settings);
CSFML_CHECK_RETURN(context, sfContextSettings{});
const sf::ContextSettings& params = context->This.getSettings();
priv::sfContextSettings_readFromCpp(params, settings);
return settings;
return convertContextSettings(context->This.getSettings());
}
@@ -1,72 +0,0 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <CSFML/Window.h>
#include <SFML/Window.hpp>
namespace priv
{
////////////////////////////////////////////////////////////
// Create a "null" sfContextSettings that's returned in case of an error.
////////////////////////////////////////////////////////////
inline sfContextSettings sfContextSettings_null()
{
sfContextSettings settings = {0, 0, 0, 0, 0, 0, false};
return settings;
}
////////////////////////////////////////////////////////////
// Read the data of an sf::ContextSettings into an sfContextSettings
////////////////////////////////////////////////////////////
inline void sfContextSettings_readFromCpp(const sf::ContextSettings& from, sfContextSettings& to)
{
to.depthBits = from.depthBits;
to.stencilBits = from.stencilBits;
to.antialiasingLevel = from.antialiasingLevel;
to.majorVersion = from.majorVersion;
to.minorVersion = from.minorVersion;
to.attributeFlags = from.attributeFlags;
to.sRgbCapable = from.sRgbCapable;
}
////////////////////////////////////////////////////////////
// Write the data of an sfContextSettings into an sf::ContextSettings
////////////////////////////////////////////////////////////
inline void sfContextSettings_writeToCpp(const sfContextSettings& from, sf::ContextSettings& to)
{
to.depthBits = from.depthBits;
to.stencilBits = from.stencilBits;
to.antialiasingLevel = from.antialiasingLevel;
to.majorVersion = from.majorVersion;
to.minorVersion = from.minorVersion;
to.attributeFlags = from.attributeFlags;
to.sRgbCapable = from.sRgbCapable;
}
}
@@ -0,0 +1,60 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <CSFML/Window.h>
#include <SFML/Window.hpp>
////////////////////////////////////////////////////////////
// Convert sf::ContextSettings to sfContextSettings
////////////////////////////////////////////////////////////
[[nodiscard]] inline sfContextSettings convertContextSettings(const sf::ContextSettings& settings)
{
return {settings.depthBits,
settings.stencilBits,
settings.antialiasingLevel,
settings.majorVersion,
settings.minorVersion,
settings.attributeFlags,
settings.sRgbCapable};
}
////////////////////////////////////////////////////////////
// Convert sfContextSettings to sf::ContextSettings
////////////////////////////////////////////////////////////
[[nodiscard]] inline sf::ContextSettings convertContextSettings(const sfContextSettings& settings)
{
return {settings.depthBits,
settings.stencilBits,
settings.antialiasingLevel,
settings.majorVersion,
settings.minorVersion,
settings.attributeFlags,
settings.sRgbCapable};
}
+49
View File
@@ -0,0 +1,49 @@
////////////////////////////////////////////////////////////
//
// SFML - Simple and Fast Multimedia Library
// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org)
//
// 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.
//
////////////////////////////////////////////////////////////
#pragma once
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/VideoMode.hpp>
#include <CSFML/Window/VideoMode.h>
////////////////////////////////////////////////////////////
// Convert sf::VideoMode to sfVideoMode
////////////////////////////////////////////////////////////
[[nodiscard]] inline sfVideoMode convertVideoMode(const sf::VideoMode& videoMode)
{
return {videoMode.size.x, videoMode.size.y, videoMode.bitsPerPixel};
}
////////////////////////////////////////////////////////////
// Convert sfVideoMode to sf::VideoMode
////////////////////////////////////////////////////////////
[[nodiscard]] inline sf::VideoMode convertVideoMode(const sfVideoMode& videoMode)
{
return sf::VideoMode({videoMode.width, videoMode.height}, videoMode.bitsPerPixel);
}
+2 -1
View File
@@ -27,13 +27,14 @@
////////////////////////////////////////////////////////////
#include <CSFML/Window/Cursor.h>
#include <CSFML/Window/CursorStruct.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
////////////////////////////////////////////////////////////
sfCursor* sfCursor_createFromPixels(const uint8_t* pixels, sfVector2u size, sfVector2u hotspot)
{
auto cursor = sf::Cursor::createFromPixels(pixels, sf::Vector2u(size.x, size.y), sf::Vector2u(hotspot.x, hotspot.y));
auto cursor = sf::Cursor::createFromPixels(pixels, convertVector2(size), convertVector2(hotspot));
if (!cursor)
return nullptr;
+9 -16
View File
@@ -29,6 +29,7 @@
#include <CSFML/Window/WindowBaseStruct.hpp>
#include <CSFML/Window/WindowStruct.hpp>
#include <SFML/Window/Mouse.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -42,14 +43,10 @@ bool sfMouse_isButtonPressed(sfMouseButton button)
////////////////////////////////////////////////////////////
sfVector2i sfMouse_getPosition(const sfWindow* relativeTo)
{
sf::Vector2i sfmlPos;
if (relativeTo)
sfmlPos = sf::Mouse::getPosition(relativeTo->This);
else
sfmlPos = sf::Mouse::getPosition();
return convertVector2(sf::Mouse::getPosition(relativeTo->This));
sfVector2i position = {sfmlPos.x, sfmlPos.y};
return position;
return convertVector2(sf::Mouse::getPosition());
}
@@ -57,23 +54,19 @@ sfVector2i sfMouse_getPosition(const sfWindow* relativeTo)
void sfMouse_setPosition(sfVector2i position, const sfWindow* relativeTo)
{
if (relativeTo)
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y), relativeTo->This);
sf::Mouse::setPosition(convertVector2(position), relativeTo->This);
else
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y));
sf::Mouse::setPosition(convertVector2(position));
}
////////////////////////////////////////////////////////////
sfVector2i sfMouse_getPositionWindowBase(const sfWindowBase* relativeTo)
{
sf::Vector2i sfmlPos;
if (relativeTo)
sfmlPos = sf::Mouse::getPosition(relativeTo->This);
else
sfmlPos = sf::Mouse::getPosition();
return convertVector2(sf::Mouse::getPosition(relativeTo->This));
sfVector2i position = { sfmlPos.x, sfmlPos.y };
return position;
return convertVector2(sf::Mouse::getPosition());
}
@@ -81,7 +74,7 @@ sfVector2i sfMouse_getPositionWindowBase(const sfWindowBase* relativeTo)
void sfMouse_setPositionWindowBase(sfVector2i position, const sfWindowBase* relativeTo)
{
if (relativeTo)
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y), relativeTo->This);
sf::Mouse::setPosition(convertVector2(position), relativeTo->This);
else
sf::Mouse::setPosition(sf::Vector2i(position.x, position.y));
sf::Mouse::setPosition(convertVector2(position));
}
+2 -4
View File
@@ -27,6 +27,7 @@
////////////////////////////////////////////////////////////
#include <CSFML/Window/Sensor.h>
#include <SFML/Window/Sensor.hpp>
#include <CSFML/System/ConvertVector3.hpp>
#include <CSFML/Internal.hpp>
@@ -45,8 +46,5 @@ void sfSensor_setEnabled(sfSensorType sensor, bool enabled)
////////////////////////////////////////////////////////////
sfVector3f sfSensor_getValue(sfSensorType sensor)
{
sf::Vector3f sfmlValue = sf::Sensor::getValue(static_cast<sf::Sensor::Type>(sensor));
sfVector3f value = {sfmlValue.x, sfmlValue.y, sfmlValue.z};
return value;
return convertVector3(sf::Sensor::getValue(static_cast<sf::Sensor::Type>(sensor)));
}
+5 -14
View File
@@ -29,6 +29,7 @@
#include <SFML/Window/Touch.hpp>
#include <CSFML/Window/WindowBaseStruct.hpp>
#include <CSFML/Window/WindowStruct.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/Internal.hpp>
@@ -41,27 +42,17 @@ bool sfTouch_isDown(unsigned int finger)
////////////////////////////////////////////////////////////
sfVector2i sfTouch_getPosition(unsigned int finger, const sfWindow* relativeTo)
{
sf::Vector2i sfmlPosition;
if (relativeTo)
sfmlPosition = sf::Touch::getPosition(finger, relativeTo->This);
else
sfmlPosition = sf::Touch::getPosition(finger);
return convertVector2(sf::Touch::getPosition(finger, relativeTo->This));
sfVector2i position = {sfmlPosition.x, sfmlPosition.y};
return position;
return convertVector2(sf::Touch::getPosition(finger));
}
////////////////////////////////////////////////////////////
sfVector2i sfTouch_getPositionWindowBase(unsigned int finger, const sfWindowBase* relativeTo)
{
sf::Vector2i sfmlPosition;
if (relativeTo)
sfmlPosition = sf::Touch::getPosition(finger, relativeTo->This);
else
sfmlPosition = sf::Touch::getPosition(finger);
return convertVector2(sf::Touch::getPosition(finger, relativeTo->This));
sfVector2i position = { sfmlPosition.x, sfmlPosition.y };
return position;
return convertVector2(sf::Touch::getPosition(finger));
}
+5 -18
View File
@@ -26,6 +26,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <CSFML/Window/VideoMode.h>
#include <CSFML/Window/ConvertVideoMode.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <CSFML/Internal.hpp>
@@ -33,13 +34,7 @@
////////////////////////////////////////////////////////////
sfVideoMode sfVideoMode_getDesktopMode()
{
sf::VideoMode desktop = sf::VideoMode::getDesktopMode();
sfVideoMode ret;
ret.width = desktop.size.x;
ret.height = desktop.size.y;
ret.bitsPerPixel = desktop.bitsPerPixel;
return ret;
return convertVideoMode(sf::VideoMode::getDesktopMode());
}
@@ -51,15 +46,8 @@ const sfVideoMode* sfVideoMode_getFullscreenModes(size_t* count)
// Populate the array on first call
if (modes.empty())
{
const std::vector<sf::VideoMode>& sfmlModes = sf::VideoMode::getFullscreenModes();
for (const auto& sfmlMode : sfmlModes)
{
sfVideoMode mode;
mode.width = sfmlMode.size.x;
mode.height = sfmlMode.size.y;
mode.bitsPerPixel = sfmlMode.bitsPerPixel;
modes.push_back(mode);
}
for (const auto& mode : sf::VideoMode::getFullscreenModes())
modes.push_back(convertVideoMode(mode));
}
if (count)
@@ -72,6 +60,5 @@ const sfVideoMode* sfVideoMode_getFullscreenModes(size_t* count)
////////////////////////////////////////////////////////////
bool sfVideoMode_isValid(sfVideoMode mode)
{
sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel);
return videoMode.isValid();
return convertVideoMode(mode).isValid();
}
+14 -42
View File
@@ -28,27 +28,22 @@
#include <CSFML/Window/Window.h>
#include <CSFML/Window/WindowStruct.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/Window/ContextSettingsInternal.hpp>
#include <CSFML/Window/ConvertContextSettings.hpp>
#include <CSFML/Window/CursorStruct.hpp>
#include <CSFML/Window/ConvertVideoMode.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/ConvertEvent.hpp>
////////////////////////////////////////////////////////////
sfWindow* sfWindow_create(sfVideoMode mode, const char* title, uint32_t style, sfWindowState state, const sfContextSettings* settings)
{
// Convert video mode
sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
priv::sfContextSettings_writeToCpp(*settings, params);
}
const sf::ContextSettings params = settings ? convertContextSettings(*settings) : sf::ContextSettings();
// Create the window
sfWindow* window = new sfWindow;
window->This.create(videoMode, title, style, static_cast<sf::State>(state), params);
window->This.create(convertVideoMode(mode), title, style, static_cast<sf::State>(state), params);
return window;
}
@@ -56,19 +51,12 @@ sfWindow* sfWindow_create(sfVideoMode mode, const char* title, uint32_t style, s
////////////////////////////////////////////////////////////
sfWindow* sfWindow_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style, sfWindowState state, const sfContextSettings* settings)
{
// Convert video mode
sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel);
// Convert context settings
sf::ContextSettings params;
if (settings)
{
priv::sfContextSettings_writeToCpp(*settings, params);
}
const sf::ContextSettings params = settings ? convertContextSettings(*settings) : sf::ContextSettings();
// Create the window
sfWindow* window = new sfWindow;
window->This.create(videoMode, reinterpret_cast<const char32_t*>(title), style, static_cast<sf::State>(state), params);
window->This.create(convertVideoMode(mode), reinterpret_cast<const char32_t*>(title), style, static_cast<sf::State>(state), params);
return window;
}
@@ -78,11 +66,7 @@ sfWindow* sfWindow_createUnicode(sfVideoMode mode, const sfChar32* title, uint32
sfWindow* sfWindow_createFromHandle(sfWindowHandle handle, const sfContextSettings* settings)
{
// Convert context settings
sf::ContextSettings params;
if (settings)
{
priv::sfContextSettings_writeToCpp(*settings, params);
}
const sf::ContextSettings params = settings ? convertContextSettings(*settings) : sf::ContextSettings();
// Create the window
sfWindow* window = new sfWindow;
@@ -115,13 +99,9 @@ bool sfWindow_isOpen(const sfWindow* window)
////////////////////////////////////////////////////////////
sfContextSettings sfWindow_getSettings(const sfWindow* window)
{
sfContextSettings settings = priv::sfContextSettings_null();
CSFML_CHECK_RETURN(window, settings);
CSFML_CHECK_RETURN(window, sfContextSettings{});
const sf::ContextSettings& params = window->This.getSettings();
priv::sfContextSettings_readFromCpp(params, settings);
return settings;
return convertContextSettings(window->This.getSettings());
}
@@ -171,18 +151,14 @@ sfVector2i sfWindow_getPosition(const sfWindow* window)
sfVector2i position = {0, 0};
CSFML_CHECK_RETURN(window, position);
sf::Vector2i sfmlPos = window->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
return position;
return convertVector2(window->This.getPosition());
}
////////////////////////////////////////////////////////////
void sfWindow_setPosition(sfWindow* window, sfVector2i position)
{
CSFML_CALL(window, setPosition(sf::Vector2i(position.x, position.y)));
CSFML_CALL(window, setPosition(convertVector2(position)));
}
@@ -192,18 +168,14 @@ sfVector2u sfWindow_getSize(const sfWindow* window)
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(window, size);
sf::Vector2u sfmlSize = window->This.getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(window->This.getSize());
}
////////////////////////////////////////////////////////////
void sfWindow_setSize(sfWindow* window, sfVector2u size)
{
CSFML_CALL(window, setSize(sf::Vector2u(size.x, size.y)));
CSFML_CALL(window, setSize(convertVector2(size)));
}
+8 -20
View File
@@ -29,19 +29,18 @@
#include <CSFML/Window/WindowBaseStruct.hpp>
#include <CSFML/Internal.hpp>
#include <CSFML/Window/CursorStruct.hpp>
#include <CSFML/Window/ConvertVideoMode.hpp>
#include <SFML/Window/VideoMode.hpp>
#include <CSFML/System/ConvertVector2.hpp>
#include <CSFML/ConvertEvent.hpp>
////////////////////////////////////////////////////////////
sfWindowBase* sfWindowBase_create(sfVideoMode mode, const char* title, uint32_t style)
{
// Convert video mode
sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel);
// Create the window
sfWindowBase* windowBase = new sfWindowBase;
windowBase->This.create(videoMode, title, style);
windowBase->This.create(convertVideoMode(mode), title, style);
return windowBase;
}
@@ -50,12 +49,9 @@ sfWindowBase* sfWindowBase_create(sfVideoMode mode, const char* title, uint32_t
////////////////////////////////////////////////////////////
sfWindowBase* sfWindowBase_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style)
{
// Convert video mode
sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel);
// Create the window
sfWindowBase* windowBase = new sfWindowBase;
windowBase->This.create(videoMode, reinterpret_cast<const char32_t*>(title), style);
windowBase->This.create(convertVideoMode(mode), reinterpret_cast<const char32_t*>(title), style);
return windowBase;
}
@@ -139,18 +135,14 @@ sfVector2i sfWindowBase_getPosition(const sfWindowBase* windowBase)
sfVector2i position = {0, 0};
CSFML_CHECK_RETURN(windowBase, position);
sf::Vector2i sfmlPos = windowBase->This.getPosition();
position.x = sfmlPos.x;
position.y = sfmlPos.y;
return position;
return convertVector2(windowBase->This.getPosition());
}
////////////////////////////////////////////////////////////
void sfWindowBase_setPosition(sfWindowBase* windowBase, sfVector2i position)
{
CSFML_CALL(windowBase, setPosition(sf::Vector2i(position.x, position.y)));
CSFML_CALL(windowBase, setPosition(convertVector2(position)));
}
@@ -160,18 +152,14 @@ sfVector2u sfWindowBase_getSize(const sfWindowBase* windowBase)
sfVector2u size = {0, 0};
CSFML_CHECK_RETURN(windowBase, size);
sf::Vector2u sfmlSize = windowBase->This.getSize();
size.x = sfmlSize.x;
size.y = sfmlSize.y;
return size;
return convertVector2(windowBase->This.getSize());
}
////////////////////////////////////////////////////////////
void sfWindowBase_setSize(sfWindowBase* windowBase, sfVector2u size)
{
CSFML_CALL(windowBase, setSize(sf::Vector2u(size.x, size.y)));
CSFML_CALL(windowBase, setSize(convertVector2(size)));
}