diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index bf7f7b7..cb1fcd0 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -42,7 +42,7 @@ jobs: uses: actions/checkout@v4 with: repository: SFML/SFML - ref: 2.6.0 + ref: master path: SFML - name: Configure SFML CMake diff --git a/.gitignore b/.gitignore index 5469574..172e41d 100644 --- a/.gitignore +++ b/.gitignore @@ -41,5 +41,8 @@ cmake-build-*/ .idea/ .vs/ +# CMake User Presets +CMakeUserPresets.json + # System files .DS_Store \ No newline at end of file diff --git a/examples/example.c b/examples/example.c index 86040db..c694fa7 100644 --- a/examples/example.c +++ b/examples/example.c @@ -7,7 +7,7 @@ int main(void) { // Create the main window const sfVideoMode mode = {800, 600, 32}; - sfRenderWindow* window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, NULL); + sfRenderWindow* window = sfRenderWindow_create(mode, "SFML window", sfResize | sfClose, sfWindowed, NULL); if (!window) return EXIT_FAILURE; @@ -18,8 +18,7 @@ int main(void) sfRenderWindow_destroy(window); return EXIT_FAILURE; } - sfSprite* sprite = sfSprite_create(); - sfSprite_setTexture(sprite, texture, true); + sfSprite* sprite = sfSprite_create(texture); const sfVector2f spritePosition = {200, 200}; sfSprite_setPosition(sprite, spritePosition); @@ -32,9 +31,8 @@ int main(void) sfRenderWindow_destroy(window); return EXIT_FAILURE; } - sfText* text = sfText_create(); + sfText* text = sfText_create(font); sfText_setString(text, "Hello, SFML!"); - sfText_setFont(text, font); sfText_setCharacterSize(text, 50); // Load a music to play diff --git a/include/SFML/Audio/Sound.h b/include/SFML/Audio/Sound.h index 2b46eb8..d7a7c80 100644 --- a/include/SFML/Audio/Sound.h +++ b/include/SFML/Audio/Sound.h @@ -37,11 +37,13 @@ //////////////////////////////////////////////////////////// /// \brief Create a new sound +/// +/// \param soundBuffer Sound buffer containing the audio data to play with the sound /// /// \return A new sfSound object /// //////////////////////////////////////////////////////////// -CSFML_AUDIO_API sfSound* sfSound_create(void); +CSFML_AUDIO_API sfSound* sfSound_create(const sfSoundBuffer* buffer); //////////////////////////////////////////////////////////// /// \brief Create a new sound by copying an existing one diff --git a/include/SFML/Config.h b/include/SFML/Config.h index c7ffe86..6ed9ca1 100644 --- a/include/SFML/Config.h +++ b/include/SFML/Config.h @@ -142,4 +142,14 @@ #endif + +//////////////////////////////////////////////////////////// +/// Define sfChar32 +/// +/// Work around macOS not providing +//////////////////////////////////////////////////////////// +#include +typedef uint32_t sfChar32; + + #endif // SFML_CONFIG_H diff --git a/include/SFML/Graphics/Image.h b/include/SFML/Graphics/Image.h index 5000a2c..d78f392 100644 --- a/include/SFML/Graphics/Image.h +++ b/include/SFML/Graphics/Image.h @@ -224,9 +224,11 @@ CSFML_GRAPHICS_API void sfImage_createMaskFromColor(sfImage* image, sfColor colo /// \param destY Y coordinate of the destination position /// \param sourceRect Sub-rectangle of the source image to copy /// \param applyAlpha Should the copy take in account the source transparency? +/// +/// \return True if the operation was successful, false otherwise /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfImage_copyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect, bool applyAlpha); +CSFML_GRAPHICS_API bool sfImage_copyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect, bool applyAlpha); //////////////////////////////////////////////////////////// /// \brief Change the color of a pixel in an image diff --git a/include/SFML/Graphics/RenderTexture.h b/include/SFML/Graphics/RenderTexture.h index d043333..f29897d 100644 --- a/include/SFML/Graphics/RenderTexture.h +++ b/include/SFML/Graphics/RenderTexture.h @@ -40,21 +40,6 @@ #include -//////////////////////////////////////////////////////////// -/// \brief Construct a new render texture -/// -/// \param width Width of the render texture -/// \param height Height of the render texture -/// \param depthBuffer Do you want a depth-buffer attached? (useful only if you're doing 3D OpenGL on the rendertexture) -/// -/// \return A new sfRenderTexture object, or NULL if it failed -/// -/// \deprecated -/// Use sfRenderTexture_createWithSettings instead. -/// -//////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfRenderTexture* sfRenderTexture_create(unsigned int width, unsigned int height, bool depthBuffer); - //////////////////////////////////////////////////////////// /// \brief Construct a new render texture /// @@ -65,7 +50,7 @@ CSFML_GRAPHICS_API sfRenderTexture* sfRenderTexture_create(unsigned int width, u /// \return A new sfRenderTexture object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfRenderTexture* sfRenderTexture_createWithSettings(unsigned int width, unsigned int height, const sfContextSettings* settings); +CSFML_GRAPHICS_API sfRenderTexture* sfRenderTexture_create(unsigned int width, unsigned int height, const sfContextSettings* settings); //////////////////////////////////////////////////////////// /// \brief Destroy an existing render texture diff --git a/include/SFML/Graphics/RenderWindow.h b/include/SFML/Graphics/RenderWindow.h index 64a4c23..406d21d 100644 --- a/include/SFML/Graphics/RenderWindow.h +++ b/include/SFML/Graphics/RenderWindow.h @@ -52,7 +52,7 @@ /// \param settings Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint32_t style, const sfContextSettings* settings); +CSFML_GRAPHICS_API sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint32_t style, sfWindowState state, const sfContextSettings* settings); //////////////////////////////////////////////////////////// /// \brief Construct a new render window (with a UTF-32 title) @@ -63,7 +63,7 @@ CSFML_GRAPHICS_API sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const /// \param settings Creation settings (pass NULL to use default values) /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const uint32_t* title, uint32_t style, const sfContextSettings* settings); +CSFML_GRAPHICS_API sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style, sfWindowState state, const sfContextSettings* settings); //////////////////////////////////////////////////////////// /// \brief Construct a render window from an existing control @@ -196,7 +196,7 @@ CSFML_GRAPHICS_API void sfRenderWindow_setTitle(sfRenderWindow* renderWindow, co /// \param title New title /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfRenderWindow_setUnicodeTitle(sfRenderWindow* renderWindow, const uint32_t* title); +CSFML_GRAPHICS_API void sfRenderWindow_setUnicodeTitle(sfRenderWindow* renderWindow, const sfChar32* title); //////////////////////////////////////////////////////////// /// \brief Change a render window's icon @@ -352,7 +352,7 @@ CSFML_GRAPHICS_API void sfRenderWindow_display(sfRenderWindow* renderWindow); /// \return Window handle /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfWindowHandle sfRenderWindow_getSystemHandle(const sfRenderWindow* renderWindow); +CSFML_GRAPHICS_API sfWindowHandle sfRenderWindow_getNativeHandle(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// /// \brief Clear a render window with the given color diff --git a/include/SFML/Graphics/Sprite.h b/include/SFML/Graphics/Sprite.h index fc401fb..e8f11d3 100644 --- a/include/SFML/Graphics/Sprite.h +++ b/include/SFML/Graphics/Sprite.h @@ -39,11 +39,13 @@ //////////////////////////////////////////////////////////// /// \brief Create a new sprite +/// +/// \param texture Source texture /// /// \return A new sfSprite object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfSprite* sfSprite_create(void); +CSFML_GRAPHICS_API sfSprite* sfSprite_create(const sfTexture* texture); //////////////////////////////////////////////////////////// /// \brief Copy an existing sprite diff --git a/include/SFML/Graphics/Text.h b/include/SFML/Graphics/Text.h index ec4ddda..1738b0a 100644 --- a/include/SFML/Graphics/Text.h +++ b/include/SFML/Graphics/Text.h @@ -52,11 +52,13 @@ typedef enum //////////////////////////////////////////////////////////// /// \brief Create a new text +/// +/// \param font Font used to draw the string /// /// \return A new sfText object, or NULL if it failed /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API sfText* sfText_create(void); +CSFML_GRAPHICS_API sfText* sfText_create(const sfFont* font); //////////////////////////////////////////////////////////// /// \brief Copy an existing text @@ -247,7 +249,7 @@ CSFML_GRAPHICS_API void sfText_setString(sfText* text, const char* string); /// \param string New string /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API void sfText_setUnicodeString(sfText* text, const uint32_t* string); +CSFML_GRAPHICS_API void sfText_setUnicodeString(sfText* text, const sfChar32* string); //////////////////////////////////////////////////////////// /// \brief Set the font of a text @@ -391,13 +393,13 @@ CSFML_GRAPHICS_API const char* sfText_getString(const sfText* text); //////////////////////////////////////////////////////////// /// \brief Get the string of a text (returns a unicode string) -/// +/// /// \param text Text object /// /// \return String as UTF-32 /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API const uint32_t* sfText_getUnicodeString(const sfText* text); +CSFML_GRAPHICS_API const sfChar32* sfText_getUnicodeString(const sfText* text); //////////////////////////////////////////////////////////// /// \brief Get the font used by a text diff --git a/include/SFML/Network/Ftp.h b/include/SFML/Network/Ftp.h index b4428c5..03fa7aa 100644 --- a/include/SFML/Network/Ftp.h +++ b/include/SFML/Network/Ftp.h @@ -219,6 +219,9 @@ CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getMessage(const sfFtpDirec //////////////////////////////////////////////////////////// /// \brief Get the directory returned in a FTP directory response /// +/// The returned const char* owns the string and must be freed to +/// avoid memory leaks. +/// /// \param ftpDirectoryResponse Ftp directory response /// /// \return Directory name @@ -227,6 +230,20 @@ CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getMessage(const sfFtpDirec CSFML_NETWORK_API const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDirectoryResponse* ftpDirectoryResponse); +//////////////////////////////////////////////////////////// +/// \brief Get the directory returned in a FTP directory response +/// +/// The returned const sfChar32* owns the string and must be freed to +/// avoid memory leaks. +/// +/// \param ftpDirectoryResponse Ftp directory response +/// +/// \return Directory name +/// +//////////////////////////////////////////////////////////// +CSFML_NETWORK_API const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(const sfFtpDirectoryResponse* ftpDirectoryResponse); + + //////////////////////////////////////////////////////////// /// \brief Destroy a FTP response /// diff --git a/include/SFML/System.h b/include/SFML/System.h index c5d7636..6faf790 100644 --- a/include/SFML/System.h +++ b/include/SFML/System.h @@ -33,9 +33,7 @@ #include #include #include -#include #include -#include #include #include #include diff --git a/include/SFML/System/Mutex.h b/include/SFML/System/Mutex.h deleted file mode 100644 index df1eb98..0000000 --- a/include/SFML/System/Mutex.h +++ /dev/null @@ -1,68 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_MUTEX_H -#define SFML_MUTEX_H - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -//////////////////////////////////////////////////////////// -/// \brief Create a new mutex -/// -/// \return A new sfMutex object -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API sfMutex* sfMutex_create(void); - -//////////////////////////////////////////////////////////// -/// \brief Destroy a mutex -/// -/// \param mutex Mutex to destroy -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API void sfMutex_destroy(sfMutex* mutex); - -//////////////////////////////////////////////////////////// -/// \brief Lock a mutex -/// -/// \param mutex Mutex object -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API void sfMutex_lock(sfMutex* mutex); - -//////////////////////////////////////////////////////////// -/// \brief Unlock a mutex -/// -/// \param mutex Mutex object -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API void sfMutex_unlock(sfMutex* mutex); - - -#endif // SFML_MUTEX_H diff --git a/include/SFML/System/Thread.h b/include/SFML/System/Thread.h deleted file mode 100644 index dfd88aa..0000000 --- a/include/SFML/System/Thread.h +++ /dev/null @@ -1,103 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREAD_H -#define SFML_THREAD_H - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include - - -//////////////////////////////////////////////////////////// -/// \brief Create a new thread from a function pointer -/// -/// Note: this does *not* run the thread, use sfThread_launch. -/// -/// \param function Entry point of the thread -/// \param userData Custom data to pass to the thread function -/// -/// \return A new sfThread object -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API sfThread* sfThread_create(void (*function)(void*), void* userData); - -//////////////////////////////////////////////////////////// -/// \brief Destroy a thread -/// -/// This function calls sfThread_wait, so that the internal thread -/// cannot survive after the sfThread object is destroyed. -/// -/// \param thread Thread to destroy -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API void sfThread_destroy(sfThread* thread); - -//////////////////////////////////////////////////////////// -/// \brief Run a thread -/// -/// This function starts the entry point passed to the -/// thread's constructor, and returns immediately. -/// After this function returns, the thread's function is -/// running in parallel to the calling code. -/// -/// \param thread Thread object -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API void sfThread_launch(sfThread* thread); - -//////////////////////////////////////////////////////////// -/// \brief Wait until a thread finishes -/// -/// This function will block the execution until the -/// thread's function ends. -/// Warning: if the thread function never ends, the calling -/// thread will block forever. -/// If this function is called from its owner thread, it -/// returns without doing anything. -/// -/// \param thread Thread object -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API void sfThread_wait(sfThread* thread); - -//////////////////////////////////////////////////////////// -/// \brief Terminate a thread -/// -/// This function immediately stops the thread, without waiting -/// for its function to finish. -/// Terminating a thread with this function is not safe, -/// and can lead to local variables not being destroyed -/// on some operating systems. You should rather try to make -/// the thread function terminate by itself. -/// -/// \param thread Thread object -/// -//////////////////////////////////////////////////////////// -CSFML_SYSTEM_API void sfThread_terminate(sfThread* thread); - - -#endif // SFML_THREAD_H diff --git a/include/SFML/Window/Clipboard.h b/include/SFML/Window/Clipboard.h index 95c73f0..0c074b4 100644 --- a/include/SFML/Window/Clipboard.h +++ b/include/SFML/Window/Clipboard.h @@ -55,7 +55,7 @@ CSFML_WINDOW_API const char* sfClipboard_getString(void); /// \return Clipboard contents as UTF-32 /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API const uint32_t* sfClipboard_getUnicodeString(void); +CSFML_WINDOW_API const sfChar32* sfClipboard_getUnicodeString(void); //////////////////////////////////////////////////////////// /// \brief Set the content of the clipboard as ANSI string data @@ -79,7 +79,6 @@ CSFML_WINDOW_API void sfClipboard_setString(const char* text); /// to the clipboard /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API void sfClipboard_setUnicodeString(const uint32_t* text); - +CSFML_WINDOW_API void sfClipboard_setUnicodeString(const sfChar32* text); #endif // SFML_CURSOR_H diff --git a/include/SFML/Window/Window.h b/include/SFML/Window/Window.h index 6c388a5..04b7945 100644 --- a/include/SFML/Window/Window.h +++ b/include/SFML/Window/Window.h @@ -81,12 +81,13 @@ typedef struct /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) /// \param title Title of the window /// \param style Window style +/// \param state Window state /// \param settings Additional settings for the underlying OpenGL context /// /// \return A new sfWindow object /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API sfWindow* sfWindow_create(sfVideoMode mode, const char* title, uint32_t style, const sfContextSettings* settings); +CSFML_WINDOW_API sfWindow* sfWindow_create(sfVideoMode mode, const char* title, uint32_t style, sfWindowState state, const sfContextSettings* settings); //////////////////////////////////////////////////////////// /// \brief Construct a new window (with a UTF-32 title) @@ -104,12 +105,13 @@ CSFML_WINDOW_API sfWindow* sfWindow_create(sfVideoMode mode, const char* title, /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) /// \param title Title of the window (UTF-32) /// \param style Window style +/// \param state Window state /// \param settings Additional settings for the underlying OpenGL context /// /// \return A new sfWindow object /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API sfWindow* sfWindow_createUnicode(sfVideoMode mode, const uint32_t* title, uint32_t style, const sfContextSettings* settings); +CSFML_WINDOW_API sfWindow* sfWindow_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style, sfWindowState state, const sfContextSettings* settings); //////////////////////////////////////////////////////////// /// \brief Construct a window from an existing control @@ -277,7 +279,7 @@ CSFML_WINDOW_API void sfWindow_setTitle(sfWindow* window, const char* title); /// \param title New title /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API void sfWindow_setUnicodeTitle(sfWindow* window, const uint32_t* title); +CSFML_WINDOW_API void sfWindow_setUnicodeTitle(sfWindow* window, const sfChar32* title); //////////////////////////////////////////////////////////// /// \brief Change a window's icon @@ -472,7 +474,7 @@ CSFML_WINDOW_API void sfWindow_display(sfWindow* window); /// \return System handle of the window /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API sfWindowHandle sfWindow_getSystemHandle(const sfWindow* window); +CSFML_WINDOW_API sfWindowHandle sfWindow_getNativeHandle(const sfWindow* window); #endif // SFML_WINDOW_H diff --git a/include/SFML/Window/WindowBase.h b/include/SFML/Window/WindowBase.h index 97c3197..f090ed7 100644 --- a/include/SFML/Window/WindowBase.h +++ b/include/SFML/Window/WindowBase.h @@ -47,11 +47,22 @@ typedef enum sfTitlebar = 1 << 0, ///< Title bar + fixed border sfResize = 1 << 1, ///< Titlebar + resizable border + maximize button sfClose = 1 << 2, ///< Titlebar + close button - sfFullscreen = 1 << 3, ///< Fullscreen mode (this flag and all others are mutually exclusive) + sfDefaultStyle = sfTitlebar | sfResize | sfClose ///< Default window style } sfWindowStyle; +//////////////////////////////////////////////////////////// +/// \brief Enumeration of the window states +/// +//////////////////////////////////////////////////////////// +typedef enum +{ + sfWindowed, //!< Floating window + sfFullscreen //!< Fullscreen window +} sfWindowState; + + //////////////////////////////////////////////////////////// /// \brief Construct a new window /// @@ -86,7 +97,7 @@ CSFML_WINDOW_API sfWindowBase* sfWindowBase_create(sfVideoMode mode, const char* /// \return A new sfWindow object /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API sfWindowBase* sfWindowBase_createUnicode(sfVideoMode mode, const uint32_t* title, uint32_t style); +CSFML_WINDOW_API sfWindowBase* sfWindowBase_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style); //////////////////////////////////////////////////////////// /// \brief Construct a window from an existing control @@ -231,7 +242,7 @@ CSFML_WINDOW_API void sfWindowBase_setTitle(sfWindowBase* windowBase, const char /// \param title New title /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API void sfWindowBase_setUnicodeTitle(sfWindowBase* windowBase, const uint32_t* title); +CSFML_WINDOW_API void sfWindowBase_setUnicodeTitle(sfWindowBase* windowBase, const sfChar32* title); //////////////////////////////////////////////////////////// /// \brief Change a window's icon @@ -366,7 +377,7 @@ CSFML_WINDOW_API bool sfWindowBase_hasFocus(const sfWindowBase* windowBase); /// \return System handle of the window /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API sfWindowHandle sfWindowBase_getSystemHandle(const sfWindowBase* windowBase); +CSFML_WINDOW_API sfWindowHandle sfWindowBase_getNativeHandle(const sfWindowBase* windowBase); //////////////////////////////////////////////////////////// /// \brief Create a Vulkan rendering surface diff --git a/src/SFML/Audio/CMakeLists.txt b/src/SFML/Audio/CMakeLists.txt index 38999ed..9c893d7 100644 --- a/src/SFML/Audio/CMakeLists.txt +++ b/src/SFML/Audio/CMakeLists.txt @@ -32,4 +32,4 @@ set(SRC # define the csfml-audio target csfml_add_library(csfml-audio SOURCES ${SRC} - DEPENDS sfml-audio) + DEPENDS SFML::Audio) diff --git a/src/SFML/Audio/Listener.cpp b/src/SFML/Audio/Listener.cpp index f27f262..ae8283c 100644 --- a/src/SFML/Audio/Listener.cpp +++ b/src/SFML/Audio/Listener.cpp @@ -47,7 +47,7 @@ float sfListener_getGlobalVolume(void) //////////////////////////////////////////////////////////// void sfListener_setPosition(sfVector3f position) { - sf::Listener::setPosition(position.x, position.y, position.z); + sf::Listener::setPosition({ position.x, position.y, position.z }); } @@ -63,7 +63,7 @@ sfVector3f sfListener_getPosition() //////////////////////////////////////////////////////////// void sfListener_setDirection(sfVector3f direction) { - sf::Listener::setDirection(direction.x, direction.y, direction.z); + sf::Listener::setDirection({ direction.x, direction.y, direction.z }); } @@ -79,7 +79,7 @@ sfVector3f sfListener_getDirection() //////////////////////////////////////////////////////////// void sfListener_setUpVector(sfVector3f upVector) { - sf::Listener::setUpVector(upVector.x, upVector.y, upVector.z); + sf::Listener::setUpVector({ upVector.x, upVector.y, upVector.z }); } diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index f0aed6e..17f6ef4 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -125,8 +125,8 @@ sfTimeSpan sfMusic_getLoopPoints(const sfMusic* music) //////////////////////////////////////////////////////////// void sfMusic_setLoopPoints(sfMusic* music, sfTimeSpan timePoints) { - CSFML_CALL(music, setLoopPoints(sf::Music::TimeSpan(sf::microseconds(timePoints.offset.microseconds), - sf::microseconds(timePoints.length.microseconds)))); + CSFML_CALL(music, setLoopPoints(sf::Music::TimeSpan({ sf::microseconds(timePoints.offset.microseconds), + sf::microseconds(timePoints.length.microseconds)}))); } diff --git a/src/SFML/Audio/Sound.cpp b/src/SFML/Audio/Sound.cpp index 3fd7661..7c9e8b3 100644 --- a/src/SFML/Audio/Sound.cpp +++ b/src/SFML/Audio/Sound.cpp @@ -31,9 +31,11 @@ //////////////////////////////////////////////////////////// -sfSound* sfSound_create(void) +sfSound* sfSound_create(const sfSoundBuffer* buffer) { - return new sfSound; + CSFML_CHECK_RETURN(buffer, nullptr); + + return new sfSound{ sf::Sound{ buffer->This }, buffer }; } diff --git a/src/SFML/Audio/SoundRecorderStruct.h b/src/SFML/Audio/SoundRecorderStruct.h index 2e70516..5e09c43 100644 --- a/src/SFML/Audio/SoundRecorderStruct.h +++ b/src/SFML/Audio/SoundRecorderStruct.h @@ -66,7 +66,7 @@ private : return true; } - bool onProcessSamples(const sf::Int16* samples, std::size_t sampleCount) override + bool onProcessSamples(const std::int16_t* samples, std::size_t sampleCount) override { if (myProcessCallback) return myProcessCallback(samples, sampleCount, myUserData); diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index ee87315..1065ec1 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -109,7 +109,7 @@ void sfSoundStream_setVolume(sfSoundStream* soundStream, float volume) //////////////////////////////////////////////////////////// void sfSoundStream_setPosition(sfSoundStream* soundStream, sfVector3f position) { - CSFML_CALL(soundStream, setPosition(position.x, position.y, position.z)); + CSFML_CALL(soundStream, setPosition({ position.x, position.y, position.z })); } diff --git a/src/SFML/CMakeLists.txt b/src/SFML/CMakeLists.txt index 251204d..8601251 100644 --- a/src/SFML/CMakeLists.txt +++ b/src/SFML/CMakeLists.txt @@ -21,7 +21,7 @@ if(CSFML_LINK_SFML_STATICALLY) set(SFML_STATIC_LIBRARIES TRUE) add_definitions(-DSFML_STATIC) endif() -find_package(SFML 2.6 COMPONENTS network graphics audio REQUIRED) +find_package(SFML 3.0.0 COMPONENTS Network Graphics Audio REQUIRED) # add the modules subdirectories add_subdirectory(System) diff --git a/src/SFML/CallbackStream.h b/src/SFML/CallbackStream.h index 4cd5419..a2a370e 100644 --- a/src/SFML/CallbackStream.h +++ b/src/SFML/CallbackStream.h @@ -66,7 +66,7 @@ public: /// \return The number of bytes actually read /// //////////////////////////////////////////////////////////// - sf::Int64 read(void* data, sf::Int64 size) override + std::int64_t read(void* data, std::int64_t size) override { return myStream.read ? myStream.read(data, size, myStream.userData) : -1; } @@ -79,7 +79,7 @@ public: /// \return The position actually seeked to, or -1 on error /// //////////////////////////////////////////////////////////// - sf::Int64 seek(sf::Int64 position) override + std::int64_t seek(std::int64_t position) override { return myStream.seek ? myStream.seek(position, myStream.userData) : -1; } @@ -90,7 +90,7 @@ public: /// \return The current position, or -1 on error. /// //////////////////////////////////////////////////////////// - sf::Int64 tell() override + std::int64_t tell() override { return myStream.tell ? myStream.tell(myStream.userData) : -1; } @@ -101,7 +101,7 @@ public: /// \return The total number of bytes available in the stream, or -1 on error /// //////////////////////////////////////////////////////////// - sf::Int64 getSize() override + std::int64_t getSize() override { return myStream.getSize ? myStream.getSize(myStream.userData) : -1; } diff --git a/src/SFML/System/Mutex.cpp b/src/SFML/Char32.hpp similarity index 73% rename from src/SFML/System/Mutex.cpp rename to src/SFML/Char32.hpp index cf83711..09fab98 100644 --- a/src/SFML/System/Mutex.cpp +++ b/src/SFML/Char32.hpp @@ -22,37 +22,28 @@ // //////////////////////////////////////////////////////////// +#ifndef SFML_CHAR32_HPP +#define SFML_CHAR32_HPP + //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include -#include -#include +#include +#include +#include //////////////////////////////////////////////////////////// -sfMutex* sfMutex_create(void) -{ - return new sfMutex; -} - - +// Define utils to copy from / to sfChar32 and sf::String //////////////////////////////////////////////////////////// -void sfMutex_destroy(sfMutex* mutex) +inline sfChar32* copyToChar32(const sf::String& str) { - delete mutex; + std::size_t byteCount = sizeof(sfChar32) * str.getSize(); + sfChar32* utf32 = static_cast(malloc(byteCount + sizeof(sfChar32))); + memcpy(utf32, str.getData(), byteCount); + utf32[str.getSize()] = 0; + + return utf32; } - -//////////////////////////////////////////////////////////// -void sfMutex_lock(sfMutex* mutex) -{ - CSFML_CALL(mutex, lock()); -} - - -//////////////////////////////////////////////////////////// -void sfMutex_unlock(sfMutex* mutex) -{ - CSFML_CALL(mutex, unlock()); -} +#endif // SFML_CHAR32_HPP diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index c358fd8..72e0567 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -73,4 +73,4 @@ set(SRC # define the csfml-graphics target csfml_add_library(csfml-graphics SOURCES ${SRC} - DEPENDS sfml-graphics) + DEPENDS SFML::Graphics) diff --git a/src/SFML/Graphics/CircleShape.cpp b/src/SFML/Graphics/CircleShape.cpp index a5b1e51..9716621 100644 --- a/src/SFML/Graphics/CircleShape.cpp +++ b/src/SFML/Graphics/CircleShape.cpp @@ -61,28 +61,28 @@ void sfCircleShape_destroy(sfCircleShape* shape) //////////////////////////////////////////////////////////// void sfCircleShape_setPosition(sfCircleShape* shape, sfVector2f position) { - CSFML_CALL(shape, setPosition(position.x, position.y)); + CSFML_CALL(shape, setPosition({ position.x, position.y })); } //////////////////////////////////////////////////////////// void sfCircleShape_setRotation(sfCircleShape* shape, float angle) { - CSFML_CALL(shape, setRotation(angle)); + CSFML_CALL(shape, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfCircleShape_setScale(sfCircleShape* shape, sfVector2f scale) { - CSFML_CALL(shape, setScale(scale.x, scale.y)); + CSFML_CALL(shape, setScale({ scale.x, scale.y })); } //////////////////////////////////////////////////////////// void sfCircleShape_setOrigin(sfCircleShape* shape, sfVector2f origin) { - CSFML_CALL(shape, setOrigin(origin.x, origin.y)); + CSFML_CALL(shape, setOrigin({ origin.x, origin.y })); } @@ -103,7 +103,7 @@ sfVector2f sfCircleShape_getPosition(const sfCircleShape* shape) //////////////////////////////////////////////////////////// float sfCircleShape_getRotation(const sfCircleShape* shape) { - CSFML_CALL_RETURN(shape, getRotation(), 0.f); + CSFML_CALL_RETURN(shape, getRotation().asDegrees(), 0.f); } @@ -138,21 +138,21 @@ sfVector2f sfCircleShape_getOrigin(const sfCircleShape* shape) //////////////////////////////////////////////////////////// void sfCircleShape_move(sfCircleShape* shape, sfVector2f offset) { - CSFML_CALL(shape, move(offset.x, offset.y)); + CSFML_CALL(shape, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfCircleShape_rotate(sfCircleShape* shape, float angle) { - CSFML_CALL(shape, rotate(angle)); + CSFML_CALL(shape, rotate(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfCircleShape_scale(sfCircleShape* shape, sfVector2f factors) { - CSFML_CALL(shape, scale(factors.x, factors.y)); + CSFML_CALL(shape, scale({ factors.x, factors.y })); } @@ -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.left, rect.top }, { rect.width, rect.height }))); } diff --git a/src/SFML/Graphics/ConvexShape.cpp b/src/SFML/Graphics/ConvexShape.cpp index c1317e1..c56bfbf 100644 --- a/src/SFML/Graphics/ConvexShape.cpp +++ b/src/SFML/Graphics/ConvexShape.cpp @@ -58,28 +58,28 @@ void sfConvexShape_destroy(sfConvexShape* shape) //////////////////////////////////////////////////////////// void sfConvexShape_setPosition(sfConvexShape* shape, sfVector2f position) { - CSFML_CALL(shape, setPosition(position.x, position.y)); + CSFML_CALL(shape, setPosition({ position.x, position.y })); } //////////////////////////////////////////////////////////// void sfConvexShape_setRotation(sfConvexShape* shape, float angle) { - CSFML_CALL(shape, setRotation(angle)); + CSFML_CALL(shape, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfConvexShape_setScale(sfConvexShape* shape, sfVector2f scale) { - CSFML_CALL(shape, setScale(scale.x, scale.y)); + CSFML_CALL(shape, setScale({ scale.x, scale.y })); } //////////////////////////////////////////////////////////// void sfConvexShape_setOrigin(sfConvexShape* shape, sfVector2f origin) { - CSFML_CALL(shape, setOrigin(origin.x, origin.y)); + CSFML_CALL(shape, setOrigin({ origin.x, origin.y })); } @@ -100,7 +100,7 @@ sfVector2f sfConvexShape_getPosition(const sfConvexShape* shape) //////////////////////////////////////////////////////////// float sfConvexShape_getRotation(const sfConvexShape* shape) { - CSFML_CALL_RETURN(shape, getRotation(), 0.f); + CSFML_CALL_RETURN(shape, getRotation().asDegrees(), 0.f); } @@ -135,21 +135,21 @@ sfVector2f sfConvexShape_getOrigin(const sfConvexShape* shape) //////////////////////////////////////////////////////////// void sfConvexShape_move(sfConvexShape* shape, sfVector2f offset) { - CSFML_CALL(shape, move(offset.x, offset.y)); + CSFML_CALL(shape, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfConvexShape_rotate(sfConvexShape* shape, float angle) { - CSFML_CALL(shape, rotate(angle)); + CSFML_CALL(shape, rotate(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfConvexShape_scale(sfConvexShape* shape, sfVector2f factors) { - CSFML_CALL(shape, scale(factors.x, factors.y)); + CSFML_CALL(shape, scale({ factors.x, factors.y })); } @@ -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.left, rect.top }, { rect.width, rect.height }))); } diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 7fc4864..bff6180 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -36,7 +36,7 @@ sfImage* sfImage_create(unsigned int width, unsigned int height) { sfImage* image = new sfImage; - image->This.create(width, height); + image->This.create({ width, height }); return image; } @@ -46,7 +46,7 @@ sfImage* sfImage_create(unsigned int width, unsigned int height) sfImage* sfImage_createFromColor(unsigned int width, unsigned int height, sfColor color) { sfImage* image = new sfImage; - image->This.create(width, height, sf::Color(color.r, color.g, color.b, color.a)); + image->This.create({ width, height }, sf::Color(color.r, color.g, color.b, color.a)); return image; } @@ -56,7 +56,7 @@ sfImage* sfImage_createFromColor(unsigned int width, unsigned int height, sfColo sfImage* sfImage_createFromPixels(unsigned int width, unsigned int height, const uint8_t* data) { sfImage* image = new sfImage; - image->This.create(width, height, data); + image->This.create({ width, height }, data); return image; } @@ -137,7 +137,17 @@ bool sfImage_saveToFile(const sfImage* image, const char* filename) bool sfImage_saveToMemory(const sfImage* image, sfBuffer* output, const char* format) { CSFML_CHECK_RETURN(output, false); - CSFML_CALL_RETURN(image, saveToMemory(output->buffer, format), false); + CSFML_CHECK_RETURN(image, false); + + auto data = image->This.saveToMemory(format); + + if (data) + { + output->buffer = std::move(*data); + return true; + } + + return false; } @@ -149,18 +159,21 @@ void sfImage_createMaskFromColor(sfImage* image, sfColor colorKey, uint8_t alpha //////////////////////////////////////////////////////////// -void sfImage_copyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect, bool applyAlpha) +bool sfImage_copyImage(sfImage* image, const sfImage* source, unsigned int destX, unsigned int destY, sfIntRect sourceRect, bool applyAlpha) { - CSFML_CHECK(source); - sf::IntRect sfmlRect(sourceRect.left, sourceRect.top, sourceRect.width, sourceRect.height); - CSFML_CALL(image, copy(source->This, destX, destY, sfmlRect, applyAlpha)); + CSFML_CHECK_RETURN(image, false); + CSFML_CHECK_RETURN(source, false); + + sf::IntRect sfmlRect({ sourceRect.left, sourceRect.top }, { sourceRect.width, sourceRect.height }); + + return image->This.copy(source->This, { destX, destY }, sfmlRect, applyAlpha); } //////////////////////////////////////////////////////////// void sfImage_setPixel(sfImage* image, unsigned int x, unsigned int y, sfColor color) { - CSFML_CALL(image, setPixel(x, y, sf::Color(color.r, color.g, color.b, color.a))); + CSFML_CALL(image, setPixel({ x, y }, sf::Color(color.r, color.g, color.b, color.a))); } @@ -170,7 +183,7 @@ sfColor sfImage_getPixel(const sfImage* image, unsigned int x, unsigned int y) sfColor color = {0, 0, 0, 0}; CSFML_CHECK_RETURN(image, color); - sf::Color sfmlColor = image->This.getPixel(x, y); + sf::Color sfmlColor = image->This.getPixel({ x, y }); return sfColor_fromRGBA(sfmlColor.r, sfmlColor.g, sfmlColor.b, sfmlColor.a); } diff --git a/src/SFML/Graphics/Rect.cpp b/src/SFML/Graphics/Rect.cpp index 5198ed6..887d044 100644 --- a/src/SFML/Graphics/Rect.cpp +++ b/src/SFML/Graphics/Rect.cpp @@ -51,12 +51,12 @@ sfVector2i toCType(const sf::Vector2i& vector) 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->left, rect->top }, { rect->width, rect->height }).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->left, rect->top }, { rect->width, rect->height }).contains({ x, y }); } @@ -68,24 +68,26 @@ 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->left, rect1->top }, { rect1->width, rect1->height }); + sf::FloatRect SFMLRect2({ rect2->left, rect2->top }, { rect2->width, rect2->height }); if (intersection) { - sf::FloatRect overlap; - bool intersects = SFMLRect1.intersects(SFMLRect2, overlap); + std::optional overlap = SFMLRect1.findIntersection(SFMLRect2); - intersection->left = overlap.left; - intersection->top = overlap.top; - intersection->width = overlap.width; - intersection->height = overlap.height; + if (overlap) + { + intersection->left = overlap->left; + intersection->top = overlap->top; + intersection->width = overlap->width; + intersection->height = overlap->height; + } - return intersects; + return overlap.has_value(); } else { - return SFMLRect1.intersects(SFMLRect2); + return SFMLRect1.findIntersection(SFMLRect2).has_value(); } } bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntRect* intersection) @@ -93,24 +95,26 @@ 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->left, rect1->top }, { rect1->width, rect1->height }); + sf::IntRect SFMLRect2({ rect2->left, rect2->top }, { rect2->width, rect2->height }); if (intersection) { - sf::IntRect overlap; - bool intersects = SFMLRect1.intersects(SFMLRect2, overlap); + std::optional overlap = SFMLRect1.findIntersection(SFMLRect2); - intersection->left = overlap.left; - intersection->top = overlap.top; - intersection->width = overlap.width; - intersection->height = overlap.height; + if (overlap) + { + intersection->left = overlap->left; + intersection->top = overlap->top; + intersection->width = overlap->width; + intersection->height = overlap->height; + } - return intersects; + return overlap.has_value(); } else { - return SFMLRect1.intersects(SFMLRect2); + return SFMLRect1.findIntersection(SFMLRect2).has_value(); } } @@ -120,11 +124,11 @@ bool sfIntRect_intersects(const sfIntRect* rect1, const sfIntRect* rect2, sfIntR //////////////////////////////////////////////////////////// sfVector2f sfFloatRect_getPosition(const sfFloatRect* rect) { - return toCType(sf::FloatRect(rect->left, rect->top, rect->width, rect->height).getPosition()); + 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()); + return toCType(sf::IntRect({ rect->left, rect->top }, { rect->width, rect->height }).getPosition()); } @@ -133,9 +137,9 @@ sfVector2i sfIntRect_getPosition(const sfIntRect* rect) //////////////////////////////////////////////////////////// sfVector2f sfFloatRect_getSize(const sfFloatRect* rect) { - return toCType(sf::FloatRect(rect->left, rect->top, rect->width, rect->height).getSize()); + 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()); + return toCType(sf::IntRect({ rect->left, rect->top }, { rect->width, rect->height }).getSize()); } diff --git a/src/SFML/Graphics/RectangleShape.cpp b/src/SFML/Graphics/RectangleShape.cpp index 98075dd..fe1c433 100644 --- a/src/SFML/Graphics/RectangleShape.cpp +++ b/src/SFML/Graphics/RectangleShape.cpp @@ -58,28 +58,28 @@ void sfRectangleShape_destroy(sfRectangleShape* shape) //////////////////////////////////////////////////////////// void sfRectangleShape_setPosition(sfRectangleShape* shape, sfVector2f position) { - CSFML_CALL(shape, setPosition(position.x, position.y)); + CSFML_CALL(shape, setPosition({ position.x, position.y })); } //////////////////////////////////////////////////////////// void sfRectangleShape_setRotation(sfRectangleShape* shape, float angle) { - CSFML_CALL(shape, setRotation(angle)); + CSFML_CALL(shape, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfRectangleShape_setScale(sfRectangleShape* shape, sfVector2f scale) { - CSFML_CALL(shape, setScale(scale.x, scale.y)); + CSFML_CALL(shape, setScale({ scale.x, scale.y })); } //////////////////////////////////////////////////////////// void sfRectangleShape_setOrigin(sfRectangleShape* shape, sfVector2f origin) { - CSFML_CALL(shape, setOrigin(origin.x, origin.y)); + CSFML_CALL(shape, setOrigin({ origin.x, origin.y })); } @@ -100,7 +100,7 @@ sfVector2f sfRectangleShape_getPosition(const sfRectangleShape* shape) //////////////////////////////////////////////////////////// float sfRectangleShape_getRotation(const sfRectangleShape* shape) { - CSFML_CALL_RETURN(shape, getRotation(), 0.f); + CSFML_CALL_RETURN(shape, getRotation().asDegrees(), 0.f); } @@ -135,21 +135,21 @@ sfVector2f sfRectangleShape_getOrigin(const sfRectangleShape* shape) //////////////////////////////////////////////////////////// void sfRectangleShape_move(sfRectangleShape* shape, sfVector2f offset) { - CSFML_CALL(shape, move(offset.x, offset.y)); + CSFML_CALL(shape, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfRectangleShape_rotate(sfRectangleShape* shape, float angle) { - CSFML_CALL(shape, rotate(angle)); + CSFML_CALL(shape, rotate(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfRectangleShape_scale(sfRectangleShape* shape, sfVector2f factors) { - CSFML_CALL(shape, scale(factors.x, factors.y)); + CSFML_CALL(shape, scale({ factors.x, factors.y })); } @@ -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.left, rect.top }, { rect.width, rect.height }))); } diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index fabb278..f36f29c 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -41,20 +41,7 @@ //////////////////////////////////////////////////////////// -sfRenderTexture* sfRenderTexture_create(unsigned int width, unsigned int height, bool depthBuffer) -{ - sfRenderTexture* renderTexture = new sfRenderTexture; - renderTexture->This.create(width, height, depthBuffer); - renderTexture->Target = new sfTexture(const_cast(&renderTexture->This.getTexture())); - renderTexture->DefaultView.This = renderTexture->This.getDefaultView(); - renderTexture->CurrentView.This = renderTexture->This.getView(); - - return renderTexture; -} - - -//////////////////////////////////////////////////////////// -sfRenderTexture* sfRenderTexture_createWithSettings(unsigned int width, unsigned int height, const sfContextSettings* settings) +sfRenderTexture* sfRenderTexture_create(unsigned int width, unsigned int height, const sfContextSettings* settings) { // Convert context settings sf::ContextSettings params; @@ -65,7 +52,13 @@ sfRenderTexture* sfRenderTexture_createWithSettings(unsigned int width, unsigned // Create the render texture sfRenderTexture* renderTexture = new sfRenderTexture; - renderTexture->This.create(width, height, params); + + if (!renderTexture->This.create({ width, height }, params)) + { + delete renderTexture; + return nullptr; + } + renderTexture->Target = new sfTexture(const_cast(&renderTexture->This.getTexture())); renderTexture->DefaultView.This = renderTexture->This.getDefaultView(); renderTexture->CurrentView.This = renderTexture->This.getView(); diff --git a/src/SFML/Graphics/RenderWindow.cpp b/src/SFML/Graphics/RenderWindow.cpp index bd651d2..6e39024 100644 --- a/src/SFML/Graphics/RenderWindow.cpp +++ b/src/SFML/Graphics/RenderWindow.cpp @@ -45,10 +45,10 @@ //////////////////////////////////////////////////////////// -sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint32_t style, const sfContextSettings* settings) +sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint32_t style, sfWindowState state, const sfContextSettings* settings) { // Convert video mode - sf::VideoMode videoMode(mode.width, mode.height, mode.bitsPerPixel); + sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel); // Convert context settings sf::ContextSettings params; @@ -59,7 +59,7 @@ sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint3 // Create the window sfRenderWindow* renderWindow = new sfRenderWindow; - renderWindow->This.create(videoMode, title, style, params); + renderWindow->This.create(videoMode, title, style, static_cast(state), params); renderWindow->DefaultView.This = renderWindow->This.getDefaultView(); renderWindow->CurrentView.This = renderWindow->This.getView(); @@ -67,10 +67,10 @@ sfRenderWindow* sfRenderWindow_create(sfVideoMode mode, const char* title, uint3 } //////////////////////////////////////////////////////////// -sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const uint32_t* title, uint32_t style, const sfContextSettings* settings) +sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style, sfWindowState state, const sfContextSettings* settings) { // Convert video mode - sf::VideoMode videoMode(mode.width, mode.height, mode.bitsPerPixel); + sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel); // Convert context settings sf::ContextSettings params; @@ -81,7 +81,7 @@ sfRenderWindow* sfRenderWindow_createUnicode(sfVideoMode mode, const uint32_t* t // Create the window sfRenderWindow* renderWindow = new sfRenderWindow; - renderWindow->This.create(videoMode, title, style, params); + renderWindow->This.create(videoMode, reinterpret_cast(title), style, static_cast(state), params); renderWindow->DefaultView.This = renderWindow->This.getDefaultView(); renderWindow->CurrentView.This = renderWindow->This.getView(); @@ -243,16 +243,16 @@ void sfRenderWindow_setTitle(sfRenderWindow* renderWindow, const char* title) //////////////////////////////////////////////////////////// -void sfRenderWindow_setUnicodeTitle(sfRenderWindow* renderWindow, const uint32_t* title) +void sfRenderWindow_setUnicodeTitle(sfRenderWindow* renderWindow, const sfChar32* title) { - CSFML_CALL(renderWindow, setTitle(title)); + CSFML_CALL(renderWindow, setTitle(reinterpret_cast(title))); } //////////////////////////////////////////////////////////// void sfRenderWindow_setIcon(sfRenderWindow* renderWindow, unsigned int width, unsigned int height, const uint8_t* pixels) { - CSFML_CALL(renderWindow, setIcon(width, height, pixels)); + CSFML_CALL(renderWindow, setIcon({ width, height }, pixels)); } @@ -343,11 +343,11 @@ void sfRenderWindow_setJoystickThreshold(sfRenderWindow* renderWindow, float thr //////////////////////////////////////////////////////////// -sfWindowHandle sfRenderWindow_getSystemHandle(const sfRenderWindow* renderWindow) +sfWindowHandle sfRenderWindow_getNativeHandle(const sfRenderWindow* renderWindow) { CSFML_CHECK_RETURN(renderWindow, 0); - return static_cast(renderWindow->This.getSystemHandle()); + return static_cast(renderWindow->This.getNativeHandle()); } diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 144b36c..01b85da 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -45,12 +45,12 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* if (!vertexShaderFilename) { // fragment shader only - success = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Fragment); + success = shader->This.loadFromFile(fragmentShaderFilename, sf::Shader::Type::Fragment); } else if (!fragmentShaderFilename) { // vertex shader only - success = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Vertex); + success = shader->This.loadFromFile(vertexShaderFilename, sf::Shader::Type::Vertex); } else { @@ -63,7 +63,7 @@ sfShader* sfShader_createFromFile(const char* vertexShaderFilename, const char* if (!vertexShaderFilename && !fragmentShaderFilename) { // geometry shader only - success = shader->This.loadFromFile(geometryShaderFilename, sf::Shader::Geometry); + success = shader->This.loadFromFile(geometryShaderFilename, sf::Shader::Type::Geometry); } else { @@ -95,12 +95,12 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geomet if (!vertexShader) { // fragment shader only - success = shader->This.loadFromMemory(fragmentShader, sf::Shader::Fragment); + success = shader->This.loadFromMemory(fragmentShader, sf::Shader::Type::Fragment); } else if (!fragmentShader) { // vertex shader only - success = shader->This.loadFromMemory(vertexShader, sf::Shader::Vertex); + success = shader->This.loadFromMemory(vertexShader, sf::Shader::Type::Vertex); } else { @@ -113,7 +113,7 @@ sfShader* sfShader_createFromMemory(const char* vertexShader, const char* geomet if (!vertexShader && !fragmentShader) { // geometry shader only - success = shader->This.loadFromMemory(geometryShader, sf::Shader::Geometry); + success = shader->This.loadFromMemory(geometryShader, sf::Shader::Type::Geometry); } else { @@ -146,13 +146,13 @@ sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputSt { // fragment shader only CallbackStream stream(fragmentShaderStream); - success = shader->This.loadFromStream(stream, sf::Shader::Fragment); + success = shader->This.loadFromStream(stream, sf::Shader::Type::Fragment); } else if (!fragmentShaderStream) { // vertex shader only CallbackStream stream(vertexShaderStream); - success = shader->This.loadFromStream(stream, sf::Shader::Vertex); + success = shader->This.loadFromStream(stream, sf::Shader::Type::Vertex); } else { @@ -168,7 +168,7 @@ sfShader* sfShader_createFromStream(sfInputStream* vertexShaderStream, sfInputSt if (!vertexShaderStream && !fragmentShaderStream) { // geometry shader only - success = shader->This.loadFromStream(geometryStream, sf::Shader::Geometry); + success = shader->This.loadFromStream(geometryStream, sf::Shader::Type::Geometry); } else { @@ -379,7 +379,7 @@ void sfShader_setMat4UniformArray(sfShader* shader, const char* name, const sfGl void sfShader_setTextureParameter(sfShader* shader, const char* name, const sfTexture* texture) { CSFML_CHECK(texture); - CSFML_CALL(shader, setParameter(name,*texture->This)); + CSFML_CALL(shader, setUniform(name, *texture->This)); } diff --git a/src/SFML/Graphics/Shape.cpp b/src/SFML/Graphics/Shape.cpp index 9bc7b66..6177e75 100644 --- a/src/SFML/Graphics/Shape.cpp +++ b/src/SFML/Graphics/Shape.cpp @@ -51,28 +51,28 @@ void sfShape_destroy(sfShape* shape) //////////////////////////////////////////////////////////// void sfShape_setPosition(sfShape* shape, sfVector2f position) { - CSFML_CALL(shape, setPosition(position.x, position.y)); + CSFML_CALL(shape, setPosition({ position.x, position.y })); } //////////////////////////////////////////////////////////// void sfShape_setRotation(sfShape* shape, float angle) { - CSFML_CALL(shape, setRotation(angle)); + CSFML_CALL(shape, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfShape_setScale(sfShape* shape, sfVector2f scale) { - CSFML_CALL(shape, setScale(scale.x, scale.y)); + CSFML_CALL(shape, setScale({ scale.x, scale.y })); } //////////////////////////////////////////////////////////// void sfShape_setOrigin(sfShape* shape, sfVector2f origin) { - CSFML_CALL(shape, setOrigin(origin.x, origin.y)); + CSFML_CALL(shape, setOrigin({ origin.x, origin.y })); } @@ -93,7 +93,7 @@ sfVector2f sfShape_getPosition(const sfShape* shape) //////////////////////////////////////////////////////////// float sfShape_getRotation(const sfShape* shape) { - CSFML_CALL_RETURN(shape, getRotation(), 0.f); + CSFML_CALL_RETURN(shape, getRotation().asDegrees(), 0.f); } @@ -128,21 +128,21 @@ sfVector2f sfShape_getOrigin(const sfShape* shape) //////////////////////////////////////////////////////////// void sfShape_move(sfShape* shape, sfVector2f offset) { - CSFML_CALL(shape, move(offset.x, offset.y)); + CSFML_CALL(shape, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfShape_rotate(sfShape* shape, float angle) { - CSFML_CALL(shape, rotate(angle)); + CSFML_CALL(shape, rotate(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfShape_scale(sfShape* shape, sfVector2f factors) { - CSFML_CALL(shape, scale(factors.x, factors.y)); + CSFML_CALL(shape, scale({ factors.x, factors.y })); } @@ -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.left, rect.top }, { rect.width, rect.height }))); } diff --git a/src/SFML/Graphics/Sprite.cpp b/src/SFML/Graphics/Sprite.cpp index 7000343..9e12667 100644 --- a/src/SFML/Graphics/Sprite.cpp +++ b/src/SFML/Graphics/Sprite.cpp @@ -34,12 +34,12 @@ //////////////////////////////////////////////////////////// -sfSprite* sfSprite_create(void) +sfSprite* sfSprite_create(const sfTexture* texture) { - sfSprite* sprite = new sfSprite; - sprite->Texture = nullptr; + CSFML_CHECK_RETURN(texture, nullptr); + CSFML_CHECK_RETURN(texture->This, nullptr); - return sprite; + return new sfSprite{ sf::Sprite{*texture->This}, texture, {}, {} }; } @@ -62,28 +62,28 @@ void sfSprite_destroy(sfSprite* sprite) //////////////////////////////////////////////////////////// void sfSprite_setPosition(sfSprite* sprite, sfVector2f position) { - CSFML_CALL(sprite, setPosition(position.x, position.y)); + CSFML_CALL(sprite, setPosition({ position.x, position.y })); } //////////////////////////////////////////////////////////// void sfSprite_setRotation(sfSprite* sprite, float angle) { - CSFML_CALL(sprite, setRotation(angle)); + CSFML_CALL(sprite, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfSprite_setScale(sfSprite* sprite, sfVector2f scale) { - CSFML_CALL(sprite, setScale(scale.x, scale.y)); + CSFML_CALL(sprite, setScale({ scale.x, scale.y })); } //////////////////////////////////////////////////////////// void sfSprite_setOrigin(sfSprite* sprite, sfVector2f origin) { - CSFML_CALL(sprite, setOrigin(origin.x, origin.y)); + CSFML_CALL(sprite, setOrigin({ origin.x, origin.y })); } @@ -104,7 +104,7 @@ sfVector2f sfSprite_getPosition(const sfSprite* sprite) //////////////////////////////////////////////////////////// float sfSprite_getRotation(const sfSprite* sprite) { - CSFML_CALL_RETURN(sprite, getRotation(), 0.f); + CSFML_CALL_RETURN(sprite, getRotation().asDegrees(), 0.f); } @@ -139,21 +139,21 @@ sfVector2f sfSprite_getOrigin(const sfSprite* sprite) //////////////////////////////////////////////////////////// void sfSprite_move(sfSprite* sprite, sfVector2f offset) { - CSFML_CALL(sprite, move(offset.x, offset.y)); + CSFML_CALL(sprite, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfSprite_rotate(sfSprite* sprite, float angle) { - CSFML_CALL(sprite, rotate(angle)); + CSFML_CALL(sprite, rotate(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfSprite_scale(sfSprite* sprite, sfVector2f factors) { - CSFML_CALL(sprite, scale(factors.x, factors.y)); + CSFML_CALL(sprite, scale({ factors.x, factors.y })); } @@ -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.left, rectangle.top }, { rectangle.width, rectangle.height }))); } diff --git a/src/SFML/Graphics/Text.cpp b/src/SFML/Graphics/Text.cpp index db76bcf..1bb51d8 100644 --- a/src/SFML/Graphics/Text.cpp +++ b/src/SFML/Graphics/Text.cpp @@ -34,12 +34,11 @@ //////////////////////////////////////////////////////////// -sfText* sfText_create(void) +sfText* sfText_create(const sfFont* font) { - sfText* text = new sfText; - text->Font = nullptr; + CSFML_CHECK_RETURN(font, nullptr); - return text; + return new sfText{ sf::Text{font->This}, font, {}, {}, {} }; } @@ -62,28 +61,28 @@ void sfText_destroy(sfText* text) //////////////////////////////////////////////////////////// void sfText_setPosition(sfText* text, sfVector2f position) { - CSFML_CALL(text, setPosition(position.x, position.y)); + CSFML_CALL(text, setPosition({ position.x, position.y })); } //////////////////////////////////////////////////////////// void sfText_setRotation(sfText* text, float angle) { - CSFML_CALL(text, setRotation(angle)); + CSFML_CALL(text, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfText_setScale(sfText* text, sfVector2f scale) { - CSFML_CALL(text, setScale(scale.x, scale.y)); + CSFML_CALL(text, setScale({ scale.x, scale.y })); } //////////////////////////////////////////////////////////// void sfText_setOrigin(sfText* text, sfVector2f origin) { - CSFML_CALL(text, setOrigin(origin.x, origin.y)); + CSFML_CALL(text, setOrigin({ origin.x, origin.y })); } @@ -104,7 +103,7 @@ sfVector2f sfText_getPosition(const sfText* text) //////////////////////////////////////////////////////////// float sfText_getRotation(const sfText* text) { - CSFML_CALL_RETURN(text, getRotation(), 0.f); + CSFML_CALL_RETURN(text, getRotation().asDegrees(), 0.f); } @@ -139,21 +138,21 @@ sfVector2f sfText_getOrigin(const sfText* text) //////////////////////////////////////////////////////////// void sfText_move(sfText* text, sfVector2f offset) { - CSFML_CALL(text, move(offset.x, offset.y)); + CSFML_CALL(text, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfText_rotate(sfText* text, float angle) { - CSFML_CALL(text, rotate(angle)); + CSFML_CALL(text, rotate(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfText_scale(sfText* text, sfVector2f factors) { - CSFML_CALL(text, scale(factors.x, factors.y)); + CSFML_CALL(text, scale({ factors.x, factors.y })); } @@ -185,9 +184,9 @@ void sfText_setString(sfText* text, const char* string) //////////////////////////////////////////////////////////// -void sfText_setUnicodeString(sfText* text, const uint32_t* string) +void sfText_setUnicodeString(sfText* text, const sfChar32* string) { - sf::String UTF32Text = string; + sf::String UTF32Text = reinterpret_cast(string); CSFML_CALL(text, setString(UTF32Text)); } @@ -270,11 +269,11 @@ const char* sfText_getString(const sfText* text) //////////////////////////////////////////////////////////// -const uint32_t* sfText_getUnicodeString(const sfText* text) +const sfChar32* sfText_getUnicodeString(const sfText* text) { CSFML_CHECK_RETURN(text, nullptr); - return text->This.getString().getData(); + return reinterpret_cast(text->This.getString().getData()); } diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 593dc4c..67aa608 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -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->create({ width, height })) { delete texture; texture = nullptr; @@ -56,7 +56,7 @@ 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->left, area->top }, { area->width, area->height }); if (!texture->This->loadFromFile(filename, rect)) { @@ -74,7 +74,7 @@ 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->left, area->top }, { area->width, area->height }); texture->This->setSrgb(true); @@ -94,7 +94,7 @@ 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->left, area->top }, { area->width, area->height }); if (!texture->This->loadFromMemory(data, sizeInBytes, rect)) { @@ -112,7 +112,7 @@ 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->left, area->top }, { area->width, area->height }); texture->This->setSrgb(true); @@ -135,7 +135,7 @@ 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->left, area->top }, { area->width, area->height }); CallbackStream sfmlStream(stream); if (!texture->This->loadFromStream(sfmlStream, rect)) @@ -156,7 +156,7 @@ sfTexture* sfTexture_createSrgbFromStream(sfInputStream* stream, const sfIntRect sf::IntRect rect; if (area) - rect = sf::IntRect(area->left, area->top, area->width, area->height); + rect = sf::IntRect({ area->left, area->top }, { area->width, area->height }); texture->This->setSrgb(true); @@ -180,7 +180,7 @@ 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->left, area->top }, { area->width, area->height }); if (!texture->This->loadFromImage(image->This, rect)) { @@ -200,7 +200,7 @@ 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->left, area->top }, { area->width, area->height }); texture->This->setSrgb(true); @@ -260,7 +260,7 @@ sfImage* sfTexture_copyToImage(const sfTexture* texture) //////////////////////////////////////////////////////////// void sfTexture_updateFromPixels(sfTexture* texture, const uint8_t* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y) { - CSFML_CALL_PTR(texture, update(pixels, width, height, x, y)); + CSFML_CALL_PTR(texture, update(pixels, { width, height }, { x, y })); } @@ -270,7 +270,7 @@ void sfTexture_updateFromTexture(sfTexture* destination, const sfTexture* textur CSFML_CHECK(texture); CSFML_CHECK(texture->This); - CSFML_CALL_PTR(destination, update(*texture->This, x, y)); + CSFML_CALL_PTR(destination, update(*texture->This, { x, y })); } @@ -279,7 +279,7 @@ void sfTexture_updateFromImage(sfTexture* texture, const sfImage* image, unsigne { CSFML_CHECK(image); - CSFML_CALL_PTR(texture, update(image->This, x, y)); + CSFML_CALL_PTR(texture, update(image->This, { x, y })); } @@ -288,7 +288,7 @@ void sfTexture_updateFromWindow(sfTexture* texture, const sfWindow* window, unsi { CSFML_CHECK(window); - CSFML_CALL_PTR(texture, update(window->This, x, y)); + CSFML_CALL_PTR(texture, update(window->This, { x, y })); } @@ -297,7 +297,7 @@ void sfTexture_updateFromRenderWindow(sfTexture* texture, const sfRenderWindow* { CSFML_CHECK(renderWindow); - CSFML_CALL_PTR(texture, update(renderWindow->This, x, y)); + CSFML_CALL_PTR(texture, update(renderWindow->This, { x, y })); } @@ -367,7 +367,7 @@ unsigned int sfTexture_getNativeHandle(const sfTexture* texture) //////////////////////////////////////////////////////////// void sfTexture_bind(const sfTexture* texture, sfTextureCoordinateType type) { - sf::Texture::bind(texture ? texture->This : nullptr, static_cast(type)); + sf::Texture::bind(texture ? texture->This : nullptr, static_cast(type)); } diff --git a/src/SFML/Graphics/Transform.cpp b/src/SFML/Graphics/Transform.cpp index 6e630de..717b0ee 100644 --- a/src/SFML/Graphics/Transform.cpp +++ b/src/SFML/Graphics/Transform.cpp @@ -77,7 +77,7 @@ sfVector2f sfTransform_transformPoint(const sfTransform* transform, sfVector2f p sfVector2f p = {0, 0}; CSFML_CHECK_RETURN(transform, p); - sf::Vector2f sfmlPoint = convertTransform(*transform).transformPoint(point.x, point.y); + sf::Vector2f sfmlPoint = convertTransform(*transform).transformPoint({ point.x, point.y }); p.x = sfmlPoint.x; p.y = sfmlPoint.y; @@ -92,7 +92,7 @@ sfFloatRect sfTransform_transformRect(const sfTransform* transform, sfFloatRect sfFloatRect rect = {0, 0, 0, 0}; CSFML_CHECK_RETURN(transform, rect); - sf::FloatRect sfmlRect = convertTransform(*transform).transformRect(sf::FloatRect(rectangle.left, rectangle.top, rectangle.width, rectangle.height)); + sf::FloatRect sfmlRect = convertTransform(*transform).transformRect(sf::FloatRect({ rectangle.left, rectangle.top }, { rectangle.width, rectangle.height })); rect.left = sfmlRect.left; rect.top = sfmlRect.top; @@ -118,7 +118,7 @@ void sfTransform_translate(sfTransform* transform, float x, float y) { CSFML_CHECK(transform); - *transform = convertTransform(convertTransform(*transform).translate(x, y)); + *transform = convertTransform(convertTransform(*transform).translate({ x, y })); } @@ -127,7 +127,7 @@ void sfTransform_rotate(sfTransform* transform, float angle) { CSFML_CHECK(transform); - *transform = convertTransform(convertTransform(*transform).rotate(angle)); + *transform = convertTransform(convertTransform(*transform).rotate(sf::degrees(angle))); } @@ -136,7 +136,7 @@ void sfTransform_rotateWithCenter(sfTransform* transform, float angle, float cen { CSFML_CHECK(transform); - *transform = convertTransform(convertTransform(*transform).rotate(angle, centerX, centerY)); + *transform = convertTransform(convertTransform(*transform).rotate(sf::degrees(angle), { centerX, centerY })); } @@ -145,7 +145,7 @@ void sfTransform_scale(sfTransform* transform, float scaleX, float scaleY) { CSFML_CHECK(transform); - *transform = convertTransform(convertTransform(*transform).scale(scaleX, scaleY)); + *transform = convertTransform(convertTransform(*transform).scale({ scaleX, scaleY })); } @@ -154,7 +154,7 @@ void sfTransform_scaleWithCenter(sfTransform* transform, float scaleX, float sca { CSFML_CHECK(transform); - *transform = convertTransform(convertTransform(*transform).scale(scaleX, scaleY, centerX, centerY)); + *transform = convertTransform(convertTransform(*transform).scale({ scaleX, scaleY }, { centerX, centerY })); } diff --git a/src/SFML/Graphics/Transformable.cpp b/src/SFML/Graphics/Transformable.cpp index 7c1773f..14739cb 100644 --- a/src/SFML/Graphics/Transformable.cpp +++ b/src/SFML/Graphics/Transformable.cpp @@ -59,28 +59,28 @@ void sfTransformable_destroy(sfTransformable* transformable) //////////////////////////////////////////////////////////// void sfTransformable_setPosition(sfTransformable* transformable, sfVector2f position) { - CSFML_CALL(transformable, setPosition(position.x, position.y)); + CSFML_CALL(transformable, setPosition({ position.x, position.y })); } //////////////////////////////////////////////////////////// void sfTransformable_setRotation(sfTransformable* transformable, float angle) { - CSFML_CALL(transformable, setRotation(angle)); + CSFML_CALL(transformable, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfTransformable_setScale(sfTransformable* transformable, sfVector2f scale) { - CSFML_CALL(transformable, setScale(scale.x, scale.y)); + CSFML_CALL(transformable, setScale({ scale.x, scale.y })); } //////////////////////////////////////////////////////////// void sfTransformable_setOrigin(sfTransformable* transformable, sfVector2f origin) { - CSFML_CALL(transformable, setOrigin(origin.x, origin.y)); + CSFML_CALL(transformable, setOrigin({ origin.x, origin.y })); } @@ -101,7 +101,7 @@ sfVector2f sfTransformable_getPosition(const sfTransformable* transformable) //////////////////////////////////////////////////////////// float sfTransformable_getRotation(const sfTransformable* transformable) { - CSFML_CALL_RETURN(transformable, getRotation(), 0.f); + CSFML_CALL_RETURN(transformable, getRotation().asDegrees(), 0.f); } @@ -136,21 +136,21 @@ sfVector2f sfTransformable_getOrigin(const sfTransformable* transformable) //////////////////////////////////////////////////////////// void sfTransformable_move(sfTransformable* transformable, sfVector2f offset) { - CSFML_CALL(transformable, move(offset.x, offset.y)); + CSFML_CALL(transformable, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfTransformable_rotate(sfTransformable* transformable, float angle) { - CSFML_CALL(transformable, rotate(angle)); + CSFML_CALL(transformable, rotate(sf::degrees(angle))); } //////////////////////////////////////////////////////////// void sfTransformable_scale(sfTransformable* transformable, sfVector2f factors) { - CSFML_CALL(transformable, scale(factors.x, factors.y)); + CSFML_CALL(transformable, scale({ factors.x, factors.y })); } diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index 2e1bb04..a364e05 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -66,35 +66,35 @@ void sfView_destroy(sfView* view) //////////////////////////////////////////////////////////// void sfView_setCenter(sfView* view, sfVector2f center) { - CSFML_CALL(view, setCenter(center.x, center.y)); + CSFML_CALL(view, setCenter({ center.x, center.y })); } //////////////////////////////////////////////////////////// void sfView_setSize(sfView* view, sfVector2f size) { - CSFML_CALL(view, setSize(size.x, size.y)); + CSFML_CALL(view, setSize({ size.x, size.y })); } //////////////////////////////////////////////////////////// void sfView_setRotation(sfView* view, float angle) { - CSFML_CALL(view, setRotation(angle)); + CSFML_CALL(view, setRotation(sf::degrees(angle))); } //////////////////////////////////////////////////////////// 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.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, reset(sf::FloatRect({ rectangle.left, rectangle.top }, { rectangle.width, rectangle.height }))); } @@ -129,7 +129,7 @@ sfVector2f sfView_getSize(const sfView* view) //////////////////////////////////////////////////////////// float sfView_getRotation(const sfView* view) { - CSFML_CALL_RETURN(view, getRotation(), 0.f); + CSFML_CALL_RETURN(view, getRotation().asDegrees(), 0.f); } @@ -152,14 +152,14 @@ sfFloatRect sfView_getViewport(const sfView* view) //////////////////////////////////////////////////////////// void sfView_move(sfView* view, sfVector2f offset) { - CSFML_CALL(view, move(offset.x, offset.y)); + CSFML_CALL(view, move({ offset.x, offset.y })); } //////////////////////////////////////////////////////////// void sfView_rotate(sfView* view, float angle) { - CSFML_CALL(view, rotate(angle)); + CSFML_CALL(view, rotate(sf::degrees(angle))); } diff --git a/src/SFML/Internal.h b/src/SFML/Internal.h index 651f29c..4e927ad 100644 --- a/src/SFML/Internal.h +++ b/src/SFML/Internal.h @@ -25,10 +25,13 @@ #ifndef SFML_INTERNAL_H #define SFML_INTERNAL_H + //////////////////////////////////////////////////////////// // Define macros to check the validity of CSFML objects in debug run //////////////////////////////////////////////////////////// #include +#include +#include #ifndef NDEBUG @@ -131,4 +134,12 @@ #endif +//////////////////////////////////////////////////////////// +// Ensure char32_t has the same size as sfChar32 (uint32_t) +// Identical alignment and size is required because we're type punning +// when doing sfChar32* <-> char32_t* casts +//////////////////////////////////////////////////////////// +static_assert(sizeof(sfChar32) == sizeof(char32_t)); +static_assert(alignof(sfChar32) == alignof(char32_t)); + #endif // SFML_INTERNAL_H diff --git a/src/SFML/Network/CMakeLists.txt b/src/SFML/Network/CMakeLists.txt index cd90788..6d13a5b 100644 --- a/src/SFML/Network/CMakeLists.txt +++ b/src/SFML/Network/CMakeLists.txt @@ -35,4 +35,4 @@ set(SRC # define the csfml-network target csfml_add_library(csfml-network SOURCES ${SRC} - DEPENDS sfml-network) + DEPENDS SFML::Network) diff --git a/src/SFML/Network/Ftp.cpp b/src/SFML/Network/Ftp.cpp index d3cecc2..85648ac 100644 --- a/src/SFML/Network/Ftp.cpp +++ b/src/SFML/Network/Ftp.cpp @@ -28,7 +28,10 @@ #include #include #include +#include #include +#include +#include //////////////////////////////////////////////////////////// @@ -117,8 +120,17 @@ const char* sfFtpDirectoryResponse_getMessage(const sfFtpDirectoryResponse* ftpD const char* sfFtpDirectoryResponse_getDirectory(const sfFtpDirectoryResponse* ftpDirectoryResponse) { CSFML_CHECK_RETURN(ftpDirectoryResponse, nullptr); + return strdup(ftpDirectoryResponse->This.getDirectory().string().c_str()); +} - return ftpDirectoryResponse->This.getDirectory().c_str(); + +//////////////////////////////////////////////////////////// +const sfChar32* sfFtpDirectoryResponse_getDirectoryUnicode(const sfFtpDirectoryResponse* ftpDirectoryResponse) +{ + CSFML_CHECK_RETURN(ftpDirectoryResponse, nullptr); + + sf::String str = sf::String(ftpDirectoryResponse->This.getDirectory().c_str()); + return copyToChar32(str); } @@ -173,9 +185,12 @@ sfFtpResponse* sfFtp_connect(sfFtp* ftp, sfIpAddress server, unsigned short port { CSFML_CHECK_RETURN(ftp, nullptr); - sf::IpAddress SFMLServer(server.address); + std::optional SFMLServer = sf::IpAddress::resolve(server.address); - return new sfFtpResponse(ftp->This.connect(SFMLServer, port, sf::microseconds(timeout.microseconds))); + if (!SFMLServer) + return nullptr; + + return new sfFtpResponse(ftp->This.connect(*SFMLServer, port, sf::microseconds(timeout.microseconds))); } diff --git a/src/SFML/Network/IpAddress.cpp b/src/SFML/Network/IpAddress.cpp index 7f52e8f..65680da 100644 --- a/src/SFML/Network/IpAddress.cpp +++ b/src/SFML/Network/IpAddress.cpp @@ -33,18 +33,22 @@ namespace { // Helper function for converting a SFML address to a CSFML one - sfIpAddress fromSFMLAddress(sf::IpAddress address) + sfIpAddress fromSFMLAddress(std::optional address) { sfIpAddress result = {0}; - strncpy(result.address, address.toString().c_str(), 15); + + if (address) + { + strncpy(result.address, address->toString().c_str(), 15); + } return result; } // Helper function for converting a CSFML address to a SFML one - sf::IpAddress toSFMLAddress(sfIpAddress address) + std::optional toSFMLAddress(sfIpAddress address) { - return sf::IpAddress(address.address); + return sf::IpAddress::resolve(address.address); } } @@ -68,7 +72,7 @@ const sfIpAddress sfIpAddress_Broadcast = sfIpAddress_fromBytes(255, 255, 255, 2 //////////////////////////////////////////////////////////// sfIpAddress sfIpAddress_fromString(const char* address) { - return fromSFMLAddress(sf::IpAddress(address)); + return fromSFMLAddress(sf::IpAddress::resolve(address)); } @@ -97,7 +101,8 @@ void sfIpAddress_toString(sfIpAddress address, char* string) //////////////////////////////////////////////////////////// uint32_t sfIpAddress_toInteger(sfIpAddress address) { - return toSFMLAddress(address).toInteger(); + auto sfmlAddress = toSFMLAddress(address); + return sfmlAddress ? sfmlAddress->toInteger() : 0; } diff --git a/src/SFML/Network/Packet.cpp b/src/SFML/Network/Packet.cpp index bb41327..4d506dd 100644 --- a/src/SFML/Network/Packet.cpp +++ b/src/SFML/Network/Packet.cpp @@ -99,7 +99,7 @@ bool sfPacket_endOfPacket(const sfPacket* packet) bool sfPacket_canRead(const sfPacket* packet) { CSFML_CHECK_RETURN(packet, false); - return packet->This; + return static_cast(packet->This); } diff --git a/src/SFML/Network/TcpListener.cpp b/src/SFML/Network/TcpListener.cpp index 818fad7..8f96d2e 100644 --- a/src/SFML/Network/TcpListener.cpp +++ b/src/SFML/Network/TcpListener.cpp @@ -71,8 +71,14 @@ sfSocketStatus sfTcpListener_listen(sfTcpListener* listener, unsigned short port { CSFML_CHECK_RETURN(listener, sfSocketError); - sf::IpAddress sfmlAddress(address.address); - return static_cast(listener->This.listen(port, sfmlAddress)); + std::optional sfmlAddress = sf::IpAddress::resolve(address.address); + + if (!sfmlAddress) + { + return sfSocketError; + } + + return static_cast(listener->This.listen(port, *sfmlAddress)); } diff --git a/src/SFML/Network/TcpSocket.cpp b/src/SFML/Network/TcpSocket.cpp index 2b2728e..b53d671 100644 --- a/src/SFML/Network/TcpSocket.cpp +++ b/src/SFML/Network/TcpSocket.cpp @@ -74,8 +74,12 @@ sfIpAddress sfTcpSocket_getRemoteAddress(const sfTcpSocket* socket) sfIpAddress result = sfIpAddress_None; CSFML_CHECK_RETURN(socket, result); - sf::IpAddress address = socket->This.getRemoteAddress(); - strncpy(result.address, address.toString().c_str(), 15); + std::optional address = socket->This.getRemoteAddress(); + + if (address) + { + strncpy(result.address, address->toString().c_str(), 15); + } return result; } @@ -91,11 +95,16 @@ unsigned short sfTcpSocket_getRemotePort(const sfTcpSocket* socket) //////////////////////////////////////////////////////////// sfSocketStatus sfTcpSocket_connect(sfTcpSocket* socket, sfIpAddress remoteAddress, unsigned short remotePort, sfTime timeout) { - sf::IpAddress address(remoteAddress.address); + std::optional address = sf::IpAddress::resolve(remoteAddress.address); + + if (!address) + { + return sfSocketError; + } CSFML_CHECK_RETURN(socket, sfSocketError); - return static_cast(socket->This.connect(address, remotePort, sf::microseconds(timeout.microseconds))); + return static_cast(socket->This.connect(*address, remotePort, sf::microseconds(timeout.microseconds))); } diff --git a/src/SFML/Network/UdpSocket.cpp b/src/SFML/Network/UdpSocket.cpp index c004546..2999629 100644 --- a/src/SFML/Network/UdpSocket.cpp +++ b/src/SFML/Network/UdpSocket.cpp @@ -72,8 +72,14 @@ sfSocketStatus sfUdpSocket_bind(sfUdpSocket* socket, unsigned short port, sfIpAd { CSFML_CHECK_RETURN(socket, sfSocketError); - sf::IpAddress sfmlAddress(address.address); - return static_cast(socket->This.bind(port, sfmlAddress)); + std::optional sfmlAddress = sf::IpAddress::resolve(address.address); + + if (!sfmlAddress) + { + return sfSocketError; + } + + return static_cast(socket->This.bind(port, *sfmlAddress)); } @@ -90,9 +96,14 @@ sfSocketStatus sfUdpSocket_send(sfUdpSocket* socket, const void* data, size_t si CSFML_CHECK_RETURN(socket, sfSocketError); // Convert the address - sf::IpAddress address(remoteAddress.address); + std::optional address = sf::IpAddress::resolve(remoteAddress.address); - return static_cast(socket->This.send(data, size, address, remotePort)); + if (!address) + { + return sfSocketError; + } + + return static_cast(socket->This.send(data, size, *address, remotePort)); } @@ -101,12 +112,12 @@ sfSocketStatus sfUdpSocket_receive(sfUdpSocket* socket, void* data, size_t size, { CSFML_CHECK_RETURN(socket, sfSocketError); - sf::IpAddress address; + std::optional address; unsigned short port; std::size_t sizeReceived; sf::Socket::Status status = socket->This.receive(data, size, sizeReceived, address, port); - if (status != sf::Socket::Done) + if (status != sf::Socket::Status::Done) return static_cast(status); if (received) @@ -115,7 +126,11 @@ sfSocketStatus sfUdpSocket_receive(sfUdpSocket* socket, void* data, size_t size, if (remoteAddress) { *remoteAddress = sfIpAddress_None; - strncpy(remoteAddress->address, address.toString().c_str(), 15); + + if (address) + { + strncpy(remoteAddress->address, address->toString().c_str(), 15); + } } if (remotePort) @@ -132,9 +147,14 @@ sfSocketStatus sfUdpSocket_sendPacket(sfUdpSocket* socket, sfPacket* packet, sfI CSFML_CHECK_RETURN(packet, sfSocketError); // Convert the address - sf::IpAddress address(remoteAddress.address); + std::optional address = sf::IpAddress::resolve(remoteAddress.address); - return static_cast(socket->This.send(packet->This, address, remotePort)); + if (!address) + { + return sfSocketError; + } + + return static_cast(socket->This.send(packet->This, *address, remotePort)); } @@ -144,17 +164,21 @@ sfSocketStatus sfUdpSocket_receivePacket(sfUdpSocket* socket, sfPacket* packet, CSFML_CHECK_RETURN(socket, sfSocketError); CSFML_CHECK_RETURN(packet, sfSocketError); - sf::IpAddress address; + std::optional address; unsigned short port; sf::Socket::Status status = socket->This.receive(packet->This, address, port); - if (status != sf::Socket::Done) + if (status != sf::Socket::Status::Done) return static_cast(status); if (remoteAddress) { *remoteAddress = sfIpAddress_None; - strncpy(remoteAddress->address, address.toString().c_str(), 15); + + if (address) + { + strncpy(remoteAddress->address, address->toString().c_str(), 15); + } } if (remotePort) diff --git a/src/SFML/System/BufferStruct.h b/src/SFML/System/BufferStruct.h index ffa814f..6d1fc13 100644 --- a/src/SFML/System/BufferStruct.h +++ b/src/SFML/System/BufferStruct.h @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include //////////////////////////////////////////////////////////// @@ -37,7 +38,7 @@ //////////////////////////////////////////////////////////// struct sfBuffer { - std::vector buffer; + std::vector buffer; }; diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 2ea169c..fd81ffd 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -13,14 +13,8 @@ set(SRC ${SRCROOT}/ClockStruct.h ${INCROOT}/Clock.h ${INCROOT}/InputStream.h - ${SRCROOT}/Mutex.cpp - ${SRCROOT}/MutexStruct.h - ${INCROOT}/Mutex.h ${SRCROOT}/Sleep.cpp ${INCROOT}/Sleep.h - ${SRCROOT}/Thread.cpp - ${SRCROOT}/ThreadStruct.h - ${INCROOT}/Thread.h ${SRCROOT}/Time.cpp ${INCROOT}/Time.h ${INCROOT}/Types.h @@ -31,4 +25,4 @@ set(SRC # define the csfml-system target csfml_add_library(csfml-system SOURCES ${SRC} - DEPENDS sfml-system) + DEPENDS SFML::System) diff --git a/src/SFML/System/Clock.cpp b/src/SFML/System/Clock.cpp index 98601d1..460339b 100644 --- a/src/SFML/System/Clock.cpp +++ b/src/SFML/System/Clock.cpp @@ -27,6 +27,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include diff --git a/src/SFML/System/MutexStruct.h b/src/SFML/System/MutexStruct.h deleted file mode 100644 index f87b7c7..0000000 --- a/src/SFML/System/MutexStruct.h +++ /dev/null @@ -1,43 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_MUTEXSTRUCT_H -#define SFML_MUTEXSTRUCT_H - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -//////////////////////////////////////////////////////////// -// Internal structure of sfMutex -//////////////////////////////////////////////////////////// -struct sfMutex -{ - sf::Mutex This; -}; - - -#endif // SFML_MUTEXSTRUCT_H diff --git a/src/SFML/System/Sleep.cpp b/src/SFML/System/Sleep.cpp index 10cf4f0..92a019c 100644 --- a/src/SFML/System/Sleep.cpp +++ b/src/SFML/System/Sleep.cpp @@ -27,6 +27,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include diff --git a/src/SFML/System/Thread.cpp b/src/SFML/System/Thread.cpp deleted file mode 100644 index b49f56a..0000000 --- a/src/SFML/System/Thread.cpp +++ /dev/null @@ -1,65 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include -#include -#include - - -//////////////////////////////////////////////////////////// -sfThread* sfThread_create(void (*function)(void*), void* userData) -{ - return new sfThread(function, userData); -} - - -//////////////////////////////////////////////////////////// -void sfThread_destroy(sfThread* thread) -{ - delete thread; -} - - -//////////////////////////////////////////////////////////// -void sfThread_launch(sfThread* thread) -{ - CSFML_CALL(thread, launch()); -} - - -//////////////////////////////////////////////////////////// -void sfThread_wait(sfThread* thread) -{ - CSFML_CALL(thread, wait()); -} - - -//////////////////////////////////////////////////////////// -void sfThread_terminate(sfThread* thread) -{ - CSFML_CALL(thread, terminate()); -} diff --git a/src/SFML/System/ThreadStruct.h b/src/SFML/System/ThreadStruct.h deleted file mode 100644 index b0248d1..0000000 --- a/src/SFML/System/ThreadStruct.h +++ /dev/null @@ -1,48 +0,0 @@ -//////////////////////////////////////////////////////////// -// -// SFML - Simple and Fast Multimedia Library -// Copyright (C) 2007-2023 Laurent Gomila (laurent@sfml-dev.org) -// -// This software is provided 'as-is', without any express or implied warranty. -// In no event will the authors be held liable for any damages arising from the use of this software. -// -// Permission is granted to anyone to use this software for any purpose, -// including commercial applications, and to alter it and redistribute it freely, -// subject to the following restrictions: -// -// 1. The origin of this software must not be misrepresented; -// you must not claim that you wrote the original software. -// If you use this software in a product, an acknowledgment -// in the product documentation would be appreciated but is not required. -// -// 2. Altered source versions must be plainly marked as such, -// and must not be misrepresented as being the original software. -// -// 3. This notice may not be removed or altered from any source distribution. -// -//////////////////////////////////////////////////////////// - -#ifndef SFML_THREADSTRUCT_H -#define SFML_THREADSTRUCT_H - -//////////////////////////////////////////////////////////// -// Headers -//////////////////////////////////////////////////////////// -#include - - -//////////////////////////////////////////////////////////// -// Internal structure of sfThread -//////////////////////////////////////////////////////////// -struct sfThread -{ - sfThread(void (*function)(void*), void* userData) : - This(function, userData) - { - } - - sf::Thread This; -}; - - -#endif // SFML_THREADSTRUCT_H diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index a9a5a88..405c01a 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -43,4 +43,4 @@ set(SRC # define the csfml-window target csfml_add_library(csfml-window SOURCES ${SRC} - DEPENDS sfml-window) + DEPENDS SFML::Window) diff --git a/src/SFML/Window/Clipboard.cpp b/src/SFML/Window/Clipboard.cpp index b6a7f6f..e75d0e8 100644 --- a/src/SFML/Window/Clipboard.cpp +++ b/src/SFML/Window/Clipboard.cpp @@ -25,9 +25,11 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include #include #include #include +#include namespace @@ -46,10 +48,10 @@ const char* sfClipboard_getString() //////////////////////////////////////////////////////////// -const uint32_t* sfClipboard_getUnicodeString() +const sfChar32* sfClipboard_getUnicodeString() { ClipboardString = sf::Clipboard::getString(); - return ClipboardString.getData(); + return reinterpret_cast(ClipboardString.getData()); } @@ -61,7 +63,7 @@ void sfClipboard_setString(const char* text) //////////////////////////////////////////////////////////// -void sfClipboard_setUnicodeString(const uint32_t* text) +void sfClipboard_setUnicodeString(const sfChar32* text) { - sf::Clipboard::setString(text); + sf::Clipboard::setString(reinterpret_cast(text)); } diff --git a/src/SFML/Window/VideoMode.cpp b/src/SFML/Window/VideoMode.cpp index 8f7cef5..d8fbcde 100644 --- a/src/SFML/Window/VideoMode.cpp +++ b/src/SFML/Window/VideoMode.cpp @@ -35,8 +35,8 @@ sfVideoMode sfVideoMode_getDesktopMode(void) { sf::VideoMode desktop = sf::VideoMode::getDesktopMode(); sfVideoMode ret; - ret.width = desktop.width; - ret.height = desktop.height; + ret.width = desktop.size.x; + ret.height = desktop.size.y; ret.bitsPerPixel = desktop.bitsPerPixel; return ret; @@ -55,8 +55,8 @@ const sfVideoMode* sfVideoMode_getFullscreenModes(size_t* count) for (const auto& sfmlMode : sfmlModes) { sfVideoMode mode; - mode.width = sfmlMode.width; - mode.height = sfmlMode.height; + mode.width = sfmlMode.size.x; + mode.height = sfmlMode.size.y; mode.bitsPerPixel = sfmlMode.bitsPerPixel; modes.push_back(mode); } @@ -72,6 +72,6 @@ const sfVideoMode* sfVideoMode_getFullscreenModes(size_t* count) //////////////////////////////////////////////////////////// bool sfVideoMode_isValid(sfVideoMode mode) { - sf::VideoMode videoMode(mode.width, mode.height, mode.bitsPerPixel); + sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel); return videoMode.isValid(); } diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 7a507b0..73792a8 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -34,10 +34,10 @@ //////////////////////////////////////////////////////////// -sfWindow* sfWindow_create(sfVideoMode mode, const char* title, uint32_t style, const sfContextSettings* settings) +sfWindow* sfWindow_create(sfVideoMode mode, const char* title, uint32_t style, sfWindowState state, const sfContextSettings* settings) { // Convert video mode - sf::VideoMode videoMode(mode.width, mode.height, mode.bitsPerPixel); + sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel); // Convert context settings sf::ContextSettings params; @@ -48,16 +48,16 @@ sfWindow* sfWindow_create(sfVideoMode mode, const char* title, uint32_t style, c // Create the window sfWindow* window = new sfWindow; - window->This.create(videoMode, title, style, params); + window->This.create(videoMode, title, style, static_cast(state), params); return window; } //////////////////////////////////////////////////////////// -sfWindow* sfWindow_createUnicode(sfVideoMode mode, const uint32_t* title, uint32_t style, const sfContextSettings* settings) +sfWindow* sfWindow_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style, sfWindowState state, const sfContextSettings* settings) { // Convert video mode - sf::VideoMode videoMode(mode.width, mode.height, mode.bitsPerPixel); + sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel); // Convert context settings sf::ContextSettings params; @@ -68,7 +68,7 @@ sfWindow* sfWindow_createUnicode(sfVideoMode mode, const uint32_t* title, uint32 // Create the window sfWindow* window = new sfWindow; - window->This.create(videoMode, title, style, params); + window->This.create(videoMode, reinterpret_cast(title), style, static_cast(state), params); return window; } @@ -217,16 +217,16 @@ void sfWindow_setTitle(sfWindow* window, const char* title) //////////////////////////////////////////////////////////// -void sfWindow_setUnicodeTitle(sfWindow* window, const uint32_t* title) +void sfWindow_setUnicodeTitle(sfWindow* window, const sfChar32* title) { - CSFML_CALL(window, setTitle(title)); + CSFML_CALL(window, setTitle(reinterpret_cast(title))); } //////////////////////////////////////////////////////////// void sfWindow_setIcon(sfWindow* window, unsigned int width, unsigned int height, const uint8_t* pixels) { - CSFML_CALL(window, setIcon(width, height, pixels)); + CSFML_CALL(window, setIcon({ width, height }, pixels)); } @@ -316,9 +316,9 @@ void sfWindow_setJoystickThreshold(sfWindow* window, float threshold) //////////////////////////////////////////////////////////// -sfWindowHandle sfWindow_getSystemHandle(const sfWindow* window) +sfWindowHandle sfWindow_getNativeHandle(const sfWindow* window) { CSFML_CHECK_RETURN(window, 0); - return static_cast(window->This.getSystemHandle()); + return static_cast(window->This.getNativeHandle()); } diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index 58a4498..7c9ecc2 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include @@ -36,7 +37,7 @@ sfWindowBase* sfWindowBase_create(sfVideoMode mode, const char* title, uint32_t style) { // Convert video mode - sf::VideoMode videoMode(mode.width, mode.height, mode.bitsPerPixel); + sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel); // Create the window sfWindowBase* windowBase = new sfWindowBase; @@ -47,14 +48,14 @@ sfWindowBase* sfWindowBase_create(sfVideoMode mode, const char* title, uint32_t //////////////////////////////////////////////////////////// -sfWindowBase* sfWindowBase_createUnicode(sfVideoMode mode, const uint32_t* title, uint32_t style) +sfWindowBase* sfWindowBase_createUnicode(sfVideoMode mode, const sfChar32* title, uint32_t style) { // Convert video mode - sf::VideoMode videoMode(mode.width, mode.height, mode.bitsPerPixel); + sf::VideoMode videoMode({ mode.width, mode.height }, mode.bitsPerPixel); // Create the window sfWindowBase* windowBase = new sfWindowBase; - windowBase->This.create(videoMode, title, style); + windowBase->This.create(videoMode, reinterpret_cast(title), style); return windowBase; } @@ -184,16 +185,16 @@ void sfWindowBase_setTitle(sfWindowBase* windowBase, const char* title) //////////////////////////////////////////////////////////// -void sfWindowBase_setUnicodeTitle(sfWindowBase* windowBase, const uint32_t* title) +void sfWindowBase_setUnicodeTitle(sfWindowBase* windowBase, const sfChar32* title) { - CSFML_CALL(windowBase, setTitle(title)); + CSFML_CALL(windowBase, setTitle(reinterpret_cast(title))); } //////////////////////////////////////////////////////////// void sfWindowBase_setIcon(sfWindowBase* windowBase, unsigned int width, unsigned int height, const uint8_t* pixels) { - CSFML_CALL(windowBase, setIcon(width, height, pixels)); + CSFML_CALL(windowBase, setIcon({ width, height }, pixels)); } @@ -256,11 +257,11 @@ bool sfWindowBase_hasFocus(const sfWindowBase* windowBase) //////////////////////////////////////////////////////////// -sfWindowHandle sfWindowBase_getSystemHandle(const sfWindowBase* windowBase) +sfWindowHandle sfWindowBase_getNativeHandle(const sfWindowBase* windowBase) { CSFML_CHECK_RETURN(windowBase, 0); - return static_cast(windowBase->This.getSystemHandle()); + return static_cast(windowBase->This.getNativeHandle()); } ////////////////////////////////////////////////////////////