Merged VideoMode::GetMode and VideoMode::GetModesCount into a single new function VideoMode::GetFullscreenModes
git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1453 4e206d99-4929-0410-ac5d-dfc041789085
This commit is contained in:
parent
e924c9cf39
commit
809b09292f
21 changed files with 256 additions and 446 deletions
|
@ -25,7 +25,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Cocoa/VideoModeSupport.hpp>
|
||||
#include <SFML/Window/VideoModeImpl.hpp>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
#include <algorithm>
|
||||
|
|
@ -25,7 +25,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Linux/VideoModeSupport.hpp>
|
||||
#include <SFML/Window/VideoModeImpl.hpp>
|
||||
#include <SFML/System/Err.hpp>
|
||||
#include <X11/Xlib.h>
|
||||
#include <X11/extensions/Xrandr.h>
|
||||
|
@ -37,10 +37,9 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
||||
std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
|
||||
{
|
||||
// First, clear array to fill
|
||||
modes.clear();
|
||||
std::vector<VideoMode> modes;
|
||||
|
||||
// Open a connection with the X server
|
||||
Display* disp = XOpenDisplay(NULL);
|
||||
|
@ -106,11 +105,13 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
|||
// We couldn't connect to the X server
|
||||
Err() << "Failed to connect to the X server while trying to get the supported video modes" << std::endl;
|
||||
}
|
||||
|
||||
return modes;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
VideoMode VideoModeSupport::GetDesktopVideoMode()
|
||||
VideoMode VideoModeImpl::GetDesktopMode()
|
||||
{
|
||||
VideoMode desktopMode;
|
||||
|
|
@ -1,69 +0,0 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_VIDEOMODESUPPORTLINUX_HPP
|
||||
#define SFML_VIDEOMODESUPPORTLINUX_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Linux (X11) implementation of VideoModeSupport;
|
||||
/// gives access to video mode related OS-specific functions
|
||||
////////////////////////////////////////////////////////////
|
||||
class VideoModeSupport
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the list of all the supported video modes
|
||||
///
|
||||
/// \param modes Array to fill with available video modes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void GetSupportedVideoModes(std::vector<VideoMode>& modes);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current desktop video mode
|
||||
///
|
||||
/// \return Current desktop video mode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static VideoMode GetDesktopVideoMode();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VIDEOMODESUPPORTLINUX_HPP
|
|
@ -26,47 +26,9 @@
|
|||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <SFML/Window/VideoModeSupport.hpp>
|
||||
#include <SFML/Window/VideoModeImpl.hpp>
|
||||
#include <algorithm>
|
||||
#include <vector>
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Private data
|
||||
////////////////////////////////////////////////////////////
|
||||
namespace
|
||||
{
|
||||
// Global array of supported video modes
|
||||
std::vector<sf::VideoMode> supportedModes;
|
||||
|
||||
// Functor for sorting modes from highest to lowest
|
||||
struct CompareModes
|
||||
{
|
||||
bool operator ()(const sf::VideoMode& left, const sf::VideoMode& right) const
|
||||
{
|
||||
if (left.BitsPerPixel > right.BitsPerPixel)
|
||||
return true;
|
||||
else if (left.BitsPerPixel < right.BitsPerPixel)
|
||||
return false;
|
||||
else if (left.Width > right.Width)
|
||||
return true;
|
||||
else if (left.Width < right.Width)
|
||||
return false;
|
||||
else
|
||||
return (left.Height > right.Height);
|
||||
}
|
||||
};
|
||||
|
||||
// Get and sort valid video modes
|
||||
static void InitializeModes()
|
||||
{
|
||||
// We request the array of valid modes
|
||||
sf::priv::VideoModeSupport::GetSupportedVideoModes(supportedModes);
|
||||
|
||||
// And we sort them from highest to lowest (so that number 0 is the best)
|
||||
std::sort(supportedModes.begin(), supportedModes.end(), CompareModes());
|
||||
}
|
||||
}
|
||||
#include <functional>
|
||||
|
||||
|
||||
namespace sf
|
||||
|
@ -94,44 +56,33 @@ BitsPerPixel(bitsPerPixel)
|
|||
////////////////////////////////////////////////////////////
|
||||
VideoMode VideoMode::GetDesktopMode()
|
||||
{
|
||||
// Directly forward to the video mode support
|
||||
return priv::VideoModeSupport::GetDesktopVideoMode();
|
||||
// Directly forward to the OS-specific implementation
|
||||
return priv::VideoModeImpl::GetDesktopMode();
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
VideoMode VideoMode::GetMode(std::size_t index)
|
||||
const std::vector<VideoMode>& VideoMode::GetFullscreenModes()
|
||||
{
|
||||
// Build and cache the list of valid modes on first call
|
||||
if (supportedModes.empty())
|
||||
InitializeModes();
|
||||
static std::vector<VideoMode> modes;
|
||||
|
||||
if (index < GetModesCount())
|
||||
return supportedModes[index];
|
||||
else
|
||||
return VideoMode();
|
||||
}
|
||||
// Populate the array on first call
|
||||
if (modes.empty())
|
||||
{
|
||||
modes = priv::VideoModeImpl::GetFullscreenModes();
|
||||
std::sort(modes.begin(), modes.end(), std::greater<VideoMode>());
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
std::size_t VideoMode::GetModesCount()
|
||||
{
|
||||
// Build and cache the list of valid modes on first call
|
||||
if (supportedModes.empty())
|
||||
InitializeModes();
|
||||
|
||||
return supportedModes.size();
|
||||
return modes;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool VideoMode::IsValid() const
|
||||
{
|
||||
// Build and cache the list of valid modes on first call
|
||||
if (supportedModes.empty())
|
||||
InitializeModes();
|
||||
const std::vector<VideoMode>& modes = GetFullscreenModes();
|
||||
|
||||
return std::find(supportedModes.begin(), supportedModes.end(), *this) != supportedModes.end();
|
||||
return std::find(modes.begin(), modes.end(), *this) != modes.end();
|
||||
}
|
||||
|
||||
|
||||
|
@ -150,4 +101,46 @@ bool operator !=(const VideoMode& left, const VideoMode& right)
|
|||
return !(left == right);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator <(const VideoMode& left, const VideoMode& right)
|
||||
{
|
||||
if (left.BitsPerPixel == right.BitsPerPixel)
|
||||
{
|
||||
if (left.Width == right.Width)
|
||||
{
|
||||
return left.Height < right.Height;
|
||||
}
|
||||
else
|
||||
{
|
||||
return left.Width < right.Width;
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
return left.BitsPerPixel < right.BitsPerPixel;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator >(const VideoMode& left, const VideoMode& right)
|
||||
{
|
||||
return right < left;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator <=(const VideoMode& left, const VideoMode& right)
|
||||
{
|
||||
return !(right < left);
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
bool operator >=(const VideoMode& left, const VideoMode& right)
|
||||
{
|
||||
return !(left < right);
|
||||
}
|
||||
|
||||
} // namespace sf
|
||||
|
|
|
@ -1,69 +1,68 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_VIDEOMODESUPPORTCOCOA_HPP
|
||||
#define SFML_VIDEOMODESUPPORTCOCOA_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Cocoa implementation of VideoModeSupport
|
||||
/// Give access to video mode related OS-specific functions
|
||||
////////////////////////////////////////////////////////////
|
||||
class VideoModeSupport
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get supported video modes
|
||||
///
|
||||
/// \param Modes : Array to fill with available video modes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void GetSupportedVideoModes(std::vector<VideoMode>& Modes);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// Get current desktop video mode
|
||||
///
|
||||
/// \return Current desktop video mode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static VideoMode GetDesktopVideoMode();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VIDEOMODESUPPORTCOCOA_HPP
|
||||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_VIDEOMODEIMPL_HPP
|
||||
#define SFML_VIDEOMODEIMPL_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief OS-specific implementation of video modes functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class VideoModeImpl
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the list of all the supported fullscreen video modes
|
||||
///
|
||||
/// \return Array filled with the fullscreen video modes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static std::vector<VideoMode> GetFullscreenModes();
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current desktop video mode
|
||||
///
|
||||
/// \return Current desktop video mode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static VideoMode GetDesktopMode();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VIDEOMODEIMPL_HPP
|
|
@ -1,49 +0,0 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_VIDEOMODESUPPORT_HPP
|
||||
#define SFML_VIDEOMODESUPPORT_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Config.hpp>
|
||||
|
||||
|
||||
#if defined(SFML_SYSTEM_WINDOWS)
|
||||
|
||||
#include <SFML/Window/Win32/VideoModeSupport.hpp>
|
||||
|
||||
#elif defined(SFML_SYSTEM_LINUX) || defined(SFML_SYSTEM_FREEBSD)
|
||||
|
||||
#include <SFML/Window/Linux/VideoModeSupport.hpp>
|
||||
|
||||
#elif defined(SFML_SYSTEM_MACOS)
|
||||
|
||||
#include <SFML/Window/Cocoa/VideoModeSupport.hpp>
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
#endif // SFML_VIDEOMODESUPPORT_HPP
|
|
@ -25,7 +25,7 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/Win32/VideoModeSupport.hpp>
|
||||
#include <SFML/Window/VideoModeImpl.hpp>
|
||||
#include <windows.h>
|
||||
#include <algorithm>
|
||||
|
||||
|
@ -35,10 +35,9 @@ namespace sf
|
|||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
||||
std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
|
||||
{
|
||||
// First, clear array to fill
|
||||
modes.clear();
|
||||
std::vector<VideoMode> modes;
|
||||
|
||||
// Enumerate all available video modes for the primary display adapter
|
||||
DEVMODE win32Mode;
|
||||
|
@ -52,11 +51,13 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
|||
if (std::find(modes.begin(), modes.end(), mode) == modes.end())
|
||||
modes.push_back(mode);
|
||||
}
|
||||
|
||||
return modes;
|
||||
}
|
||||
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
VideoMode VideoModeSupport::GetDesktopVideoMode()
|
||||
VideoMode VideoModeImpl::GetDesktopMode()
|
||||
{
|
||||
DEVMODE win32Mode;
|
||||
win32Mode.dmSize = sizeof(win32Mode);
|
|
@ -1,70 +0,0 @@
|
|||
////////////////////////////////////////////////////////////
|
||||
//
|
||||
// SFML - Simple and Fast Multimedia Library
|
||||
// Copyright (C) 2007-2008 Laurent Gomila (laurent.gom@gmail.com)
|
||||
//
|
||||
// This software is provided 'as-is', without any express or implied warranty.
|
||||
// In no event will the authors be held liable for any damages arising from the use of this software.
|
||||
//
|
||||
// Permission is granted to anyone to use this software for any purpose,
|
||||
// including commercial applications, and to alter it and redistribute it freely,
|
||||
// subject to the following restrictions:
|
||||
//
|
||||
// 1. The origin of this software must not be misrepresented;
|
||||
// you must not claim that you wrote the original software.
|
||||
// If you use this software in a product, an acknowledgment
|
||||
// in the product documentation would be appreciated but is not required.
|
||||
//
|
||||
// 2. Altered source versions must be plainly marked as such,
|
||||
// and must not be misrepresented as being the original software.
|
||||
//
|
||||
// 3. This notice may not be removed or altered from any source distribution.
|
||||
//
|
||||
////////////////////////////////////////////////////////////
|
||||
|
||||
#ifndef SFML_VIDEOMODESUPPORTWIN32_HPP
|
||||
#define SFML_VIDEOMODESUPPORTWIN32_HPP
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
// Headers
|
||||
////////////////////////////////////////////////////////////
|
||||
#include <SFML/Window/VideoMode.hpp>
|
||||
#include <vector>
|
||||
|
||||
|
||||
namespace sf
|
||||
{
|
||||
namespace priv
|
||||
{
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Windows implementation of VideoModeSupport;
|
||||
/// gives access to video mode related OS-specific functions
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
class VideoModeSupport
|
||||
{
|
||||
public :
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the list of all the supported video modes
|
||||
///
|
||||
/// \param modes Array to fill with available video modes
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static void GetSupportedVideoModes(std::vector<VideoMode>& modes);
|
||||
|
||||
////////////////////////////////////////////////////////////
|
||||
/// \brief Get the current desktop video mode
|
||||
///
|
||||
/// \return Current desktop video mode
|
||||
///
|
||||
////////////////////////////////////////////////////////////
|
||||
static VideoMode GetDesktopVideoMode();
|
||||
};
|
||||
|
||||
} // namespace priv
|
||||
|
||||
} // namespace sf
|
||||
|
||||
|
||||
#endif // SFML_VIDEOMODESUPPORTWIN32_HPP
|
|
@ -109,11 +109,11 @@ void Window::Create(VideoMode mode, const std::string& title, unsigned long styl
|
|||
}
|
||||
else
|
||||
{
|
||||
// Make sure the chosen video mode is compatible
|
||||
// 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;
|
||||
mode = VideoMode::GetMode(0);
|
||||
mode = VideoMode::GetFullscreenModes()[0];
|
||||
}
|
||||
|
||||
// Update the fullscreen window
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue