mirror of
https://github.com/SFML/SFML.git
synced 2025-01-19 07:45:13 +08:00
Deduplicate Window{Base}::create
implementations
Co-authored-by: binary1248 <binary1248@hotmail.com>
This commit is contained in:
parent
f46c888e9b
commit
a9d9ef6d83
@ -463,6 +463,18 @@ protected:
|
|||||||
private:
|
private:
|
||||||
friend class Window;
|
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
|
/// \brief Processes an event before it is sent to the user
|
||||||
///
|
///
|
||||||
|
@ -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)
|
void Window::create(VideoMode mode, const String& title, std::uint32_t style, const ContextSettings& settings)
|
||||||
{
|
{
|
||||||
// Destroy the previous window implementation
|
// Delegate to base class for creation logic
|
||||||
close();
|
WindowBase::create(mode, style);
|
||||||
|
|
||||||
// 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<std::uint32_t>(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<std::uint32_t>(Style::Titlebar);
|
|
||||||
else
|
|
||||||
style |= Style::Titlebar;
|
|
||||||
#else
|
|
||||||
if ((style & Style::Close) || (style & Style::Resize))
|
|
||||||
style |= Style::Titlebar;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Recreate the window implementation
|
// Recreate the window implementation
|
||||||
m_impl = priv::WindowImpl::create(mode, title, style, settings);
|
m_impl = priv::WindowImpl::create(mode, title, style, settings);
|
||||||
|
@ -78,45 +78,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)
|
||||||
{
|
{
|
||||||
// Destroy the previous window implementation
|
WindowBase::create(mode, style);
|
||||||
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<std::uint32_t>(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<std::uint32_t>(Style::Titlebar);
|
|
||||||
else
|
|
||||||
style |= Style::Titlebar;
|
|
||||||
#else
|
|
||||||
if ((style & Style::Close) || (style & Style::Resize))
|
|
||||||
style |= Style::Titlebar;
|
|
||||||
#endif
|
|
||||||
|
|
||||||
// Recreate the window implementation
|
// Recreate the window implementation
|
||||||
m_impl = priv::WindowImpl::create(mode, title, style, ContextSettings(0, 0, 0, 0, 0, 0xFFFFFFFF, false));
|
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<std::uint32_t>(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<std::uint32_t>(Style::Titlebar);
|
||||||
|
else
|
||||||
|
style |= Style::Titlebar;
|
||||||
|
#else
|
||||||
|
if ((style & Style::Close) || (style & Style::Resize))
|
||||||
|
style |= Style::Titlebar;
|
||||||
|
#endif
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void WindowBase::filterEvent(const Event& event)
|
void WindowBase::filterEvent(const Event& event)
|
||||||
{
|
{
|
||||||
|
Loading…
Reference in New Issue
Block a user