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
@ -52,24 +52,15 @@ typedef struct
|
|||||||
CSFML_API sfVideoMode sfVideoMode_GetDesktopMode();
|
CSFML_API sfVideoMode sfVideoMode_GetDesktopMode();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get a valid video mode
|
/// Get all the supported video modes for fullscreen mode.
|
||||||
/// Index must be in range [0, GetModesCount()[
|
/// Modes are sorted from best to worst.
|
||||||
/// 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);
|
CSFML_API const sfVideoMode* sfVideoMode_GetFullscreenModes(size_t* Count);
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// Get valid video modes count
|
|
||||||
///
|
|
||||||
/// \return Number of valid video modes available
|
|
||||||
///
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
CSFML_API size_t sfVideoMode_GetModesCount();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Tell whether or not a video mode is supported
|
/// Tell whether or not a video mode is supported
|
||||||
|
@ -30,7 +30,6 @@
|
|||||||
#include <SFML/Internal.h>
|
#include <SFML/Internal.h>
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get the current desktop video mode
|
/// Get the current desktop video mode
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -47,28 +46,31 @@ sfVideoMode sfVideoMode_GetDesktopMode()
|
|||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get a valid video mode
|
/// Get all the supported video modes for fullscreen mode.
|
||||||
/// Index must be in range [0, GetModesCount()[
|
/// Modes are sorted from best to worst.
|
||||||
/// 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);
|
static std::vector<sfVideoMode> modes;
|
||||||
sfVideoMode ret;
|
|
||||||
ret.Width = mode.Width;
|
|
||||||
ret.Height = mode.Height;
|
|
||||||
ret.BitsPerPixel = mode.BitsPerPixel;
|
|
||||||
|
|
||||||
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();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
return !modes.empty() ? &modes[0] : NULL;
|
||||||
/// Get valid video modes count
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
size_t sfVideoMode_GetModesCount()
|
|
||||||
{
|
|
||||||
return sf::VideoMode::GetModesCount();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@ -7,8 +7,7 @@ EXPORTS
|
|||||||
sfInput_GetMouseY
|
sfInput_GetMouseY
|
||||||
sfInput_GetJoystickAxis
|
sfInput_GetJoystickAxis
|
||||||
sfVideoMode_GetDesktopMode
|
sfVideoMode_GetDesktopMode
|
||||||
sfVideoMode_GetMode
|
sfVideoMode_GetFullscreenModes
|
||||||
sfVideoMode_GetModesCount
|
|
||||||
sfVideoMode_IsValid
|
sfVideoMode_IsValid
|
||||||
sfWindow_Create
|
sfWindow_Create
|
||||||
sfWindow_CreateFromHandle
|
sfWindow_CreateFromHandle
|
||||||
|
@ -7,8 +7,7 @@ EXPORTS
|
|||||||
sfInput_GetMouseY
|
sfInput_GetMouseY
|
||||||
sfInput_GetJoystickAxis
|
sfInput_GetJoystickAxis
|
||||||
sfVideoMode_GetDesktopMode
|
sfVideoMode_GetDesktopMode
|
||||||
sfVideoMode_GetMode
|
sfVideoMode_GetFullscreenModes
|
||||||
sfVideoMode_GetModesCount
|
|
||||||
sfVideoMode_IsValid
|
sfVideoMode_IsValid
|
||||||
sfWindow_Create
|
sfWindow_Create
|
||||||
sfWindow_CreateFromHandle
|
sfWindow_CreateFromHandle
|
||||||
|
@ -124,13 +124,12 @@
|
|||||||
<Unit filename="..\..\src\SFML\Window\Input.cpp" />
|
<Unit filename="..\..\src\SFML\Window\Input.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Joystick.hpp" />
|
<Unit filename="..\..\src\SFML\Window\Joystick.hpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\VideoMode.cpp" />
|
<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.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Win32\ContextWGL.hpp" />
|
<Unit filename="..\..\src\SFML\Window\Win32\ContextWGL.hpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.cpp" />
|
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.hpp" />
|
<Unit filename="..\..\src\SFML\Window\Win32\Joystick.hpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp" />
|
<Unit filename="..\..\src\SFML\Window\Win32\VideoModeImpl.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Win32\VideoModeSupport.hpp" />
|
|
||||||
<Unit filename="..\..\src\SFML\Window\Win32\WindowImplWin32.cpp" />
|
<Unit filename="..\..\src\SFML\Window\Win32\WindowImplWin32.cpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Win32\WindowImplWin32.hpp" />
|
<Unit filename="..\..\src\SFML\Window\Win32\WindowImplWin32.hpp" />
|
||||||
<Unit filename="..\..\src\SFML\Window\Window.cpp" />
|
<Unit filename="..\..\src\SFML\Window\Window.cpp" />
|
||||||
|
@ -400,11 +400,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp"
|
RelativePath="..\..\src\SFML\Window\Win32\VideoModeImpl.cpp"
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.hpp"
|
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -493,7 +489,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\VideoModeSupport.hpp"
|
RelativePath="..\..\src\SFML\Window\VideoModeImpl.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
@ -363,11 +363,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.cpp"
|
RelativePath="..\..\src\SFML\Window\Win32\VideoModeImpl.cpp"
|
||||||
>
|
|
||||||
</File>
|
|
||||||
<File
|
|
||||||
RelativePath="..\..\src\SFML\Window\Win32\VideoModeSupport.hpp"
|
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
@ -456,7 +452,7 @@
|
|||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
RelativePath="..\..\src\SFML\Window\VideoModeSupport.hpp"
|
RelativePath="..\..\src\SFML\Window\VideoModeImpl.hpp"
|
||||||
>
|
>
|
||||||
</File>
|
</File>
|
||||||
<File
|
<File
|
||||||
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
@ -56,26 +56,24 @@ namespace SFML
|
|||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Get the number of valid video modes
|
/// Get the list of all the supported fullscreen video modes
|
||||||
/// </summary>
|
/// </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];
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
return Modes;
|
||||||
/// <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);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
@ -116,10 +114,7 @@ namespace SFML
|
|||||||
static extern VideoMode sfVideoMode_GetDesktopMode();
|
static extern VideoMode sfVideoMode_GetDesktopMode();
|
||||||
|
|
||||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||||
static extern uint sfVideoMode_GetModesCount();
|
unsafe static extern VideoMode* sfVideoMode_GetFullscreenModes(out uint Count);
|
||||||
|
|
||||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
|
||||||
static extern VideoMode sfVideoMode_GetMode(uint Index);
|
|
||||||
|
|
||||||
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
[DllImport("csfml-window"), SuppressUnmanagedCodeSecurity]
|
||||||
static extern bool sfVideoMode_IsValid(VideoMode Mode);
|
static extern bool sfVideoMode_IsValid(VideoMode Mode);
|
||||||
|
@ -29,7 +29,7 @@
|
|||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Config.hpp>
|
#include <SFML/Config.hpp>
|
||||||
#include <cstdlib>
|
#include <vector>
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
@ -69,30 +69,20 @@ public :
|
|||||||
static VideoMode GetDesktopMode();
|
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()[.
|
/// When creating a fullscreen window, the video mode is restricted
|
||||||
/// Modes are sorted from best to worst, so that
|
/// to be compatible with what the graphics driver and monitor
|
||||||
/// sf::VideoMode::GetMode(0) will always give the best.
|
/// 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 Array containing all the supported fullscreen modes
|
||||||
///
|
|
||||||
/// \return Corresponding video mode (invalid mode if index is out of range)
|
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static VideoMode GetMode(std::size_t index);
|
static const std::vector<VideoMode>& GetFullscreenModes();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// \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();
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// \brief Tell whether or not the video mode is valid
|
/// \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,
|
/// \param left Left operand (a video mode)
|
||||||
/// i.e. it checks if all their members are equal.
|
/// \param right Right operand (a video mode)
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
///
|
||||||
/// \return True if modes are equal
|
/// \return True if modes are equal
|
||||||
///
|
///
|
||||||
@ -129,19 +116,60 @@ public :
|
|||||||
SFML_API bool operator ==(const VideoMode& left, const VideoMode& right);
|
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,
|
/// \param left Left operand (a video mode)
|
||||||
/// i.e. it checks if not all their members are equal.
|
/// \param right Right operand (a video mode)
|
||||||
///
|
|
||||||
/// \param left Left operand
|
|
||||||
/// \param right Right operand
|
|
||||||
///
|
///
|
||||||
/// \return True if modes are different
|
/// \return True if modes are different
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
SFML_API bool operator !=(const VideoMode& left, const VideoMode& 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 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
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
@ -161,14 +189,12 @@ SFML_API bool operator !=(const VideoMode& left, const VideoMode& right);
|
|||||||
/// and the graphics card support), otherwise your window
|
/// and the graphics card support), otherwise your window
|
||||||
/// creation will just fail.
|
/// 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:
|
/// the list of all the video modes supported by the system:
|
||||||
/// GetModesCount() to get the number of video modes in the
|
/// GetFullscreenModes().
|
||||||
/// list, and GetMode() to retrieve a particular mode
|
|
||||||
/// from the list.
|
|
||||||
///
|
///
|
||||||
/// A custom video mode can also be checked directly with
|
/// A custom video mode can also be checked directly for
|
||||||
/// its IsValid() function.
|
/// fullscreen compatibility with its IsValid() function.
|
||||||
///
|
///
|
||||||
/// Additionnally, sf::VideoMode provides a static function
|
/// Additionnally, sf::VideoMode provides a static function
|
||||||
/// to get the mode currently used by the desktop: GetDesktopMode().
|
/// 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:
|
/// Usage example:
|
||||||
/// \code
|
/// \code
|
||||||
/// // Display the list of all the video modes available for fullscreen
|
/// // 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 << ": "
|
/// std::cout << "Mode #" << i << ": "
|
||||||
/// << mode.Width << "x" << mode.Height << " - "
|
/// << mode.Width << "x" << mode.Height << " - "
|
||||||
/// << mode.BitsPerPixel << " bpp" << std::endl;
|
/// << mode.BitsPerPixel << " bpp" << std::endl;
|
||||||
|
@ -25,7 +25,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/Cocoa/VideoModeSupport.hpp>
|
#include <SFML/Window/VideoModeImpl.hpp>
|
||||||
#include <ApplicationServices/ApplicationServices.h>
|
#include <ApplicationServices/ApplicationServices.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
@ -25,7 +25,7 @@
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/Linux/VideoModeSupport.hpp>
|
#include <SFML/Window/VideoModeImpl.hpp>
|
||||||
#include <SFML/System/Err.hpp>
|
#include <SFML/System/Err.hpp>
|
||||||
#include <X11/Xlib.h>
|
#include <X11/Xlib.h>
|
||||||
#include <X11/extensions/Xrandr.h>
|
#include <X11/extensions/Xrandr.h>
|
||||||
@ -37,10 +37,9 @@ namespace sf
|
|||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
|
||||||
{
|
{
|
||||||
// First, clear array to fill
|
std::vector<VideoMode> modes;
|
||||||
modes.clear();
|
|
||||||
|
|
||||||
// Open a connection with the X server
|
// Open a connection with the X server
|
||||||
Display* disp = XOpenDisplay(NULL);
|
Display* disp = XOpenDisplay(NULL);
|
||||||
@ -106,11 +105,13 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
|||||||
// We couldn't connect to the X server
|
// 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;
|
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;
|
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
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/VideoMode.hpp>
|
#include <SFML/Window/VideoMode.hpp>
|
||||||
#include <SFML/Window/VideoModeSupport.hpp>
|
#include <SFML/Window/VideoModeImpl.hpp>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
#include <vector>
|
#include <functional>
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
/// 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());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
@ -94,44 +56,33 @@ BitsPerPixel(bitsPerPixel)
|
|||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
VideoMode VideoMode::GetDesktopMode()
|
VideoMode VideoMode::GetDesktopMode()
|
||||||
{
|
{
|
||||||
// Directly forward to the video mode support
|
// Directly forward to the OS-specific implementation
|
||||||
return priv::VideoModeSupport::GetDesktopVideoMode();
|
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
|
static std::vector<VideoMode> modes;
|
||||||
if (supportedModes.empty())
|
|
||||||
InitializeModes();
|
|
||||||
|
|
||||||
if (index < GetModesCount())
|
// Populate the array on first call
|
||||||
return supportedModes[index];
|
if (modes.empty())
|
||||||
else
|
{
|
||||||
return VideoMode();
|
modes = priv::VideoModeImpl::GetFullscreenModes();
|
||||||
}
|
std::sort(modes.begin(), modes.end(), std::greater<VideoMode>());
|
||||||
|
}
|
||||||
|
|
||||||
|
return modes;
|
||||||
////////////////////////////////////////////////////////////
|
|
||||||
std::size_t VideoMode::GetModesCount()
|
|
||||||
{
|
|
||||||
// Build and cache the list of valid modes on first call
|
|
||||||
if (supportedModes.empty())
|
|
||||||
InitializeModes();
|
|
||||||
|
|
||||||
return supportedModes.size();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
bool VideoMode::IsValid() const
|
bool VideoMode::IsValid() const
|
||||||
{
|
{
|
||||||
// Build and cache the list of valid modes on first call
|
const std::vector<VideoMode>& modes = GetFullscreenModes();
|
||||||
if (supportedModes.empty())
|
|
||||||
InitializeModes();
|
|
||||||
|
|
||||||
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);
|
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
|
} // namespace sf
|
||||||
|
@ -22,14 +22,13 @@
|
|||||||
//
|
//
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
|
|
||||||
#ifndef SFML_VIDEOMODESUPPORTCOCOA_HPP
|
#ifndef SFML_VIDEOMODEIMPL_HPP
|
||||||
#define SFML_VIDEOMODESUPPORTCOCOA_HPP
|
#define SFML_VIDEOMODEIMPL_HPP
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
// Headers
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/VideoMode.hpp>
|
#include <SFML/Window/VideoMode.hpp>
|
||||||
#include <vector>
|
|
||||||
|
|
||||||
|
|
||||||
namespace sf
|
namespace sf
|
||||||
@ -37,28 +36,28 @@ namespace sf
|
|||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Cocoa implementation of VideoModeSupport
|
/// \brief OS-specific implementation of video modes functions
|
||||||
/// Give access to video mode related OS-specific functions
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
class VideoModeSupport
|
class VideoModeImpl
|
||||||
{
|
{
|
||||||
public :
|
public :
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get supported video modes
|
/// \brief Get the list of all the supported fullscreen video modes
|
||||||
///
|
///
|
||||||
/// \param Modes : Array to fill with available video modes
|
/// \return Array filled with the fullscreen video modes
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static void GetSupportedVideoModes(std::vector<VideoMode>& Modes);
|
static std::vector<VideoMode> GetFullscreenModes();
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
/// Get current desktop video mode
|
/// \brief Get the current desktop video mode
|
||||||
///
|
///
|
||||||
/// \return Current desktop video mode
|
/// \return Current desktop video mode
|
||||||
///
|
///
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
static VideoMode GetDesktopVideoMode();
|
static VideoMode GetDesktopMode();
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace priv
|
} // namespace priv
|
||||||
@ -66,4 +65,4 @@ public :
|
|||||||
} // namespace sf
|
} // namespace sf
|
||||||
|
|
||||||
|
|
||||||
#endif // SFML_VIDEOMODESUPPORTCOCOA_HPP
|
#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
|
// Headers
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
#include <SFML/Window/Win32/VideoModeSupport.hpp>
|
#include <SFML/Window/VideoModeImpl.hpp>
|
||||||
#include <windows.h>
|
#include <windows.h>
|
||||||
#include <algorithm>
|
#include <algorithm>
|
||||||
|
|
||||||
@ -35,10 +35,9 @@ namespace sf
|
|||||||
namespace priv
|
namespace priv
|
||||||
{
|
{
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
std::vector<VideoMode> VideoModeImpl::GetFullscreenModes()
|
||||||
{
|
{
|
||||||
// First, clear array to fill
|
std::vector<VideoMode> modes;
|
||||||
modes.clear();
|
|
||||||
|
|
||||||
// Enumerate all available video modes for the primary display adapter
|
// Enumerate all available video modes for the primary display adapter
|
||||||
DEVMODE win32Mode;
|
DEVMODE win32Mode;
|
||||||
@ -52,11 +51,13 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector<VideoMode>& modes)
|
|||||||
if (std::find(modes.begin(), modes.end(), mode) == modes.end())
|
if (std::find(modes.begin(), modes.end(), mode) == modes.end())
|
||||||
modes.push_back(mode);
|
modes.push_back(mode);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return modes;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
////////////////////////////////////////////////////////////
|
////////////////////////////////////////////////////////////
|
||||||
VideoMode VideoModeSupport::GetDesktopVideoMode()
|
VideoMode VideoModeImpl::GetDesktopMode()
|
||||||
{
|
{
|
||||||
DEVMODE win32Mode;
|
DEVMODE win32Mode;
|
||||||
win32Mode.dmSize = sizeof(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
|
else
|
||||||
{
|
{
|
||||||
// Make sure the chosen video mode is compatible
|
// Make sure that the chosen video mode is compatible
|
||||||
if (!mode.IsValid())
|
if (!mode.IsValid())
|
||||||
{
|
{
|
||||||
Err() << "The requested video mode is not available, switching to a valid mode" << std::endl;
|
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
|
// Update the fullscreen window
|
||||||
|
Loading…
x
Reference in New Issue
Block a user