Use structured bindings

This commit is contained in:
Chris Thrasher 2023-03-01 22:50:45 -07:00
parent f371a99b39
commit f3aac01744
4 changed files with 8 additions and 12 deletions

View File

@ -432,8 +432,7 @@ int main()
} }
// Update the current example // Update the current example
float x = static_cast<float>(sf::Mouse::getPosition(window).x) / static_cast<float>(window.getSize().x); const auto [x, y] = sf::Vector2f(sf::Mouse::getPosition(window)).cwiseDiv(sf::Vector2f(window.getSize()));
float y = static_cast<float>(sf::Mouse::getPosition(window).y) / static_cast<float>(window.getSize().y);
effects[current]->update(clock.getElapsedTime().asSeconds(), x, y); effects[current]->update(clock.getElapsedTime().asSeconds(), x, y);
// Clear the window // Clear the window

View File

@ -190,8 +190,7 @@ const View& RenderTarget::getDefaultView() const
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
IntRect RenderTarget::getViewport(const View& view) const IntRect RenderTarget::getViewport(const View& view) const
{ {
float width = static_cast<float>(getSize().x); const auto [width, height] = Vector2f(getSize());
float height = static_cast<float>(getSize().y);
const FloatRect& viewport = view.getViewport(); const FloatRect& viewport = view.getViewport();
return IntRect({static_cast<int>(0.5f + width * viewport.left), static_cast<int>(0.5f + height * viewport.top)}, return IntRect({static_cast<int>(0.5f + width * viewport.left), static_cast<int>(0.5f + height * viewport.top)},

View File

@ -282,8 +282,7 @@ bool Texture::loadFromStream(InputStream& stream, const IntRect& area)
bool Texture::loadFromImage(const Image& image, const IntRect& area) bool Texture::loadFromImage(const Image& image, const IntRect& area)
{ {
// Retrieve the image size // Retrieve the image size
int width = static_cast<int>(image.getSize().x); const auto [width, height] = Vector2i(image.getSize());
int height = static_cast<int>(image.getSize().y);
// Load the entire image if the source area is either empty or contains the whole image // Load the entire image if the source area is either empty or contains the whole image
if (area.width == 0 || (area.height == 0) || if (area.width == 0 || (area.height == 0) ||

View File

@ -165,8 +165,7 @@ m_cursorGrabbed(m_fullscreen)
HDC screenDC = GetDC(nullptr); HDC screenDC = GetDC(nullptr);
int left = (GetDeviceCaps(screenDC, HORZRES) - static_cast<int>(mode.size.x)) / 2; int left = (GetDeviceCaps(screenDC, HORZRES) - static_cast<int>(mode.size.x)) / 2;
int top = (GetDeviceCaps(screenDC, VERTRES) - static_cast<int>(mode.size.y)) / 2; int top = (GetDeviceCaps(screenDC, VERTRES) - static_cast<int>(mode.size.y)) / 2;
int width = static_cast<int>(mode.size.x); auto [width, height] = Vector2i(mode.size);
int height = static_cast<int>(mode.size.y);
ReleaseDC(nullptr, screenDC); ReleaseDC(nullptr, screenDC);
// Choose the window style according to the Style parameter // Choose the window style according to the Style parameter