diff --git a/include/SFML/Window/WindowBase.hpp b/include/SFML/Window/WindowBase.hpp index 132e13b41..bffc9012e 100644 --- a/include/SFML/Window/WindowBase.hpp +++ b/include/SFML/Window/WindowBase.hpp @@ -463,6 +463,18 @@ protected: private: friend class Window; + //////////////////////////////////////////////////////////// + /// \brief Create (or recreate) the window + /// + /// Implementation detail for sharing underlying implementation + /// with sf::Window + /// + /// \param mode Video mode to use (defines the width, height and depth of the rendering area of the window) + /// \param style %Window style, a bitwise OR combination of sf::Style enumerators + /// + //////////////////////////////////////////////////////////// + void create(VideoMode mode, std::uint32_t& style); + //////////////////////////////////////////////////////////// /// \brief Processes an event before it is sent to the user /// diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 81f987fb8..0b7121e19 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -74,45 +74,8 @@ void Window::create(VideoMode mode, const String& title, std::uint32_t style) //////////////////////////////////////////////////////////// void Window::create(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings) { - // Destroy the previous window implementation - close(); - - // Fullscreen style requires some tests - if (style & Style::Fullscreen) - { - // Make sure there's not already a fullscreen window (only one is allowed) - if (getFullscreenWindow()) - { - err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; - style &= ~static_cast(Style::Fullscreen); - } - else - { - // Make sure that the chosen video mode is compatible - if (!mode.isValid()) - { - err() << "The requested video mode is not available, switching to a valid mode" << std::endl; - assert(!VideoMode::getFullscreenModes().empty() && "No video modes available"); - mode = VideoMode::getFullscreenModes()[0]; - err() << " VideoMode: { size: { " << mode.size.x << ", " << mode.size.y - << " }, bitsPerPixel: " << mode.bitsPerPixel << " }" << std::endl; - } - - // Update the fullscreen window - setFullscreenWindow(this); - } - } - -// Check validity of style according to the underlying platform -#if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID) - if (style & Style::Fullscreen) - style &= ~static_cast(Style::Titlebar); - else - style |= Style::Titlebar; -#else - if ((style & Style::Close) || (style & Style::Resize)) - style |= Style::Titlebar; -#endif + // Delegate to base class for creation logic + WindowBase::create(mode, style); // Recreate the window implementation m_impl = priv::WindowImpl::create(mode, title, style, settings); diff --git a/src/SFML/Window/WindowBase.cpp b/src/SFML/Window/WindowBase.cpp index 9d6e8e73e..775daa936 100644 --- a/src/SFML/Window/WindowBase.cpp +++ b/src/SFML/Window/WindowBase.cpp @@ -78,45 +78,7 @@ WindowBase::~WindowBase() //////////////////////////////////////////////////////////// void WindowBase::create(VideoMode mode, const String& title, std::uint32_t style) { - // Destroy the previous window implementation - close(); - - // Fullscreen style requires some tests - if (style & Style::Fullscreen) - { - // Make sure there's not already a fullscreen window (only one is allowed) - if (getFullscreenWindow()) - { - err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; - style &= ~static_cast(Style::Fullscreen); - } - else - { - // Make sure that the chosen video mode is compatible - if (!mode.isValid()) - { - err() << "The requested video mode is not available, switching to a valid mode" << std::endl; - assert(!VideoMode::getFullscreenModes().empty() && "No video modes available"); - mode = VideoMode::getFullscreenModes()[0]; - err() << " VideoMode: { size: { " << mode.size.x << ", " << mode.size.y - << " }, bitsPerPixel: " << mode.bitsPerPixel << " }" << std::endl; - } - - // Update the fullscreen window - setFullscreenWindow(this); - } - } - -// Check validity of style according to the underlying platform -#if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID) - if (style & Style::Fullscreen) - style &= ~static_cast(Style::Titlebar); - else - style |= Style::Titlebar; -#else - if ((style & Style::Close) || (style & Style::Resize)) - style |= Style::Titlebar; -#endif + WindowBase::create(mode, style); // Recreate the window implementation m_impl = priv::WindowImpl::create(mode, title, style, ContextSettings(0, 0, 0, 0, 0, 0xFFFFFFFF, false)); @@ -384,6 +346,51 @@ void WindowBase::onResize() } +//////////////////////////////////////////////////////////// +void WindowBase::create(VideoMode mode, std::uint32_t& style) +{ + // Destroy the previous window implementation + close(); + + // Fullscreen style requires some tests + if (style & Style::Fullscreen) + { + // Make sure there's not already a fullscreen window (only one is allowed) + if (getFullscreenWindow()) + { + err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; + style &= ~static_cast(Style::Fullscreen); + } + else + { + // Make sure that the chosen video mode is compatible + if (!mode.isValid()) + { + err() << "The requested video mode is not available, switching to a valid mode" << std::endl; + assert(!VideoMode::getFullscreenModes().empty() && "No video modes available"); + mode = VideoMode::getFullscreenModes()[0]; + err() << " VideoMode: { size: { " << mode.size.x << ", " << mode.size.y + << " }, bitsPerPixel: " << mode.bitsPerPixel << " }" << std::endl; + } + + // Update the fullscreen window + setFullscreenWindow(this); + } + } + +// Check validity of style according to the underlying platform +#if defined(SFML_SYSTEM_IOS) || defined(SFML_SYSTEM_ANDROID) + if (style & Style::Fullscreen) + style &= ~static_cast(Style::Titlebar); + else + style |= Style::Titlebar; +#else + if ((style & Style::Close) || (style & Style::Resize)) + style |= Style::Titlebar; +#endif +} + + //////////////////////////////////////////////////////////// void WindowBase::filterEvent(const Event& event) {