Update to latest SFML 3 API

This commit is contained in:
Chris Thrasher committed 2024-08-09 13:22:43 -06:00
1 parent a9c35c8e85
commit b778f44681
34 files changed
+319 -382

No files matched your search

+2 -2
View File
@@ -40,13 +40,13 @@ jobs:
- name: Install Linux Dependencies
if: runner.os == 'Linux'
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
run: sudo apt-get update && sudo apt-get install libxrandr-dev libxcursor-dev libxi-dev libudev-dev libflac-dev libvorbis-dev libgl1-mesa-dev libegl1-mesa-dev
- name: Checkout SFML
uses: actions/checkout@v4
with:
repository: SFML/SFML
ref: b583eaf1606e54e5f443b094b3b2a6e3af72a5a4
ref: 8096ba24fccb6b76a7d9e8cc71a3afb7b02e517c
path: SFML
- name: Configure SFML CMake
+3 -3
View File
@@ -110,14 +110,14 @@ CSFML_AUDIO_API void sfMusic_destroy(sfMusic* music);
///
/// If set, the music will restart from beginning after
/// reaching the end and so on, until it is stopped or
/// sfMusic_setLoop(music, false) is called.
/// sfMusic_setLooping(music, false) is called.
/// The default looping state for musics is false.
///
/// \param music Music object
/// \param loop true to play in loop, false to play once
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API void sfMusic_setLoop(sfMusic* music, bool loop);
CSFML_AUDIO_API void sfMusic_setLooping(sfMusic* music, bool loop);
////////////////////////////////////////////////////////////
/// \brief Tell whether or not a music is in loop mode
@@ -127,7 +127,7 @@ CSFML_AUDIO_API void sfMusic_setLoop(sfMusic* music, bool loop);
/// \return true if the music is looping, false otherwise
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API bool sfMusic_getLoop(const sfMusic* music);
CSFML_AUDIO_API bool sfMusic_isLooping(const sfMusic* music);
////////////////////////////////////////////////////////////
/// \brief Get the total duration of a music
+3 -3
View File
@@ -128,14 +128,14 @@ CSFML_AUDIO_API const sfSoundBuffer* sfSound_getBuffer(const sfSound* sound);
///
/// If set, the sound will restart from beginning after
/// reaching the end and so on, until it is stopped or
/// sfSound_setLoop(sound, false) is called.
/// sfSound_setLooping(sound, false) is called.
/// The default looping state for sounds is false.
///
/// \param sound Sound object
/// \param loop true to play in loop, false to play once
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API void sfSound_setLoop(sfSound* sound, bool loop);
CSFML_AUDIO_API void sfSound_setLooping(sfSound* sound, bool loop);
////////////////////////////////////////////////////////////
/// \brief Tell whether or not a sound is in loop mode
@@ -145,7 +145,7 @@ CSFML_AUDIO_API void sfSound_setLoop(sfSound* sound, bool loop);
/// \return true if the sound is looping, false otherwise
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API bool sfSound_getLoop(const sfSound* sound);
CSFML_AUDIO_API bool sfSound_isLooping(const sfSound* sound);
////////////////////////////////////////////////////////////
/// \brief Get the current status of a sound (stopped, paused, playing)
+3 -3
View File
@@ -259,14 +259,14 @@ CSFML_AUDIO_API void sfSoundStream_setPlayingOffset(sfSoundStream* soundStream,
///
/// If set, the stream will restart from beginning after
/// reaching the end and so on, until it is stopped or
/// sfSoundStream_setLoop(stream, false) is called.
/// sfSoundStream_setLooping(stream, false) is called.
/// The default looping state for sound streams is false.
///
/// \param soundStream Sound stream object
/// \param loop true to play in loop, false to play once
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API void sfSoundStream_setLoop(sfSoundStream* soundStream, bool loop);
CSFML_AUDIO_API void sfSoundStream_setLooping(sfSoundStream* soundStream, bool loop);
////////////////////////////////////////////////////////////
/// \brief Get the pitch of a sound stream
@@ -337,7 +337,7 @@ CSFML_AUDIO_API float sfSoundStream_getAttenuation(const sfSoundStream* soundStr
/// \return true if the music is looping, false otherwise
///
////////////////////////////////////////////////////////////
CSFML_AUDIO_API bool sfSoundStream_getLoop(const sfSoundStream* soundStream);
CSFML_AUDIO_API bool sfSoundStream_isLooping(const sfSoundStream* soundStream);
////////////////////////////////////////////////////////////
/// \brief Get the current playing position of a sound stream
+4 -30
View File
@@ -39,18 +39,14 @@
////////////////////////////////////////////////////////////
typedef struct
{
float left;
float top;
float width;
float height;
sfVector2f position;
sfVector2f size;
} sfFloatRect;
typedef struct
{
int left;
int top;
int width;
int height;
sfVector2i position;
sfVector2i size;
} sfIntRect;
////////////////////////////////////////////////////////////
@@ -79,27 +75,5 @@ CSFML_GRAPHICS_API bool sfIntRect_contains(const sfIntRect* rect, int x, int y);
CSFML_GRAPHICS_API bool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2, sfFloatRect* intersection);
CSFML_GRAPHICS_API bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection);
////////////////////////////////////////////////////////////
/// \brief Get the position of the rectangle's top-left corner
///
/// \return Position of rectangle
///
/// \see getSize
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfVector2f sfFloatRect_getPosition(const sfFloatRect* rect);
CSFML_GRAPHICS_API sfVector2i sfIntRect_getPosition(const sfIntRect* rect);
////////////////////////////////////////////////////////////
/// \brief Get the size of the rectangle
///
/// \return Size of rectangle
///
/// \see getPosition
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API sfVector2f sfFloatRect_getSize(const sfFloatRect* rect);
CSFML_GRAPHICS_API sfVector2i sfIntRect_getSize(const sfIntRect* rect);
#endif // SFML_RECT_H
-11
View File
@@ -117,17 +117,6 @@ CSFML_GRAPHICS_API void sfView_setRotation(sfView* view, float angle);
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfView_setViewport(sfView* view, sfFloatRect viewport);
////////////////////////////////////////////////////////////
/// \brief Reset a view to the given rectangle
///
/// Note that this function resets the rotation angle to 0.
///
/// \param view View object
/// \param rectangle Rectangle defining the zone to display
///
////////////////////////////////////////////////////////////
CSFML_GRAPHICS_API void sfView_reset(sfView* view, sfFloatRect rectangle);
////////////////////////////////////////////////////////////
/// \brief Get the center of a view
///
+3 -2
View File
@@ -29,10 +29,11 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/System/Export.h>
#include <stdlib.h>
typedef int64_t (*sfInputStreamReadFunc)(void* data, int64_t size, void* userData);
typedef int64_t (*sfInputStreamSeekFunc)(int64_t position, void* userData);
typedef int64_t (*sfInputStreamReadFunc)(void* data, size_t size, void* userData);
typedef int64_t (*sfInputStreamSeekFunc)(size_t position, void* userData);
typedef int64_t (*sfInputStreamTellFunc)(void* userData);
typedef int64_t (*sfInputStreamGetSizeFunc)(void* userData);
+4 -4
View File
@@ -83,16 +83,16 @@ void sfMusic_destroy(sfMusic* music)
////////////////////////////////////////////////////////////
void sfMusic_setLoop(sfMusic* music, bool loop)
void sfMusic_setLooping(sfMusic* music, bool loop)
{
CSFML_CALL(music, setLoop(loop != 0));
CSFML_CALL(music, setLooping(loop != 0));
}
////////////////////////////////////////////////////////////
bool sfMusic_getLoop(const sfMusic* music)
bool sfMusic_isLooping(const sfMusic* music)
{
CSFML_CALL_RETURN(music, getLoop(), false);
CSFML_CALL_RETURN(music, isLooping(), false);
}
+4 -4
View File
@@ -97,16 +97,16 @@ const sfSoundBuffer* sfSound_getBuffer(const sfSound* sound)
////////////////////////////////////////////////////////////
void sfSound_setLoop(sfSound* sound, bool loop)
void sfSound_setLooping(sfSound* sound, bool loop)
{
CSFML_CALL(sound, setLoop(loop));
CSFML_CALL(sound, setLooping(loop));
}
////////////////////////////////////////////////////////////
bool sfSound_getLoop(const sfSound* sound)
bool sfSound_isLooping(const sfSound* sound)
{
CSFML_CALL_RETURN(sound, getLoop(), false);
CSFML_CALL_RETURN(sound, isLooping(), false);
}
+12 -12
View File
@@ -34,22 +34,22 @@
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromFile(const char* filename)
{
auto soundBuffer = sf::SoundBuffer::loadFromFile(filename);
if (!soundBuffer)
sf::SoundBuffer soundBuffer;
if (!soundBuffer.loadFromFile(filename))
return nullptr;
return new sfSoundBuffer{std::move(*soundBuffer)};
return new sfSoundBuffer{std::move(soundBuffer)};
}
////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromMemory(const void* data, size_t sizeInBytes)
{
auto soundBuffer = sf::SoundBuffer::loadFromMemory(data, sizeInBytes);
if (!soundBuffer)
sf::SoundBuffer soundBuffer;
if (!soundBuffer.loadFromMemory(data, sizeInBytes))
return nullptr;
return new sfSoundBuffer{std::move(*soundBuffer)};
return new sfSoundBuffer{std::move(soundBuffer)};
}
@@ -60,11 +60,11 @@ sfSoundBuffer* sfSoundBuffer_createFromStream(sfInputStream* stream)
CSFML_CHECK_RETURN(stream, nullptr);
CallbackStream sfmlStream(stream);
auto soundBuffer = sf::SoundBuffer::loadFromStream(sfmlStream);
if (!soundBuffer)
sf::SoundBuffer soundBuffer;
if (!soundBuffer.loadFromStream(sfmlStream))
return nullptr;
return new sfSoundBuffer{std::move(*soundBuffer)};
return new sfSoundBuffer{std::move(soundBuffer)};
}
@@ -80,11 +80,11 @@ sfSoundBuffer* sfSoundBuffer_createFromSamples(const int16_t* samples,
for (std::size_t i = 0; i < channelMap.size(); ++i)
channelMap[i] = static_cast<sf::SoundChannel>(channelMapData[i]);
auto soundBuffer = sf::SoundBuffer::loadFromSamples(samples, sampleCount, channelCount, sampleRate, channelMap);
if (!soundBuffer)
sf::SoundBuffer soundBuffer;
if (!soundBuffer.loadFromSamples(samples, sampleCount, channelCount, sampleRate, channelMap))
return nullptr;
return new sfSoundBuffer{std::move(*soundBuffer)};
return new sfSoundBuffer{std::move(soundBuffer)};
}
+2 -2
View File
@@ -70,9 +70,9 @@ const sfSoundBuffer* sfSoundBufferRecorder_getBuffer(const sfSoundBufferRecorder
{
CSFML_CHECK_RETURN(soundBufferRecorder, nullptr);
soundBufferRecorder->SoundBuffer = sfSoundBuffer{soundBufferRecorder->This.getBuffer()};
soundBufferRecorder->SoundBuffer.This = soundBufferRecorder->This.getBuffer();
return &*soundBufferRecorder->SoundBuffer;
return &soundBufferRecorder->SoundBuffer;
}
////////////////////////////////////////////////////////////
+3 -5
View File
@@ -31,17 +31,15 @@
#include <SFML/Audio/SoundBufferRecorder.hpp>
#include <SFML/Audio/SoundBufferStruct.h>
#include <optional>
////////////////////////////////////////////////////////////
// Internal structure of sfSoundBufferRecorder
////////////////////////////////////////////////////////////
struct sfSoundBufferRecorder
{
sf::SoundBufferRecorder This;
mutable std::optional<sfSoundBuffer> SoundBuffer;
std::string DeviceName;
sf::SoundBufferRecorder This;
mutable sfSoundBuffer SoundBuffer;
std::string DeviceName;
};
+4 -4
View File
@@ -144,9 +144,9 @@ void sfSoundStream_setPlayingOffset(sfSoundStream* soundStream, sfTime timeOffse
////////////////////////////////////////////////////////////
void sfSoundStream_setLoop(sfSoundStream* soundStream, bool loop)
void sfSoundStream_setLooping(sfSoundStream* soundStream, bool loop)
{
CSFML_CALL(soundStream, setLoop(loop));
CSFML_CALL(soundStream, setLooping(loop));
}
@@ -201,9 +201,9 @@ float sfSoundStream_getAttenuation(const sfSoundStream* soundStream)
////////////////////////////////////////////////////////////
bool sfSoundStream_getLoop(const sfSoundStream* soundStream)
bool sfSoundStream_isLooping(const sfSoundStream* soundStream)
{
CSFML_CALL_RETURN(soundStream, getLoop(), false);
CSFML_CALL_RETURN(soundStream, isLooping(), false);
}
+39 -11
View File
@@ -63,12 +63,19 @@ public:
/// \param data Buffer where to copy the read data
/// \param size Desired number of bytes to read
///
/// \return The number of bytes actually read
/// \return The number of bytes actually read, or `std::nullopt` on error
///
////////////////////////////////////////////////////////////
std::int64_t read(void* data, std::int64_t size) override
std::optional<std::size_t> read(void* data, std::size_t size) override
{
return myStream.read ? myStream.read(data, size, myStream.userData) : -1;
if (!myStream.read)
return std::nullopt;
const auto bytesRead = myStream.read(data, size, myStream.userData);
if (bytesRead != -1)
return static_cast<std::size_t>(bytesRead);
return std::nullopt;
}
////////////////////////////////////////////////////////////
@@ -76,23 +83,37 @@ public:
///
/// \param position The position to seek to, from the beginning
///
/// \return The position actually seeked to, or -1 on error
/// \return The position actually seeked to, or `std::nullopt` on error
///
////////////////////////////////////////////////////////////
std::int64_t seek(std::int64_t position) override
std::optional<std::size_t> seek(std::size_t position) override
{
return myStream.seek ? myStream.seek(position, myStream.userData) : -1;
if (!myStream.seek)
return std::nullopt;
const auto actualPosition = myStream.seek(position, myStream.userData);
if (actualPosition != -1)
return static_cast<std::size_t>(actualPosition);
return std::nullopt;
}
////////////////////////////////////////////////////////////
/// \brief Return the current reading position in the stream
///
/// \return The current position, or -1 on error.
/// \return The current position, or `std::nullopt` on error
///
////////////////////////////////////////////////////////////
std::int64_t tell() override
std::optional<std::size_t> tell() override
{
return myStream.tell ? myStream.tell(myStream.userData) : -1;
if (!myStream.tell)
return std::nullopt;
const auto position = myStream.tell(myStream.userData);
if (position != -1)
return static_cast<std::size_t>(position);
return std::nullopt;
}
////////////////////////////////////////////////////////////
@@ -101,9 +122,16 @@ public:
/// \return The total number of bytes available in the stream, or -1 on error
///
////////////////////////////////////////////////////////////
std::int64_t getSize() override
std::optional<std::size_t> getSize() override
{
return myStream.getSize ? myStream.getSize(myStream.userData) : -1;
if (!myStream.getSize)
return std::nullopt;
const auto bytesAvailable = myStream.getSize(myStream.userData);
if (bytesAvailable != -1)
return static_cast<std::size_t>(bytesAvailable);
return std::nullopt;
}
private:
+16 -16
View File
@@ -187,7 +187,7 @@ void sfCircleShape_setTexture(sfCircleShape* shape, const sfTexture* texture, bo
////////////////////////////////////////////////////////////
void sfCircleShape_setTextureRect(sfCircleShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.left, rect.top }, { rect.width, rect.height })));
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
}
@@ -224,14 +224,14 @@ const sfTexture* sfCircleShape_getTexture(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfIntRect sfCircleShape_getTextureRect(const sfCircleShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -321,14 +321,14 @@ void sfCircleShape_setPointCount(sfCircleShape* shape, size_t count)
////////////////////////////////////////////////////////////
sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -337,14 +337,14 @@ sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfCircleShape_getGlobalBounds(const sfCircleShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+16 -16
View File
@@ -184,7 +184,7 @@ void sfConvexShape_setTexture(sfConvexShape* shape, const sfTexture* texture, bo
////////////////////////////////////////////////////////////
void sfConvexShape_setTextureRect(sfConvexShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.left, rect.top }, { rect.width, rect.height })));
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
}
@@ -221,14 +221,14 @@ const sfTexture* sfConvexShape_getTexture(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfIntRect sfConvexShape_getTextureRect(const sfConvexShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -311,14 +311,14 @@ void sfConvexShape_setPoint(sfConvexShape* shape, size_t index, sfVector2f point
////////////////////////////////////////////////////////////
sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -327,14 +327,14 @@ sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfConvexShape_getGlobalBounds(const sfConvexShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+24 -21
View File
@@ -34,22 +34,22 @@
////////////////////////////////////////////////////////////
sfFont* sfFont_createFromFile(const char* filename)
{
auto font = sf::Font::loadFromFile(filename);
if (!font)
sf::Font font;
if (!font.openFromFile(filename))
return nullptr;
return new sfFont{std::move(*font), {}, {}};
return new sfFont{std::move(font), {}, {}};
}
////////////////////////////////////////////////////////////
sfFont* sfFont_createFromMemory(const void* data, size_t sizeInBytes)
{
auto font = sf::Font::loadFromMemory(data, sizeInBytes);
if (!font)
sf::Font font;
if (!font.openFromMemory(data, sizeInBytes))
return nullptr;
return new sfFont{std::move(*font), {}, {}};
return new sfFont{std::move(font), {}, {}};
}
@@ -58,12 +58,15 @@ sfFont* sfFont_createFromStream(sfInputStream* stream)
{
CSFML_CHECK_RETURN(stream, nullptr);
auto sfmlStream = std::make_shared<CallbackStream>(stream);
auto font = sf::Font::loadFromStream(*sfmlStream);
if (!font)
return nullptr;
sfFont* font = new sfFont;
font->Stream = CallbackStream(stream);
if (!font->This.openFromStream(font->Stream))
{
delete font;
font = nullptr;
}
return new sfFont{std::move(*font), {}, std::move(sfmlStream)};
return font;
}
@@ -86,20 +89,20 @@ void sfFont_destroy(sfFont* font)
////////////////////////////////////////////////////////////
sfGlyph sfFont_getGlyph(const sfFont* font, uint32_t codePoint, unsigned int characterSize, bool bold, float outlineThickness)
{
sfGlyph glyph = {0, {0, 0, 0, 0}, {0, 0, 0, 0}};
sfGlyph glyph = {0, {{0, 0}, {0, 0}}, {{0, 0}, {0, 0}}};
CSFML_CHECK_RETURN(font, glyph);
sf::Glyph SFMLGlyph = font->This.getGlyph(codePoint, characterSize, bold, outlineThickness);
glyph.advance = SFMLGlyph.advance;
glyph.bounds.left = SFMLGlyph.bounds.left;
glyph.bounds.top = SFMLGlyph.bounds.top;
glyph.bounds.width = SFMLGlyph.bounds.width;
glyph.bounds.height = SFMLGlyph.bounds.height;
glyph.textureRect.left = SFMLGlyph.textureRect.left;
glyph.textureRect.top = SFMLGlyph.textureRect.top;
glyph.textureRect.width = SFMLGlyph.textureRect.width;
glyph.textureRect.height = SFMLGlyph.textureRect.height;
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;
return glyph;
}
+1 -2
View File
@@ -32,7 +32,6 @@
#include <SFML/Graphics/TextureStruct.h>
#include <SFML/CallbackStream.h>
#include <map>
#include <memory>
////////////////////////////////////////////////////////////
@@ -42,7 +41,7 @@ struct sfFont
{
sf::Font This;
std::map<unsigned int, sfTexture> Textures;
std::shared_ptr<CallbackStream> Stream;
CallbackStream Stream;
};
+11 -11
View File
@@ -35,7 +35,7 @@
////////////////////////////////////////////////////////////
sfImage* sfImage_create(unsigned int width, unsigned int height)
{
return new sfImage{sf::Image({width, height})};
return new sfImage{sf::Image(sf::Vector2u(width, height))};
}
@@ -56,22 +56,22 @@ sfImage* sfImage_createFromPixels(unsigned int width, unsigned int height, const
////////////////////////////////////////////////////////////
sfImage* sfImage_createFromFile(const char* filename)
{
auto image = sf::Image::loadFromFile(filename);
if (!image)
sf::Image image;
if (!image.loadFromFile(filename))
return nullptr;
return new sfImage{std::move(*image)};
return new sfImage{std::move(image)};
}
////////////////////////////////////////////////////////////
sfImage* sfImage_createFromMemory(const void* data, size_t sizeInBytes)
{
auto image = sf::Image::loadFromMemory(data, sizeInBytes);
if (!image)
sf::Image image;
if (!image.loadFromMemory(data, sizeInBytes))
return nullptr;
return new sfImage{std::move(*image)};
return new sfImage{std::move(image)};
}
@@ -81,11 +81,11 @@ sfImage* sfImage_createFromStream(sfInputStream* stream)
CSFML_CHECK_RETURN(stream, nullptr);
CallbackStream sfmlStream(stream);
auto image = sf::Image::loadFromStream(sfmlStream);
if (!image)
sf::Image image;
if (!image.loadFromStream(sfmlStream))
return nullptr;
return new sfImage{std::move(*image)};
return new sfImage{std::move(image)};
}
@@ -143,7 +143,7 @@ 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.left, sourceRect.top }, { sourceRect.width, sourceRect.height });
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);
}
+14 -55
View File
@@ -30,33 +30,18 @@
#include <SFML/Internal.h>
namespace
{
sfVector2f toCType(const sf::Vector2f& vector)
{
sfVector2f vec = {vector.x, vector.y};
return vec;
}
sfVector2i toCType(const sf::Vector2i& vector)
{
sfVector2i vec = {vector.x, vector.y};
return vec;
}
}
////////////////////////////////////////////////////////////
/// Check if a point is inside a rectangle's area
////////////////////////////////////////////////////////////
bool sfFloatRect_contains(const sfFloatRect* rect, float x, float y)
{
CSFML_CHECK_RETURN(rect, false);
return sf::FloatRect({ rect->left, rect->top }, { rect->width, rect->height }).contains({ x, y });
return sf::FloatRect({ rect->position.x, rect->position.y }, { rect->size.x, rect->size.y }).contains({ x, y });
}
bool sfIntRect_contains(const sfIntRect* rect, int x, int y)
{
CSFML_CHECK_RETURN(rect, false);
return sf::IntRect({ rect->left, rect->top }, { rect->width, rect->height }).contains({ x, y });
return sf::IntRect({ rect->position.x, rect->position.y }, { rect->size.x, rect->size.y }).contains({ x, y });
}
@@ -68,8 +53,8 @@ bool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2,
CSFML_CHECK_RETURN(rect1, false);
CSFML_CHECK_RETURN(rect2, false);
sf::FloatRect SFMLRect1({ rect1->left, rect1->top }, { rect1->width, rect1->height });
sf::FloatRect SFMLRect2({ rect2->left, rect2->top }, { rect2->width, rect2->height });
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 });
if (intersection)
{
@@ -77,10 +62,10 @@ bool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2,
if (overlap)
{
intersection->left = overlap->left;
intersection->top = overlap->top;
intersection->width = overlap->width;
intersection->height = overlap->height;
intersection->position.x = overlap->position.x;
intersection->position.y = overlap->position.y;
intersection->size.x = overlap->size.x;
intersection->size.y = overlap->size.y;
}
return overlap.has_value();
@@ -95,8 +80,8 @@ bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntR
CSFML_CHECK_RETURN(rect1, false);
CSFML_CHECK_RETURN(rect2, false);
sf::IntRect SFMLRect1({ rect1->left, rect1->top }, { rect1->width, rect1->height });
sf::IntRect SFMLRect2({ rect2->left, rect2->top }, { rect2->width, rect2->height });
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 });
if (intersection)
{
@@ -104,10 +89,10 @@ bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntR
if (overlap)
{
intersection->left = overlap->left;
intersection->top = overlap->top;
intersection->width = overlap->width;
intersection->height = overlap->height;
intersection->position.x = overlap->position.x;
intersection->position.y = overlap->position.y;
intersection->size.x = overlap->size.x;
intersection->size.y = overlap->size.y;
}
return overlap.has_value();
@@ -117,29 +102,3 @@ bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntR
return SFMLRect1.findIntersection(SFMLRect2).has_value();
}
}
////////////////////////////////////////////////////////////
/// Get the position of the rectangle's top-left corner
////////////////////////////////////////////////////////////
sfVector2f sfFloatRect_getPosition(const sfFloatRect* rect)
{
return toCType(sf::FloatRect({ rect->left, rect->top }, { rect->width, rect->height }).getPosition());
}
sfVector2i sfIntRect_getPosition(const sfIntRect* rect)
{
return toCType(sf::IntRect({ rect->left, rect->top }, { rect->width, rect->height }).getPosition());
}
////////////////////////////////////////////////////////////
/// Get the size of the rectangle
////////////////////////////////////////////////////////////
sfVector2f sfFloatRect_getSize(const sfFloatRect* rect)
{
return toCType(sf::FloatRect({ rect->left, rect->top }, { rect->width, rect->height }).getSize());
}
sfVector2i sfIntRect_getSize(const sfIntRect* rect)
{
return toCType(sf::IntRect({ rect->left, rect->top }, { rect->width, rect->height }).getSize());
}
+16 -16
View File
@@ -184,7 +184,7 @@ void sfRectangleShape_setTexture(sfRectangleShape* shape, const sfTexture* textu
////////////////////////////////////////////////////////////
void sfRectangleShape_setTextureRect(sfRectangleShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.left, rect.top }, { rect.width, rect.height })));
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
}
@@ -221,14 +221,14 @@ const sfTexture* sfRectangleShape_getTexture(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfIntRect sfRectangleShape_getTextureRect(const sfRectangleShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -318,14 +318,14 @@ sfVector2f sfRectangleShape_getSize(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfRectangleShape_getLocalBounds(const sfRectangleShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -334,14 +334,14 @@ sfFloatRect sfRectangleShape_getLocalBounds(const sfRectangleShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfRectangleShape_getGlobalBounds(const sfRectangleShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+12 -11
View File
@@ -51,14 +51,15 @@ sfRenderTexture* sfRenderTexture_create(unsigned int width, unsigned int height,
}
// Create the render texture
auto renderTexture = sf::RenderTexture::create({ width, height }, params);
if (!renderTexture)
sf::RenderTexture renderTexture;
if (!renderTexture.resize({ width, height }, params))
return nullptr;
return new sfRenderTexture{std::move(*renderTexture),
new sfTexture(const_cast<sf::Texture*>(&renderTexture->getTexture())),
{renderTexture->getDefaultView()},
{renderTexture->getView()}};
auto* texture = new sfTexture(const_cast<sf::Texture*>(&renderTexture.getTexture()));
const auto defaultView = sfView{renderTexture.getDefaultView()};
const auto currentView = sfView{renderTexture.getView()};
return new sfRenderTexture{std::move(renderTexture), texture, defaultView, currentView};
}
@@ -145,15 +146,15 @@ const sfView* sfRenderTexture_getDefaultView(const sfRenderTexture* renderTextur
////////////////////////////////////////////////////////////
sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderTexture, rect);
sf::IntRect SFMLrect = renderTexture->This.getViewport(view->This);
rect.left = SFMLrect.left;
rect.top = SFMLrect.top;
rect.width = SFMLrect.width;
rect.height = SFMLrect.height;
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;
}
+9 -9
View File
@@ -150,14 +150,14 @@ bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
const sf::Event sfmlEvent = renderWindow->This.pollEvent();
const std::optional sfmlEvent = renderWindow->This.pollEvent();
// No event, return
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event);
convertEvent(*sfmlEvent, event);
return true;
}
@@ -170,14 +170,14 @@ bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
const sf::Event sfmlEvent = renderWindow->This.waitEvent();
const std::optional sfmlEvent = renderWindow->This.waitEvent();
// Error, return
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event);
convertEvent(*sfmlEvent, event);
return true;
}
@@ -388,15 +388,15 @@ const sfView* sfRenderWindow_getDefaultView(const sfRenderWindow* renderWindow)
////////////////////////////////////////////////////////////
sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const sfView* view)
{
sfIntRect rect = {0, 0, 0, 0};
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(view, rect);
CSFML_CHECK_RETURN(renderWindow, rect);
sf::IntRect SFMLrect = renderWindow->This.getViewport(view->This);
rect.left = SFMLrect.left;
rect.top = SFMLrect.top;
rect.width = SFMLrect.width;
rect.height = SFMLrect.height;
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;
}
+27 -24
View File
@@ -36,7 +36,8 @@
////////////////////////////////////////////////////////////
sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* geometryShaderFilename, const char* fragmentShaderFilename)
{
std::optional<sf::Shader> shader;
bool success = false;
sf::Shader shader;
if (vertexShaderFilename || geometryShaderFilename || fragmentShaderFilename)
{
if (!geometryShaderFilename)
@@ -44,17 +45,17 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char*
if (!vertexShaderFilename)
{
// fragment shader only
shader = sf::Shader::loadFromFile(fragmentShaderFilename, sf::Shader::Type::Fragment);
success = shader.loadFromFile(fragmentShaderFilename, sf::Shader::Type::Fragment);
}
else if (!fragmentShaderFilename)
{
// vertex shader only
shader = sf::Shader::loadFromFile(vertexShaderFilename, sf::Shader::Type::Vertex);
success = shader.loadFromFile(vertexShaderFilename, sf::Shader::Type::Vertex);
}
else
{
// vertex + fragment shaders
shader = sf::Shader::loadFromFile(vertexShaderFilename, fragmentShaderFilename);
success = shader.loadFromFile(vertexShaderFilename, fragmentShaderFilename);
}
}
else
@@ -62,27 +63,28 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char*
if (!vertexShaderFilename && !fragmentShaderFilename)
{
// geometry shader only
shader = sf::Shader::loadFromFile(geometryShaderFilename, sf::Shader::Type::Geometry);
success = shader.loadFromFile(geometryShaderFilename, sf::Shader::Type::Geometry);
}
else
{
// vertex + geometry + fragment shaders
shader = sf::Shader::loadFromFile(vertexShaderFilename, geometryShaderFilename, fragmentShaderFilename);
success = shader.loadFromFile(vertexShaderFilename, geometryShaderFilename, fragmentShaderFilename);
}
}
}
if (!shader)
if (!success)
return nullptr;
return new sfShader{std::move(*shader)};
return new sfShader{std::move(shader)};
}
////////////////////////////////////////////////////////////
sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geometryShader, const char* fragmentShader)
{
std::optional<sf::Shader> shader;
bool success = false;
sf::Shader shader;
if (vertexShader || geometryShader || fragmentShader)
{
if (!geometryShader)
@@ -90,17 +92,17 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geomet
if (!vertexShader)
{
// fragment shader only
shader = sf::Shader::loadFromMemory(fragmentShader, sf::Shader::Type::Fragment);
success = shader.loadFromMemory(fragmentShader, sf::Shader::Type::Fragment);
}
else if (!fragmentShader)
{
// vertex shader only
shader = sf::Shader::loadFromMemory(vertexShader, sf::Shader::Type::Vertex);
success = shader.loadFromMemory(vertexShader, sf::Shader::Type::Vertex);
}
else
{
// vertex + fragment shaders
shader = sf::Shader::loadFromMemory(vertexShader, fragmentShader);
success = shader.loadFromMemory(vertexShader, fragmentShader);
}
}
else
@@ -108,27 +110,28 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geomet
if (!vertexShader && !fragmentShader)
{
// geometry shader only
shader = sf::Shader::loadFromMemory(geometryShader, sf::Shader::Type::Geometry);
success = shader.loadFromMemory(geometryShader, sf::Shader::Type::Geometry);
}
else
{
// vertex + geometry + fragment shaders
shader = sf::Shader::loadFromMemory(vertexShader, geometryShader, fragmentShader);
success = shader.loadFromMemory(vertexShader, geometryShader, fragmentShader);
}
}
}
if (!shader)
if (!success)
return nullptr;
return new sfShader{std::move(*shader)};
return new sfShader{std::move(shader)};
}
////////////////////////////////////////////////////////////
sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* geometryShaderStream, sfInputStream* fragmentShaderStream)
{
std::optional<sf::Shader> shader;
bool success = false;
sf::Shader shader;
if (vertexShaderStream || geometryShaderStream || fragmentShaderStream)
{
if (!geometryShaderStream)
@@ -137,20 +140,20 @@ sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputSt
{
// fragment shader only
CallbackStream stream(fragmentShaderStream);
shader = sf::Shader::loadFromStream(stream, sf::Shader::Type::Fragment);
success = shader.loadFromStream(stream, sf::Shader::Type::Fragment);
}
else if (!fragmentShaderStream)
{
// vertex shader only
CallbackStream stream(vertexShaderStream);
shader = sf::Shader::loadFromStream(stream, sf::Shader::Type::Vertex);
success = shader.loadFromStream(stream, sf::Shader::Type::Vertex);
}
else
{
// vertex + fragment shaders
CallbackStream vertexStream(vertexShaderStream);
CallbackStream fragmentStream(fragmentShaderStream);
shader = sf::Shader::loadFromStream(vertexStream, fragmentStream);
success = shader.loadFromStream(vertexStream, fragmentStream);
}
}
else
@@ -159,22 +162,22 @@ sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputSt
if (!vertexShaderStream && !fragmentShaderStream)
{
// geometry shader only
shader = sf::Shader::loadFromStream(geometryStream, sf::Shader::Type::Geometry);
success = shader.loadFromStream(geometryStream, sf::Shader::Type::Geometry);
}
else
{
// vertex + geometry + fragment shaders
CallbackStream vertexStream(vertexShaderStream);
CallbackStream fragmentStream(fragmentShaderStream);
shader = sf::Shader::loadFromStream(vertexStream, geometryStream, fragmentStream);
success = shader.loadFromStream(vertexStream, geometryStream, fragmentStream);
}
}
}
if (!shader)
if (!success)
return nullptr;
return new sfShader{std::move(*shader)};
return new sfShader{std::move(shader)};
}
+16 -16
View File
@@ -177,7 +177,7 @@ void sfShape_setTexture(sfShape* shape, const sfTexture* texture, bool resetRect
////////////////////////////////////////////////////////////
void sfShape_setTextureRect(sfShape* shape, sfIntRect rect)
{
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.left, rect.top }, { rect.width, rect.height })));
CSFML_CALL(shape, setTextureRect(sf::IntRect({ rect.position.x, rect.position.y }, { rect.size.x, rect.size.y })));
}
@@ -214,14 +214,14 @@ const sfTexture* sfShape_getTexture(const sfShape* shape)
////////////////////////////////////////////////////////////
sfIntRect sfShape_getTextureRect(const sfShape* shape)
{
sfIntRect rect = {0, 0, 0, 0};
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -290,14 +290,14 @@ sfVector2f sfShape_getPoint(const sfShape* shape, size_t index)
////////////////////////////////////////////////////////////
sfFloatRect sfShape_getLocalBounds(const sfShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -306,14 +306,14 @@ sfFloatRect sfShape_getLocalBounds(const sfShape* shape)
////////////////////////////////////////////////////////////
sfFloatRect sfShape_getGlobalBounds(const sfShape* shape)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+16 -16
View File
@@ -191,7 +191,7 @@ void sfSprite_setTexture(sfSprite* sprite, const sfTexture* texture, bool resetR
////////////////////////////////////////////////////////////
void sfSprite_setTextureRect(sfSprite* sprite, sfIntRect rectangle)
{
CSFML_CALL(sprite, setTextureRect(sf::IntRect({ rectangle.left, rectangle.top }, { rectangle.width, rectangle.height })));
CSFML_CALL(sprite, setTextureRect(sf::IntRect({ rectangle.position.x, rectangle.position.y }, { rectangle.size.x, rectangle.size.y })));
}
@@ -214,14 +214,14 @@ const sfTexture* sfSprite_getTexture(const sfSprite* sprite)
////////////////////////////////////////////////////////////
sfIntRect sfSprite_getTextureRect(const sfSprite* sprite)
{
sfIntRect rect = {0, 0, 0, 0};
sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(sprite, rect);
sf::IntRect sfmlRect = sprite->This.getTextureRect();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -246,14 +246,14 @@ sfColor sfSprite_getColor(const sfSprite* sprite)
////////////////////////////////////////////////////////////
sfFloatRect sfSprite_getLocalBounds(const sfSprite* sprite)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(sprite, rect);
sf::FloatRect sfmlRect = sprite->This.getLocalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -262,14 +262,14 @@ sfFloatRect sfSprite_getLocalBounds(const sfSprite* sprite)
////////////////////////////////////////////////////////////
sfFloatRect sfSprite_getGlobalBounds(const sfSprite* sprite)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(sprite, rect);
sf::FloatRect sfmlRect = sprite->This.getGlobalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+10 -10
View File
@@ -378,14 +378,14 @@ sfVector2f sfText_findCharacterPos(const sfText* text, size_t index)
////////////////////////////////////////////////////////////
sfFloatRect sfText_getLocalBounds(const sfText* text)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(text, rect);
sf::FloatRect sfmlRect = text->This.getLocalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
@@ -394,14 +394,14 @@ sfFloatRect sfText_getLocalBounds(const sfText* text)
////////////////////////////////////////////////////////////
sfFloatRect sfText_getGlobalBounds(const sfText* text)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(text, rect);
sf::FloatRect sfmlRect = text->This.getGlobalBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+17 -25
View File
@@ -39,7 +39,7 @@ sfTexture* sfTexture_create(unsigned int width, unsigned int height)
{
sfTexture* texture = new sfTexture;
if (!texture->This->create({ width, height }))
if (!texture->This->resize({ width, height }))
{
delete texture;
texture = nullptr;
@@ -56,9 +56,9 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
if (!texture->This->loadFromFile(filename, rect))
if (!texture->This->loadFromFile(filename, false, rect))
{
delete texture;
texture = nullptr;
@@ -74,11 +74,9 @@ sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* a
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
texture->This->setSrgb(true);
if (!texture->This->loadFromFile(filename, rect))
if (!texture->This->loadFromFile(filename, true, rect))
{
delete texture;
texture = nullptr;
@@ -94,9 +92,9 @@ sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, cons
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
if (!texture->This->loadFromMemory(data, sizeInBytes, rect))
if (!texture->This->loadFromMemory(data, sizeInBytes, false, rect))
{
delete texture;
texture = nullptr;
@@ -112,11 +110,9 @@ sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes,
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
texture->This->setSrgb(true);
if (!texture->This->loadFromMemory(data, sizeInBytes, rect))
if (!texture->This->loadFromMemory(data, sizeInBytes, true, rect))
{
delete texture;
texture = nullptr;
@@ -135,10 +131,10 @@ sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* ar
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
CallbackStream sfmlStream(stream);
if (!texture->This->loadFromStream(sfmlStream, rect))
if (!texture->This->loadFromStream(sfmlStream, false, rect))
{
delete texture;
texture = nullptr;
@@ -156,12 +152,10 @@ sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
texture->This->setSrgb(true);
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
CallbackStream sfmlStream(stream);
if (!texture->This->loadFromStream(sfmlStream, rect))
if (!texture->This->loadFromStream(sfmlStream, true, rect))
{
delete texture;
texture = nullptr;
@@ -180,9 +174,9 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
if (!texture->This->loadFromImage(image->This, rect))
if (!texture->This->loadFromImage(image->This, false, rect))
{
delete texture;
texture = nullptr;
@@ -200,11 +194,9 @@ sfTexture* sfTexture_createSrgbFromImage(const sfImage* image, const sfIntRect*
sf::IntRect rect;
if (area)
rect = sf::IntRect({ area->left, area->top }, { area->width, area->height });
rect = sf::IntRect({ area->position.x, area->position.y }, { area->size.x, area->size.y });
texture->This->setSrgb(true);
if (!texture->This->loadFromImage(image->This, rect))
if (!texture->This->loadFromImage(image->This, true, rect))
{
delete texture;
texture = nullptr;
+6 -6
View File
@@ -89,15 +89,15 @@ sfVector2f sfTransform_transformPoint(const sfTransform* transform, sfVector2f p
////////////////////////////////////////////////////////////
sfFloatRect sfTransform_transformRect(const sfTransform* transform, sfFloatRect rectangle)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(transform, rect);
sf::FloatRect sfmlRect = convertTransform(*transform).transformRect(sf::FloatRect({ rectangle.left, rectangle.top }, { rectangle.width, rectangle.height }));
sf::FloatRect sfmlRect = convertTransform(*transform).transformRect(sf::FloatRect({ rectangle.position.x, rectangle.position.y }, { rectangle.size.x, rectangle.size.y }));
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+5 -5
View File
@@ -110,14 +110,14 @@ sfPrimitiveType sfVertexArray_getPrimitiveType(sfVertexArray* vertexArray)
////////////////////////////////////////////////////////////
sfFloatRect sfVertexArray_getBounds(sfVertexArray* vertexArray)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(vertexArray, rect);
sf::FloatRect sfmlRect = vertexArray->This.getBounds();
rect.left = sfmlRect.left;
rect.top = sfmlRect.top;
rect.width = sfmlRect.width;
rect.height = sfmlRect.height;
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;
}
+7 -17
View File
@@ -40,10 +40,7 @@ sfView* sfView_create(void)
////////////////////////////////////////////////////////////
sfView* sfView_createFromRect(sfFloatRect rectangle)
{
sfView* view = new sfView;
sfView_reset(view, rectangle);
return view;
return new sfView{sf::View(sf::FloatRect({rectangle.position.x, rectangle.position.y}, {rectangle.size.x, rectangle.size.y}))};
}
@@ -87,14 +84,7 @@ void sfView_setRotation(sfView* view, float angle)
////////////////////////////////////////////////////////////
void sfView_setViewport(sfView* view, sfFloatRect viewport)
{
CSFML_CALL(view, setViewport(sf::FloatRect({ viewport.left, viewport.top }, { viewport.width, viewport.height })));
}
////////////////////////////////////////////////////////////
void sfView_reset(sfView* view, sfFloatRect rectangle)
{
CSFML_CALL(view, reset(sf::FloatRect({ rectangle.left, rectangle.top }, { rectangle.width, rectangle.height })));
CSFML_CALL(view, setViewport(sf::FloatRect({ viewport.position.x, viewport.position.y }, { viewport.size.x, viewport.size.y })));
}
@@ -136,14 +126,14 @@ float sfView_getRotation(const sfView* view)
////////////////////////////////////////////////////////////
sfFloatRect sfView_getViewport(const sfView* view)
{
sfFloatRect rect = {0, 0, 0, 0};
sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(view, rect);
sf::FloatRect SFMLRect = view->This.getViewport();
rect.left = SFMLRect.left;
rect.top = SFMLRect.top;
rect.width = SFMLRect.width;
rect.height = SFMLRect.height;
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;
}
+2 -2
View File
@@ -33,7 +33,7 @@
////////////////////////////////////////////////////////////
sfCursor* sfCursor_createFromPixels(const uint8_t* pixels, sfVector2u size, sfVector2u hotspot)
{
auto cursor = sf::Cursor::loadFromPixels(pixels, sf::Vector2u(size.x, size.y), sf::Vector2u(hotspot.x, hotspot.y));
auto cursor = sf::Cursor::createFromPixels(pixels, sf::Vector2u(size.x, size.y), sf::Vector2u(hotspot.x, hotspot.y));
if (!cursor)
return nullptr;
@@ -44,7 +44,7 @@ sfCursor* sfCursor_createFromPixels(const uint8_t* pixels, sfVector2u size, sfVe
////////////////////////////////////////////////////////////
sfCursor* sfCursor_createFromSystem(sfCursorType type)
{
auto cursor = sf::Cursor::loadFromSystem(static_cast<sf::Cursor::Type>(type));
auto cursor = sf::Cursor::createFromSystem(static_cast<sf::Cursor::Type>(type));
if (!cursor)
return nullptr;
+4 -4
View File
@@ -132,14 +132,14 @@ bool sfWindow_pollEvent(sfWindow* window, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
const sf::Event sfmlEvent = window->This.pollEvent();
const std::optional sfmlEvent = window->This.pollEvent();
// No event, return
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event);
convertEvent(*sfmlEvent, event);
return true;
}
@@ -152,14 +152,14 @@ bool sfWindow_waitEvent(sfWindow* window, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
const sf::Event sfmlEvent = window->This.waitEvent();
const std::optional sfmlEvent = window->This.waitEvent();
// Error, return
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event);
convertEvent(*sfmlEvent, event);
return true;
}
+4 -4
View File
@@ -100,14 +100,14 @@ bool sfWindowBase_pollEvent(sfWindowBase* windowBase, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
const sf::Event sfmlEvent = windowBase->This.pollEvent();
const std::optional sfmlEvent = windowBase->This.pollEvent();
// No event, return
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event);
convertEvent(*sfmlEvent, event);
return true;
}
@@ -120,14 +120,14 @@ bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfEvent* event)
CSFML_CHECK_RETURN(event, false);
// Get the event
const sf::Event sfmlEvent = windowBase->This.waitEvent();
const std::optional sfmlEvent = windowBase->This.waitEvent();
// Error, return
if (!sfmlEvent)
return false;
// Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event);
convertEvent(*sfmlEvent, event);
return true;
}