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:
LaurentGom 2010-03-12 14:07:28 +00:00
parent e924c9cf39
commit 809b09292f
21 changed files with 256 additions and 446 deletions

View File

@ -52,24 +52,15 @@ typedef struct
CSFML_API sfVideoMode sfVideoMode_GetDesktopMode();
////////////////////////////////////////////////////////////
/// Get a valid video mode
/// Index must be in range [0, GetModesCount()[
/// Modes are sorted from best to worst
/// Get all the supported video modes for fullscreen mode.
/// Modes are sorted from best to worst.
///
/// \param index : Index of video mode to get
/// \param Count : Variable that will be filled with the number of modes
///
/// \return Corresponding video mode (invalid mode if index is out of range)
/// \return Pointer to an array of \a count video modes
///
////////////////////////////////////////////////////////////
CSFML_API sfVideoMode sfVideoMode_GetMode(size_t index);
////////////////////////////////////////////////////////////
/// Get valid video modes count
///
/// \return Number of valid video modes available
///
////////////////////////////////////////////////////////////
CSFML_API size_t sfVideoMode_GetModesCount();
CSFML_API const sfVideoMode* sfVideoMode_GetFullscreenModes(size_t* Count);
////////////////////////////////////////////////////////////
/// Tell whether or not a video mode is supported

View File

@ -30,7 +30,6 @@
#include <SFML/Internal.h>
////////////////////////////////////////////////////////////
/// Get the current desktop video mode
////////////////////////////////////////////////////////////
@ -47,28 +46,31 @@ sfVideoMode sfVideoMode_GetDesktopMode()
////////////////////////////////////////////////////////////
/// Get a valid video mode
/// Index must be in range [0, GetModesCount()[
/// Modes are sorted from best to worst
/// Get all the supported video modes for fullscreen mode.
/// Modes are sorted from best to worst.
////////////////////////////////////////////////////////////
sfVideoMode sfVideoMode_GetMode(size_t index)
const sfVideoMode* sfVideoMode_GetFullscreenModes(size_t* Count)
{
sf::VideoMode mode = sf::VideoMode::GetMode(index);
sfVideoMode ret;
ret.Width = mode.Width;
ret.Height = mode.Height;
ret.BitsPerPixel = mode.BitsPerPixel;
static std::vector<sfVideoMode> modes;
return ret;
}
// Populate the array on first call
if (modes.empty())
{
const std::vector<sf::VideoMode>& SFMLModes = sf::VideoMode::GetFullscreenModes();
for (std::vector<sf::VideoMode>::const_iterator it = SFMLModes.begin(); it != SFMLModes.end(); ++it)
{
sfVideoMode mode;
mode.Width = it->Width;
mode.Height = it->Height;
mode.BitsPerPixel = it->BitsPerPixel;
modes.push_back(mode);
}
}
if (Count)
*Count = modes.size();
////////////////////////////////////////////////////////////
/// Get valid video modes count
////////////////////////////////////////////////////////////
size_t sfVideoMode_GetModesCount()
{
return sf::VideoMode::GetModesCount();
return !modes.empty() ? &modes[0] : NULL;
}

View File

@ -7,8 +7,7 @@ EXPORTS
sfInput_GetMouseY
sfInput_GetJoystickAxis
sfVideoMode_GetDesktopMode
sfVideoMode_GetMode
sfVideoMode_GetModesCount
sfVideoMode_GetFullscreenModes
sfVideoMode_IsValid
sfWindow_Create
sfWindow_CreateFromHandle

View File

@ -7,8 +7,7 @@ EXPORTS
sfInput_GetMouseY
sfInput_GetJoystickAxis
sfVideoMode_GetDesktopMode
sfVideoMode_GetMode
sfVideoMode_GetModesCount
sfVideoMode_GetFullscreenModes
sfVideoMode_IsValid
sfWindow_Create
sfWindow_CreateFromHandle

View File

@ -124,13 +124,12 @@
<Unit filename="..\..\src\SFML\Window\Input.cpp" />
<Unit filename="..\..\src\SFML\Window\Joystick.hpp" />
<Unit filename="..\..\src\SFML\Window\VideoMode.cpp" />
<Unit filename="..\..\src\SFML\Window\VideoModeSupport.hpp" />
<Unit filename="..\..\src\SFML\Window\VideoModeImpl.hpp" />
<Unit filename="..\..\src\SFML\Window\Win32\ContextWGL.cpp" />
<Unit filename="..\..\src\SFML\Window\Win32\ContextWGL.hpp" />
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.cpp" />
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.hpp" />
<Unit filename="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp" />
<Unit filename="..\..\src\SFML\Window\Win32\VideoModeSupport.hpp" />
<Unit filename="..\..\src\SFML\Window\Win32\VideoModeImpl.cpp" />
<Unit filename="..\..\src\SFML\Window\Win32\WindowImplWin32.cpp" />
<Unit filename="..\..\src\SFML\Window\Win32\WindowImplWin32.hpp" />
<Unit filename="..\..\src\SFML\Window\Window.cpp" />

View File

@ -400,11 +400,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp"
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.hpp"
RelativePath="..\..\src\SFML\Window\Win32\VideoModeImpl.cpp"
>
</File>
<File
@ -493,7 +489,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\VideoModeSupport.hpp"
RelativePath="..\..\src\SFML\Window\VideoModeImpl.hpp"
>
</File>
<File

View File

@ -363,11 +363,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp"
>
</File>
<File
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.hpp"
RelativePath="..\..\src\SFML\Window\Win32\VideoModeImpl.cpp"
>
</File>
<File
@ -456,7 +452,7 @@
>
</File>
<File
RelativePath="..\..\src\SFML\Window\VideoModeSupport.hpp"
RelativePath="..\..\src\SFML\Window\VideoModeImpl.hpp"
>
</File>
<File

Binary file not shown.

Binary file not shown.

Binary file not shown.

View File

@ -56,26 +56,24 @@ namespace SFML
////////////////////////////////////////////////////////////
/// <summary>
/// Get the number of valid video modes
/// Get the list of all the supported fullscreen video modes
/// </summary>
////////////////////////////////////////////////////////////
public static uint ModesCount
public static VideoMode[] FullscreenModes
{
get {return sfVideoMode_GetModesCount();}
}
get
{
unsafe
{
uint Count;
VideoMode* ModesPtr = sfVideoMode_GetFullscreenModes(out Count);
VideoMode[] Modes = new VideoMode[Count];
for (uint i = 0; i < Count; ++i)
Modes[i] = ModesPtr[i];
////////////////////////////////////////////////////////////
/// <summary>
/// Get a valid video mode.
/// Index must be in range [0, ModesCount[.
/// Modes are sorted from best to worst
/// </summary>
/// <param name="index">Index of the video mode to get</param>
/// <returns>index-th video mode</returns>
////////////////////////////////////////////////////////////
public static VideoMode GetMode(uint index)
{
return sfVideoMode_GetMode(index);
return Modes;
}
}
}
////////////////////////////////////////////////////////////
@ -116,10 +114,7 @@ namespace SFML
static extern VideoMode sfVideoMode_GetDesktopMode();
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern uint sfVideoMode_GetModesCount();
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern VideoMode sfVideoMode_GetMode(uint Index);
unsafe static extern VideoMode* sfVideoMode_GetFullscreenModes(out uint Count);
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
static extern bool sfVideoMode_IsValid(VideoMode Mode);

View File

@ -29,7 +29,7 @@
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Config.hpp>
#include <cstdlib>
#include <vector>
namespace sf
@ -69,30 +69,20 @@ public :
static VideoMode GetDesktopMode();
////////////////////////////////////////////////////////////
/// \brief Get a valid video mode
/// \brief Retrieve all the video modes supported in fullscreen mode
///
/// The parameter \a index must be in the range [0, GetModesCount()[.
/// Modes are sorted from best to worst, so that
/// sf::VideoMode::GetMode(0) will always give the best.
/// When creating a fullscreen window, the video mode is restricted
/// to be compatible with what the graphics driver and monitor
/// support. This function returns the complete list of all video
/// modes that can be used in fullscreen mode.
/// The returned array is sorted from best to worst, so that
/// the first element will always give the best mode (higher
/// width, height and bits-per-pixel).
///
/// \param index Index of video mode to get
///
/// \return Corresponding video mode (invalid mode if index is out of range)
/// \return Array containing all the supported fullscreen modes
///
////////////////////////////////////////////////////////////
static VideoMode GetMode(std::size_t index);
////////////////////////////////////////////////////////////
/// \brief Get the total number of valid video modes available
///
/// The validity of video modes is only relevant when using
/// fullscreen windows; otherwise any video mode can be used
/// with no restriction.
///
/// \return Number of valid video modes available for fullscreen mode
///
////////////////////////////////////////////////////////////
static std::size_t GetModesCount();
static const std::vector<VideoMode>& GetFullscreenModes();
////////////////////////////////////////////////////////////
/// \brief Tell whether or not the video mode is valid
@ -115,13 +105,10 @@ public :
};
////////////////////////////////////////////////////////////
/// \brief Overload of binary == operator
/// \brief Overload of == operator to compare two video modes
///
/// This operator compares strict equality between two modes,
/// i.e. it checks if all their members are equal.
///
/// \param left Left operand
/// \param right Right operand
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if modes are equal
///
@ -129,19 +116,60 @@ public :
SFML_API bool operator ==(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \brief Overload of binary != operator
/// \brief Overload of != operator to compare two video modes
///
/// This operator compares strict difference between two modes,
/// i.e. it checks if not all their members are equal.
///
/// \param left Left operand
/// \param right Right operand
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if modes are different
///
////////////////////////////////////////////////////////////
SFML_API bool operator !=(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \brief Overload of < operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is lesser than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator <(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \brief Overload of > operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is greater than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator >(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \brief Overload of <= operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is lesser or equal than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator <=(const VideoMode& left, const VideoMode& right);
////////////////////////////////////////////////////////////
/// \brief Overload of >= operator to compare video modes
///
/// \param left Left operand (a video mode)
/// \param right Right operand (a video mode)
///
/// \return True if \a left is greater or equal than \a right
///
////////////////////////////////////////////////////////////
SFML_API bool operator >=(const VideoMode& left, const VideoMode& right);
} // namespace sf
@ -161,14 +189,12 @@ SFML_API bool operator !=(const VideoMode& left, const VideoMode& right);
/// and the graphics card support), otherwise your window
/// creation will just fail.
///
/// sf::VideoMode provides two static functions for retrieving
/// sf::VideoMode provides a static function for retrieving
/// the list of all the video modes supported by the system:
/// GetModesCount() to get the number of video modes in the
/// list, and GetMode() to retrieve a particular mode
/// from the list.
/// GetFullscreenModes().
///
/// A custom video mode can also be checked directly with
/// its IsValid() function.
/// A custom video mode can also be checked directly for
/// fullscreen compatibility with its IsValid() function.
///
/// Additionnally, sf::VideoMode provides a static function
/// to get the mode currently used by the desktop: GetDesktopMode().
@ -178,9 +204,10 @@ SFML_API bool operator !=(const VideoMode& left, const VideoMode& right);
/// Usage example:
/// \code
/// // Display the list of all the video modes available for fullscreen
/// for (std::size_t i = 0; i < sf::VideoMode::GetModesCount(); ++i)
/// std::vector<sf::VideoMode> modes = sf::VideoMode::GetFullscreenModes();
/// for (std::size_t i = 0; i < modes.size(); ++i)
/// {
/// sf::VideoMode mode = sf::VideoMode::GetMode(i);
/// sf::VideoMode mode = modes[i];
/// std::cout << "Mode #" << i << ": "
/// << mode.Width << "x" << mode.Height << " - "
/// << mode.BitsPerPixel << " bpp" << std::endl;

View File

@ -25,7 +25,7 @@
////////////////////////////////////////////////////////////
// Headers
////////////////////////////////////////////////////////////
#include <SFML/Window/Cocoa/VideoModeSupport.hpp>
#include <SFML/Window/VideoModeImpl.hpp>
#include <ApplicationServices/ApplicationServices.h>
#include <algorithm>

View File

@ -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;

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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

View File

@ -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);

View File

@ -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

View File

@ -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