From 6591c595048db6beecc06fc5f5912eded026b27c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Lukas=20D=C3=BCrrenberger?= Date: Fri, 13 Sep 2024 20:00:01 +0200 Subject: [PATCH] Add window create functions without style specifier This brings the create() functions inline with the constructor overloads for WindowBase, Window, and RenderWindow --- include/SFML/Window/Window.hpp | 37 +++++++++++++++++++++++++++--- include/SFML/Window/WindowBase.hpp | 14 +++++++++++ src/SFML/Window/Window.cpp | 14 +++++++++++ src/SFML/Window/WindowBase.cpp | 7 ++++++ test/Window/Window.test.cpp | 34 ++++++++++++++++++++++++++- test/Window/WindowBase.test.cpp | 8 +++++++ 6 files changed, 110 insertions(+), 4 deletions(-) diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index 62e20a82d..2cc0da4e8 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -180,9 +180,8 @@ public: /// If \a `state` is `State::Fullscreen`, then \a `mode` must be /// a valid video mode. /// - /// The last parameter is an optional structure specifying - /// advanced OpenGL context settings such as anti-aliasing, - /// depth-buffer bits, etc. + /// The last parameter is a structure specifying advanced OpenGL + /// context settings such as anti-aliasing, depth-buffer bits, etc. /// /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) /// \param title Title of the window @@ -193,6 +192,38 @@ public: //////////////////////////////////////////////////////////// virtual void create(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& settings); + //////////////////////////////////////////////////////////// + /// \brief Create (or recreate) the window + /// + /// If the window was already created, it closes it first. + /// If \a `state` is `State::Fullscreen`, then \a `mode` must be + /// a valid video mode. + /// + /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) + /// \param title Title of the window + /// \param state %Window state + /// + //////////////////////////////////////////////////////////// + void create(VideoMode mode, const String& title, State state) override; + + //////////////////////////////////////////////////////////// + /// \brief Create (or recreate) the window + /// + /// If the window was already created, it closes it first. + /// If \a `state` is `State::Fullscreen`, then \a `mode` must be + /// a valid video mode. + /// + /// The last parameter is a structure specifying advanced OpenGL + /// context settings such as anti-aliasing, depth-buffer bits, etc. + /// + /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) + /// \param title Title of the window + /// \param state %Window state + /// \param settings Additional settings for the underlying OpenGL context + /// + //////////////////////////////////////////////////////////// + virtual void create(VideoMode mode, const String& title, State state, const ContextSettings& settings); + //////////////////////////////////////////////////////////// /// \brief Create (or recreate) the window from an existing control /// diff --git a/include/SFML/Window/WindowBase.hpp b/include/SFML/Window/WindowBase.hpp index 7161bed76..33d105165 100644 --- a/include/SFML/Window/WindowBase.hpp +++ b/include/SFML/Window/WindowBase.hpp @@ -157,6 +157,20 @@ public: //////////////////////////////////////////////////////////// virtual void create(VideoMode mode, const String& title, std::uint32_t style = Style::Default, State state = State::Windowed); + //////////////////////////////////////////////////////////// + /// \brief Create (or recreate) the window + /// + /// If the window was already created, it closes it first. + /// If \a `state` is `State::Fullscreen`, then \a `mode` must be + /// a valid video mode. + /// + /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) + /// \param title Title of the window + /// \param state %Window state + /// + //////////////////////////////////////////////////////////// + virtual void create(VideoMode mode, const String& title, State state); + //////////////////////////////////////////////////////////// /// \brief Create (or recreate) the window from an existing control /// diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index fc0cc6291..54d6ac3bd 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -95,6 +95,20 @@ void Window::create(VideoMode mode, const String& title, std::uint32_t style, St } +//////////////////////////////////////////////////////////// +void Window::create(VideoMode mode, const String& title, State state) +{ + Window::create(mode, title, sf::Style::Default, state, ContextSettings{}); +} + + +//////////////////////////////////////////////////////////// +void Window::create(VideoMode mode, const String& title, State state, const ContextSettings& settings) +{ + Window::create(mode, title, sf::Style::Default, state, settings); +} + + //////////////////////////////////////////////////////////// void Window::create(WindowHandle handle) { diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index 9d925f833..f16d9513a 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -102,6 +102,13 @@ void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style } +//////////////////////////////////////////////////////////// +void WindowBase::create(VideoMode mode, const String& title, State state) +{ + create(mode, title, Style::Default, state); +} + + //////////////////////////////////////////////////////////// void WindowBase::create(WindowHandle handle) { diff --git a/test/Window/Window.test.cpp b/test/Window/Window.test.cpp index b48e91705..f5443d7ae 100644 --- a/test/Window/Window.test.cpp +++ b/test/Window/Window.test.cpp @@ -128,7 +128,16 @@ TEST_CASE("[Window] sf::Window", runDisplayTests()) CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default); } - SECTION("Mode, title, style, and context settings") + SECTION("Mode, title, style, and state") + { + window.create(sf::VideoMode({240, 360}), "Window Tests", sf::Style::Resize, sf::State::Windowed); + CHECK(window.isOpen()); + CHECK(window.getSize() == sf::Vector2u(240, 360)); + CHECK(window.getNativeHandle() != sf::WindowHandle()); + CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default); + } + + SECTION("Mode, title, style, state, and context settings") { window.create(sf::VideoMode({240, 360}), "Window Tests", @@ -142,5 +151,28 @@ TEST_CASE("[Window] sf::Window", runDisplayTests()) CHECK(window.getSettings().stencilBits >= 1); CHECK(window.getSettings().antiAliasingLevel >= 1); } + + SECTION("Mode, title, and state") + { + window.create(sf::VideoMode({240, 360}), "Window Tests", sf::State::Windowed); + CHECK(window.isOpen()); + CHECK(window.getSize() == sf::Vector2u(240, 360)); + CHECK(window.getNativeHandle() != sf::WindowHandle()); + CHECK(window.getSettings().attributeFlags == sf::ContextSettings::Default); + } + + SECTION("Mode, title, state, and context settings") + { + window.create(sf::VideoMode({240, 360}), + "Window Tests", + sf::State::Windowed, + sf::ContextSettings{/* depthBits*/ 1, /* stencilBits */ 1, /* antiAliasingLevel */ 1}); + CHECK(window.isOpen()); + CHECK(window.getSize() == sf::Vector2u(240, 360)); + CHECK(window.getNativeHandle() != sf::WindowHandle()); + CHECK(window.getSettings().depthBits >= 1); + CHECK(window.getSettings().stencilBits >= 1); + CHECK(window.getSettings().antiAliasingLevel >= 1); + } } } diff --git a/test/Window/WindowBase.test.cpp b/test/Window/WindowBase.test.cpp index d9dcfb3e3..66b01befc 100644 --- a/test/Window/WindowBase.test.cpp +++ b/test/Window/WindowBase.test.cpp @@ -88,6 +88,14 @@ TEST_CASE("[Window] sf::WindowBase", runDisplayTests()) CHECK(windowBase.getNativeHandle() != sf::WindowHandle()); } + SECTION("Mode, title, and state") + { + windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests", sf::State::Windowed); + CHECK(windowBase.isOpen()); + CHECK(windowBase.getSize() == sf::Vector2u(240, 360)); + CHECK(windowBase.getNativeHandle() != sf::WindowHandle()); + } + SECTION("Mode, title, style, and state") { windowBase.create(sf::VideoMode({240, 360}), "WindowBase Tests", sf::Style::Resize, sf::State::Windowed);