From f3aac017447da946bcc15db0e7cdc804bd96c95f Mon Sep 17 00:00:00 2001 From: Chris Thrasher Date: Wed, 1 Mar 2023 22:50:45 -0700 Subject: [PATCH] Use structured bindings --- examples/shader/Shader.cpp | 3 +-- src/SFML/Graphics/RenderTarget.cpp | 5 ++--- src/SFML/Graphics/Texture.cpp | 3 +-- src/SFML/Window/Win32/WindowImplWin32.cpp | 9 ++++----- 4 files changed, 8 insertions(+), 12 deletions(-) diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index 36f612d6..4422f998 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -432,8 +432,7 @@ int main() } // Update the current example - float x = static_cast(sf::Mouse::getPosition(window).x) / static_cast(window.getSize().x); - float y = static_cast(sf::Mouse::getPosition(window).y) / static_cast(window.getSize().y); + const auto [x, y] = sf::Vector2f(sf::Mouse::getPosition(window)).cwiseDiv(sf::Vector2f(window.getSize())); effects[current]->update(clock.getElapsedTime().asSeconds(), x, y); // Clear the window diff --git a/src/SFML/Graphics/RenderTarget.cpp b/src/SFML/Graphics/RenderTarget.cpp index 69bdd086..ab2ef6e5 100644 --- a/src/SFML/Graphics/RenderTarget.cpp +++ b/src/SFML/Graphics/RenderTarget.cpp @@ -190,9 +190,8 @@ const View& RenderTarget::getDefaultView() const //////////////////////////////////////////////////////////// IntRect RenderTarget::getViewport(const View& view) const { - float width = static_cast(getSize().x); - float height = static_cast(getSize().y); - const FloatRect& viewport = view.getViewport(); + const auto [width, height] = Vector2f(getSize()); + const FloatRect& viewport = view.getViewport(); return IntRect({static_cast(0.5f + width * viewport.left), static_cast(0.5f + height * viewport.top)}, {static_cast(0.5f + width * viewport.width), static_cast(0.5f + height * viewport.height)}); diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 89e31461..0d928a49 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -282,8 +282,7 @@ bool Texture::loadFromStream(InputStream& stream, const IntRect& area) bool Texture::loadFromImage(const Image& image, const IntRect& area) { // Retrieve the image size - int width = static_cast(image.getSize().x); - int height = static_cast(image.getSize().y); + const auto [width, height] = Vector2i(image.getSize()); // Load the entire image if the source area is either empty or contains the whole image if (area.width == 0 || (area.height == 0) || diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index a35c67cf..c0ce5f05 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -162,11 +162,10 @@ m_cursorGrabbed(m_fullscreen) registerWindowClass(); // Compute position and size - HDC screenDC = GetDC(nullptr); - int left = (GetDeviceCaps(screenDC, HORZRES) - static_cast(mode.size.x)) / 2; - int top = (GetDeviceCaps(screenDC, VERTRES) - static_cast(mode.size.y)) / 2; - int width = static_cast(mode.size.x); - int height = static_cast(mode.size.y); + HDC screenDC = GetDC(nullptr); + int left = (GetDeviceCaps(screenDC, HORZRES) - static_cast(mode.size.x)) / 2; + int top = (GetDeviceCaps(screenDC, VERTRES) - static_cast(mode.size.y)) / 2; + auto [width, height] = Vector2i(mode.size); ReleaseDC(nullptr, screenDC); // Choose the window style according to the Style parameter