Added a high-level check to disallow having two fullscreen windows at the same time

git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/trunk@1042 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
laurentgom 2009-03-06 18:11:10 +00:00
parent 2c7c76a668
commit 06b5299c2b
4 changed files with 37 additions and 9 deletions

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -32,11 +32,19 @@
#include <iostream> #include <iostream>
////////////////////////////////////////////////////////////
// Private data
////////////////////////////////////////////////////////////
namespace
{
const sf::Window* FullscreenWindow = NULL;
}
namespace sf namespace sf
{ {
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
/// Default constructor /// Default constructor
///
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
Window::Window() : Window::Window() :
myWindow (NULL), myWindow (NULL),
@ -95,20 +103,36 @@ Window::~Window()
//////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////
void Window::Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, const WindowSettings& Params) void Window::Create(VideoMode Mode, const std::string& Title, unsigned long WindowStyle, const WindowSettings& Params)
{ {
// Check validity of video mode // Destroy the previous window implementation
if ((WindowStyle & Style::Fullscreen) && !Mode.IsValid()) Close();
// Fullscreen style requires some tests
if (WindowStyle & Style::Fullscreen)
{ {
std::cerr << "The requested video mode is not available, switching to a valid mode" << std::endl; // Make sure there's not already a fullscreen window (only one is allowed)
Mode = VideoMode::GetMode(0); if (FullscreenWindow)
{
std::cerr << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl;
WindowStyle &= ~Style::Fullscreen;
}
else
{
// Make sure the chosen video mode is compatible
if (!Mode.IsValid())
{
std::cerr << "The requested video mode is not available, switching to a valid mode" << std::endl;
Mode = VideoMode::GetMode(0);
}
// Update the fullscreen window
FullscreenWindow = this;
}
} }
// Check validity of style // Check validity of style
if ((WindowStyle & Style::Close) || (WindowStyle & Style::Resize)) if ((WindowStyle & Style::Close) || (WindowStyle & Style::Resize))
WindowStyle |= Style::Titlebar; WindowStyle |= Style::Titlebar;
// Destroy the previous window implementation
delete myWindow;
// Activate the global context // Activate the global context
Context::GetGlobal().SetActive(true); Context::GetGlobal().SetActive(true);
@ -123,7 +147,7 @@ void Window::Create(VideoMode Mode, const std::string& Title, unsigned long Wind
void Window::Create(WindowHandle Handle, const WindowSettings& Params) void Window::Create(WindowHandle Handle, const WindowSettings& Params)
{ {
// Destroy the previous window implementation // Destroy the previous window implementation
delete myWindow; Close();
// Activate the global context // Activate the global context
Context::GetGlobal().SetActive(true); Context::GetGlobal().SetActive(true);
@ -143,6 +167,10 @@ void Window::Close()
// Delete the window implementation // Delete the window implementation
delete myWindow; delete myWindow;
myWindow = NULL; myWindow = NULL;
// Update the fullscreen window
if (this == FullscreenWindow)
FullscreenWindow = NULL;
} }