diff --git a/include/SFML/Config.hpp b/include/SFML/Config.hpp index 05c7719ee1..2b698cf6b3 100644 --- a/include/SFML/Config.hpp +++ b/include/SFML/Config.hpp @@ -156,6 +156,23 @@ #endif +//////////////////////////////////////////////////////////// +// Cross-platform deprecation warning +//////////////////////////////////////////////////////////// +#ifdef __GNUC__ + // clang also has this defined. deprecated(message) is only for gcc >= 4.5 + #if (__GNUC__ >= 4) && (__GNUC_MINOR__ >= 5) + #define SFML_DEPRECATED(message, func) func __attribute__ ((deprecated(message))) + #else + #define SFML_DEPRECATED(message, func) func __attribute__ ((deprecated)) + #endif +#elif defined(_MSC_VER) + #define SFML_DEPRECATED(message, func) __declspec(deprecated(message)) func +#else + #warning WARNING: This compiler does not support SFML_DEPRECATED + #define SFML_DEPRECATED(message, func) func +#endif + //////////////////////////////////////////////////////////// // Define portable fixed-size types diff --git a/include/SFML/Graphics.hpp b/include/SFML/Graphics.hpp index 7a7f4da8cc..25cef8f807 100644 --- a/include/SFML/Graphics.hpp +++ b/include/SFML/Graphics.hpp @@ -39,7 +39,6 @@ #include #include #include -#include #include #include #include diff --git a/include/SFML/Graphics/Font.hpp b/include/SFML/Graphics/Font.hpp index ac6b00eb65..68a6aca68a 100644 --- a/include/SFML/Graphics/Font.hpp +++ b/include/SFML/Graphics/Font.hpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include #include #include #include diff --git a/include/SFML/Graphics/Glyph.hpp b/include/SFML/Graphics/Glyph.hpp index 0068872398..8201195db7 100644 --- a/include/SFML/Graphics/Glyph.hpp +++ b/include/SFML/Graphics/Glyph.hpp @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include namespace sf diff --git a/include/SFML/Graphics/Image.hpp b/include/SFML/Graphics/Image.hpp index 11dc8f705c..e19aa005e0 100644 --- a/include/SFML/Graphics/Image.hpp +++ b/include/SFML/Graphics/Image.hpp @@ -28,9 +28,9 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// +#include #include #include -#include #include #include diff --git a/include/SFML/Graphics/Rect.hpp b/include/SFML/Graphics/Rect.hpp index f11a920477..a710ad0489 100644 --- a/include/SFML/Graphics/Rect.hpp +++ b/include/SFML/Graphics/Rect.hpp @@ -22,227 +22,10 @@ // //////////////////////////////////////////////////////////// -#ifndef SFML_RECT_HPP -#define SFML_RECT_HPP //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include -#include +#include - -namespace sf -{ -//////////////////////////////////////////////////////////// -/// \brief Utility class for manipulating 2D axis aligned rectangles -/// -//////////////////////////////////////////////////////////// -template -class Rect -{ -public: - - //////////////////////////////////////////////////////////// - /// \brief Default constructor - /// - /// Creates an empty rectangle (it is equivalent to calling - /// Rect(0, 0, 0, 0)). - /// - //////////////////////////////////////////////////////////// - Rect(); - - //////////////////////////////////////////////////////////// - /// \brief Construct the rectangle from its coordinates - /// - /// Be careful, the last two parameters are the width - /// and height, not the right and bottom coordinates! - /// - /// \param rectLeft Left coordinate of the rectangle - /// \param rectTop Top coordinate of the rectangle - /// \param rectWidth Width of the rectangle - /// \param rectHeight Height of the rectangle - /// - //////////////////////////////////////////////////////////// - Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight); - - //////////////////////////////////////////////////////////// - /// \brief Construct the rectangle from position and size - /// - /// Be careful, the last parameter is the size, - /// not the bottom-right corner! - /// - /// \param position Position of the top-left corner of the rectangle - /// \param size Size of the rectangle - /// - //////////////////////////////////////////////////////////// - Rect(const Vector2& position, const Vector2& size); - - //////////////////////////////////////////////////////////// - /// \brief Construct the rectangle from another type of rectangle - /// - /// This constructor doesn't replace the copy constructor, - /// it's called only when U != T. - /// A call to this constructor will fail to compile if U - /// is not convertible to T. - /// - /// \param rectangle Rectangle to convert - /// - //////////////////////////////////////////////////////////// - template - explicit Rect(const Rect& rectangle); - - //////////////////////////////////////////////////////////// - /// \brief Check if a point is inside the rectangle's area - /// - /// \param x X coordinate of the point to test - /// \param y Y coordinate of the point to test - /// - /// \return True if the point is inside, false otherwise - /// - /// \see intersects - /// - //////////////////////////////////////////////////////////// - bool contains(T x, T y) const; - - //////////////////////////////////////////////////////////// - /// \brief Check if a point is inside the rectangle's area - /// - /// \param point Point to test - /// - /// \return True if the point is inside, false otherwise - /// - /// \see intersects - /// - //////////////////////////////////////////////////////////// - bool contains(const Vector2& point) const; - - //////////////////////////////////////////////////////////// - /// \brief Check the intersection between two rectangles - /// - /// \param rectangle Rectangle to test - /// - /// \return True if rectangles overlap, false otherwise - /// - /// \see contains - /// - //////////////////////////////////////////////////////////// - bool intersects(const Rect& rectangle) const; - - //////////////////////////////////////////////////////////// - /// \brief Check the intersection between two rectangles - /// - /// This overload returns the overlapped rectangle in the - /// \a intersection parameter. - /// - /// \param rectangle Rectangle to test - /// \param intersection Rectangle to be filled with the intersection - /// - /// \return True if rectangles overlap, false otherwise - /// - /// \see contains - /// - //////////////////////////////////////////////////////////// - bool intersects(const Rect& rectangle, Rect& intersection) const; - - //////////////////////////////////////////////////////////// - // Member data - //////////////////////////////////////////////////////////// - T left; ///< Left coordinate of the rectangle - T top; ///< Top coordinate of the rectangle - T width; ///< Width of the rectangle - T height; ///< Height of the rectangle -}; - -//////////////////////////////////////////////////////////// -/// \relates Rect -/// \brief Overload of binary operator == -/// -/// This operator compares strict equality between two rectangles. -/// -/// \param left Left operand (a rectangle) -/// \param right Right operand (a rectangle) -/// -/// \return True if \a left is equal to \a right -/// -//////////////////////////////////////////////////////////// -template -bool operator ==(const Rect& left, const Rect& right); - -//////////////////////////////////////////////////////////// -/// \relates Rect -/// \brief Overload of binary operator != -/// -/// This operator compares strict difference between two rectangles. -/// -/// \param left Left operand (a rectangle) -/// \param right Right operand (a rectangle) -/// -/// \return True if \a left is not equal to \a right -/// -//////////////////////////////////////////////////////////// -template -bool operator !=(const Rect& left, const Rect& right); - -#include - -// Create typedefs for the most common types -typedef Rect IntRect; -typedef Rect FloatRect; - -} // namespace sf - - -#endif // SFML_RECT_HPP - - -//////////////////////////////////////////////////////////// -/// \class sf::Rect -/// \ingroup graphics -/// -/// A rectangle is defined by its top-left corner and its size. -/// It is a very simple class defined for convenience, so -/// its member variables (left, top, width and height) are public -/// and can be accessed directly, just like the vector classes -/// (Vector2 and Vector3). -/// -/// To keep things simple, sf::Rect doesn't define -/// functions to emulate the properties that are not directly -/// members (such as right, bottom, center, etc.), it rather -/// only provides intersection functions. -/// -/// sf::Rect uses the usual rules for its boundaries: -/// \li The left and top edges are included in the rectangle's area -/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area -/// -/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1) -/// don't intersect. -/// -/// sf::Rect is a template and may be used with any numeric type, but -/// for simplicity the instantiations used by SFML are typedef'd: -/// \li sf::Rect is sf::IntRect -/// \li sf::Rect is sf::FloatRect -/// -/// So that you don't have to care about the template syntax. -/// -/// Usage example: -/// \code -/// // Define a rectangle, located at (0, 0) with a size of 20x5 -/// sf::IntRect r1(0, 0, 20, 5); -/// -/// // Define another rectangle, located at (4, 2) with a size of 18x10 -/// sf::Vector2i position(4, 2); -/// sf::Vector2i size(18, 10); -/// sf::IntRect r2(position, size); -/// -/// // Test intersections with the point (3, 1) -/// bool b1 = r1.contains(3, 1); // true -/// bool b2 = r2.contains(3, 1); // false -/// -/// // Test the intersection between r1 and r2 -/// sf::IntRect result; -/// bool b3 = r1.intersects(r2, result); // true -/// // result == (4, 2, 16, 3) -/// \endcode -/// -//////////////////////////////////////////////////////////// +#warning #include is deprected, use #include instead. diff --git a/include/SFML/Graphics/RenderTarget.hpp b/include/SFML/Graphics/RenderTarget.hpp index eb02355278..1938953576 100644 --- a/include/SFML/Graphics/RenderTarget.hpp +++ b/include/SFML/Graphics/RenderTarget.hpp @@ -30,7 +30,6 @@ //////////////////////////////////////////////////////////// #include #include -#include #include #include #include @@ -38,6 +37,7 @@ #include #include #include +#include namespace sf diff --git a/include/SFML/Graphics/Sprite.hpp b/include/SFML/Graphics/Sprite.hpp index c7447dffbf..5b6c7c4876 100644 --- a/include/SFML/Graphics/Sprite.hpp +++ b/include/SFML/Graphics/Sprite.hpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include namespace sf diff --git a/include/SFML/Graphics/Text.hpp b/include/SFML/Graphics/Text.hpp index c31ec611ac..f2b99ccdfd 100644 --- a/include/SFML/Graphics/Text.hpp +++ b/include/SFML/Graphics/Text.hpp @@ -32,8 +32,8 @@ #include #include #include -#include #include +#include #include #include #include diff --git a/include/SFML/Graphics/Transform.hpp b/include/SFML/Graphics/Transform.hpp index a555a33d6f..4749898e8d 100644 --- a/include/SFML/Graphics/Transform.hpp +++ b/include/SFML/Graphics/Transform.hpp @@ -29,7 +29,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include diff --git a/include/SFML/Graphics/VertexArray.hpp b/include/SFML/Graphics/VertexArray.hpp index f0820a5349..ddbfb8bddc 100644 --- a/include/SFML/Graphics/VertexArray.hpp +++ b/include/SFML/Graphics/VertexArray.hpp @@ -31,8 +31,8 @@ #include #include #include -#include #include +#include #include diff --git a/include/SFML/Graphics/View.hpp b/include/SFML/Graphics/View.hpp index 4bd62d83a0..eb914dcff1 100644 --- a/include/SFML/Graphics/View.hpp +++ b/include/SFML/Graphics/View.hpp @@ -29,8 +29,8 @@ // Headers //////////////////////////////////////////////////////////// #include -#include #include +#include #include diff --git a/include/SFML/System.hpp b/include/SFML/System.hpp index 6af065277a..4f9eec78fa 100644 --- a/include/SFML/System.hpp +++ b/include/SFML/System.hpp @@ -38,6 +38,7 @@ #include #include #include +#include #include #include #include diff --git a/include/SFML/System/Rect.hpp b/include/SFML/System/Rect.hpp new file mode 100644 index 0000000000..ad2b8a7923 --- /dev/null +++ b/include/SFML/System/Rect.hpp @@ -0,0 +1,248 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// +// 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_RECT_HPP +#define SFML_RECT_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// \brief Utility class for manipulating 2D axis aligned rectangles +/// +//////////////////////////////////////////////////////////// +template +class Rect +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Default constructor + /// + /// Creates an empty rectangle (it is equivalent to calling + /// Rect(0, 0, 0, 0)). + /// + //////////////////////////////////////////////////////////// + Rect(); + + //////////////////////////////////////////////////////////// + /// \brief Construct the rectangle from its coordinates + /// + /// Be careful, the last two parameters are the width + /// and height, not the right and bottom coordinates! + /// + /// \param rectLeft Left coordinate of the rectangle + /// \param rectTop Top coordinate of the rectangle + /// \param rectWidth Width of the rectangle + /// \param rectHeight Height of the rectangle + /// + //////////////////////////////////////////////////////////// + Rect(T rectLeft, T rectTop, T rectWidth, T rectHeight); + + //////////////////////////////////////////////////////////// + /// \brief Construct the rectangle from position and size + /// + /// Be careful, the last parameter is the size, + /// not the bottom-right corner! + /// + /// \param position Position of the top-left corner of the rectangle + /// \param size Size of the rectangle + /// + //////////////////////////////////////////////////////////// + Rect(const Vector2& position, const Vector2& size); + + //////////////////////////////////////////////////////////// + /// \brief Construct the rectangle from another type of rectangle + /// + /// This constructor doesn't replace the copy constructor, + /// it's called only when U != T. + /// A call to this constructor will fail to compile if U + /// is not convertible to T. + /// + /// \param rectangle Rectangle to convert + /// + //////////////////////////////////////////////////////////// + template + explicit Rect(const Rect& rectangle); + + //////////////////////////////////////////////////////////// + /// \brief Check if a point is inside the rectangle's area + /// + /// \param x X coordinate of the point to test + /// \param y Y coordinate of the point to test + /// + /// \return True if the point is inside, false otherwise + /// + /// \see intersects + /// + //////////////////////////////////////////////////////////// + bool contains(T x, T y) const; + + //////////////////////////////////////////////////////////// + /// \brief Check if a point is inside the rectangle's area + /// + /// \param point Point to test + /// + /// \return True if the point is inside, false otherwise + /// + /// \see intersects + /// + //////////////////////////////////////////////////////////// + bool contains(const Vector2& point) const; + + //////////////////////////////////////////////////////////// + /// \brief Check the intersection between two rectangles + /// + /// \param rectangle Rectangle to test + /// + /// \return True if rectangles overlap, false otherwise + /// + /// \see contains + /// + //////////////////////////////////////////////////////////// + bool intersects(const Rect& rectangle) const; + + //////////////////////////////////////////////////////////// + /// \brief Check the intersection between two rectangles + /// + /// This overload returns the overlapped rectangle in the + /// \a intersection parameter. + /// + /// \param rectangle Rectangle to test + /// \param intersection Rectangle to be filled with the intersection + /// + /// \return True if rectangles overlap, false otherwise + /// + /// \see contains + /// + //////////////////////////////////////////////////////////// + bool intersects(const Rect& rectangle, Rect& intersection) const; + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + T left; ///< Left coordinate of the rectangle + T top; ///< Top coordinate of the rectangle + T width; ///< Width of the rectangle + T height; ///< Height of the rectangle +}; + +//////////////////////////////////////////////////////////// +/// \relates Rect +/// \brief Overload of binary operator == +/// +/// This operator compares strict equality between two rectangles. +/// +/// \param left Left operand (a rectangle) +/// \param right Right operand (a rectangle) +/// +/// \return True if \a left is equal to \a right +/// +//////////////////////////////////////////////////////////// +template +bool operator ==(const Rect& left, const Rect& right); + +//////////////////////////////////////////////////////////// +/// \relates Rect +/// \brief Overload of binary operator != +/// +/// This operator compares strict difference between two rectangles. +/// +/// \param left Left operand (a rectangle) +/// \param right Right operand (a rectangle) +/// +/// \return True if \a left is not equal to \a right +/// +//////////////////////////////////////////////////////////// +template +bool operator !=(const Rect& left, const Rect& right); + +#include + +// Create typedefs for the most common types +typedef Rect IntRect; +typedef Rect FloatRect; + +} // namespace sf + + +#endif // SFML_RECT_HPP + + +//////////////////////////////////////////////////////////// +/// \class sf::Rect +/// \ingroup graphics +/// +/// A rectangle is defined by its top-left corner and its size. +/// It is a very simple class defined for convenience, so +/// its member variables (left, top, width and height) are public +/// and can be accessed directly, just like the vector classes +/// (Vector2 and Vector3). +/// +/// To keep things simple, sf::Rect doesn't define +/// functions to emulate the properties that are not directly +/// members (such as right, bottom, center, etc.), it rather +/// only provides intersection functions. +/// +/// sf::Rect uses the usual rules for its boundaries: +/// \li The left and top edges are included in the rectangle's area +/// \li The right (left + width) and bottom (top + height) edges are excluded from the rectangle's area +/// +/// This means that sf::IntRect(0, 0, 1, 1) and sf::IntRect(1, 1, 1, 1) +/// don't intersect. +/// +/// sf::Rect is a template and may be used with any numeric type, but +/// for simplicity the instantiations used by SFML are typedef'd: +/// \li sf::Rect is sf::IntRect +/// \li sf::Rect is sf::FloatRect +/// +/// So that you don't have to care about the template syntax. +/// +/// Usage example: +/// \code +/// // Define a rectangle, located at (0, 0) with a size of 20x5 +/// sf::IntRect r1(0, 0, 20, 5); +/// +/// // Define another rectangle, located at (4, 2) with a size of 18x10 +/// sf::Vector2i position(4, 2); +/// sf::Vector2i size(18, 10); +/// sf::IntRect r2(position, size); +/// +/// // Test intersections with the point (3, 1) +/// bool b1 = r1.contains(3, 1); // true +/// bool b2 = r2.contains(3, 1); // false +/// +/// // Test the intersection between r1 and r2 +/// sf::IntRect result; +/// bool b3 = r1.intersects(r2, result); // true +/// // result == (4, 2, 16, 3) +/// \endcode +/// +//////////////////////////////////////////////////////////// diff --git a/include/SFML/Graphics/Rect.inl b/include/SFML/System/Rect.inl similarity index 100% rename from include/SFML/Graphics/Rect.inl rename to include/SFML/System/Rect.inl diff --git a/include/SFML/Window.hpp b/include/SFML/Window.hpp index 103f8882a1..d07ab457ac 100644 --- a/include/SFML/Window.hpp +++ b/include/SFML/Window.hpp @@ -36,6 +36,7 @@ #include #include #include +#include #include #include #include diff --git a/include/SFML/Window/Screen.hpp b/include/SFML/Window/Screen.hpp new file mode 100644 index 0000000000..37e60c27fa --- /dev/null +++ b/include/SFML/Window/Screen.hpp @@ -0,0 +1,127 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// +// 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_SCREEN_HPP +#define SFML_SCREEN_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include + +#include +#include + +namespace sf +{ + +//////////////////////////////////////////////////////////// +/// \brief Class representing a screen (monitor, projector, ...) +/// +//////////////////////////////////////////////////////////// +class SFML_WINDOW_API Screen +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Construct a screen with its attributes + /// + /// \param name Name of the screen + /// \param id Id of the screen + /// \param bounds Bounds of the screen in virtual screen space + /// \param workingArea Working area of the screen in virtual screen space + /// \param refreshRate Refresh rate of the screen + /// \param dpi Dpi (dots per inch) of the screen + /// \param isPrimary Is it the primary screen? + /// \param fullscreenModes A vector containing the supported fullscreen modes + /// \param desktopMode Desktop mode of the screen + /// + //////////////////////////////////////////////////////////// + Screen(std::wstring name, unsigned int id, IntRect bounds, IntRect workingArea, unsigned int refreshRate, Vector2u dpi, bool isPrimary, std::vector fullscreenModes, VideoMode desktopMode); + + //////////////////////////////////////////////////////////// + /// \brief Get the number of currently connected screens + /// + /// \return Current screen count + /// + //////////////////////////////////////////////////////////// + static std::size_t count(); + + //////////////////////////////////////////////////////////// + /// \brief Get a screen based on its Id + /// + /// If the screen with the specified Id could not be found + /// the default screen (with Id 0) is returned. + /// + /// \param id Id of the screen we want to get + /// + /// \return Screen with specified Id + /// + //////////////////////////////////////////////////////////// + static const Screen& get(unsigned int id); + + //////////////////////////////////////////////////////////// + // Member data + //////////////////////////////////////////////////////////// + std::wstring name; ///< Name of the screen + unsigned int id; ///< Id of the screen + IntRect bounds; ///< Bounds of the screen in virtual screen space + IntRect workingArea; ///< Working area of the screen in virtual screen space + unsigned int refreshRate; ///< Refresh rate of the screen + Vector2u dpi; ///< Dpi (dots per inch) of the screen + bool isPrimary; ///< Is this the primary screen? + std::vector fullscreenModes; ///< Supported fullscreen modes of this screen + VideoMode desktopMode; ///< Desktop mode of the screen +}; + +} // namespace sf + + +#endif // SFML_SCREEN_HPP + + +//////////////////////////////////////////////////////////// +/// \class sf::Screen +/// \ingroup window +/// +/// The bounds of the screen are composed of its position +/// in virtual screen space and its size. +/// +/// The working area of the screen is a subrect of the screens +/// bounds. It is the usable area of a screen in virtual screen space. +/// For example it excludes the taskbar on windows or the dock +/// and menu bar on OSX. +/// +/// The fullscreenModes vector contains the complete list of +/// all video modes that can be used in fullscreen mode by +/// this screen. When creating a fullscreen window, the video +/// mode is restricted to be compatible with what the graphics +/// driver and screen support. +/// The returned vector is sorted from best to worst, so that +/// the first element will always give the best mode (higher +/// width, height and bits-per-pixel). +/// +//////////////////////////////////////////////////////////// diff --git a/include/SFML/Window/VideoMode.hpp b/include/SFML/Window/VideoMode.hpp index 5eb268cda4..5ac69f7af8 100644 --- a/include/SFML/Window/VideoMode.hpp +++ b/include/SFML/Window/VideoMode.hpp @@ -56,9 +56,10 @@ class SFML_WINDOW_API VideoMode /// \param modeWidth Width in pixels /// \param modeHeight Height in pixels /// \param modeBitsPerPixel Pixel depths in bits per pixel + /// \param modeScreenId ID of the screen this video mode is associated with /// //////////////////////////////////////////////////////////// - VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel = 32); + VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel = 32, unsigned int modeScreenId = 0); //////////////////////////////////////////////////////////// /// \brief Get the current desktop video mode @@ -66,7 +67,7 @@ class SFML_WINDOW_API VideoMode /// \return Current desktop video mode /// //////////////////////////////////////////////////////////// - static VideoMode getDesktopMode(); + SFML_DEPRECATED("sf::VideoMode::getDesktopMode() is deprected, use sf::Screen::get(0).getDesktopMode() instead.", static VideoMode getDesktopMode()); //////////////////////////////////////////////////////////// /// \brief Retrieve all the video modes supported in fullscreen mode @@ -82,7 +83,7 @@ class SFML_WINDOW_API VideoMode /// \return Array containing all the supported fullscreen modes /// //////////////////////////////////////////////////////////// - static const std::vector& getFullscreenModes(); + SFML_DEPRECATED("sf::VideoMode::getFullscreenModes() is deprected, use sf::Screen::get(0).getFullscreenModes() instead.", static const std::vector& getFullscreenModes()); //////////////////////////////////////////////////////////// /// \brief Tell whether or not the video mode is valid @@ -102,6 +103,7 @@ class SFML_WINDOW_API VideoMode unsigned int width; ///< Video mode width, in pixels unsigned int height; ///< Video mode height, in pixels unsigned int bitsPerPixel; ///< Video mode pixel depth, in bits per pixels + unsigned int screenId; ///< ID of the screen this video mode is associated with }; //////////////////////////////////////////////////////////// diff --git a/include/SFML/Window/Window.hpp b/include/SFML/Window/Window.hpp index 44f0752261..bdd875a9f3 100644 --- a/include/SFML/Window/Window.hpp +++ b/include/SFML/Window/Window.hpp @@ -31,6 +31,7 @@ #include #include #include +#include #include #include #include diff --git a/src/SFML/Graphics/CMakeLists.txt b/src/SFML/Graphics/CMakeLists.txt index 6f02fb66f3..e653144f62 100644 --- a/src/SFML/Graphics/CMakeLists.txt +++ b/src/SFML/Graphics/CMakeLists.txt @@ -22,7 +22,6 @@ set(SRC ${SRCROOT}/ImageLoader.hpp ${INCROOT}/PrimitiveType.hpp ${INCROOT}/Rect.hpp - ${INCROOT}/Rect.inl ${SRCROOT}/RenderStates.cpp ${INCROOT}/RenderStates.hpp ${SRCROOT}/RenderTexture.cpp diff --git a/src/SFML/System/CMakeLists.txt b/src/SFML/System/CMakeLists.txt index 48629f4e02..4bc92b4107 100644 --- a/src/SFML/System/CMakeLists.txt +++ b/src/SFML/System/CMakeLists.txt @@ -15,6 +15,8 @@ set(SRC ${SRCROOT}/Mutex.cpp ${INCROOT}/Mutex.hpp ${INCROOT}/NonCopyable.hpp + ${INCROOT}/Rect.hpp + ${INCROOT}/Rect.inl ${SRCROOT}/Sleep.cpp ${INCROOT}/Sleep.hpp ${SRCROOT}/String.cpp diff --git a/src/SFML/Window/CMakeLists.txt b/src/SFML/Window/CMakeLists.txt index 386c077813..3fc7586ead 100644 --- a/src/SFML/Window/CMakeLists.txt +++ b/src/SFML/Window/CMakeLists.txt @@ -25,6 +25,9 @@ set(SRC ${SRCROOT}/Mouse.cpp ${INCROOT}/Touch.hpp ${SRCROOT}/Touch.cpp + ${INCROOT}/Screen.hpp + ${SRCROOT}/Screen.cpp + ${SRCROOT}/ScreenImpl.hpp ${INCROOT}/Sensor.hpp ${SRCROOT}/Sensor.cpp ${SRCROOT}/SensorImpl.hpp @@ -59,9 +62,10 @@ if(SFML_OS_WINDOWS) ${SRCROOT}/Win32/InputImpl.hpp ${SRCROOT}/Win32/JoystickImpl.cpp ${SRCROOT}/Win32/JoystickImpl.hpp + ${SRCROOT}/Win32/ScreenImpl.cpp + ${SRCROOT}/Win32/ScreenImpl.hpp ${SRCROOT}/Win32/SensorImpl.hpp ${SRCROOT}/Win32/SensorImpl.cpp - ${SRCROOT}/Win32/VideoModeImpl.cpp ${SRCROOT}/Win32/WindowImplWin32.cpp ${SRCROOT}/Win32/WindowImplWin32.hpp ) diff --git a/src/SFML/Window/Win32/VideoModeImpl.cpp b/src/SFML/Window/Screen.cpp similarity index 58% rename from src/SFML/Window/Win32/VideoModeImpl.cpp rename to src/SFML/Window/Screen.cpp index 4b34a0fcc7..19270488a3 100644 --- a/src/SFML/Window/Win32/VideoModeImpl.cpp +++ b/src/SFML/Window/Screen.cpp @@ -25,47 +25,40 @@ //////////////////////////////////////////////////////////// // Headers //////////////////////////////////////////////////////////// -#include -#include +#include +#include #include - namespace sf { -namespace priv -{ //////////////////////////////////////////////////////////// -std::vector VideoModeImpl::getFullscreenModes() +Screen::Screen(std::wstring name, unsigned int id, IntRect bounds, IntRect workingArea, unsigned int refreshRate, Vector2u dpi, bool isPrimary, std::vector fullscreenModes, VideoMode desktopMode) : + name(name), + id(id), + bounds(bounds), + workingArea(workingArea), + refreshRate(refreshRate), + dpi(dpi), + isPrimary(isPrimary), + fullscreenModes(fullscreenModes), + desktopMode(desktopMode) { - std::vector modes; - // Enumerate all available video modes for the primary display adapter - DEVMODE win32Mode; - win32Mode.dmSize = sizeof(win32Mode); - for (int count = 0; EnumDisplaySettings(NULL, count, &win32Mode); ++count) - { - // Convert to sf::VideoMode - VideoMode mode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); +} - // Add it only if it is not already in the array - if (std::find(modes.begin(), modes.end(), mode) == modes.end()) - modes.push_back(mode); - } - return modes; +//////////////////////////////////////////////////////////// +std::size_t Screen::count() +{ + return priv::ScreenImpl::count(); } //////////////////////////////////////////////////////////// -VideoMode VideoModeImpl::getDesktopMode() +const Screen& Screen::get(unsigned int id) { - DEVMODE win32Mode; - win32Mode.dmSize = sizeof(win32Mode); - EnumDisplaySettings(NULL, ENUM_CURRENT_SETTINGS, &win32Mode); - - return VideoMode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); + return priv::ScreenImpl::get(id); } -} // namespace priv } // namespace sf diff --git a/src/SFML/Window/ScreenImpl.hpp b/src/SFML/Window/ScreenImpl.hpp new file mode 100644 index 0000000000..83b8edf239 --- /dev/null +++ b/src/SFML/Window/ScreenImpl.hpp @@ -0,0 +1,74 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// +// 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_SCREENIMPL_HPP +#define SFML_SCREENIMPL_HPP + + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +/// \brief OS-specific implementation of screen functions +/// +//////////////////////////////////////////////////////////// +class ScreenImpl +{ +public: + + //////////////////////////////////////////////////////////// + /// \brief Get the number of currently connected screens + /// + /// \return Current screen count + /// + //////////////////////////////////////////////////////////// + static std::size_t count(); + + //////////////////////////////////////////////////////////// + /// \brief Get a screen based on its Id + /// + /// If the screen with the specified Id could not be found + /// the default screen (with Id 0) is returned. + /// + /// \param id Id of the screen we want to get + /// + /// \return Screen with specified Id + /// + //////////////////////////////////////////////////////////// + static const Screen& get(unsigned int id); + +}; + +} //namespace priv + +} //namespace sf + +#endif // SFML_SCREENIMPL_HPP diff --git a/src/SFML/Window/VideoMode.cpp b/src/SFML/Window/VideoMode.cpp index 8f3861d493..5d883772e2 100644 --- a/src/SFML/Window/VideoMode.cpp +++ b/src/SFML/Window/VideoMode.cpp @@ -26,9 +26,9 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include +#include #include -#include namespace sf @@ -37,17 +37,19 @@ namespace sf VideoMode::VideoMode() : width (0), height (0), -bitsPerPixel(0) +bitsPerPixel(0), +screenId (0) { } //////////////////////////////////////////////////////////// -VideoMode::VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel) : +VideoMode::VideoMode(unsigned int modeWidth, unsigned int modeHeight, unsigned int modeBitsPerPixel, unsigned int modeScreenId) : width (modeWidth), height (modeHeight), -bitsPerPixel(modeBitsPerPixel) +bitsPerPixel(modeBitsPerPixel), +screenId (modeScreenId) { } @@ -56,40 +58,37 @@ bitsPerPixel(modeBitsPerPixel) //////////////////////////////////////////////////////////// VideoMode VideoMode::getDesktopMode() { - // Directly forward to the OS-specific implementation - return priv::VideoModeImpl::getDesktopMode(); + return sf::Screen::get(0).desktopMode; } //////////////////////////////////////////////////////////// const std::vector& VideoMode::getFullscreenModes() { - static std::vector modes; - - // Populate the array on first call - if (modes.empty()) - { - modes = priv::VideoModeImpl::getFullscreenModes(); - std::sort(modes.begin(), modes.end(), std::greater()); - } - - return modes; + return sf::Screen::get(0).fullscreenModes; } //////////////////////////////////////////////////////////// bool VideoMode::isValid() const { - const std::vector& modes = getFullscreenModes(); + if(screenId < sf::Screen::count()) + { + const std::vector& modes = sf::Screen::get(screenId).fullscreenModes; + + return std::find(modes.begin(), modes.end(), *this) != modes.end(); + } - return std::find(modes.begin(), modes.end(), *this) != modes.end(); + err() << "The screen with ID " << screenId << " is not available. Please use sf::Screen::count() to get the available number of screens." << std::endl; + return false; } //////////////////////////////////////////////////////////// bool operator ==(const VideoMode& left, const VideoMode& right) { - return (left.width == right.width) && + return (left.screenId == right.screenId) && + (left.width == right.width) && (left.height == right.height) && (left.bitsPerPixel == right.bitsPerPixel); } diff --git a/src/SFML/Window/Win32/ScreenImpl.cpp b/src/SFML/Window/Win32/ScreenImpl.cpp new file mode 100644 index 0000000000..701ff02a68 --- /dev/null +++ b/src/SFML/Window/Win32/ScreenImpl.cpp @@ -0,0 +1,285 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// +// 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. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include +#include +#include + +#ifdef _WIN32_WINDOWS + #undef _WIN32_WINDOWS +#endif +#ifdef _WIN32_WINNT + #undef _WIN32_WINNT +#endif +#define _WIN32_WINDOWS 0x0501 +#define _WIN32_WINNT 0x0501 +#include +#ifndef EDD_GET_DEVICE_INTERFACE_NAME + #define EDD_GET_DEVICE_INTERFACE_NAME 0x00000001 +#endif + +#include +#include +#include +#include + +#include + +namespace +{ + std::vector > screensWithDeviceName; + + + //////////////////////////////////////////////////////////// + bool screenSorter(const std::pair& left, const std::pair& right) + { + return (left.first.bounds.left < right.first.bounds.left); + } + + + //////////////////////////////////////////////////////////// + void ensureScreenListInitilized() + { + static bool initialized = false; + if(!initialized) + { + // Enumerate over all available screen + DISPLAY_DEVICE displayDevice; + std::memset(&displayDevice, 0, sizeof(displayDevice)); + displayDevice.cb = sizeof(displayDevice); + for (int count = 0; EnumDisplayDevices(NULL, count, &displayDevice, 0); ++count) + { + // check if the screen is not mirrored and there is actually a screen attached + if (!(displayDevice.StateFlags & DISPLAY_DEVICE_MIRRORING_DRIVER) && + displayDevice.StateFlags & DISPLAY_DEVICE_ATTACHED_TO_DESKTOP) + { + // try to get the screens current desktop video mode + // to access its position and dimension in the virtual screen space + DEVMODE win32desktopMode; + std::memset(&win32desktopMode, 0, sizeof(win32desktopMode)); + win32desktopMode.dmSize = sizeof(win32desktopMode); + if (EnumDisplaySettingsEx(displayDevice.DeviceName, ENUM_CURRENT_SETTINGS, &win32desktopMode, 0) == FALSE) + { + std::wcout << "Couldn't get desktop settings of screen: " << displayDevice.DeviceName << std::endl; + break; + } + const sf::VideoMode desktopMode(win32desktopMode.dmPelsWidth, win32desktopMode.dmPelsHeight, win32desktopMode.dmBitsPerPel); + unsigned int refreshRate = win32desktopMode.dmDisplayFrequency; + + // get the screens real name + DISPLAY_DEVICE nameDD; + std::memset(&nameDD, 0, sizeof(nameDD)); + nameDD.cb = sizeof(nameDD); + EnumDisplayDevices(displayDevice.DeviceName, 0, &nameDD, EDD_GET_DEVICE_INTERFACE_NAME); + const std::wstring monitorName(nameDD.DeviceString); + + // get the bounds and the working area + sf::IntRect bounds; + sf::IntRect workingArea; + POINT point; + point.x = win32desktopMode.dmPosition.x; + point.y = win32desktopMode.dmPosition.y; + HMONITOR monitor = MonitorFromPoint(point, MONITOR_DEFAULTTONEAREST); + + MONITORINFOEX info; + std::memset(&info, 0, sizeof(MONITORINFOEX)); + info.cbSize = sizeof(MONITORINFOEX); + if (GetMonitorInfo(monitor, &info) == TRUE) + { + bounds = sf::IntRect(info.rcMonitor.left, info.rcMonitor.top, info.rcMonitor.right - info.rcMonitor.left, info.rcMonitor.bottom - info.rcMonitor.top); + workingArea = sf::IntRect(info.rcWork.left, info.rcWork.top, info.rcWork.right - info.rcWork.left, info.rcWork.bottom - info.rcWork.top); + } + else + { + bounds = sf::IntRect(win32desktopMode.dmPosition.x, win32desktopMode.dmPosition.y, win32desktopMode.dmPelsWidth, win32desktopMode.dmPelsHeight); + workingArea = bounds; + } + + // get the DPI + sf::Vector2u dpi; + + // Since windows 8.1 you can get the DPI on a per monitor basis + HINSTANCE shCoreDll = LoadLibrary(L"Shcore.dll"); + if (shCoreDll) + { + typedef HRESULT (WINAPI* GetDpiForMonitorFuncType)(HMONITOR hmonitor, int dpiType, UINT* dpiX, UINT* dpiY); + GetDpiForMonitorFuncType GetDpiForMonitorFunc = reinterpret_cast(GetProcAddress(shCoreDll, "GetDpiForMonitor")); + + if (GetDpiForMonitorFunc) + { + UINT dpiX; + UINT dpiY; + + if (GetDpiForMonitorFunc(monitor, 0, &dpiX, &dpiY) == S_OK) + { + dpi = sf::Vector2u(dpiX, dpiY); + } + } + + FreeLibrary(shCoreDll); + } + + HDC hdc = CreateDC(displayDevice.DeviceName, NULL, NULL, NULL); + if (hdc) + { + // If the library loading failed (library not available or windows version < 8.1) + // use the old way of getting the DPI (one value for all monitors) + if (dpi == sf::Vector2u()) + { + dpi = sf::Vector2u(GetDeviceCaps(hdc, LOGPIXELSX), GetDeviceCaps(hdc, LOGPIXELSY)); + } + + // try to get the device refresh rate + const unsigned int deviceRefreshRate = GetDeviceCaps(hdc, VREFRESH); + if (deviceRefreshRate > 1) + { + // 0,1 means hardware default, so we keep using the desktop modes refresh rate + refreshRate = deviceRefreshRate; + } + + DeleteDC(hdc); + } + + // get the supported fullscreen modes + std::vector fullscreenModes; + DEVMODE win32Mode; + std::memset(&win32Mode, 0, sizeof(win32Mode)); + win32Mode.dmSize = sizeof(win32Mode); + for (int fullScreenCount = 0; EnumDisplaySettings(displayDevice.DeviceName, fullScreenCount, &win32Mode); ++fullScreenCount) + { + // Convert to VideoMode + sf::VideoMode mode(win32Mode.dmPelsWidth, win32Mode.dmPelsHeight, win32Mode.dmBitsPerPel); + + // Add it only if it is not already in the array + if (std::find(fullscreenModes.begin(), fullscreenModes.end(), mode) == fullscreenModes.end()) + fullscreenModes.push_back(mode); + } + + // check if this is the primary monitor + bool isPrimary = false; + if (displayDevice.StateFlags & DISPLAY_DEVICE_PRIMARY_DEVICE) + { + isPrimary = true; + } + + // save the data + sf::Screen screen(monitorName, 0, bounds, workingArea, refreshRate, dpi, isPrimary, fullscreenModes, desktopMode); + screensWithDeviceName.push_back(std::make_pair(screen, std::wstring(displayDevice.DeviceName))); + } + } + + // sort the screens from left to right + std::sort(screensWithDeviceName.begin(), screensWithDeviceName.end(), screenSorter); + + // put the primary screen at index [0] + for (unsigned int i = 0; i < screensWithDeviceName.size(); ++i) + { + if(screensWithDeviceName[i].first.isPrimary) + { + std::pair primaryScreen = screensWithDeviceName[i]; + screensWithDeviceName.erase(screensWithDeviceName.begin() + i); + screensWithDeviceName.insert(screensWithDeviceName.begin(), primaryScreen); + } + } + + // update the video mode screen ids + for (unsigned int id = 0; id < screensWithDeviceName.size(); ++id) + { + screensWithDeviceName[id].first.id = id; + + for (unsigned int mode = 0; mode < screensWithDeviceName[id].first.fullscreenModes.size(); ++mode) + { + screensWithDeviceName[id].first.fullscreenModes[mode].screenId = id; + } + + screensWithDeviceName[id].first.desktopMode.screenId = id; + } + + + // display the gathered information + for (int i = 0; i < screensWithDeviceName.size(); ++i) + { + sf::Screen screen = screensWithDeviceName[i].first; + std::wcout << screen.name << " " << screen.refreshRate << "Hz " << screen.dpi.x << "x" << screen.dpi.y << "dpi " << screensWithDeviceName[i].second << std::endl; + const sf::IntRect bounds = screen.bounds; + const sf::IntRect workingArea = screen.workingArea; + std::cout << "x: " << bounds.left << " y: " << bounds.top << " width: " << bounds.width << " height: " << bounds.height << std::endl; + std::cout << "x: " << workingArea.left << " y: " << workingArea.top << " width: " << workingArea.width << " height: " << workingArea.height << std::endl; + std::cout << std::endl; + } + + initialized = true; + } + } +} + + +namespace sf +{ +namespace priv +{ +//////////////////////////////////////////////////////////// +std::size_t ScreenImpl::count() +{ + ensureScreenListInitilized(); + + return screensWithDeviceName.size(); +} + + +//////////////////////////////////////////////////////////// +const Screen& ScreenImpl::get(unsigned int id) +{ + ensureScreenListInitilized(); + + if (id < screensWithDeviceName.size()) + return screensWithDeviceName[id].first; + + err() << "Screen with ID: " << id << " requested. No device with specified ID found. Returning default screen." << std::endl; + return screensWithDeviceName[0].first; +} + + + + +//////////////////////////////////////////////////////////// +const std::wstring getDisplayDeviceFromId(unsigned int screenId) +{ + ensureScreenListInitilized(); + + if (screenId < screensWithDeviceName.size()) + return screensWithDeviceName[screenId].second; + + err() << "Diplay device with ID: " << screenId << " requested. No device with specified ID found." << std::endl; + return std::wstring(); +} + + +} // namespace priv + +} // namespace sf diff --git a/src/SFML/Window/Win32/ScreenImpl.hpp b/src/SFML/Window/Win32/ScreenImpl.hpp new file mode 100644 index 0000000000..32fc5c7c5a --- /dev/null +++ b/src/SFML/Window/Win32/ScreenImpl.hpp @@ -0,0 +1,45 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2015 Laurent Gomila (laurent@sfml-dev.org) +// +// 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_SCREENIMPLWIN32_HPP +#define SFML_SCREENIMPLWIN32_HPP + +#include + + +namespace sf +{ +namespace priv +{ + + const std::wstring getDisplayDeviceFromId(unsigned int screenId); + +} // namespace priv + +} // namespace sf + +#endif // SFML_SCREENIMPLWIN32_HPP +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// diff --git a/src/SFML/Window/Win32/WglContext.cpp b/src/SFML/Window/Win32/WglContext.cpp index c4e8b93323..374e88cc1a 100644 --- a/src/SFML/Window/Win32/WglContext.cpp +++ b/src/SFML/Window/Win32/WglContext.cpp @@ -28,6 +28,7 @@ #include // included first to avoid a warning about macro redefinition #include #include +#include #include #include #include @@ -84,7 +85,7 @@ m_ownsWindow (true) // Create the context if (m_deviceContext) - createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, ContextSettings()); + createContext(shared, Screen::get(0).desktopMode.bitsPerPixel, ContextSettings()); } @@ -124,7 +125,7 @@ m_ownsWindow (true) // Create the context if (m_deviceContext) - createContext(shared, VideoMode::getDesktopMode().bitsPerPixel, settings); + createContext(shared, Screen::get(0).desktopMode.bitsPerPixel, settings); } diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 8bf86ab819..61576cee09 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -35,11 +35,15 @@ #define _WIN32_WINNT 0x0501 #define WINVER 0x0501 #include +#include +#include #include #include #include +#include #include #include +#include // MinGW lacks the definition of some Win32 constants #ifndef XBUTTON1 @@ -166,12 +170,11 @@ m_mouseInside (false) registerWindowClass(); // Compute position and size - HDC screenDC = GetDC(NULL); - int left = (GetDeviceCaps(screenDC, HORZRES) - static_cast(mode.width)) / 2; - int top = (GetDeviceCaps(screenDC, VERTRES) - static_cast(mode.height)) / 2; - int width = mode.width; - int height = mode.height; - ReleaseDC(NULL, screenDC); + const IntRect screenDimensions = Screen::get(mode.screenId).bounds; + const int left = ((screenDimensions.width - static_cast(mode.width)) / 2) + screenDimensions.left; + const int top = ((screenDimensions.height - static_cast(mode.height)) / 2) + screenDimensions.top;; + int width = mode.width; + int height = mode.height; // Choose the window style according to the Style parameter DWORD win32Style = WS_VISIBLE; @@ -425,15 +428,22 @@ void WindowImplWin32::registerWindowClass() //////////////////////////////////////////////////////////// void WindowImplWin32::switchToFullscreen(const VideoMode& mode) { + const IntRect screenDimensions = Screen::get(mode.screenId).bounds; + DEVMODE devMode; + std::memset(&devMode, 0, sizeof(devMode)); devMode.dmSize = sizeof(devMode); - devMode.dmPelsWidth = mode.width; - devMode.dmPelsHeight = mode.height; + devMode.dmPosition.x = screenDimensions.left; + devMode.dmPosition.y = screenDimensions.top; + devMode.dmPelsWidth = screenDimensions.width; + devMode.dmPelsHeight = screenDimensions.height; devMode.dmBitsPerPel = mode.bitsPerPixel; - devMode.dmFields = DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; + devMode.dmFields = DM_POSITION | DM_PELSWIDTH | DM_PELSHEIGHT | DM_BITSPERPEL; + + const std::wstring& deviceName = priv::getDisplayDeviceFromId(mode.screenId); // Apply fullscreen mode - if (ChangeDisplaySettingsW(&devMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) + if (ChangeDisplaySettingsEx(deviceName.c_str(), &devMode, NULL, CDS_FULLSCREEN, NULL) != DISP_CHANGE_SUCCESSFUL) { err() << "Failed to change display mode for fullscreen" << std::endl; return; @@ -444,7 +454,7 @@ void WindowImplWin32::switchToFullscreen(const VideoMode& mode) SetWindowLongW(m_handle, GWL_EXSTYLE, WS_EX_APPWINDOW); // Resize the window so that it fits the entire screen - SetWindowPos(m_handle, HWND_TOP, 0, 0, mode.width, mode.height, SWP_FRAMECHANGED); + SetWindowPos(m_handle, HWND_TOP, screenDimensions.left, screenDimensions.top, screenDimensions.width, screenDimensions.height, SWP_FRAMECHANGED); ShowWindow(m_handle, SW_SHOW); // Set "this" as the current fullscreen window diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index a091325fb8..4e79b5ae4c 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -101,7 +101,7 @@ void Window::create(VideoMode mode, const String& title, Uint32 style, const Con if (!mode.isValid()) { err() << "The requested video mode is not available, switching to a valid mode" << std::endl; - mode = VideoMode::getFullscreenModes()[0]; + mode = Screen::get(mode.screenId).fullscreenModes[0]; } // Update the fullscreen window @@ -141,7 +141,8 @@ void Window::create(WindowHandle handle, const ContextSettings& settings) m_impl = priv::WindowImpl::create(handle); // Recreate the context - m_context = priv::GlContext::create(settings, m_impl, VideoMode::getDesktopMode().bitsPerPixel); + // TODO: Maybe implement a get screen from point + m_context = priv::GlContext::create(settings, m_impl, Screen::get(0).desktopMode.bitsPerPixel); // Perform common initializations initialize();