Skip to content

Commit

Permalink
Add sf::State
Browse files Browse the repository at this point in the history
  • Loading branch information
ChrisThrasher committed Dec 10, 2023
1 parent f93e1e4 commit e3c33de
Show file tree
Hide file tree
Showing 11 changed files with 61 additions and 20 deletions.
6 changes: 5 additions & 1 deletion examples/opengl/OpenGL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,11 @@ 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,
sf::State::Windowed,
contextSettings);
window.setVerticalSyncEnabled(true);
window.setMinimumSize(sf::Vector2u(400, 300));
window.setMaximumSize(sf::Vector2u(1200, 900));
Expand Down
2 changes: 1 addition & 1 deletion examples/window/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,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, sf::State::Windowed, contextSettings);

// Make it the active window for OpenGL calls
if (!window.setActive())
Expand Down
2 changes: 2 additions & 0 deletions include/SFML/Graphics/RenderWindow.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -70,12 +70,14 @@ class SFML_GRAPHICS_API RenderWindow : public Window, public RenderTarget
/// \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 style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param state %Window state
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
RenderWindow(VideoMode mode,
const String& title,
std::uint32_t style = Style::Default,
State state = State::Windowed,
const ContextSettings& settings = ContextSettings());

////////////////////////////////////////////////////////////
Expand Down
8 changes: 6 additions & 2 deletions include/SFML/Window/Window.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -78,12 +78,14 @@ class SFML_WINDOW_API Window : public WindowBase, GlResource
/// \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 style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param state %Window state
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
Window(VideoMode mode,
const String& title,
std::uint32_t style = Style::Default,
State state = State::Windowed,
const ContextSettings& settings = ContextSettings());

////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -120,9 +122,10 @@ class SFML_WINDOW_API Window : public WindowBase, GlResource
/// \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 style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param state %Window state
///
////////////////////////////////////////////////////////////
void create(VideoMode mode, const String& title, std::uint32_t style = Style::Default) override;
void create(VideoMode mode, const String& title, std::uint32_t style = Style::Default, State state = State::Windowed) override;

////////////////////////////////////////////////////////////
/// \brief Create (or recreate) the window
Expand All @@ -138,10 +141,11 @@ class SFML_WINDOW_API Window : public WindowBase, GlResource
/// \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 style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param state %Window state
/// \param settings Additional settings for the underlying OpenGL context
///
////////////////////////////////////////////////////////////
virtual void create(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings);
virtual void create(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& settings);

////////////////////////////////////////////////////////////
/// \brief Create (or recreate) the window from an existing control
Expand Down
6 changes: 4 additions & 2 deletions include/SFML/Window/WindowBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,9 +80,10 @@ class SFML_WINDOW_API WindowBase
/// \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 style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param state %Window state
///
////////////////////////////////////////////////////////////
WindowBase(VideoMode mode, const String& title, std::uint32_t style = Style::Default);
WindowBase(VideoMode mode, const String& title, std::uint32_t style = Style::Default, State state = State::Windowed);

////////////////////////////////////////////////////////////
/// \brief Construct the window from an existing control
Expand Down Expand Up @@ -122,9 +123,10 @@ class SFML_WINDOW_API WindowBase
/// \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 style %Window style, a bitwise OR combination of sf::Style enumerators
/// \param state %Window state
///
////////////////////////////////////////////////////////////
virtual void create(VideoMode mode, const String& title, std::uint32_t style = Style::Default);
virtual void create(VideoMode mode, const String& title, std::uint32_t style = Style::Default, State state = State::Windowed);

////////////////////////////////////////////////////////////
/// \brief Create (or recreate) the window from an existing control
Expand Down
23 changes: 21 additions & 2 deletions include/SFML/Window/WindowStyle.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,9 @@
#pragma once


namespace sf::Style
namespace sf
{
namespace Style
{
////////////////////////////////////////////////////////////
/// \ingroup window
Expand All @@ -42,4 +44,21 @@ enum

Default = Titlebar | Resize | Close //!< Default window style
};
} // namespace sf::Style

} // namespace Style

////////////////////////////////////////////////////////////
/// \ingroup window
/// \brief Enumeration of the window states
///
////////////////////////////////////////////////////////////
enum class State
{
Windowed, //!<
// Minimized, //!<
// Maximized, //!<
// Fullscreen, //!<
// Hidden //!<
};

} // namespace sf
4 changes: 2 additions & 2 deletions src/SFML/Graphics/RenderWindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ RenderWindow::RenderWindow() = default;


////////////////////////////////////////////////////////////
RenderWindow::RenderWindow(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings)
RenderWindow::RenderWindow(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& settings)
{
// Don't call the base class constructor because it contains virtual function calls
Window::create(mode, title, style, settings);
Window::create(mode, title, style, state, settings);
}


Expand Down
10 changes: 5 additions & 5 deletions src/SFML/Window/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,9 +44,9 @@ Window::Window() = default;


////////////////////////////////////////////////////////////
Window::Window(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings)
Window::Window(VideoMode mode, const String& title, std::uint32_t style, State state, const ContextSettings& settings)
{
Window::create(mode, title, style, settings);
Window::create(mode, title, style, state, settings);
}


Expand All @@ -65,14 +65,14 @@ Window::~Window()


////////////////////////////////////////////////////////////
void Window::create(VideoMode mode, const String& title, std::uint32_t style)
void Window::create(VideoMode mode, const String& title, std::uint32_t style, State state)
{
Window::create(mode, title, style, ContextSettings());
Window::create(mode, title, style, state, ContextSettings());
}


////////////////////////////////////////////////////////////
void Window::create(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings)
void Window::create(VideoMode mode, const String& title, std::uint32_t style, State /* state */, const ContextSettings& settings)
{
// Destroy the previous window implementation
close();
Expand Down
6 changes: 3 additions & 3 deletions src/SFML/Window/WindowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -55,9 +55,9 @@ WindowBase::WindowBase() = default;


////////////////////////////////////////////////////////////
WindowBase::WindowBase(VideoMode mode, const String& title, std::uint32_t style)
WindowBase::WindowBase(VideoMode mode, const String& title, std::uint32_t style, State state)
{
WindowBase::create(mode, title, style);
WindowBase::create(mode, title, style, state);
}


Expand All @@ -76,7 +76,7 @@ WindowBase::~WindowBase()


////////////////////////////////////////////////////////////
void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style)
void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style, State /* state */)
{
// Destroy the previous window implementation
close();
Expand Down
2 changes: 2 additions & 0 deletions test/Graphics/RenderWindow.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests())
const sf::RenderWindow window(sf::VideoMode(sf::Vector2u(256, 256), 24),
"Window Title",
sf::Style::Default,
sf::State::Windowed,
sf::ContextSettings());
CHECK(window.getSize() == sf::Vector2u(256, 256));
}
Expand All @@ -37,6 +38,7 @@ TEST_CASE("[Graphics] sf::RenderWindow", runDisplayTests())
sf::RenderWindow window(sf::VideoMode(sf::Vector2u(256, 256), 24),
"Window Title",
sf::Style::Default,
sf::State::Windowed,
sf::ContextSettings());
REQUIRE(window.getSize() == sf::Vector2u(256, 256));

Expand Down
12 changes: 10 additions & 2 deletions test/Window/Window.test.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,11 @@ TEST_CASE("[Window] sf::Window", runDisplayTests())

SECTION("Mode, title, style, and context settings constructor")
{
const sf::Window window(sf::VideoMode({360, 240}), "Window Tests", sf::Style::Resize, sf::ContextSettings(1, 1, 1));
const sf::Window window(sf::VideoMode({360, 240}),
"Window Tests",
sf::Style::Resize,
sf::State::Windowed,
sf::ContextSettings(1, 1, 1));
CHECK(window.isOpen());
CHECK(window.getSize() == sf::Vector2u(360, 240));
CHECK(window.getNativeHandle() != sf::WindowHandle());
Expand Down Expand Up @@ -93,7 +97,11 @@ TEST_CASE("[Window] sf::Window", runDisplayTests())

SECTION("Mode, title, style, and context settings")
{
window.create(sf::VideoMode({240, 360}), "Window Tests", sf::Style::Resize, sf::ContextSettings(1, 1, 1));
window.create(sf::VideoMode({240, 360}),
"Window Tests",
sf::Style::Resize,
sf::State::Windowed,
sf::ContextSettings(1, 1, 1));
CHECK(window.isOpen());
CHECK(window.getSize() == sf::Vector2u(240, 360));
CHECK(window.getNativeHandle() != sf::WindowHandle());
Expand Down

0 comments on commit e3c33de

Please sign in to comment.