diff --git a/examples/android/app/src/main/jni/main.cpp b/examples/android/app/src/main/jni/main.cpp index d9c9d58d..8d794f73 100644 --- a/examples/android/app/src/main/jni/main.cpp +++ b/examples/android/app/src/main/jni/main.cpp @@ -87,8 +87,8 @@ int main(int argc, char *argv[]) return EXIT_FAILURE; sf::Sprite image(texture); - image.setPosition({screen.width / 2.f, screen.height / 2.f}); - image.setOrigin({texture.getSize().x / 2.f, texture.getSize().y / 2.f}); + image.setPosition(sf::Vector2f(screen.size) / 2.f); + image.setOrigin(sf::Vector2f(texture.getSize()) / 2.f); sf::Font font; if (!font.loadFromFile("tuffy.ttf")) @@ -123,8 +123,8 @@ int main(int argc, char *argv[]) window.close(); break; case sf::Event::Resized: - view.setSize(event.size.width, event.size.height); - view.setCenter({event.size.width / 2.f, event.size.height / 2.f}); + view.setSize(sf::Vector2f(event.size.width, event.size.height)); + view.setCenter(sf::Vector2f(event.size.width, event.size.height) / 2.f); window.setView(view); break; case sf::Event::LostFocus: diff --git a/examples/island/Island.cpp b/examples/island/Island.cpp index 2d145b06..21bb0086 100644 --- a/examples/island/Island.cpp +++ b/examples/island/Island.cpp @@ -87,7 +87,7 @@ void generateTerrain(sf::Vertex* vertexBuffer); int main() { // Create the window of the application - sf::RenderWindow window(sf::VideoMode(windowWidth, windowHeight), "SFML Island", + sf::RenderWindow window(sf::VideoMode({windowWidth, windowHeight}), "SFML Island", sf::Style::Titlebar | sf::Style::Close); window.setVerticalSyncEnabled(true); diff --git a/examples/joystick/Joystick.cpp b/examples/joystick/Joystick.cpp index 06367742..107389a0 100644 --- a/examples/joystick/Joystick.cpp +++ b/examples/joystick/Joystick.cpp @@ -87,7 +87,7 @@ namespace int main() { // Create the window of the application - sf::RenderWindow window(sf::VideoMode(400, 775), "Joystick", sf::Style::Close); + sf::RenderWindow window(sf::VideoMode({400, 775}), "Joystick", sf::Style::Close); window.setVerticalSyncEnabled(true); // Load the text font diff --git a/examples/opengl/OpenGL.cpp b/examples/opengl/OpenGL.cpp index 78d339d3..df8cb5a2 100644 --- a/examples/opengl/OpenGL.cpp +++ b/examples/opengl/OpenGL.cpp @@ -45,7 +45,7 @@ int main() contextSettings.sRgbCapable = sRgb; // Create the main window - sf::RenderWindow window(sf::VideoMode(800, 600), "SFML graphics with OpenGL", sf::Style::Default, contextSettings); + sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML graphics with OpenGL", sf::Style::Default, contextSettings); window.setVerticalSyncEnabled(true); // Create a sprite for the background diff --git a/examples/shader/Shader.cpp b/examples/shader/Shader.cpp index d826e90d..c25031dc 100644 --- a/examples/shader/Shader.cpp +++ b/examples/shader/Shader.cpp @@ -192,7 +192,7 @@ public: bool onLoad() override { // Create the off-screen surface - if (!m_surface.create(800, 600)) + if (!m_surface.create({800, 600})) return false; m_surface.setSmooth(true); @@ -352,7 +352,7 @@ private: int main() { // Create the main window - sf::RenderWindow window(sf::VideoMode(800, 600), "SFML Shader", + sf::RenderWindow window(sf::VideoMode({800, 600}), "SFML Shader", sf::Style::Titlebar | sf::Style::Close); window.setVerticalSyncEnabled(true); diff --git a/examples/tennis/Tennis.cpp b/examples/tennis/Tennis.cpp index 1bce9c31..98c28cf0 100644 --- a/examples/tennis/Tennis.cpp +++ b/examples/tennis/Tennis.cpp @@ -38,7 +38,7 @@ int main() float ballRadius = 10.f; // Create the window of the application - sf::RenderWindow window(sf::VideoMode(static_cast(gameWidth), static_cast(gameHeight), 32), "SFML Tennis", + sf::RenderWindow window(sf::VideoMode({static_cast(gameWidth), static_cast(gameHeight)}, 32), "SFML Tennis", sf::Style::Titlebar | sf::Style::Close); window.setVerticalSyncEnabled(true); @@ -151,7 +151,7 @@ int main() if (event.type == sf::Event::Resized) { sf::View view; - view.setSize(gameWidth, gameHeight); + view.setSize({gameWidth, gameHeight}); view.setCenter({gameWidth / 2.f, gameHeight / 2.f}); window.setView(view); } diff --git a/examples/vulkan/Vulkan.cpp b/examples/vulkan/Vulkan.cpp index 988ec465..88005b69 100644 --- a/examples/vulkan/Vulkan.cpp +++ b/examples/vulkan/Vulkan.cpp @@ -187,7 +187,7 @@ class VulkanExample public: // Constructor VulkanExample() : - window(sf::VideoMode(800, 600), "SFML window with Vulkan", sf::Style::Default), + window(sf::VideoMode({800, 600}), "SFML window with Vulkan", sf::Style::Default), vulkanAvailable(sf::Vulkan::isAvailable()), maxFramesInFlight(2), currentFrame(0), diff --git a/examples/window/Window.cpp b/examples/window/Window.cpp index 83c84a56..af236caa 100644 --- a/examples/window/Window.cpp +++ b/examples/window/Window.cpp @@ -27,7 +27,7 @@ int main() contextSettings.depthBits = 24; // Create the main window - sf::Window window(sf::VideoMode(640, 480), "SFML window with OpenGL", sf::Style::Default, contextSettings); + sf::Window window(sf::VideoMode({640, 480}), "SFML window with OpenGL", sf::Style::Default, contextSettings); // Make it the active window for OpenGL calls if (!window.setActive()) diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index ce9bda6f..0d2097f6 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -395,14 +395,13 @@ private: //////////////////////////////////////////////////////////// /// \brief Find a suitable rectangle within the texture for a glyph /// - /// \param page Page of glyphs to search in - /// \param width Width of the rectangle - /// \param height Height of the rectangle + /// \param page Page of glyphs to search in + /// \param size Width and height of the rectangle /// /// \return Found rectangle within the texture /// //////////////////////////////////////////////////////////// - IntRect findGlyphRect(Page& page, unsigned int width, unsigned int height) const; + IntRect findGlyphRect(Page& page, const Vector2u& size) const; //////////////////////////////////////////////////////////// /// \brief Make sure that the given size is the current one diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 309058a1..468eb4d0 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -89,12 +89,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Create the image and fill it with a unique color /// - /// \param width Width of the image - /// \param height Height of the image - /// \param color Fill color + /// \param size Width and height of the image + /// \param color Fill color /// //////////////////////////////////////////////////////////// - void create(unsigned int width, unsigned int height, const Color& color = Color(0, 0, 0)); + void create(const Vector2u& size, const Color& color = Color(0, 0, 0)); //////////////////////////////////////////////////////////// /// \brief Create the image from an array of pixels @@ -104,12 +103,11 @@ public: /// an undefined behavior. /// If \a pixels is null, an empty image is created. /// - /// \param width Width of the image - /// \param height Height of the image + /// \param size Width and height of the image /// \param pixels Array of pixels to copy to the image /// //////////////////////////////////////////////////////////// - void create(unsigned int width, unsigned int height, const Uint8* pixels); + void create(const Vector2u& size, const Uint8* pixels); //////////////////////////////////////////////////////////// /// \brief Load the image from a file on disk @@ -237,13 +235,12 @@ public: /// details on the \b over operator. /// /// \param source Source image to copy - /// \param destX X coordinate of the destination position - /// \param destY Y coordinate of the destination position + /// \param dest Coordinates of the destination position /// \param sourceRect Sub-rectangle of the source image to copy /// \param applyAlpha Should the copy take into account the source transparency? /// //////////////////////////////////////////////////////////// - void copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect = IntRect({0, 0}, {0, 0}), bool applyAlpha = false); + void copy(const Image& source, const Vector2u& dest, const IntRect& sourceRect = IntRect({0, 0}, {0, 0}), bool applyAlpha = false); //////////////////////////////////////////////////////////// /// \brief Change the color of a pixel @@ -252,14 +249,13 @@ public: /// coordinates, using out-of-range values will result in /// an undefined behavior. /// - /// \param x X coordinate of pixel to change - /// \param y Y coordinate of pixel to change - /// \param color New color of the pixel + /// \param coords Coordinates of pixel to change + /// \param color New color of the pixel /// /// \see getPixel /// //////////////////////////////////////////////////////////// - void setPixel(unsigned int x, unsigned int y, const Color& color); + void setPixel(const Vector2u& coords, const Color& color); //////////////////////////////////////////////////////////// /// \brief Get the color of a pixel @@ -268,15 +264,14 @@ public: /// coordinates, using out-of-range values will result in /// an undefined behavior. /// - /// \param x X coordinate of pixel to get - /// \param y Y coordinate of pixel to get + /// \param coords Coordinates of pixel to change /// - /// \return Color of the pixel at coordinates (x, y) + /// \return Color of the pixel at given coordinates /// /// \see setPixel /// //////////////////////////////////////////////////////////// - Color getPixel(unsigned int x, unsigned int y) const; + Color getPixel(const Vector2u& coords) const; //////////////////////////////////////////////////////////// /// \brief Get a read-only pointer to the array of pixels diff --git a/include/SFML/Graphics/RenderTexture.hpp b/include/SFML/Graphics/RenderTexture.hpp index 2c3b2866..d5e77861 100644 --- a/include/SFML/Graphics/RenderTexture.hpp +++ b/include/SFML/Graphics/RenderTexture.hpp @@ -78,14 +78,13 @@ public: /// requires a depth or stencil buffer. Otherwise it is unnecessary, and /// you should leave this parameter at its default value. /// - /// \param width Width of the render-texture - /// \param height Height of the render-texture + /// \param size Width and height of the render-texture /// \param settings Additional settings for the underlying OpenGL texture and context /// /// \return True if creation has been successful /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool create(unsigned int width, unsigned int height, const ContextSettings& settings = ContextSettings()); + [[nodiscard]] bool create(const Vector2u& size, const ContextSettings& settings = ContextSettings()); //////////////////////////////////////////////////////////// /// \brief Get the maximum anti-aliasing level supported by the system diff --git a/include/SFML/Graphics/Texture.hpp b/include/SFML/Graphics/Texture.hpp index ef50660b..90de43e5 100644 --- a/include/SFML/Graphics/Texture.hpp +++ b/include/SFML/Graphics/Texture.hpp @@ -91,13 +91,12 @@ public: /// /// If this function fails, the texture is left unchanged. /// - /// \param width Width of the texture - /// \param height Height of the texture + /// \param size Width and height of the texture /// /// \return True if creation was successful /// //////////////////////////////////////////////////////////// - [[nodiscard]] bool create(unsigned int width, unsigned int height); + [[nodiscard]] bool create(const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Load the texture from a file on disk @@ -272,13 +271,11 @@ public: /// texture was not previously created. /// /// \param pixels Array of pixels to copy to the texture - /// \param width Width of the pixel region contained in \a pixels - /// \param height Height of the pixel region contained in \a pixels - /// \param x X offset in the texture where to copy the source pixels - /// \param y Y offset in the texture where to copy the source pixels + /// \param size Width and height of the pixel region contained in \a pixels + /// \param dest Coordinates of the destination position /// //////////////////////////////////////////////////////////// - void update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y); + void update(const Uint8* pixels, const Vector2u& size, const Vector2u& dest); //////////////////////////////////////////////////////////// /// \brief Update a part of this texture from another texture @@ -304,18 +301,17 @@ public: /// \brief Update a part of this texture from another texture /// /// No additional check is performed on the size of the texture, - /// passing an invalid combination of texture size and offset + /// passing an invalid combination of texture size and destination /// will lead to an undefined behavior. /// /// This function does nothing if either texture was not /// previously created. /// /// \param texture Source texture to copy to this texture - /// \param x X offset in this texture where to copy the source texture - /// \param y Y offset in this texture where to copy the source texture + /// \param dest Coordinates of the destination position /// //////////////////////////////////////////////////////////// - void update(const Texture& texture, unsigned int x, unsigned int y); + void update(const Texture& texture, const Vector2u& dest); //////////////////////////////////////////////////////////// /// \brief Update the texture from an image @@ -341,18 +337,17 @@ public: /// \brief Update a part of the texture from an image /// /// No additional check is performed on the size of the image, - /// passing an invalid combination of image size and offset + /// passing an invalid combination of image size and destination /// will lead to an undefined behavior. /// /// This function does nothing if the texture was not /// previously created. /// /// \param image Image to copy to the texture - /// \param x X offset in the texture where to copy the source image - /// \param y Y offset in the texture where to copy the source image + /// \param dest Coordinates of the destination position /// //////////////////////////////////////////////////////////// - void update(const Image& image, unsigned int x, unsigned int y); + void update(const Image& image, const Vector2u& dest); //////////////////////////////////////////////////////////// /// \brief Update the texture from the contents of a window @@ -378,18 +373,17 @@ public: /// \brief Update a part of the texture from the contents of a window /// /// No additional check is performed on the size of the window, - /// passing an invalid combination of window size and offset + /// passing an invalid combination of window size and destination /// will lead to an undefined behavior. /// /// This function does nothing if either the texture or the window /// was not previously created. /// /// \param window Window to copy to the texture - /// \param x X offset in the texture where to copy the source window - /// \param y Y offset in the texture where to copy the source window + /// \param dest Coordinates of the destination position /// //////////////////////////////////////////////////////////// - void update(const Window& window, unsigned int x, unsigned int y); + void update(const Window& window, const Vector2u& dest); //////////////////////////////////////////////////////////// /// \brief Enable or disable the smooth filter diff --git a/include/SFML/Graphics/View.hpp b/include/SFML/Graphics/View.hpp index fbcc2ecd..1c35fe58 100644 --- a/include/SFML/Graphics/View.hpp +++ b/include/SFML/Graphics/View.hpp @@ -80,17 +80,6 @@ public: //////////////////////////////////////////////////////////// void setCenter(const Vector2f& center); - //////////////////////////////////////////////////////////// - /// \brief Set the size of the view - /// - /// \param width New width of the view - /// \param height New height of the view - /// - /// \see setCenter, getCenter - /// - //////////////////////////////////////////////////////////// - void setSize(float width, float height); - //////////////////////////////////////////////////////////// /// \brief Set the size of the view /// @@ -182,17 +171,6 @@ public: //////////////////////////////////////////////////////////// const FloatRect& getViewport() const; - //////////////////////////////////////////////////////////// - /// \brief Move the view relatively to its current position - /// - /// \param offsetX X coordinate of the move offset - /// \param offsetY Y coordinate of the move offset - /// - /// \see setCenter, rotate, zoom - /// - //////////////////////////////////////////////////////////// - void move(float offsetX, float offsetY); - //////////////////////////////////////////////////////////// /// \brief Move the view relatively to its current position /// diff --git a/include/SFML/Window/Context.hpp b/include/SFML/Window/Context.hpp index 39eeeeb4..bdc0f931 100644 --- a/include/SFML/Window/Context.hpp +++ b/include/SFML/Window/Context.hpp @@ -30,6 +30,7 @@ //////////////////////////////////////////////////////////// #include #include +#include #include @@ -156,7 +157,7 @@ public: /// \param height Back buffer height /// //////////////////////////////////////////////////////////// - Context(const ContextSettings& settings, unsigned int width, unsigned int height); + Context(const ContextSettings& settings, const Vector2u& size); private: diff --git a/include/SFML/Window/VideoMode.hpp b/include/SFML/Window/VideoMode.hpp index bbab9c1a..a4127fa4 100644 --- a/include/SFML/Window/VideoMode.hpp +++ b/include/SFML/Window/VideoMode.hpp @@ -29,6 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include @@ -53,12 +54,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Construct the video mode with its attributes /// - /// \param modeWidth Width in pixels - /// \param modeHeight Height in pixels + /// \param modeSize Width and height in pixels /// \param modeBitsPerPixel Pixel depths in bits per pixel /// //////////////////////////////////////////////////////////// - VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel = 32); + explicit VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel = 32); //////////////////////////////////////////////////////////// /// \brief Get the current desktop video mode @@ -99,8 +99,7 @@ public: //////////////////////////////////////////////////////////// // Member data //////////////////////////////////////////////////////////// - unsigned int width; //!< Video mode width, in pixels - unsigned int height; //!< Video mode height, in pixels + Vector2u size; //!< Video mode width and height, in pixels unsigned int bitsPerPixel; //!< Video mode pixel depth, in bits per pixels }; diff --git a/include/SFML/Window/WindowBase.hpp b/include/SFML/Window/WindowBase.hpp index 28fd10e0..b03fc064 100644 --- a/include/SFML/Window/WindowBase.hpp +++ b/include/SFML/Window/WindowBase.hpp @@ -273,8 +273,7 @@ public: /// /// The OS default icon is used by default. /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the array of pixels in memory. The /// pixels are copied, so you need not keep the /// source alive after calling this function. @@ -282,7 +281,7 @@ public: /// \see setTitle /// //////////////////////////////////////////////////////////// - void setIcon(unsigned int width, unsigned int height, const Uint8* pixels); + void setIcon(const Vector2u& size, const Uint8* pixels); //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 56857851..5defd921 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -630,7 +630,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f Page& page = loadPage(characterSize); // Find a good position for the new glyph into the texture - glyph.textureRect = findGlyphRect(page, width, height); + glyph.textureRect = findGlyphRect(page, {width, height}); // Make sure the texture data is positioned in the center // of the allocated texture rectangle @@ -695,7 +695,7 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f unsigned int y = static_cast(glyph.textureRect.top) - padding; unsigned int w = static_cast(glyph.textureRect.width) + 2 * padding; unsigned int h = static_cast(glyph.textureRect.height) + 2 * padding; - page.texture.update(m_pixelBuffer.data(), w, h, x, y); + page.texture.update(m_pixelBuffer.data(), {w, h}, {x, y}); } // Delete the FT glyph @@ -707,21 +707,21 @@ Glyph Font::loadGlyph(Uint32 codePoint, unsigned int characterSize, bool bold, f //////////////////////////////////////////////////////////// -IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) const +IntRect Font::findGlyphRect(Page& page, const Vector2u& size) const { // Find the line that fits well the glyph Row* row = nullptr; float bestRatio = 0; for (auto it = page.rows.begin(); it != page.rows.end() && !row; ++it) { - float ratio = static_cast(height) / static_cast(it->height); + float ratio = static_cast(size.y) / static_cast(it->height); // Ignore rows that are either too small or too high if ((ratio < 0.7f) || (ratio > 1.f)) continue; // Check if there's enough horizontal space left in the row - if (width > page.texture.getSize().x - it->width) + if (size.x > page.texture.getSize().x - it->width) continue; // Make sure that this new row is the best found so far @@ -736,17 +736,16 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) // If we didn't find a matching row, create a new one (10% taller than the glyph) if (!row) { - unsigned int rowHeight = height + height / 10; - while ((page.nextRow + rowHeight >= page.texture.getSize().y) || (width >= page.texture.getSize().x)) + unsigned int rowHeight = size.y + size.y / 10; + while ((page.nextRow + rowHeight >= page.texture.getSize().y) || (size.x >= page.texture.getSize().x)) { // Not enough space: resize the texture if possible - unsigned int textureWidth = page.texture.getSize().x; - unsigned int textureHeight = page.texture.getSize().y; - if ((textureWidth * 2 <= Texture::getMaximumSize()) && (textureHeight * 2 <= Texture::getMaximumSize())) + Vector2u textureSize = page.texture.getSize(); + if ((textureSize.x * 2 <= Texture::getMaximumSize()) && (textureSize.y * 2 <= Texture::getMaximumSize())) { // Make the texture 2 times bigger Texture newTexture; - if (!newTexture.create(textureWidth * 2, textureHeight * 2)) + if (!newTexture.create(textureSize * 2u)) { err() << "Failed to create new page texture" << std::endl; return IntRect({0, 0}, {2, 2}); @@ -771,10 +770,10 @@ IntRect Font::findGlyphRect(Page& page, unsigned int width, unsigned int height) } // Find the glyph's rectangle on the selected row - IntRect rect(Rect({row->width, row->top}, {width, height})); + IntRect rect(Rect({row->width, row->top}, size)); // Update the row informations - row->width += width; + row->width += size.x; return rect; } @@ -828,12 +827,12 @@ nextRow(3) { // Make sure that the texture is initialized by default sf::Image image; - image.create(128, 128, Color(255, 255, 255, 0)); + image.create({128, 128}, Color(255, 255, 255, 0)); // Reserve a 2x2 white square for texturing underlines for (unsigned int x = 0; x < 2; ++x) for (unsigned int y = 0; y < 2; ++y) - image.setPixel(x, y, Color(255, 255, 255, 255)); + image.setPixel({x, y}, Color(255, 255, 255, 255)); // Create the texture if (!texture.loadFromImage(image)) diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index d6dfe6b5..53d8f18d 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -70,12 +70,12 @@ Image& Image::operator=(Image&&) noexcept = default; //////////////////////////////////////////////////////////// -void Image::create(unsigned int width, unsigned int height, const Color& color) +void Image::create(const Vector2u& size, const Color& color) { - if (width && height) + if (size.x && size.y) { // Create a new pixel buffer first for exception safety's sake - std::vector newPixels(static_cast(width) * static_cast(height) * 4); + std::vector newPixels(static_cast(size.x) * static_cast(size.y) * 4); // Fill it with the specified color Uint8* ptr = newPixels.data(); @@ -92,8 +92,7 @@ void Image::create(unsigned int width, unsigned int height, const Color& color) m_pixels.swap(newPixels); // Assign the new size - m_size.x = width; - m_size.y = height; + m_size = size; } else { @@ -108,19 +107,18 @@ void Image::create(unsigned int width, unsigned int height, const Color& color) //////////////////////////////////////////////////////////// -void Image::create(unsigned int width, unsigned int height, const Uint8* pixels) +void Image::create(const Vector2u& size, const Uint8* pixels) { - if (pixels && width && height) + if (pixels && size.x && size.y) { // Create a new pixel buffer first for exception safety's sake - std::vector newPixels(pixels, pixels + width * height * 4); + std::vector newPixels(pixels, pixels + size.x * size.y * 4); // Commit the new pixel buffer m_pixels.swap(newPixels); // Assign the new size - m_size.x = width; - m_size.y = height; + m_size = size; } else { @@ -204,7 +202,7 @@ void Image::createMaskFromColor(const Color& color, Uint8 alpha) //////////////////////////////////////////////////////////// -void Image::copy(const Image& source, unsigned int destX, unsigned int destY, const IntRect& sourceRect, bool applyAlpha) +void Image::copy(const Image& source, const Vector2u& dest, const IntRect& sourceRect, bool applyAlpha) { // Make sure that both images are valid if ((source.m_size.x == 0) || (source.m_size.y == 0) || (m_size.x == 0) || (m_size.y == 0)) @@ -230,8 +228,8 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co // Then find the valid bounds of the destination rectangle auto width = static_cast(srcRect.width); auto height = static_cast(srcRect.height); - if (destX + width > m_size.x) width = m_size.x - destX; - if (destY + height > m_size.y) height = m_size.y - destY; + if (dest.x + width > m_size.x) width = m_size.x - dest.x; + if (dest.y + height > m_size.y) height = m_size.y - dest.y; // Make sure the destination area is valid if ((width <= 0) || (height <= 0)) @@ -243,7 +241,7 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co int srcStride = static_cast(source.m_size.x) * 4; int dstStride = static_cast(m_size.x) * 4; const Uint8* srcPixels = source.m_pixels.data() + (static_cast(srcRect.left) + static_cast(srcRect.top) * source.m_size.x) * 4; - Uint8* dstPixels = m_pixels.data() + (destX + destY * m_size.x) * 4; + Uint8* dstPixels = m_pixels.data() + (dest.x + dest.y * m_size.x) * 4; // Copy the pixels if (applyAlpha) @@ -290,9 +288,9 @@ void Image::copy(const Image& source, unsigned int destX, unsigned int destY, co //////////////////////////////////////////////////////////// -void Image::setPixel(unsigned int x, unsigned int y, const Color& color) +void Image::setPixel(const Vector2u& coords, const Color& color) { - Uint8* pixel = &m_pixels[(x + y * m_size.x) * 4]; + Uint8* pixel = &m_pixels[(coords.x + coords.y * m_size.x) * 4]; *pixel++ = color.r; *pixel++ = color.g; *pixel++ = color.b; @@ -301,9 +299,9 @@ void Image::setPixel(unsigned int x, unsigned int y, const Color& color) //////////////////////////////////////////////////////////// -Color Image::getPixel(unsigned int x, unsigned int y) const +Color Image::getPixel(const Vector2u& coords) const { - const Uint8* pixel = &m_pixels[(x + y * m_size.x) * 4]; + const Uint8* pixel = &m_pixels[(coords.x + coords.y * m_size.x) * 4]; return Color(pixel[0], pixel[1], pixel[2], pixel[3]); } diff --git a/src/SFML/Graphics/RenderTexture.cpp b/src/SFML/Graphics/RenderTexture.cpp index c4c7f2dc..b0ddd48e 100644 --- a/src/SFML/Graphics/RenderTexture.cpp +++ b/src/SFML/Graphics/RenderTexture.cpp @@ -44,13 +44,13 @@ RenderTexture::~RenderTexture() = default; //////////////////////////////////////////////////////////// -bool RenderTexture::create(unsigned int width, unsigned int height, const ContextSettings& settings) +bool RenderTexture::create(const Vector2u& size, const ContextSettings& settings) { // Set texture to be in sRGB scale if requested m_texture.setSrgb(settings.sRgbCapable); // Create the texture - if (!m_texture.create(width, height)) + if (!m_texture.create(size)) { err() << "Impossible to create render texture (failed to create the target texture)" << std::endl; return false; @@ -75,7 +75,7 @@ bool RenderTexture::create(unsigned int width, unsigned int height, const Contex } // Initialize the render texture - if (!m_impl->create(width, height, m_texture.m_texture, settings)) + if (!m_impl->create(size, m_texture.m_texture, settings)) return false; // We can now initialize the render target part diff --git a/src/SFML/Graphics/RenderTextureImpl.hpp b/src/SFML/Graphics/RenderTextureImpl.hpp index ce529348..dfdf26c8 100644 --- a/src/SFML/Graphics/RenderTextureImpl.hpp +++ b/src/SFML/Graphics/RenderTextureImpl.hpp @@ -28,6 +28,7 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include namespace sf @@ -72,15 +73,14 @@ public: //////////////////////////////////////////////////////////// /// \brief Create the render texture implementation /// - /// \param width Width of the texture to render to - /// \param height Height of the texture to render to + /// \param size Width and height of the texture to render to /// \param textureId OpenGL identifier of the target texture /// \param settings Context settings to create render-texture with /// /// \return True if creation has been successful /// //////////////////////////////////////////////////////////// - virtual bool create(unsigned int width, unsigned int height, unsigned int textureId, const ContextSettings& settings) = 0; + virtual bool create(const Vector2u& size, unsigned int textureId, const ContextSettings& settings) = 0; //////////////////////////////////////////////////////////// /// \brief Activate or deactivate the render texture for rendering diff --git a/src/SFML/Graphics/RenderTextureImplDefault.cpp b/src/SFML/Graphics/RenderTextureImplDefault.cpp index c63d3c89..ef9b7d22 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.cpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.cpp @@ -40,8 +40,7 @@ namespace priv //////////////////////////////////////////////////////////// RenderTextureImplDefault::RenderTextureImplDefault() : m_context(), -m_width (0), -m_height (0) +m_size (0, 0) { } @@ -62,14 +61,13 @@ unsigned int RenderTextureImplDefault::getMaximumAntialiasingLevel() //////////////////////////////////////////////////////////// -bool RenderTextureImplDefault::create(unsigned int width, unsigned int height, unsigned int, const ContextSettings& settings) +bool RenderTextureImplDefault::create(const Vector2u& size, unsigned int, const ContextSettings& settings) { // Store the dimensions - m_width = width; - m_height = height; + m_size = size; // Create the in-memory OpenGL context - m_context = std::make_unique(settings, width, height); + m_context = std::make_unique(settings, size); return true; } @@ -97,7 +95,7 @@ void RenderTextureImplDefault::updateTexture(unsigned int textureId) // Copy the rendered pixels to the texture glCheck(glBindTexture(GL_TEXTURE_2D, textureId)); - glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, static_cast(m_width), static_cast(m_height))); + glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, 0, 0, 0, 0, static_cast(m_size.x), static_cast(m_size.y))); } } // namespace priv diff --git a/src/SFML/Graphics/RenderTextureImplDefault.hpp b/src/SFML/Graphics/RenderTextureImplDefault.hpp index 6c7d6acb..40cca9df 100644 --- a/src/SFML/Graphics/RenderTextureImplDefault.hpp +++ b/src/SFML/Graphics/RenderTextureImplDefault.hpp @@ -74,15 +74,14 @@ private: //////////////////////////////////////////////////////////// /// \brief Create the render texture implementation /// - /// \param width Width of the texture to render to - /// \param height Height of the texture to render to + /// \param size Width and height of the texture to render to /// \param textureId OpenGL identifier of the target texture /// \param settings Context settings to create render-texture with /// /// \return True if creation has been successful /// //////////////////////////////////////////////////////////// - bool create(unsigned int width, unsigned int height, unsigned int textureId, const ContextSettings& settings) override; + bool create(const Vector2u& size, unsigned int textureId, const ContextSettings& settings) override; //////////////////////////////////////////////////////////// /// \brief Activate or deactivate the render texture for rendering @@ -117,8 +116,7 @@ private: // Member data //////////////////////////////////////////////////////////// std::unique_ptr m_context; //!< P-Buffer based context - unsigned int m_width; //!< Width of the P-Buffer - unsigned int m_height; //!< Height of the P-Buffer + Vector2u m_size; //!< Width and height of the P-Buffer }; } // namespace priv diff --git a/src/SFML/Graphics/RenderTextureImplFBO.cpp b/src/SFML/Graphics/RenderTextureImplFBO.cpp index 419b64f4..0d24c02c 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.cpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.cpp @@ -119,8 +119,7 @@ namespace priv RenderTextureImplFBO::RenderTextureImplFBO() : m_depthStencilBuffer(0), m_colorBuffer (0), -m_width (0), -m_height (0), +m_size (0, 0), m_context (), m_textureId (0), m_multisample (false), @@ -212,11 +211,10 @@ void RenderTextureImplFBO::unbind() //////////////////////////////////////////////////////////// -bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsigned int textureId, const ContextSettings& settings) +bool RenderTextureImplFBO::create(const Vector2u& size, unsigned int textureId, const ContextSettings& settings) { // Store the dimensions - m_width = width; - m_height = height; + m_size = size; { TransientContextLock lock; @@ -268,7 +266,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig return false; } glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer)); - glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH24_STENCIL8, static_cast(width), static_cast(height))); + glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH24_STENCIL8, static_cast(size.x), static_cast(size.y))); #else @@ -291,7 +289,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig return false; } glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer)); - glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH_COMPONENT, static_cast(width), static_cast(height))); + glCheck(GLEXT_glRenderbufferStorage(GLEXT_GL_RENDERBUFFER, GLEXT_GL_DEPTH_COMPONENT, static_cast(size.x), static_cast(size.y))); } } else @@ -309,7 +307,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig return false; } glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_colorBuffer)); - glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast(settings.antialiasingLevel), m_sRgb ? GL_SRGB8_ALPHA8_EXT : GL_RGBA, static_cast(width), static_cast(height))); + glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast(settings.antialiasingLevel), m_sRgb ? GL_SRGB8_ALPHA8_EXT : GL_RGBA, static_cast(size.x), static_cast(size.y))); // Create the multisample depth/stencil buffer if requested if (settings.stencilBits) @@ -323,7 +321,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig return false; } glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer)); - glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast(settings.antialiasingLevel), GLEXT_GL_DEPTH24_STENCIL8, static_cast(width), static_cast(height))); + glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast(settings.antialiasingLevel), GLEXT_GL_DEPTH24_STENCIL8, static_cast(size.x), static_cast(size.y))); m_stencil = true; } @@ -338,7 +336,7 @@ bool RenderTextureImplFBO::create(unsigned int width, unsigned int height, unsig return false; } glCheck(GLEXT_glBindRenderbuffer(GLEXT_GL_RENDERBUFFER, m_depthStencilBuffer)); - glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast(settings.antialiasingLevel), GLEXT_GL_DEPTH_COMPONENT, static_cast(width), static_cast(height))); + glCheck(GLEXT_glRenderbufferStorageMultisample(GLEXT_GL_RENDERBUFFER, static_cast(settings.antialiasingLevel), GLEXT_GL_DEPTH_COMPONENT, static_cast(size.x), static_cast(size.y))); } #else @@ -592,7 +590,7 @@ void RenderTextureImplFBO::updateTexture(unsigned int) // In case of multisampling, make sure both FBOs // are already available within the current context - if (m_multisample && m_width && m_height && activate(true)) + if (m_multisample && m_size.x && m_size.y && activate(true)) { Uint64 contextId = Context::getActiveContextId(); @@ -605,7 +603,7 @@ void RenderTextureImplFBO::updateTexture(unsigned int) { // Set up the blit target (draw framebuffer) and blit (from the read framebuffer, our multisample FBO) glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, frameBufferIt->second)); - glCheck(GLEXT_glBlitFramebuffer(0, 0, static_cast(m_width), static_cast(m_height), 0, 0, static_cast(m_width), static_cast(m_height), GL_COLOR_BUFFER_BIT, GL_NEAREST)); + glCheck(GLEXT_glBlitFramebuffer(0, 0, static_cast(m_size.x), static_cast(m_size.y), 0, 0, static_cast(m_size.x), static_cast(m_size.y), GL_COLOR_BUFFER_BIT, GL_NEAREST)); glCheck(GLEXT_glBindFramebuffer(GLEXT_GL_DRAW_FRAMEBUFFER, multisampleIt->second)); } } diff --git a/src/SFML/Graphics/RenderTextureImplFBO.hpp b/src/SFML/Graphics/RenderTextureImplFBO.hpp index 778e6efd..c376716b 100644 --- a/src/SFML/Graphics/RenderTextureImplFBO.hpp +++ b/src/SFML/Graphics/RenderTextureImplFBO.hpp @@ -89,15 +89,14 @@ private: //////////////////////////////////////////////////////////// /// \brief Create the render texture implementation /// - /// \param width Width of the texture to render to - /// \param height Height of the texture to render to + /// \param size Width and height of the texture to render to /// \param textureId OpenGL identifier of the target texture /// \param settings Context settings to create render-texture with /// /// \return True if creation has been successful /// //////////////////////////////////////////////////////////// - bool create(unsigned int width, unsigned int height, unsigned int textureId, const ContextSettings& settings) override; + bool create(const Vector2u& size, unsigned int textureId, const ContextSettings& settings) override; //////////////////////////////////////////////////////////// /// \brief Create an FBO in the current context @@ -143,8 +142,7 @@ private: std::unordered_map m_multisampleFrameBuffers; //!< Optional per-context OpenGL frame buffer objects with multisample attachments unsigned int m_depthStencilBuffer; //!< Optional depth/stencil buffer attached to the frame buffer unsigned int m_colorBuffer; //!< Optional multisample color buffer attached to the frame buffer - unsigned int m_width; //!< Width of the attachments - unsigned int m_height; //!< Height of the attachments + Vector2u m_size; //!< Width and height of the attachments std::unique_ptr m_context; //!< Backup OpenGL context, used when none already exist unsigned int m_textureId; //!< The ID of the texture to attach to the FBO bool m_multisample; //!< Whether we have to create a multisample frame buffer as well diff --git a/src/SFML/Graphics/Texture.cpp b/src/SFML/Graphics/Texture.cpp index 7b65cc37..699062ab 100644 --- a/src/SFML/Graphics/Texture.cpp +++ b/src/SFML/Graphics/Texture.cpp @@ -94,7 +94,7 @@ m_cacheId (TextureImpl::getUniqueId()) { if (copy.m_texture) { - if (create(copy.getSize().x, copy.getSize().y)) + if (create(copy.getSize())) { update(copy); } @@ -121,12 +121,12 @@ Texture::~Texture() //////////////////////////////////////////////////////////// -bool Texture::create(unsigned int width, unsigned int height) +bool Texture::create(const Vector2u& size) { // Check if texture parameters are valid before creating it - if ((width == 0) || (height == 0)) + if ((size.x == 0) || (size.y == 0)) { - err() << "Failed to create texture, invalid size (" << width << "x" << height << ")" << std::endl; + err() << "Failed to create texture, invalid size (" << size.x << "x" << size.y << ")" << std::endl; return false; } @@ -136,7 +136,7 @@ bool Texture::create(unsigned int width, unsigned int height) priv::ensureExtensionsInit(); // Compute the internal texture dimensions depending on NPOT textures support - Vector2u actualSize(getValidSize(width), getValidSize(height)); + Vector2u actualSize(getValidSize(size.x), getValidSize(size.y)); // Check the maximum texture size unsigned int maxSize = getMaximumSize(); @@ -150,8 +150,7 @@ bool Texture::create(unsigned int width, unsigned int height) } // All the validity checks passed, we can store the new texture settings - m_size.x = width; - m_size.y = height; + m_size = size; m_actualSize = actualSize; m_pixelsFlipped = false; m_fboAttachment = false; @@ -255,7 +254,7 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) ((area.left <= 0) && (area.top <= 0) && (area.width >= width) && (area.height >= height))) { // Load the entire image - if (create(image.getSize().x, image.getSize().y)) + if (create(image.getSize())) { update(image); @@ -278,7 +277,7 @@ bool Texture::loadFromImage(const Image& image, const IntRect& area) if (rectangle.top + rectangle.height > height) rectangle.height = height - rectangle.top; // Create the texture and upload the pixels - if (create(static_cast(rectangle.width), static_cast(rectangle.height))) + if (create(Vector2u(rectangle.getSize()))) { TransientContextLock lock; @@ -394,7 +393,7 @@ Image Texture::copyToImage() const // Create the image Image image; - image.create(m_size.x, m_size.y, pixels.data()); + image.create(m_size, pixels.data()); return image; } @@ -404,15 +403,15 @@ Image Texture::copyToImage() const void Texture::update(const Uint8* pixels) { // Update the whole texture - update(pixels, m_size.x, m_size.y, 0, 0); + update(pixels, m_size, {0, 0}); } //////////////////////////////////////////////////////////// -void Texture::update(const Uint8* pixels, unsigned int width, unsigned int height, unsigned int x, unsigned int y) +void Texture::update(const Uint8* pixels, const Vector2u& size, const Vector2u& dest) { - assert(x + width <= m_size.x); - assert(y + height <= m_size.y); + assert(dest.x + size.x <= m_size.x); + assert(dest.y + size.y <= m_size.y); if (pixels && m_texture) { @@ -423,7 +422,7 @@ void Texture::update(const Uint8* pixels, unsigned int width, unsigned int heigh // Copy pixels from the given array to the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast(x), static_cast(y), static_cast(width), static_cast(height), GL_RGBA, GL_UNSIGNED_BYTE, pixels)); + glCheck(glTexSubImage2D(GL_TEXTURE_2D, 0, static_cast(dest.x), static_cast(dest.y), static_cast(size.x), static_cast(size.y), GL_RGBA, GL_UNSIGNED_BYTE, pixels)); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); m_hasMipmap = false; m_pixelsFlipped = false; @@ -440,15 +439,15 @@ void Texture::update(const Uint8* pixels, unsigned int width, unsigned int heigh void Texture::update(const Texture& texture) { // Update the whole texture - update(texture, 0, 0); + update(texture, {0, 0}); } //////////////////////////////////////////////////////////// -void Texture::update(const Texture& texture, unsigned int x, unsigned int y) +void Texture::update(const Texture& texture, const Vector2u& dest) { - assert(x + texture.m_size.x <= m_size.x); - assert(y + texture.m_size.y <= m_size.y); + assert(dest.x + texture.m_size.x <= m_size.x); + assert(dest.y + texture.m_size.y <= m_size.y); if (!m_texture || !texture.m_texture) return; @@ -505,7 +504,7 @@ void Texture::update(const Texture& texture, unsigned int x, unsigned int y) // Blit the texture contents from the source to the destination texture glCheck(GLEXT_glBlitFramebuffer( 0, texture.m_pixelsFlipped ? static_cast(texture.m_size.y) : 0, static_cast(texture.m_size.x), texture.m_pixelsFlipped ? 0 : static_cast(texture.m_size.y), // Source rectangle, flip y if source is flipped - static_cast(x), static_cast(y), static_cast(x + texture.m_size.x), static_cast(y + texture.m_size.y), // Destination rectangle + static_cast(dest.x), static_cast(dest.y), static_cast(dest.x + texture.m_size.x), static_cast(dest.y + texture.m_size.y), // Destination rectangle GL_COLOR_BUFFER_BIT, GL_NEAREST )); } @@ -541,7 +540,7 @@ void Texture::update(const Texture& texture, unsigned int x, unsigned int y) #endif // SFML_OPENGL_ES - update(texture.copyToImage(), x, y); + update(texture.copyToImage(), dest); } @@ -549,29 +548,29 @@ void Texture::update(const Texture& texture, unsigned int x, unsigned int y) void Texture::update(const Image& image) { // Update the whole texture - update(image.getPixelsPtr(), image.getSize().x, image.getSize().y, 0, 0); + update(image.getPixelsPtr(), image.getSize(), {0, 0}); } //////////////////////////////////////////////////////////// -void Texture::update(const Image& image, unsigned int x, unsigned int y) +void Texture::update(const Image& image, const Vector2u& dest) { - update(image.getPixelsPtr(), image.getSize().x, image.getSize().y, x, y); + update(image.getPixelsPtr(), image.getSize(), dest); } //////////////////////////////////////////////////////////// void Texture::update(const Window& window) { - update(window, 0, 0); + update(window, {0, 0}); } //////////////////////////////////////////////////////////// -void Texture::update(const Window& window, unsigned int x, unsigned int y) +void Texture::update(const Window& window, const Vector2u& dest) { - assert(x + window.getSize().x <= m_size.x); - assert(y + window.getSize().y <= m_size.y); + assert(dest.x + window.getSize().x <= m_size.x); + assert(dest.y + window.getSize().y <= m_size.y); if (m_texture && window.setActive(true)) { @@ -582,7 +581,7 @@ void Texture::update(const Window& window, unsigned int x, unsigned int y) // Copy pixels from the back-buffer to the texture glCheck(glBindTexture(GL_TEXTURE_2D, m_texture)); - glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, static_cast(x), static_cast(y), 0, 0, static_cast(window.getSize().x), static_cast(window.getSize().y))); + glCheck(glCopyTexSubImage2D(GL_TEXTURE_2D, 0, static_cast(dest.x), static_cast(dest.y), 0, 0, static_cast(window.getSize().x), static_cast(window.getSize().y))); glCheck(glTexParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, m_isSmooth ? GL_LINEAR : GL_NEAREST)); m_hasMipmap = false; m_pixelsFlipped = true; diff --git a/src/SFML/Graphics/View.cpp b/src/SFML/Graphics/View.cpp index e3e254ec..438e0c2b 100644 --- a/src/SFML/Graphics/View.cpp +++ b/src/SFML/Graphics/View.cpp @@ -78,22 +78,13 @@ void View::setCenter(const Vector2f& center) m_invTransformUpdated = false; } - -//////////////////////////////////////////////////////////// -void View::setSize(float width, float height) -{ - m_size.x = width; - m_size.y = height; - - m_transformUpdated = false; - m_invTransformUpdated = false; -} - - //////////////////////////////////////////////////////////// void View::setSize(const Vector2f& size) { - setSize(size.x, size.y); + m_size = size; + + m_transformUpdated = false; + m_invTransformUpdated = false; } @@ -173,7 +164,7 @@ void View::rotate(Angle angle) //////////////////////////////////////////////////////////// void View::zoom(float factor) { - setSize(m_size.x * factor, m_size.y * factor); + setSize(m_size * factor); } diff --git a/src/SFML/Window/Android/VideoModeImpl.cpp b/src/SFML/Window/Android/VideoModeImpl.cpp index 7bd3bfbd..046e3ca0 100644 --- a/src/SFML/Window/Android/VideoModeImpl.cpp +++ b/src/SFML/Window/Android/VideoModeImpl.cpp @@ -43,7 +43,7 @@ std::vector VideoModeImpl::getFullscreenModes() // Return both portrait and landscape resolutions std::vector modes; modes.push_back(desktop); - modes.emplace_back(desktop.height, desktop.width, desktop.bitsPerPixel); + modes.emplace_back(Vector2u(desktop.size.y, desktop.size.x), desktop.bitsPerPixel); return modes; } @@ -55,7 +55,7 @@ VideoMode VideoModeImpl::getDesktopMode() priv::ActivityStates& states = priv::getActivity(); std::scoped_lock lock(states.mutex); - return VideoMode(static_cast(states.screenSize.x), static_cast(states.screenSize.y)); + return VideoMode(Vector2u(states.screenSize)); } } // namespace priv diff --git a/src/SFML/Window/Android/WindowImplAndroid.cpp b/src/SFML/Window/Android/WindowImplAndroid.cpp index 64654919..2715646f 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.cpp +++ b/src/SFML/Window/Android/WindowImplAndroid.cpp @@ -61,7 +61,7 @@ WindowImplAndroid::WindowImplAndroid(WindowHandle /* handle */) //////////////////////////////////////////////////////////// WindowImplAndroid::WindowImplAndroid(VideoMode mode, const String& /* title */, unsigned long style, const ContextSettings& /* settings */) -: m_size(mode.width, mode.height) +: m_size(mode.size) , m_windowBeingCreated(false) , m_windowBeingDestroyed(false) , m_hasFocus(false) @@ -160,7 +160,7 @@ void WindowImplAndroid::setTitle(const String& /* title */) //////////////////////////////////////////////////////////// -void WindowImplAndroid::setIcon(unsigned int /* width */, unsigned int /* height */, const Uint8* /* pixels */) +void WindowImplAndroid::setIcon(const Vector2u& /* size */, const Uint8* /* pixels */) { // Not applicable } diff --git a/src/SFML/Window/Android/WindowImplAndroid.hpp b/src/SFML/Window/Android/WindowImplAndroid.hpp index 95a3bc48..dee5fc44 100644 --- a/src/SFML/Window/Android/WindowImplAndroid.hpp +++ b/src/SFML/Window/Android/WindowImplAndroid.hpp @@ -123,12 +123,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the window's icon /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; + void setIcon(const Vector2u& size, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Window/Context.cpp b/src/SFML/Window/Context.cpp index ffdfce50..75f0f7fb 100644 --- a/src/SFML/Window/Context.cpp +++ b/src/SFML/Window/Context.cpp @@ -118,8 +118,8 @@ GlFunctionPointer Context::getFunction(const char* name) //////////////////////////////////////////////////////////// -Context::Context(const ContextSettings& settings, unsigned int width, unsigned int height) -: m_context(priv::GlContext::create(settings, width, height)) +Context::Context(const ContextSettings& settings, const Vector2u& size) +: m_context(priv::GlContext::create(settings, size)) { if (!setActive(true)) { diff --git a/src/SFML/Window/DRM/DRMContext.cpp b/src/SFML/Window/DRM/DRMContext.cpp index 60fe0b01..9760e84f 100644 --- a/src/SFML/Window/DRM/DRMContext.cpp +++ b/src/SFML/Window/DRM/DRMContext.cpp @@ -204,8 +204,7 @@ m_config (nullptr), m_currentBO (nullptr), m_nextBO (nullptr), m_gbmSurface (nullptr), -m_width (0), -m_height (0), +m_size (0, 0), m_shown (false), m_scanOut (false) { @@ -222,9 +221,9 @@ m_scanOut (false) createContext(shared); if (shared) - createSurface(shared->m_width, shared->m_height, VideoMode::getDesktopMode().bitsPerPixel, false); + createSurface(shared->m_size, VideoMode::getDesktopMode().bitsPerPixel, false); else // create a surface to force the GL to initialize (seems to be required for glGetString() etc ) - createSurface(1, 1, VideoMode::getDesktopMode().bitsPerPixel, false); + createSurface({1, 1}, VideoMode::getDesktopMode().bitsPerPixel, false); } @@ -237,8 +236,7 @@ m_config (nullptr), m_currentBO (nullptr), m_nextBO (nullptr), m_gbmSurface (nullptr), -m_width (0), -m_height (0), +m_size (0, 0), m_shown (false), m_scanOut (false) { @@ -255,12 +253,12 @@ m_scanOut (false) createContext(shared); Vector2u size = owner.getSize(); - createSurface(size.x, size.y, bitsPerPixel, true); + createSurface(size, bitsPerPixel, true); } //////////////////////////////////////////////////////////// -DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height) : +DRMContext::DRMContext(DRMContext* shared, const ContextSettings& settings, const Vector2u& size) : m_display (EGL_NO_DISPLAY), m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE), @@ -268,8 +266,7 @@ m_config (nullptr), m_currentBO (nullptr), m_nextBO (nullptr), m_gbmSurface (nullptr), -m_width (0), -m_height (0), +m_size (0, 0), m_shown (false), m_scanOut (false) { @@ -284,7 +281,7 @@ m_scanOut (false) // Create EGL context createContext(shared); - createSurface(width, height, VideoMode::getDesktopMode().bitsPerPixel, false); + createSurface(size, VideoMode::getDesktopMode().bitsPerPixel, false); } @@ -431,7 +428,7 @@ void DRMContext::createContext(DRMContext* shared) //////////////////////////////////////////////////////////// -void DRMContext::createSurface(unsigned int width, unsigned int height, unsigned int /*bpp*/, bool scanout) +void DRMContext::createSurface(const Vector2u& size, unsigned int /*bpp*/, bool scanout) { sf::Uint32 flags = GBM_BO_USE_RENDERING; @@ -441,8 +438,8 @@ void DRMContext::createSurface(unsigned int width, unsigned int height, unsigned m_gbmSurface = gbm_surface_create( gbmDevice, - width, - height, + size.x, + size.y, GBM_FORMAT_ARGB8888, flags); @@ -452,8 +449,7 @@ void DRMContext::createSurface(unsigned int width, unsigned int height, unsigned return; } - m_width = width; - m_height = height; + m_size = size; m_surface = eglCheck(eglCreateWindowSurface(m_display, m_config, reinterpret_cast(m_gbmSurface), nullptr)); diff --git a/src/SFML/Window/DRM/DRMContext.hpp b/src/SFML/Window/DRM/DRMContext.hpp index 2785de65..a7472ae9 100644 --- a/src/SFML/Window/DRM/DRMContext.hpp +++ b/src/SFML/Window/DRM/DRMContext.hpp @@ -76,11 +76,10 @@ public: /// /// \param shared Context to share the new one with /// \param settings Creation parameters - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// //////////////////////////////////////////////////////////// - DRMContext(DRMContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height); + DRMContext(DRMContext* shared, const ContextSettings& settings, const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Destructor @@ -131,13 +130,12 @@ public: //////////////////////////////////////////////////////////// /// \brief Create the EGL surface /// - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// \param bpp Pixel depth, in bits per pixel /// \param scanout True to present the surface to the screen /// //////////////////////////////////////////////////////////// - void createSurface(unsigned int width, unsigned int height, unsigned int bpp, bool scanout); + void createSurface(const Vector2u& size, unsigned int bpp, bool scanout); //////////////////////////////////////////////////////////// /// \brief Destroy the EGL surface @@ -200,8 +198,7 @@ private: gbm_bo* m_currentBO; gbm_bo* m_nextBO; gbm_surface* m_gbmSurface; - unsigned int m_width; - unsigned int m_height; + Vector2u m_size; bool m_shown; bool m_scanOut; }; diff --git a/src/SFML/Window/DRM/VideoModeImpl.cpp b/src/SFML/Window/DRM/VideoModeImpl.cpp index 13471a47..66356b4c 100644 --- a/src/SFML/Window/DRM/VideoModeImpl.cpp +++ b/src/SFML/Window/DRM/VideoModeImpl.cpp @@ -47,8 +47,7 @@ std::vector VideoModeImpl::getFullscreenModes() { for (int i = 0; i < conn->count_modes; i++) modes.push_back( - VideoMode(conn->modes[i].hdisplay, - conn->modes[i].vdisplay)); + VideoMode({conn->modes[i].hdisplay, conn->modes[i].vdisplay})); } else modes.push_back(getDesktopMode()); @@ -63,9 +62,9 @@ VideoMode VideoModeImpl::getDesktopMode() drm* drm = sf::priv::DRMContext::getDRM(); drmModeModeInfoPtr ptr = drm->mode; if (ptr) - return VideoMode(ptr->hdisplay, ptr->vdisplay); + return VideoMode({ptr->hdisplay, ptr->vdisplay}); else - return VideoMode(0, 0); + return VideoMode({0, 0}); } } // namespace priv diff --git a/src/SFML/Window/DRM/WindowImplDRM.cpp b/src/SFML/Window/DRM/WindowImplDRM.cpp index 761245c0..805be5a9 100644 --- a/src/SFML/Window/DRM/WindowImplDRM.cpp +++ b/src/SFML/Window/DRM/WindowImplDRM.cpp @@ -48,7 +48,7 @@ m_size(0, 0) //////////////////////////////////////////////////////////// WindowImplDRM::WindowImplDRM(VideoMode mode, const String& /*title*/, unsigned long /*style*/, const ContextSettings& /*settings*/) : -m_size(mode.width, mode.height) +m_size(mode.size) { sf::priv::InputImpl::setTerminalConfig(); } @@ -101,7 +101,7 @@ void WindowImplDRM::setTitle(const String& /*title*/) //////////////////////////////////////////////////////////// -void WindowImplDRM::setIcon(unsigned int /*width*/, unsigned int /*height*/, const Uint8* /*pixels*/) +void WindowImplDRM::setIcon(const Vector2u& /*size*/, const Uint8* /*pixels*/) { } diff --git a/src/SFML/Window/DRM/WindowImplDRM.hpp b/src/SFML/Window/DRM/WindowImplDRM.hpp index f3f75697..2ce27731 100644 --- a/src/SFML/Window/DRM/WindowImplDRM.hpp +++ b/src/SFML/Window/DRM/WindowImplDRM.hpp @@ -119,12 +119,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the window's icon /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; + virtual void setIcon(const Vector2u& size, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Window/EglContext.cpp b/src/SFML/Window/EglContext.cpp index 98eb1049..6f69b237 100644 --- a/src/SFML/Window/EglContext.cpp +++ b/src/SFML/Window/EglContext.cpp @@ -171,7 +171,7 @@ m_config (nullptr) //////////////////////////////////////////////////////////// -EglContext::EglContext(EglContext* /*shared*/, const ContextSettings& /*settings*/, unsigned int /*width*/, unsigned int /*height*/) : +EglContext::EglContext(EglContext* /*shared*/, const ContextSettings& /*settings*/, const Vector2u& /*size*/) : m_display (EGL_NO_DISPLAY), m_context (EGL_NO_CONTEXT), m_surface (EGL_NO_SURFACE), @@ -179,7 +179,7 @@ m_config (nullptr) { EglContextImpl::ensureInit(); - sf::err() << "Warning: context has not been initialized. The constructor EglContext(shared, settings, width, height) is currently not implemented." << std::endl; + sf::err() << "Warning: context has not been initialized. The constructor EglContext(shared, settings, size) is currently not implemented." << std::endl; } diff --git a/src/SFML/Window/EglContext.hpp b/src/SFML/Window/EglContext.hpp index eae711c5..f3abc6f4 100644 --- a/src/SFML/Window/EglContext.hpp +++ b/src/SFML/Window/EglContext.hpp @@ -71,11 +71,10 @@ public: /// /// \param shared Context to share the new one with /// \param settings Creation parameters - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// //////////////////////////////////////////////////////////// - EglContext(EglContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height); + EglContext(EglContext* shared, const ContextSettings& settings, const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/Window/GlContext.cpp b/src/SFML/Window/GlContext.cpp index 605dc727..27d13662 100644 --- a/src/SFML/Window/GlContext.cpp +++ b/src/SFML/Window/GlContext.cpp @@ -501,7 +501,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co // Re-create our shared context as a core context ContextSettings sharedSettings(0, 0, 0, settings.majorVersion, settings.minorVersion, settings.attributeFlags); - sharedContext = std::make_unique(nullptr, sharedSettings, 1, 1); + sharedContext = std::make_unique(nullptr, sharedSettings, Vector2u(1, 1)); sharedContext->initialize(sharedSettings); // Reload our extensions vector @@ -530,7 +530,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, co //////////////////////////////////////////////////////////// -std::unique_ptr GlContext::create(const ContextSettings& settings, unsigned int width, unsigned int height) +std::unique_ptr GlContext::create(const ContextSettings& settings, const Vector2u& size) { using GlContextImpl::mutex; using GlContextImpl::resourceCount; @@ -553,7 +553,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, un // Re-create our shared context as a core context ContextSettings sharedSettings(0, 0, 0, settings.majorVersion, settings.minorVersion, settings.attributeFlags); - sharedContext = std::make_unique(nullptr, sharedSettings, 1, 1); + sharedContext = std::make_unique(nullptr, sharedSettings, Vector2u(1, 1)); sharedContext->initialize(sharedSettings); // Reload our extensions vector @@ -569,7 +569,7 @@ std::unique_ptr GlContext::create(const ContextSettings& settings, un sharedContext->setActive(true); // Create the context - context = std::make_unique(sharedContext.get(), settings, width, height); + context = std::make_unique(sharedContext.get(), settings, size); sharedContext->setActive(false); } diff --git a/src/SFML/Window/GlContext.hpp b/src/SFML/Window/GlContext.hpp index 3d1feec8..976e19aa 100644 --- a/src/SFML/Window/GlContext.hpp +++ b/src/SFML/Window/GlContext.hpp @@ -128,13 +128,12 @@ public: /// to use according to the OS. /// /// \param settings Creation parameters - /// \param width Back buffer width - /// \param height Back buffer height + /// \param size Back buffer width and height /// /// \return Pointer to the created context /// //////////////////////////////////////////////////////////// - static std::unique_ptr create(const ContextSettings& settings, unsigned int width, unsigned int height); + static std::unique_ptr create(const ContextSettings& settings, const Vector2u& size); public: //////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/OSX/InputImpl.mm b/src/SFML/Window/OSX/InputImpl.mm index c661080b..07148ee0 100644 --- a/src/SFML/Window/OSX/InputImpl.mm +++ b/src/SFML/Window/OSX/InputImpl.mm @@ -155,7 +155,7 @@ Vector2i InputImpl::getMousePosition() AutoreleasePool pool; // Reverse Y axis to match SFML coord. NSPoint pos = [NSEvent mouseLocation]; - pos.y = sf::VideoMode::getDesktopMode().height - pos.y; + pos.y = sf::VideoMode::getDesktopMode().size.y - pos.y; int scale = static_cast([[NSScreen mainScreen] backingScaleFactor]); return Vector2i(static_cast(pos.x), static_cast(pos.y)) * scale; diff --git a/src/SFML/Window/OSX/SFContext.hpp b/src/SFML/Window/OSX/SFContext.hpp index 9e264cb5..6e70a41e 100644 --- a/src/SFML/Window/OSX/SFContext.hpp +++ b/src/SFML/Window/OSX/SFContext.hpp @@ -90,12 +90,11 @@ public: /// /// \param shared Context to share the new one with /// \param settings Creation parameters - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// //////////////////////////////////////////////////////////// SFContext(SFContext* shared, const ContextSettings& settings, - unsigned int width, unsigned int height); + const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/Window/OSX/SFContext.mm b/src/SFML/Window/OSX/SFContext.mm index fce9d66b..6a5d7c91 100644 --- a/src/SFML/Window/OSX/SFContext.mm +++ b/src/SFML/Window/OSX/SFContext.mm @@ -81,7 +81,7 @@ m_window(0) //////////////////////////////////////////////////////////// SFContext::SFContext(SFContext* shared, const ContextSettings& settings, - unsigned int width, unsigned int height) : + const Vector2u& size) : m_context(0), m_view(0), m_window(0) @@ -94,11 +94,11 @@ m_window(0) createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, settings); // Create a dummy window/view pair (hidden) and assign it our context. - m_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, width, height) + m_window = [[NSWindow alloc] initWithContentRect:NSMakeRect(0, 0, size.x, size.y) styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered defer:NO]; // Don't defer it! - m_view = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, width, height)]; + m_view = [[NSOpenGLView alloc] initWithFrame:NSMakeRect(0, 0, size.x, size.y)]; [m_window setContentView:m_view]; [m_view setOpenGLContext:m_context]; [m_context setView:m_view]; diff --git a/src/SFML/Window/OSX/SFOpenGLView.mm b/src/SFML/Window/OSX/SFOpenGLView.mm index 474b57a0..5711c96b 100644 --- a/src/SFML/Window/OSX/SFOpenGLView.mm +++ b/src/SFML/Window/OSX/SFOpenGLView.mm @@ -247,7 +247,7 @@ // Send a resize event if the scaling factor changed if ((m_scaleFactor != oldScaleFactor) && (m_requester != 0)) { NSSize newSize = [self frame].size; - m_requester->windowResized(static_cast(newSize.width), static_cast(newSize.height)); + m_requester->windowResized({static_cast(newSize.width), static_cast(newSize.height)}); } } @@ -279,7 +279,7 @@ // The new size NSSize newSize = [self frame].size; - m_requester->windowResized(static_cast(newSize.width), static_cast(newSize.height)); + m_requester->windowResized({static_cast(newSize.width), static_cast(newSize.height)}); } //////////////////////////////////////////////////////// diff --git a/src/SFML/Window/OSX/SFWindowController.mm b/src/SFML/Window/OSX/SFWindowController.mm index d4e5adeb..e605874f 100644 --- a/src/SFML/Window/OSX/SFWindowController.mm +++ b/src/SFML/Window/OSX/SFWindowController.mm @@ -183,7 +183,7 @@ // Create a screen-sized window on the main display sf::VideoMode desktop = sf::VideoMode::getDesktopMode(); sf::priv::scaleInWidthHeight(desktop, nil); - NSRect windowRect = NSMakeRect(0, 0, desktop.width, desktop.height); + NSRect windowRect = NSMakeRect(0, 0, desktop.size.x, desktop.size.y); m_window = [[SFWindow alloc] initWithContentRect:windowRect styleMask:NSBorderlessWindowMask backing:NSBackingStoreBuffered @@ -223,10 +223,10 @@ } // Create our OpenGL view size and the view - CGFloat width = std::min(mode.width, desktop.width); - CGFloat height = std::min(mode.height, desktop.height); - CGFloat x = (desktop.width - width) / 2.0; - CGFloat y = (desktop.height - height) / 2.0; + CGFloat width = std::min(mode.size.x, desktop.size.x); + CGFloat height = std::min(mode.size.y, desktop.size.y); + CGFloat x = (desktop.size.x - width) / 2.0; + CGFloat y = (desktop.size.y - height) / 2.0; NSRect oglRect = NSMakeRect(x, y, width, height); m_oglView = [[SFOpenGLView alloc] initWithFrame:oglRect @@ -253,7 +253,7 @@ // We know that style & sf::Style::Fullscreen is false. // Create our window size. - NSRect rect = NSMakeRect(0, 0, mode.width, mode.height); + NSRect rect = NSMakeRect(0, 0, mode.size.x, mode.size.y); // Convert the SFML window style to Cocoa window style. unsigned int nsStyle = NSBorderlessWindowMask; @@ -451,11 +451,11 @@ sf::VideoMode desktop = sf::VideoMode::getDesktopMode(); sf::priv::scaleInWidthHeight(desktop, nil); - width = std::min(width, desktop.width); - height = std::min(height, desktop.height); + width = std::min(width, desktop.size.x); + height = std::min(height, desktop.size.y); - CGFloat x = (desktop.width - width) / 2.0; - CGFloat y = (desktop.height - height) / 2.0; + CGFloat x = (desktop.size.x - width) / 2.0; + CGFloat y = (desktop.size.y - height) / 2.0; NSRect oglRect = NSMakeRect(x, y, width, height); [m_oglView setFrame:oglRect]; @@ -482,7 +482,7 @@ // The size is not the requested one, we fire an event if (m_requester != 0) - m_requester->windowResized(width, height - static_cast([self titlebarHeight])); + m_requester->windowResized({width, height - static_cast([self titlebarHeight])}); } NSRect frame = NSMakeRect([m_window frame].origin.x, diff --git a/src/SFML/Window/OSX/Scaling.h b/src/SFML/Window/OSX/Scaling.h index 915193d4..80657d4a 100644 --- a/src/SFML/Window/OSX/Scaling.h +++ b/src/SFML/Window/OSX/Scaling.h @@ -60,8 +60,8 @@ void scaleIn(T& in, id delegate) template void scaleInWidthHeight(T& in, id delegate) { - scaleIn(in.width, delegate); - scaleIn(in.height, delegate); + scaleIn(in.size.x, delegate); + scaleIn(in.size.y, delegate); } template @@ -85,10 +85,10 @@ void scaleOut(T& out, id delegate) } template -void scaleOutWidthHeight(T& out, id delegate) +void scaleOutWidthHeight(T& width, T& height, id delegate) { - scaleOut(out.width, delegate); - scaleOut(out.height, delegate); + scaleOut(width, delegate); + scaleOut(height, delegate); } template diff --git a/src/SFML/Window/OSX/VideoModeImpl.cpp b/src/SFML/Window/OSX/VideoModeImpl.cpp index 0c5f25f3..b2ade097 100644 --- a/src/SFML/Window/OSX/VideoModeImpl.cpp +++ b/src/SFML/Window/OSX/VideoModeImpl.cpp @@ -62,7 +62,7 @@ std::vector VideoModeImpl::getFullscreenModes() VideoMode mode = convertCGModeToSFMode(cgmode); // Skip if bigger than desktop as we currently don't perform hard resolution switch - if ((mode.width > desktop.width) || (mode.height > desktop.height)) + if ((mode.size.x > desktop.size.x) || (mode.size.y > desktop.size.y)) continue; // If not yet listed we add it to our modes array. diff --git a/src/SFML/Window/OSX/WindowImplCocoa.hpp b/src/SFML/Window/OSX/WindowImplCocoa.hpp index cfe508f8..ff568f97 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.hpp +++ b/src/SFML/Window/OSX/WindowImplCocoa.hpp @@ -113,11 +113,10 @@ public: /// /// Send the event to SFML WindowImpl class. /// - /// \param width new width - /// \param height new height + /// \param size new width and height /// //////////////////////////////////////////////////////////// - void windowResized(unsigned int width, unsigned int height); + void windowResized(const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Window Lost Focus Event - called by the cocoa window object @@ -301,12 +300,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the window's icon /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; + void setIcon(const Vector2u& size, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Window/OSX/WindowImplCocoa.mm b/src/SFML/Window/OSX/WindowImplCocoa.mm index 1a8ccc22..57b8be56 100644 --- a/src/SFML/Window/OSX/WindowImplCocoa.mm +++ b/src/SFML/Window/OSX/WindowImplCocoa.mm @@ -219,13 +219,13 @@ void WindowImplCocoa::windowClosed(void) //////////////////////////////////////////////////////////// -void WindowImplCocoa::windowResized(unsigned int width, unsigned int height) +void WindowImplCocoa::windowResized(const Vector2u& size) { Event event; event.type = Event::Resized; - event.size.width = width; - event.size.height = height; - scaleOutWidthHeight(event.size, m_delegate); + event.size.width = size.x; + event.size.height = size.y; + scaleOutWidthHeight(event.size.width, event.size.height, m_delegate); pushEvent(event); } @@ -455,10 +455,10 @@ void WindowImplCocoa::setTitle(const String& title) //////////////////////////////////////////////////////////// -void WindowImplCocoa::setIcon(unsigned int width, unsigned int height, const Uint8* pixels) +void WindowImplCocoa::setIcon(const Vector2u& size, const Uint8* pixels) { AutoreleasePool pool; - [m_delegate setIconTo:width by:height with:pixels]; + [m_delegate setIconTo:size.x by:size.y with:pixels]; } diff --git a/src/SFML/Window/OSX/cg_sf_conversion.mm b/src/SFML/Window/OSX/cg_sf_conversion.mm index 715c039c..9501160a 100644 --- a/src/SFML/Window/OSX/cg_sf_conversion.mm +++ b/src/SFML/Window/OSX/cg_sf_conversion.mm @@ -95,8 +95,8 @@ VideoMode convertCGModeToSFMode(CGDisplayModeRef cgmode) // // [1]: "APIs for Supporting High Resolution" > "Additions and Changes for OS X v10.8" // https://developer.apple.com/library/mac/documentation/GraphicsAnimation/Conceptual/HighResolutionOSX/APIs/APIs.html#//apple_ref/doc/uid/TP40012302-CH5-SW27 - VideoMode mode(static_cast(CGDisplayModeGetWidth(cgmode)), static_cast(CGDisplayModeGetHeight(cgmode)), static_cast(modeBitsPerPixel(cgmode))); - scaleOutWidthHeight(mode, nil); + VideoMode mode({static_cast(CGDisplayModeGetWidth(cgmode)), static_cast(CGDisplayModeGetHeight(cgmode))}, static_cast(modeBitsPerPixel(cgmode))); + scaleOutWidthHeight(mode.size.x, mode.size.y, nil); return mode; } diff --git a/src/SFML/Window/Unix/GlxContext.cpp b/src/SFML/Window/Unix/GlxContext.cpp index d2272b32..8a5b5b9c 100644 --- a/src/SFML/Window/Unix/GlxContext.cpp +++ b/src/SFML/Window/Unix/GlxContext.cpp @@ -124,7 +124,7 @@ m_ownsWindow(false) ensureExtensionsInit(m_display, DefaultScreen(m_display)); // Create the rendering surface (window or pbuffer if supported) - createSurface(shared, 1, 1, VideoMode::getDesktopMode().bitsPerPixel); + createSurface(shared, {1, 1}, VideoMode::getDesktopMode().bitsPerPixel); // Create the context createContext(shared); @@ -157,7 +157,7 @@ m_ownsWindow(false) //////////////////////////////////////////////////////////// -GlxContext::GlxContext(GlxContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height) : +GlxContext::GlxContext(GlxContext* shared, const ContextSettings& settings, const Vector2u& size) : m_display (nullptr), m_window (0), m_context (nullptr), @@ -174,7 +174,7 @@ m_ownsWindow(false) ensureExtensionsInit(m_display, DefaultScreen(m_display)); // Create the rendering surface (window or pbuffer if supported) - createSurface(shared, width, height, VideoMode::getDesktopMode().bitsPerPixel); + createSurface(shared, size, VideoMode::getDesktopMode().bitsPerPixel); // Create the context createContext(shared); @@ -472,7 +472,7 @@ void GlxContext::updateSettingsFromWindow() //////////////////////////////////////////////////////////// -void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned int height, unsigned int bitsPerPixel) +void GlxContext::createSurface(GlxContext* shared, const Vector2u& size, unsigned int bitsPerPixel) { // Choose the visual according to the context settings XVisualInfo visualInfo = selectBestVisual(m_display, bitsPerPixel, m_settings); @@ -521,8 +521,8 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned { int attributes[] = { - GLX_PBUFFER_WIDTH, static_cast(width), - GLX_PBUFFER_HEIGHT, static_cast(height), + GLX_PBUFFER_WIDTH, static_cast(size.x), + GLX_PBUFFER_HEIGHT, static_cast(size.y), 0, 0 }; @@ -553,7 +553,7 @@ void GlxContext::createSurface(GlxContext* shared, unsigned int width, unsigned m_window = XCreateWindow(m_display, RootWindow(m_display, screen), 0, 0, - width, height, + size.x, size.y, 0, DefaultDepth(m_display, screen), InputOutput, diff --git a/src/SFML/Window/Unix/GlxContext.hpp b/src/SFML/Window/Unix/GlxContext.hpp index 21d865c3..fd91e0a8 100644 --- a/src/SFML/Window/Unix/GlxContext.hpp +++ b/src/SFML/Window/Unix/GlxContext.hpp @@ -69,11 +69,10 @@ public: /// /// \param shared Context to share the new one with /// \param settings Creation parameters - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// //////////////////////////////////////////////////////////// - GlxContext(GlxContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height); + GlxContext(GlxContext* shared, const ContextSettings& settings, const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Destructor @@ -152,12 +151,11 @@ private: /// \brief Create the context's drawing surface /// /// \param shared Context to share the new one with (can be a null pointer) - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// \param bitsPerPixel Pixel depth, in bits per pixel /// //////////////////////////////////////////////////////////// - void createSurface(GlxContext* shared, unsigned int width, unsigned int height, unsigned int bitsPerPixel); + void createSurface(GlxContext* shared, const Vector2u& size, unsigned int bitsPerPixel); //////////////////////////////////////////////////////////// /// \brief Create the context's drawing surface from an existing window diff --git a/src/SFML/Window/Unix/VideoModeImpl.cpp b/src/SFML/Window/Unix/VideoModeImpl.cpp index 3dfb1771..118e1341 100644 --- a/src/SFML/Window/Unix/VideoModeImpl.cpp +++ b/src/SFML/Window/Unix/VideoModeImpl.cpp @@ -74,15 +74,15 @@ std::vector VideoModeImpl::getFullscreenModes() for (int j = 0; j < nbSizes; ++j) { // Convert to VideoMode - VideoMode mode(static_cast(sizes[j].width), - static_cast(sizes[j].height), + VideoMode mode({static_cast(sizes[j].width), + static_cast(sizes[j].height)}, static_cast(depths[i])); Rotation currentRotation; XRRConfigRotations(config, ¤tRotation); if (currentRotation == RR_Rotate_90 || currentRotation == RR_Rotate_270) - std::swap(mode.width, mode.height); + std::swap(mode.size.x, mode.size.y); // Add it only if it is not already in the array if (std::find(modes.begin(), modes.end(), mode) == modes.end()) @@ -152,15 +152,15 @@ VideoMode VideoModeImpl::getDesktopMode() XRRScreenSize* sizes = XRRConfigSizes(config, &nbSizes); if (sizes && (nbSizes > 0)) { - desktopMode = VideoMode(static_cast(sizes[currentMode].width), - static_cast(sizes[currentMode].height), + desktopMode = VideoMode({static_cast(sizes[currentMode].width), + static_cast(sizes[currentMode].height)}, static_cast(DefaultDepth(display, screen))); Rotation modeRotation; XRRConfigRotations(config, &modeRotation); if (modeRotation == RR_Rotate_90 || modeRotation == RR_Rotate_270) - std::swap(desktopMode.width, desktopMode.height); + std::swap(desktopMode.size.x, desktopMode.size.y); } // Free the configuration instance diff --git a/src/SFML/Window/Unix/WindowImplX11.cpp b/src/SFML/Window/Unix/WindowImplX11.cpp index 2c87a892..5cc32d9a 100644 --- a/src/SFML/Window/Unix/WindowImplX11.cpp +++ b/src/SFML/Window/Unix/WindowImplX11.cpp @@ -592,12 +592,12 @@ m_lastInputTime (0) } else { - windowPosition.x = (DisplayWidth(m_display, m_screen) - static_cast(mode.width)) / 2; - windowPosition.y = (DisplayHeight(m_display, m_screen) - static_cast(mode.height)) / 2; + const Vector2i displaySize(DisplayWidth(m_display, m_screen), DisplayHeight(m_display, m_screen)); + windowPosition = displaySize - Vector2i(mode.size) / 2; } - unsigned int width = mode.width; - unsigned int height = mode.height; + unsigned int width = mode.size.x; + unsigned int height = mode.size.y; Visual* visual = nullptr; int depth = 0; @@ -1007,12 +1007,12 @@ void WindowImplX11::setTitle(const String& title) //////////////////////////////////////////////////////////// -void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8* pixels) +void WindowImplX11::setIcon(const Vector2u& size, const Uint8* pixels) { // X11 wants BGRA pixels: swap red and blue channels // Note: this memory will be freed by XDestroyImage - auto* iconPixels = static_cast(std::malloc(static_cast(width) * static_cast(height) * 4)); - for (std::size_t i = 0; i < static_cast(width) * static_cast(height); ++i) + auto* iconPixels = static_cast(std::malloc(static_cast(size.x) * static_cast(size.y) * 4)); + for (std::size_t i = 0; i < static_cast(size.x) * static_cast(size.y); ++i) { iconPixels[i * 4 + 0] = pixels[i * 4 + 2]; iconPixels[i * 4 + 1] = pixels[i * 4 + 1]; @@ -1023,7 +1023,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 // Create the icon pixmap Visual* defVisual = DefaultVisual(m_display, m_screen); auto defDepth = static_cast(DefaultDepth(m_display, m_screen)); - XImage* iconImage = XCreateImage(m_display, defVisual, defDepth, ZPixmap, 0, reinterpret_cast(iconPixels), width, height, 32, 0); + XImage* iconImage = XCreateImage(m_display, defVisual, defDepth, ZPixmap, 0, reinterpret_cast(iconPixels), size.x, size.y, 32, 0); if (!iconImage) { err() << "Failed to set the window's icon" << std::endl; @@ -1036,31 +1036,31 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 if (m_iconMaskPixmap) XFreePixmap(m_display, m_iconMaskPixmap); - m_iconPixmap = XCreatePixmap(m_display, RootWindow(m_display, m_screen), width, height, defDepth); + m_iconPixmap = XCreatePixmap(m_display, RootWindow(m_display, m_screen), size.x, size.y, defDepth); XGCValues values; GC iconGC = XCreateGC(m_display, m_iconPixmap, 0, &values); - XPutImage(m_display, m_iconPixmap, iconGC, iconImage, 0, 0, 0, 0, width, height); + XPutImage(m_display, m_iconPixmap, iconGC, iconImage, 0, 0, 0, 0, size.x, size.y); XFreeGC(m_display, iconGC); XDestroyImage(iconImage); // Create the mask pixmap (must have 1 bit depth) - std::size_t pitch = (width + 7) / 8; - std::vector maskPixels(pitch * height, 0); - for (std::size_t j = 0; j < height; ++j) + std::size_t pitch = (size.x + 7) / 8; + std::vector maskPixels(pitch * size.y, 0); + for (std::size_t j = 0; j < size.y; ++j) { for (std::size_t i = 0; i < pitch; ++i) { for (std::size_t k = 0; k < 8; ++k) { - if (i * 8 + k < width) + if (i * 8 + k < size.x) { - Uint8 opacity = (pixels[(i * 8 + k + j * width) * 4 + 3] > 0) ? 1 : 0; + Uint8 opacity = (pixels[(i * 8 + k + j * size.x) * 4 + 3] > 0) ? 1 : 0; maskPixels[i + j * pitch] |= static_cast(opacity << k); } } } } - m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, reinterpret_cast(maskPixels.data()), width, height, 1, 0, 1); + m_iconMaskPixmap = XCreatePixmapFromBitmapData(m_display, m_window, reinterpret_cast(maskPixels.data()), size.x, size.y, 1, 0, 1); // Send our new icon to the window through the WMHints XWMHints* hints = XAllocWMHints(); @@ -1072,16 +1072,16 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 // ICCCM wants BGRA pixels: swap red and blue channels // ICCCM also wants the first 2 unsigned 32-bit values to be width and height - std::vector icccmIconPixels(2 + width * height, 0); + std::vector icccmIconPixels(2 + size.x * size.y, 0); unsigned long* ptr = icccmIconPixels.data(); #pragma GCC diagnostic push #pragma GCC diagnostic ignored "-Wnull-dereference" // False positive. - *ptr++ = width; - *ptr++ = height; + *ptr++ = size.x; + *ptr++ = size.y; #pragma GCC diagnostic pop - for (std::size_t i = 0; i < static_cast(width) * static_cast(height); ++i) + for (std::size_t i = 0; i < static_cast(size.x) * static_cast(size.y); ++i) { *ptr++ = static_cast((pixels[i * 4 + 2] << 0 ) | (pixels[i * 4 + 1] << 8 ) | @@ -1098,7 +1098,7 @@ void WindowImplX11::setIcon(unsigned int width, unsigned int height, const Uint8 32, PropModeReplace, reinterpret_cast(icccmIconPixels.data()), - static_cast(2 + width * height)); + static_cast(2 + size.x * size.y)); XFlush(m_display); } @@ -1379,8 +1379,8 @@ void WindowImplX11::setVideoMode(const VideoMode& mode) std::swap(res->modes[i].height, res->modes[i].width); // Check if screen size match - if ((res->modes[i].width == mode.width) && - (res->modes[i].height == mode.height)) + if ((res->modes[i].width == mode.size.x) && + (res->modes[i].height == mode.size.y)) { xRandMode = res->modes[i].id; modeFound = true; diff --git a/src/SFML/Window/Unix/WindowImplX11.hpp b/src/SFML/Window/Unix/WindowImplX11.hpp index 7ca264e0..568fe379 100644 --- a/src/SFML/Window/Unix/WindowImplX11.hpp +++ b/src/SFML/Window/Unix/WindowImplX11.hpp @@ -124,12 +124,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the window's icon /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; + void setIcon(const Vector2u& size, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Window/VideoMode.cpp b/src/SFML/Window/VideoMode.cpp index fa834c94..fcd08651 100644 --- a/src/SFML/Window/VideoMode.cpp +++ b/src/SFML/Window/VideoMode.cpp @@ -35,8 +35,7 @@ namespace sf { //////////////////////////////////////////////////////////// VideoMode::VideoMode() : -width (0), -height (0), +size (0, 0), bitsPerPixel(0) { @@ -44,9 +43,8 @@ bitsPerPixel(0) //////////////////////////////////////////////////////////// -VideoMode::VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel) : -width (modeWidth), -height (modeHeight), +VideoMode::VideoMode(const Vector2u& modeSize, unsigned int modeBitsPerPixel) : +size (modeSize), bitsPerPixel(modeBitsPerPixel) { @@ -89,8 +87,7 @@ bool VideoMode::isValid() const //////////////////////////////////////////////////////////// bool operator ==(const VideoMode& left, const VideoMode& right) { - return (left.width == right.width) && - (left.height == right.height) && + return (left.size == right.size) && (left.bitsPerPixel == right.bitsPerPixel); } @@ -107,13 +104,13 @@ bool operator <(const VideoMode& left, const VideoMode& right) { if (left.bitsPerPixel == right.bitsPerPixel) { - if (left.width == right.width) + if (left.size.x == right.size.x) { - return left.height < right.height; + return left.size.y < right.size.y; } else { - return left.width < right.width; + return left.size.x < right.size.x; } } else diff --git a/src/SFML/Window/Win32/VideoModeImpl.cpp b/src/SFML/Window/Win32/VideoModeImpl.cpp index c8d0ac07..5ba44551 100644 --- a/src/SFML/Window/Win32/VideoModeImpl.cpp +++ b/src/SFML/Window/Win32/VideoModeImpl.cpp @@ -46,7 +46,7 @@ std::vector VideoModeImpl::getFullscreenModes() for (int count = 0; EnumDisplaySettings(nullptr, static_cast(count), &win32Mode); ++count) { // Convert to sf::VideoMode - VideoMode mode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); + VideoMode mode({win32Mode.dmPelsWidth, win32Mode.dmPelsHeight}, win32Mode.dmBitsPerPel); // Add it only if it is not already in the array if (std::find(modes.begin(), modes.end(), mode) == modes.end()) @@ -65,7 +65,7 @@ VideoMode VideoModeImpl::getDesktopMode() win32Mode.dmDriverExtra = 0; EnumDisplaySettings(nullptr, ENUM_CURRENT_SETTINGS, &win32Mode); - return VideoMode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); + return VideoMode({win32Mode.dmPelsWidth, win32Mode.dmPelsHeight}, win32Mode.dmBitsPerPel); } } // namespace priv diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index 068364d4..dbdbe274 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -103,7 +103,7 @@ String getErrorString(DWORD errorCode) //////////////////////////////////////////////////////////// WglContext::WglContext(WglContext* shared) : -WglContext(shared, ContextSettings(), 1u, 1u) +WglContext(shared, ContextSettings(), {1u, 1u}) { } @@ -130,7 +130,7 @@ m_ownsWindow (false) //////////////////////////////////////////////////////////// -WglContext::WglContext(WglContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height) : +WglContext::WglContext(WglContext* shared, const ContextSettings& settings, const Vector2u& size) : m_window (nullptr), m_pbuffer (nullptr), m_deviceContext(nullptr), @@ -143,7 +143,7 @@ m_ownsWindow (false) m_settings = settings; // Create the rendering surface (window or pbuffer if supported) - createSurface(shared, width, height, VideoMode::getDesktopMode().bitsPerPixel); + createSurface(shared, size, VideoMode::getDesktopMode().bitsPerPixel); // Create the context createContext(shared); @@ -523,7 +523,7 @@ void WglContext::updateSettingsFromPixelFormat() //////////////////////////////////////////////////////////// -void WglContext::createSurface(WglContext* shared, unsigned int width, unsigned int height, unsigned int bitsPerPixel) +void WglContext::createSurface(WglContext* shared, const Vector2u& size, unsigned int bitsPerPixel) { // Check if the shared context already exists and pbuffers are supported if (shared && shared->m_deviceContext && SF_GLAD_WGL_ARB_pbuffer) @@ -534,7 +534,7 @@ void WglContext::createSurface(WglContext* shared, unsigned int width, unsigned { int attributes[] = {0, 0}; - m_pbuffer = wglCreatePbufferARB(shared->m_deviceContext, bestFormat, static_cast(width), static_cast(height), attributes); + m_pbuffer = wglCreatePbufferARB(shared->m_deviceContext, bestFormat, static_cast(size.x), static_cast(size.y), attributes); if (m_pbuffer) { @@ -563,7 +563,7 @@ void WglContext::createSurface(WglContext* shared, unsigned int width, unsigned // with other contexts and thus wglShareLists would always fail // Create the hidden window - m_window = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, static_cast(width), static_cast(height), nullptr, nullptr, GetModuleHandle(nullptr), nullptr); + m_window = CreateWindowA("STATIC", "", WS_POPUP | WS_DISABLED, 0, 0, static_cast(size.x), static_cast(size.y), nullptr, nullptr, GetModuleHandle(nullptr), nullptr); ShowWindow(m_window, SW_HIDE); m_deviceContext = GetDC(m_window); diff --git a/src/SFML/Window/Win32/WglContext.hpp b/src/SFML/Window/Win32/WglContext.hpp index b867cec3..605b50a6 100644 --- a/src/SFML/Window/Win32/WglContext.hpp +++ b/src/SFML/Window/Win32/WglContext.hpp @@ -68,11 +68,10 @@ public: /// /// \param shared Context to share the new one with /// \param settings Creation parameters - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// //////////////////////////////////////////////////////////// - WglContext(WglContext* shared, const ContextSettings& settings, unsigned int width, unsigned int height); + WglContext(WglContext* shared, const ContextSettings& settings, const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Destructor @@ -152,12 +151,11 @@ private: /// \brief Create the context's drawing surface /// /// \param shared Shared context (can be a null pointer) - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// \param bitsPerPixel Pixel depth, in bits per pixel /// //////////////////////////////////////////////////////////// - void createSurface(WglContext* shared, unsigned int width, unsigned int height, unsigned int bitsPerPixel); + void createSurface(WglContext* shared, const Vector2u& size, unsigned int bitsPerPixel); //////////////////////////////////////////////////////////// /// \brief Create the context's drawing surface from an existing window diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index a49dc6c0..b2ed27fd 100755 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -164,7 +164,7 @@ m_cursorVisible (true), // might need to call GetCursorInfo m_lastCursor (LoadCursor(nullptr, IDC_ARROW)), m_icon (nullptr), m_keyRepeatEnabled(true), -m_lastSize (mode.width, mode.height), +m_lastSize (mode.size), m_resizing (false), m_surrogate (0), m_mouseInside (false), @@ -180,10 +180,10 @@ m_cursorGrabbed (m_fullscreen) // Compute position and size HDC screenDC = GetDC(nullptr); - int left = (GetDeviceCaps(screenDC, HORZRES) - static_cast(mode.width)) / 2; - int top = (GetDeviceCaps(screenDC, VERTRES) - static_cast(mode.height)) / 2; - int width = static_cast(mode.width); - int height = static_cast(mode.height); + 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); ReleaseDC(nullptr, screenDC); // Choose the window style according to the Style parameter @@ -226,7 +226,7 @@ m_cursorGrabbed (m_fullscreen) // By default, the OS limits the size of the window the the desktop size, // we have to resize it after creation to apply the real size - setSize(Vector2u(mode.width, mode.height)); + setSize(mode.size); // Switch to fullscreen if requested if (m_fullscreen) @@ -351,14 +351,14 @@ void WindowImplWin32::setTitle(const String& title) //////////////////////////////////////////////////////////// -void WindowImplWin32::setIcon(unsigned int width, unsigned int height, const Uint8* pixels) +void WindowImplWin32::setIcon(const Vector2u& size, const Uint8* pixels) { // First destroy the previous one if (m_icon) DestroyIcon(m_icon); // Windows wants BGRA pixels: swap red and blue channels - std::vector iconPixels(width * height * 4); + std::vector iconPixels(size.x * size.y * 4); for (std::size_t i = 0; i < iconPixels.size() / 4; ++i) { iconPixels[i * 4 + 0] = pixels[i * 4 + 2]; @@ -368,7 +368,7 @@ void WindowImplWin32::setIcon(unsigned int width, unsigned int height, const Uin } // Create the icon from the pixel array - m_icon = CreateIcon(GetModuleHandleW(nullptr), static_cast(width), static_cast(height), 1, 32, nullptr, iconPixels.data()); + m_icon = CreateIcon(GetModuleHandleW(nullptr), static_cast(size.x), static_cast(size.y), 1, 32, nullptr, iconPixels.data()); // Set it as both big and small icon of the window if (m_icon) @@ -479,8 +479,8 @@ void WindowImplWin32::switchToFullscreen(const VideoMode& mode) { DEVMODE devMode; devMode.dmSize = sizeof(devMode); - devMode.dmPelsWidth = mode.width; - devMode.dmPelsHeight = mode.height; + devMode.dmPelsWidth = mode.size.x; + devMode.dmPelsHeight = mode.size.y; devMode.dmBitsPerPel = mode.bitsPerPixel; devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; @@ -496,7 +496,7 @@ void WindowImplWin32::switchToFullscreen(const VideoMode& mode) SetWindowLongPtr(m_handle, GWL_EXSTYLE, WS_EX_APPWINDOW); // Resize the window so that it fits the entire screen - SetWindowPos(m_handle, HWND_TOP, 0, 0, static_cast(mode.width), static_cast(mode.height), SWP_FRAMECHANGED); + SetWindowPos(m_handle, HWND_TOP, 0, 0, static_cast(mode.size.x), static_cast(mode.size.y), SWP_FRAMECHANGED); ShowWindow(m_handle, SW_SHOW); // Set "this" as the current fullscreen window diff --git a/src/SFML/Window/Win32/WindowImplWin32.hpp b/src/SFML/Window/Win32/WindowImplWin32.hpp index f4fa76e3..6216cc35 100755 --- a/src/SFML/Window/Win32/WindowImplWin32.hpp +++ b/src/SFML/Window/Win32/WindowImplWin32.hpp @@ -123,12 +123,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the window's icon /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; + void setIcon(const Vector2u& size, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index 3086313d..ac9b42f6 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -235,10 +235,10 @@ void WindowBase::setTitle(const String& title) //////////////////////////////////////////////////////////// -void WindowBase::setIcon(unsigned int width, unsigned int height, const Uint8* pixels) +void WindowBase::setIcon(const Vector2u& size, const Uint8* pixels) { if (m_impl) - m_impl->setIcon(width, height, pixels); + m_impl->setIcon(size, pixels); } diff --git a/src/SFML/Window/WindowImpl.hpp b/src/SFML/Window/WindowImpl.hpp index 5b016586..91a42ce9 100644 --- a/src/SFML/Window/WindowImpl.hpp +++ b/src/SFML/Window/WindowImpl.hpp @@ -176,12 +176,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the window's icon /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - virtual void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) = 0; + virtual void setIcon(const Vector2u& size, const Uint8* pixels) = 0; //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Window/iOS/EaglContext.hpp b/src/SFML/Window/iOS/EaglContext.hpp index 5e1a851c..4860a705 100644 --- a/src/SFML/Window/iOS/EaglContext.hpp +++ b/src/SFML/Window/iOS/EaglContext.hpp @@ -77,12 +77,11 @@ public: /// /// \param shared Context to share the new one with /// \param settings Creation parameters - /// \param width Back buffer width, in pixels - /// \param height Back buffer height, in pixels + /// \param size Back buffer width and height, in pixels /// //////////////////////////////////////////////////////////// EaglContext(EaglContext* shared, const ContextSettings& settings, - unsigned int width, unsigned int height); + const Vector2u& size); //////////////////////////////////////////////////////////// /// \brief Destructor diff --git a/src/SFML/Window/iOS/EaglContext.mm b/src/SFML/Window/iOS/EaglContext.mm index 92875d4b..622f7a9a 100644 --- a/src/SFML/Window/iOS/EaglContext.mm +++ b/src/SFML/Window/iOS/EaglContext.mm @@ -126,7 +126,7 @@ m_clock () //////////////////////////////////////////////////////////// EaglContext::EaglContext(EaglContext* /* shared */, const ContextSettings& /* settings */, - unsigned int /* width */, unsigned int /* height */) : + const Vector2u& /* size */) : m_context (nil), m_framebuffer (0), m_colorbuffer (0), diff --git a/src/SFML/Window/iOS/VideoModeImpl.mm b/src/SFML/Window/iOS/VideoModeImpl.mm index 03c60c83..095af56f 100644 --- a/src/SFML/Window/iOS/VideoModeImpl.mm +++ b/src/SFML/Window/iOS/VideoModeImpl.mm @@ -41,7 +41,7 @@ std::vector VideoModeImpl::getFullscreenModes() // Return both portrait and landscape resolutions std::vector modes; modes.push_back(desktop); - modes.emplace_back(desktop.height, desktop.width, desktop.bitsPerPixel); + modes.emplace_back(Vector2u(desktop.size.y, desktop.size.x), desktop.bitsPerPixel); return modes; } @@ -51,7 +51,7 @@ VideoMode VideoModeImpl::getDesktopMode() { CGRect bounds = [[UIScreen mainScreen] bounds]; double backingScale = [SFAppDelegate getInstance].backingScaleFactor; - return VideoMode(static_cast(bounds.size.width * backingScale), static_cast(bounds.size.height * backingScale)); + return VideoMode({static_cast(bounds.size.width * backingScale), static_cast(bounds.size.height * backingScale)}); } } // namespace priv diff --git a/src/SFML/Window/iOS/WindowImplUIKit.hpp b/src/SFML/Window/iOS/WindowImplUIKit.hpp index f8e29581..c1db522c 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.hpp +++ b/src/SFML/Window/iOS/WindowImplUIKit.hpp @@ -126,12 +126,11 @@ public: //////////////////////////////////////////////////////////// /// \brief Change the window's icon /// - /// \param width Icon's width, in pixels - /// \param height Icon's height, in pixels + /// \param size Icon's width and height, in pixels /// \param pixels Pointer to the pixels in memory, format must be RGBA 32 bits /// //////////////////////////////////////////////////////////// - void setIcon(unsigned int width, unsigned int height, const Uint8* pixels) override; + void setIcon(const Vector2u& size, const Uint8* pixels) override; //////////////////////////////////////////////////////////// /// \brief Show or hide the window diff --git a/src/SFML/Window/iOS/WindowImplUIKit.mm b/src/SFML/Window/iOS/WindowImplUIKit.mm index e518fd4a..ae474f1c 100644 --- a/src/SFML/Window/iOS/WindowImplUIKit.mm +++ b/src/SFML/Window/iOS/WindowImplUIKit.mm @@ -64,7 +64,7 @@ WindowImplUIKit::WindowImplUIKit(VideoMode mode, [UIApplication sharedApplication].statusBarHidden = !(style & Style::Titlebar) || (style & Style::Fullscreen); // Set the orientation according to the requested size - if (mode.width > mode.height) + if (mode.size.x > mode.size.y) [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationLandscapeLeft]; else [[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait]; @@ -180,7 +180,7 @@ void WindowImplUIKit::setTitle(const String& /* title */) //////////////////////////////////////////////////////////// -void WindowImplUIKit::setIcon(unsigned int /* width */, unsigned int /* height */, const Uint8* /* pixels */) +void WindowImplUIKit::setIcon(const Vector2u& /* size */, const Uint8* /* pixels */) { // Not applicable } diff --git a/test/TestUtilities/WindowUtil.cpp b/test/TestUtilities/WindowUtil.cpp index 637e328c..5463559a 100644 --- a/test/TestUtilities/WindowUtil.cpp +++ b/test/TestUtilities/WindowUtil.cpp @@ -6,7 +6,7 @@ namespace sf { std::ostream& operator <<(std::ostream& os, const sf::VideoMode& videoMode) { - os << videoMode.width << "x" << videoMode.height << "x" << videoMode.bitsPerPixel; + os << videoMode.size.x << "x" << videoMode.size.y << "x" << videoMode.bitsPerPixel; return os; } } diff --git a/test/Window/VideoMode.cpp b/test/Window/VideoMode.cpp index 6f5e0512..0bfefc37 100644 --- a/test/Window/VideoMode.cpp +++ b/test/Window/VideoMode.cpp @@ -10,24 +10,21 @@ TEST_CASE("sf::VideoMode class - [window]") SUBCASE("Default constructor") { sf::VideoMode videoMode; - CHECK(videoMode.width == 0); - CHECK(videoMode.height == 0); + CHECK(videoMode.size == sf::Vector2u(0, 0)); CHECK(videoMode.bitsPerPixel == 0); } SUBCASE("Width, height constructor") { - sf::VideoMode videoMode(800, 600); - CHECK(videoMode.width == 800); - CHECK(videoMode.height == 600); + sf::VideoMode videoMode({800, 600}); + CHECK(videoMode.size == sf::Vector2u(800, 600)); CHECK(videoMode.bitsPerPixel == 32); } SUBCASE("Width, height, bit depth constructor") { - sf::VideoMode videoMode(800, 600, 24); - CHECK(videoMode.width == 800); - CHECK(videoMode.height == 600); + sf::VideoMode videoMode({800, 600}, 24); + CHECK(videoMode.size == sf::Vector2u(800, 600)); CHECK(videoMode.bitsPerPixel == 24); } } @@ -37,55 +34,55 @@ TEST_CASE("sf::VideoMode class - [window]") SUBCASE("operator==") { CHECK(sf::VideoMode() == sf::VideoMode()); - CHECK(sf::VideoMode(0, 0, 0) == sf::VideoMode(0, 0, 0)); - CHECK(sf::VideoMode(1080, 1920, 64) == sf::VideoMode(1080, 1920, 64)); + CHECK(sf::VideoMode({0, 0}, 0) == sf::VideoMode({0, 0}, 0)); + CHECK(sf::VideoMode({1080, 1920}, 64) == sf::VideoMode({1080, 1920}, 64)); } SUBCASE("operator!=") { - CHECK(sf::VideoMode() != sf::VideoMode(1, 0)); - CHECK(sf::VideoMode() != sf::VideoMode(0, 1)); - CHECK(sf::VideoMode() != sf::VideoMode(0, 0, 1)); - CHECK(sf::VideoMode(720, 720) != sf::VideoMode(720, 720, 24)); - CHECK(sf::VideoMode(1080, 1920, 16) != sf::VideoMode(400, 600)); + CHECK(sf::VideoMode() != sf::VideoMode({1, 0})); + CHECK(sf::VideoMode() != sf::VideoMode({0, 1})); + CHECK(sf::VideoMode() != sf::VideoMode({0, 0}, 1)); + CHECK(sf::VideoMode({720, 720}) != sf::VideoMode({720, 720}, 24)); + CHECK(sf::VideoMode({1080, 1920}, 16) != sf::VideoMode({400, 600})); } SUBCASE("operator<") { - CHECK(sf::VideoMode() < sf::VideoMode(0, 0, 1)); - CHECK(sf::VideoMode(800, 800, 24) < sf::VideoMode(1080, 1920, 48)); - CHECK(sf::VideoMode(400, 600, 48) < sf::VideoMode(600, 400, 48)); - CHECK(sf::VideoMode(400, 400, 48) < sf::VideoMode(400, 600, 48)); + CHECK(sf::VideoMode() < sf::VideoMode({0, 0}, 1)); + CHECK(sf::VideoMode({800, 800}, 24) < sf::VideoMode({1080, 1920}, 48)); + CHECK(sf::VideoMode({400, 600}, 48) < sf::VideoMode({600, 400}, 48)); + CHECK(sf::VideoMode({400, 400}, 48) < sf::VideoMode({400, 600}, 48)); } SUBCASE("operator>") { - CHECK(sf::VideoMode(1, 0) > sf::VideoMode(0, 0, 1)); - CHECK(sf::VideoMode(800, 800, 48) > sf::VideoMode(1080, 1920, 24)); - CHECK(sf::VideoMode(600, 400, 48) > sf::VideoMode(400, 600, 48)); - CHECK(sf::VideoMode(400, 600, 48) > sf::VideoMode(400, 400, 48)); + CHECK(sf::VideoMode({1, 0}) > sf::VideoMode({0, 0}, 1)); + CHECK(sf::VideoMode({800, 800}, 48) > sf::VideoMode({1080, 1920}, 24)); + CHECK(sf::VideoMode({600, 400}, 48) > sf::VideoMode({400, 600}, 48)); + CHECK(sf::VideoMode({400, 600}, 48) > sf::VideoMode({400, 400}, 48)); } SUBCASE("operator<=") { - CHECK(sf::VideoMode() <= sf::VideoMode(0, 0, 1)); - CHECK(sf::VideoMode(800, 800, 24) <= sf::VideoMode(1080, 1920, 48)); - CHECK(sf::VideoMode(400, 600, 48) <= sf::VideoMode(600, 400, 48)); - CHECK(sf::VideoMode(400, 400, 48) <= sf::VideoMode(400, 600, 48)); + CHECK(sf::VideoMode() <= sf::VideoMode({0, 0}, 1)); + CHECK(sf::VideoMode({800, 800}, 24) <= sf::VideoMode({1080, 1920}, 48)); + CHECK(sf::VideoMode({400, 600}, 48) <= sf::VideoMode({600, 400}, 48)); + CHECK(sf::VideoMode({400, 400}, 48) <= sf::VideoMode({400, 600}, 48)); CHECK(sf::VideoMode() <= sf::VideoMode()); - CHECK(sf::VideoMode(0, 0, 0) <= sf::VideoMode(0, 0, 0)); - CHECK(sf::VideoMode(1080, 1920, 64) <= sf::VideoMode(1080, 1920, 64)); + CHECK(sf::VideoMode({0, 0}, 0) <= sf::VideoMode({0, 0}, 0)); + CHECK(sf::VideoMode({1080, 1920}, 64) <= sf::VideoMode({1080, 1920}, 64)); } SUBCASE("operator>=") { - CHECK(sf::VideoMode(1, 0) >= sf::VideoMode(0, 0, 1)); - CHECK(sf::VideoMode(800, 800, 48) >= sf::VideoMode(1080, 1920, 24)); - CHECK(sf::VideoMode(600, 400, 48) >= sf::VideoMode(400, 600, 48)); - CHECK(sf::VideoMode(400, 600, 48) >= sf::VideoMode(400, 400, 48)); + CHECK(sf::VideoMode({1, 0}) >= sf::VideoMode({0, 0}, 1)); + CHECK(sf::VideoMode({800, 800}, 48) >= sf::VideoMode({1080, 1920}, 24)); + CHECK(sf::VideoMode({600, 400}, 48) >= sf::VideoMode({400, 600}, 48)); + CHECK(sf::VideoMode({400, 600}, 48) >= sf::VideoMode({400, 400}, 48)); CHECK(sf::VideoMode() >= sf::VideoMode()); - CHECK(sf::VideoMode(0, 0, 0) >= sf::VideoMode(0, 0, 0)); - CHECK(sf::VideoMode(1080, 1920, 64) >= sf::VideoMode(1080, 1920, 64)); + CHECK(sf::VideoMode({0, 0}, 0) >= sf::VideoMode({0, 0}, 0)); + CHECK(sf::VideoMode({1080, 1920}, 64) >= sf::VideoMode({1080, 1920}, 64)); } } }