From c8cf84511dc1bbc9a6ce35c2df2089364d2eb2ec Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Mon, 23 Sep 2024 13:55:33 -0600 Subject: [PATCH] Fix clang-tidy-19 errors --- .clang-tidy | 4 + examples/ftp/Ftp.cpp | 3 + examples/island/Island.cpp | 399 +++++++++--------- examples/opengl/OpenGL.cpp | 3 + examples/sockets/Sockets.cpp | 9 +- examples/sockets/TCP.cpp | 2 + examples/sockets/TCP.hpp | 4 + examples/sockets/UDP.cpp | 2 + examples/sockets/UDP.hpp | 4 + examples/sound/Sound.cpp | 3 + examples/tennis/Tennis.cpp | 3 + examples/voip/Client.cpp | 2 + examples/voip/Client.hpp | 3 + examples/voip/Server.cpp | 2 + examples/voip/Server.hpp | 3 + examples/voip/VoIP.cpp | 11 +- src/SFML/Graphics/GLExtensions.cpp | 6 +- src/SFML/Network/SocketSelector.cpp | 4 +- src/SFML/Window/GlContext.cpp | 2 +- .../Window/macOS/SFKeyboardModifiersHelper.mm | 111 ++--- src/SFML/Window/macOS/WindowImplCocoa.mm | 2 +- test/TestUtilities/GraphicsUtil.hpp | 4 + test/TestUtilities/WindowUtil.cpp | 3 +- test/TestUtilities/WindowUtil.hpp | 4 - 24 files changed, 287 insertions(+), 306 deletions(-) create mode 100644 examples/sockets/TCP.hpp create mode 100644 examples/sockets/UDP.hpp create mode 100644 examples/voip/Client.hpp create mode 100644 examples/voip/Server.hpp diff --git a/.clang-tidy b/.clang-tidy index f03087b2e..a0f06aa94 100644 --- a/.clang-tidy +++ b/.clang-tidy @@ -19,6 +19,7 @@ Checks: > -bugprone-narrowing-conversions, -bugprone-signed-char-misuse, -bugprone-string-integer-assignment, + -bugprone-suspicious-stringview-data-usage, -bugprone-switch-missing-default-case, -bugprone-unchecked-optional-access, -clang-analyzer-nullability.NullablePassedToNonnull, @@ -27,6 +28,7 @@ Checks: > -clang-analyzer-optin.osx.*, -clang-analyzer-osx.*, -clang-analyzer-unix.Malloc, + -clang-analyzer-unix.StdCLibraryFunctions, -cppcoreguidelines-avoid-c-arrays, -cppcoreguidelines-avoid-const-or-ref-data-members, -cppcoreguidelines-avoid-do-while, @@ -62,11 +64,13 @@ Checks: > -readability-avoid-nested-conditional-operator, -readability-braces-around-statements, -readability-convert-member-functions-to-static, + -readability-enum-initial-value, -readability-function-cognitive-complexity, -readability-function-size, -readability-identifier-length, -readability-implicit-bool-conversion, -readability-magic-numbers, + -readability-math-missing-parentheses, -readability-named-parameter, -readability-redundant-casting, -readability-uppercase-literal-suffix, diff --git a/examples/ftp/Ftp.cpp b/examples/ftp/Ftp.cpp index 0de98478f..803f31e2a 100644 --- a/examples/ftp/Ftp.cpp +++ b/examples/ftp/Ftp.cpp @@ -7,6 +7,8 @@ #include +namespace +{ //////////////////////////////////////////////////////////// /// Print a FTP response into a standard output stream /// @@ -15,6 +17,7 @@ std::ostream& operator<<(std::ostream& stream, const sf::Ftp::Response& response { return stream << static_cast(response.getStatus()) << response.getMessage(); } +} // namespace //////////////////////////////////////////////////////////// diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 0f4548121..c8d324c9d 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -69,208 +69,6 @@ float snowcapHeight = 0.6f; float heightFactor = static_cast(windowSize.y) / 2.0f; float heightFlatten = 3.0f; float lightFactor = 0.7f; -} // namespace - - -// Forward declarations of the functions we define further down -void threadFunction(); -void generateTerrain(sf::Vertex* vertexBuffer); - - -//////////////////////////////////////////////////////////// -/// Entry point of application -/// -/// \return Application exit code -/// -//////////////////////////////////////////////////////////// -int main() -{ - // Create the window of the application - sf::RenderWindow window(sf::VideoMode(windowSize), "SFML Island", sf::Style::Titlebar | sf::Style::Close); - window.setVerticalSyncEnabled(true); - - const sf::Font font("resources/tuffy.ttf"); - - // Create all of our graphics resources - sf::Text hudText(font); - sf::Text statusText(font); - sf::Shader terrainShader; - sf::RenderStates terrainStates; - sf::VertexBuffer terrain(sf::PrimitiveType::Triangles, sf::VertexBuffer::Usage::Static); - - // Set up our text drawables - statusText.setCharacterSize(28); - statusText.setFillColor(sf::Color::White); - statusText.setOutlineColor(sf::Color::Black); - statusText.setOutlineThickness(2.0f); - - hudText.setCharacterSize(14); - hudText.setFillColor(sf::Color::White); - hudText.setOutlineColor(sf::Color::Black); - hudText.setOutlineThickness(2.0f); - hudText.setPosition({5.0f, 5.0f}); - - // Staging buffer for our terrain data that we will upload to our VertexBuffer - std::vector terrainStagingBuffer; - - // Set up our graphics resources and set the status text accordingly - if (!sf::VertexBuffer::isAvailable() || !sf::Shader::isAvailable()) - { - statusText.setString("Shaders and/or Vertex Buffers Unsupported"); - } - else if (!terrainShader.loadFromFile("resources/terrain.vert", "resources/terrain.frag")) - { - statusText.setString("Failed to load shader program"); - } - else - { - // Start up our thread pool - for (unsigned int i = 0; i < threadCount; ++i) - { - threads.emplace_back(threadFunction); - } - - // Create our VertexBuffer with enough space to hold all the terrain geometry - if (!terrain.create(resolution.x * resolution.y * 6)) - { - std::cerr << "Failed to create vertex buffer" << std::endl; - return EXIT_FAILURE; - } - - // Resize the staging buffer to be able to hold all the terrain geometry - terrainStagingBuffer.resize(resolution.x * resolution.y * 6); - - // Generate the initial terrain - generateTerrain(terrainStagingBuffer.data()); - - statusText.setString("Generating Terrain..."); - - // Set up the render states - terrainStates = sf::RenderStates(&terrainShader); - } - - // Center the status text - statusText.setPosition((sf::Vector2f(windowSize) - statusText.getLocalBounds().size) / 2.f); - - // Set up an array of pointers to our settings for arrow navigation - constexpr std::array settings = { - {{"perlinFrequency", &perlinFrequency}, - {"perlinFrequencyBase", &perlinFrequencyBase}, - {"heightBase", &heightBase}, - {"edgeFactor", &edgeFactor}, - {"edgeDropoffExponent", &edgeDropoffExponent}, - {"snowcapHeight", &snowcapHeight}, - {"heightFactor", &heightFactor}, - {"heightFlatten", &heightFlatten}, - {"lightFactor", &lightFactor}}}; - - std::size_t currentSetting = 0; - - std::ostringstream osstr; - sf::Clock clock; - - while (window.isOpen()) - { - // Handle events - while (const std::optional event = window.pollEvent()) - { - // Window closed or escape key pressed: exit - if (event->is() || - (event->is() && - event->getIf()->code == sf::Keyboard::Key::Escape)) - { - window.close(); - break; - } - - // Arrow key pressed: - // TODO Replace use of getNativeHandle() when validity function is added - if (terrainShader.getNativeHandle() != 0 && event->is()) - { - switch (event->getIf()->code) - { - case sf::Keyboard::Key::Enter: - generateTerrain(terrainStagingBuffer.data()); - break; - case sf::Keyboard::Key::Down: - currentSetting = (currentSetting + 1) % settings.size(); - break; - case sf::Keyboard::Key::Up: - currentSetting = (currentSetting + settings.size() - 1) % settings.size(); - break; - case sf::Keyboard::Key::Left: - *(settings[currentSetting].value) -= 0.1f; - break; - case sf::Keyboard::Key::Right: - *(settings[currentSetting].value) += 0.1f; - break; - default: - break; - } - } - } - - // Clear, draw graphics objects and display - window.clear(); - - window.draw(statusText); - - if (terrainShader.getNativeHandle() != 0) - { - { - const std::lock_guard lock(workQueueMutex); - - // Don't bother updating/drawing the VertexBuffer while terrain is being regenerated - if (!pendingWorkCount) - { - // If there is new data pending to be uploaded to the VertexBuffer, do it now - if (bufferUploadPending) - { - if (!terrain.update(terrainStagingBuffer.data())) - { - std::cerr << "Failed to update vertex buffer" << std::endl; - return EXIT_FAILURE; - } - - bufferUploadPending = false; - } - - terrainShader.setUniform("lightFactor", lightFactor); - window.draw(terrain, terrainStates); - } - } - - // Update and draw the HUD text - osstr.str(""); - osstr << "Frame: " << clock.restart().asMilliseconds() << "ms\n" - << "perlinOctaves: " << perlinOctaves << "\n\n" - << "Use the arrow keys to change the values.\nUse the return key to regenerate the terrain.\n\n"; - - for (std::size_t i = 0; i < settings.size(); ++i) - osstr << ((i == currentSetting) ? ">> " : " ") << settings[i].name << ": " - << *(settings[i].value) << '\n'; - - hudText.setString(osstr.str()); - - window.draw(hudText); - } - - // Display things on screen - window.display(); - } - - // Shut down our thread pool - { - const std::lock_guard lock(workQueueMutex); - workPending = false; - } - - while (!threads.empty()) - { - threads.back().join(); - threads.pop_back(); - } -} //////////////////////////////////////////////////////////// @@ -620,3 +418,200 @@ void generateTerrain(sf::Vertex* buffer) pendingWorkCount = blockCount; } } +} // namespace + + +//////////////////////////////////////////////////////////// +/// Entry point of application +/// +/// \return Application exit code +/// +//////////////////////////////////////////////////////////// +int main() +{ + // Create the window of the application + sf::RenderWindow window(sf::VideoMode(windowSize), "SFML Island", sf::Style::Titlebar | sf::Style::Close); + window.setVerticalSyncEnabled(true); + + const sf::Font font("resources/tuffy.ttf"); + + // Create all of our graphics resources + sf::Text hudText(font); + sf::Text statusText(font); + sf::Shader terrainShader; + sf::RenderStates terrainStates; + sf::VertexBuffer terrain(sf::PrimitiveType::Triangles, sf::VertexBuffer::Usage::Static); + + // Set up our text drawables + statusText.setCharacterSize(28); + statusText.setFillColor(sf::Color::White); + statusText.setOutlineColor(sf::Color::Black); + statusText.setOutlineThickness(2.0f); + + hudText.setCharacterSize(14); + hudText.setFillColor(sf::Color::White); + hudText.setOutlineColor(sf::Color::Black); + hudText.setOutlineThickness(2.0f); + hudText.setPosition({5.0f, 5.0f}); + + // Staging buffer for our terrain data that we will upload to our VertexBuffer + std::vector terrainStagingBuffer; + + // Set up our graphics resources and set the status text accordingly + if (!sf::VertexBuffer::isAvailable() || !sf::Shader::isAvailable()) + { + statusText.setString("Shaders and/or Vertex Buffers Unsupported"); + } + else if (!terrainShader.loadFromFile("resources/terrain.vert", "resources/terrain.frag")) + { + statusText.setString("Failed to load shader program"); + } + else + { + // Start up our thread pool + for (unsigned int i = 0; i < threadCount; ++i) + { + threads.emplace_back(threadFunction); + } + + // Create our VertexBuffer with enough space to hold all the terrain geometry + if (!terrain.create(resolution.x * resolution.y * 6)) + { + std::cerr << "Failed to create vertex buffer" << std::endl; + return EXIT_FAILURE; + } + + // Resize the staging buffer to be able to hold all the terrain geometry + terrainStagingBuffer.resize(resolution.x * resolution.y * 6); + + // Generate the initial terrain + generateTerrain(terrainStagingBuffer.data()); + + statusText.setString("Generating Terrain..."); + + // Set up the render states + terrainStates = sf::RenderStates(&terrainShader); + } + + // Center the status text + statusText.setPosition((sf::Vector2f(windowSize) - statusText.getLocalBounds().size) / 2.f); + + // Set up an array of pointers to our settings for arrow navigation + constexpr std::array settings = { + {{"perlinFrequency", &perlinFrequency}, + {"perlinFrequencyBase", &perlinFrequencyBase}, + {"heightBase", &heightBase}, + {"edgeFactor", &edgeFactor}, + {"edgeDropoffExponent", &edgeDropoffExponent}, + {"snowcapHeight", &snowcapHeight}, + {"heightFactor", &heightFactor}, + {"heightFlatten", &heightFlatten}, + {"lightFactor", &lightFactor}}}; + + std::size_t currentSetting = 0; + + std::ostringstream osstr; + sf::Clock clock; + + while (window.isOpen()) + { + // Handle events + while (const std::optional event = window.pollEvent()) + { + // Window closed or escape key pressed: exit + if (event->is() || + (event->is() && + event->getIf()->code == sf::Keyboard::Key::Escape)) + { + window.close(); + break; + } + + // Arrow key pressed: + // TODO Replace use of getNativeHandle() when validity function is added + if (terrainShader.getNativeHandle() != 0 && event->is()) + { + switch (event->getIf()->code) + { + case sf::Keyboard::Key::Enter: + generateTerrain(terrainStagingBuffer.data()); + break; + case sf::Keyboard::Key::Down: + currentSetting = (currentSetting + 1) % settings.size(); + break; + case sf::Keyboard::Key::Up: + currentSetting = (currentSetting + settings.size() - 1) % settings.size(); + break; + case sf::Keyboard::Key::Left: + *(settings[currentSetting].value) -= 0.1f; + break; + case sf::Keyboard::Key::Right: + *(settings[currentSetting].value) += 0.1f; + break; + default: + break; + } + } + } + + // Clear, draw graphics objects and display + window.clear(); + + window.draw(statusText); + + if (terrainShader.getNativeHandle() != 0) + { + { + const std::lock_guard lock(workQueueMutex); + + // Don't bother updating/drawing the VertexBuffer while terrain is being regenerated + if (!pendingWorkCount) + { + // If there is new data pending to be uploaded to the VertexBuffer, do it now + if (bufferUploadPending) + { + if (!terrain.update(terrainStagingBuffer.data())) + { + std::cerr << "Failed to update vertex buffer" << std::endl; + return EXIT_FAILURE; + } + + bufferUploadPending = false; + } + + terrainShader.setUniform("lightFactor", lightFactor); + window.draw(terrain, terrainStates); + } + } + + // Update and draw the HUD text + osstr.str(""); + osstr << "Frame: " << clock.restart().asMilliseconds() << "ms\n" + << "perlinOctaves: " << perlinOctaves << "\n\n" + << "Use the arrow keys to change the values.\nUse the return key to regenerate the terrain.\n\n"; + + for (std::size_t i = 0; i < settings.size(); ++i) + osstr << ((i == currentSetting) ? ">> " : " ") << settings[i].name << ": " + << *(settings[i].value) << '\n'; + + hudText.setString(osstr.str()); + + window.draw(hudText); + } + + // Display things on screen + window.display(); + } + + // Shut down our thread pool + { + const std::lock_guard lock(workQueueMutex); + workPending = false; + } + + while (!threads.empty()) + { + threads.back().join(); + threads.pop_back(); + } +} diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index 6d7f77332..538d19d1a 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -20,6 +20,8 @@ #define GL_SRGB8_ALPHA8 0x8C43 #endif +namespace +{ std::filesystem::path resourcesDir() { #ifdef SFML_SYSTEM_IOS @@ -28,6 +30,7 @@ std::filesystem::path resourcesDir() return "resources"; #endif } +} // namespace //////////////////////////////////////////////////////////// /// Entry point of application diff --git a/examples/sockets/Sockets.cpp b/examples/sockets/Sockets.cpp index 5a59b5211..b9721ec73 100644 --- a/examples/sockets/Sockets.cpp +++ b/examples/sockets/Sockets.cpp @@ -1,15 +1,12 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include "TCP.hpp" +#include "UDP.hpp" + #include -void runTcpServer(unsigned short port); -void runTcpClient(unsigned short port); -void runUdpServer(unsigned short port); -void runUdpClient(unsigned short port); - - //////////////////////////////////////////////////////////// /// Entry point of application /// diff --git a/examples/sockets/TCP.cpp b/examples/sockets/TCP.cpp index cc4d2bcfc..86556576f 100644 --- a/examples/sockets/TCP.cpp +++ b/examples/sockets/TCP.cpp @@ -1,6 +1,8 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include "TCP.hpp" + #include #include diff --git a/examples/sockets/TCP.hpp b/examples/sockets/TCP.hpp new file mode 100644 index 000000000..d28e5a5f3 --- /dev/null +++ b/examples/sockets/TCP.hpp @@ -0,0 +1,4 @@ +#pragma once + +void runTcpServer(unsigned short port); +void runTcpClient(unsigned short port); diff --git a/examples/sockets/UDP.cpp b/examples/sockets/UDP.cpp index 594a28450..e0b688136 100644 --- a/examples/sockets/UDP.cpp +++ b/examples/sockets/UDP.cpp @@ -1,6 +1,8 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include "UDP.hpp" + #include #include diff --git a/examples/sockets/UDP.hpp b/examples/sockets/UDP.hpp new file mode 100644 index 000000000..4bf259c4e --- /dev/null +++ b/examples/sockets/UDP.hpp @@ -0,0 +1,4 @@ +#pragma once + +void runUdpServer(unsigned short port); +void runUdpClient(unsigned short port); diff --git a/examples/sound/Sound.cpp b/examples/sound/Sound.cpp index fe17d3114..88ef1709a 100644 --- a/examples/sound/Sound.cpp +++ b/examples/sound/Sound.cpp @@ -6,6 +6,8 @@ #include +namespace +{ //////////////////////////////////////////////////////////// /// Play a sound /// @@ -69,6 +71,7 @@ void playMusic(const std::filesystem::path& filename) std::cout << '\n' << std::endl; } +} // namespace //////////////////////////////////////////////////////////// diff --git a/examples/tennis/Tennis.cpp b/examples/tennis/Tennis.cpp index 0aa62a67c..a808597af 100644 --- a/examples/tennis/Tennis.cpp +++ b/examples/tennis/Tennis.cpp @@ -16,6 +16,8 @@ #include #endif +namespace +{ std::filesystem::path resourcesDir() { #ifdef SFML_SYSTEM_IOS @@ -24,6 +26,7 @@ std::filesystem::path resourcesDir() return "resources"; #endif } +} // namespace //////////////////////////////////////////////////////////// /// Entry point of application diff --git a/examples/voip/Client.cpp b/examples/voip/Client.cpp index 128da5b17..842ec6897 100644 --- a/examples/voip/Client.cpp +++ b/examples/voip/Client.cpp @@ -1,6 +1,8 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include "Client.hpp" + #include #include diff --git a/examples/voip/Client.hpp b/examples/voip/Client.hpp new file mode 100644 index 000000000..af49849e1 --- /dev/null +++ b/examples/voip/Client.hpp @@ -0,0 +1,3 @@ +#pragma once + +void doClient(unsigned short port); diff --git a/examples/voip/Server.cpp b/examples/voip/Server.cpp index 6d714bb33..978a654ef 100644 --- a/examples/voip/Server.cpp +++ b/examples/voip/Server.cpp @@ -1,6 +1,8 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include "Server.hpp" + #include #include diff --git a/examples/voip/Server.hpp b/examples/voip/Server.hpp new file mode 100644 index 000000000..08c60c895 --- /dev/null +++ b/examples/voip/Server.hpp @@ -0,0 +1,3 @@ +#pragma once + +void doServer(unsigned short port); diff --git a/examples/voip/VoIP.cpp b/examples/voip/VoIP.cpp index a97c64cab..fd3eb20f1 100644 --- a/examples/voip/VoIP.cpp +++ b/examples/voip/VoIP.cpp @@ -1,17 +1,12 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include "Client.hpp" +#include "Server.hpp" + #include -//////////////////////////////////////////////////////////// -// Function prototypes -// (I'm too lazy to put them into separate headers...) -//////////////////////////////////////////////////////////// -void doClient(unsigned short port); -void doServer(unsigned short port); - - //////////////////////////////////////////////////////////// /// Entry point of application /// diff --git a/src/SFML/Graphics/GLExtensions.cpp b/src/SFML/Graphics/GLExtensions.cpp index 8a83089ff..a2baf58c8 100644 --- a/src/SFML/Graphics/GLExtensions.cpp +++ b/src/SFML/Graphics/GLExtensions.cpp @@ -50,7 +50,7 @@ #endif -namespace sf::priv +namespace { //////////////////////////////////////////////////////////// void extensionSanityCheck() @@ -82,8 +82,10 @@ void extensionSanityCheck() check(GLEXT_copy_buffer_dependencies); #endif } +} // namespace - +namespace sf::priv +{ //////////////////////////////////////////////////////////// void ensureExtensionsInit() { diff --git a/src/SFML/Network/SocketSelector.cpp b/src/SFML/Network/SocketSelector.cpp index 86c750fcf..3ff8eed41 100644 --- a/src/SFML/Network/SocketSelector.cpp +++ b/src/SFML/Network/SocketSelector.cpp @@ -31,6 +31,7 @@ #include +#include #include #include #include @@ -119,8 +120,7 @@ void SocketSelector::add(Socket& socket) } // SocketHandle is an int in POSIX - if (m_impl->maxSocket < handle) - m_impl->maxSocket = handle; + m_impl->maxSocket = std::max(m_impl->maxSocket, handle); #endif diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 51d6b7ce2..4e4104550 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -388,7 +388,7 @@ struct GlContext::TransientContext //////////////////////////////////////////////////////////// static std::optional& get() { - thread_local std::optional transientContext; + static thread_local std::optional transientContext; return transientContext; } diff --git a/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm b/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm index 06580e44a..f44d72232 100644 --- a/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm +++ b/src/SFML/Window/macOS/SFKeyboardModifiersHelper.mm @@ -75,33 +75,40 @@ namespace /// Share 'modifiers' state with all windows to correctly fire pressed/released events ModifiersState state; BOOL isStateInitialized = NO; + +//////////////////////////////////////////////////////// +BOOL isKeyMaskActive(NSUInteger modifiers, NSUInteger mask) +{ + // Here we need to make sure it's exactly the mask since some masks + // share some bits such that the & operation would result in a non zero + // value without corresponding to the processed key. + return (modifiers & mask) == mask; } - -//////////////////////////////////////////////////////////// -// Local & Private Functions -//////////////////////////////////////////////////////////// - -//////////////////////////////////////////////////////////// -/// \brief Carefully observe if the key mask is on in the modifiers -/// -//////////////////////////////////////////////////////////// -BOOL isKeyMaskActive(NSUInteger modifiers, NSUInteger mask); - - -//////////////////////////////////////////////////////////// -/// \brief Handle one modifier key mask -/// -/// Update the key state and send events to the requester -/// -//////////////////////////////////////////////////////////// +//////////////////////////////////////////////////////// void processOneModifier(NSUInteger modifiers, NSUInteger mask, BOOL& wasDown, sf::Keyboard::Key key, sf::Keyboard::Scancode code, - sf::priv::WindowImplCocoa& requester); + sf::priv::WindowImplCocoa& requester) +{ + // State + const BOOL isDown = isKeyMaskActive(modifiers, mask); + // Check for key pressed event + if (isDown && !wasDown) + requester.keyDown(keyPressedEventWithModifiers(modifiers, key, code)); + + // And check for key released event + else if (!isDown && wasDown) + requester.keyUp(keyReleasedEventWithModifiers(modifiers, key, code)); + + // else isDown == wasDown, so no change + + // Update state + wasDown = isDown; +} //////////////////////////////////////////////////////////// /// \brief Handle left & right modifier keys @@ -119,12 +126,12 @@ void processLeftRightModifiers( sf::Keyboard::Key rightKey, sf::Keyboard::Scancode leftCode, sf::Keyboard::Scancode rightCode, - sf::priv::WindowImplCocoa& requester); - - -//////////////////////////////////////////////////////////// -// Implementations -//////////////////////////////////////////////////////////// + sf::priv::WindowImplCocoa& requester) +{ + processOneModifier(modifiers, leftMask, leftWasDown, leftKey, leftCode, requester); + processOneModifier(modifiers, rightMask, rightWasDown, rightKey, rightCode, requester); +} +} //////////////////////////////////////////////////////// @@ -237,57 +244,3 @@ void handleModifiersChanged(NSUInteger modifiers, sf::priv::WindowImplCocoa& req sf::Keyboard::Scan::CapsLock, requester); } - - -//////////////////////////////////////////////////////// -BOOL isKeyMaskActive(NSUInteger modifiers, NSUInteger mask) -{ - // Here we need to make sure it's exactly the mask since some masks - // share some bits such that the & operation would result in a non zero - // value without corresponding to the processed key. - return (modifiers & mask) == mask; -} - - -//////////////////////////////////////////////////////// -void processOneModifier(NSUInteger modifiers, - NSUInteger mask, - BOOL& wasDown, - sf::Keyboard::Key key, - sf::Keyboard::Scancode code, - sf::priv::WindowImplCocoa& requester) -{ - // State - const BOOL isDown = isKeyMaskActive(modifiers, mask); - - // Check for key pressed event - if (isDown && !wasDown) - requester.keyDown(keyPressedEventWithModifiers(modifiers, key, code)); - - // And check for key released event - else if (!isDown && wasDown) - requester.keyUp(keyReleasedEventWithModifiers(modifiers, key, code)); - - // else isDown == wasDown, so no change - - // Update state - wasDown = isDown; -} - - -//////////////////////////////////////////////////////// -void processLeftRightModifiers( - NSUInteger modifiers, - NSUInteger leftMask, - NSUInteger rightMask, - BOOL& leftWasDown, - BOOL& rightWasDown, - sf::Keyboard::Key leftKey, - sf::Keyboard::Key rightKey, - sf::Keyboard::Scancode leftCode, - sf::Keyboard::Scancode rightCode, - sf::priv::WindowImplCocoa& requester) -{ - processOneModifier(modifiers, leftMask, leftWasDown, leftKey, leftCode, requester); - processOneModifier(modifiers, rightMask, rightWasDown, rightKey, rightCode, requester); -} diff --git a/src/SFML/Window/macOS/WindowImplCocoa.mm b/src/SFML/Window/macOS/WindowImplCocoa.mm index c09f1f60f..c7d66b124 100644 --- a/src/SFML/Window/macOS/WindowImplCocoa.mm +++ b/src/SFML/Window/macOS/WindowImplCocoa.mm @@ -69,7 +69,6 @@ NSString* sfStringToNSString(const sf::String& string) NSString* const str = [[NSString alloc] initWithBytes:data length:length encoding:encoding]; return [str autorelease]; } -} //////////////////////////////////////////////////////// @@ -94,6 +93,7 @@ void showMouseCursor() isCursorHidden = false; } } +} #pragma mark #pragma mark WindowImplCocoa's ctor/dtor diff --git a/test/TestUtilities/GraphicsUtil.hpp b/test/TestUtilities/GraphicsUtil.hpp index c6349cc8a..3c7baf3e6 100644 --- a/test/TestUtilities/GraphicsUtil.hpp +++ b/test/TestUtilities/GraphicsUtil.hpp @@ -11,6 +11,8 @@ namespace sf { struct BlendMode; +enum class StencilComparison; +enum class StencilUpdateOperation; struct StencilMode; class Color; class Transform; @@ -19,6 +21,8 @@ template class Rect; std::ostream& operator<<(std::ostream& os, const BlendMode& blendMode); +std::ostream& operator<<(std::ostream& os, const StencilComparison& comparison); +std::ostream& operator<<(std::ostream& os, const StencilUpdateOperation& updateOperation); std::ostream& operator<<(std::ostream& os, const StencilMode& stencilMode); std::ostream& operator<<(std::ostream& os, Color color); std::ostream& operator<<(std::ostream& os, const Transform& transform); diff --git a/test/TestUtilities/WindowUtil.cpp b/test/TestUtilities/WindowUtil.cpp index 83a7c030c..8114ddb55 100644 --- a/test/TestUtilities/WindowUtil.cpp +++ b/test/TestUtilities/WindowUtil.cpp @@ -1,4 +1,5 @@ -// Note: No need to increase compile time by including TestUtilities/Window.hpp +#include "WindowUtil.hpp" + #include #include diff --git a/test/TestUtilities/WindowUtil.hpp b/test/TestUtilities/WindowUtil.hpp index 869250342..85868e571 100644 --- a/test/TestUtilities/WindowUtil.hpp +++ b/test/TestUtilities/WindowUtil.hpp @@ -8,8 +8,6 @@ #include #include -// Required because WindowUtil.cpp doesn't include WindowUtil.hpp -// NOLINTNEXTLINE(readability-redundant-declaration) std::string runDisplayTests(); // String conversions for Catch2 @@ -17,7 +15,5 @@ namespace sf { class VideoMode; -// Required because WindowUtil.cpp doesn't include WindowUtil.hpp -// NOLINTNEXTLINE(readability-redundant-declaration) std::ostream& operator<<(std::ostream& os, const VideoMode& videoMode); } // namespace sf