Add window create functions without style specifier

This brings the create() functions inline with the constructor overloads
for WindowBase, Window, and RenderWindow
This commit is contained in:
Lukas Dürrenberger 2024-09-13 20:00:01 +02:00 committed by Chris Thrasher
parent e2ea1d8a7c
commit 6591c59504
6 changed files with 110 additions and 4 deletions

View File

@ -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
///

View File

@ -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
///

View File

@ -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)
{

View File

@ -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)
{

View File

@ -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);
}
}
}

View File

@ -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);