diff --git a/include/CSFML/Graphics/RenderTexture.h b/include/CSFML/Graphics/RenderTexture.h index ce041e6..e8d20db 100644 --- a/include/CSFML/Graphics/RenderTexture.h +++ b/include/CSFML/Graphics/RenderTexture.h @@ -33,6 +33,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,33 @@ CSFML_GRAPHICS_API void sfRenderTexture_display(sfRenderTexture* renderTexture); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRenderTexture_clear(sfRenderTexture* renderTexture, sfColor color); +//////////////////////////////////////////////////////////// +/// \brief Clear the stencil buffer to a specific value +/// +/// The specified value is truncated to the bit width of +/// the current stencil buffer. +/// +/// \param renderTexture Render texture object +/// \param stencilValue Stencil value to clear to +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRenderTexture_clearStencil(sfRenderTexture* renderTexture, sfStencilValue stencilValue); + +//////////////////////////////////////////////////////////// +/// \brief Clear the entire target with a single color and stencil value +/// +/// The specified stencil value is truncated to the bit +/// width of the current stencil buffer. +/// +/// \param renderTexture Render texture object +/// \param color Fill color to use to clear the render target +/// \param stencilValue Stencil value to clear to +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRenderTexture_clearColorAndStencil(sfRenderTexture* renderTexture, + sfColor color, + sfStencilValue stencilValue); + //////////////////////////////////////////////////////////// /// \brief Change the current active view of a render texture /// @@ -148,6 +176,22 @@ CSFML_GRAPHICS_API const sfView* sfRenderTexture_getDefaultView(const sfRenderTe //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, const sfView* view); +//////////////////////////////////////////////////////////// +/// \brief Get the scissor rectangle of a view, applied to this render target +/// +/// The scissor rectangle is defined in the view as a ratio. This +/// function simply applies this ratio to the current dimensions +/// of the render target to calculate the pixels rectangle +/// that the scissor rectangle actually covers in the target. +/// +/// \param renderTexture Render texture object +/// \param view The view for which we want to compute the scissor rectangle +/// +/// \return Scissor rectangle, expressed in pixels +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfIntRect sfRenderTexture_getScissor(const sfRenderTexture* renderTexture, const sfView* view); + //////////////////////////////////////////////////////////// /// \brief Convert a point from texture coordinates to world coordinates /// diff --git a/include/CSFML/Graphics/RenderWindow.h b/include/CSFML/Graphics/RenderWindow.h index 1766f28..c936270 100644 --- a/include/CSFML/Graphics/RenderWindow.h +++ b/include/CSFML/Graphics/RenderWindow.h @@ -33,8 +33,10 @@ #include #include #include +#include #include #include +#include #include #include #include @@ -122,12 +124,18 @@ CSFML_GRAPHICS_API bool sfRenderWindow_isOpen(const sfRenderWindow* renderWindow CSFML_GRAPHICS_API sfContextSettings sfRenderWindow_getSettings(const sfRenderWindow* renderWindow); //////////////////////////////////////////////////////////// -/// \brief Get the event on top of event queue of a render window, if any, and pop it +/// \brief Pop the event on top of event queue, if any, and return it +/// +/// This function is not blocking: if there's no pending event then +/// it will return false and leave \a event unmodified. +/// Note that more than one event may be present in the event queue, +/// thus you should always call this function in a loop +/// to make sure that you process every pending event. /// /// \param renderWindow Render window object /// \param event Event to fill, if any /// -/// \return true if an event was returned, false if event queue was empty +/// \return true if an event was returned, or false if the event queue was empty /// //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event); @@ -135,13 +143,28 @@ CSFML_GRAPHICS_API bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, s //////////////////////////////////////////////////////////// /// \brief Wait for an event and return it /// -/// \param renderWindow Render window object -/// \param event Event to fill +/// This function is blocking: if there's no pending event then +/// it will wait until an event is received or until the provided +/// timeout elapses. Only if an error or a timeout occurs the +/// function returns `false`. +/// This function is typically used when you have a thread that is +/// dedicated to events handling: you want to make this thread sleep +/// as long as no new event is received. +/// \code +/// while (sfRenderWindow_waitEvent(renderWindow, timeout, &event)) +/// { +/// // process event... +/// } +/// \endcode /// -/// \return false if an error occurred +/// \param renderWindow Render window object +/// \param timeout Maximum time to wait (`sfTime_Zero` for infinite) +/// \param event Event to fill, if any +/// +/// \return true if an event was returned, false if event queue was empty or function timed out /// //////////////////////////////////////////////////////////// -CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event); +CSFML_GRAPHICS_API bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfTime timeout, sfEvent* event); //////////////////////////////////////////////////////////// /// \brief Get the position of a render window @@ -377,6 +400,31 @@ CSFML_GRAPHICS_API sfWindowHandle sfRenderWindow_getNativeHandle(const sfRenderW //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfRenderWindow_clear(sfRenderWindow* renderWindow, sfColor color); +//////////////////////////////////////////////////////////// +/// \brief Clear the stencil buffer to a specific value +/// +/// The specified value is truncated to the bit width of +/// the current stencil buffer. +/// +/// \param renderWindow Render window object +/// \param stencilValue Stencil value to clear to +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRenderWindow_clearStencil(sfRenderWindow* renderWindow, sfStencilValue stencilValue); + +//////////////////////////////////////////////////////////// +/// \brief Clear the entire target with a single color and stencil value +/// +/// The specified stencil value is truncated to the bit +/// width of the current stencil buffer. +/// +/// \param renderWindow Render window object +/// \param color Fill color to use to clear the render target +/// \param stencilValue Stencil value to clear to +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfRenderWindow_clearColorAndStencil(sfRenderWindow* renderWindow, sfColor color, sfStencilValue stencilValue); + //////////////////////////////////////////////////////////// /// \brief Change the current active view of a render window /// @@ -417,6 +465,22 @@ CSFML_GRAPHICS_API const sfView* sfRenderWindow_getDefaultView(const sfRenderWin //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const sfView* view); +//////////////////////////////////////////////////////////// +/// \brief Get the scissor rectangle of a view, applied to this render target +/// +/// The scissor rectangle is defined in the view as a ratio. This +/// function simply applies this ratio to the current dimensions +/// of the render target to calculate the pixels rectangle +/// that the scissor rectangle actually covers in the target. +/// +/// \param renderWindow Render window object +/// \param view The view for which we want to compute the scissor rectangle +/// +/// \return Scissor rectangle, expressed in pixels +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfIntRect sfRenderWindow_getScissor(const sfRenderWindow* renderWindow, const sfView* view); + //////////////////////////////////////////////////////////// /// \brief Convert a point from window coordinates to world coordinates /// diff --git a/include/CSFML/Graphics/StencilMode.h b/include/CSFML/Graphics/StencilMode.h new file mode 100644 index 0000000..fed229d --- /dev/null +++ b/include/CSFML/Graphics/StencilMode.h @@ -0,0 +1,96 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#pragma once + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +//////////////////////////////////////////////////////// +/// \brief Enumeration of the stencil test comparisons that can be performed +/// +/// The comparisons are mapped directly to their OpenGL equivalents, +/// specified by `glStencilFunc()`. +//////////////////////////////////////////////////////// +typedef enum +{ + sfStencilComparisonNever, //!< The stencil test never passes + sfStencilComparisonLess, //!< The stencil test passes if the new value is less than the value in the stencil buffer + sfStencilComparisonLessEqual, //!< The stencil test passes if the new value is less than or equal to the value in the stencil buffer + sfStencilComparisonGreater, //!< The stencil test passes if the new value is greater than the value in the stencil buffer + sfStencilComparisonGreaterEqual, //!< The stencil test passes if the new value is greater than or equal to the value in the stencil buffer + sfStencilComparisonEqual, //!< The stencil test passes if the new value is strictly equal to the value in the stencil buffer + sfStencilComparisonNotEqual, //!< The stencil test passes if the new value is strictly unequal to the value in the stencil buffer + sfStencilComparisonAlways //!< The stencil test always passes +} sfStencilComparison; + + +//////////////////////////////////////////////////////// +/// \brief Enumeration of the stencil buffer update operations +/// +/// The update operations are mapped directly to their OpenGL equivalents, +/// specified by `glStencilOp()`. +//////////////////////////////////////////////////////// +typedef enum +{ + sfStencilUpdateOperationKeep, //!< If the stencil test passes, the value in the stencil buffer is not modified + sfStencilUpdateOperationZero, //!< If the stencil test passes, the value in the stencil buffer is set to zero + sfStencilUpdateOperationReplace, //!< If the stencil test passes, the value in the stencil buffer is set to the new value + sfStencilUpdateOperationIncrement, //!< If the stencil test passes, the value in the stencil buffer is incremented and if required clamped + sfStencilUpdateOperationDecrement, //!< If the stencil test passes, the value in the stencil buffer is decremented and if required clamped + sfStencilUpdateOperationInvert, //!< If the stencil test passes, the value in the stencil buffer is bitwise inverted +} sfStencilUpdateOperation; + + +//////////////////////////////////////////////////////// +/// \brief Stencil value type (also used as a mask) +/// +//////////////////////////////////////////////////////// +typedef struct +{ + unsigned int value; //!< The stored stencil value +} sfStencilValue; + + +//////////////////////////////////////////////////////////// +/// \brief Stencil modes for drawing +/// +//////////////////////////////////////////////////////////// +typedef struct +{ + sfStencilComparison stencilComparison; //!< The comparison we're performing the stencil test with + sfStencilUpdateOperation stencilUpdateOperation; //!< The update operation to perform if the stencil test passes + sfStencilValue stencilReference; //!< The reference value we're performing the stencil test with + sfStencilValue stencilMask; //!< The mask to apply to both the reference value and the value in the stencil buffer + bool stencilOnly; //!< Whether we should update the color buffer in addition to the stencil buffer +} sfStencilMode; + +//////////////////////////////////////////////////////////// +/// \brief Define the default values for a StencilMode +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API const sfStencilMode sfStencilMode_default; diff --git a/include/CSFML/Graphics/Texture.h b/include/CSFML/Graphics/Texture.h index 85abe71..3fa5085 100644 --- a/include/CSFML/Graphics/Texture.h +++ b/include/CSFML/Graphics/Texture.h @@ -57,6 +57,16 @@ typedef enum //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfTexture* sfTexture_create(sfVector2u size); +//////////////////////////////////////////////////////////// +/// \brief Create a new sRGB-enabled texture +/// +/// \param size Texture size +/// +/// \return A new sfTexture object, or NULL if it failed +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfTexture* sfTexture_createSrgb(sfVector2u size); + //////////////////////////////////////////////////////////// /// \brief Create a new texture from a file /// diff --git a/include/CSFML/Graphics/View.h b/include/CSFML/Graphics/View.h index 89217fd..2ee4e33 100644 --- a/include/CSFML/Graphics/View.h +++ b/include/CSFML/Graphics/View.h @@ -117,6 +117,29 @@ CSFML_GRAPHICS_API void sfView_setRotation(sfView* view, float angle); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API void sfView_setViewport(sfView* view, sfFloatRect viewport); +//////////////////////////////////////////////////////////// +/// \brief Set the target scissor rectangle +/// +/// The scissor rectangle, expressed as a factor (between 0 and 1) of +/// the RenderTarget, specifies the region of the RenderTarget whose +/// pixels are able to be modified by draw or clear operations. +/// Any pixels which lie outside of the scissor rectangle will +/// not be modified by draw or clear operations. +/// For example, a scissor rectangle which only allows modifications +/// to the right side of the target would be defined +/// with `sfView_setScissor(view, (sfFloatRect){{0.5f, 0.f}, {0.5f, 1.f}})`. +/// By default, a view has a scissor rectangle which allows +/// modifications to the entire target. This is equivalent to +/// disabling the scissor test entirely. Passing the default +/// scissor rectangle to this function will also disable +/// scissor testing. +/// +/// \param view View object +/// \param scissor New scissor rectangle +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API void sfView_setScissor(sfView* view, sfFloatRect scissor); + //////////////////////////////////////////////////////////// /// \brief Get the center of a view /// @@ -157,6 +180,16 @@ CSFML_GRAPHICS_API float sfView_getRotation(const sfView* view); //////////////////////////////////////////////////////////// CSFML_GRAPHICS_API sfFloatRect sfView_getViewport(const sfView* view); +//////////////////////////////////////////////////////////// +/// \brief Get the scissor rectangle of the view +/// +/// \param view View object +/// +/// \return Scissor rectangle, expressed as a factor of the target size +/// +//////////////////////////////////////////////////////////// +CSFML_GRAPHICS_API sfFloatRect sfView_getScissor(const sfView* view); + //////////////////////////////////////////////////////////// /// \brief Move a view relatively to its current position /// diff --git a/include/CSFML/Window/Event.h b/include/CSFML/Window/Event.h index 4866d8a..4130438 100644 --- a/include/CSFML/Window/Event.h +++ b/include/CSFML/Window/Event.h @@ -52,6 +52,7 @@ typedef enum sfEvtMouseButtonPressed, ///< A mouse button was pressed (data in event.mouseButton) sfEvtMouseButtonReleased, ///< A mouse button was released (data in event.mouseButton) sfEvtMouseMoved, ///< The mouse cursor moved (data in event.mouseMove) + sfEvtMouseMovedRaw, ///< The mouse cursor moved (data in event.mouseMove) sfEvtMouseEntered, ///< The mouse cursor entered the area of the window (no data) sfEvtMouseLeft, ///< The mouse cursor left the area of the window (no data) sfEvtJoystickButtonPressed, ///< A joystick button was pressed (data in event.joystickButton) @@ -100,10 +101,19 @@ typedef struct typedef struct { sfEventType type; - int x; - int y; + sfVector2i position; } sfMouseMoveEvent; +//////////////////////////////////////////////////////////// +/// \brief Mouse move raw event parameters +/// +//////////////////////////////////////////////////////////// +typedef struct +{ + sfEventType type; + sfVector2i delta; +} sfMouseMoveRawEvent; + //////////////////////////////////////////////////////////// /// \brief Mouse buttons events parameters /// @@ -112,8 +122,7 @@ typedef struct { sfEventType type; sfMouseButton button; - int x; - int y; + sfVector2i position; } sfMouseButtonEvent; //////////////////////////////////////////////////////////// @@ -125,8 +134,7 @@ typedef struct sfEventType type; sfMouseWheel wheel; float delta; - int x; - int y; + sfVector2i position; } sfMouseWheelScrollEvent; //////////////////////////////////////////////////////////// @@ -168,9 +176,8 @@ typedef struct //////////////////////////////////////////////////////////// typedef struct { - sfEventType type; - unsigned int width; - unsigned int height; + sfEventType type; + sfVector2u size; } sfSizeEvent; //////////////////////////////////////////////////////////// @@ -181,8 +188,7 @@ typedef struct { sfEventType type; unsigned int finger; - int x; - int y; + sfVector2i position; } sfTouchEvent; //////////////////////////////////////////////////////////// @@ -193,9 +199,7 @@ typedef struct { sfEventType type; sfSensorType sensorType; - float x; - float y; - float z; + sfVector3f value; } sfSensorEvent; //////////////////////////////////////////////////////////// @@ -209,6 +213,7 @@ typedef union sfKeyEvent key; ///< Key event parameters sfTextEvent text; ///< Text event parameters sfMouseMoveEvent mouseMove; ///< Mouse move event parameters + sfMouseMoveRawEvent mouseMoveRaw; ///< Mouse move raw event parameters sfMouseButtonEvent mouseButton; ///< Mouse button event parameters sfMouseWheelScrollEvent mouseWheelScroll; ///< Mouse wheel event parameters sfJoystickMoveEvent joystickMove; ///< Joystick move event parameters diff --git a/include/CSFML/Window/Window.h b/include/CSFML/Window/Window.h index e70a5d2..8c32cd8 100644 --- a/include/CSFML/Window/Window.h +++ b/include/CSFML/Window/Window.h @@ -29,6 +29,7 @@ //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -201,7 +202,7 @@ CSFML_WINDOW_API sfContextSettings sfWindow_getSettings(const sfWindow* window); /// to make sure that you process every pending event. /// /// \param window Window object -/// \param event Event to be returned +/// \param event Event to fill, if any /// /// \return true if an event was returned, or false if the event queue was empty /// @@ -212,20 +213,27 @@ CSFML_WINDOW_API bool sfWindow_pollEvent(sfWindow* window, sfEvent* event); /// \brief Wait for an event and return it /// /// This function is blocking: if there's no pending event then -/// it will wait until an event is received. -/// After this function returns (and no error occurred), -/// the \a event object is always valid and filled properly. -/// This function is typically used when you have a thread that -/// is dedicated to events handling: you want to make this thread -/// sleep as long as no new event is received. +/// it will wait until an event is received or until the provided +/// timeout elapses. Only if an error or a timeout occurs the +/// function returns `false`. +/// This function is typically used when you have a thread that is +/// dedicated to events handling: you want to make this thread sleep +/// as long as no new event is received. +/// \code +/// while (sfWindow_waitEvent(window, timeout, &event)) +/// { +/// // process event... +/// } +/// \endcode /// -/// \param window Window object -/// \param event Event to be returned +/// \param window Window object +/// \param timeout Maximum time to wait (`sfTime_Zero` for infinite) +/// \param event Event to fill, if any /// -/// \return false if any error occurred +/// \return true if an event was returned, false if event queue was empty or function timed out /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API bool sfWindow_waitEvent(sfWindow* window, sfEvent* event); +CSFML_WINDOW_API bool sfWindow_waitEvent(sfWindow* window, sfTime timeout, sfEvent* event); //////////////////////////////////////////////////////////// /// \brief Get the position of a window diff --git a/include/CSFML/Window/WindowBase.h b/include/CSFML/Window/WindowBase.h index 17d5317..4d922c0 100644 --- a/include/CSFML/Window/WindowBase.h +++ b/include/CSFML/Window/WindowBase.h @@ -29,6 +29,7 @@ //////////////////////////////////////////////////////////// #include +#include #include #include #include @@ -157,7 +158,7 @@ CSFML_WINDOW_API bool sfWindowBase_isOpen(const sfWindowBase* windowBase); /// to make sure that you process every pending event. /// /// \param windowBase Window object -/// \param event Event to be returned +/// \param event Event to fill, if any /// /// \return true if an event was returned, or false if the event queue was empty /// @@ -168,20 +169,27 @@ CSFML_WINDOW_API bool sfWindowBase_pollEvent(sfWindowBase* windowBase, sfEvent* /// \brief Wait for an event and return it /// /// This function is blocking: if there's no pending event then -/// it will wait until an event is received. -/// After this function returns (and no error occurred), -/// the \a event object is always valid and filled properly. -/// This function is typically used when you have a thread that -/// is dedicated to events handling: you want to make this thread -/// sleep as long as no new event is received. +/// it will wait until an event is received or until the provided +/// timeout elapses. Only if an error or a timeout occurs the +/// function returns `false`. +/// This function is typically used when you have a thread that is +/// dedicated to events handling: you want to make this thread sleep +/// as long as no new event is received. +/// \code +/// while (sfWindowBase_waitEvent(windowBase, timeout, &event)) +/// { +/// // process event... +/// } +/// \endcode /// -/// \param windowBase Window object -/// \param event Event to be returned +/// \param windowBase Window base object +/// \param timeout Maximum time to wait (`sfTime_Zero` for infinite) +/// \param event Event to fill, if any /// -/// \return false if any error occurred +/// \return true if an event was returned, false if event queue was empty or function timed out /// //////////////////////////////////////////////////////////// -CSFML_WINDOW_API bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfEvent* event); +CSFML_WINDOW_API bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfTime timeout, sfEvent* event); //////////////////////////////////////////////////////////// /// \brief Get the position of a window diff --git a/src/CSFML/ConvertEvent.hpp b/src/CSFML/ConvertEvent.hpp index 344bdfd..f92f5f1 100644 --- a/src/CSFML/ConvertEvent.hpp +++ b/src/CSFML/ConvertEvent.hpp @@ -27,6 +27,8 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include +#include #include #include @@ -48,9 +50,8 @@ } else if (const auto* resized = sfmlEvent->getIf()) { - event->type = sfEvtResized; - event->size.width = resized->size.x; - event->size.height = resized->size.y; + event->type = sfEvtResized; + event->size.size = convertVector2(resized->size); } else if (sfmlEvent->is()) { @@ -87,31 +88,32 @@ } else if (const auto* mouseWheelScrolled = sfmlEvent->getIf()) { - event->type = sfEvtMouseWheelScrolled; - event->mouseWheelScroll.wheel = static_cast(mouseWheelScrolled->wheel); - event->mouseWheelScroll.delta = mouseWheelScrolled->delta; - event->mouseWheelScroll.x = mouseWheelScrolled->position.x; - event->mouseWheelScroll.y = mouseWheelScrolled->position.y; + event->type = sfEvtMouseWheelScrolled; + event->mouseWheelScroll.wheel = static_cast(mouseWheelScrolled->wheel); + event->mouseWheelScroll.delta = mouseWheelScrolled->delta; + event->mouseWheelScroll.position = convertVector2(mouseWheelScrolled->position); } else if (const auto* mouseButtonPressed = sfmlEvent->getIf()) { - event->type = sfEvtMouseButtonPressed; - event->mouseButton.button = static_cast(mouseButtonPressed->button); - event->mouseButton.x = mouseButtonPressed->position.x; - event->mouseButton.y = mouseButtonPressed->position.y; + event->type = sfEvtMouseButtonPressed; + event->mouseButton.button = static_cast(mouseButtonPressed->button); + event->mouseButton.position = convertVector2(mouseButtonPressed->position); } else if (const auto* mouseButtonReleased = sfmlEvent->getIf()) { - event->type = sfEvtMouseButtonReleased; - event->mouseButton.button = static_cast(mouseButtonReleased->button); - event->mouseButton.x = mouseButtonReleased->position.x; - event->mouseButton.y = mouseButtonReleased->position.y; + event->type = sfEvtMouseButtonReleased; + event->mouseButton.button = static_cast(mouseButtonReleased->button); + event->mouseButton.position = convertVector2(mouseButtonReleased->position); } else if (const auto* mouseMoved = sfmlEvent->getIf()) { - event->type = sfEvtMouseMoved; - event->mouseMove.x = mouseMoved->position.x; - event->mouseMove.y = mouseMoved->position.y; + event->type = sfEvtMouseMoved; + event->mouseMove.position = convertVector2(mouseMoved->position); + } + else if (const auto* mouseMovedRaw = sfmlEvent->getIf()) + { + event->type = sfEvtMouseMovedRaw; + event->mouseMoveRaw.delta = convertVector2(mouseMovedRaw->delta); } else if (sfmlEvent->is()) { @@ -152,32 +154,27 @@ } else if (const auto* touchBegan = sfmlEvent->getIf()) { - event->type = sfEvtTouchBegan; - event->touch.finger = touchBegan->finger; - event->touch.x = touchBegan->position.x; - event->touch.y = touchBegan->position.y; + event->type = sfEvtTouchBegan; + event->touch.finger = touchBegan->finger; + event->touch.position = convertVector2(touchBegan->position); } else if (const auto* touchMoved = sfmlEvent->getIf()) { - event->type = sfEvtTouchMoved; - event->touch.finger = touchMoved->finger; - event->touch.x = touchMoved->position.x; - event->touch.y = touchMoved->position.y; + event->type = sfEvtTouchMoved; + event->touch.finger = touchMoved->finger; + event->touch.position = convertVector2(touchMoved->position); } else if (const auto* touchEnded = sfmlEvent->getIf()) { - event->type = sfEvtTouchEnded; - event->touch.finger = touchEnded->finger; - event->touch.x = touchEnded->position.x; - event->touch.y = touchEnded->position.y; + event->type = sfEvtTouchEnded; + event->touch.finger = touchEnded->finger; + event->touch.position = convertVector2(touchEnded->position); } else if (const auto* sensorChanged = sfmlEvent->getIf()) { event->type = sfEvtSensorChanged; event->sensor.sensorType = static_cast(sensorChanged->type); - event->sensor.x = sensorChanged->value.x; - event->sensor.y = sensorChanged->value.y; - event->sensor.z = sensorChanged->value.z; + event->sensor.value = convertVector3(sensorChanged->value); } return true; diff --git a/src/CSFML/Graphics/CMakeLists.txt b/src/CSFML/Graphics/CMakeLists.txt index ea25a87..8314201 100644 --- a/src/CSFML/Graphics/CMakeLists.txt +++ b/src/CSFML/Graphics/CMakeLists.txt @@ -14,6 +14,7 @@ set(SRC ${SRCROOT}/ConvertColor.hpp ${SRCROOT}/ConvertRect.hpp ${SRCROOT}/ConvertRenderStates.hpp + ${SRCROOT}/ConvertStencil.hpp ${SRCROOT}/ConvertTransform.hpp ${SRCROOT}/ConvexShape.cpp ${SRCROOT}/ConvexShapeStruct.hpp @@ -47,6 +48,8 @@ set(SRC ${SRCROOT}/Sprite.cpp ${SRCROOT}/SpriteStruct.hpp ${INCROOT}/Sprite.h + ${INCROOT}/StencilMode.h + ${SRCROOT}/StencilMode.cpp ${SRCROOT}/Text.cpp ${SRCROOT}/TextStruct.hpp ${INCROOT}/Text.h diff --git a/src/CSFML/Graphics/ConvertStencil.hpp b/src/CSFML/Graphics/ConvertStencil.hpp new file mode 100644 index 0000000..d3a0584 --- /dev/null +++ b/src/CSFML/Graphics/ConvertStencil.hpp @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2024 Laurent Gomila (laurent@sfml-dev.org) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#pragma once + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + +#include + + +//////////////////////////////////////////////////////////// +// Convert sf::StencilValue to sfStencilValue +//////////////////////////////////////////////////////////// +[[nodiscard]] inline sfStencilValue convertStencilValue(const sf::StencilValue value) +{ + return {value.value}; +} + +//////////////////////////////////////////////////////////// +// Convert sfStencilValue to sf::StencilValue +//////////////////////////////////////////////////////////// +[[nodiscard]] inline sf::StencilValue convertStencilValue(const sfStencilValue value) +{ + return {value.value}; +} + + +//////////////////////////////////////////////////////////// +// Convert sf::StencilMode to sfStencilMode +//////////////////////////////////////////////////////////// +[[nodiscard]] inline sfStencilMode convertStencilMode(const sf::StencilMode value) +{ + return {static_cast(value.stencilComparison), + static_cast(value.stencilUpdateOperation), + convertStencilValue(value.stencilReference), + convertStencilValue(value.stencilMask), + value.stencilOnly}; +} + +//////////////////////////////////////////////////////////// +// Convert sfStencilMode to sf::StencilMode +//////////////////////////////////////////////////////////// +[[nodiscard]] inline sf::StencilMode convertStencilMode(const sfStencilMode value) +{ + return {static_cast(value.stencilComparison), + static_cast(value.stencilUpdateOperation), + convertStencilValue(value.stencilReference), + convertStencilValue(value.stencilMask), + value.stencilOnly}; +} diff --git a/src/CSFML/Graphics/RenderTexture.cpp b/src/CSFML/Graphics/RenderTexture.cpp index aebeadf..f85baf4 100644 --- a/src/CSFML/Graphics/RenderTexture.cpp +++ b/src/CSFML/Graphics/RenderTexture.cpp @@ -29,6 +29,7 @@ #include #include #include +#include #include #include #include @@ -108,6 +109,22 @@ void sfRenderTexture_clear(sfRenderTexture* renderTexture, sfColor color) } +//////////////////////////////////////////////////////////// +void sfRenderTexture_clearStencil(sfRenderTexture* renderTexture, sfStencilValue stencilValue) +{ + assert(renderTexture); + renderTexture->This.clearStencil(convertStencilValue(stencilValue)); +} + + +//////////////////////////////////////////////////////////// +void sfRenderTexture_clearColorAndStencil(sfRenderTexture* renderTexture, sfColor color, sfStencilValue stencilValue) +{ + assert(renderTexture); + renderTexture->This.clear(convertColor(color), convertStencilValue(stencilValue)); +} + + //////////////////////////////////////////////////////////// void sfRenderTexture_setView(sfRenderTexture* renderTexture, const sfView* view) { @@ -143,6 +160,15 @@ sfIntRect sfRenderTexture_getViewport(const sfRenderTexture* renderTexture, cons } +//////////////////////////////////////////////////////////// +sfIntRect sfRenderTexture_getScissor(const sfRenderTexture* renderTexture, const sfView* view) +{ + assert(renderTexture); + assert(view); + return convertRect(renderTexture->This.getScissor(view->This)); +} + + //////////////////////////////////////////////////////////// sfVector2f sfRenderTexture_mapPixelToCoords(const sfRenderTexture* renderTexture, sfVector2i point, const sfView* targetView) { diff --git a/src/CSFML/Graphics/RenderWindow.cpp b/src/CSFML/Graphics/RenderWindow.cpp index 380d34e..b5eeb94 100644 --- a/src/CSFML/Graphics/RenderWindow.cpp +++ b/src/CSFML/Graphics/RenderWindow.cpp @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -149,11 +150,11 @@ bool sfRenderWindow_pollEvent(sfRenderWindow* renderWindow, sfEvent* event) //////////////////////////////////////////////////////////// -bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfEvent* event) +bool sfRenderWindow_waitEvent(sfRenderWindow* renderWindow, sfTime timeout, sfEvent* event) { assert(renderWindow); assert(event); - return convertEvent(renderWindow->This.waitEvent(), event); + return convertEvent(renderWindow->This.waitEvent(sf::microseconds(timeout.microseconds)), event); } @@ -334,6 +335,22 @@ void sfRenderWindow_clear(sfRenderWindow* renderWindow, sfColor color) } +//////////////////////////////////////////////////////////// +void sfRenderWindow_clearStencil(sfRenderWindow* renderWindow, sfStencilValue stencilValue) +{ + assert(renderWindow); + renderWindow->This.clearStencil(convertStencilValue(stencilValue)); +} + + +//////////////////////////////////////////////////////////// +void sfRenderWindow_clearColorAndStencil(sfRenderWindow* renderWindow, sfColor color, sfStencilValue stencilValue) +{ + assert(renderWindow); + renderWindow->This.clear(convertColor(color), convertStencilValue(stencilValue)); +} + + //////////////////////////////////////////////////////////// void sfRenderWindow_setView(sfRenderWindow* renderWindow, const sfView* view) { @@ -369,6 +386,15 @@ sfIntRect sfRenderWindow_getViewport(const sfRenderWindow* renderWindow, const s } +//////////////////////////////////////////////////////////// +sfIntRect sfRenderWindow_getScissor(const sfRenderWindow* renderWindow, const sfView* view) +{ + assert(renderWindow); + assert(view); + return convertRect(renderWindow->This.getScissor(view->This)); +} + + //////////////////////////////////////////////////////////// sfVector2f sfRenderWindow_mapPixelToCoords(const sfRenderWindow* renderWindow, sfVector2i point, const sfView* targetView) { diff --git a/src/CSFML/Graphics/StencilMode.cpp b/src/CSFML/Graphics/StencilMode.cpp new file mode 100644 index 0000000..88246ec --- /dev/null +++ b/src/CSFML/Graphics/StencilMode.cpp @@ -0,0 +1,32 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2024 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 + + +//////////////////////////////////////////////////////////// +const sfStencilMode sfStencilMode_default = {sfStencilComparisonAlways, sfStencilUpdateOperationKeep, {0}, {~0u}, false}; diff --git a/src/CSFML/Graphics/Texture.cpp b/src/CSFML/Graphics/Texture.cpp index b2fe59c..4975460 100644 --- a/src/CSFML/Graphics/Texture.cpp +++ b/src/CSFML/Graphics/Texture.cpp @@ -48,6 +48,17 @@ sfTexture* sfTexture_create(sfVector2u size) } +//////////////////////////////////////////////////////////// +sfTexture* sfTexture_createSrgb(sfVector2u size) +{ + auto texture = std::make_unique(); + if (!texture->This->resize(convertVector2(size), true)) + return nullptr; + + return texture.release(); +} + + //////////////////////////////////////////////////////////// sfTexture* sfTexture_createFromFile(const char* filename, const sfIntRect* area) { diff --git a/src/CSFML/Graphics/View.cpp b/src/CSFML/Graphics/View.cpp index bb3e9fd..d538801 100644 --- a/src/CSFML/Graphics/View.cpp +++ b/src/CSFML/Graphics/View.cpp @@ -92,6 +92,14 @@ void sfView_setViewport(sfView* view, sfFloatRect viewport) } +//////////////////////////////////////////////////////////// +void sfView_setScissor(sfView* view, sfFloatRect scissor) +{ + assert(view); + view->This.setScissor(convertRect(scissor)); +} + + //////////////////////////////////////////////////////////// sfVector2f sfView_getCenter(const sfView* view) { @@ -124,6 +132,14 @@ sfFloatRect sfView_getViewport(const sfView* view) } +//////////////////////////////////////////////////////////// +sfFloatRect sfView_getScissor(const sfView* view) +{ + assert(view); + return convertRect(view->This.getScissor()); +} + + //////////////////////////////////////////////////////////// void sfView_move(sfView* view, sfVector2f offset) { diff --git a/src/CSFML/Window/Window.cpp b/src/CSFML/Window/Window.cpp index 051b6a6..23ba0ea 100644 --- a/src/CSFML/Window/Window.cpp +++ b/src/CSFML/Window/Window.cpp @@ -123,11 +123,11 @@ bool sfWindow_pollEvent(sfWindow* window, sfEvent* event) //////////////////////////////////////////////////////////// -bool sfWindow_waitEvent(sfWindow* window, sfEvent* event) +bool sfWindow_waitEvent(sfWindow* window, sfTime timeout, sfEvent* event) { assert(window); assert(event); - return convertEvent(window->This.waitEvent(), event); + return convertEvent(window->This.waitEvent(sf::microseconds(timeout.microseconds)), event); } diff --git a/src/CSFML/Window/WindowBase.cpp b/src/CSFML/Window/WindowBase.cpp index 3358d74..e6e1143 100644 --- a/src/CSFML/Window/WindowBase.cpp +++ b/src/CSFML/Window/WindowBase.cpp @@ -102,11 +102,11 @@ bool sfWindowBase_pollEvent(sfWindowBase* windowBase, sfEvent* event) //////////////////////////////////////////////////////////// -bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfEvent* event) +bool sfWindowBase_waitEvent(sfWindowBase* windowBase, sfTime timeout, sfEvent* event) { assert(windowBase); assert(event); - return convertEvent(windowBase->This.waitEvent(), event); + return convertEvent(windowBase->This.waitEvent(sf::microseconds(timeout.microseconds)), event); }