Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 21 additions & 4 deletions examples/window/Window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,9 @@
////////////////////////////////////////////////////////////
#include <SFML/Window.hpp>

#include <array>
#include <iostream>

#include <cstdlib>

#define GLAD_GL_IMPLEMENTATION
Expand All @@ -12,10 +15,6 @@
#include <SFML/Main.hpp>
#endif

#include <array>
#include <iostream>

#include <cstdlib>

////////////////////////////////////////////////////////////
/// Entry point of application
Expand Down Expand Up @@ -151,6 +150,24 @@ int main()
window.close();
}

// Set with state with function keys
if (const auto* keyPressed = event->getIf<sf::Event::KeyPressed>())
{
switch (keyPressed->scancode)
{
case sf::Keyboard::Scancode::F1:
window.setState(sf::State::Fullscreen, sf::VideoMode::getFullscreenModes().front().size);
assert(window.getState() == sf::State::Fullscreen);
break;
case sf::Keyboard::Scancode::F2:
window.setState(sf::State::Windowed, {640, 480});
assert(window.getState() == sf::State::Windowed);
break;
default:
break;
}
}

// Resize event: adjust the viewport
if (const auto* resized = event->getIf<sf::Event::Resized>())
{
Expand Down
33 changes: 33 additions & 0 deletions include/SFML/Window/WindowBase.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -424,6 +424,39 @@ class SFML_WINDOW_API WindowBase
////////////////////////////////////////////////////////////
void setIcon(Vector2u size, const std::uint8_t* pixels);

////////////////////////////////////////////////////////////
/// \brief Set the window state
///
/// \note This function will reuse the window's current size
/// when switching modes. If this behavior is not desired then
/// use the overloaded function that accepts a different size.
///
/// \param state New state to be applied to the window
///
/// \see `setState`
///
////////////////////////////////////////////////////////////
void setState(State state);

////////////////////////////////////////////////////////////
/// \brief Set the window state with a different size
///
/// \param state New state to be applied to the window
/// \param size New window size to be applied with the new state
///
/// \see `setState`
///
////////////////////////////////////////////////////////////
void setState(State state, Vector2u size);

////////////////////////////////////////////////////////////
/// \brief Get the window's current state
///
/// \return Current state of the window
///
////////////////////////////////////////////////////////////
[[nodiscard]] State getState() const;

////////////////////////////////////////////////////////////
/// \brief Show or hide the window
///
Expand Down
22 changes: 22 additions & 0 deletions src/SFML/Window/Android/WindowImplAndroid.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,28 @@ void WindowImplAndroid::setIcon(Vector2u /* size */, const std::uint8_t* /* pixe
}


////////////////////////////////////////////////////////////
void WindowImplAndroid::setState(State /*state*/)
{
// TODO: Not implemented yet
}


////////////////////////////////////////////////////////////
void WindowImplAndroid::setState(State /*state*/, Vector2u /*size*/)
{
// TODO: Not implemented yet
}


////////////////////////////////////////////////////////////
State WindowImplAndroid::getState() const
{
const ActivityStates& states = getActivity();
return states.fullscreen ? State::Fullscreen : State::Windowed;
}


////////////////////////////////////////////////////////////
void WindowImplAndroid::setVisible(bool /* visible */)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Android/WindowImplAndroid.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,15 @@ class WindowImplAndroid : public WindowImpl
////////////////////////////////////////////////////////////
void setIcon(Vector2u size, const std::uint8_t* pixels) override;

////////////////////////////////////////////////////////////
void setState(State state) override;

////////////////////////////////////////////////////////////
void setState(State state, sf::Vector2u size) override;

////////////////////////////////////////////////////////////
[[nodiscard]] State getState() const override;

////////////////////////////////////////////////////////////
void setVisible(bool visible) override;

Expand Down
21 changes: 21 additions & 0 deletions src/SFML/Window/DRM/WindowImplDRM.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,27 @@ void WindowImplDRM::setIcon(Vector2u /*size*/, const std::uint8_t* /*pixels*/)
}


////////////////////////////////////////////////////////////
void WindowImplDRM::setState(State /*state*/)
{
// TODO: Not implemented yet
}


////////////////////////////////////////////////////////////
void WindowImplDRM::setState(State /*state*/, Vector2u /*size*/)
{
// TODO: Not implemented yet
}


////////////////////////////////////////////////////////////
State WindowImplDRM::getState() const
{
return State::Windowed;
}


////////////////////////////////////////////////////////////
void WindowImplDRM::setVisible(bool /*visible*/)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/DRM/WindowImplDRM.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,15 @@ class WindowImplDRM : public WindowImpl
////////////////////////////////////////////////////////////
void setIcon(Vector2u size, const std::uint8_t* pixels) override;

////////////////////////////////////////////////////////////
void setState(State state) override;

////////////////////////////////////////////////////////////
void setState(State state, sf::Vector2u size) override;

////////////////////////////////////////////////////////////
[[nodiscard]] State getState() const override;

////////////////////////////////////////////////////////////
void setVisible(bool visible) override;

Expand Down
21 changes: 21 additions & 0 deletions src/SFML/Window/Unix/WindowImplX11.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1192,6 +1192,27 @@ void WindowImplX11::setIcon(Vector2u size, const std::uint8_t* pixels)
}


////////////////////////////////////////////////////////////
void WindowImplX11::setState(State /*state*/)
{
// TODO: Not implemented yet
}


////////////////////////////////////////////////////////////
void WindowImplX11::setState(State /*state*/, Vector2u /*size*/)
{
// TODO: Not implemented yet
}


////////////////////////////////////////////////////////////
State WindowImplX11::getState() const
{
return m_fullscreen ? State::Fullscreen : State::Windowed;
}


////////////////////////////////////////////////////////////
void WindowImplX11::setVisible(bool visible)
{
Expand Down
9 changes: 9 additions & 0 deletions src/SFML/Window/Unix/WindowImplX11.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,15 @@ class WindowImplX11 : public WindowImpl
////////////////////////////////////////////////////////////
void setIcon(Vector2u size, const std::uint8_t* pixels) override;

////////////////////////////////////////////////////////////
void setState(State state) override;

////////////////////////////////////////////////////////////
void setState(State state, Vector2u size) override;

////////////////////////////////////////////////////////////
[[nodiscard]] State getState() const override;

////////////////////////////////////////////////////////////
void setVisible(bool visible) override;

Expand Down
Loading
Loading