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
+316 -379

No files matched your search

+2 -2
View File
@@ -40,13 +40,13 @@ jobs:
- name: Install Linux Dependencies - name: Install Linux Dependencies
if: runner.os == 'Linux' 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 - name: Checkout SFML
uses: actions/checkout@v4 uses: actions/checkout@v4
with: with:
repository: SFML/SFML repository: SFML/SFML
ref: b583eaf1606e54e5f443b094b3b2a6e3af72a5a4 ref: 8096ba24fccb6b76a7d9e8cc71a3afb7b02e517c
path: SFML path: SFML
- name: Configure SFML CMake - 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 /// If set, the music will restart from beginning after
/// reaching the end and so on, until it is stopped or /// 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. /// The default looping state for musics is false.
/// ///
/// \param music Music object /// \param music Music object
/// \param loop true to play in loop, false to play once /// \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 /// \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 /// \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 /// \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 /// If set, the sound will restart from beginning after
/// reaching the end and so on, until it is stopped or /// 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. /// The default looping state for sounds is false.
/// ///
/// \param sound Sound object /// \param sound Sound object
/// \param loop true to play in loop, false to play once /// \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 /// \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 /// \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) /// \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 /// If set, the stream will restart from beginning after
/// reaching the end and so on, until it is stopped or /// 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. /// The default looping state for sound streams is false.
/// ///
/// \param soundStream Sound stream object /// \param soundStream Sound stream object
/// \param loop true to play in loop, false to play once /// \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 /// \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 /// \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 /// \brief Get the current playing position of a sound stream
+4 -30
View File
@@ -39,18 +39,14 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
typedef struct typedef struct
{ {
float left; sfVector2f position;
float top; sfVector2f size;
float width;
float height;
} sfFloatRect; } sfFloatRect;
typedef struct typedef struct
{ {
int left; sfVector2i position;
int top; sfVector2i size;
int width;
int height;
} sfIntRect; } 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 sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2, sfFloatRect* intersection);
CSFML_GRAPHICS_API bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* 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 #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); 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 /// \brief Get the center of a view
/// ///
+3 -2
View File
@@ -29,10 +29,11 @@
// Headers // Headers
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
#include <SFML/System/Export.h> #include <SFML/System/Export.h>
#include <stdlib.h>
typedef int64_t (*sfInputStreamReadFunc)(void* data, int64_t size, void* userData); typedef int64_t (*sfInputStreamReadFunc)(void* data, size_t size, void* userData);
typedef int64_t (*sfInputStreamSeekFunc)(int64_t position, void* userData); typedef int64_t (*sfInputStreamSeekFunc)(size_t position, void* userData);
typedef int64_t (*sfInputStreamTellFunc)(void* userData); typedef int64_t (*sfInputStreamTellFunc)(void* userData);
typedef int64_t (*sfInputStreamGetSizeFunc)(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) sfSoundBuffer* sfSoundBuffer_createFromFile(const char* filename)
{ {
auto soundBuffer = sf::SoundBuffer::loadFromFile(filename); sf::SoundBuffer soundBuffer;
if (!soundBuffer) if (!soundBuffer.loadFromFile(filename))
return nullptr; return nullptr;
return new sfSoundBuffer{std::move(*soundBuffer)}; return new sfSoundBuffer{std::move(soundBuffer)};
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfSoundBuffer* sfSoundBuffer_createFromMemory(const void* data, size_t sizeInBytes) sfSoundBuffer* sfSoundBuffer_createFromMemory(const void* data, size_t sizeInBytes)
{ {
auto soundBuffer = sf::SoundBuffer::loadFromMemory(data, sizeInBytes); sf::SoundBuffer soundBuffer;
if (!soundBuffer) if (!soundBuffer.loadFromMemory(data, sizeInBytes))
return nullptr; 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); CSFML_CHECK_RETURN(stream, nullptr);
CallbackStream sfmlStream(stream); CallbackStream sfmlStream(stream);
auto soundBuffer = sf::SoundBuffer::loadFromStream(sfmlStream); sf::SoundBuffer soundBuffer;
if (!soundBuffer) if (!soundBuffer.loadFromStream(sfmlStream))
return nullptr; 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) for (std::size_t i = 0; i < channelMap.size(); ++i)
channelMap[i] = static_cast<sf::SoundChannel>(channelMapData[i]); channelMap[i] = static_cast<sf::SoundChannel>(channelMapData[i]);
auto soundBuffer = sf::SoundBuffer::loadFromSamples(samples, sampleCount, channelCount, sampleRate, channelMap); sf::SoundBuffer soundBuffer;
if (!soundBuffer) if (!soundBuffer.loadFromSamples(samples, sampleCount, channelCount, sampleRate, channelMap))
return nullptr; 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); CSFML_CHECK_RETURN(soundBufferRecorder, nullptr);
soundBufferRecorder->SoundBuffer = sfSoundBuffer{soundBufferRecorder->This.getBuffer()}; soundBufferRecorder->SoundBuffer.This = soundBufferRecorder->This.getBuffer();
return &*soundBufferRecorder->SoundBuffer; return &soundBufferRecorder->SoundBuffer;
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
+1 -3
View File
@@ -31,8 +31,6 @@
#include <SFML/Audio/SoundBufferRecorder.hpp> #include <SFML/Audio/SoundBufferRecorder.hpp>
#include <SFML/Audio/SoundBufferStruct.h> #include <SFML/Audio/SoundBufferStruct.h>
#include <optional>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
// Internal structure of sfSoundBufferRecorder // Internal structure of sfSoundBufferRecorder
@@ -40,7 +38,7 @@
struct sfSoundBufferRecorder struct sfSoundBufferRecorder
{ {
sf::SoundBufferRecorder This; sf::SoundBufferRecorder This;
mutable std::optional<sfSoundBuffer> SoundBuffer; mutable sfSoundBuffer SoundBuffer;
std::string DeviceName; 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 data Buffer where to copy the read data
/// \param size Desired number of bytes to read /// \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 /// \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 /// \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 /// \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: 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) 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 sfCircleShape_getTextureRect(const sfCircleShape* shape)
{ {
sfIntRect rect = {0, 0, 0, 0}; sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect); CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect(); sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -321,14 +321,14 @@ void sfCircleShape_setPointCount(sfCircleShape* shape, size_t count)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape) sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
{ {
sfFloatRect rect = {0, 0, 0, 0}; sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds(); sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -337,14 +337,14 @@ sfFloatRect sfCircleShape_getLocalBounds(const sfCircleShape* shape)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfCircleShape_getGlobalBounds(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); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds(); sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; 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) 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 sfConvexShape_getTextureRect(const sfConvexShape* shape)
{ {
sfIntRect rect = {0, 0, 0, 0}; sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect); CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect(); sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -311,14 +311,14 @@ void sfConvexShape_setPoint(sfConvexShape* shape, size_t index, sfVector2f point
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape) sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape)
{ {
sfFloatRect rect = {0, 0, 0, 0}; sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds(); sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -327,14 +327,14 @@ sfFloatRect sfConvexShape_getLocalBounds(const sfConvexShape* shape)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfConvexShape_getGlobalBounds(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); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds(); sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
+23 -20
View File
@@ -34,22 +34,22 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFont* sfFont_createFromFile(const char* filename) sfFont* sfFont_createFromFile(const char* filename)
{ {
auto font = sf::Font::loadFromFile(filename); sf::Font font;
if (!font) if (!font.openFromFile(filename))
return nullptr; return nullptr;
return new sfFont{std::move(*font), {}, {}}; return new sfFont{std::move(font), {}, {}};
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFont* sfFont_createFromMemory(const void* data, size_t sizeInBytes) sfFont* sfFont_createFromMemory(const void* data, size_t sizeInBytes)
{ {
auto font = sf::Font::loadFromMemory(data, sizeInBytes); sf::Font font;
if (!font) if (!font.openFromMemory(data, sizeInBytes))
return nullptr; 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); CSFML_CHECK_RETURN(stream, nullptr);
auto sfmlStream = std::make_shared<CallbackStream>(stream); sfFont* font = new sfFont;
auto font = sf::Font::loadFromStream(*sfmlStream); font->Stream = CallbackStream(stream);
if (!font) if (!font->This.openFromStream(font->Stream))
return nullptr; {
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 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); CSFML_CHECK_RETURN(font, glyph);
sf::Glyph SFMLGlyph = font->This.getGlyph(codePoint, characterSize, bold, outlineThickness); sf::Glyph SFMLGlyph = font->This.getGlyph(codePoint, characterSize, bold, outlineThickness);
glyph.advance = SFMLGlyph.advance; glyph.advance = SFMLGlyph.advance;
glyph.bounds.left = SFMLGlyph.bounds.left; glyph.bounds.position.x = SFMLGlyph.bounds.position.x;
glyph.bounds.top = SFMLGlyph.bounds.top; glyph.bounds.position.y = SFMLGlyph.bounds.position.y;
glyph.bounds.width = SFMLGlyph.bounds.width; glyph.bounds.size.x = SFMLGlyph.bounds.size.x;
glyph.bounds.height = SFMLGlyph.bounds.height; glyph.bounds.size.y = SFMLGlyph.bounds.size.y;
glyph.textureRect.left = SFMLGlyph.textureRect.left; glyph.textureRect.position.x = SFMLGlyph.textureRect.position.x;
glyph.textureRect.top = SFMLGlyph.textureRect.top; glyph.textureRect.position.y = SFMLGlyph.textureRect.position.y;
glyph.textureRect.width = SFMLGlyph.textureRect.width; glyph.textureRect.size.x = SFMLGlyph.textureRect.size.x;
glyph.textureRect.height = SFMLGlyph.textureRect.height; glyph.textureRect.size.y = SFMLGlyph.textureRect.size.y;
return glyph; return glyph;
} }
+1 -2
View File
@@ -32,7 +32,6 @@
#include <SFML/Graphics/TextureStruct.h> #include <SFML/Graphics/TextureStruct.h>
#include <SFML/CallbackStream.h> #include <SFML/CallbackStream.h>
#include <map> #include <map>
#include <memory>
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
@@ -42,7 +41,7 @@ struct sfFont
{ {
sf::Font This; sf::Font This;
std::map<unsigned int, sfTexture> Textures; 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) 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) sfImage* sfImage_createFromFile(const char* filename)
{ {
auto image = sf::Image::loadFromFile(filename); sf::Image image;
if (!image) if (!image.loadFromFile(filename))
return nullptr; return nullptr;
return new sfImage{std::move(*image)}; return new sfImage{std::move(image)};
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfImage* sfImage_createFromMemory(const void* data, size_t sizeInBytes) sfImage* sfImage_createFromMemory(const void* data, size_t sizeInBytes)
{ {
auto image = sf::Image::loadFromMemory(data, sizeInBytes); sf::Image image;
if (!image) if (!image.loadFromMemory(data, sizeInBytes))
return nullptr; 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); CSFML_CHECK_RETURN(stream, nullptr);
CallbackStream sfmlStream(stream); CallbackStream sfmlStream(stream);
auto image = sf::Image::loadFromStream(sfmlStream); sf::Image image;
if (!image) if (!image.loadFromStream(sfmlStream))
return nullptr; 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(image, false);
CSFML_CHECK_RETURN(source, 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); return image->This.copy(source->This, { destX, destY }, sfmlRect, applyAlpha);
} }
+14 -55
View File
@@ -30,33 +30,18 @@
#include <SFML/Internal.h> #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 /// Check if a point is inside a rectangle's area
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
bool sfFloatRect_contains(const sfFloatRect* rect, float x, float y) bool sfFloatRect_contains(const sfFloatRect* rect, float x, float y)
{ {
CSFML_CHECK_RETURN(rect, false); 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) bool sfIntRect_contains(const sfIntRect* rect, int x, int y)
{ {
CSFML_CHECK_RETURN(rect, false); 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(rect1, false);
CSFML_CHECK_RETURN(rect2, false); CSFML_CHECK_RETURN(rect2, false);
sf::FloatRect SFMLRect1({ rect1->left, rect1->top }, { rect1->width, rect1->height }); sf::FloatRect SFMLRect1({ rect1->position.x, rect1->position.y }, { rect1->size.x, rect1->size.y });
sf::FloatRect SFMLRect2({ rect2->left, rect2->top }, { rect2->width, rect2->height }); sf::FloatRect SFMLRect2({ rect2->position.x, rect2->position.y }, { rect2->size.x, rect2->size.y });
if (intersection) if (intersection)
{ {
@@ -77,10 +62,10 @@ bool sfFloatRect_intersects(const sfFloatRect* rect1, const sfFloatRect* rect2,
if (overlap) if (overlap)
{ {
intersection->left = overlap->left; intersection->position.x = overlap->position.x;
intersection->top = overlap->top; intersection->position.y = overlap->position.y;
intersection->width = overlap->width; intersection->size.x = overlap->size.x;
intersection->height = overlap->height; intersection->size.y = overlap->size.y;
} }
return overlap.has_value(); 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(rect1, false);
CSFML_CHECK_RETURN(rect2, false); CSFML_CHECK_RETURN(rect2, false);
sf::IntRect SFMLRect1({ rect1->left, rect1->top }, { rect1->width, rect1->height }); sf::IntRect SFMLRect1({ rect1->position.x, rect1->position.y }, { rect1->size.x, rect1->size.y });
sf::IntRect SFMLRect2({ rect2->left, rect2->top }, { rect2->width, rect2->height }); sf::IntRect SFMLRect2({ rect2->position.x, rect2->position.y }, { rect2->size.x, rect2->size.y });
if (intersection) if (intersection)
{ {
@@ -104,10 +89,10 @@ bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntR
if (overlap) if (overlap)
{ {
intersection->left = overlap->left; intersection->position.x = overlap->position.x;
intersection->top = overlap->top; intersection->position.y = overlap->position.y;
intersection->width = overlap->width; intersection->size.x = overlap->size.x;
intersection->height = overlap->height; intersection->size.y = overlap->size.y;
} }
return overlap.has_value(); return overlap.has_value();
@@ -117,29 +102,3 @@ bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntR
return SFMLRect1.findIntersection(SFMLRect2).has_value(); 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) 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 sfRectangleShape_getTextureRect(const sfRectangleShape* shape)
{ {
sfIntRect rect = {0, 0, 0, 0}; sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect); CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect(); sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -318,14 +318,14 @@ sfVector2f sfRectangleShape_getSize(const sfRectangleShape* shape)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfRectangleShape_getLocalBounds(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); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds(); sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -334,14 +334,14 @@ sfFloatRect sfRectangleShape_getLocalBounds(const sfRectangleShape* shape)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfRectangleShape_getGlobalBounds(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); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds(); sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
+12 -11
View File
@@ -51,14 +51,15 @@ sfRenderTexture* sfRenderTexture_create(unsigned int width, unsigned int height,
} }
// Create the render texture // Create the render texture
auto renderTexture = sf::RenderTexture::create({ width, height }, params); sf::RenderTexture renderTexture;
if (!renderTexture) if (!renderTexture.resize({ width, height }, params))
return nullptr; return nullptr;
return new sfRenderTexture{std::move(*renderTexture), auto* texture = new sfTexture(const_cast<sf::Texture*>(&renderTexture.getTexture()));
new sfTexture(const_cast<sf::Texture*>(&renderTexture->getTexture())), const auto defaultView = sfView{renderTexture.getDefaultView()};
{renderTexture->getDefaultView()}, const auto currentView = sfView{renderTexture.getView()};
{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 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(view, rect);
CSFML_CHECK_RETURN(renderTexture, rect); CSFML_CHECK_RETURN(renderTexture, rect);
sf::IntRect SFMLrect = renderTexture->This.getViewport(view->This); sf::IntRect SFMLrect = renderTexture->This.getViewport(view->This);
rect.left = SFMLrect.left; rect.position.x = SFMLrect.position.x;
rect.top = SFMLrect.top; rect.position.y = SFMLrect.position.y;
rect.width = SFMLrect.width; rect.size.x = SFMLrect.size.x;
rect.height = SFMLrect.height; rect.size.y = SFMLrect.size.y;
return rect; return rect;
} }
+9 -9
View File
@@ -150,14 +150,14 @@ bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event)
CSFML_CHECK_RETURN(event, false); CSFML_CHECK_RETURN(event, false);
// Get the event // Get the event
const sf::Event sfmlEvent = renderWindow->This.pollEvent(); const std::optional sfmlEvent = renderWindow->This.pollEvent();
// No event, return // No event, return
if (!sfmlEvent) if (!sfmlEvent)
return false; return false;
// Convert the sf::Event event to a sfEvent // Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event); convertEvent(*sfmlEvent, event);
return true; return true;
} }
@@ -170,14 +170,14 @@ bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event)
CSFML_CHECK_RETURN(event, false); CSFML_CHECK_RETURN(event, false);
// Get the event // Get the event
const sf::Event sfmlEvent = renderWindow->This.waitEvent(); const std::optional sfmlEvent = renderWindow->This.waitEvent();
// Error, return // Error, return
if (!sfmlEvent) if (!sfmlEvent)
return false; return false;
// Convert the sf::Event event to a sfEvent // Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event); convertEvent(*sfmlEvent, event);
return true; return true;
} }
@@ -388,15 +388,15 @@ const sfView* sfRenderWindow_getDefaultView(const sfRenderWindow* renderWindow)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const sfView* view) 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(view, rect);
CSFML_CHECK_RETURN(renderWindow, rect); CSFML_CHECK_RETURN(renderWindow, rect);
sf::IntRect SFMLrect = renderWindow->This.getViewport(view->This); sf::IntRect SFMLrect = renderWindow->This.getViewport(view->This);
rect.left = SFMLrect.left; rect.position.x = SFMLrect.position.x;
rect.top = SFMLrect.top; rect.position.y = SFMLrect.position.y;
rect.width = SFMLrect.width; rect.size.x = SFMLrect.size.x;
rect.height = SFMLrect.height; rect.size.y = SFMLrect.size.y;
return rect; return rect;
} }
+27 -24
View File
@@ -36,7 +36,8 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* geometryShaderFilename, const char* fragmentShaderFilename) 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 (vertexShaderFilename || geometryShaderFilename || fragmentShaderFilename)
{ {
if (!geometryShaderFilename) if (!geometryShaderFilename)
@@ -44,17 +45,17 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char*
if (!vertexShaderFilename) if (!vertexShaderFilename)
{ {
// fragment shader only // fragment shader only
shader = sf::Shader::loadFromFile(fragmentShaderFilename, sf::Shader::Type::Fragment); success = shader.loadFromFile(fragmentShaderFilename, sf::Shader::Type::Fragment);
} }
else if (!fragmentShaderFilename) else if (!fragmentShaderFilename)
{ {
// vertex shader only // vertex shader only
shader = sf::Shader::loadFromFile(vertexShaderFilename, sf::Shader::Type::Vertex); success = shader.loadFromFile(vertexShaderFilename, sf::Shader::Type::Vertex);
} }
else else
{ {
// vertex + fragment shaders // vertex + fragment shaders
shader = sf::Shader::loadFromFile(vertexShaderFilename, fragmentShaderFilename); success = shader.loadFromFile(vertexShaderFilename, fragmentShaderFilename);
} }
} }
else else
@@ -62,27 +63,28 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char*
if (!vertexShaderFilename && !fragmentShaderFilename) if (!vertexShaderFilename && !fragmentShaderFilename)
{ {
// geometry shader only // geometry shader only
shader = sf::Shader::loadFromFile(geometryShaderFilename, sf::Shader::Type::Geometry); success = shader.loadFromFile(geometryShaderFilename, sf::Shader::Type::Geometry);
} }
else else
{ {
// vertex + geometry + fragment shaders // vertex + geometry + fragment shaders
shader = sf::Shader::loadFromFile(vertexShaderFilename, geometryShaderFilename, fragmentShaderFilename); success = shader.loadFromFile(vertexShaderFilename, geometryShaderFilename, fragmentShaderFilename);
} }
} }
} }
if (!shader) if (!success)
return nullptr; 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) 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 (vertexShader || geometryShader || fragmentShader)
{ {
if (!geometryShader) if (!geometryShader)
@@ -90,17 +92,17 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geomet
if (!vertexShader) if (!vertexShader)
{ {
// fragment shader only // fragment shader only
shader = sf::Shader::loadFromMemory(fragmentShader, sf::Shader::Type::Fragment); success = shader.loadFromMemory(fragmentShader, sf::Shader::Type::Fragment);
} }
else if (!fragmentShader) else if (!fragmentShader)
{ {
// vertex shader only // vertex shader only
shader = sf::Shader::loadFromMemory(vertexShader, sf::Shader::Type::Vertex); success = shader.loadFromMemory(vertexShader, sf::Shader::Type::Vertex);
} }
else else
{ {
// vertex + fragment shaders // vertex + fragment shaders
shader = sf::Shader::loadFromMemory(vertexShader, fragmentShader); success = shader.loadFromMemory(vertexShader, fragmentShader);
} }
} }
else else
@@ -108,27 +110,28 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geomet
if (!vertexShader && !fragmentShader) if (!vertexShader && !fragmentShader)
{ {
// geometry shader only // geometry shader only
shader = sf::Shader::loadFromMemory(geometryShader, sf::Shader::Type::Geometry); success = shader.loadFromMemory(geometryShader, sf::Shader::Type::Geometry);
} }
else else
{ {
// vertex + geometry + fragment shaders // vertex + geometry + fragment shaders
shader = sf::Shader::loadFromMemory(vertexShader, geometryShader, fragmentShader); success = shader.loadFromMemory(vertexShader, geometryShader, fragmentShader);
} }
} }
} }
if (!shader) if (!success)
return nullptr; return nullptr;
return new sfShader{std::move(*shader)}; return new sfShader{std::move(shader)};
} }
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputStream* geometryShaderStream, sfInputStream* fragmentShaderStream) 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 (vertexShaderStream || geometryShaderStream || fragmentShaderStream)
{ {
if (!geometryShaderStream) if (!geometryShaderStream)
@@ -137,20 +140,20 @@ sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputSt
{ {
// fragment shader only // fragment shader only
CallbackStream stream(fragmentShaderStream); CallbackStream stream(fragmentShaderStream);
shader = sf::Shader::loadFromStream(stream, sf::Shader::Type::Fragment); success = shader.loadFromStream(stream, sf::Shader::Type::Fragment);
} }
else if (!fragmentShaderStream) else if (!fragmentShaderStream)
{ {
// vertex shader only // vertex shader only
CallbackStream stream(vertexShaderStream); CallbackStream stream(vertexShaderStream);
shader = sf::Shader::loadFromStream(stream, sf::Shader::Type::Vertex); success = shader.loadFromStream(stream, sf::Shader::Type::Vertex);
} }
else else
{ {
// vertex + fragment shaders // vertex + fragment shaders
CallbackStream vertexStream(vertexShaderStream); CallbackStream vertexStream(vertexShaderStream);
CallbackStream fragmentStream(fragmentShaderStream); CallbackStream fragmentStream(fragmentShaderStream);
shader = sf::Shader::loadFromStream(vertexStream, fragmentStream); success = shader.loadFromStream(vertexStream, fragmentStream);
} }
} }
else else
@@ -159,22 +162,22 @@ sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputSt
if (!vertexShaderStream && !fragmentShaderStream) if (!vertexShaderStream && !fragmentShaderStream)
{ {
// geometry shader only // geometry shader only
shader = sf::Shader::loadFromStream(geometryStream, sf::Shader::Type::Geometry); success = shader.loadFromStream(geometryStream, sf::Shader::Type::Geometry);
} }
else else
{ {
// vertex + geometry + fragment shaders // vertex + geometry + fragment shaders
CallbackStream vertexStream(vertexShaderStream); CallbackStream vertexStream(vertexShaderStream);
CallbackStream fragmentStream(fragmentShaderStream); CallbackStream fragmentStream(fragmentShaderStream);
shader = sf::Shader::loadFromStream(vertexStream, geometryStream, fragmentStream); success = shader.loadFromStream(vertexStream, geometryStream, fragmentStream);
} }
} }
} }
if (!shader) if (!success)
return nullptr; 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) 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 sfShape_getTextureRect(const sfShape* shape)
{ {
sfIntRect rect = {0, 0, 0, 0}; sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect); CSFML_CHECK_RETURN(shape, rect);
sf::IntRect sfmlRect = shape->This.getTextureRect(); sf::IntRect sfmlRect = shape->This.getTextureRect();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -290,14 +290,14 @@ sfVector2f sfShape_getPoint(const sfShape* shape, size_t index)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfShape_getLocalBounds(const sfShape* shape) sfFloatRect sfShape_getLocalBounds(const sfShape* shape)
{ {
sfFloatRect rect = {0, 0, 0, 0}; sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(shape, rect); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getLocalBounds(); sf::FloatRect sfmlRect = shape->This.getLocalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -306,14 +306,14 @@ sfFloatRect sfShape_getLocalBounds(const sfShape* shape)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfShape_getGlobalBounds(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); CSFML_CHECK_RETURN(shape, rect);
sf::FloatRect sfmlRect = shape->This.getGlobalBounds(); sf::FloatRect sfmlRect = shape->This.getGlobalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; 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) 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 sfSprite_getTextureRect(const sfSprite* sprite)
{ {
sfIntRect rect = {0, 0, 0, 0}; sfIntRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(sprite, rect); CSFML_CHECK_RETURN(sprite, rect);
sf::IntRect sfmlRect = sprite->This.getTextureRect(); sf::IntRect sfmlRect = sprite->This.getTextureRect();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -246,14 +246,14 @@ sfColor sfSprite_getColor(const sfSprite* sprite)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfSprite_getLocalBounds(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); CSFML_CHECK_RETURN(sprite, rect);
sf::FloatRect sfmlRect = sprite->This.getLocalBounds(); sf::FloatRect sfmlRect = sprite->This.getLocalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -262,14 +262,14 @@ sfFloatRect sfSprite_getLocalBounds(const sfSprite* sprite)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfSprite_getGlobalBounds(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); CSFML_CHECK_RETURN(sprite, rect);
sf::FloatRect sfmlRect = sprite->This.getGlobalBounds(); sf::FloatRect sfmlRect = sprite->This.getGlobalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; 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 sfText_getLocalBounds(const sfText* text)
{ {
sfFloatRect rect = {0, 0, 0, 0}; sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(text, rect); CSFML_CHECK_RETURN(text, rect);
sf::FloatRect sfmlRect = text->This.getLocalBounds(); sf::FloatRect sfmlRect = text->This.getLocalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
@@ -394,14 +394,14 @@ sfFloatRect sfText_getLocalBounds(const sfText* text)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfText_getGlobalBounds(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); CSFML_CHECK_RETURN(text, rect);
sf::FloatRect sfmlRect = text->This.getGlobalBounds(); sf::FloatRect sfmlRect = text->This.getGlobalBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
+17 -25
View File
@@ -39,7 +39,7 @@ sfTexture* sfTexture_create(unsigned int width, unsigned int height)
{ {
sfTexture* texture = new sfTexture; sfTexture* texture = new sfTexture;
if (!texture->This->create({ width, height })) if (!texture->This->resize({ width, height }))
{ {
delete texture; delete texture;
texture = nullptr; texture = nullptr;
@@ -56,9 +56,9 @@ sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area)
sf::IntRect rect; sf::IntRect rect;
if (area) 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; delete texture;
texture = nullptr; texture = nullptr;
@@ -74,11 +74,9 @@ sfTexture* sfTexture_createSrgbFromFile(const char* filename, const sfIntRect* a
sf::IntRect rect; sf::IntRect rect;
if (area) 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, true, rect))
if (!texture->This->loadFromFile(filename, rect))
{ {
delete texture; delete texture;
texture = nullptr; texture = nullptr;
@@ -94,9 +92,9 @@ sfTexture* sfTexture_createFromMemory(const void* data, size_t sizeInBytes, cons
sf::IntRect rect; sf::IntRect rect;
if (area) 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; delete texture;
texture = nullptr; texture = nullptr;
@@ -112,11 +110,9 @@ sfTexture* sfTexture_createSrgbFromMemory(const void* data, size_t sizeInBytes,
sf::IntRect rect; sf::IntRect rect;
if (area) 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, true, rect))
if (!texture->This->loadFromMemory(data, sizeInBytes, rect))
{ {
delete texture; delete texture;
texture = nullptr; texture = nullptr;
@@ -135,10 +131,10 @@ sfTexture* sfTexture_createFromStream(sfInputStream* stream, const sfIntRect* ar
sf::IntRect rect; sf::IntRect rect;
if (area) 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); CallbackStream sfmlStream(stream);
if (!texture->This->loadFromStream(sfmlStream, rect)) if (!texture->This->loadFromStream(sfmlStream, false, rect))
{ {
delete texture; delete texture;
texture = nullptr; texture = nullptr;
@@ -156,12 +152,10 @@ sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect
sf::IntRect rect; sf::IntRect rect;
if (area) 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);
CallbackStream sfmlStream(stream); CallbackStream sfmlStream(stream);
if (!texture->This->loadFromStream(sfmlStream, rect)) if (!texture->This->loadFromStream(sfmlStream, true, rect))
{ {
delete texture; delete texture;
texture = nullptr; texture = nullptr;
@@ -180,9 +174,9 @@ sfTexture* sfTexture_createFromImage(const sfImage* image, const sfIntRect* area
sf::IntRect rect; sf::IntRect rect;
if (area) 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; delete texture;
texture = nullptr; texture = nullptr;
@@ -200,11 +194,9 @@ sfTexture* sfTexture_createSrgbFromImage(const sfImage* image, const sfIntRect*
sf::IntRect rect; sf::IntRect rect;
if (area) 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, true, rect))
if (!texture->This->loadFromImage(image->This, rect))
{ {
delete texture; delete texture;
texture = nullptr; 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 sfTransform_transformRect(const sfTransform* transform, sfFloatRect rectangle)
{ {
sfFloatRect rect = {0, 0, 0, 0}; sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(transform, rect); 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.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
+5 -5
View File
@@ -110,14 +110,14 @@ sfPrimitiveType sfVertexArray_getPrimitiveType(sfVertexArray* vertexArray)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfVertexArray_getBounds(sfVertexArray* vertexArray) sfFloatRect sfVertexArray_getBounds(sfVertexArray* vertexArray)
{ {
sfFloatRect rect = {0, 0, 0, 0}; sfFloatRect rect = {{0, 0}, {0, 0}};
CSFML_CHECK_RETURN(vertexArray, rect); CSFML_CHECK_RETURN(vertexArray, rect);
sf::FloatRect sfmlRect = vertexArray->This.getBounds(); sf::FloatRect sfmlRect = vertexArray->This.getBounds();
rect.left = sfmlRect.left; rect.position.x = sfmlRect.position.x;
rect.top = sfmlRect.top; rect.position.y = sfmlRect.position.y;
rect.width = sfmlRect.width; rect.size.x = sfmlRect.size.x;
rect.height = sfmlRect.height; rect.size.y = sfmlRect.size.y;
return rect; return rect;
} }
+7 -17
View File
@@ -40,10 +40,7 @@ sfView* sfView_create(void)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfView* sfView_createFromRect(sfFloatRect rectangle) sfView* sfView_createFromRect(sfFloatRect rectangle)
{ {
sfView* view = new sfView; return new sfView{sf::View(sf::FloatRect({rectangle.position.x, rectangle.position.y}, {rectangle.size.x, rectangle.size.y}))};
sfView_reset(view, rectangle);
return view;
} }
@@ -87,14 +84,7 @@ void sfView_setRotation(sfView* view, float angle)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void sfView_setViewport(sfView* view, sfFloatRect viewport) void sfView_setViewport(sfView* view, sfFloatRect viewport)
{ {
CSFML_CALL(view, setViewport(sf::FloatRect({ viewport.left, viewport.top }, { viewport.width, viewport.height }))); CSFML_CALL(view, setViewport(sf::FloatRect({ viewport.position.x, viewport.position.y }, { viewport.size.x, viewport.size.y })));
}
////////////////////////////////////////////////////////////
void sfView_reset(sfView* view, sfFloatRect rectangle)
{
CSFML_CALL(view, reset(sf::FloatRect({ rectangle.left, rectangle.top }, { rectangle.width, rectangle.height })));
} }
@@ -136,14 +126,14 @@ float sfView_getRotation(const sfView* view)
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfFloatRect sfView_getViewport(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); CSFML_CHECK_RETURN(view, rect);
sf::FloatRect SFMLRect = view->This.getViewport(); sf::FloatRect SFMLRect = view->This.getViewport();
rect.left = SFMLRect.left; rect.position.x = SFMLRect.position.x;
rect.top = SFMLRect.top; rect.position.y = SFMLRect.position.y;
rect.width = SFMLRect.width; rect.size.x = SFMLRect.size.x;
rect.height = SFMLRect.height; rect.size.y = SFMLRect.size.y;
return rect; return rect;
} }
+2 -2
View File
@@ -33,7 +33,7 @@
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfCursor* sfCursor_createFromPixels(const uint8_t* pixels, sfVector2u size, sfVector2u hotspot) 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) if (!cursor)
return nullptr; return nullptr;
@@ -44,7 +44,7 @@ sfCursor* sfCursor_createFromPixels(const uint8_t* pixels, sfVector2u size, sfVe
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
sfCursor* sfCursor_createFromSystem(sfCursorType type) 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) if (!cursor)
return nullptr; return nullptr;
+4 -4
View File
@@ -132,14 +132,14 @@ bool sfWindow_pollEvent(sfWindow* window, sfEvent* event)
CSFML_CHECK_RETURN(event, false); CSFML_CHECK_RETURN(event, false);
// Get the event // Get the event
const sf::Event sfmlEvent = window->This.pollEvent(); const std::optional sfmlEvent = window->This.pollEvent();
// No event, return // No event, return
if (!sfmlEvent) if (!sfmlEvent)
return false; return false;
// Convert the sf::Event event to a sfEvent // Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event); convertEvent(*sfmlEvent, event);
return true; return true;
} }
@@ -152,14 +152,14 @@ bool sfWindow_waitEvent(sfWindow* window, sfEvent* event)
CSFML_CHECK_RETURN(event, false); CSFML_CHECK_RETURN(event, false);
// Get the event // Get the event
const sf::Event sfmlEvent = window->This.waitEvent(); const std::optional sfmlEvent = window->This.waitEvent();
// Error, return // Error, return
if (!sfmlEvent) if (!sfmlEvent)
return false; return false;
// Convert the sf::Event event to a sfEvent // Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event); convertEvent(*sfmlEvent, event);
return true; return true;
} }
+4 -4
View File
@@ -100,14 +100,14 @@ bool sfWindowBase_pollEvent(sfWindowBase* windowBase, sfEvent* event)
CSFML_CHECK_RETURN(event, false); CSFML_CHECK_RETURN(event, false);
// Get the event // Get the event
const sf::Event sfmlEvent = windowBase->This.pollEvent(); const std::optional sfmlEvent = windowBase->This.pollEvent();
// No event, return // No event, return
if (!sfmlEvent) if (!sfmlEvent)
return false; return false;
// Convert the sf::Event event to a sfEvent // Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event); convertEvent(*sfmlEvent, event);
return true; return true;
} }
@@ -120,14 +120,14 @@ bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfEvent* event)
CSFML_CHECK_RETURN(event, false); CSFML_CHECK_RETURN(event, false);
// Get the event // Get the event
const sf::Event sfmlEvent = windowBase->This.waitEvent(); const std::optional sfmlEvent = windowBase->This.waitEvent();
// Error, return // Error, return
if (!sfmlEvent) if (!sfmlEvent)
return false; return false;
// Convert the sf::Event event to a sfEvent // Convert the sf::Event event to a sfEvent
convertEvent(sfmlEvent, event); convertEvent(*sfmlEvent, event);
return true; return true;
} }